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); }
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); }
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); }
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); }
public void Update(DbAccount acc) { acc.Flush(); acc.Reload(); }
public string ResolveIgn(DbAccount acc) => Hashes.GetString(0, $"account.{acc.AccountId}", "name").Exec();
public DbDeath(DbAccount acc, int charId) { Account = acc; CharId = charId; Init(acc.Database, "death." + acc.AccountId + "." + charId); }
public DailyCalendar(DbAccount acc) { Account = acc; Init(acc.Database, "calendar." + acc.AccountId); }
public DbClassStats(DbAccount acc) { Account = acc; Init(acc.Database, "classStats." + acc.AccountId); }
public void VerifyAge(DbAccount acc) { Hashes.Set(0, acc.Key, "isAgeVerified", "1"); Update(acc); }
public void BanAccount(DbAccount acc) { Hashes.Set(0, acc.Key, "banned", "1"); Update(acc); }
public void AddChar(DbAccount acc) { acc.MaxCharSlot++; Update(acc); }
public DbClassStats ReadClassStats(DbAccount acc) => new DbClassStats(acc);
public void AddChest(DbAccount acc) { acc.VaultCount++; Update(acc); }
public bool CheckPackage(DbAccount acc, int package, int total) => acc.PurchasedPackages.Where(pack => pack == package).ToList().Count >= total;
public bool CheckMysteryBox(DbAccount acc, int box, int total) => acc.PurchasedBoxes.Where(mbox => mbox == box).ToList().Count >= total;
public void UnmuteAccount(DbAccount acc) { _db.HashSetAsync(acc.Key, "muted", "0"); Update(acc); }
public void VerifyAge(DbAccount acc) { _db.HashSet(acc.Key, "isAgeVerified", "1"); Update(acc); }
public DbVault ReadVault(DbAccount acc) => new DbVault(acc);
public void MuteAccount(DbAccount acc) { Connection.Hashes.Set(0, acc.Key, "muted", "1"); Update(acc); }
public void UnmuteAccount(DbAccount acc) { Hashes.Set(0, acc.Key, "muted", "0"); Update(acc); }
public void UpdateAccountLifetime(DbAccount account, int accountType, int amount) { throw new NotImplementedException(); }
public DbVault(DbAccount acc) { Account = acc; Init(acc.Database, "vault." + acc.AccountId); }
public int GetLockTime(DbAccount acc) => (int)Keys.TimeToLive(1, $"lock.{acc.AccountId}").Exec();
public DbClassAvailability(DbAccount acc) { Account = acc; Init(acc.Database, $"classAvailability.{acc.AccountId}"); }
public IDisposable Lock(DbAccount acc) => new l(this, acc);
internal DbChar(DbAccount acc, int charId) { Account = acc; CharId = charId; Init(acc.Database, "char." + acc.AccountId + "." + charId); }
public l(Database db, DbAccount acc) { this.db = db; this.acc = acc; lockOk = db.AcquireLock(acc); }
public DbGuild(DbAccount acc) { Id = Convert.ToInt32(acc.GuildId); Init(acc.Database, "guild." + Id); }
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); }