Пример #1
0
        public void UpdateFame(DbAccount acc, double amount, bool fromDeath = false)
        {
            var trans = _db.CreateTransaction();

            trans.HashIncrementAsync(acc.Key, "fame", amount);

            if (fromDeath)
            {
                trans.HashIncrementAsync(acc.Key, "totalFame", amount);
            }

            trans.ExecuteAsync();

            acc.Fame += amount;

            if (fromDeath)
            {
                acc.TotalFame += amount;
            }

            Update(acc);
        }
Пример #2
0
        public bool SaveCharacter(DbAccount acc, DbChar character, bool lockAcc)
        {
            try
            {
                using (var trans = Connection.CreateTransaction())
                {
                    if (lockAcc)
                    {
                        trans.AddCondition(Condition.KeyEquals(1,
                                                               $"lock.{acc.AccountId}", acc.LockToken));
                    }
                    character.Flush(trans);
                    var stats = new DbClassStats(acc);
                    stats.Update(character);
                    stats.Flush(trans);
                    return(trans.Execute().Exec());
                }
            }
            catch { }

            return(false);
        }
Пример #3
0
        public LoginStatus Verify(string uuid, string password, out DbAccount acc)
        {
            acc = null;

            var info = new DbLoginInfo(_db, uuid);

            if (info.IsNull)
            {
                return(LoginStatus.AccountNotExists);
            }

            var userPass = Utils.SHA1(password + info.Salt);

            if (Convert.ToBase64String(userPass) != info.HashedPassword)
            {
                return(LoginStatus.InvalidCredentials);
            }

            acc = new DbAccount(_db, info.AccountId);

            return(LoginStatus.OK);
        }
Пример #4
0
        public bool RenameIGN(DbAccount acc, string newName, string lockToken)
        {
            if (Names.Contains(newName, StringComparer.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            var trans = _db.CreateTransaction();

            trans.AddCondition(Condition.StringEqual(NAME_LOCK, lockToken));
            trans.HashDeleteAsync("names", acc.Name.ToUpperInvariant());
            trans.HashSetAsync("names", newName.ToUpperInvariant(), acc.AccountId.ToString());

            if (!trans.Execute())
            {
                return(false);
            }

            acc.Name       = newName;
            acc.NameChosen = true;
            acc.FlushAsync();
            return(true);
        }
Пример #5
0
 public void Update(DbAccount acc)
 {
     acc.Flush();
     acc.Reload();
 }
Пример #6
0
 public string ResolveIgn(DbAccount acc) => Hashes.GetString(0, $"account.{acc.AccountId}", "name").Exec();
Пример #7
0
 public DbDeath(DbAccount acc, int charId)
 {
     Account = acc;
     CharId  = charId;
     Init(acc.Database, "death." + acc.AccountId + "." + charId);
 }
Пример #8
0
 public DailyCalendar(DbAccount acc)
 {
     Account = acc;
     Init(acc.Database, "calendar." + acc.AccountId);
 }
Пример #9
0
 public DbClassStats(DbAccount acc)
 {
     Account = acc;
     Init(acc.Database, "classStats." + acc.AccountId);
 }
Пример #10
0
 public void VerifyAge(DbAccount acc)
 {
     Hashes.Set(0, acc.Key, "isAgeVerified", "1");
     Update(acc);
 }
Пример #11
0
 public void BanAccount(DbAccount acc)
 {
     Hashes.Set(0, acc.Key, "banned", "1");
     Update(acc);
 }
Пример #12
0
 public void AddChar(DbAccount acc)
 {
     acc.MaxCharSlot++;
     Update(acc);
 }
Пример #13
0
 public DbClassStats ReadClassStats(DbAccount acc) => new DbClassStats(acc);
Пример #14
0
 public void AddChest(DbAccount acc)
 {
     acc.VaultCount++;
     Update(acc);
 }
Пример #15
0
 public bool CheckPackage(DbAccount acc, int package, int total)
 => acc.PurchasedPackages.Where(pack => pack == package).ToList().Count >= total;
Пример #16
0
 public bool CheckMysteryBox(DbAccount acc, int box, int total)
 => acc.PurchasedBoxes.Where(mbox => mbox == box).ToList().Count >= total;
Пример #17
0
        public void UnmuteAccount(DbAccount acc)
        {
            _db.HashSetAsync(acc.Key, "muted", "0");

            Update(acc);
        }
Пример #18
0
        public void VerifyAge(DbAccount acc)
        {
            _db.HashSet(acc.Key, "isAgeVerified", "1");

            Update(acc);
        }
Пример #19
0
 public DbVault ReadVault(DbAccount acc) => new DbVault(acc);
Пример #20
0
 public void MuteAccount(DbAccount acc)
 {
     Connection.Hashes.Set(0, acc.Key, "muted", "1");
     Update(acc);
 }
Пример #21
0
 public void UnmuteAccount(DbAccount acc)
 {
     Hashes.Set(0, acc.Key, "muted", "0");
     Update(acc);
 }
Пример #22
0
 public void UpdateAccountLifetime(DbAccount account, int accountType, int amount)
 {
     throw new NotImplementedException();
 }
Пример #23
0
 public DbVault(DbAccount acc)
 {
     Account = acc;
     Init(acc.Database, "vault." + acc.AccountId);
 }
Пример #24
0
 public int GetLockTime(DbAccount acc) => (int)Keys.TimeToLive(1, $"lock.{acc.AccountId}").Exec();
Пример #25
0
 public DbClassAvailability(DbAccount acc)
 {
     Account = acc;
     Init(acc.Database, $"classAvailability.{acc.AccountId}");
 }
Пример #26
0
 public IDisposable Lock(DbAccount acc) => new l(this, acc);
Пример #27
0
 internal DbChar(DbAccount acc, int charId)
 {
     Account = acc;
     CharId  = charId;
     Init(acc.Database, "char." + acc.AccountId + "." + charId);
 }
Пример #28
0
 public l(Database db, DbAccount acc)
 {
     this.db  = db;
     this.acc = acc;
     lockOk   = db.AcquireLock(acc);
 }
Пример #29
0
 public DbGuild(DbAccount acc)
 {
     Id = Convert.ToInt32(acc.GuildId);
     Init(acc.Database, "guild." + Id);
 }
Пример #30
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())
            {
                AccountType       = (int)AccountType.FREE_ACCOUNT,
                AccountLifetime   = DateTime.MinValue,
                UUID              = uuid,
                Name              = Names[(uint)uuid.GetHashCode() % Names.Length],
                Admin             = false,
                NameChosen        = false,
                Verified          = Settings.STARTUP.VERIFIED,
                Converted         = false,
                GuildId           = "-1",
                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,
                EmpiresCoin       = Settings.STARTUP.EMPIRES_COIN,
                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);
        }