public void FlushData() { if (Program.isBeta) { return; } KONNode node = new KONNode("LEVELING_SERVER"); node.AddValue("id", Id); if (LevelUpChannel != null) { node.AddValue("levelUpChannel", (ulong)LevelUpChannel); } node.AddValue("xpCooldown", XPCooldown); node.AddValue("xpPerLevel", XPPerLevel); node.AddValue("minXPPerMessage", MinXPPerMessage); node.AddValue("maxXPPerMessage", MaxXPPerMessage); KONNode rolesNode = new KONNode("ROLES"); foreach (KeyValuePair <int, ulong> role in RoleRewards) { KONNode roleNode = new KONNode("ROLE"); roleNode.AddValue("id", role.Value); roleNode.AddValue("level", role.Key); rolesNode.AddChild(roleNode); } node.AddChild(rolesNode); KONNode levelUpMsgNode = new KONNode("LEVEL_UP_MESSAGES"); foreach (KeyValuePair <int, string> message in LevelUpMessages) { KONNode messageNode = new KONNode("MESSAGE"); messageNode.AddValue("level", message.Key); messageNode.AddValue("message", message.Value); levelUpMsgNode.AddChild(messageNode); } node.AddChild(levelUpMsgNode); KONArray usersArray = new KONArray("USERS"); foreach (LevelingUser user in UsersByRank) { usersArray.AddItem(user.Id); } node.AddArray(usersArray); File.WriteAllText($@"{Utils.levelingDataPath}/Server_{Id}/Index.cb", SensitiveInformation.EncryptDataFile(KONWriter.Default.Write(node))); }
public static void FlushDatabase(bool flushAll = false) { if (Program.isBeta) { return; } DatabaseNode = new KONNode("DATABASE"); KONArray guildsArray = new KONArray("GUILDS"); foreach (GuildData guildData in Guilds.Values) { guildsArray.AddItem(guildData.Id); } DatabaseNode.AddArray(guildsArray); File.WriteAllText($@"{Utils.localDataPath}/Database.cb", SensitiveInformation.EncryptDataFile("//PERSISTENT\n" + KONWriter.Default.Write(DatabaseNode))); if (flushAll) { foreach (KeyValuePair <ulong, GuildData> guild in Guilds) { guild.Value.FlushData(true); } } }
public static void WriteDatabase() { if (Program.isBeta) { return; } KONNode databaseNode = new KONNode("CONVERSATION_DATABASE"); KONNode channelsNode = new KONNode("CHANNELS"); foreach (ConversationChannel channel in ConversationChannels) { KONNode channelNode = new KONNode("CHANNEL"); channelNode.AddValue("id", channel.Id); channelNode.AddValue("name", channel.Server); channelNode.AddValue("guildId", channel.GuildId); channelsNode.AddChild(channelNode); } databaseNode.AddChild(channelsNode); KONNode preVerifiedUsersNode = new KONNode("PREVERIFIED_USERS"); foreach (PreVerifiedUser user in PreVerifiedUsers.Values) { KONNode userNode = new KONNode("USER"); userNode.AddValue("id", user.Id); userNode.AddValue("messages", user.MessagesSent); userNode.AddValue("lastMessageTime", user.LastMessageSentTime.ToUnixTimeSeconds()); preVerifiedUsersNode.AddChild(userNode); } databaseNode.AddChild(preVerifiedUsersNode); KONArray acceptedUsers = new KONArray("ACCEPTED_USERS"); foreach (ulong user in AcceptedUsers) { acceptedUsers.AddItem(user); } KONArray administrators = new KONArray("ADMINISTRATORS"); foreach (ulong user in Administrators) { administrators.AddItem(user); } KONArray moderators = new KONArray("MODERATORS"); foreach (ulong user in Moderators) { moderators.AddItem(user); } KONArray bannedUsers = new KONArray("BANNED_USERS"); foreach (ulong user in BannedUsers) { bannedUsers.AddItem(user); } KONArray verifiedUsers = new KONArray("VERIFIED_USERS"); foreach (ulong user in VerifiedUsers) { verifiedUsers.AddItem(user); } databaseNode.AddArray(acceptedUsers); databaseNode.AddArray(administrators); databaseNode.AddArray(moderators); databaseNode.AddArray(bannedUsers); databaseNode.AddArray(verifiedUsers); File.WriteAllText($@"{Utils.conversationDataPath}/ConversationDatabase.cb", SensitiveInformation.EncryptDataFile(KONWriter.Default.Write(databaseNode))); }