Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        public virtual void HandleMaplePointAmount(ClientConnection pConnection, MaplePacket pPacket)
        {
            int amount = pPacket.ReadInt(); // Life can be so easy

            using (UpdateQueryBuilder q = new UpdateQueryBuilder("users"))
            {
                q.SetWhereColumn("account_id", pConnection.AccountID);
                q.SetColumn("maplepoints", amount);
                q.RunQuery();
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
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;
        }