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
            });
        }
示例#2
0
        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
            });
        }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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();
            }
        }
示例#6
0
 public static void SavePet(int pCharacterInternalID, ItemPet pPet, InsertQueryBuilder pInsertBuilder)
 {
     if (!pInsertBuilder.HasColumns)
     {
         pInsertBuilder.OnDuplicateUpdate = true;
         pInsertBuilder.AddColumn("character_id", false);
         pInsertBuilder.AddColumn("cashid", false);
         pInsertBuilder.AddColumn("name", true);
         pInsertBuilder.AddColumn("closeness", true);
         pInsertBuilder.AddColumn("fullness", true);
         pInsertBuilder.AddColumn("level", true);
     }
     pInsertBuilder.AddRow(pCharacterInternalID, pPet.CashID, pPet.Petname, pPet.Closeness, pPet.Fullness, pPet.Level);
 }
示例#7
0
        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;
                }
            }
        }
示例#8
0
        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();
            }
        }
示例#9
0
        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;
            }
        }
示例#10
0
        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 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();
            }
        }
示例#13
0
        public static void SavePet(int pCharacterInternalID, ItemPet pPet, InsertQueryBuilder pInsertBuilder)
        {
            if (!pInsertBuilder.HasColumns)
            {
                pInsertBuilder.OnDuplicateUpdate = true;
                pInsertBuilder.AddColumn("character_id", false);
                pInsertBuilder.AddColumn("cashid", false);
                pInsertBuilder.AddColumn("name", true);
                pInsertBuilder.AddColumn("closeness", true);
                pInsertBuilder.AddColumn("fullness", true);
                pInsertBuilder.AddColumn("level", true);
            }
            pInsertBuilder.AddRow(pCharacterInternalID, pPet.CashID, pPet.Petname, pPet.Closeness, pPet.Fullness, pPet.Level);

        }
示例#14
0
        public static void SaveItem(ClientConnection pConnection, ushort pInventory, short pSlot, ItemBase pItem, InsertQueryBuilder itemsTable, bool pDontSetChecksum = false)
        {
            if (!itemsTable.HasColumns)
            {
                itemsTable.OnDuplicateUpdate = true;
                itemsTable.AddColumn("character_id", false);
                itemsTable.AddColumn("itemid", true);
                itemsTable.AddColumn("inventory", false);
                itemsTable.AddColumn("slot", false);
                itemsTable.AddColumn("checksum", true);
                itemsTable.AddColumns(true,
                                      "cashid", "amount", "expires", "slots", "scrolls",
                                      "str", "dex", "int", "luk", "maxhp", "maxmp",
                                      "weaponatt", "weapondef", "magicatt", "magicdef", "acc", "avo", "hands", "jump", "speed", "name", "flags",
                                      "itemlevel", "itemexp",
                                      "hammers",
                                      "battlemodedmg",
                                      "statusflag",
                                      "potential1", "potential2", "potential3",
                                      "potential4", "potential5", "potential6",
                                      "display_id",
                                      "socketstate",
                                      "nebulite1", "nebulite2", "nebulite3",
                                      "uniqueid",
                                      "bagid",
                                      "moreflags",
                                      "durability",
                                      "max_scissors"
                                      );
            }

            int checksum = pItem.GetChecksum();


            if (pItem is ItemEquip)
            {
                var equip = pItem as ItemEquip;

                itemsTable.AddRow(
                    pConnection.CharacterInternalID,
                    equip.ItemID,
                    pInventory,
                    pSlot,
                    checksum,
                    equip.CashID,
                    equip.Amount,
                    equip.Expires,
                    equip.Slots, equip.Scrolls,
                    equip.Str, equip.Dex, equip.Int, equip.Luk,
                    equip.HP, equip.MP,
                    equip.Watk, equip.Wdef, equip.Matk, equip.Mdef,
                    equip.Acc, equip.Avo, equip.Hands, equip.Jump, equip.Speed,
                    equip.Name, equip.Flags,
                    equip.ItemLevel, equip.ItemEXP,
                    equip.ViciousHammer,
                    equip.BattleModeDamage,
                    equip.StatusFlags,
                    equip.Potential1, equip.Potential2, equip.Potential3,
                    equip.Potential4, equip.Potential5, equip.Potential6,
                    equip.DisplayID,
                    equip.SocketState,
                    equip.Nebulite1, equip.Nebulite2, equip.Nebulite3,
                    equip.UniqueID,
                    pItem.BagID,
                    equip.SetFlags,
                    equip.Durability,
                    equip.MaxScissors
                    );
            }
            else
            {
                string name  = pItem is ItemRechargable ? (pItem as ItemRechargable).CraftName : null;
                int    flags = pItem is ItemRechargable ? (pItem as ItemRechargable).Flags : 0;

                itemsTable.AddRow(
                    pConnection.CharacterInternalID,
                    pItem.ItemID,
                    pInventory,
                    pSlot,
                    checksum,
                    pItem.CashID,
                    pItem.Amount,
                    pItem.Expires,
                    null, null,
                    null, null, null, null,
                    null, null,
                    null, null, null, null,
                    null, null, null, null, null,
                    name, flags,
                    null, null,
                    null,
                    null,
                    null,
                    null, null, null,
                    null, null, null,
                    null,
                    null,
                    null, null, null,
                    pItem is ItemRechargable ? (pItem as ItemRechargable).UniqueID : 0,
                    pItem.BagID,
                    null,
                    null,
                    null
                    );
            }

            if (!pDontSetChecksum)
            {
                AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, pInventory, pSlot, checksum);
            }
        }
