public bool UnBanAccount(Database db, string accId) { var acc = new DbAccount(_db, accId); if (acc.Banned) { acc.Banned = false; acc.FlushAsync(); return(true); } return(false); }
public bool BanAccount(Database db, string accId) { var acc = new DbAccount(_db, accId) { Banned = true }; if (acc.IsNull || acc.AccountType >= (int)AccountType.MOD) { return(false); } acc.FlushAsync(); Update(acc); return(true); }
public bool RenameUUID(DbAccount acc, string newUuid, string lockToken) { var p = _db.HashGet("login", acc.UUID.ToUpperInvariant()); var trans = _db.CreateTransaction(); trans.AddCondition(Condition.StringEqual(REG_LOCK, lockToken)); trans.AddCondition(Condition.HashNotExists("login", newUuid.ToUpperInvariant())); trans.HashDeleteAsync("login", acc.UUID.ToUpperInvariant()); trans.HashSetAsync("login", newUuid.ToUpperInvariant(), p); if (!trans.Execute()) { return(false); } acc.UUID = newUuid; acc.FlushAsync(); return(true); }
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.FlushAsync(); acc.Reload(); }
public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc) { acc = null; if (!_db.HashSet("logins", uuid.ToUpperInvariant(), "{}", When.NotExists)) { return(RegisterStatus.UsedName); } int newAccId = (int)_db.StringIncrement("nextAccId"); acc = new DbAccount(_db, newAccId.ToString()) { AccountType = (int)AccountType.REGULAR, 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.UtcNow, 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.FlushAsync(); var login = new DbLoginInfo(_db, 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.FlushAsync(); var vault = new DbVault(acc); vault[0] = Enumerable.Repeat(-1, 8).ToArray(); vault.FlushAsync(); return(RegisterStatus.OK); }