Пример #1
0
 public void IgnoreAccount(DbAccount acc, int lockId)
 {
     try
     {
         List <int> x = acc.Ignored.ToList();
         if (!x.Contains(lockId))
         {
             x.Add(lockId);
             int[] result = x.ToArray();
             acc.Ignored = result;
             acc.Flush();
             acc.Reload();
         }
         else
         {
             x.Remove(lockId);
             int[] result = x.ToArray();
             acc.Ignored = result;
             acc.Flush();
             acc.Reload();
         }
     }
     catch
     {
         List <int> x = new List <int>();
         x.Add(lockId);
         int[] result = x.ToArray();
         acc.Ignored = result;
         acc.Flush();
         acc.Reload();
     }
 }
Пример #2
0
        public bool RemoveFromGuild(DbAccount acc)
        {
            var guild = GetGuild(Convert.ToInt32(acc.GuildId));

            if (guild == null)
            {
                return(false);
            }

            List <int> members;

            members = guild.Members.ToList();
            if (members.Contains(Convert.ToInt32(acc.AccountId)))
            {
                members.Remove(Convert.ToInt32(acc.AccountId));
                guild.Members = members.ToArray();
                guild.Flush();
            }
            var idBuff = BitConverter.GetBytes(guild.Id);

            if (members.Count <= 0)
            {
                using (var t = CreateTransaction())
                    t.Hashes.Remove(0, "guilds", guild.Name.ToUpperInvariant());
            }

            acc.GuildId   = "-1";
            acc.GuildRank = -1;
            acc.GuildFame = -1;
            acc.Flush();
            return(true);
        }
Пример #3
0
        public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc)
        {
            acc = null;
            if (!Hashes.SetIfNotExists(0, "logins", uuid.ToUpperInvariant(), "{}").Exec())
            {
                return(RegisterStatus.UsedName);
            }

            int newAccId = (int)Strings.Increment(0, "nextAccId").Exec();

            acc = new DbAccount(this, newAccId.ToString())
            {
                UUID          = uuid,
                Name          = defaultNames[(uint)uuid.GetHashCode() % defaultNames.Length],
                Rank          = 0,
                Admin         = false,
                NameChosen    = false,
                Verified      = false,
                Converted     = false,
                GuildId       = "-1",
                GuildRank     = -1,
                VaultCount    = 1,
                MaxCharSlot   = 3,
                RegTime       = DateTime.Now,
                Guest         = true,
                Fame          = 0,
                TotalFame     = 0,
                Credits       = 1000,
                FortuneTokens = 0,
                Gifts         = new int[] { 0xae9 },
                PetYardType   = 1,
                IsAgeVerified = 1,
            };
            acc.Flush();

            var login = new DbLoginInfo(this, uuid);

            var x = new byte[0x10];

            gen.GetNonZeroBytes(x);
            string salt = Convert.ToBase64String(x);
            string hash = Convert.ToBase64String(Utils.SHA1(password + salt));

            login.HashedPassword = hash;
            login.Salt           = salt;
            login.AccountId      = acc.AccountId;
            login.Flush();

            var stats = new DbClassStats(acc);

            stats.Flush();

            var vault = new DbVault(acc);

            vault[0] = Enumerable.Repeat(-1, 8).ToArray();
            vault.Flush();

            return(RegisterStatus.OK);
        }
Пример #4
0
        public void AddSkin(DbAccount acc, int skin)
        {
            List <int> skinList = acc.OwnedSkins.ToList();

            skinList.Add(skin);
            int[] result = skinList.ToArray();
            acc.OwnedSkins = result;
            acc.Flush();
            acc.Reload();
        }
Пример #5
0
        public void AddPackage(DbAccount acc, int package)
        {
            List <int> packageList = acc.PurchasedPackages.ToList();

            packageList.Add(package);
            int[] result = packageList.ToArray();
            acc.PurchasedPackages = result;
            acc.Flush();
            acc.Reload();
        }
