public virtual void HandleLoginFromWeb(ClientConnection pConnection, MaplePacket pPacket) { byte error = pPacket.ReadByte(); if (error != 0) { pConnection.Logger_WriteLine("Got Status: {0}", error); if (error == 0x07) { pConnection.Logger_WriteLine("Already logged in!"); } return; } int userid = pPacket.ReadInt(); pPacket.ReadByte(); // Gender or GenderSelect/PinSelect pPacket.ReadByte(); pPacket.ReadShort(); // Admin info! pPacket.ReadInt(); // ReadBytes(4) pPacket.ReadByte(); // 0x95 string username = pPacket.ReadString(); // Username pPacket.ReadByte(); // 0? pPacket.ReadByte(); // Quiet Ban pPacket.ReadLong(); // Quiet Ban Time pPacket.ReadString(); // Username. Again. DateTime creationtime = DateTime.FromFileTime(pPacket.ReadLong()); // creation datetime pPacket.ReadInt(); pPacket.ReadBytes(8); // CC key pPacket.ReadString(); ParseLogin(pConnection, userid, username, creationtime); }
public void HandleCommand(ClientConnection pConnection, string pCommand, string[] pArguments) { if (CommandHandlers.ContainsKey(pCommand)) { CommandHandlers[pCommand](pConnection, pArguments); } }
public virtual void HandleLogin(ClientConnection pConnection, MaplePacket pPacket) { int error = pPacket.ReadInt(); pPacket.ReadShort(); if (error != 0) { pConnection.Logger_WriteLine("Got Status: {0}", error); if (error == 0x07) { pConnection.Logger_WriteLine("Already logged in!"); } return; } int userid = pPacket.ReadInt(); byte gender = pPacket.ReadByte(); // Gender or GenderSelect/PinSelect pPacket.ReadByte(); short admin = pPacket.ReadShort(); pPacket.ReadInt(); // ReadBytes(4) pPacket.ReadByte(); // 0x95 string username = pPacket.ReadString(); // Username pPacket.ReadByte(); // 0? byte qban = pPacket.ReadByte(); // Quiet Ban DateTime qban_time = DateTime.FromFileTime(pPacket.ReadLong()); // Quiet Ban Time DateTime creationtime = DateTime.FromFileTime(pPacket.ReadLong()); // Creation Time pPacket.ReadInt(); // 78? pPacket.Skip(2); // 1 1 pPacket.ReadBytes(8); // CC key ParseLogin(pConnection, userid, username, creationtime); }
public static ItemBase DecodeItemData(ClientConnection pConnection, MaplePacket pPacket) { byte type = pPacket.ReadByte(); ItemBase ret = null; switch (type) { case 1: ret = new ItemEquip(); ret.Amount = 1; break; case 2: ret = new ItemRechargable(); break; case 3: ret = new ItemPet(); ret.Amount = 1; break; default: { Logger.WriteLine("Unkown ItemType: {0}", type); return null; } } ret.Decode(pConnection, pPacket); return ret; }
public override void HandleLogin(ClientConnection pConnection, MaplePacket pPacket) { byte error = pPacket.ReadByte(); if (error != 0) { pConnection.Logger_WriteLine("Got Status: {0}", error); if (error == 0x07) { pConnection.Logger_WriteLine("Already logged in?"); } return; } int userid = pPacket.ReadInt(); pPacket.ReadByte(); // Gender or GenderSelect/PinSelect pPacket.ReadByte(); pPacket.ReadByte(); // Admin? Has bitflag 5 string username = pPacket.ReadString(); // Username pPacket.ReadByte(); pPacket.ReadByte(); DateTime creationtime = DateTime.FromFileTime(pPacket.ReadLong()); // Incorrect :/. Nowhere to be found if (pPacket.ReadBool() == false) pPacket.ReadString(); // Username, with astriks as protection: 'd**mondo2*' pPacket.ReadString(); // wat. if (pPacket.ReadBool()) pPacket.ReadBytes(15); // Every job that can be chosen pPacket.ReadInt(); // YYYYMMDDHH, as in character info -.-? ParseLogin(pConnection, userid, username, creationtime); }
public virtual void HandleVersion(ClientConnection pConnection, MaplePacket pPacket) { byte locale = pPacket.ReadByte(); ushort version = pPacket.ReadUShort(); ushort subversion = pPacket.ReadUShort(); pConnection.Logger_WriteLine("Detected MapleStory version of client: {1}.{2} (locale: {0})", locale, version, subversion); pConnection.MapleVersion = version; pConnection.CharData = null; // Back to the LoginServer!!! if (locale != ServerMapleInfo.LOCALE) { pConnection.Logger_WriteLine("Incompatible MapleStory locale detected!!!!"); pConnection.SendInfoText("Unsupported MapleStory client detected. Mapler.me only supports MapleStory Global version {0} at the moment.", ServerMapleInfo.VERSION); // This should _never_ happen XD (different encryption and such) pConnection.Disconnect(); } else if (version > ServerMapleInfo.VERSION) { pConnection.Logger_WriteLine("MapleStory client of user is outdated/incorrect. Disconnect."); pConnection.SendInfoText("Your MapleStory client seems outdated. Update your client in order to use the Mapler.me service.\r\nVersion identified: {0}\r\nSupported version: {1}", version, ServerMapleInfo.VERSION); pConnection.Disconnect(); } else if (version < ServerMapleInfo.VERSION) { pConnection.Logger_WriteLine("MapleStory client of user is more up-to-date than Mapler.me service!!!"); pConnection.SendInfoText("As your client is more up-to-date than the Mapler.me service, you are unable to use the Mapler.me service at this time.\r\nCheck the Mapler.me website and/or Twitter (@maplerme) for updates!\r\n\r\nCurrently supported version: {0}\r\nYour version: {1}", ServerMapleInfo.VERSION, version); pConnection.Disconnect(); } }
public void Decode(ClientConnection pConnection, MaplePacket pPacket) { var v = pPacket.ReadByte(); // ? Running = new Dictionary<ushort, string>(); Done = new Dictionary<ushort, long>(); for (int i = pPacket.ReadShort(); i > 0; i--) { Running.Add(pPacket.ReadUShort(), pPacket.ReadString()); } if (v == 0) { for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); // UNK lol } } for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadString(); // 1NX1702337 pPacket.ReadString(); // '1' or '0 ' ?! } var hurr = pPacket.ReadByte(); // ? // ADDED IN v.128 !!!! for (int i = pPacket.ReadShort(); i > 0; i--) { // New method of creating dates... var id = pPacket.ReadUShort(); var date = pPacket.ReadUInt(); long ft = DecodeTimeFromInt(pConnection, date); if (!Done.ContainsKey(id)) Done.Add(id, ft); else pConnection.Logger_WriteLine("Duplicate Quest (Done): {0}", id); } if (hurr == 0) { for (int i = pPacket.ReadShort(); i > 0; i--) { Done.Add(pPacket.ReadUShort(), pPacket.ReadLong()); } } }
public void DeleteItemChecksum(ClientConnection pConnection, ushort pInventory, short pSlot) { var info = GetCharInfoByIDAndWorldID(pConnection.CharacterID, pConnection.WorldID); if (info == null) throw new Exception("DeleteItemChecksum when character not found? ID: " + pConnection.CharacterID + "; WorldID: " + pConnection.WorldID); if (!info.SlotHashes.ContainsKey(pInventory)) return; if (!info.SlotHashes[pInventory].ContainsKey(pSlot)) return; info.SlotHashes[pInventory].Remove(pSlot); }
private long DecodeTimeFromInt(ClientConnection pConnection, uint pValue) { long ft = 0; DateTime temp; if (DateTime.TryParseExact(pValue.ToString(), "yyMMddHHmm", provider, DateTimeStyles.None, out temp)) ft = temp.ToFileTime(); else { pConnection.Logger_WriteLine("Unable to parse {0} as date. GG nexon.", pValue); ft = 150842304000000000L; // GG Nexon. } return ft; }
public virtual void HandleCharacterLoadRequest(ClientConnection pConnection, MaplePacket pPacket) { if (!(pConnection.ConnectedToPort >= 8585 && pConnection.ConnectedToPort <= 8600)) { pConnection.Logger_WriteLine("Ignoring Character Load Request; not connected to a channel server"); return; } int characterid = pPacket.ReadInt(); byte[] machineid = pPacket.ReadBytes(16); pConnection.MachineID = machineid; if (pConnection.UserID == -1) { SessionRestartCache.Instance.TryRestartSession(pConnection, characterid, machineid); } }
public virtual void Decode(ClientConnection pConnection, MaplePacket pPacket) { ItemID = pPacket.ReadInt(); if (pPacket.ReadBool()) { CashID = pPacket.ReadLong(); } else { CashID = 0; } Expires = pPacket.ReadLong(); BagID = pPacket.ReadInt(); }
public static void HandleTokenCheck(ClientConnection pConnection, MaplePacket pPacket) { string token = pPacket.ReadString(); bool okay = false; int accountid = -1; okay = Queries.CheckAccountToken(token, out accountid); if (!okay) { pConnection.Logger_ErrorLog("Kicked client; token was not valid."); pConnection.Disconnect(); return; } else { pConnection.Logger_WriteLine("Accepted client. Logged in with account ID {0}", accountid); pConnection.AccountID = accountid; } }
public virtual void HandleKeymapUpdate(ClientConnection pConnection, MaplePacket pPacket) { int mode = pPacket.ReadInt(); if (mode == 0) { Dictionary<byte, KeyValuePair<byte, int>> modifieds = new Dictionary<byte, KeyValuePair<byte, int>>(); int amount = pPacket.ReadInt(); for (int i = 0; i < amount; i++) { int idx = pPacket.ReadInt(); byte type = pPacket.ReadByte(); int value = pPacket.ReadInt(); if (idx < 0 || idx > ServerMapleInfo.KEYMAP_SLOTS) { pConnection.Logger_WriteLine("ERROR: Keymap contained invalid index!"); return; } if (modifieds.ContainsKey((byte)idx)) continue; // -.-'' modifieds.Add((byte)idx, new KeyValuePair<byte, int>(type, value)); } if (modifieds.Count == 0) return; StringBuilder sb = new StringBuilder(); sb.Append("UPDATE character_keymaps SET "); foreach (var kvp in modifieds) sb.AppendFormat("map_{0}_type = {1}, map_{0}_value = {2},", kvp.Key, kvp.Value.Key, kvp.Value.Value); sb.Append(" WHERE character_id = " + pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(sb.ToString().Replace(", WHERE", " WHERE")); } }
private static long FlaggedValue(ClientConnection pConnection, int pItemID, uint pValue, uint pFlag, MaplePacket pPacket, long pTypeValue, bool pLogIfFound = false) { if (pValue.HasFlag(pFlag)) { var val = pPacket.ReadLong(); if (pLogIfFound) pConnection.Logger_WriteLine("Found flag {3} {0:X8}: {1} | ItemID: {2}", pFlag, val, pItemID, pTypeValue.GetType().Name); return val; } else return 0; }
public void Decode(ClientConnection pConnection, MaplePacket pPacket) { ID = pPacket.ReadShort(); ItemID = pPacket.ReadInt(); Level = (byte)pPacket.ReadInt(); }
public void DecodePQ(ClientConnection pConnection, MaplePacket pPacket) { PartyQuestsRunning = new Dictionary<ushort, string>(); for (int i = pPacket.ReadShort(); i > 0; i--) { ushort id = pPacket.ReadUShort(); string value = pPacket.ReadString(); if (!PartyQuestsRunning.ContainsKey(id)) PartyQuestsRunning.Add(id, value); else pConnection.Logger_WriteLine("Duplicate PQ (Running): {0}", id); } }
public void Decode(ClientConnection pConnection, MaplePacket pPacket) { InventorySlots = new byte[INVENTORIES]; for (int i = 0; i < INVENTORIES; i++) InventorySlots[i] = pPacket.ReadByte(); pPacket.ReadLong(); // 94354848000000000 | 1-1-1900 EquipmentItems = new Dictionary<short, ItemEquip>[EQUIP_INVENTORIES]; #if LOCALE_EMS for (byte i = 0; i < 3; i++) { EquipmentItems[i] = new Dictionary<short, ItemEquip>(); while (true) { short slot = pPacket.ReadShort(); if (slot == 0) break; slot = CharacterInventory.CorrectEquipSlot(i, slot); ItemEquip equip = (ItemEquip)ItemBase.DecodeItemData(pConnection, pPacket); EquipmentItems[i].Add(slot, equip); } } pPacket.ReadBool(); // EMS only -.- for (byte i = 3; i < EQUIP_INVENTORIES; i++) { EquipmentItems[i] = new Dictionary<short, ItemEquip>(); while (true) { short slot = pPacket.ReadShort(); if (slot == 0) break; slot = CharacterInventory.CorrectEquipSlot(i, slot); ItemEquip equip = (ItemEquip)ItemBase.DecodeItemData(pConnection, pPacket); EquipmentItems[i].Add(slot, equip); } } #else for (byte i = 0; i < EQUIP_INVENTORIES; i++) { EquipmentItems[i] = new Dictionary<short, ItemEquip>(); while (true) { short slot = pPacket.ReadShort(); if (slot == 0) break; slot = CharacterInventory.CorrectEquipSlot(i, slot); ItemEquip equip = (ItemEquip)ItemBase.DecodeItemData(pConnection, pPacket); EquipmentItems[i].Add(slot, equip); } } #endif InventoryItems = new Dictionary<byte, ItemBase>[NORMAL_INVENTORIES]; BagItems = new Dictionary<int, BagItem>(); for (byte i = 0; i < NORMAL_INVENTORIES; i++) { InventoryItems[i] = new Dictionary<byte, ItemBase>(); while (true) { byte slot = pPacket.ReadByte(); if (slot == 0) break; ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket); InventoryItems[i].Add(slot, item); if (item.BagID != -1) { // Update BagID... O.o item.BagID = GameHelper.GetBagID(item.BagID, i); BagItem bi = new BagItem(item); BagItems.Add(item.BagID, bi); } } } // Bagzzz for (int inv = 3; inv <= 4; inv++) { var bags = pPacket.ReadInt(); for (int i = 0; i < bags; i++) { int bagid = pPacket.ReadInt(); int bagitemid = pPacket.ReadInt(); BagItem bi = BagItems[GameHelper.GetBagID(bagid, inv - 2)]; // No addition to inv...! while (true) { int slotid = pPacket.ReadInt(); if (slotid == -1) break; ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket); bi.Items.Add((byte)slotid, item); } } } }
public void PushLevelUP(ClientConnection pConnection, byte pNewLevel) { Push(Types.LevelUP, pConnection.AccountID, pConnection.CharacterInternalID, pNewLevel.ToString()); }
public override void HandleStatUpdate(ClientConnection pConnection, MaplePacket pPacket) { pPacket.ReadByte(); long updateFlag = pPacket.ReadLong(); if (updateFlag == 0) { return; // Fake Update -.- / Unstuck } bool didsomething = false; if (CheckFlag(updateFlag, 1)) // Skin { didsomething = true; pConnection.CharData.Stats.Skin = pPacket.ReadByte(); } if (CheckFlag(updateFlag, 2)) // Eyes { didsomething = true; pConnection.CharData.Stats.Face = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 4)) // Eyes { didsomething = true; pConnection.CharData.Stats.Hair = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 0x10)) { didsomething = true; var level = pPacket.ReadByte(); Timeline.Instance.PushLevelUP(pConnection, level); pConnection.CharData.Stats.Level = level; pConnection.Logger_WriteLine("{0} leveled up to level {1}!!!", pConnection.CharData.Stats.Name, level); } if (CheckFlag(updateFlag, 0x20)) { didsomething = true; var jobid = pPacket.ReadShort(); Timeline.Instance.PushJobUP(pConnection, (ushort)jobid); pConnection.CharData.Stats.JobID = jobid; pConnection.Logger_WriteLine("{0} changed to job {1}!!!", pConnection.CharData.Stats.Name, jobid); } if (CheckFlag(updateFlag, 0x40)) { didsomething = true; pConnection.CharData.Stats.Str = pPacket.ReadShort(); } if (CheckFlag(updateFlag, 0x80)) { didsomething = true; pConnection.CharData.Stats.Dex = pPacket.ReadShort(); } if (CheckFlag(updateFlag, 0x100)) { didsomething = true; pConnection.CharData.Stats.Int = pPacket.ReadShort(); } if (CheckFlag(updateFlag, 0x200)) { didsomething = true; pConnection.CharData.Stats.Luk = pPacket.ReadShort(); } if (CheckFlag(updateFlag, 0x400)) { didsomething = true; pConnection.CharData.Stats.HP = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 0x800)) { didsomething = true; pConnection.CharData.Stats.MaxHP = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 0x1000)) { didsomething = true; pConnection.CharData.Stats.MP = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 0x2000)) { didsomething = true; pConnection.CharData.Stats.MaxMP = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 0x4000)) { didsomething = true; pConnection.CharData.Stats.AP = pPacket.ReadShort(); } if (CheckFlag(updateFlag, 0x8000)) { didsomething = true; short a1 = pConnection.CharData.Stats.JobID; pConnection.CharData.Stats.SPData.Clear(); if (GameHelper.IsExtendedSPJob(pConnection.CharData.Stats.JobID)) { byte amnt = pPacket.ReadByte(); List <byte> haslist = new List <byte>(); for (int j = 0; j < amnt; j++) { byte v1 = pPacket.ReadByte(); // Job ID int v2 = pPacket.ReadInt(); // Amount pConnection.CharData.Stats.SPData.Add(new KeyValuePair <byte, int>(v1, v2)); haslist.Add(v1); } for (byte j = 1; j < 20; j++) { if (!haslist.Contains(j)) { pConnection.CharData.Stats.SPData.Add(new KeyValuePair <byte, int>(j, 0)); } } } else { pConnection.CharData.Stats.SPData.Add(new KeyValuePair <byte, int>(0, pPacket.ReadShort())); } } if (CheckFlag(updateFlag, 0x10000)) { didsomething = true; long newexp = pPacket.ReadLong(); byte point = (byte)EXPTable.GetLevelPercentage(pConnection.CharData.Stats.Level, newexp); if (pConnection.LastExpPoint != point) { // Ohhh Timeline.Instance.PushExpPoint(pConnection, point); } pConnection.CharData.Stats.EXP = newexp; pConnection.LastExpPoint = point; } if (CheckFlag(updateFlag, 0x20000)) { didsomething = true; int fame = pPacket.ReadInt(); Timeline.Instance.PushGotFame(pConnection, fame - pConnection.CharData.Stats.Fame, fame); pConnection.CharData.Stats.Fame = fame; } if (CheckFlag(updateFlag, 0x40000)) { didsomething = true; pConnection.CharData.Stats.Mesos = pPacket.ReadLong(); } // EMS Weird stuff if (CheckFlag(updateFlag, 0x80000)) { var value = pPacket.ReadLong(); pConnection.Logger_WriteLine("0x80000 | {0}", value); } if (CheckFlag(updateFlag, 0x100000)) { var value = pPacket.ReadByte(); pConnection.Logger_WriteLine("0x100000 | {0}", value); } if (CheckFlag(updateFlag, 0x200000)) { // Ambition/Charisma D: pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Charisma] = pPacket.ReadInt(); } if (CheckFlag(updateFlag, 0x400000)) { pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Insight] = pPacket.ReadInt(); didsomething = true; } if (CheckFlag(updateFlag, 0x800000)) { pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Willpower] = pPacket.ReadInt(); didsomething = true; } if (CheckFlag(updateFlag, 0x1000000)) { pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.CraftDiligence] = pPacket.ReadInt(); didsomething = true; } if (CheckFlag(updateFlag, 0x2000000)) { pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Empathy] = pPacket.ReadInt(); didsomething = true; } if (CheckFlag(updateFlag, 0x4000000)) { pConnection.CharData.Stats.Traits[(int)GW_CharacterStat.TraitVals.Charm] = pPacket.ReadInt(); didsomething = true; } if (CheckFlag(updateFlag, 0x8000000)) { pPacket.ReadBytes(21); } if (CheckFlag(updateFlag, 0x10000000)) { pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); } if (CheckFlag(updateFlag, 0x20000000)) { for (byte i = 0; i < 9; i++) { pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); } } if (CheckFlag(updateFlag, 0x40000000)) { var value1 = pPacket.ReadInt(); var value2 = pPacket.ReadByte(); var value3 = pPacket.ReadInt(); pConnection.Logger_WriteLine("0x40000000 | {0} | {1} | {2}", value1, value2, value3); } if (CheckFlag(updateFlag, 0x80000000)) { var value1 = pPacket.ReadByte(); var value2 = pPacket.ReadByte(); pConnection.Logger_WriteLine("0x80000000 | {0} | {1}", value1, value2); } if (CheckFlag(updateFlag, 0x100000000)) { var value = pPacket.ReadInt(); pConnection.Logger_WriteLine("0x100000000 | {0}", value); } if (CheckFlag(updateFlag, 0x200000000)) { var value = pPacket.ReadInt(); pConnection.Logger_WriteLine("0x200000000 | {0}", value); } if (didsomething) { pConnection.CharData.SaveCharacterInfo(pConnection); pConnection.SendTimeUpdate(); } }
public bool SaveData(ClientConnection pConnection) { int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection); if (internalid == -1) { // Failure! return false; } using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID); if (info != null) { // Update info! pConnection.CharacterID = Stats.ID; CharacterInventory inventory = Inventory; for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { short slot = equipdata.Key; var equip = equipdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot)) { int hash = info.SlotHashes[0][slot]; int objhash = equipdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[0].Remove(slot); } else { addrow = true; } if (addrow) Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true); } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i + 1][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i + 1].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)bag.Key; foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done bag items"); { string removequery = ""; bool added = false; foreach (var hashlist in info.SlotHashes) { foreach (var leftovers in hashlist.Value) { pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key); added = true; removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid); } } if (added) { System.IO.File.WriteAllText("removequery.sql", removequery); MySQL_Connection.Instance.RunQuery(removequery); } } } else { pConnection.Logger_WriteLine("Saving Items"); pConnection.CharacterInternalID = internalid; pConnection.CharacterID = Stats.ID; string itemlist = ""; itemlist += "INSERT INTO items VALUES "; List<string> querylist = new List<string>(); for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { var equip = equipdata.Value; Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true); } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)(bag.Key); foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done bag items"); AccountDataCache.Instance.LoadBaseData(Stats.Name); } itemsTable.RunQuery(); pConnection.Logger_WriteLine("Saved item data"); petTable.RunQuery(); pConnection.Logger_WriteLine("Saved pet data"); AccountDataCache.Instance.LoadInventoryHashes(internalid, true); MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.Running) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery("insert-update-quests.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.Done) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery("insert-update-quests-done.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.PartyQuestsRunning) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.PartyQuestsDone) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid); using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills")) { skillTable.OnDuplicateUpdate = true; skillTable.AddColumn("character_id", false); skillTable.AddColumn("skillid", false); skillTable.AddColumn("level", true); skillTable.AddColumn("maxlevel", true); skillTable.AddColumn("expires", true); foreach (var skill in Skills.SkillList) { skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration); } skillTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid); using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data")) { spTable.OnDuplicateUpdate = true; spTable.AddColumn("character_id", false); spTable.AddColumn("slot", false); spTable.AddColumn("amount", true); foreach (var kvp in Stats.SPData) { spTable.AddRow(internalid, kvp.Key, kvp.Value); } spTable.RunQuery(); } using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations")) { teleportRocks.OnDuplicateUpdate = true; teleportRocks.AddColumn("character_id"); for (int i = 0; i < 41; i++) teleportRocks.AddColumn("map" + i, true); teleportRocks.AddRowUnsafe( pConnection.CharacterInternalID, Inventory.TeleportRocks.ToList() ); teleportRocks.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid); using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels")) { table.AddColumn("character_id"); table.AddColumn("block"); table.AddColumn("index"); table.AddColumn("card", true); table.AddColumn("level", true); foreach (var card in EvolutionCards) { table.AddRow( pConnection.CharacterInternalID, card.Block, card.ID, card.ItemID, card.Level ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings")) { table.AddColumn("character_id"); table.AddColumn("friend_name"); table.AddColumn("cashid1"); table.AddColumn("cashid2"); table.AddColumn("type"); foreach (var ring in Rings) { string type = ""; switch (ring.RingType) { case Ring.Type.Couple: type = "couple"; break; case Ring.Type.Marriage: type = "marriage"; break; case Ring.Type.Friend: type = "friend"; break; } table.AddRow( pConnection.CharacterInternalID, ring.FriendName, ring.RingCashID1, ring.RingCashID1, type ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities")) { table.AddColumn("character_id"); table.AddColumn("id"); table.AddColumn("skill_id"); table.AddColumn("level"); foreach (var stat in Abilities) { table.AddRow( pConnection.CharacterInternalID, stat.Item1, stat.Item2, stat.Item3 ); } table.RunQuery(); } return true; } }
public void PushGotFame(ClientConnection pConnection, int pAdd, int pNewFame) { Push(Types.GotFame, pConnection.AccountID, pConnection.CharacterInternalID, pAdd + ";" + pNewFame); }
public virtual void HandleInventoryUpdate(ClientConnection pConnection, MaplePacket pPacket) { CharacterInventory inventory = pConnection.CharData.Inventory; byte type1 = pPacket.ReadByte(); byte items = pPacket.ReadByte(); byte type3 = pPacket.ReadByte(); if (type3 == 0) // Add or update item { for (var amnt = 0; amnt < items; amnt++) { byte type4 = pPacket.ReadByte(); byte inv = pPacket.ReadByte(); short slot = pPacket.ReadShort(); inv -= 1; if (type4 == 0) // New Item { ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket); if (inv == 0) { // Equip byte internalInventory = CharacterInventory.GetEquipInventoryFromSlot(slot); slot = CharacterInventory.CorrectEquipSlot(internalInventory, slot); if (!inventory.EquipmentItems[internalInventory].ContainsKey(slot)) inventory.EquipmentItems[internalInventory].Add(slot, item as ItemEquip); else inventory.EquipmentItems[internalInventory][slot] = item as ItemEquip; } else { if (!inventory.InventoryItems[inv - 1].ContainsKey((byte)slot)) inventory.InventoryItems[inv - 1].Add((byte)slot, item); else inventory.InventoryItems[inv - 1][(byte)slot] = item; } using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) { itemsTable.OnDuplicateUpdate = true; Queries.SaveItem(pConnection, inv, slot, item, itemsTable); itemsTable.RunQuery(); } if (item is ItemPet) { var pet = item as ItemPet; using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { petTable.OnDuplicateUpdate = true; Queries.SavePet(pConnection.CharacterInternalID, pet, petTable); petTable.RunQuery(); } } } else if (type4 == 1) // Update amount { short amount = pPacket.ReadShort(); if (inv == 0) { pConnection.Logger_WriteLine("WUTWUT"); // Should _never_ happen continue; } ItemBase item = inventory.InventoryItems[inv - 1][(byte)slot]; item.Amount = amount; AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, inv, slot, item.GetChecksum()); using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("amount", amount); itemTable.SetColumn("checksum", item.GetChecksum()); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slot); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } else if (type4 == 2) // Swap { short slotfrom = slot; short slotto = pPacket.ReadShort(); bool founditem = false; if (inv == 0) { // Equips! byte internalInventoryFrom = CharacterInventory.GetEquipInventoryFromSlot(slotfrom); byte internalInventoryTo = CharacterInventory.GetEquipInventoryFromSlot(slotto); slotfrom = CharacterInventory.CorrectEquipSlot(internalInventoryFrom, slotfrom); slotto = CharacterInventory.CorrectEquipSlot(internalInventoryTo, slotto); // Switch Equips ItemEquip item = inventory.EquipmentItems[internalInventoryFrom][slotfrom]; if (inventory.EquipmentItems[internalInventoryTo].ContainsKey(slotto)) { inventory.EquipmentItems[internalInventoryFrom][slotfrom] = inventory.EquipmentItems[internalInventoryTo][slotto]; inventory.EquipmentItems[internalInventoryTo].Remove(slotto); // Remove item founditem = true; } else { inventory.EquipmentItems[internalInventoryFrom].Remove(slotfrom); } inventory.EquipmentItems[internalInventoryTo].Add(slotto, item); } else { // Switch Items ItemBase item = inventory.InventoryItems[inv - 1][(byte)slotfrom]; if (inventory.InventoryItems[inv - 1].ContainsKey((byte)slotto)) { inventory.InventoryItems[inv - 1][(byte)slotfrom] = inventory.InventoryItems[inv - 1][(byte)slotto]; inventory.InventoryItems[inv - 1].Remove((byte)slotto); // Remove item founditem = true; } else { inventory.InventoryItems[inv - 1].Remove((byte)slotfrom); } inventory.InventoryItems[inv - 1].Add((byte)slotto, item); } if (founditem) // New slot contained item { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slotto); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotto); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } if (founditem) // Fix other slot { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom); itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } } else if (type4 == 3) { // Drop/delete item. if (inv == 0) { // Equips! byte internalInventory = CharacterInventory.GetEquipInventoryFromSlot(slot); slot = CharacterInventory.CorrectEquipSlot(internalInventory, slot); if (inventory.EquipmentItems[internalInventory].ContainsKey(slot)) { inventory.EquipmentItems[internalInventory].Remove(slot); AccountDataCache.Instance.DeleteItemChecksum(pConnection, 0, slot); } else pConnection.Logger_WriteLine("!!! Could not find item @ {0} {1}", inv, slot); } else { if (inventory.InventoryItems[inv - 1].ContainsKey((byte)slot)) { inventory.InventoryItems[inv - 1].Remove((byte)slot); AccountDataCache.Instance.DeleteItemChecksum(pConnection, (ushort)(inv - 1), slot); } else pConnection.Logger_WriteLine("!!! Could not find item @ {0} {1}", inv, slot); } using (DeleteQueryBuilder itemTable = new DeleteQueryBuilder("items")) { itemTable.SetWhereColumn("inventory", inv); itemTable.SetWhereColumn("slot", slot); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); itemTable.RunQuery(); } } else if (type4 == 4) { pPacket.ReadLong(); // Unknown..? } else if (type4 == 5) { // 'Swap' items from and to bags inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); short to = pPacket.ReadShort(); byte slotto = (byte)(to % 100); byte bagto = (byte)(to / 100); slotfrom -= 1; slotto -= 1; if (bagto == 0) bagto = 255; else bagto -= 1; if (bagfrom == 0) bagfrom = 255; else bagfrom -= 1; ushort invto = bagto == 255 ? inv : GameHelper.GetBagID(bagto, inv); ushort invfrom = bagfrom == 255 ? inv : GameHelper.GetBagID(bagfrom, inv); if ( (bagfrom != 255 && bagto != 255) || (bagfrom == bagto) || // Check if the item is being moved to itself or something (bagfrom == 255 && !inventory.InventoryItems[inv].ContainsKey(slotfrom)) || (bagfrom != 255 && (!inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems[invfrom].Items.ContainsKey(slotfrom))) || (bagto != 255 && !inventory.BagItems.ContainsKey(invto)) // Only check if bag exists ) { pConnection.Logger_WriteLine("Invalid item movement in bag !!!"); continue; } bool founditem = false; if (bagfrom == 255) { // Move to bag ItemBase ib = inventory.InventoryItems[inv][slotfrom]; if (inventory.BagItems[invto].Items.ContainsKey(slotto)) { inventory.InventoryItems[inv][slotfrom] = inventory.BagItems[invto].Items[slotto]; inventory.BagItems[invto].Items.Remove(slotto); founditem = true; } inventory.BagItems[invto].Items.Add(slotto, ib); } else { // Move to normal slot ItemBase ib = inventory.BagItems[invfrom].Items[slotfrom]; if (inventory.InventoryItems[inv].ContainsKey(slotto)) { inventory.BagItems[invfrom].Items[slotfrom] = inventory.InventoryItems[inv][slotto]; inventory.InventoryItems[inv].Remove(slotto); } inventory.InventoryItems[inv].Add(slotto, ib); using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) { itemsTable.OnDuplicateUpdate = true; Queries.SaveItem(pConnection, inv, slot, ib, itemsTable); itemsTable.RunQuery(); } } /* * Item A: item being used to move/swap | inv 3, slot 21 (Etc) | slotfrom, invfrom * Item B: item that is being swapped with A | inv 11, slot 3 (Bag 2) | slotto, invto * * Move B to a temp slot, to the new inventory: inv 11 -> inv 3, slot 3 -> slot 3021 * Move A to B: inv 3 -> inv 11, slot 21 -> slot 3 * Move B to A: slot 3021 -> slot 21 * */ if (founditem) // New slot contained item { // Temporary moving item using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom + 3000); itemTable.SetColumn("inventory", invfrom); itemTable.SetWhereColumn("inventory", invto); itemTable.SetWhereColumn("slot", slotto); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotto); itemTable.SetColumn("inventory", invto); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } if (founditem) // Fix other slot { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } } else if (type4 == 6) { // Update bag item amount inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); short amount = pPacket.ReadShort(); slotfrom -= 1; if (bagfrom == 0) { pConnection.Logger_WriteLine("Invalid item bag!"); continue; } else bagfrom -= 1; ushort invfrom = GameHelper.GetBagID(bagfrom, inv); if ( !inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems[invfrom].Items.ContainsKey(slotfrom) ) { pConnection.Logger_WriteLine("Invalid item movement in bag (item did not exist)!!!"); continue; } ItemBase item = inventory.BagItems[invfrom].Items[slotfrom]; item.Amount = amount; AccountDataCache.Instance.SetChecksumOfSlot(pConnection.CharacterID, pConnection.WorldID, inv, slot, item.GetChecksum()); using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("amount", amount); itemTable.SetColumn("checksum", item.GetChecksum()); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slot); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } else if (type4 == 7) { // Delete/drop bag item D: inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); slotfrom -= 1; bagfrom -= 1; ushort invfrom = GameHelper.GetBagID(bagfrom, inv); using (DeleteQueryBuilder itemTable = new DeleteQueryBuilder("items")) { itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } else if (type4 == 8) { // Swap/move item in bags inv -= 1; short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); short to = pPacket.ReadShort(); byte slotto = (byte)(to % 100); byte bagto = (byte)(to / 100); slotfrom -= 1; slotto -= 1; bagto -= 1; bagfrom -= 1; ushort invto = GameHelper.GetBagID(bagto, inv); ushort invfrom = GameHelper.GetBagID(bagfrom, inv); if (!inventory.BagItems.ContainsKey(invfrom) || !inventory.BagItems.ContainsKey(invto)) { pConnection.Logger_WriteLine("Invalid item movement in bag"); continue; } if (!inventory.BagItems[invfrom].Items.ContainsKey(slotfrom)) { pConnection.Logger_WriteLine("Invalid item movement in bag (item not found)"); continue; } ItemBase item = inventory.BagItems[invfrom].Items[slotfrom]; bool founditem = false; if (inventory.BagItems[invto].Items.ContainsKey(slotto)) { // Swap inventory.BagItems[invfrom].Items[slotfrom] = inventory.BagItems[invto].Items[slotto]; inventory.BagItems[invto].Items.Remove(slotto); // Delete item founditem = true; } inventory.BagItems[invto].Items.Add(slotto, item); if (founditem) // New slot contained item { // Temporary moving item using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom + 3000); itemTable.SetColumn("inventory", invfrom); itemTable.SetWhereColumn("inventory", invto); itemTable.SetWhereColumn("slot", slotto); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotto); itemTable.SetColumn("inventory", invto); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } if (founditem) // Fix other slot { using (UpdateQueryBuilder itemTable = new UpdateQueryBuilder("items")) { itemTable.SetColumn("slot", slotfrom); itemTable.SetWhereColumn("inventory", invfrom); itemTable.SetWhereColumn("slot", slotfrom + 3000); itemTable.SetWhereColumn("character_id", pConnection.CharacterInternalID); MySQL_Connection.Instance.RunQuery(itemTable.ToString()); } } } else if (type4 == 9) { // Add item directly to bag inv -= 1; ItemBase item = ItemBase.DecodeItemData(pConnection, pPacket); short from = slot; byte slotfrom = (byte)(from % 100); byte bagfrom = (byte)(from / 100); slotfrom -= 1; bagfrom -= 1; ushort invfrom = GameHelper.GetBagID(bagfrom, inv); if (!inventory.BagItems.ContainsKey(invfrom)) continue; inventory.BagItems[invfrom].Items[slotfrom] = item; using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) { itemsTable.OnDuplicateUpdate = true; Queries.SaveItem(pConnection, invfrom, slotfrom, item, itemsTable); itemsTable.RunQuery(); } if (item is ItemPet) { var pet = item as ItemPet; using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { petTable.OnDuplicateUpdate = true; Queries.SavePet(pConnection.CharacterInternalID, pet, petTable); petTable.RunQuery(); } } } else if (type4 == 10) { pConnection.Logger_WriteLine("Player probably removed some bag item... O.o?"); } } } pConnection.SendTimeUpdate(); }
public void PushExpPoint(ClientConnection pConnection, int pVal) { Push(Types.EXPPoint, pConnection.AccountID, pConnection.CharacterInternalID, pVal.ToString() + ";" + pConnection.CharData.Stats.MapID); }
public void Decode(ClientConnection pConnection, MaplePacket pPacket) { if (pPacket.ReadBool()) { for (short i = pPacket.ReadShort(); i > 0; i--) { Skill skill = new Skill(); skill.ID = pPacket.ReadInt(); skill.Level = pPacket.ReadInt(); skill.Expiration = pPacket.ReadLong(); if (GameHelper.is_skill_need_master_level(skill.ID)) { skill.MasterLevel = pPacket.ReadInt(); } else { skill.MasterLevel = -1; } if (SkillList.ContainsKey(skill.ID)) // NEXON { pConnection.Logger_WriteLine("Found duplicate skill {0}", skill.ID); } else { SkillList.Add(skill.ID, skill); } } // Link skills for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadShort(); } } else { pConnection.Logger_WriteLine("Character has 'new' skilllist!"); // 0.0 for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); } for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); } for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadLong(); } for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); } for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); } for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); } } short amnt = pPacket.ReadShort(); for (short i = 0; i < amnt; i++) { Cooldowns.Add(pPacket.ReadInt(), pPacket.ReadInt()); } }
public virtual void HandleInventorySlotsUpdate(ClientConnection pConnection, MaplePacket pPacket) { CharacterInventory inventory = pConnection.CharData.Inventory; byte inv = pPacket.ReadByte(); byte newslots = pPacket.ReadByte(); if (inv < 1 || inv > 5) return; if (newslots < 24 || newslots > 96) return; // Just to be sure inventory.InventorySlots[inv - 1] = newslots; string slotname = ""; switch (inv) { case 1: slotname = "eqp"; break; case 2: slotname = "use"; break; case 3: slotname = "setup"; break; case 4: slotname = "etc"; break; case 5: slotname = "cash"; break; } MySQL_Connection.Instance.RunQuery(string.Format("UPDATE characters SET {0}_slots = {1} WHERE internal_id = {2}", slotname, newslots, pConnection.CharacterInternalID)); pConnection.SendTimeUpdate(); }
public void Decode(ClientConnection pConnection, MaplePacket pPacket) { pPacket.Skip(8); // Flag #if LOCALE_GMS pPacket.Skip(1); #endif { // Added GMS V.132 pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } #if LOCALE_EMS pPacket.Skip(1); #endif int tmp = pPacket.ReadByte(); pPacket.Skip(tmp * 4); tmp = pPacket.ReadInt(); pPacket.Skip(tmp * (4 + 8)); #if LOCALE_GMS pPacket.Skip(1); #endif if (pPacket.ReadBool()) { tmp = pPacket.ReadInt(); pPacket.Skip(tmp * 8); tmp = pPacket.ReadInt(); pPacket.Skip(tmp * 8); } Stats = new GW_CharacterStat(); Stats.Decode(pPacket); this.BuddylistSize = pPacket.ReadByte(); #if LOCALE_EMS pPacket.ReadByte(); #endif if (pPacket.ReadBool()) { BlessingOfTheFairy = pPacket.ReadString(); } else { BlessingOfTheFairy = null; } if (pPacket.ReadBool()) { BlessingOfEmpress = pPacket.ReadString(); } else { BlessingOfEmpress = null; } if (pPacket.ReadBool()) { UltimateExplorer = pPacket.ReadString(); } else { UltimateExplorer = null; } Stats.DecodeMesos(pPacket); // .-. #if LOCALE_EMS pPacket.ReadByte(); // Bool check pPacket.ReadInt(); #endif // Unknown stuff here for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadLong(); } #if LOCALE_GMS // Magical potion pots!!! for (int i = pPacket.ReadInt(); i > 0; i--) // V.126 { pPacket.ReadInt(); // Potion pot ID pPacket.ReadInt(); // Max value pPacket.ReadInt(); // HP pPacket.ReadInt(); // ??? (Not max value of MP) pPacket.ReadInt(); // MP pPacket.ReadLong(); // Start date O.o? pPacket.ReadLong(); // End date O.o? } #endif #if LOCALE_GMS // V.142 - RED stuff? for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); } { pPacket.ReadInt(); for (int i = 3; i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); } } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); } if (pPacket.ReadBool()) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadLong(); pPacket.ReadLong(); pPacket.ReadLong(); } for (int j = 0; j < 2; j++) // called 2 times under each other! { for (int i = pPacket.ReadByte(); i > 0; i--) { pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadString(); } } #endif #if LOCALE_EMS // REMOVED GMS V.141?! for (int i = pPacket.ReadInt(); i > 0; i--) // V.137 { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } pPacket.ReadInt(); for (int i = 6; i > 0; i--) { pPacket.ReadInt(); } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadString(); } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadString(); } #endif Inventory = new CharacterInventory(); Inventory.Decode(pConnection, pPacket); //UnknownIntegerListNumber3 = new Dictionary<int, long>(); for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadLong(); //UnknownIntegerListNumber3.Add(pPacket.ReadInt(), pPacket.ReadLong()); } //UnknownIntegerListNumber4 = new Dictionary<long, long>(); for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadLong(); pPacket.ReadLong(); //UnknownIntegerListNumber4.Add(pPacket.ReadLong(), pPacket.ReadLong()); } while (true) { byte val = pPacket.ReadByte(); if (val == 0) { break; } { pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadLong(); pPacket.ReadLong(); pPacket.ReadLong(); pPacket.ReadLong(); } } Skills = new CharacterSkills(); Skills.Decode(pConnection, pPacket); Quests = new CharacterQuests(); Quests.Decode(pConnection, pPacket); // Match for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } { Rings = new List <Ring>(); MarriedWith = null; // Couple for (int i = pPacket.ReadShort(); i > 0; i--) { Rings.Add(new Ring(Ring.Type.Couple, pPacket)); } // Friend for (int i = pPacket.ReadShort(); i > 0; i--) { Rings.Add(new Ring(Ring.Type.Friend, pPacket)); } // Marriage for (int i = pPacket.ReadShort(); i > 0; i--) { Ring ring = new Ring(Ring.Type.Marriage, pPacket, Stats.Name); Rings.Add(ring); MarriedWith = ring.FriendName; } } Inventory.DecodeTeleportRocks(pPacket); #if LOCALE_GMS Monsterbook = new CharacterMonsterBook(); Monsterbook.Decode(pPacket); pPacket.ReadInt(); // -1? for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); } { // Newyear cards... meh // WHAT MEH, SOMEONE HAS THIS FFS D:!!! for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); // Card ID? pPacket.ReadInt(); // Sender ID pPacket.ReadString(); // Sender name pPacket.ReadByte(); // GENDER..? pPacket.ReadLong(); // Sent at? pPacket.ReadInt(); // Receiver ID pPacket.ReadString(); // Receiver name pPacket.ReadByte(); pPacket.ReadByte(); pPacket.ReadLong(); // Receive date? pPacket.ReadString(); // Message } } #else for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); pPacket.ReadString(); } #endif Quests.DecodePQ(pConnection, pPacket); if (GameHelper.IsWildHunter(Stats.JobID)) { pPacket.ReadByte(); // Level pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); // Caught mob } Quests.DecodePQDone(pConnection, pPacket); for (int i = pPacket.ReadShort(); i > 0; i--) { short cnt = pPacket.ReadShort(); int unk = pPacket.ReadInt(); // 9010040 | Conor (NPC) if (cnt > 0 && unk > 0) { for (short j = 0; j < cnt; j++) { pPacket.ReadInt(); // 9010040 | Conor (NPC) pPacket.ReadShort(); pPacket.ReadInt(); // 4330019 | Pink Coin Purse pPacket.ReadShort(); } } } for (int i = 13; i > 0; i--) { pPacket.ReadInt(); // Stolen Skills } for (int i = 4; i > 0; i--) { pPacket.ReadInt(); // Chosen Skills? } // Inner Stats Abilities = new List <Tuple <byte, int, byte> >(); for (int i = pPacket.ReadShort(); i > 0; i--) { byte id = pPacket.ReadByte(); // 'ID' int skillid = pPacket.ReadInt(); // Skill ID byte level = pPacket.ReadByte(); // Level pPacket.ReadByte(); // Rank Abilities.Add(new Tuple <byte, int, byte>(id, skillid, level)); } #if LOCALE_GMS { // V.134 for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadString(); pPacket.ReadInt(); pPacket.ReadString(); for (int j = pPacket.ReadInt(); j > 0; j--) { pPacket.ReadByte(); } } pPacket.ReadByte(); } #endif Stats.HonourLevel = pPacket.ReadInt(); Stats.HonourExp = pPacket.ReadInt(); { byte unk = pPacket.ReadByte(); if (unk == 1) { while (true) { tmp = pPacket.ReadUShort(); if (tmp <= 0) { break; } while (true) { ushort tmp2 = pPacket.ReadUShort(); if (tmp2 <= 0) { break; } pPacket.ReadInt(); pPacket.ReadInt(); } } } else { while (true) { tmp = pPacket.ReadUShort(); if (tmp <= 0) { break; } pPacket.ReadUShort(); pPacket.ReadInt(); pPacket.ReadInt(); } } } if (pPacket.ReadBool()) { // Wat. ItemBase.DecodeItemData(pConnection, pPacket); pPacket.ReadInt(); } { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); } { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadLong(); } #if LOCALE_EMS pPacket.ReadBool(); pPacket.ReadBool(); #endif { EvolutionCards = new List <EvolutionCard>(); for (short i = pPacket.ReadShort(); i > 0; i--) { var card = new EvolutionCard(); card.Decode(pConnection, pPacket); card.Block = 1; EvolutionCards.Add(card); } for (short i = pPacket.ReadShort(); i > 0; i--) { var card = new EvolutionCard(); card.Decode(pConnection, pPacket); card.Block = 2; EvolutionCards.Add(card); } } #if LOCALE_EMS if (pPacket.ReadBool()) { // Wat. ItemBase.DecodeItemData(pConnection, pPacket); pPacket.ReadInt(); pPacket.ReadInt(); } #endif #if LOCALE_EMS // No farm info for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.Skip(20); } #else { // V.134 for (byte i = pPacket.ReadByte(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadLong(); } } { // V.134 // FARM INFO. Creating... = not yet created farm. Else: farmname pPacket.ReadString(); // Creating... pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } #if LOCALE_GMS if (pPacket.ReadBool()) { // Wat. ItemBase.DecodeItemData(pConnection, pPacket); pPacket.ReadInt(); pPacket.ReadInt(); } #endif { // V.141 pPacket.ReadInt(); pPacket.ReadLong(); // A bit off here, should be filetime value pPacket.ReadInt(); } pPacket.Skip(84); // I don't even pPacket.ReadByte(); { for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); pPacket.ReadShort(); } } { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.Skip(32); } { if (pPacket.ReadInt() > 0) { for (int i = 0; i < 3; i++) { pPacket.Skip(4 + 4 + 4); pPacket.ReadString(); pPacket.Skip(4 * 7); pPacket.Skip(8 * 4); pPacket.Skip(4 * 4); pPacket.Skip(1 * 5); pPacket.Skip(4 * 3); pPacket.ReadString(); pPacket.Skip(4 * 2); pPacket.ReadByte(); byte tmptmp = pPacket.ReadByte(); if ((tmptmp & 0x01) != 0) { pPacket.ReadInt(); pPacket.ReadString(); pPacket.Skip(24); } for (int j = pPacket.ReadInt(); j > 0; j++) { pPacket.Skip(4 * 9); } } } } // Removed in V.141 //pPacket.ReadInt(); // I DONT EVEN D: #endif }
public override void Decode(ClientConnection pConnection, MaplePacket pPacket) { base.Decode(pConnection, pPacket); Amount = pPacket.ReadShort(); CraftName = pPacket.ReadString(); Flags = pPacket.ReadShort(); int itemtype = ItemID / 10000; if (itemtype == 233 || itemtype == 207 || itemtype == 287 || itemtype == 288 || itemtype == 289) // Stars, Bullets & Familiars UniqueID = pPacket.ReadLong(); }
public void PushSkillUP(ClientConnection pConnection, int pSkill, int pLevel) { Push(Types.SkillUP, pConnection.AccountID, pConnection.CharacterInternalID, string.Format("{0};{1}", pSkill, pLevel)); }
public override void Decode(ClientConnection pConnection, MaplePacket pPacket) { base.Decode(pConnection, pPacket); Petname = pPacket.ReadString(13); Level = pPacket.ReadByte(); Closeness = pPacket.ReadShort(); Fullness = pPacket.ReadByte(); this.Expires = pPacket.ReadLong(); pPacket.Skip(2 + 2 + 4 + 2 + 1 + 4 + 4 + 2); // Last 2: // - int: -1 // - short: 100 // V.132: + 2 }
public static void HandleServerConnectionStatus(ClientConnection pConnection, MaplePacket pPacket) { if (pPacket.ReadBool()) { string ip = pPacket.ReadString(); ushort port = pPacket.ReadUShort(); pConnection.Logger_WriteLine("- Client got connection with MapleStory server @ {0}:{1}", ip, port); pConnection.ConnectedToIP = ip; pConnection.ConnectedToPort = port; if (port == 8484) { pConnection.SendInfoText("Mapler.me is awaiting account check! Happy mapling!"); var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection); if (info != null) SessionRestartCache.Instance.RemoveInfo(info); pConnection.ChannelID = 255; } else { pConnection.SendInfoText("You successfully connected, or are in the Cash Shop!"); } pConnection.ConnectedTimeToServer = MasterThread.CurrentDate; } else { pConnection.Logger_WriteLine("- Client lost connection with MapleStory server"); pConnection.SendInfoText("Maplestory is closed, or not connected properly."); pConnection.ConnectedToIP = "0.0.0.0"; pConnection.ConnectedToPort = 0; if (pConnection.ConnectedTimeToServer != DateTime.MinValue) { var timespan = MasterThread.CurrentDate - pConnection.ConnectedTimeToServer; pConnection.Logger_WriteLine("Player was connected for {0}", timespan); if (timespan.TotalSeconds < 5) { pConnection.Logger_WriteLine("CLIENT PROBABLY FAILED TO CONNECT!!!"); } if (pConnection.CharData != null) { // Probably CC-ing or something. record MySQL_Connection.Instance.RunQuery("INSERT INTO connection_log VALUES " + MySQL_Connection.BuildValuesRow(pConnection.AccountID, pConnection.CharacterInternalID, pConnection.ChannelID, pConnection.ConnectedTimeToServer, new MySQL_Connection.NowType())); } } // Delete if there's session info var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection); if (info != null) SessionRestartCache.Instance.RemoveInfo(info); pConnection.CharData = null; pConnection.CharacterInternalID = -1; pConnection.CharacterID = -1; pConnection.ChannelID = 255; } }
public void DecodePQDone(ClientConnection pConnection, MaplePacket pPacket) { PartyQuestsDone = new Dictionary<ushort, long>(); for (int i = pPacket.ReadShort(); i > 0; i--) { ushort id = pPacket.ReadUShort(); #if LOCALE_EMS var date = pPacket.ReadUInt(); long time = DecodeTimeFromInt(pConnection, date); #else long time = pPacket.ReadLong(); #endif if (!PartyQuestsDone.ContainsKey(id)) PartyQuestsDone.Add(id, time); else pConnection.Logger_WriteLine("Duplicate PQ (Done): {0}", id); } }
public RestartInfo GetInfoForConnection(ClientConnection pConnection) { return Cache.Find((i) => { return (i.CharacterID == pConnection.CharacterID && i.CompareMachineID(pConnection.MachineID) && i.IP == pConnection.IP); }); }
public static void HandleServerConnectionStatus(ClientConnection pConnection, MaplePacket pPacket) { if (pPacket.ReadBool()) { string ip = pPacket.ReadString(); ushort port = pPacket.ReadUShort(); pConnection.Logger_WriteLine("- Client got connection with MapleStory server @ {0}:{1}", ip, port); pConnection.ConnectedToIP = ip; pConnection.ConnectedToPort = port; if (port == 8484) { pConnection.SendInfoText("Mapler.me is awaiting account check! Happy mapling!"); var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection); if (info != null) { SessionRestartCache.Instance.RemoveInfo(info); } pConnection.ChannelID = 255; } else { pConnection.SendInfoText("You successfully connected, or are in the Cash Shop!"); } pConnection.ConnectedTimeToServer = MasterThread.CurrentDate; } else { pConnection.Logger_WriteLine("- Client lost connection with MapleStory server"); pConnection.SendInfoText("Maplestory is closed, or not connected properly."); pConnection.ConnectedToIP = "0.0.0.0"; pConnection.ConnectedToPort = 0; if (pConnection.ConnectedTimeToServer != DateTime.MinValue) { var timespan = MasterThread.CurrentDate - pConnection.ConnectedTimeToServer; pConnection.Logger_WriteLine("Player was connected for {0}", timespan); if (timespan.TotalSeconds < 5) { pConnection.Logger_WriteLine("CLIENT PROBABLY FAILED TO CONNECT!!!"); } if (pConnection.CharData != null) { // Probably CC-ing or something. record MySQL_Connection.Instance.RunQuery("INSERT INTO connection_log VALUES " + MySQL_Connection.BuildValuesRow(pConnection.AccountID, pConnection.CharacterInternalID, pConnection.ChannelID, pConnection.ConnectedTimeToServer, new MySQL_Connection.NowType())); } } // Delete if there's session info var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection); if (info != null) { SessionRestartCache.Instance.RemoveInfo(info); } pConnection.CharData = null; pConnection.CharacterInternalID = -1; pConnection.CharacterID = -1; pConnection.ChannelID = 255; } }
public void TryRestartSession(ClientConnection pConnection, int pCharacterID, byte[] pMachineID) { RestartInfo restartInfo = Cache.Find((i) => { return (i.CharacterID == pCharacterID && i.CompareMachineID(pMachineID) && i.IP == pConnection.IP); }); if (restartInfo != null) { // Found character // NOTE: // When a player/IP has 2 characters with the same ID on 2 different worlds // And the connection resets. And the player changes to the other character. // And a blue moon. Then worlds collide and apocalypse var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(pCharacterID, restartInfo.WorldID); if (info != null) { if (info.AccountID != pConnection.AccountID) { pConnection.Logger_WriteLine("Unable to restore session for {0} (IP: {1})! Account id not the same! (Trying to hack it?)", pCharacterID, pConnection.IP); return; } // Okay. We got this pConnection.WorldID = info.WorldID; pConnection.UserID = info.UserID; // Do not set the IDs of the character // pConnection.CharacterInternalID = info.InternalID; pConnection.Logger_WriteLine("Restored session for characterid {0} world {1} (IP: {2})", pCharacterID, info.WorldID, pConnection.IP); // Scratch him off the cache list Cache.Remove(restartInfo); } else { pConnection.Logger_WriteLine("Unable to restore session for {0} (IP: {1})! Not found in Internal Storage.", pCharacterID, pConnection.IP); } } else { pConnection.Logger_WriteLine("No info found for character id {0} (IP: {1})", pCharacterID, pConnection.IP); } }
static void Main(string[] args) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnexpectedExHandler); Console.CancelKeyPress += Console_CancelKeyPress; Logger.SetLogfile(false); MasterThread.Load("MPLRServer"); try { MySQL_Connection.Initialize(); } catch { Environment.Exit(12); } AccountDataCache.Initialize(); #if LOCALE_GMS GMSKeys.Initialize(); #endif CommandHandler.Initialize(); Timeline.Init(); Random = new System.Random(); { InitializeValidHeaders(); AcceptedIPs = new List <string>(); #if LOCALE_GMS AcceptedIPs.Add("8.31.9"); // GMS #elif LOCALE_EMS AcceptedIPs.Add("109.234.77"); // EMS #endif Clients = new List <ClientConnection>(); StartPinger(); StartCharacterDeleteQueue(); } EXPTable.Load(); SessionRestartCache.Start(); // For clients Acceptor accept = new Acceptor(ServerMapleInfo.MAPLER_PORT, sock => { new ClientConnection(sock); }); // For online check! byte[] OnlineCheckInfo = null; { MaplePacket packet = new MaplePacket(ServerMapleInfo.VERSION); packet.WriteByte(ServerMapleInfo.LOCALE); byte[] temp = packet.ToArray(); OnlineCheckInfo = new byte[temp.Length + 1]; Buffer.BlockCopy(temp, 0, OnlineCheckInfo, 1, temp.Length); OnlineCheckInfo[0] = (byte)(temp.Length + 4); packet.Dispose(); packet = null; } Acceptor acceptCheck = new Acceptor(ServerMapleInfo.MAPLER_PORT_SERVER_INFO, sock => { sock.Send(OnlineCheckInfo); sock.Send(BitConverter.GetBytes(Clients.Count)); sock.Shutdown(System.Net.Sockets.SocketShutdown.Both); sock.Close(); }); Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); Logger.WriteLine("| |"); Logger.WriteLine("| Mapler.me Server |"); Logger.WriteLine("| |"); #if LOCALE_GMS Logger.WriteLine("| GLOBAL |"); #elif LOCALE_EMS Logger.WriteLine("| EUROPE |"); #elif LOCALE_KMS Logger.WriteLine("| KOREA |"); #endif Logger.WriteLine("| |"); Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); Logger.WriteLine("| Build For: {0,3} Locale {1,1} |", ServerMapleInfo.VERSION, ServerMapleInfo.LOCALE); Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); Logger.WriteLine("Accepting connections on {0}, and info requests on {1}", ServerMapleInfo.MAPLER_PORT, ServerMapleInfo.MAPLER_PORT_SERVER_INFO); while (true) { string cmd = Console.ReadLine(); if (cmd == null) { break; // CTRL + C } string[] arguments = cmd.Split(' '); if (arguments.Length >= 1) { switch (arguments[0]) { #if LOCALE_GMS case "getkeys": { GMSKeys.Initialize(); break; } #endif case "reload_store": { MasterThread.Instance.AddCallback(a => { AccountDataCache.Instance.Load(); }); break; } case "request_screenshots": { MasterThread.Instance.AddCallback(a => { var tmp = new List <ClientConnection>(Clients); foreach (var client in tmp) { using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, 0xEEFE)) { pack.SwitchOver(); client.SendPacket(pack); } } }); break; } case "testsession": { int accountid = arguments.Length > 1 ? Int32.Parse(arguments[1]) : -1; bool raw = arguments.Length > 2; var verp = new MSBLoader(); var connection = new ClientConnection(verp); connection.AccountID = accountid; verp.Parse("Savefile.msb", raw); break; } case "players": { string names = string.Join(", ", Clients); Console.WriteLine("Players online:\r\n{0}", names); break; } case "close": case "stop": case "exit": { MasterThread.Instance.AddCallback(a => { var tmp = new List <ClientConnection>(Clients); foreach (var client in tmp) { // client.Save(true, true); client.Disconnect(); } MySQL_Connection.Instance.Stop = true; MasterThread.Instance.Stop = true; }); break; } default: Console.WriteLine("Command not found"); break; } } } }
public override void Decode(ClientConnection pConnection, MaplePacket pPacket) { base.Decode(pConnection, pPacket); List<string> flagsList = new List<string>(); { { uint flag = pPacket.ReadUInt(); this.Slots = FlaggedValue(pConnection, this.ItemID, flag, 0x01, pPacket, this.Slots); this.Scrolls = FlaggedValue(pConnection, this.ItemID, flag, 0x02, pPacket, this.Scrolls); this.Str = FlaggedValue(pConnection, this.ItemID, flag, 0x04, pPacket, this.Str); this.Dex = FlaggedValue(pConnection, this.ItemID, flag, 0x08, pPacket, this.Dex); this.Int = FlaggedValue(pConnection, this.ItemID, flag, 0x10, pPacket, this.Int); this.Luk = FlaggedValue(pConnection, this.ItemID, flag, 0x20, pPacket, this.Luk); this.HP = FlaggedValue(pConnection, this.ItemID, flag, 0x40, pPacket, this.HP); this.MP = FlaggedValue(pConnection, this.ItemID, flag, 0x80, pPacket, this.MP); this.Watk = FlaggedValue(pConnection, this.ItemID, flag, 0x100, pPacket, this.Watk); this.Matk = FlaggedValue(pConnection, this.ItemID, flag, 0x200, pPacket, this.Matk); this.Wdef = FlaggedValue(pConnection, this.ItemID, flag, 0x400, pPacket, this.Wdef); this.Mdef = FlaggedValue(pConnection, this.ItemID, flag, 0x800, pPacket, this.Mdef); this.Acc = FlaggedValue(pConnection, this.ItemID, flag, 0x1000, pPacket, this.Acc); this.Avo = FlaggedValue(pConnection, this.ItemID, flag, 0x2000, pPacket, this.Avo); this.Hands = FlaggedValue(pConnection, this.ItemID, flag, 0x4000, pPacket, this.Hands); this.Speed = FlaggedValue(pConnection, this.ItemID, flag, 0x8000, pPacket, this.Speed); this.Jump = FlaggedValue(pConnection, this.ItemID, flag, 0x10000, pPacket, this.Jump); this.Flags = FlaggedValue(pConnection, this.ItemID, flag, 0x20000, pPacket, this.Flags); this.IncreasesSkills = FlaggedValue(pConnection, this.ItemID, flag, 0x40000, pPacket, this.IncreasesSkills); this.ItemLevel = FlaggedValue(pConnection, this.ItemID, flag, 0x80000, pPacket, this.ItemLevel); this.ItemEXP = FlaggedValue(pConnection, this.ItemID, flag, 0x100000, pPacket, this.ItemEXP); this.Durability = FlaggedValue(pConnection, this.ItemID, flag, 0x200000, pPacket, this.Durability); this.ViciousHammer = FlaggedValue(pConnection, this.ItemID, flag, 0x400000, pPacket, this.ViciousHammer); this.BattleModeDamage = FlaggedValue(pConnection, this.ItemID, flag, 0x800000, pPacket, this.BattleModeDamage); FlaggedValue(pConnection, this.ItemID, flag, 0x1000000, pPacket, (byte)0, true); // Item level changer? FlaggedValue(pConnection, this.ItemID, flag, 0x2000000, pPacket, (short)0, true); // Enhancement buff? FlaggedValue(pConnection, this.ItemID, flag, 0x4000000, pPacket, (int)0, true); FlaggedValue(pConnection, this.ItemID, flag, 0x8000000, pPacket, (byte)0, true); // Required level changer?! FlaggedValue(pConnection, this.ItemID, flag, 0x10000000, pPacket, (byte)0, true); // Yggdrasil Wisdom? FlaggedValue(pConnection, this.ItemID, flag, 0x20000000, pPacket, (byte)0, true); // Final Strike? FlaggedValue(pConnection, this.ItemID, flag, 0x40000000, pPacket, (byte)0, true); // Boss Damage %? FlaggedValue(pConnection, this.ItemID, flag, 0x80000000, pPacket, (byte)0, true); // Ignore Damage %? } { uint flag = pPacket.ReadUInt(); FlaggedValue(pConnection, this.ItemID, flag, 0x01, pPacket, (byte)0, true); // Total damage? FlaggedValue(pConnection, this.ItemID, flag, 0x02, pPacket, (byte)0, true); // All stats? this.MaxScissors = FlaggedValue(pConnection, this.ItemID, flag, 0x04, pPacket, this.MaxScissors); FlaggedValue(pConnection, this.ItemID, flag, 0x08, pPacket, (long)0, true); FlaggedValue(pConnection, this.ItemID, flag, 0x10, pPacket, (int)0, true); } } this.Name = pPacket.ReadString(); this.StatusFlags = pPacket.ReadUShort(); // Actually 2 bytes this.Potential1 = pPacket.ReadUShort(); this.Potential2 = pPacket.ReadUShort(); this.Potential3 = pPacket.ReadUShort(); this.Potential4 = pPacket.ReadUShort(); this.Potential5 = pPacket.ReadUShort(); this.Potential6 = pPacket.ReadUShort(); this.DisplayID = pPacket.ReadUShort(); #if LOCALE_GMS this.SocketState = pPacket.ReadUShort(); this.Nebulite1 = pPacket.ReadShort(); this.Nebulite2 = pPacket.ReadShort(); this.Nebulite3 = pPacket.ReadShort(); #else pPacket.ReadShort(); #endif if (CashID == 0) this.UniqueID = pPacket.ReadLong(); else this.UniqueID = 0; pPacket.ReadLong(); // Some weird expiration time pPacket.ReadInt(); // always -1? #if (LOCALE_EMS || LOCALE_GMS) // Prolly RED patch related pPacket.ReadLong(); pPacket.ReadLong(); // This is 94354848000000000; a default date for no expiration. pPacket.ReadInt(); for (int i = 0; i < 3; i++) pPacket.ReadInt(); #endif // Fix setflags if ((this.Flags & 0x80) == 0x80 && this.Name != "") { flagsList.Add("crafted"); } this.SetFlags = string.Join(",", flagsList); }
public void Decode(ClientConnection pConnection, MaplePacket pPacket) { pPacket.Skip(8); // Flag #if LOCALE_GMS pPacket.Skip(1); #endif { // Added GMS V.132 pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } #if LOCALE_EMS pPacket.Skip(1); #endif int tmp = pPacket.ReadByte(); pPacket.Skip(tmp * 4); tmp = pPacket.ReadInt(); pPacket.Skip(tmp * (4 + 8)); #if LOCALE_GMS pPacket.Skip(1); #endif if (pPacket.ReadBool()) { tmp = pPacket.ReadInt(); pPacket.Skip(tmp * 8); tmp = pPacket.ReadInt(); pPacket.Skip(tmp * 8); } Stats = new GW_CharacterStat(); Stats.Decode(pPacket); this.BuddylistSize = pPacket.ReadByte(); #if LOCALE_EMS pPacket.ReadByte(); #endif if (pPacket.ReadBool()) BlessingOfTheFairy = pPacket.ReadString(); else BlessingOfTheFairy = null; if (pPacket.ReadBool()) BlessingOfEmpress = pPacket.ReadString(); else BlessingOfEmpress = null; if (pPacket.ReadBool()) UltimateExplorer = pPacket.ReadString(); else UltimateExplorer = null; Stats.DecodeMesos(pPacket); // .-. #if LOCALE_EMS pPacket.ReadByte(); // Bool check pPacket.ReadInt(); #endif // Unknown stuff here for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadLong(); } #if LOCALE_GMS // Magical potion pots!!! for (int i = pPacket.ReadInt(); i > 0; i--) // V.126 { pPacket.ReadInt(); // Potion pot ID pPacket.ReadInt(); // Max value pPacket.ReadInt(); // HP pPacket.ReadInt(); // ??? (Not max value of MP) pPacket.ReadInt(); // MP pPacket.ReadLong(); // Start date O.o? pPacket.ReadLong(); // End date O.o? } #endif #if LOCALE_GMS // V.142 - RED stuff? for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); } { pPacket.ReadInt(); for (int i = 3; i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); } } for (int i = pPacket.ReadInt(); i > 0; i--) pPacket.ReadInt(); if (pPacket.ReadBool()) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadLong(); pPacket.ReadLong(); pPacket.ReadLong(); } for (int j = 0; j < 2; j++) // called 2 times under each other! { for (int i = pPacket.ReadByte(); i > 0; i--) { pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadString(); } } #endif #if LOCALE_EMS // REMOVED GMS V.141?! for (int i = pPacket.ReadInt(); i > 0; i--) // V.137 { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } pPacket.ReadInt(); for (int i = 6; i > 0; i--) { pPacket.ReadInt(); } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadString(); } for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadString(); } #endif Inventory = new CharacterInventory(); Inventory.Decode(pConnection, pPacket); //UnknownIntegerListNumber3 = new Dictionary<int, long>(); for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadLong(); //UnknownIntegerListNumber3.Add(pPacket.ReadInt(), pPacket.ReadLong()); } //UnknownIntegerListNumber4 = new Dictionary<long, long>(); for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadLong(); pPacket.ReadLong(); //UnknownIntegerListNumber4.Add(pPacket.ReadLong(), pPacket.ReadLong()); } while (true) { byte val = pPacket.ReadByte(); if (val == 0) break; { pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadLong(); pPacket.ReadLong(); pPacket.ReadLong(); pPacket.ReadLong(); } } Skills = new CharacterSkills(); Skills.Decode(pConnection, pPacket); Quests = new CharacterQuests(); Quests.Decode(pConnection, pPacket); // Match for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } { Rings = new List<Ring>(); MarriedWith = null; // Couple for (int i = pPacket.ReadShort(); i > 0; i--) { Rings.Add(new Ring(Ring.Type.Couple, pPacket)); } // Friend for (int i = pPacket.ReadShort(); i > 0; i--) { Rings.Add(new Ring(Ring.Type.Friend, pPacket)); } // Marriage for (int i = pPacket.ReadShort(); i > 0; i--) { Ring ring = new Ring(Ring.Type.Marriage, pPacket, Stats.Name); Rings.Add(ring); MarriedWith = ring.FriendName; } } Inventory.DecodeTeleportRocks(pPacket); #if LOCALE_GMS Monsterbook = new CharacterMonsterBook(); Monsterbook.Decode(pPacket); pPacket.ReadInt(); // -1? for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); } { // Newyear cards... meh // WHAT MEH, SOMEONE HAS THIS FFS D:!!! for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadInt(); // Card ID? pPacket.ReadInt(); // Sender ID pPacket.ReadString(); // Sender name pPacket.ReadByte(); // GENDER..? pPacket.ReadLong(); // Sent at? pPacket.ReadInt(); // Receiver ID pPacket.ReadString(); // Receiver name pPacket.ReadByte(); pPacket.ReadByte(); pPacket.ReadLong(); // Receive date? pPacket.ReadString(); // Message } } #else for (int i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); pPacket.ReadString(); } #endif Quests.DecodePQ(pConnection, pPacket); if (GameHelper.IsWildHunter(Stats.JobID)) { pPacket.ReadByte(); // Level pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); // Caught mob } Quests.DecodePQDone(pConnection, pPacket); for (int i = pPacket.ReadShort(); i > 0; i--) { short cnt = pPacket.ReadShort(); int unk = pPacket.ReadInt(); // 9010040 | Conor (NPC) if (cnt > 0 && unk > 0) { for (short j = 0; j < cnt; j++) { pPacket.ReadInt(); // 9010040 | Conor (NPC) pPacket.ReadShort(); pPacket.ReadInt(); // 4330019 | Pink Coin Purse pPacket.ReadShort(); } } } for (int i = 13; i > 0; i--) { pPacket.ReadInt(); // Stolen Skills } for (int i = 4; i > 0; i--) { pPacket.ReadInt(); // Chosen Skills? } // Inner Stats Abilities = new List<Tuple<byte, int, byte>>(); for (int i = pPacket.ReadShort(); i > 0; i--) { byte id = pPacket.ReadByte(); // 'ID' int skillid = pPacket.ReadInt(); // Skill ID byte level = pPacket.ReadByte(); // Level pPacket.ReadByte(); // Rank Abilities.Add(new Tuple<byte, int, byte>(id, skillid, level)); } #if LOCALE_GMS { // V.134 for (int i = pPacket.ReadInt(); i > 0; i--) { pPacket.ReadString(); pPacket.ReadInt(); pPacket.ReadString(); for (int j = pPacket.ReadInt(); j > 0; j--) { pPacket.ReadByte(); } } pPacket.ReadByte(); } #endif Stats.HonourLevel = pPacket.ReadInt(); Stats.HonourExp = pPacket.ReadInt(); { byte unk = pPacket.ReadByte(); if (unk == 1) { while (true) { tmp = pPacket.ReadUShort(); if (tmp <= 0) break; while (true) { ushort tmp2 = pPacket.ReadUShort(); if (tmp2 <= 0) break; pPacket.ReadInt(); pPacket.ReadInt(); } } } else { while (true) { tmp = pPacket.ReadUShort(); if (tmp <= 0) break; pPacket.ReadUShort(); pPacket.ReadInt(); pPacket.ReadInt(); } } } if (pPacket.ReadBool()) { // Wat. ItemBase.DecodeItemData(pConnection, pPacket); pPacket.ReadInt(); } { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); } { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadLong(); } #if LOCALE_EMS pPacket.ReadBool(); pPacket.ReadBool(); #endif { EvolutionCards = new List<EvolutionCard>(); for (short i = pPacket.ReadShort(); i > 0; i--) { var card = new EvolutionCard(); card.Decode(pConnection, pPacket); card.Block = 1; EvolutionCards.Add(card); } for (short i = pPacket.ReadShort(); i > 0; i--) { var card = new EvolutionCard(); card.Decode(pConnection, pPacket); card.Block = 2; EvolutionCards.Add(card); } } #if LOCALE_EMS if (pPacket.ReadBool()) { // Wat. ItemBase.DecodeItemData(pConnection, pPacket); pPacket.ReadInt(); pPacket.ReadInt(); } #endif #if LOCALE_EMS // No farm info for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.Skip(20); } #else { // V.134 for (byte i = pPacket.ReadByte(); i > 0; i--) { pPacket.ReadInt(); pPacket.ReadLong(); } } { // V.134 // FARM INFO. Creating... = not yet created farm. Else: farmname pPacket.ReadString(); // Creating... pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadByte(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); } #if LOCALE_GMS if (pPacket.ReadBool()) { // Wat. ItemBase.DecodeItemData(pConnection, pPacket); pPacket.ReadInt(); pPacket.ReadInt(); } #endif { // V.141 pPacket.ReadInt(); pPacket.ReadLong(); // A bit off here, should be filetime value pPacket.ReadInt(); } pPacket.Skip(84); // I don't even pPacket.ReadByte(); { for (short i = pPacket.ReadShort(); i > 0; i--) { pPacket.ReadShort(); pPacket.ReadShort(); } } { pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.ReadInt(); pPacket.Skip(32); } { if (pPacket.ReadInt() > 0) { for (int i = 0; i < 3; i++) { pPacket.Skip(4 + 4 + 4); pPacket.ReadString(); pPacket.Skip(4 * 7); pPacket.Skip(8 * 4); pPacket.Skip(4 * 4); pPacket.Skip(1 * 5); pPacket.Skip(4 * 3); pPacket.ReadString(); pPacket.Skip(4 * 2); pPacket.ReadByte(); byte tmptmp = pPacket.ReadByte(); if ((tmptmp & 0x01) != 0) { pPacket.ReadInt(); pPacket.ReadString(); pPacket.Skip(24); } for (int j = pPacket.ReadInt(); j > 0; j++) { pPacket.Skip(4 * 9); } } } } // Removed in V.141 //pPacket.ReadInt(); // I DONT EVEN D: #endif }
public void PushJobUP(ClientConnection pConnection, ushort pJob) { Push(Types.JobUP, pConnection.AccountID, pConnection.CharacterInternalID, pJob.ToString()); }
public int SaveCharacterInfo(ClientConnection pConnection) { return Queries.AddOrUpdateCharacter(pConnection, Stats.ID, Stats.Name, pConnection.UserID, pConnection.WorldID, pConnection.ChannelID, 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.HonourLevel, Stats.HonourExp, Stats.Mesos, Stats.DemonMark, Stats.Gender, Stats.Skin, Stats.Face, Stats.Hair, Inventory.InventorySlots, BlessingOfTheFairy, BlessingOfEmpress, UltimateExplorer, Stats.Pets, Stats.Traits, MarriedWith ); }
public bool SaveData(ClientConnection pConnection) { int internalid = pConnection.CharacterInternalID = SaveCharacterInfo(pConnection); if (internalid == -1) { // Failure! return(false); } using (InsertQueryBuilder itemsTable = new InsertQueryBuilder("items")) using (InsertQueryBuilder petTable = new InsertQueryBuilder("pets")) { var info = AccountDataCache.Instance.GetCharInfoByIDAndWorldID(Stats.ID, pConnection.WorldID); if (info != null) { // Update info! pConnection.CharacterID = Stats.ID; CharacterInventory inventory = Inventory; for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { short slot = equipdata.Key; var equip = equipdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(0) && info.SlotHashes[0].ContainsKey(slot)) { int hash = info.SlotHashes[0][slot]; int objhash = equipdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[0].Remove(slot); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, 0, slot, equip, itemsTable, true); } } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i + 1) && info.SlotHashes[i + 1].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i + 1][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i + 1].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)bag.Key; foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; bool addrow = false; if (info.SlotHashes.ContainsKey(i) && info.SlotHashes[i].ContainsKey(itemdata.Key)) { int hash = info.SlotHashes[i][itemdata.Key]; int objhash = itemdata.Value.GetChecksum(); if (hash != objhash) { pConnection.Logger_WriteLine("{0} != {1}", hash, objhash); addrow = true; } info.SlotHashes[i].Remove(itemdata.Key); } else { addrow = true; } if (addrow) { Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } } pConnection.Logger_WriteLine("Done bag items"); { string removequery = ""; bool added = false; foreach (var hashlist in info.SlotHashes) { foreach (var leftovers in hashlist.Value) { pConnection.Logger_WriteLine("Deleting item @ inv {0} slot {1}", hashlist.Key, leftovers.Key); added = true; removequery += string.Format("DELETE FROM items WHERE character_id = {2} AND inventory = {0} AND slot = {1};\r\n", hashlist.Key, leftovers.Key, internalid); } } if (added) { System.IO.File.WriteAllText("removequery.sql", removequery); MySQL_Connection.Instance.RunQuery(removequery); } } } else { pConnection.Logger_WriteLine("Saving Items"); pConnection.CharacterInternalID = internalid; pConnection.CharacterID = Stats.ID; string itemlist = ""; itemlist += "INSERT INTO items VALUES "; List <string> querylist = new List <string>(); for (byte i = 0; i < Inventory.EquipmentItems.Length; i++) { var equips = Inventory.EquipmentItems[i]; foreach (var equipdata in equips) { var equip = equipdata.Value; Queries.SaveItem(pConnection, 0, equipdata.Key, equip, itemsTable, true); } } pConnection.Logger_WriteLine("Done equips"); for (int i = 0; i < Inventory.InventoryItems.Length; i++) { var items = Inventory.InventoryItems[i]; foreach (var itemdata in items) { var item = itemdata.Value; Queries.SaveItem(pConnection, (byte)(i + 1), itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done items"); foreach (var bag in Inventory.BagItems) { ushort i = (ushort)(bag.Key); foreach (var itemdata in bag.Value.Items) { var item = itemdata.Value; Queries.SaveItem(pConnection, i, itemdata.Key, item, itemsTable, true); if (item is ItemPet) { Queries.SavePet(pConnection.CharacterInternalID, item as ItemPet, petTable); } } } pConnection.Logger_WriteLine("Done bag items"); AccountDataCache.Instance.LoadBaseData(Stats.Name); } itemsTable.RunQuery(); pConnection.Logger_WriteLine("Saved item data"); petTable.RunQuery(); pConnection.Logger_WriteLine("Saved pet data"); AccountDataCache.Instance.LoadInventoryHashes(internalid, true); MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.Running) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery("insert-update-quests.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.Done) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery("insert-update-quests-done.sql"); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_running_party WHERE character_id = " + internalid); using (InsertQueryBuilder questsTable = new InsertQueryBuilder("quests_running_party")) { questsTable.OnDuplicateUpdate = true; questsTable.AddColumn("character_id", false); questsTable.AddColumn("questid", true); questsTable.AddColumn("data", true); foreach (var quest in Quests.PartyQuestsRunning) { questsTable.AddRow(internalid, quest.Key, quest.Value); } questsTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM quests_done_party WHERE character_id = " + internalid); using (InsertQueryBuilder doneTable = new InsertQueryBuilder("quests_done_party")) { doneTable.AddColumn("character_id", false); doneTable.AddColumn("questid", false); doneTable.AddColumn("time", false); foreach (var quest in Quests.PartyQuestsDone) { doneTable.AddRow(internalid, quest.Key, quest.Value); } doneTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM skills WHERE character_id = " + internalid); using (InsertQueryBuilder skillTable = new InsertQueryBuilder("skills")) { skillTable.OnDuplicateUpdate = true; skillTable.AddColumn("character_id", false); skillTable.AddColumn("skillid", false); skillTable.AddColumn("level", true); skillTable.AddColumn("maxlevel", true); skillTable.AddColumn("expires", true); foreach (var skill in Skills.SkillList) { skillTable.AddRow(internalid, skill.Key, skill.Value.Level, skill.Value.MasterLevel != -1 ? (object)skill.Value.MasterLevel : null, skill.Value.Expiration); } skillTable.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM sp_data WHERE character_id = " + internalid); using (InsertQueryBuilder spTable = new InsertQueryBuilder("sp_data")) { spTable.OnDuplicateUpdate = true; spTable.AddColumn("character_id", false); spTable.AddColumn("slot", false); spTable.AddColumn("amount", true); foreach (var kvp in Stats.SPData) { spTable.AddRow(internalid, kvp.Key, kvp.Value); } spTable.RunQuery(); } using (InsertQueryBuilder teleportRocks = new InsertQueryBuilder("teleport_rock_locations")) { teleportRocks.OnDuplicateUpdate = true; teleportRocks.AddColumn("character_id"); for (int i = 0; i < 41; i++) { teleportRocks.AddColumn("map" + i, true); } teleportRocks.AddRowUnsafe( pConnection.CharacterInternalID, Inventory.TeleportRocks.ToList() ); teleportRocks.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM evolution_levels WHERE character_id = " + internalid); using (InsertQueryBuilder table = new InsertQueryBuilder("evolution_levels")) { table.AddColumn("character_id"); table.AddColumn("block"); table.AddColumn("index"); table.AddColumn("card", true); table.AddColumn("level", true); foreach (var card in EvolutionCards) { table.AddRow( pConnection.CharacterInternalID, card.Block, card.ID, card.ItemID, card.Level ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_rings WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_rings")) { table.AddColumn("character_id"); table.AddColumn("friend_name"); table.AddColumn("cashid1"); table.AddColumn("cashid2"); table.AddColumn("type"); foreach (var ring in Rings) { string type = ""; switch (ring.RingType) { case Ring.Type.Couple: type = "couple"; break; case Ring.Type.Marriage: type = "marriage"; break; case Ring.Type.Friend: type = "friend"; break; } table.AddRow( pConnection.CharacterInternalID, ring.FriendName, ring.RingCashID1, ring.RingCashID1, type ); } table.RunQuery(); } MySQL_Connection.Instance.RunQuery("DELETE FROM character_abilities WHERE character_id = " + pConnection.CharacterInternalID); using (InsertQueryBuilder table = new InsertQueryBuilder("character_abilities")) { table.AddColumn("character_id"); table.AddColumn("id"); table.AddColumn("skill_id"); table.AddColumn("level"); foreach (var stat in Abilities) { table.AddRow( pConnection.CharacterInternalID, stat.Item1, stat.Item2, stat.Item3 ); } table.RunQuery(); } return(true); } }
static void Main(string[] args) { AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnexpectedExHandler); Console.CancelKeyPress += Console_CancelKeyPress; Logger.SetLogfile(false); MasterThread.Load("MPLRServer"); try { MySQL_Connection.Initialize(); } catch { Environment.Exit(12); } AccountDataCache.Initialize(); #if LOCALE_GMS GMSKeys.Initialize(); #endif CommandHandler.Initialize(); Timeline.Init(); Random = new System.Random(); { InitializeValidHeaders(); AcceptedIPs = new List<string>(); #if LOCALE_GMS AcceptedIPs.Add("8.31.9"); // GMS #elif LOCALE_EMS AcceptedIPs.Add("109.234.77"); // EMS #endif Clients = new List<ClientConnection>(); StartPinger(); StartCharacterDeleteQueue(); } EXPTable.Load(); SessionRestartCache.Start(); // For clients Acceptor accept = new Acceptor(ServerMapleInfo.MAPLER_PORT, sock => { new ClientConnection(sock); }); // For online check! byte[] OnlineCheckInfo = null; { MaplePacket packet = new MaplePacket(ServerMapleInfo.VERSION); packet.WriteByte(ServerMapleInfo.LOCALE); byte[] temp = packet.ToArray(); OnlineCheckInfo = new byte[temp.Length + 1]; Buffer.BlockCopy(temp, 0, OnlineCheckInfo, 1, temp.Length); OnlineCheckInfo[0] = (byte)(temp.Length + 4); packet.Dispose(); packet = null; } Acceptor acceptCheck = new Acceptor(ServerMapleInfo.MAPLER_PORT_SERVER_INFO, sock => { sock.Send(OnlineCheckInfo); sock.Send(BitConverter.GetBytes(Clients.Count)); sock.Shutdown(System.Net.Sockets.SocketShutdown.Both); sock.Close(); }); Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); Logger.WriteLine("| |"); Logger.WriteLine("| Mapler.me Server |"); Logger.WriteLine("| |"); #if LOCALE_GMS Logger.WriteLine("| GLOBAL |"); #elif LOCALE_EMS Logger.WriteLine("| EUROPE |"); #elif LOCALE_KMS Logger.WriteLine("| KOREA |"); #endif Logger.WriteLine("| |"); Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); Logger.WriteLine("| Build For: {0,3} Locale {1,1} |", ServerMapleInfo.VERSION, ServerMapleInfo.LOCALE); Logger.WriteLine("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); Logger.WriteLine("Accepting connections on {0}, and info requests on {1}", ServerMapleInfo.MAPLER_PORT, ServerMapleInfo.MAPLER_PORT_SERVER_INFO); while (true) { string cmd = Console.ReadLine(); if (cmd == null) break; // CTRL + C string[] arguments = cmd.Split(' '); if (arguments.Length >= 1) { switch (arguments[0]) { #if LOCALE_GMS case "getkeys": { GMSKeys.Initialize(); break; } #endif case "reload_store": { MasterThread.Instance.AddCallback(a => { AccountDataCache.Instance.Load(); }); break; } case "request_screenshots": { MasterThread.Instance.AddCallback(a => { var tmp = new List<ClientConnection>(Clients); foreach (var client in tmp) { using (MaplePacket pack = new MaplePacket(MaplePacket.CommunicationType.ServerPacket, 0xEEFE)) { pack.SwitchOver(); client.SendPacket(pack); } } }); break; } case "testsession": { int accountid = arguments.Length > 1 ? Int32.Parse(arguments[1]) : -1; bool raw = arguments.Length > 2; var verp = new MSBLoader(); var connection = new ClientConnection(verp); connection.AccountID = accountid; verp.Parse("Savefile.msb", raw); break; } case "players": { string names = string.Join(", ", Clients); Console.WriteLine("Players online:\r\n{0}", names); break; } case "close": case "stop": case "exit": { MasterThread.Instance.AddCallback(a => { var tmp = new List<ClientConnection>(Clients); foreach (var client in tmp) { // client.Save(true, true); client.Disconnect(); } MySQL_Connection.Instance.Stop = true; MasterThread.Instance.Stop = true; }); break; } default: Console.WriteLine("Command not found"); break; } } } }
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; }