/// <summary> /// Updates guild member's rank in the database. /// </summary> /// <param name="member"></param> public void UpdateGuildMemberRank(GuildMember member) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `guild_members` SET {0} WHERE `guildId` = @guildId AND `characterId` = @characterId", conn)) { cmd.AddParameter("@guildId", member.GuildId); cmd.AddParameter("@characterId", member.CharacterId); cmd.Set("rank", (int)member.Rank); cmd.Execute(); } }
/// <summary> /// Writes guild's leader's name and its members current ranks to database. /// </summary> /// <param name="guild"></param> public void UpdateGuildLeader(Guild guild) { using (var conn = this.Connection) using (var transaction = conn.BeginTransaction()) { using (var cmd = new UpdateCommand("UPDATE `guilds` SET {0} WHERE `guildId` = @guildId", conn, transaction)) { cmd.AddParameter("@guildId", guild.Id); cmd.Set("leaderName", guild.LeaderName); cmd.Execute(); } foreach (var member in guild.GetMembers()) { using (var cmd = new UpdateCommand("UPDATE `guild_members` SET {0} WHERE `characterId` = @characterId", conn, transaction)) { cmd.AddParameter("@characterId", member.CharacterId); cmd.Set("rank", (int)member.Rank); cmd.Execute(); } } transaction.Commit(); } }
/// <summary> /// Updates creature's online status. /// </summary> /// <param name="creatureId"></param> /// <param name="isOnline"></param> public void UpdateOnlineStatus(long creatureId, bool isOnline) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `creatures` SET {0} WHERE `creatureId` = @creatureId", conn)) { cmd.AddParameter("@creatureId", creatureId); cmd.Set("online", isOnline); cmd.Execute(); } }
/// <summary> /// Changes auth level of account. /// </summary> /// <param name="accountId"></param> /// <param name="level"></param> /// <returns></returns> public bool ChangeAuth(string accountId, int level) { using (var conn = AuraDb.Instance.Connection) using (var cmd = new UpdateCommand("UPDATE `accounts` SET {0} WHERE `accountId` = @accountId", conn)) { cmd.AddParameter("@accountId", accountId); cmd.Set("authority", level); return (cmd.Execute() > 0); } }
/// <summary> /// Changes auth level of account. /// </summary> /// <param name="accountId"></param> /// <param name="level"></param> /// <returns></returns> public bool ChangeAuth(string accountId, int level) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `accounts` SET {0} WHERE `accountId` = @accountId", conn)) { cmd.AddParameter("@accountId", accountId); cmd.Set("authority", level); return(cmd.Execute() > 0); } }
/// <summary> /// Updates guild's disbanded field in database. /// </summary> /// <param name="guild"></param> public void UpdateDisbandGuild(Guild guild) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `guilds` SET {0} WHERE `guildId` = @guildId", conn)) { cmd.AddParameter("@guildId", guild.Id); cmd.Set("disbanded", guild.Disbanded); cmd.Execute(); } }
/// <summary> /// Writes guild's points and gold to database. /// </summary> /// <param name="guild"></param> public void UpdateGuildResources(Guild guild) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `guilds` SET {0} WHERE `guildId` = @guildId", conn)) { cmd.AddParameter("@guildId", guild.Id); cmd.Set("points", guild.Points); cmd.Set("gold", guild.Gold); cmd.Execute(); } }
/// <summary> /// Writes guild's messages to database. /// </summary> /// <param name="guild"></param> public bool UpdateGuildMessages(Guild guild) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `guilds` SET {0} WHERE `guildId` = @guildId", conn)) { cmd.AddParameter("@guildId", guild.Id); cmd.Set("introMessage", guild.IntroMessage); cmd.Set("welcomeMessage", guild.WelcomeMessage); cmd.Set("leavingMessage", guild.LeavingMessage); cmd.Set("rejectionMessage", guild.RejectionMessage); return(cmd.Execute() > 0); } }
/// <summary> /// Writes guild's points and gold to database. /// </summary> /// <param name="guild"></param> public void UpdateGuildStone(Guild guild) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `guilds` SET {0} WHERE `guildId` = @guildId", conn)) { cmd.AddParameter("@guildId", guild.Id); cmd.Set("stonePropId", guild.Stone.PropId); cmd.Set("stoneRegionId", guild.Stone.RegionId); cmd.Set("stoneX", guild.Stone.X); cmd.Set("stoneY", guild.Stone.Y); cmd.Set("stoneDirection", guild.Stone.Direction); cmd.Execute(); } }
/// <summary> /// Writes guild robe information to database. /// </summary> /// <param name="guild"></param> public void UpdateGuildRobe(Guild guild) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `guilds` SET {0} WHERE `guildId` = @guildId", conn)) { cmd.AddParameter("@guildId", guild.Id); cmd.Set("hasRobe", guild.HasRobe); if (guild.HasRobe) { cmd.Set("emblemMark", guild.Robe.EmblemMark); cmd.Set("emblemOutline", guild.Robe.EmblemOutline); cmd.Set("stripes", guild.Robe.Stripes); cmd.Set("robeColor", guild.Robe.RobeColor); cmd.Set("badgeColor", guild.Robe.BadgeColor); cmd.Set("emblemMarkColor", guild.Robe.EmblemMarkColor); cmd.Set("emblemOutlineColor", guild.Robe.EmblemOutlineColor); cmd.Set("stripesColor", guild.Robe.StripesColor); } cmd.Execute(); } }
/// <summary> /// Sets read flag for given note. /// </summary> /// <param name="noteId"></param> public void SetNoteRead(long noteId) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `notes` SET {0} WHERE `noteId` = @noteId", conn)) { cmd.Set("read", true); cmd.AddParameter("@noteId", noteId); cmd.Execute(); } }
/// <summary> /// Updates deletion time for character, or deletes it. /// </summary> /// <param name="character"></param> public void UpdateDeletionTime(Character character) { using (var conn = this.Connection) { if (character.DeletionFlag == DeletionFlag.Delete) { using (var mc = new MySqlCommand("DELETE FROM `creatures` WHERE `creatureId` = @creatureId", conn)) { mc.Parameters.AddWithValue("@creatureId", character.CreatureId); mc.ExecuteNonQuery(); } } else { using (var cmd = new UpdateCommand("UPDATE `creatures` SET {0} WHERE `creatureId` = @creatureId", conn)) { cmd.AddParameter("@creatureId", character.CreatureId); cmd.Set("deletionTime", character.DeletionTime); cmd.Execute(); } } } }
/// <summary> /// Updates contact's last login time. /// </summary> /// <param name="contact"></param> private void UpdateLastLogin(Contact contact) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `contacts` SET {0} WHERE `contactId` = @contactId", conn)) { cmd.AddParameter("@contactId", contact.Id); cmd.Set("lastLogin", contact.LastLogin); cmd.Execute(); } }
/// <summary> /// Updates friendship status for contact 1. /// </summary> /// <param name="contactId"></param> /// <returns></returns> public void SetFriendshipStatusOneSided(int contactId1, int contactId2, FriendshipStatus status) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `friends` SET {0} WHERE (`userId1` = @userId1 AND `userId2` = @userId2)", conn)) { cmd.Set("status", (byte)status); cmd.AddParameter("@userId1", contactId1); cmd.AddParameter("@userId2", contactId2); cmd.Execute(); } }
/// <summary> /// Deletes group from database and moves friends in that group to ETC. /// </summary> /// <param name="user"></param> /// <param name="groupId"></param> public void DeleteGroup(User user, int groupId) { using (var conn = this.Connection) { // Move friends using (var cmd = new UpdateCommand("UPDATE `friends` SET {0} WHERE `userId1` = @userId1 AND `groupId` = @oldGroupId", conn)) { cmd.Set("groupId", -1); cmd.AddParameter("@userId1", user.Id); cmd.AddParameter("@oldGroupId", groupId); cmd.Execute(); } // Delete group using (var mc = new MySqlCommand("DELETE FROM `groups` WHERE `contactId` = @contactId AND `groupId` = @groupId", conn)) { mc.Parameters.AddWithValue("@contactId", user.Id); mc.Parameters.AddWithValue("@groupId", groupId); mc.ExecuteNonQuery(); } } }
/// <summary> /// Changes group the friend is in in the database. /// </summary> /// <param name="user"></param> /// <param name="friendContactId"></param> /// <param name="groupId"></param> public void ChangeGroup(User user, int friendContactId, int groupId) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `friends` SET {0} WHERE `userId1` = @userId1 AND `userId2` = @userId2", conn)) { cmd.Set("groupId", groupId); cmd.AddParameter("@userId1", user.Id); cmd.AddParameter("@userId2", friendContactId); cmd.Execute(); } }
/// <summary> /// Renames group in database. /// </summary> /// <param name="user"></param> /// <param name="groupId"></param> /// <param name="groupName"></param> public void RenameGroup(User user, int groupId, string groupName) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `groups` SET {0} WHERE `groupId` = @groupId AND `contactId` = @contactId", conn)) { cmd.Set("name", groupName); cmd.AddParameter("@groupId", groupId); cmd.AddParameter("@contactId", user.Id); cmd.Execute(); } }
/// <summary> /// Saves user's options to database. /// </summary> /// <param name="user"></param> public void SaveOptions(User user) { using (var conn = this.Connection) using (var cmd = new UpdateCommand("UPDATE `contacts` SET {0} WHERE `contactId` = @contactId", conn)) { cmd.Set("status", (byte)user.Status); cmd.Set("chatOptions", (uint)user.ChatOptions); cmd.Set("nickname", user.Nickname ?? ""); cmd.AddParameter("@contactId", user.Id); cmd.Execute(); } }