Пример #6
0
        public void AddMysteryBox(DbAccount acc, int box)
        {
            List <int> boxList = acc.PurchasedBoxes.ToList();

            boxList.Add(box);
            int[] result = boxList.ToArray();
            acc.PurchasedBoxes = result;
            acc.Flush();
            acc.Reload();
        }
Пример #7
0
        public bool ChangeGuildRank(DbAccount acc, int rank)
        {
            if (Convert.ToInt32(acc.GuildId) <= 0 || !(new Int16[] { 0, 10, 20, 30, 40 }).Any(r => r == rank))
            {
                return(false);
            }

            acc.GuildRank = rank;
            acc.Flush();
            return(true);
        }
Пример #8
0
 public void UpdateTokens(DbAccount acc, int amount)
 {
     if (amount > 0)
     {
         WaitAll(Hashes.Increment(0, acc.Key, "fortuneTokens", amount));
     }
     else
     {
         Hashes.Increment(0, acc.Key, "fortuneTokens", amount).Wait();
     }
     acc.Flush();
     acc.Reload();
 }
Пример #9
0
 public void UpdateFame(DbAccount acc, int amount)
 {
     if (amount > 0)
     {
         WaitAll(
             Hashes.Increment(0, acc.Key, "totalFame", amount),
             Hashes.Increment(0, acc.Key, "fame", amount));
     }
     else
     {
         Hashes.Increment(0, acc.Key, "fame", amount).Wait();
     }
     acc.Flush();
     acc.Reload();
 }
Пример #10
0
        public AddGuildMemberStatus AddGuildMember(DbGuild guild, DbAccount acc, bool founder = false)
        {
            if (acc == null)
            {
                return(AddGuildMemberStatus.Error);
            }

            if (acc.NameChosen == false)
            {
                return(AddGuildMemberStatus.NameNotChosen);
            }

            if (Convert.ToInt32(acc.GuildId) == guild.Id)
            {
                return(AddGuildMemberStatus.AlreadyInGuild);
            }

            if (Convert.ToInt32(acc.GuildId) > 0)
            {
                return(AddGuildMemberStatus.InAnotherGuild);
            }

            int guildSize = 100;

            if (guild.Members.Length >= guildSize)
            {
                return(AddGuildMemberStatus.GuildFull);
            }

            var members = guild.Members.ToList();

            if (members.Contains(Convert.ToInt32(acc.AccountId)))
            {
                return(AddGuildMemberStatus.IsAMember);
            }
            members.Add(Convert.ToInt32(acc.AccountId));
            guild.Members = members.ToArray();
            guild.Flush();

            acc.GuildId   = Convert.ToString(guild.Id);
            acc.GuildRank = (founder) ? 40 : 0;
            acc.Flush();

            return(AddGuildMemberStatus.OK);
        }
Пример #11
0
        public bool RenameUUID(DbAccount acc, string newUuid, string lockToken)
        {
            string p = Hashes.GetString(0, "login", acc.UUID.ToUpperInvariant()).Exec();

            using (var trans = CreateTransaction())
            {
                trans.AddCondition(Condition.KeyEquals(1, REG_LOCK, lockToken));
                trans.Hashes.Remove(0, "login", acc.UUID.ToUpperInvariant());
                trans.Hashes.Set(0, "login", newUuid.ToUpperInvariant(), p);
                if (!trans.Execute().Exec())
                {
                    return(false);
                }
            }
            acc.UUID = newUuid;
            acc.Flush();
            return(true);
        }
Пример #12
0
        public void ChangeClassAvailability(DbAccount acc, XmlData data, ushort type)
        {
            int price;

            if (acc.Credits < (price = data.ObjectDescs[type].UnlockCost))
            {
                return;
            }

            Hashes.Set(0, $"classAvailability.{acc.AccountId}", type.ToString(),
                       JsonConvert.SerializeObject(new DbClassAvailabilityEntry()
            {
                Id         = data.ObjectTypeToId[type],
                Restricted = "unrestricted"
            }));
            UpdateCredit(acc, -price);
            acc.Flush();
            acc.Reload();
        }