示例#15
0
        public static int AddOrUpdateCharacter(
            ClientConnection pConnection, int pID, string pName, int pUserID, byte pWorldID, byte pChannelID, byte pLevel,
            short pJob, short pStr, short pDex, short pInt, short pLuk,
            int pHP, int pMaxHP, int pMP, int pMaxMP, short pAP, short pSP,
            long pEXP, int pFame, int pMap, byte pMapPos,
            int pHonourLevel, int pHonourEXP, long pMesos, int pDemonMark,
            byte pGender, byte pSkin,
            int pEyes, int pHair,

            byte[] pSlots, string pBoF, string pBoE, string pUE,
            long[] pPetIDs, int[] pTraits,
            string pMarriedWith
            )
        {
            CharacterCacheInfo cci = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pID, pWorldID);

            if (cci != null)
            {
                int internal_id = cci.InternalID;
                using (UpdateQueryBuilder query = new UpdateQueryBuilder("characters"))
                {
                    query.SetColumn("name", pName);
                    query.SetColumn("userid", pUserID);
                    query.SetColumn("world_id", pWorldID);
                    query.SetColumn("channel_id", pChannelID);
                    query.SetColumn("level", pLevel);
                    query.SetColumn("job", pJob);
                    query.SetColumn("str", pStr);
                    query.SetColumn("dex", pDex);
                    query.SetColumn("int", pInt);
                    query.SetColumn("luk", pLuk);
                    query.SetColumn("chp", pHP);
                    query.SetColumn("mhp", pMaxHP);
                    query.SetColumn("cmp", pMP);
                    query.SetColumn("mmp", pMaxMP);
                    query.SetColumn("ap", pAP);
                    query.SetColumn("sp", pSP);
                    query.SetColumn("exp", pEXP);
                    query.SetColumn("fame", pFame);
                    query.SetColumn("map", pMap);
                    query.SetColumn("pos", pMapPos);
                    query.SetColumn("gender", pGender);
                    query.SetColumn("skin", pSkin);
                    query.SetColumn("eyes", pEyes);
                    query.SetColumn("hair", pHair);
                    query.SetColumn("last_update", MySQL_Connection.NOW);

                    query.SetColumn("honourlevel", pHonourLevel);
                    query.SetColumn("honourexp", pHonourEXP);
                    query.SetColumn("mesos", pMesos);
                    query.SetColumn("demonmark", pDemonMark);

                    query.SetColumn("eqp_slots", pSlots[0]);
                    query.SetColumn("use_slots", pSlots[1]);
                    query.SetColumn("setup_slots", pSlots[2]);
                    query.SetColumn("etc_slots", pSlots[3]);
                    query.SetColumn("cash_slots", pSlots[4]);

                    query.SetColumn("blessingoffairy", pBoF);
                    query.SetColumn("blessingofempress", pBoE);
                    query.SetColumn("ultimateexplorer", pUE);

                    query.SetColumn("petcashid1", pPetIDs[0]);
                    query.SetColumn("petcashid2", pPetIDs[1]);
                    query.SetColumn("petcashid3", pPetIDs[2]);

                    query.SetColumn("trait_charisma", pTraits[0]);
                    query.SetColumn("trait_insight", pTraits[1]);
                    query.SetColumn("trait_willpower", pTraits[2]);
                    query.SetColumn("trait_craft_dili", pTraits[3]);
                    query.SetColumn("trait_empathy", pTraits[4]);
                    query.SetColumn("trait_charm", pTraits[5]);

                    query.SetColumn("married_with", pMarriedWith);

                    query.SetWhereColumn("internal_id", internal_id);

                    int result = query.RunQuery("sql_addorupdate.sql");

                    if (result >= 1)
                    {
                        //pConnection.Logger_WriteLine("Updated character info: {0}", internal_id);
                        return(cci.InternalID);
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to update character info: " + query.ToString());
                    }
                }
            }
            else
            {
                using (InsertQueryBuilder query = new InsertQueryBuilder("characters"))
                {
                    query.OnDuplicateUpdate = false;
                    query.AddColumnWithValue("internal_id", null);

                    query.AddColumnWithValue("id", pID, false);
                    query.AddColumnWithValue("name", pName);
                    query.AddColumnWithValue("userid", pUserID);
                    query.AddColumnWithValue("world_id", pWorldID);
                    query.AddColumnWithValue("channel_id", pChannelID);
                    query.AddColumnWithValue("level", pLevel);
                    query.AddColumnWithValue("job", pJob);
                    query.AddColumnWithValue("str", pStr);
                    query.AddColumnWithValue("dex", pDex);
                    query.AddColumnWithValue("int", pInt);
                    query.AddColumnWithValue("luk", pLuk);
                    query.AddColumnWithValue("chp", pHP);
                    query.AddColumnWithValue("mhp", pMaxHP);
                    query.AddColumnWithValue("cmp", pMP);
                    query.AddColumnWithValue("mmp", pMaxMP);
                    query.AddColumnWithValue("ap", pAP);
                    query.AddColumnWithValue("sp", pSP);
                    query.AddColumnWithValue("exp", pEXP);
                    query.AddColumnWithValue("fame", pFame);
                    query.AddColumnWithValue("map", pMap);
                    query.AddColumnWithValue("pos", pMapPos);
                    query.AddColumnWithValue("gender", pGender);
                    query.AddColumnWithValue("skin", pSkin);
                    query.AddColumnWithValue("eyes", pEyes);
                    query.AddColumnWithValue("hair", pHair);
                    query.AddColumnWithValue("last_update", MySQL_Connection.NOW);

                    query.AddColumnWithValue("honourlevel", pHonourLevel);
                    query.AddColumnWithValue("honourexp", pHonourEXP);
                    query.AddColumnWithValue("mesos", pMesos);
                    query.AddColumnWithValue("demonmark", pDemonMark);

                    query.AddColumnWithValue("eqp_slots", pSlots[0]);
                    query.AddColumnWithValue("use_slots", pSlots[1]);
                    query.AddColumnWithValue("setup_slots", pSlots[2]);
                    query.AddColumnWithValue("etc_slots", pSlots[3]);
                    query.AddColumnWithValue("cash_slots", pSlots[4]);

                    query.AddColumnWithValue("blessingoffairy", pBoF);
                    query.AddColumnWithValue("blessingofempress", pBoE);
                    query.AddColumnWithValue("ultimateexplorer", pUE);


                    query.AddColumnWithValue("petcashid1", pPetIDs[0]);
                    query.AddColumnWithValue("petcashid2", pPetIDs[1]);
                    query.AddColumnWithValue("petcashid3", pPetIDs[2]);

                    query.AddColumnWithValue("trait_charisma", pTraits[0]);
                    query.AddColumnWithValue("trait_insight", pTraits[1]);
                    query.AddColumnWithValue("trait_willpower", pTraits[2]);
                    query.AddColumnWithValue("trait_craft_dili", pTraits[3]);
                    query.AddColumnWithValue("trait_empathy", pTraits[4]);
                    query.AddColumnWithValue("trait_charm", pTraits[5]);

                    query.AddColumnWithValue("married_with", pMarriedWith);

                    string q = query.ToString();

                    System.IO.File.WriteAllText("sql_addorupdate_insert.sql", q);

                    int result = (int)MySQL_Connection.Instance.RunQuery(q);

                    if (result >= 1)
                    {
                        int internalid = MySQL_Connection.Instance.GetLastInsertId();
                        pConnection.Logger_WriteLine("Inserted character info: {0}", internalid);
                        return(internalid);
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to insert character info: " + q);
                    }
                }
            }

            Logger.WriteLine("ERROR WHILE ADDING OR UPDATING CHARACTER");

            return(-1);
        }
