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); }
public bool RenameIGN(DbAccount acc, string newName, string lockToken) { if (Names.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); }
public void Update(DbAccount acc) { acc.Flush(); acc.Reload(); }
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); }