public void StoreInfo(string pIP, byte[] pMachineID, int pCharacterID, byte pWorldID) { using (InsertQueryBuilder iqb = new InsertQueryBuilder("session_restarts")) { byte[] encoded_machineid = new byte[16]; for (int i = 0; i < 16; i++) { encoded_machineid[i] = (byte)(pMachineID[i] ^ (byte)(pCharacterID * pWorldID)); } iqb.AddColumn("machine_id"); iqb.AddColumn("ip", true); iqb.AddColumns(true, "character_id", "world_id"); iqb.OnDuplicateUpdate = true; iqb.AddRow(encoded_machineid, pIP, pCharacterID, pWorldID); iqb.RunQuery(); } Cache.Add(new RestartInfo { CharacterID = pCharacterID, IP = pIP, WorldID = pWorldID, MachineID = pMachineID }); }
public void Save(byte pWorldID) { pWorldID = GameHelper.GetAllianceWorldID(pWorldID); using (InsertQueryBuilder allianceTable = new InsertQueryBuilder("alliances")) { allianceTable.OnDuplicateUpdate = true; allianceTable.AddColumn("id", false); allianceTable.AddColumn("world_id", true); allianceTable.AddColumn("name", true); allianceTable.AddColumn("notice", true); allianceTable.AddColumn("rank1", true); allianceTable.AddColumn("rank2", true); allianceTable.AddColumn("rank3", true); allianceTable.AddColumn("rank4", true); allianceTable.AddColumn("rank5", true); allianceTable.AddColumn("capacity", true); allianceTable.AddRow(ID, pWorldID, Name, Notice, Ranks[0], Ranks[1], Ranks[2], Ranks[3] == "" ? null : Ranks[3], Ranks[4] == "" ? null : Ranks[4], Capacity ); allianceTable.RunQuery(); } }
public static void SaveServerIP(string pIP, ushort pPort, byte pWorldID, byte pChannelID) { using (InsertQueryBuilder iqb = new InsertQueryBuilder("server_ips")) { iqb.OnDuplicateUpdate = true; iqb.AddColumns(false, "ip", "port"); iqb.AddColumns(true, "world_id", "channel_id"); iqb.AddRow(pIP, pPort, pWorldID, pChannelID); iqb.RunQuery(); } }
public void Save(bool pReset, bool pClean = true) { if (IsFake) { return; } Logger_WriteLine("Trying to save..."); if (_exporter != null) { // Try to get logfile ID from DB if (!Directory.Exists("sessions")) { Directory.CreateDirectory("sessions"); } string filename = "sessions/Savefile_"; int packets = _exporter.GetSize(); try { using (InsertQueryBuilder iqb = new InsertQueryBuilder("session_logfiles")) { iqb.AddColumns(false, "id", "information", "at"); iqb.AddRow(null, packets + " > " + LogFilename, new MySQL_Connection.NowType()); iqb.RunQuery(); filename += MySQL_Connection.Instance.GetLastInsertId(); } } catch { filename += "NOMYSQL_" + MasterThread.CurrentDate.ToFileTime(); } filename += ".msb"; Logger_WriteLine("Saving packets to '{0}' ({1} packets logged)", filename, _exporter.GetSize()); _exporter.Save(filename, ServerMapleInfo.VERSION, base.HostEndPoint, base.ClientEndPoint); if (pReset) { _exporter = new MSBExporter(); } else if (pClean) { _exporter = null; } } }
public static void SeePlayer(int pCharacterID, string pName, byte pWorld, byte pLevel, string pGuild, int pMapID, int pSeenBy) { using (InsertQueryBuilder characterViewsTable = new InsertQueryBuilder("character_views")) { characterViewsTable.OnDuplicateUpdate = true; characterViewsTable.AddColumn("character_id", false); characterViewsTable.AddColumn("world_id", true); characterViewsTable.AddColumn("name", true); characterViewsTable.AddColumn("level", true); characterViewsTable.AddColumn("guild", true); characterViewsTable.AddColumn("mapid", true); characterViewsTable.AddColumn("last_seen_when", true); characterViewsTable.AddColumn("last_seen_by", true); characterViewsTable.AddRow(pCharacterID, pWorld, pName, pLevel, pGuild == "" ? null : pGuild, pMapID, new MySQL_Connection.NowType(), pSeenBy); characterViewsTable.RunQuery(); } }
public virtual void HandleFamiliarList(ClientConnection pConnection, MaplePacket pPacket) { using (InsertQueryBuilder familiars = new InsertQueryBuilder("familiars")) { familiars.OnDuplicateUpdate = true; familiars.AddColumn("character_id"); familiars.AddColumn("mobid"); familiars.AddColumns(true, "name", "fitality_cur", "fitality_max", "starttime", "endtime", "unktime" ); for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); // Weird id? int mobid = pPacket.ReadInt(); string name = pPacket.ReadString(13); byte currentfit = pPacket.ReadByte(); byte maxfit = pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadByte(); DateTime starttime = DateTime.FromFileTime(pPacket.ReadLong()); DateTime unktime = DateTime.FromFileTime(pPacket.ReadLong()); DateTime endtime = DateTime.FromFileTime(pPacket.ReadLong()); pPacket.ReadByte(); pPacket.ReadByte(); familiars.AddRow( pConnection.CharacterInternalID, mobid, name, currentfit, maxfit, starttime, endtime, unktime ); } familiars.RunQuery(); } }
public void Save(byte pWorldID) { pWorldID = GameHelper.GetAllianceWorldID(pWorldID); using (InsertQueryBuilder guildTable = new InsertQueryBuilder("guilds")) { guildTable.OnDuplicateUpdate = true; guildTable.AddColumn("id", false); guildTable.AddColumn("world_id", true); guildTable.AddColumn("name", true); guildTable.AddColumn("notice", true); guildTable.AddColumn("rank1", true); guildTable.AddColumn("rank2", true); guildTable.AddColumn("rank3", true); guildTable.AddColumn("rank4", true); guildTable.AddColumn("rank5", true); guildTable.AddColumn("capacity", true); guildTable.AddColumn("emblem_bg", true); guildTable.AddColumn("emblem_bg_color", true); guildTable.AddColumn("emblem_fg", true); guildTable.AddColumn("emblem_fg_color", true); guildTable.AddColumn("points", true); guildTable.AddColumn("alliance_id", true); guildTable.AddRow( ID, pWorldID, Name, Notice, Ranks[0], Ranks[1], Ranks[2], Ranks[3] == "" ? null : Ranks[3], Ranks[4] == "" ? null : Ranks[4], Capacity, Background, BackgroundColor, Foreground, ForegroundColor, Points, AllianceID ); guildTable.RunQuery(); } // Delete members first MySQL_Connection.Instance.RunQuery("DELETE FROM guild_members WHERE guild_id = " + ID); using (InsertQueryBuilder guildMembersTable = new InsertQueryBuilder("guild_members")) { guildMembersTable.OnDuplicateUpdate = true; guildMembersTable.AddColumn("guild_id", true); guildMembersTable.AddColumn("world_id", true); guildMembersTable.AddColumn("character_id", false); // Switching guild huh? guildMembersTable.AddColumn("rank", true); guildMembersTable.AddColumn("contribution", true); foreach (var member in Members) { guildMembersTable.AddRow( ID, pWorldID, member.CharacterID, member.Rank, member.Contribution ); } if (guildMembersTable.RowCount > 0) { MySQL_Connection.Instance.RunQuery(guildMembersTable.ToString()); } } using (InsertQueryBuilder guildSkillsTable = new InsertQueryBuilder("guild_skills")) { guildSkillsTable.OnDuplicateUpdate = true; guildSkillsTable.AddColumn("guild_id", false); guildSkillsTable.AddColumn("world_id", true); guildSkillsTable.AddColumn("skill_id", false); guildSkillsTable.AddColumn("level", true); guildSkillsTable.AddColumn("bought_by", true); guildSkillsTable.AddColumn("bought_at", true); guildSkillsTable.AddColumn("unk", true); foreach (var skill in Skills) { guildSkillsTable.AddRow( ID, pWorldID, skill.SkillID, skill.Level, skill.BoughtBy, skill.BoughtAt, skill.Unknown ); } if (guildSkillsTable.RowCount > 0) { MySQL_Connection.Instance.RunQuery(guildSkillsTable.ToString()); } } }
public void Save(bool pReset, bool pClean = true) { if (IsFake) return; Logger_WriteLine("Trying to save..."); if (_exporter != null) { // Try to get logfile ID from DB if (!Directory.Exists("sessions")) Directory.CreateDirectory("sessions"); string filename = "sessions/Savefile_"; int packets = _exporter.GetSize(); try { using (InsertQueryBuilder iqb = new InsertQueryBuilder("session_logfiles")) { iqb.AddColumns(false, "id", "information", "at"); iqb.AddRow(null, packets + " > " + LogFilename, new MySQL_Connection.NowType()); iqb.RunQuery(); filename += MySQL_Connection.Instance.GetLastInsertId(); } } catch { filename += "NOMYSQL_" + MasterThread.CurrentDate.ToFileTime(); } filename += ".msb"; Logger_WriteLine("Saving packets to '{0}' ({1} packets logged)", filename, _exporter.GetSize()); _exporter.Save(filename, ServerMapleInfo.VERSION, base.HostEndPoint, base.ClientEndPoint); if (pReset) _exporter = new MSBExporter(); else if (pClean) _exporter = null; } }
public virtual void HandleInventoryUpdate(ClientConnection pConnection, MaplePacket pPacket) { CharacterInventory inventory = pConnection.CharData.Inventory; byte type1 = pPacket.ReadByte(); byte items = pPacket.ReadByte(); byte type3 = pPacket.ReadByte(); if (type3 == 0) // Add or update item { for (var amnt = 0; amnt < items; amnt++) { byte type4 = pPacket.ReadByte(); byte inv = pPacket.ReadByte(); short slot = pPacket.ReadShort(); inv -= 1; if (type4 == 0) // New Item { ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket); if (inv == 0) { // Equip byte internalInventory = CharacterInventory.GetEquipInventoryFromSlot(slot); slot = CharacterInventory.CorrectEquipSlot(internalInventory, slot); if (!inventory.EquipmentItems[internalInventory].ContainsKey(slot)) inventory.EquipmentItems[internalInventory].Add(slot, item as ItemEquip); else inventory.EquipmentItems[internalInventory][slot] = item as ItemEquip; } else { if (!inventory.InventoryItems[inv - 1].ContainsKey((byte)slot)) inventory.InventoryItems[inv - 1].Add((byte)slot, item); else inventory.InventoryItems[inv - 1][(byte)slot] = item; } using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) { itemsTable.OnDuplicateUpdate = true; Queries.SaveItem(pConnection, inv, slot, item, itemsTable); itemsTable.RunQuery(); } if (item is ItemPet) { var pet = item as ItemPet; using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { petTable.OnDuplicateUpdate = true; Queries.SavePet(pConnection.CharacterInternalID, pet, petTable); petTable.RunQuery(); } } } else if (type4 == 1) // Update amount { short amount = pPacket.ReadShort(); if (inv == 0) { pConnection.Logger_WriteLine("WUTWUT"); // Should _never_ happen continue; } ItemBase item = inventory.InventoryItems[inv - 1][(byte)slot]; item.Amount = amount; AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, inv, slot, item.GetChecksum()); using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("amount", amount); itemTable.SetColumn("checksum", item.GetChecksum()); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slot); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } else if (type4 == 2) // Swap { short slotfrom = slot; short slotto = pPacket.ReadShort(); bool founditem = false; if (inv == 0) { // Equips! byte internalInventoryFrom = CharacterInventory.GetEquipInventoryFromSlot(slotfrom); byte internalInventoryTo = CharacterInventory.GetEquipInventoryFromSlot(slotto); slotfrom = CharacterInventory.CorrectEquipSlot(internalInventoryFrom, slotfrom); slotto = CharacterInventory.CorrectEquipSlot(internalInventoryTo, slotto); // Switch Equips ItemEquip item = inventory.EquipmentItems[internalInventoryFrom][slotfrom]; if (inventory.EquipmentItems[internalInventoryTo].ContainsKey(slotto)) { inventory.EquipmentItems[internalInventoryFrom][slotfrom] = inventory.EquipmentItems[internalInventoryTo][slotto]; inventory.EquipmentItems[internalInventoryTo].Remove(slotto); // Remove item founditem = true; } else { inventory.EquipmentItems[internalInventoryFrom].Remove(slotfrom); } inventory.EquipmentItems[internalInventoryTo].Add(slotto, item); } else { // Switch Items ItemBase item = inventory.InventoryItems[inv - 1][(byte)slotfrom]; if (inventory.InventoryItems[inv - 1].ContainsKey((byte)slotto)) { inventory.InventoryItems[inv - 1][(byte)slotfrom] = inventory.InventoryItems[inv - 1][(byte)slotto]; inventory.InventoryItems[inv - 1].Remove((byte)slotto); // Remove item founditem = true; } else { inventory.InventoryItems[inv - 1].Remove((byte)slotfrom); } inventory.InventoryItems[inv - 1].Add((byte)slotto, item); } if (founditem) // New slot contained item { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slotto); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotto); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } if (founditem) // Fix other slot { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } } else if (type4 == 3) { // Drop/delete item. if (inv == 0) { // Equips! byte internalInventory = CharacterInventory.GetEquipInventoryFromSlot(slot); slot = CharacterInventory.CorrectEquipSlot(internalInventory, slot); if (inventory.EquipmentItems[internalInventory].ContainsKey(slot)) { inventory.EquipmentItems[internalInventory].Remove(slot); AccountDataCache.Instance.DeleteItemChecksum(pConnection, 0, slot); } else pConnection.Logger_WriteLine("!!! Could not find item @ {0} {1}", inv, slot); } else { if (inventory.InventoryItems[inv - 1].ContainsKey((byte)slot)) { inventory.InventoryItems[inv - 1].Remove((byte)slot); AccountDataCache.Instance.DeleteItemChecksum(pConnection, (ushort)(inv - 1), slot); } else pConnection.Logger_WriteLine("!!! Could not find item @ {0} {1}", inv, slot); } using (DeleteQueryBuilder itemTable = new DeleteQueryBuilder("items")) { itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slot); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); itemTable.RunQuery(); } } else if (type4 == 4) { pPacket.ReadLong(); // Unknown..? } else if (type4 == 5) { // 'Swap' items from and to bags inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); short to = pPacket.ReadShort(); byte slotto = (byte)(to % 100); byte bagto = (byte)(to / 100); slotfrom -= 1; slotto -= 1; if (bagto == 0) bagto = 255; else bagto -= 1; if (bagfrom == 0) bagfrom = 255; else bagfrom -= 1; ushort invto = bagto == 255 ? inv : GameHelper.GetBagID(bagto, inv); ushort invfrom = bagfrom == 255 ? inv : GameHelper.GetBagID(bagfrom, inv); if ( (bagfrom != 255 && bagto != 255) || (bagfrom == bagto) || // Check if the item is being moved to itself or something (bagfrom == 255 && !inventory.InventoryItems[inv].ContainsKey(slotfrom)) || (bagfrom != 255 && (!inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems[invfrom].Items.ContainsKey(slotfrom))) || (bagto != 255 && !inventory.BagItems.ContainsKey(invto)) // Only check if bag exists ) { pConnection.Logger_WriteLine("Invalid item movement in bag !!!"); continue; } bool founditem = false; if (bagfrom == 255) { // Move to bag ItemBase ib = inventory.InventoryItems[inv][slotfrom]; if (inventory.BagItems[invto].Items.ContainsKey(slotto)) { inventory.InventoryItems[inv][slotfrom] = inventory.BagItems[invto].Items[slotto]; inventory.BagItems[invto].Items.Remove(slotto); founditem = true; } inventory.BagItems[invto].Items.Add(slotto, ib); } else { // Move to normal slot ItemBase ib = inventory.BagItems[invfrom].Items[slotfrom]; if (inventory.InventoryItems[inv].ContainsKey(slotto)) { inventory.BagItems[invfrom].Items[slotfrom] = inventory.InventoryItems[inv][slotto]; inventory.InventoryItems[inv].Remove(slotto); } inventory.InventoryItems[inv].Add(slotto, ib); using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) { itemsTable.OnDuplicateUpdate = true; Queries.SaveItem(pConnection, inv, slot, ib, itemsTable); itemsTable.RunQuery(); } } /* * Item A: item being used to move/swap | inv 3, slot 21 (Etc) | slotfrom, invfrom * Item B: item that is being swapped with A | inv 11, slot 3 (Bag 2) | slotto, invto * * Move B to a temp slot, to the new inventory: inv 11 -> inv 3, slot 3 -> slot 3021 * Move A to B: inv 3 -> inv 11, slot 21 -> slot 3 * Move B to A: slot 3021 -> slot 21 * */ if (founditem) // New slot contained item { // Temporary moving item using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom + 3000); itemTable.SetColumn("inventory", invfrom); itemTable.SetWhereColumn("inventory", invto); itemTable.SetWhereColumn("slot", slotto); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotto); itemTable.SetColumn("inventory", invto); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } if (founditem) // Fix other slot { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } } else if (type4 == 6) { // Update bag item amount inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); short amount = pPacket.ReadShort(); slotfrom -= 1; if (bagfrom == 0) { pConnection.Logger_WriteLine("Invalid item bag!"); continue; } else bagfrom -= 1; ushort invfrom = GameHelper.GetBagID(bagfrom, inv); if ( !inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems[invfrom].Items.ContainsKey(slotfrom) ) { pConnection.Logger_WriteLine("Invalid item movement in bag (item did not exist)!!!"); continue; } ItemBase item = inventory.BagItems[invfrom].Items[slotfrom]; item.Amount = amount; AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, inv, slot, item.GetChecksum()); using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("amount", amount); itemTable.SetColumn("checksum", item.GetChecksum()); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slot); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } else if (type4 == 7) { // Delete/drop bag item D: inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); slotfrom -= 1; bagfrom -= 1; ushort invfrom = GameHelper.GetBagID(bagfrom, inv); using (DeleteQueryBuilder itemTable = new DeleteQueryBuilder("items")) { itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } else if (type4 == 8) { // Swap/move item in bags inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); short to = pPacket.ReadShort(); byte slotto = (byte)(to % 100); byte bagto = (byte)(to / 100); slotfrom -= 1; slotto -= 1; bagto -= 1; bagfrom -= 1; ushort invto = GameHelper.GetBagID(bagto, inv); ushort invfrom = GameHelper.GetBagID(bagfrom, inv); if (!inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems.ContainsKey(invto)) { pConnection.Logger_WriteLine("Invalid item movement in bag"); continue; } if (!inventory.BagItems[invfrom].Items.ContainsKey(slotfrom)) { pConnection.Logger_WriteLine("Invalid item movement in bag (item not found)"); continue; } ItemBase item = inventory.BagItems[invfrom].Items[slotfrom]; bool founditem = false; if (inventory.BagItems[invto].Items.ContainsKey(slotto)) { // Swap inventory.BagItems[invfrom].Items[slotfrom] = inventory.BagItems[invto].Items[slotto]; inventory.BagItems[invto].Items.Remove(slotto); // Delete item founditem = true; } inventory.BagItems[invto].Items.Add(slotto, item); if (founditem) // New slot contained item { // Temporary moving item using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom + 3000); itemTable.SetColumn("inventory", invfrom); itemTable.SetWhereColumn("inventory", invto); itemTable.SetWhereColumn("slot", slotto); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotto); itemTable.SetColumn("inventory", invto); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } if (founditem) // Fix other slot { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } } else if (type4 == 9) { // Add item directly to bag inv -= 1; ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket); short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); slotfrom -= 1; bagfrom -= 1; ushort invfrom = GameHelper.GetBagID(bagfrom, inv); if (!inventory.BagItems.ContainsKey(invfrom)) continue; inventory.BagItems[invfrom].Items[slotfrom] = item; using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) { itemsTable.OnDuplicateUpdate = true; Queries.SaveItem(pConnection, invfrom, slotfrom, item, itemsTable); itemsTable.RunQuery(); } if (item is ItemPet) { var pet = item as ItemPet; using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { petTable.OnDuplicateUpdate = true; Queries.SavePet(pConnection.CharacterInternalID, pet, petTable); petTable.RunQuery(); } } } else if (type4 == 10) { pConnection.Logger_WriteLine("Player probably removed some bag item... O.o?"); } } } pConnection.SendTimeUpdate(); }
public virtual void HandleAbilityInfoUpdate(ClientConnection pConnection, MaplePacket pPacket) { pPacket.ReadByte(); // Unlock if (pPacket.ReadBool() == false) return; var stat = new Tuple<byte, int, byte>((byte)pPacket.ReadShort(), pPacket.ReadInt(), (byte)pPacket.ReadShort()); pPacket.ReadShort(); using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities")) { table.OnDuplicateUpdate = true; table.AddColumn("character_id"); table.AddColumn("id"); table.AddColumn("skill_id", true); table.AddColumn("level", true); table.AddRow( pConnection.CharacterInternalID, stat.Item1, stat.Item2, stat.Item3 ); table.RunQuery(); } }
public virtual void HandleBuddyList(ClientConnection pConnection, MaplePacket pPacket) { byte mode = pPacket.ReadByte(); if (mode != 0x07) return; MySQL_Connection.Instance.RunQuery(string.Format("DELETE FROM buddies WHERE character_id = {0}", pConnection.CharacterInternalID)); using (InsertQueryBuilder buddies = new InsertQueryBuilder("buddies")) { buddies.OnDuplicateUpdate = true; buddies.AddColumn("character_id"); buddies.AddColumn("friend_id"); buddies.AddColumns(true, "friend_name", "group_name"); byte amount = pPacket.ReadByte(); for (byte i = 0; i < amount; i++) { int bid = pPacket.ReadInt(); string bname = pPacket.ReadString(13); pPacket.Skip(1 + 4); string gname = pPacket.ReadString(13); pPacket.Skip(4); buddies.AddRow( pConnection.CharacterInternalID, bid, bname, gname ); } buddies.RunQuery(); } }
public void Save(byte pWorldID) { pWorldID = GameHelper.GetAllianceWorldID(pWorldID); using (InsertQueryBuilder guildTable = new InsertQueryBuilder("guilds")) { guildTable.OnDuplicateUpdate = true; guildTable.AddColumn("id", false); guildTable.AddColumn("world_id", true); guildTable.AddColumn("name", true); guildTable.AddColumn("notice", true); guildTable.AddColumn("rank1", true); guildTable.AddColumn("rank2", true); guildTable.AddColumn("rank3", true); guildTable.AddColumn("rank4", true); guildTable.AddColumn("rank5", true); guildTable.AddColumn("capacity", true); guildTable.AddColumn("emblem_bg", true); guildTable.AddColumn("emblem_bg_color", true); guildTable.AddColumn("emblem_fg", true); guildTable.AddColumn("emblem_fg_color", true); guildTable.AddColumn("points", true); guildTable.AddColumn("alliance_id", true); guildTable.AddRow( ID, pWorldID, Name, Notice, Ranks[0], Ranks[1], Ranks[2], Ranks[3] == "" ? null : Ranks[3], Ranks[4] == "" ? null : Ranks[4], Capacity, Background, BackgroundColor, Foreground, ForegroundColor, Points, AllianceID ); guildTable.RunQuery(); } // Delete members first MySQL_Connection.Instance.RunQuery("DELETE FROM guild_members WHERE guild_id = " + ID); using (InsertQueryBuilder guildMembersTable = new InsertQueryBuilder("guild_members")) { guildMembersTable.OnDuplicateUpdate = true; guildMembersTable.AddColumn("guild_id", true); guildMembersTable.AddColumn("world_id", true); guildMembersTable.AddColumn("character_id", false); // Switching guild huh? guildMembersTable.AddColumn("rank", true); guildMembersTable.AddColumn("contribution", true); foreach (var member in Members) { guildMembersTable.AddRow( ID, pWorldID, member.CharacterID, member.Rank, member.Contribution ); } if (guildMembersTable.RowCount > 0) MySQL_Connection.Instance.RunQuery(guildMembersTable.ToString()); } using (InsertQueryBuilder guildSkillsTable = new InsertQueryBuilder("guild_skills")) { guildSkillsTable.OnDuplicateUpdate = true; guildSkillsTable.AddColumn("guild_id", false); guildSkillsTable.AddColumn("world_id", true); guildSkillsTable.AddColumn("skill_id", false); guildSkillsTable.AddColumn("level", true); guildSkillsTable.AddColumn("bought_by", true); guildSkillsTable.AddColumn("bought_at", true); guildSkillsTable.AddColumn("unk", true); foreach (var skill in Skills) { guildSkillsTable.AddRow( ID, pWorldID, skill.SkillID, skill.Level, skill.BoughtBy, skill.BoughtAt, skill.Unknown ); } if (guildSkillsTable.RowCount > 0) MySQL_Connection.Instance.RunQuery(guildSkillsTable.ToString()); } }
public virtual void HandleSpawnAndroid(ClientConnection pConnection, MaplePacket pPacket) { Android android = new Android(); android.Decode(pPacket); if (android.ID == pConnection.CharacterID) { // Save android using (InsertQueryBuilder iqb = new InsertQueryBuilder("androids")) { iqb.OnDuplicateUpdate = true; iqb.AddColumn("character_id"); iqb.AddColumns(true, "name", "type", "skin", "hair", "face"); for (int i = 1; i <= 7; i++) iqb.AddColumn("equip" + i, true); iqb.AddRow(pConnection.CharacterInternalID, android.Name, android.Type, android.Skin, android.Hair, android.Face, android.Equips[0], android.Equips[1], android.Equips[2], android.Equips[3], android.Equips[4], android.Equips[5], android.Equips[6]); iqb.RunQuery(); } Logger.WriteLine("Saved android '{0}' of {1}.", android.Name, pConnection.CharData.Stats.Name); } }
public virtual void HandleMessage(ClientConnection pConnection, MaplePacket pPacket) { byte type = pPacket.ReadByte(); if (type == 0x0C) { ushort id = pPacket.ReadUShort(); string data = pPacket.ReadString(); // Server data update using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_running_party")) { iqb.OnDuplicateUpdate = true; iqb.AddColumn("character_id"); iqb.AddColumn("questid"); iqb.AddColumn("data", true); iqb.AddRow(pConnection.CharacterInternalID, id, data); iqb.RunQuery(); } } else if (type == 0x01) { ushort id = pPacket.ReadUShort(); byte mode = pPacket.ReadByte(); if (mode == 1) { string text = pPacket.ReadString(); using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_running")) { iqb.OnDuplicateUpdate = true; iqb.AddColumn("character_id"); iqb.AddColumn("questid"); iqb.AddColumn("data", true); iqb.AddRow(pConnection.CharacterInternalID, id, text); iqb.RunQuery(); } } else if (mode == 2) { // Quest complete long time = pPacket.ReadLong(); using (DeleteQueryBuilder dqb = new DeleteQueryBuilder("quests_running")) { dqb.SetWhereColumn("character_id", pConnection.CharacterInternalID); dqb.SetWhereColumn("questid", id); dqb.RunQuery(); } using (InsertQueryBuilder iqb = new InsertQueryBuilder("quests_done")) { iqb.OnDuplicateUpdate = true; iqb.AddColumn("character_id"); iqb.AddColumn("questid"); iqb.AddColumn("time", true); iqb.AddRow(pConnection.CharacterInternalID, id, time); iqb.RunQuery(); } } } }
public virtual void HandleTradeData(ClientConnection pConnection, MaplePacket pPacket) { byte type = pPacket.ReadByte(); pPacket.ReadByte(); if (type == 0x0A) { pPacket.ReadByte(); pPacket.ReadShort(); int merchid = pPacket.ReadInt(); string merchname = pPacket.ReadString(); pPacket.ReadByte(); while (true) { byte slot = pPacket.ReadByte(); if (slot == 255) break; pPacket.ReadInt(); // Player ID ParseAvatar(pPacket); pPacket.ReadString(); // Player Name pPacket.ReadShort(); // Job } pPacket.ReadShort(); pPacket.ReadString(); // Owner name pPacket.ReadShort(); // Shop cash ID pPacket.ReadString(); // Shop name pPacket.ReadInt(); // ??? pPacket.ReadByte(); // ??? byte items = pPacket.ReadByte(); using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items_trades")) { for (int i = 0; i < items; i++) { short slot = pPacket.ReadShort(); // Slot? pPacket.ReadShort(); pPacket.ReadInt(); // Price Queries.SaveItem(pConnection, (ushort)0, slot, ItemBase.DecodeItemData(pConnection, pPacket), itemsTable, true); } MySQL_Connection.Instance.RunQuery("DELETE FROM items_trades"); // Clear table itemsTable.RunQuery(); } } }
public bool SaveData(ClientConnection pConnection) { int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection); if (internalid == -1) { // Failure! return(false); } using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID); if (info != null) { // Update info! pConnection.CharacterID = Stats.ID; CharacterInventory inventory = Inventory; for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { short slot = equipdata.Key; var equip = equipdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot)) { int hash = info.SlotHashes[0][slot]; int objhash = equipdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[0].Remove(slot); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true); } } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i + 1][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i + 1].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)bag.Key; foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done bag items"); { string removequery = ""; bool added = false; foreach (var hashlist in info.SlotHashes) { foreach (var leftovers in hashlist.Value) { pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key); added = true; removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid); } } if (added) { System.IO.File.WriteAllText("removequery.sql", removequery); MySQL_Connection.Instance.RunQuery(removequery); } } } else { pConnection.Logger_WriteLine("Saving Items"); pConnection.CharacterInternalID = internalid; pConnection.CharacterID = Stats.ID; string itemlist = ""; itemlist += "INSERT INTO items VALUES "; List <string> querylist = new List <string>(); for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { var equip = equipdata.Value; Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true); } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)(bag.Key); foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done bag items"); AccountDataCache.Instance.LoadBaseData(Stats.Name); } itemsTable.RunQuery(); pConnection.Logger_WriteLine("Saved item data"); petTable.RunQuery(); pConnection.Logger_WriteLine("Saved pet data"); AccountDataCache.Instance.LoadInventoryHashes(internalid, true); MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.Running) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery("insert-update-quests.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.Done) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery("insert-update-quests-done.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.PartyQuestsRunning) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.PartyQuestsDone) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid); using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills")) { skillTable.OnDuplicateUpdate = true; skillTable.AddColumn("character_id", false); skillTable.AddColumn("skillid", false); skillTable.AddColumn("level", true); skillTable.AddColumn("maxlevel", true); skillTable.AddColumn("expires", true); foreach (var skill in Skills.SkillList) { skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration); } skillTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid); using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data")) { spTable.OnDuplicateUpdate = true; spTable.AddColumn("character_id", false); spTable.AddColumn("slot", false); spTable.AddColumn("amount", true); foreach (var kvp in Stats.SPData) { spTable.AddRow(internalid, kvp.Key, kvp.Value); } spTable.RunQuery(); } using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations")) { teleportRocks.OnDuplicateUpdate = true; teleportRocks.AddColumn("character_id"); for (int i = 0; i < 41; i++) { teleportRocks.AddColumn("map" + i, true); } teleportRocks.AddRowUnsafe( pConnection.CharacterInternalID, Inventory.TeleportRocks.ToList() ); teleportRocks.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid); using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels")) { table.AddColumn("character_id"); table.AddColumn("block"); table.AddColumn("index"); table.AddColumn("card", true); table.AddColumn("level", true); foreach (var card in EvolutionCards) { table.AddRow( pConnection.CharacterInternalID, card.Block, card.ID, card.ItemID, card.Level ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings")) { table.AddColumn("character_id"); table.AddColumn("friend_name"); table.AddColumn("cashid1"); table.AddColumn("cashid2"); table.AddColumn("type"); foreach (var ring in Rings) { string type = ""; switch (ring.RingType) { case Ring.Type.Couple: type = "couple"; break; case Ring.Type.Marriage: type = "marriage"; break; case Ring.Type.Friend: type = "friend"; break; } table.AddRow( pConnection.CharacterInternalID, ring.FriendName, ring.RingCashID1, ring.RingCashID1, type ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities")) { table.AddColumn("character_id"); table.AddColumn("id"); table.AddColumn("skill_id"); table.AddColumn("level"); foreach (var stat in Abilities) { table.AddRow( pConnection.CharacterInternalID, stat.Item1, stat.Item2, stat.Item3 ); } table.RunQuery(); } return(true); } }
public bool SaveData(ClientConnection pConnection) { int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection); if (internalid == -1) { // Failure! return false; } using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID); if (info != null) { // Update info! pConnection.CharacterID = Stats.ID; CharacterInventory inventory = Inventory; for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { short slot = equipdata.Key; var equip = equipdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot)) { int hash = info.SlotHashes[0][slot]; int objhash = equipdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[0].Remove(slot); } else { addrow = true; } if (addrow) Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true); } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i + 1][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i + 1].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)bag.Key; foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done bag items"); { string removequery = ""; bool added = false; foreach (var hashlist in info.SlotHashes) { foreach (var leftovers in hashlist.Value) { pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key); added = true; removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid); } } if (added) { System.IO.File.WriteAllText("removequery.sql", removequery); MySQL_Connection.Instance.RunQuery(removequery); } } } else { pConnection.Logger_WriteLine("Saving Items"); pConnection.CharacterInternalID = internalid; pConnection.CharacterID = Stats.ID; string itemlist = ""; itemlist += "INSERT INTO items VALUES "; List<string> querylist = new List<string>(); for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { var equip = equipdata.Value; Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true); } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)(bag.Key); foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done bag items"); AccountDataCache.Instance.LoadBaseData(Stats.Name); } itemsTable.RunQuery(); pConnection.Logger_WriteLine("Saved item data"); petTable.RunQuery(); pConnection.Logger_WriteLine("Saved pet data"); AccountDataCache.Instance.LoadInventoryHashes(internalid, true); MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.Running) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery("insert-update-quests.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.Done) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery("insert-update-quests-done.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.PartyQuestsRunning) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.PartyQuestsDone) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid); using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills")) { skillTable.OnDuplicateUpdate = true; skillTable.AddColumn("character_id", false); skillTable.AddColumn("skillid", false); skillTable.AddColumn("level", true); skillTable.AddColumn("maxlevel", true); skillTable.AddColumn("expires", true); foreach (var skill in Skills.SkillList) { skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration); } skillTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid); using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data")) { spTable.OnDuplicateUpdate = true; spTable.AddColumn("character_id", false); spTable.AddColumn("slot", false); spTable.AddColumn("amount", true); foreach (var kvp in Stats.SPData) { spTable.AddRow(internalid, kvp.Key, kvp.Value); } spTable.RunQuery(); } using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations")) { teleportRocks.OnDuplicateUpdate = true; teleportRocks.AddColumn("character_id"); for (int i = 0; i < 41; i++) teleportRocks.AddColumn("map" + i, true); teleportRocks.AddRowUnsafe( pConnection.CharacterInternalID, Inventory.TeleportRocks.ToList() ); teleportRocks.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid); using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels")) { table.AddColumn("character_id"); table.AddColumn("block"); table.AddColumn("index"); table.AddColumn("card", true); table.AddColumn("level", true); foreach (var card in EvolutionCards) { table.AddRow( pConnection.CharacterInternalID, card.Block, card.ID, card.ItemID, card.Level ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings")) { table.AddColumn("character_id"); table.AddColumn("friend_name"); table.AddColumn("cashid1"); table.AddColumn("cashid2"); table.AddColumn("type"); foreach (var ring in Rings) { string type = ""; switch (ring.RingType) { case Ring.Type.Couple: type = "couple"; break; case Ring.Type.Marriage: type = "marriage"; break; case Ring.Type.Friend: type = "friend"; break; } table.AddRow( pConnection.CharacterInternalID, ring.FriendName, ring.RingCashID1, ring.RingCashID1, type ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities")) { table.AddColumn("character_id"); table.AddColumn("id"); table.AddColumn("skill_id"); table.AddColumn("level"); foreach (var stat in Abilities) { table.AddRow( pConnection.CharacterInternalID, stat.Item1, stat.Item2, stat.Item3 ); } table.RunQuery(); } return true; } }
protected void ParseLogin(ClientConnection pConnection, int pUserID, string pUsername, DateTime pCreationDate) { pConnection.Logger_WriteLine("User logged into Nexon account '{1}', userid {0}", pUserID, pUsername); if (AccountDataCache.Instance.KnownUserlist.ContainsKey(pUserID)) { int tmp = AccountDataCache.Instance.KnownUserlist[pUserID]; if (tmp == 2) { pConnection.Logger_WriteLine("User bound to temporary account. Allocating current account to it."); using (UpdateQueryBuilder q = new UpdateQueryBuilder("users")) { q.SetColumn("account_id", pConnection.AccountID); q.SetColumn("last_check", MySQL_Connection.NOW); q.SetColumn("creation_date", pCreationDate); q.SetWhereColumn("ID", pUserID); q.RunQuery(); } AccountDataCache.Instance.KnownUserlist[pUserID] = pConnection.AccountID; pConnection.UserID = pUserID; } else if (tmp == pConnection.AccountID) { // Correct account, continue pConnection.Logger_WriteLine("User bound to same account. kay"); using (UpdateQueryBuilder q = new UpdateQueryBuilder("users")) { q.SetColumn("last_check", MySQL_Connection.NOW); q.SetWhereColumn("ID", pUserID); q.RunQuery(); } pConnection.UserID = pUserID; } else { pConnection.Logger_WriteLine("User ID not bound to this account!!! Ignoring..."); pConnection.SendInfoText("WARNING: This Nexon account ({0}) is not yours! Please login into the correct Mapler.me account.", pUsername); return; } } else { pConnection.Logger_WriteLine("Creating user for accountID {0}", pConnection.AccountID); using (InsertQueryBuilder insertq = new InsertQueryBuilder("users")) { insertq.OnDuplicateUpdate = true; insertq.AddColumn("account_id"); insertq.AddColumn("ID"); insertq.AddColumn("creation_date"); insertq.AddColumn("last_check", true); insertq.AddColumn("maplepoints"); insertq.AddRow(pConnection.AccountID, pUserID, pCreationDate, MySQL_Connection.NOW, 0); insertq.RunQuery(); } pConnection.UserID = pUserID; AccountDataCache.Instance.KnownUserlist.Add(pUserID, pConnection.AccountID); } pConnection.SendInfoText("Identified account {0}. You can now select your character.", pUsername); if (pConnection.LogFilename == "Unknown") pConnection.LogFilename = ""; else pConnection.LogFilename += "_"; pConnection.LogFilename += pConnection.AccountID.ToString(); // Save IP of loginserver if (pConnection.ConnectedToIP != null) Queries.SaveServerIP(pConnection.ConnectedToIP, pConnection.ConnectedToPort, 0, 0); }