示例#16
0
        public static void Initialize()
        {
            Instance = new CommandHandler()
            {
                CommandHandlers = new Dictionary<string,Action<ClientConnection, string[]>>()
            };

            Instance.CommandHandlers.Add("report", (pConnection, pArguments) =>
            {
                return; // Disabled


                if (pArguments.Length == 1)
                {
                    string name = pArguments[0];
                    if (name.Length > 12) return;

                    bool found = false;
                    string query = "SELECT name FROM character_views WHERE name LIKE '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(name) + "%' AND mapid = " + pConnection.CharData.Stats.MapID;
                    using (var result = MySQL_Connection.Instance.RunQuery(query) as MySql.Data.MySqlClient.MySqlDataReader)
                    {
                        if (result.HasRows && result.Read())
                        {
                            name = result.GetString(0);
                            found = true;
                        }
                        else
                        {
                            pConnection.Logger_WriteLine("Could not find {0} for {1}", name, pConnection.CharData.Stats.Name);
                        }
                    }

                    if (found)
                    {
                        using (InsertQueryBuilder iqb = new InsertQueryBuilder("reports"))
                        {
                            iqb.AddColumns(false, "id", "name", "reported_by", "reported_when", "mapid", "screenshot");
                            iqb.AddRow(null, name, pConnection.CharacterInternalID, new MySQL_Connection.NowType(), pConnection.CharData.Stats.MapID, null);

                            int result = (int)MySQL_Connection.Instance.RunQuery(iqb.ToString());
                            if (result != 0)
                            {
                                pConnection.Logger_WriteLine("Reported {0} (by {1}). Requesting Screenshot...", name, pConnection.CharData.Stats.Name);

                                using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, (ushort)0xEEFE))
                                {
                                    pack.WriteString("http://mapler.me/actions/upload_report.php");
                                    pack.WriteInt(MySQL_Connection.Instance.GetLastInsertId());
                                    pack.SwitchOver();
                                    pConnection.SendPacket(pack);
                                }
                            }
                            else
                            {
                                pConnection.Logger_WriteLine("Report FAIL {0} (by {1})", name, pConnection.CharData.Stats.Name);
                            }
                        }

                    }
                }
            });
        }
        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 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();
                    }

                }
            }
        }
示例#19
0
        public static int AddOrUpdateCharacter(
            ClientConnection pConnection, int pID, string pName, int pUserID, byte pWorldID, byte pChannelID, byte pLevel,
            short pJob, short pStr, short pDex, short pInt, short pLuk,
            int pHP, int pMaxHP, int pMP, int pMaxMP, short pAP, short pSP,
            long pEXP, int pFame, int pMap, byte pMapPos,
            int pHonourLevel, int pHonourEXP, long pMesos, int pDemonMark,
            byte pGender, byte pSkin,
            int pEyes, int pHair,

            byte[] pSlots, string pBoF, string pBoE, string pUE,
            long[] pPetIDs, int[] pTraits,
            string pMarriedWith
            )
        {
            CharacterCacheInfo cci = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pID, pWorldID);
            if (cci != null)
            {
                int internal_id = cci.InternalID;
                using (UpdateQueryBuilder query = new UpdateQueryBuilder("characters"))
                {
                    query.SetColumn("name", pName);
                    query.SetColumn("userid", pUserID);
                    query.SetColumn("world_id", pWorldID);
                    query.SetColumn("channel_id", pChannelID);
                    query.SetColumn("level", pLevel);
                    query.SetColumn("job", pJob);
                    query.SetColumn("str", pStr);
                    query.SetColumn("dex", pDex);
                    query.SetColumn("int", pInt);
                    query.SetColumn("luk", pLuk);
                    query.SetColumn("chp", pHP);
                    query.SetColumn("mhp", pMaxHP);
                    query.SetColumn("cmp", pMP);
                    query.SetColumn("mmp", pMaxMP);
                    query.SetColumn("ap", pAP);
                    query.SetColumn("sp", pSP);
                    query.SetColumn("exp", pEXP);
                    query.SetColumn("fame", pFame);
                    query.SetColumn("map", pMap);
                    query.SetColumn("pos", pMapPos);
                    query.SetColumn("gender", pGender);
                    query.SetColumn("skin", pSkin);
                    query.SetColumn("eyes", pEyes);
                    query.SetColumn("hair", pHair);
                    query.SetColumn("last_update", MySQL_Connection.NOW);

                    query.SetColumn("honourlevel", pHonourLevel);
                    query.SetColumn("honourexp", pHonourEXP);
                    query.SetColumn("mesos", pMesos);
                    query.SetColumn("demonmark", pDemonMark);

                    query.SetColumn("eqp_slots", pSlots[0]);
                    query.SetColumn("use_slots", pSlots[1]);
                    query.SetColumn("setup_slots", pSlots[2]);
                    query.SetColumn("etc_slots", pSlots[3]);
                    query.SetColumn("cash_slots", pSlots[4]);

                    query.SetColumn("blessingoffairy", pBoF);
                    query.SetColumn("blessingofempress", pBoE);
                    query.SetColumn("ultimateexplorer", pUE);

                    query.SetColumn("petcashid1", pPetIDs[0]);
                    query.SetColumn("petcashid2", pPetIDs[1]);
                    query.SetColumn("petcashid3", pPetIDs[2]);

                    query.SetColumn("trait_charisma", pTraits[0]);
                    query.SetColumn("trait_insight", pTraits[1]);
                    query.SetColumn("trait_willpower", pTraits[2]);
                    query.SetColumn("trait_craft_dili", pTraits[3]);
                    query.SetColumn("trait_empathy", pTraits[4]);
                    query.SetColumn("trait_charm", pTraits[5]);

                    query.SetColumn("married_with", pMarriedWith);

                    query.SetWhereColumn("internal_id", internal_id);

                    int result = query.RunQuery("sql_addorupdate.sql");

                    if (result >= 1)
                    {
                        //pConnection.Logger_WriteLine("Updated character info: {0}", internal_id);
                        return cci.InternalID;
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to update character info: " + query.ToString());
                    }
                }
            }
            else
            {
                using (InsertQueryBuilder query = new InsertQueryBuilder("characters"))
                {
                    query.OnDuplicateUpdate = false;
                    query.AddColumnWithValue("internal_id", null);

                    query.AddColumnWithValue("id", pID, false);
                    query.AddColumnWithValue("name", pName);
                    query.AddColumnWithValue("userid", pUserID);
                    query.AddColumnWithValue("world_id", pWorldID);
                    query.AddColumnWithValue("channel_id", pChannelID);
                    query.AddColumnWithValue("level", pLevel);
                    query.AddColumnWithValue("job", pJob);
                    query.AddColumnWithValue("str", pStr);
                    query.AddColumnWithValue("dex", pDex);
                    query.AddColumnWithValue("int", pInt);
                    query.AddColumnWithValue("luk", pLuk);
                    query.AddColumnWithValue("chp", pHP);
                    query.AddColumnWithValue("mhp", pMaxHP);
                    query.AddColumnWithValue("cmp", pMP);
                    query.AddColumnWithValue("mmp", pMaxMP);
                    query.AddColumnWithValue("ap", pAP);
                    query.AddColumnWithValue("sp", pSP);
                    query.AddColumnWithValue("exp", pEXP);
                    query.AddColumnWithValue("fame", pFame);
                    query.AddColumnWithValue("map", pMap);
                    query.AddColumnWithValue("pos", pMapPos);
                    query.AddColumnWithValue("gender", pGender);
                    query.AddColumnWithValue("skin", pSkin);
                    query.AddColumnWithValue("eyes", pEyes);
                    query.AddColumnWithValue("hair", pHair);
                    query.AddColumnWithValue("last_update", MySQL_Connection.NOW);

                    query.AddColumnWithValue("honourlevel", pHonourLevel);
                    query.AddColumnWithValue("honourexp", pHonourEXP);
                    query.AddColumnWithValue("mesos", pMesos);
                    query.AddColumnWithValue("demonmark", pDemonMark);

                    query.AddColumnWithValue("eqp_slots", pSlots[0]);
                    query.AddColumnWithValue("use_slots", pSlots[1]);
                    query.AddColumnWithValue("setup_slots", pSlots[2]);
                    query.AddColumnWithValue("etc_slots", pSlots[3]);
                    query.AddColumnWithValue("cash_slots", pSlots[4]);

                    query.AddColumnWithValue("blessingoffairy", pBoF);
                    query.AddColumnWithValue("blessingofempress", pBoE);
                    query.AddColumnWithValue("ultimateexplorer", pUE);


                    query.AddColumnWithValue("petcashid1", pPetIDs[0]);
                    query.AddColumnWithValue("petcashid2", pPetIDs[1]);
                    query.AddColumnWithValue("petcashid3", pPetIDs[2]);

                    query.AddColumnWithValue("trait_charisma", pTraits[0]);
                    query.AddColumnWithValue("trait_insight", pTraits[1]);
                    query.AddColumnWithValue("trait_willpower", pTraits[2]);
                    query.AddColumnWithValue("trait_craft_dili", pTraits[3]);
                    query.AddColumnWithValue("trait_empathy", pTraits[4]);
                    query.AddColumnWithValue("trait_charm", pTraits[5]);

                    query.AddColumnWithValue("married_with", pMarriedWith);

                    string q = query.ToString();

                    System.IO.File.WriteAllText("sql_addorupdate_insert.sql", q);

                    int result = (int)MySQL_Connection.Instance.RunQuery(q);

                    if (result >= 1)
                    {
                        int internalid = MySQL_Connection.Instance.GetLastInsertId();
                        pConnection.Logger_WriteLine("Inserted character info: {0}", internalid);
                        return internalid;
                    }
                    else
                    {
                        pConnection.Logger_WriteLine("Failed to insert character info: " + q);
                    }
                }
            }

            Logger.WriteLine("ERROR WHILE ADDING OR UPDATING CHARACTER");

            return -1;
        }
