public void IgnoreAccount(DbAccount acc, int lockId) { try { List <int> x = acc.Ignored.ToList(); if (!x.Contains(lockId)) { x.Add(lockId); int[] result = x.ToArray(); acc.Ignored = result; acc.Flush(); acc.Reload(); } else { x.Remove(lockId); int[] result = x.ToArray(); acc.Ignored = result; acc.Flush(); acc.Reload(); } } catch { List <int> x = new List <int>(); x.Add(lockId); int[] result = x.ToArray(); acc.Ignored = result; acc.Flush(); acc.Reload(); } }
public bool RemoveFromGuild(DbAccount acc) { var guild = GetGuild(Convert.ToInt32(acc.GuildId)); if (guild == null) { return(false); } List <int> members; members = guild.Members.ToList(); if (members.Contains(Convert.ToInt32(acc.AccountId))) { members.Remove(Convert.ToInt32(acc.AccountId)); guild.Members = members.ToArray(); guild.Flush(); } var idBuff = BitConverter.GetBytes(guild.Id); if (members.Count <= 0) { using (var t = CreateTransaction()) t.Hashes.Remove(0, "guilds", guild.Name.ToUpperInvariant()); } acc.GuildId = "-1"; acc.GuildRank = -1; acc.GuildFame = -1; acc.Flush(); return(true); }
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 void AddSkin(DbAccount acc, int skin) { List <int> skinList = acc.OwnedSkins.ToList(); skinList.Add(skin); int[] result = skinList.ToArray(); acc.OwnedSkins = result; acc.Flush(); acc.Reload(); }
public void AddPackage(DbAccount acc, int package) { List <int> packageList = acc.PurchasedPackages.ToList(); packageList.Add(package); int[] result = packageList.ToArray(); acc.PurchasedPackages = result; acc.Flush(); acc.Reload(); }
public void AddMysteryBox(DbAccount acc, int box) { List <int> boxList = acc.PurchasedBoxes.ToList(); boxList.Add(box); int[] result = boxList.ToArray(); acc.PurchasedBoxes = result; acc.Flush(); acc.Reload(); }
public bool ChangeGuildRank(DbAccount acc, int rank) { if (Convert.ToInt32(acc.GuildId) <= 0 || !(new Int16[] { 0, 10, 20, 30, 40 }).Any(r => r == rank)) { return(false); } acc.GuildRank = rank; acc.Flush(); return(true); }
public void UpdateTokens(DbAccount acc, int amount) { if (amount > 0) { WaitAll(Hashes.Increment(0, acc.Key, "fortuneTokens", amount)); } else { Hashes.Increment(0, acc.Key, "fortuneTokens", amount).Wait(); } acc.Flush(); acc.Reload(); }
public void UpdateFame(DbAccount acc, int amount) { if (amount > 0) { WaitAll( Hashes.Increment(0, acc.Key, "totalFame", amount), Hashes.Increment(0, acc.Key, "fame", amount)); } else { Hashes.Increment(0, acc.Key, "fame", amount).Wait(); } acc.Flush(); acc.Reload(); }
public AddGuildMemberStatus AddGuildMember(DbGuild guild, DbAccount acc, bool founder = false) { if (acc == null) { return(AddGuildMemberStatus.Error); } if (acc.NameChosen == false) { return(AddGuildMemberStatus.NameNotChosen); } if (Convert.ToInt32(acc.GuildId) == guild.Id) { return(AddGuildMemberStatus.AlreadyInGuild); } if (Convert.ToInt32(acc.GuildId) > 0) { return(AddGuildMemberStatus.InAnotherGuild); } int guildSize = 100; if (guild.Members.Length >= guildSize) { return(AddGuildMemberStatus.GuildFull); } var members = guild.Members.ToList(); if (members.Contains(Convert.ToInt32(acc.AccountId))) { return(AddGuildMemberStatus.IsAMember); } members.Add(Convert.ToInt32(acc.AccountId)); guild.Members = members.ToArray(); guild.Flush(); acc.GuildId = Convert.ToString(guild.Id); acc.GuildRank = (founder) ? 40 : 0; acc.Flush(); return(AddGuildMemberStatus.OK); }
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 void ChangeClassAvailability(DbAccount acc, XmlData data, ushort type) { int price; if (acc.Credits < (price = data.ObjectDescs[type].UnlockCost)) { return; } Hashes.Set(0, $"classAvailability.{acc.AccountId}", type.ToString(), JsonConvert.SerializeObject(new DbClassAvailabilityEntry() { Id = data.ObjectTypeToId[type], Restricted = "unrestricted" })); UpdateCredit(acc, -price); acc.Flush(); acc.Reload(); }
public bool RenameIGN(DbAccount acc, string newName, string lockToken) { if (defaultNames.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 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); }
public void VerifyAge(DbAccount acc) { Hashes.Set(0, acc.Key, "isAgeVerified", "1"); acc.Flush(); acc.Reload(); }
public void UnmuteAccount(DbAccount acc) { Hashes.Set(0, acc.Key, "muted", "0"); acc.Flush(); acc.Reload(); }
public void BanAccount(DbAccount acc) { Hashes.Set(0, acc.Key, "banned", "1"); acc.Flush(); acc.Reload(); }