public DbAccount CreateGuestAccount(string uuid) { var newAccounts = _resources.Settings.Accounts; var acnt = new DbAccount(_db, 0) { UUID = uuid, Name = GuestNames[(uint)uuid.GetHashCode() % GuestNames.Length], Admin = false, NameChosen = false, Verified = false, AgeVerified = true, FirstDeath = true, GuildId = 0, GuildRank = 0, VaultCount = newAccounts.VaultCount, MaxCharSlot = 1, RegTime = DateTime.Now, Guest = true, Fame = newAccounts.Fame, TotalFame = newAccounts.Fame, Credits = newAccounts.Gold, TotalCredits = newAccounts.Gold, PassResetToken = "" }; // make sure guest have all classes if they are supposed to var stats = new DbClassStats(acnt); if (_resources.Settings.Accounts.ClassesUnlocked) { foreach (var @class in _resources.GameData.Classes.Keys) { stats.Unlock(@class); } stats.FlushAsync(); } else { _db.KeyDelete("classStats.0"); } // make sure guests have all skins if they are supposed to if (newAccounts.SkinsUnlocked) { acnt.Skins = (from skin in _resources.GameData.Skins.Values where !skin.NoSkinSelect select skin.Type).ToArray(); } return(acnt); }
public Task <bool> SaveCharacter( DbAccount acc, DbChar character, DbClassStats stats, bool lockAcc) { var trans = _db.CreateTransaction(); if (lockAcc) { trans.AddCondition(Condition.StringEqual( $"lock:{acc.AccountId}", acc.LockToken)); } character.FlushAsync(trans); stats.Update(character); stats.FlushAsync(trans); return(trans.ExecuteAsync()); }
public LoginStatus Verify(string uuid, string password, out DbAccount acc) { acc = null; //check login var info = new DbLoginInfo(_db, uuid); if (info.IsNull) { return(LoginStatus.AccountNotExists); } byte[] userPass = Utils.SHA1(password + info.Salt); if (Convert.ToBase64String(userPass) != info.HashedPassword) { return(LoginStatus.InvalidCredentials); } acc = new DbAccount(_db, info.AccountId); // make sure account has all classes if they are supposed to var stats = new DbClassStats(acc); if (_resources.Settings.Accounts.ClassesUnlocked) { foreach (var @class in _resources.GameData.Classes.Keys) { stats.Unlock(@class); } } stats.FlushAsync(); // make sure account has all skins if they are supposed to if (_resources.Settings.Accounts.SkinsUnlocked) { acc.Skins = (from skin in _resources.GameData.Skins.Values where !skin.NoSkinSelect select skin.Type).ToArray(); } return(LoginStatus.OK); }
public RegisterStatus Register(string uuid, string password, bool isGuest, out DbAccount acc) { var newAccounts = _resources.Settings.NewAccounts; acc = null; if (!_db.HashSet("logins", uuid.ToUpperInvariant(), "{}", When.NotExists)) { return(RegisterStatus.UsedName); } int newAccId = (int)_db.StringIncrement("nextAccId"); acc = new DbAccount(_db, newAccId) { UUID = uuid, Name = GuestNames[(uint)uuid.GetHashCode() % GuestNames.Length], Admin = false, NameChosen = false, FirstDeath = true, GuildId = 0, GuildRank = 0, VaultCount = newAccounts.VaultCount, MaxCharSlot = newAccounts.MaxCharSlot, RegTime = DateTime.Now, Guest = isGuest, Fame = newAccounts.Fame, TotalFame = newAccounts.Fame, Credits = newAccounts.Credits, TotalCredits = newAccounts.Credits, PassResetToken = "", LastSeen = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds }; if (newAccounts.SkinsUnlocked) { acc.Skins = (from skin in _resources.GameData.Skins.Values select skin.Type).ToArray(); } acc.FlushAsync(); DbLoginInfo login = new DbLoginInfo(_db, uuid); byte[] 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(); DbClassStats stats = new DbClassStats(acc); if (newAccounts.ClassesUnlocked) { foreach (var @class in _resources.GameData.Classes.Keys) { stats.Unlock(@class); } } stats.FlushAsync(); return(RegisterStatus.OK); }