示例#20
0
        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();
            }
        }
示例#21
0
        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 void SaveData(ClientConnection pConnection)
        {
            GW_CharacterStat stats = Stats;
            Queries.AddOrUpdateCharacter(null, stats.ID, stats.Name, pConnection.UserID, pConnection.WorldID, stats.Level, stats.JobID,
                stats.Str, stats.Dex, stats.Int, stats.Luk,
                stats.HP, stats.MaxHP, stats.MP, stats.MaxMP, stats.AP, stats.SP,
                stats.EXP, stats.Fame, stats.MapID, stats.MapPos, stats.Gender, stats.Skin,
                stats.Face, stats.Hair);


            InsertQueryBuilder itemsTable = new InsertQueryBuilder("items");
            itemsTable.OnDuplicateUpdate = true;
            itemsTable.AddColumn("character_id", false);
            itemsTable.AddColumn("itemid", true);
            itemsTable.AddColumn("inventory", false);
            itemsTable.AddColumn("slot", false);
            itemsTable.AddColumn("checksum", true);
            itemsTable.AddColumns(true, "cashid", "amount", "slots", "scrolls", "str", "dex", "int", "luk", "maxhp", "maxmp", "weaponatt", "weapondef", "magicatt", "magicdef", "acc", "avo", "hands", "jump", "speed", "name", "flags", "hammers", "potential1", "potential2", "potential3", "potential4", "potential5", "socketstate", "socket1", "socket2", "socket3");

            InsertQueryBuilder petTable = new InsertQueryBuilder("pets");
            petTable.OnDuplicateUpdate = true;
            petTable.AddColumn("cashid", false);
            petTable.AddColumn("name", true);
            petTable.AddColumn("closeness", true);
            petTable.AddColumn("fullness", true);
            petTable.AddColumn("level", true);

            int internalid = 0;


            if (Internal_Storage.Store.Instance.KnownCharlist.ContainsKey(stats.ID) &&
                Internal_Storage.Store.Instance.KnownCharlist[stats.ID].ContainsKey(pConnection.WorldID))
            {
                // Update info!
                var internalinfo = Internal_Storage.Store.Instance.KnownCharlist[stats.ID][pConnection.WorldID];
                internalid = internalinfo.InternalID;
                Dictionary<byte, short> updatethese = new Dictionary<byte, short>();
                Dictionary<byte, short> addthese = new Dictionary<byte, short>();

                CharacterInventory inventory = Inventory;

                for (int i = 0; i < Inventory.EquipmentItems.Length; i++)
                {
                    var equips = Inventory.EquipmentItems[i];
                    foreach (var equipdata in equips)
                    {
                        short slot = (short)(i == 2 ? equipdata.Key : -equipdata.Key);
                        var equip = equipdata.Value;
                        bool addrow = false;

                        if (internalinfo.SlotHashes[0].ContainsKey(slot))
                        {
                            int hash = internalinfo.SlotHashes[0][slot];
                            int objhash = equipdata.Value.GetChecksum();
                            if (hash != objhash)
                            {
                                Logger.WriteLine("{0} != {1}", hash, objhash);
                                addrow = true;
                            }

                            internalinfo.SlotHashes[0].Remove(slot);
                        }
                        else
                        {
                            addrow = true;
                        }

                        if (addrow)
                        {
                            itemsTable.AddRow(
                                internalid,
                                equip.ItemID,
                                0,
                                i == 2 ? equipdata.Key : -equipdata.Key,
                                equip.GetChecksum(),
                                equip.CashID,
                                equip.Amount,
                                equip.Slots, equip.Scrolls,
                                equip.Str, equip.Dex, equip.Int, equip.Luk,
                                equip.HP, equip.MP,
                                equip.Watk, equip.Wdef, equip.Matk, equip.Mdef,
                                equip.Acc, equip.Avo, equip.Hands, equip.Jump, equip.Speed,
                                equip.Name, equip.Flags,
                                equip.ViciousHammer,
                                equip.Potential1, equip.Potential2, equip.Potential3, equip.Potential4, equip.Potential5,
                                equip.SocketState, equip.Socket1, equip.Socket2, equip.Socket3
                                );
                        }
                    }
                }

                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 (internalinfo.SlotHashes[i + 1].ContainsKey(itemdata.Key))
                        {
                            int hash = internalinfo.SlotHashes[i + 1][itemdata.Key];
                            int objhash = itemdata.Value.GetChecksum();
                            if (hash != objhash)
                            {
                                Logger.WriteLine("{0} != {1}", hash, objhash);
                                addrow = true;
                            }


                            internalinfo.SlotHashes[i + 1].Remove(itemdata.Key);
                        }
                        else
                        {
                            addrow = true;
                        }

                        if (addrow)
                        {
                            string name = item is ItemRechargable ? (item as ItemRechargable).CraftName : null;
                            int flags = item is ItemRechargable ? (item as ItemRechargable).Flags : 0;

                            itemsTable.AddRow(
                                internalid,
                                item.ItemID,
                                i + 1,
                                itemdata.Key,
                                (item is ItemRechargable ? (item as ItemRechargable).GetChecksum() : item.GetChecksum()),
                                item.CashID,
                                item.Amount,
                                null, null,
                                null, null, null, null,
                                null, null,
                                null, null, null, null,
                                null, null, null, null, null,
                                name, flags,
                                null,
                                null, null, null, null, null,
                                null, null, null, null
                                );

                            if (item is ItemPet)
                            {
                                var pet = item as ItemPet;
                                petTable.AddRow(pet.CashID, pet.Petname, pet.Closeness, pet.Fullness, pet.Level);
                            }
                        }
                    }
                }

                Logger.WriteLine("Done items");

                {
                    string removequery = "";
                    bool added = false;
                    for (byte i = 0; i < internalinfo.SlotHashes.Length; i++)
                    {
                        foreach (var leftovers in internalinfo.SlotHashes[i])
                        {
                            Logger.WriteLine("Deleting item @ inv {0} slot {1}", leftovers.Key, leftovers.Value);
                            added = true;
                            removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", i, leftovers.Key, internalid);
                        }
                    }
                    if (added)
                    {
                        System.IO.File.WriteAllText("removequery.sql", removequery);
                        MySQL_Connection.Instance.RunQuery(removequery);
                    }
                }
            }
            else
            {
                Logger.WriteLine("Saving Items");

                using (var result = MySQL_Connection.Instance.RunQuery("SELECT internal_id FROM characters WHERE id = " + stats.ID + " AND world_id = " + pConnection.WorldID + "") as MySql.Data.MySqlClient.MySqlDataReader)
                {
                    if (result.Read())
                    {
                        internalid = result.GetInt32(0);
                    }
                    else
                    {
                        Logger.WriteLine("OH GOD COULD NOT GET INTERNAL ID");
                        return;
                    }
                }


                string itemlist = "";
                itemlist += "INSERT INTO items VALUES ";
                List<string> querylist = new List<string>();
                for (int i = 0; i < Inventory.EquipmentItems.Length; i++)
                {
                    var equips = Inventory.EquipmentItems[i];
                    foreach (var equipdata in equips)
                    {
                        var equip = equipdata.Value;

                        itemsTable.AddRow(
                            internalid,
                            equip.ItemID,
                            0,
                            i == 2 ? equipdata.Key : -equipdata.Key,
                            equip.GetChecksum(),
                            equip.CashID,
                            equip.Amount,
                            equip.Slots, equip.Scrolls,
                            equip.Str, equip.Dex, equip.Int, equip.Luk,
                            equip.HP, equip.MP,
                            equip.Watk, equip.Wdef, equip.Matk, equip.Mdef,
                            equip.Acc, equip.Avo, equip.Hands, equip.Jump, equip.Speed,
                            equip.Name, equip.Flags,
                            equip.ViciousHammer,
                            equip.Potential1, equip.Potential2, equip.Potential3, equip.Potential4, equip.Potential5,
                            equip.SocketState, equip.Socket1, equip.Socket2, equip.Socket3
                            );
                    }
                }

                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;

                        string name = item is ItemRechargable ? (item as ItemRechargable).CraftName : null;
                        int flags = item is ItemRechargable ? (item as ItemRechargable).Flags : 0;

                        itemsTable.AddRow(
                            internalid,
                            item.ItemID,
                            i + 1,
                            itemdata.Key,
                            (item is ItemRechargable ? (item as ItemRechargable).GetChecksum() : item.GetChecksum()),
                            item.CashID,
                            item.Amount,
                            null, null,
                            null, null, null, null,
                            null, null,
                            null, null, null, null,
                            null, null, null, null, null,
                            name, flags,
                            null,
                            null, null, null, null, null,
                            null, null, null, null
                            );

                        if (item is ItemPet)
                        {
                            var pet = item as ItemPet;
                            petTable.AddRow(pet.CashID, pet.Petname, pet.Closeness, pet.Fullness, pet.Level);
                        }
                    }
                }

                Logger.WriteLine("Done items");



            }

            if (itemsTable.RowCount > 0)
            {
                string q = itemsTable.ToString();
                System.IO.File.WriteAllText("insert-update.sql", q);
                int result = (int)MySQL_Connection.Instance.RunQuery(q);
                Logger.WriteLine("Result: {0}", result);
            }

            Logger.WriteLine("Saved item data");

            if (petTable.RowCount > 0)
            {
                string q = petTable.ToString();
                System.IO.File.WriteAllText("insert-update-pet.sql", q);
                int result = (int)MySQL_Connection.Instance.RunQuery(q);
                Logger.WriteLine("Result: {0}", result);
            }

            Logger.WriteLine("Saved item data");
            Internal_Storage.Store.Instance.LoadInventoryHashes(internalid, true);

            {

                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);
                }

                if (questsTable.RowCount > 0)
                {
                    string q = questsTable.ToString();
                    System.IO.File.WriteAllText("insert-update-quests.sql", q);
                    int result = (int)MySQL_Connection.Instance.RunQuery(q);
                    Logger.WriteLine("Result: {0}", result);
                }
            }
            {
                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);
                }

                if (doneTable.RowCount > 0)
                {
                    string q = doneTable.ToString();
                    System.IO.File.WriteAllText("insert-update-quests-done.sql", q);
                    int result = (int)MySQL_Connection.Instance.RunQuery(q);
                    Logger.WriteLine("Result: {0}", result);
                }
            }

            pConnection.CharacterInternalID = internalid;
            pConnection.CharacterID = Internal_Storage.Store.Instance.KnownCharlist_INTERNAL[internalid].ID;

        }
