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 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; } }
protected void ParseLogin(ClientConnection pConnection, int pUserID, string pUsername, DateTime pCreationDate) { pConnection.Logger_WriteLine("User logged into Nexon account '{1}', userid {0}", pUserID, pUsername); if (AccountDataCache.Instance.KnownUserlist.ContainsKey(pUserID)) { int tmp = AccountDataCache.Instance.KnownUserlist[pUserID]; if (tmp == 2) { pConnection.Logger_WriteLine("User bound to temporary account. Allocating current account to it."); using (UpdateQueryBuilder q = new UpdateQueryBuilder("users")) { q.SetColumn("account_id", pConnection.AccountID); q.SetColumn("last_check", MySQL_Connection.NOW); q.SetColumn("creation_date", pCreationDate); q.SetWhereColumn("ID", pUserID); q.RunQuery(); } AccountDataCache.Instance.KnownUserlist[pUserID] = pConnection.AccountID; pConnection.UserID = pUserID; } else if (tmp == pConnection.AccountID) { // Correct account, continue pConnection.Logger_WriteLine("User bound to same account. kay"); using (UpdateQueryBuilder q = new UpdateQueryBuilder("users")) { q.SetColumn("last_check", MySQL_Connection.NOW); q.SetWhereColumn("ID", pUserID); q.RunQuery(); } pConnection.UserID = pUserID; } else { pConnection.Logger_WriteLine("User ID not bound to this account!!! Ignoring..."); pConnection.SendInfoText("WARNING: This Nexon account ({0}) is not yours! Please login into the correct Mapler.me account.", pUsername); return; } } else { pConnection.Logger_WriteLine("Creating user for accountID {0}", pConnection.AccountID); using (InsertQueryBuilder insertq = new InsertQueryBuilder("users")) { insertq.OnDuplicateUpdate = true; insertq.AddColumn("account_id"); insertq.AddColumn("ID"); insertq.AddColumn("creation_date"); insertq.AddColumn("last_check", true); insertq.AddColumn("maplepoints"); insertq.AddRow(pConnection.AccountID, pUserID, pCreationDate, MySQL_Connection.NOW, 0); insertq.RunQuery(); } pConnection.UserID = pUserID; AccountDataCache.Instance.KnownUserlist.Add(pUserID, pConnection.AccountID); } pConnection.SendInfoText("Identified account {0}. You can now select your character.", pUsername); if (pConnection.LogFilename == "Unknown") pConnection.LogFilename = ""; else pConnection.LogFilename += "_"; pConnection.LogFilename += pConnection.AccountID.ToString(); // Save IP of loginserver if (pConnection.ConnectedToIP != null) Queries.SaveServerIP(pConnection.ConnectedToIP, pConnection.ConnectedToPort, 0, 0); }
public virtual void HandleChangeMap(ClientConnection pConnection, MaplePacket pPacket) { int tmp = pPacket.ReadShort(); pPacket.Skip(tmp * (4 + 4)); int channelid = pPacket.ReadInt(); pConnection.ChannelID = (byte)channelid; #if LOCALE_EMS pPacket.ReadByte(); #endif pPacket.Skip(1 + 4); pPacket.Skip(1); // Portals taken pPacket.Skip(4); bool isConnecting = pPacket.ReadBool(); if (!isConnecting && pConnection.CharData == null) { return; } pConnection._CharactersInMap.Clear(); tmp = pPacket.ReadShort(); // Contains Message (Not used anymore lol.) if (tmp > 0) { pPacket.ReadString(); // Title for (int i = 0; i < tmp; i++) { pPacket.ReadString(); // Line N } } if (isConnecting) { pPacket.Skip(12); // RNGs pConnection.Logger_WriteLine("--------- Started parsing Character Info ----------"); CharacterData data = new CharacterData(); data.Decode(pConnection, pPacket); pConnection.Logger_WriteLine("--------- Done parsing Character Info ----------"); // Quick duplicate check Tuple<int, byte, byte, ushort> conflicted = null; using (var reader = MySQL_Connection.Instance.RunQuery("SELECT id, level, world_id, job FROM characters WHERE id <> " + data.Stats.ID + " AND name = " + MySQL_Connection.Escape(data.Stats.Name)) as MySql.Data.MySqlClient.MySqlDataReader) { if (reader.Read()) { // CONFLICTS conflicted = new Tuple<int, byte, byte, ushort>(reader.GetInt32(0), reader.GetByte(1), reader.GetByte(2), reader.GetUInt16(3)); } } if (conflicted == null) { if (!data.SaveData(pConnection)) return; pConnection.CharData = data; pConnection.Logger_WriteLine("--------- Saved parsed Character Info ----------"); pConnection.LastLoggedCharacterName = pConnection.CharData.Stats.Name; pConnection.LastLoggedDate = pConnection.CharData.Stats.DateThing.ToString(); pConnection.LogFilename += "-" + pConnection.CharacterInternalID; pConnection.LastExpPoint = (byte)EXPTable.GetLevelPercentage(data.Stats.Level, data.Stats.EXP); pConnection.SendInfoText("Your character {0} has been saved!", pConnection.CharData.Stats.Name); // Save SessionRestart Info SessionRestartCache.Instance.StoreInfo(pConnection.IP, pConnection.MachineID, pConnection.CharacterID, pConnection.WorldID); } else { pConnection.LogFilename += "-(CONFLICT)" + data.Stats.Name; pConnection.Logger_WriteLine("!!!!!! FOUND CHARACTER NAME CONFLICT ! Expected Character ID {0}, found Character ID {1} in database!", data.Stats.ID, conflicted.Item1); pConnection.Logger_WriteLine("Level diff: {0} - {1}", data.Stats.Level, conflicted.Item3); pConnection.Logger_WriteLine("Job diff: {0} - {1}", data.Stats.JobID, conflicted.Item4); pConnection.Logger_WriteLine("World diff: {0} - {1}", pConnection.WorldID, conflicted.Item2); pConnection.SendInfoText("A different character has already this name! Delete this character via the website first!"); } Queries.SaveServerIP(pConnection.ConnectedToIP, pConnection.ConnectedToPort, GameHelper.GetAllianceWorldID(pConnection.WorldID), pConnection.ChannelID); } else { pPacket.ReadByte(); int mapid = pPacket.ReadInt(); byte mappos = pPacket.ReadByte(); pConnection.Logger_WriteLine("New MapID: {0} ({1})", mapid, mappos); pConnection.CharData.Stats.MapID = mapid; pConnection.CharData.Stats.MapPos = mappos; int hp = pPacket.ReadInt(); pConnection.CharData.Stats.HP = hp; if (pPacket.ReadBool()) { pPacket.ReadInt(); pPacket.ReadInt(); } MySQL_Connection.Instance.RunQuery(string.Format("UPDATE characters SET chp = {0}, map = {1}, pos = {2} WHERE internal_id = {3}", hp, mapid, mappos, pConnection.CharacterInternalID)); } pPacket.ReadLong(); //DateTime servertime = DateTime.FromFileTime(pPacket.ReadLong()); pPacket.ReadInt(); // 100? pPacket.ReadByte(); // 0 pPacket.ReadByte(); // 0 pPacket.ReadByte(); // 1 if (pPacket.Position != pPacket.Length) { pConnection.Logger_WriteLine("Data not fully read. Halp.: {0} of {1} read", pPacket.Position, pPacket.Length); } pConnection.SendTimeUpdate(); }
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; } }