Пример #13
0
 public bool RenameIGN(DbAccount acc, string newName, string lockToken)
 {
     if (defaultNames.Contains(newName, StringComparer.InvariantCultureIgnoreCase))
     {
         return(false);
     }
     using (var trans = CreateTransaction())
     {
         trans.AddCondition(Condition.KeyEquals(1, NAME_LOCK, lockToken));
         Hashes.Remove(0, "names", acc.Name.ToUpperInvariant());
         Hashes.Set(0, "names", newName.ToUpperInvariant(), acc.AccountId.ToString());
         if (!trans.Execute().Exec())
         {
             return(false);
         }
     }
     acc.Name       = newName;
     acc.NameChosen = true;
     acc.Flush();
     return(true);
 }
Пример #14
0
        public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc)
        {
            acc = null;
            if (!Hashes.SetIfNotExists(0, "logins", uuid.ToUpperInvariant(), "{}").Exec())
            {
                return(RegisterStatus.UsedName);
            }

            int newAccId = (int)Strings.Increment(0, "nextAccId").Exec();

            acc = new DbAccount(this, newAccId.ToString())
            {
                AccType           = AccountType.FREE_ACCOUNT,
                UUID              = uuid,
                Name              = defaultNames[(uint)uuid.GetHashCode() % defaultNames.Length],
                Rank              = 0,
                Admin             = false,
                NameChosen        = false,
                Verified          = Settings.STARTUP.VERIFIED,
                Converted         = false,
                GuildId           = "0",
                GuildRank         = 0,
                GuildFame         = 0,
                VaultCount        = 1,
                MaxCharSlot       = Settings.STARTUP.MAX_CHAR_SLOTS,
                RegTime           = DateTime.Now,
                Guest             = isGuest,
                Fame              = Settings.STARTUP.FAME,
                TotalFame         = Settings.STARTUP.TOTAL_FAME,
                Credits           = Settings.STARTUP.GOLD,
                FortuneTokens     = Settings.STARTUP.TOKENS,
                Gifts             = new int[] { },
                PetYardType       = 1,
                IsAgeVerified     = Settings.STARTUP.IS_AGE_VERIFIED,
                OwnedSkins        = new int[] { },
                PurchasedPackages = new int[] { },
                PurchasedBoxes    = new int[] { },
                AuthToken         = GenerateRandomString(128),
                Muted             = false,
                Banned            = false,
                Locked            = new int[] { 0 },
                Ignored           = new int[] { 0 }
            };
            acc.Flush();

            var login = new DbLoginInfo(this, uuid);

            var x = new byte[0x10];

            gen.GetNonZeroBytes(x);
            string salt = Convert.ToBase64String(x);
            string hash = Convert.ToBase64String(Utils.SHA1(password + salt));

            login.HashedPassword = hash;
            login.Salt           = salt;
            login.AccountId      = acc.AccountId;
            login.Flush();

            var stats = new DbClassStats(acc);

            stats.Flush();

            var vault = new DbVault(acc);

            vault[0] = Enumerable.Repeat(-1, 8).ToArray();
            vault.Flush();

            return(RegisterStatus.OK);
        }
Пример #15
0
 public void VerifyAge(DbAccount acc)
 {
     Hashes.Set(0, acc.Key, "isAgeVerified", "1");
     acc.Flush();
     acc.Reload();
 }
Пример #16
0
 public void UnmuteAccount(DbAccount acc)
 {
     Hashes.Set(0, acc.Key, "muted", "0");
     acc.Flush();
     acc.Reload();
 }
Пример #17
0
 public void BanAccount(DbAccount acc)
 {
     Hashes.Set(0, acc.Key, "banned", "1");
     acc.Flush();
     acc.Reload();
 }