示例#23
0
        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);
                }
        }
示例#24
0
        public static void Initialize()
        {
            Instance = new CommandHandler()
            {
                CommandHandlers = new Dictionary <string, Action <ClientConnection, string[]> >()
            };

            Instance.CommandHandlers.Add("report", (pConnection, pArguments) =>
            {
                return; // Disabled


                if (pArguments.Length == 1)
                {
                    string name = pArguments[0];
                    if (name.Length > 12)
                    {
                        return;
                    }

                    bool found   = false;
                    string query = "SELECT name FROM character_views WHERE name LIKE '" + MySql.Data.MySqlClient.MySqlHelper.EscapeString(name) + "%' AND mapid = " + pConnection.CharData.Stats.MapID;
                    using (var result = MySQL_Connection.Instance.RunQuery(query) as MySql.Data.MySqlClient.MySqlDataReader)
                    {
                        if (result.HasRows && result.Read())
                        {
                            name  = result.GetString(0);
                            found = true;
                        }
                        else
                        {
                            pConnection.Logger_WriteLine("Could not find {0} for {1}", name, pConnection.CharData.Stats.Name);
                        }
                    }

                    if (found)
                    {
                        using (InsertQueryBuilder iqb = new InsertQueryBuilder("reports"))
                        {
                            iqb.AddColumns(false, "id", "name", "reported_by", "reported_when", "mapid", "screenshot");
                            iqb.AddRow(null, name, pConnection.CharacterInternalID, new MySQL_Connection.NowType(), pConnection.CharData.Stats.MapID, null);

                            int result = (int)MySQL_Connection.Instance.RunQuery(iqb.ToString());
                            if (result != 0)
                            {
                                pConnection.Logger_WriteLine("Reported {0} (by {1}). Requesting Screenshot...", name, pConnection.CharData.Stats.Name);

                                using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, (ushort)0xEEFE))
                                {
                                    pack.WriteString("http://mapler.me/actions/upload_report.php");
                                    pack.WriteInt(MySQL_Connection.Instance.GetLastInsertId());
                                    pack.SwitchOver();
                                    pConnection.SendPacket(pack);
                                }
                            }
                            else
                            {
                                pConnection.Logger_WriteLine("Report FAIL {0} (by {1})", name, pConnection.CharData.Stats.Name);
                            }
                        }
                    }
                }
            });
        }
        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);
        }
