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

                    }
                }
            });
        }
Exemplo n.º 3
0
        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();
                }

            }
        }
Exemplo n.º 4
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);
                            }
                        }
                    }
                }
            });
        }
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;
        }
Exemplo n.º 6
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 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;

        }
Exemplo n.º 8
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());
            }
        }
Exemplo n.º 9
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;
        }