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); }
public bool SaveCharacter(DbAccount acc, DbChar character, bool lockAcc) { using (var trans = 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()); } }
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); }