示例#26
0
        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 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 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);

            }
        }
示例#29
0
        public static void SaveItem(ClientConnection pConnection, ushort pInventory, short pSlot, ItemBase pItem, InsertQueryBuilder itemsTable, bool pDontSetChecksum = false)
        {
            if (!itemsTable.HasColumns)
            {
                itemsTable.OnDuplicateUpdate = true;
                itemsTable.AddColumn("character_id", false);
                itemsTable.AddColumn("itemid", true);
                itemsTable.AddColumn("inventory", false);
                itemsTable.AddColumn("slot", false);
                itemsTable.AddColumn("checksum", true);
                itemsTable.AddColumns(true, 
                    "cashid", "amount", "expires", "slots", "scrolls", 
                    "str", "dex", "int", "luk", "maxhp", "maxmp", 
                    "weaponatt", "weapondef", "magicatt", "magicdef", "acc", "avo", "hands", "jump", "speed", "name", "flags",
                    "itemlevel", "itemexp",
                    "hammers",
                    "battlemodedmg",
                    "statusflag",
                    "potential1", "potential2", "potential3", 
                    "potential4", "potential5", "potential6",
                    "display_id",
                    "socketstate", 
                    "nebulite1", "nebulite2", "nebulite3",
                    "uniqueid",
                    "bagid",
                    "moreflags",
                    "durability",
                    "max_scissors"
                    );
            }

            int checksum = pItem.GetChecksum();


            if (pItem is ItemEquip)
            {
                var equip = pItem as ItemEquip;

                itemsTable.AddRow(
                    pConnection.CharacterInternalID,
                    equip.ItemID,
                    pInventory,
                    pSlot,
                    checksum,
                    equip.CashID,
                    equip.Amount,
                    equip.Expires,
                    equip.Slots, equip.Scrolls,
                    equip.Str, equip.Dex, equip.Int, equip.Luk,
                    equip.HP, equip.MP,
                    equip.Watk, equip.Wdef, equip.Matk, equip.Mdef,
                    equip.Acc, equip.Avo, equip.Hands, equip.Jump, equip.Speed,
                    equip.Name, equip.Flags,
                    equip.ItemLevel, equip.ItemEXP, 
                    equip.ViciousHammer, 
                    equip.BattleModeDamage,
                    equip.StatusFlags,
                    equip.Potential1, equip.Potential2, equip.Potential3, 
                    equip.Potential4, equip.Potential5, equip.Potential6,
                    equip.DisplayID,
                    equip.SocketState, 
                    equip.Nebulite1, equip.Nebulite2, equip.Nebulite3,
                    equip.UniqueID,
                    pItem.BagID,
                    equip.SetFlags,
                    equip.Durability,
                    equip.MaxScissors
                );
            }
            else
            {

                string name = pItem is ItemRechargable ? (pItem as ItemRechargable).CraftName : null;
                int flags = pItem is ItemRechargable ? (pItem as ItemRechargable).Flags : 0;

                itemsTable.AddRow(
                    pConnection.CharacterInternalID,
                    pItem.ItemID,
                    pInventory,
                    pSlot,
                    checksum,
                    pItem.CashID,
                    pItem.Amount,
                    pItem.Expires,
                    null, null,
                    null, null, null, null,
                    null, null,
                    null, null, null, null,
                    null, null, null, null, null,
                    name, flags,
                    null, null, 
                    null, 
                    null,
                    null,
                    null, null, null, 
                    null, null, null,
                    null,
                    null, 
                    null, null, null,
                    pItem is ItemRechargable ? (pItem as ItemRechargable).UniqueID : 0,
                    pItem.BagID,
                    null,
                    null,
                    null
                    );

            }

            if (!pDontSetChecksum)
                AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, pInventory, pSlot, checksum);
        }
        public virtual void HandleSkillUpdate(ClientConnection pConnection, MaplePacket pPacket)
        {
            pPacket.ReadByte(); // Unstuck
            pPacket.ReadByte();
            ushort amount = pPacket.ReadUShort();

            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);

                for (ushort i = 0; i < amount; i++)
                {
                    int skillid = pPacket.ReadInt();
                    int level = pPacket.ReadInt();
                    int masterlevel = pPacket.ReadInt();
                    long expiration = pPacket.ReadLong();

                    Timeline.Instance.PushSkillUP(pConnection, skillid, level);

                    skillTable.AddRow(pConnection.CharacterInternalID, skillid, level, masterlevel == 0 ? null : (object)masterlevel, expiration);
                }

                if (skillTable.RowCount > 0)
                {
                    string q = skillTable.ToString();
                    System.IO.File.WriteAllText("insert-update-skills-packet.sql", q);
                    int result = (int)MySQL_Connection.Instance.RunQuery(q);
                    pConnection.Logger_WriteLine("Result Skills: {0}", result);

                    pConnection.SendTimeUpdate();
                }

            }
        }
        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();
            }
        }
示例#32
0
        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;
            }
        }
示例#33
0
        public void SaveData(ClientConnection pConnection)
        {
            GW_CharacterStat stats = Stats;

            Queries.AddOrUpdateCharacter(null, stats.ID, stats.Name, pConnection.UserID, pConnection.WorldID, stats.Level, stats.JobID,
                                         stats.Str, stats.Dex, stats.Int, stats.Luk,
                                         stats.HP, stats.MaxHP, stats.MP, stats.MaxMP, stats.AP, stats.SP,
                                         stats.EXP, stats.Fame, stats.MapID, stats.MapPos, stats.Gender, stats.Skin,
                                         stats.Face, stats.Hair);


            InsertQueryBuilder itemsTable = new InsertQueryBuilder("items");

            itemsTable.OnDuplicateUpdate = true;
            itemsTable.AddColumn("character_id", false);
            itemsTable.AddColumn("itemid", true);
            itemsTable.AddColumn("inventory", false);
            itemsTable.AddColumn("slot", false);
            itemsTable.AddColumn("checksum", true);
            itemsTable.AddColumns(true, "cashid", "amount", "slots", "scrolls", "str", "dex", "int", "luk", "maxhp", "maxmp", "weaponatt", "weapondef", "magicatt", "magicdef", "acc", "avo", "hands", "jump", "speed", "name", "flags", "hammers", "potential1", "potential2", "potential3", "potential4", "potential5", "socketstate", "socket1", "socket2", "socket3");

            InsertQueryBuilder petTable = new InsertQueryBuilder("pets");

            petTable.OnDuplicateUpdate = true;
            petTable.AddColumn("cashid", false);
            petTable.AddColumn("name", true);
            petTable.AddColumn("closeness", true);
            petTable.AddColumn("fullness", true);
            petTable.AddColumn("level", true);

            int internalid = 0;


            if (Internal_Storage.Store.Instance.KnownCharlist.ContainsKey(stats.ID) &&
                Internal_Storage.Store.Instance.KnownCharlist[stats.ID].ContainsKey(pConnection.WorldID))
            {
                // Update info!
                var internalinfo = Internal_Storage.Store.Instance.KnownCharlist[stats.ID][pConnection.WorldID];
                internalid = internalinfo.InternalID;
                Dictionary <byte, short> updatethese = new Dictionary <byte, short>();
                Dictionary <byte, short> addthese    = new Dictionary <byte, short>();

                CharacterInventory inventory = Inventory;

                for (int i = 0; i < Inventory.EquipmentItems.Length; i++)
                {
                    var equips = Inventory.EquipmentItems[i];
                    foreach (var equipdata in equips)
                    {
                        short slot   = (short)(i == 2 ? equipdata.Key : -equipdata.Key);
                        var   equip  = equipdata.Value;
                        bool  addrow = false;

                        if (internalinfo.SlotHashes[0].ContainsKey(slot))
                        {
                            int hash    = internalinfo.SlotHashes[0][slot];
                            int objhash = equipdata.Value.GetChecksum();
                            if (hash != objhash)
                            {
                                Logger.WriteLine("{0} != {1}", hash, objhash);
                                addrow = true;
                            }

                            internalinfo.SlotHashes[0].Remove(slot);
                        }
                        else
                        {
                            addrow = true;
                        }

                        if (addrow)
                        {
                            itemsTable.AddRow(
                                internalid,
                                equip.ItemID,
                                0,
                                i == 2 ? equipdata.Key : -equipdata.Key,
                                equip.GetChecksum(),
                                equip.CashID,
                                equip.Amount,
                                equip.Slots, equip.Scrolls,
                                equip.Str, equip.Dex, equip.Int, equip.Luk,
                                equip.HP, equip.MP,
                                equip.Watk, equip.Wdef, equip.Matk, equip.Mdef,
                                equip.Acc, equip.Avo, equip.Hands, equip.Jump, equip.Speed,
                                equip.Name, equip.Flags,
                                equip.ViciousHammer,
                                equip.Potential1, equip.Potential2, equip.Potential3, equip.Potential4, equip.Potential5,
                                equip.SocketState, equip.Socket1, equip.Socket2, equip.Socket3
                                );
                        }
                    }
                }

                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 (internalinfo.SlotHashes[i + 1].ContainsKey(itemdata.Key))
                        {
                            int hash    = internalinfo.SlotHashes[i + 1][itemdata.Key];
                            int objhash = itemdata.Value.GetChecksum();
                            if (hash != objhash)
                            {
                                Logger.WriteLine("{0} != {1}", hash, objhash);
                                addrow = true;
                            }


                            internalinfo.SlotHashes[i + 1].Remove(itemdata.Key);
                        }
                        else
                        {
                            addrow = true;
                        }

                        if (addrow)
                        {
                            string name  = item is ItemRechargable ? (item as ItemRechargable).CraftName : null;
                            int    flags = item is ItemRechargable ? (item as ItemRechargable).Flags : 0;

                            itemsTable.AddRow(
                                internalid,
                                item.ItemID,
                                i + 1,
                                itemdata.Key,
                                (item is ItemRechargable ? (item as ItemRechargable).GetChecksum() : item.GetChecksum()),
                                item.CashID,
                                item.Amount,
                                null, null,
                                null, null, null, null,
                                null, null,
                                null, null, null, null,
                                null, null, null, null, null,
                                name, flags,
                                null,
                                null, null, null, null, null,
                                null, null, null, null
                                );

                            if (item is ItemPet)
                            {
                                var pet = item as ItemPet;
                                petTable.AddRow(pet.CashID, pet.Petname, pet.Closeness, pet.Fullness, pet.Level);
                            }
                        }
                    }
                }

                Logger.WriteLine("Done items");

                {
                    string removequery = "";
                    bool   added       = false;
                    for (byte i = 0; i < internalinfo.SlotHashes.Length; i++)
                    {
                        foreach (var leftovers in internalinfo.SlotHashes[i])
                        {
                            Logger.WriteLine("Deleting item @ inv {0} slot {1}", leftovers.Key, leftovers.Value);
                            added        = true;
                            removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", i, leftovers.Key, internalid);
                        }
                    }
                    if (added)
                    {
                        System.IO.File.WriteAllText("removequery.sql", removequery);
                        MySQL_Connection.Instance.RunQuery(removequery);
                    }
                }
            }
            else
            {
                Logger.WriteLine("Saving Items");

                using (var result = MySQL_Connection.Instance.RunQuery("SELECT internal_id FROM characters WHERE id = " + stats.ID + " AND world_id = " + pConnection.WorldID + "") as MySql.Data.MySqlClient.MySqlDataReader)
                {
                    if (result.Read())
                    {
                        internalid = result.GetInt32(0);
                    }
                    else
                    {
                        Logger.WriteLine("OH GOD COULD NOT GET INTERNAL ID");
                        return;
                    }
                }


                string itemlist = "";
                itemlist += "INSERT INTO items VALUES ";
                List <string> querylist = new List <string>();
                for (int i = 0; i < Inventory.EquipmentItems.Length; i++)
                {
                    var equips = Inventory.EquipmentItems[i];
                    foreach (var equipdata in equips)
                    {
                        var equip = equipdata.Value;

                        itemsTable.AddRow(
                            internalid,
                            equip.ItemID,
                            0,
                            i == 2 ? equipdata.Key : -equipdata.Key,
                            equip.GetChecksum(),
                            equip.CashID,
                            equip.Amount,
                            equip.Slots, equip.Scrolls,
                            equip.Str, equip.Dex, equip.Int, equip.Luk,
                            equip.HP, equip.MP,
                            equip.Watk, equip.Wdef, equip.Matk, equip.Mdef,
                            equip.Acc, equip.Avo, equip.Hands, equip.Jump, equip.Speed,
                            equip.Name, equip.Flags,
                            equip.ViciousHammer,
                            equip.Potential1, equip.Potential2, equip.Potential3, equip.Potential4, equip.Potential5,
                            equip.SocketState, equip.Socket1, equip.Socket2, equip.Socket3
                            );
                    }
                }

                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;

                        string name  = item is ItemRechargable ? (item as ItemRechargable).CraftName : null;
                        int    flags = item is ItemRechargable ? (item as ItemRechargable).Flags : 0;

                        itemsTable.AddRow(
                            internalid,
                            item.ItemID,
                            i + 1,
                            itemdata.Key,
                            (item is ItemRechargable ? (item as ItemRechargable).GetChecksum() : item.GetChecksum()),
                            item.CashID,
                            item.Amount,
                            null, null,
                            null, null, null, null,
                            null, null,
                            null, null, null, null,
                            null, null, null, null, null,
                            name, flags,
                            null,
                            null, null, null, null, null,
                            null, null, null, null
                            );

                        if (item is ItemPet)
                        {
                            var pet = item as ItemPet;
                            petTable.AddRow(pet.CashID, pet.Petname, pet.Closeness, pet.Fullness, pet.Level);
                        }
                    }
                }

                Logger.WriteLine("Done items");
            }

            if (itemsTable.RowCount > 0)
            {
                string q = itemsTable.ToString();
                System.IO.File.WriteAllText("insert-update.sql", q);
                int result = (int)MySQL_Connection.Instance.RunQuery(q);
                Logger.WriteLine("Result: {0}", result);
            }

            Logger.WriteLine("Saved item data");

            if (petTable.RowCount > 0)
            {
                string q = petTable.ToString();
                System.IO.File.WriteAllText("insert-update-pet.sql", q);
                int result = (int)MySQL_Connection.Instance.RunQuery(q);
                Logger.WriteLine("Result: {0}", result);
            }

            Logger.WriteLine("Saved item data");
            Internal_Storage.Store.Instance.LoadInventoryHashes(internalid, true);

            {
                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);
                }

                if (questsTable.RowCount > 0)
                {
                    string q = questsTable.ToString();
                    System.IO.File.WriteAllText("insert-update-quests.sql", q);
                    int result = (int)MySQL_Connection.Instance.RunQuery(q);
                    Logger.WriteLine("Result: {0}", result);
                }
            }
            {
                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);
                }

                if (doneTable.RowCount > 0)
                {
                    string q = doneTable.ToString();
                    System.IO.File.WriteAllText("insert-update-quests-done.sql", q);
                    int result = (int)MySQL_Connection.Instance.RunQuery(q);
                    Logger.WriteLine("Result: {0}", result);
                }
            }

            pConnection.CharacterInternalID = internalid;
            pConnection.CharacterID         = Internal_Storage.Store.Instance.KnownCharlist_INTERNAL[internalid].ID;
        }