private void ChangeChannel(Packet pPacket) { byte status = pPacket.ReadByte(); string ip = string.Format("{0}.{1}.{2}.{3}", pPacket.ReadByte(), pPacket.ReadByte(), pPacket.ReadByte(), pPacket.ReadByte()); // Ignore IP ushort port = pPacket.ReadUShort(); byte[] leftover = pPacket.ReadLeftoverBytes(); CCing = true; NextPort = port; Packet packet = new Packet(); packet.WriteUShort(0x0011); packet.WriteByte(1); packet.WriteBytes(Constants.MapleStory_LoginIP_Bytes); packet.WriteUShort(8484); packet.WriteBytes(leftover); ClientSession.Instance.SendPacket(packet); Console.WriteLine("1 Status "+status+": Change Channel: " + packet.ToString()); }
/// <summary> /// Used as IAsyncResult parser for ContinueReading(). /// </summary> /// <param name="pIAR">The result AsyncCallback makes</param> private void EndReading(IAsyncResult pIAR) { int amountReceived = 0; try { amountReceived = _socket.EndReceive(pIAR); } catch (Exception ex) { amountReceived = 0; Console.WriteLine(TypeName + " amountReceived == 0! " + ex.ToString()); } if (amountReceived == 0) { Console.WriteLine(TypeName + " amountReceived == 0! OnDisconnectInternal()"); // We got a disWvsBeta.Common.Sessions here! OnDisconnectINTERNAL(); return; } // Add amount of bytes received to _bufferpos so we know if we got everything. _bufferpos += amountReceived; try { // Check if we got all data. There is _no_ way we would have received more bytes than needed. Period. if (_bufferpos == _bufferlen) { // It seems we have all data we need // Now check if we got a header if (_header) { if (!_encryption && _receivingFromServer) { // Unencrypted packets have a short header with plain length. ushort length = (ushort)(_buffer[0] | _buffer[1] << 8); StartReading(length); } else { int length = GetHeaderLength(_buffer); StartReading(length); } } else { Packet packet; if (_encryption) { _buffer = Decrypt(_buffer); packet = new Packet(_buffer); DoAction((date) => { try { OnPacketInbound(packet); } catch (Exception ex) { Console.WriteLine("Handling Packet Error: {0}", ex.ToString()); } }); } else { _encryption = true; // First packet received or sent is unencrypted. All others are. packet = new Packet(_buffer); _mapleVersion = packet.ReadUShort(); _maplePatchLocation = _maplePatchLocation = packet.ReadString(); _encryptIV = packet.ReadBytes(4); _decryptIV = packet.ReadBytes(4); _mapleLocale = packet.ReadByte(); Console.WriteLine(TypeName + " MapleVersion: {0}; Patch Location: {1}; Locale: {2}", _mapleVersion, _maplePatchLocation, _mapleLocale); if (_mapleLocale == 8 && _mapleVersion >= 118) { SwitchAESByVersion(_mapleVersion); } packet.Reset(); DoAction((date) => { try { OnHandshakeInbound(packet); } catch (Exception ex) { Console.WriteLine("Handling Packet Error: {0}", ex.ToString()); } }); } StartReading(4, true); } } else { ContinueReading(); } } catch (SocketException socketException) { Console.WriteLine(TypeName + " Socket Exception while receiving data: {0}", socketException.Message); OnDisconnectINTERNAL(); } catch (Exception ex) { Console.WriteLine(TypeName + " [ERROR] EndReading(): {0}", ex.ToString()); OnDisconnectINTERNAL(); } }
public void handleWorld(Packet packet) { byte ID = packet.ReadByte(); if (ID == 0xFF) { HandleData(null); // Logger.WriteLine("Worlds: {0}; Channels: {1}; Channel load avg: {2}", iworlds, ichannels, (double)Program.mTotalOnline / (double)ichannels); gotData = true; iworlds = ichannels = 0; return; } iworlds++; string name = packet.ReadString(); byte ribbon = packet.ReadByte(); // Ribbon string eventMsg = packet.ReadString(); // Event message packet.ReadShort(); // EXP rate packet.ReadShort(); // DROP rate int channels = packet.ReadByte(); ichannels += channels; if (!gotData) DataBase.UpdateWorldData(ID, name, channels, ribbon, eventMsg); if (Config.Instance.SkipWorlds.Contains(ID)) return; List<Channel> channelList = new List<Channel>(); Channel chan; for (int i = 0; i < channels; i++) { chan = new Channel(); chan.ChannelName = packet.ReadString(); chan.Population = packet.ReadInt(); chan.World = packet.ReadByte(); chan.ID = packet.ReadByte(); chan.ID += 1; chan.SpecialValue = packet.ReadByte(); channelList.Add(chan); Program.Connection.AmountOnline += chan.Population; if (OldLoads.ContainsKey(chan.ChannelName) && OldLoads[chan.ChannelName] >= 10 && (chan.Population * 100 / OldLoads[chan.ChannelName]) <= 20) { Logger.WriteLine("{0} crashed, as it went from {1:N0} to {2:N0} people online.", chan.ChannelName, OldLoads[chan.ChannelName], chan.Population); DataBase.AddCrash(chan.World, chan.ID, OldLoads[chan.ChannelName], chan.Population); TweetCrash(chan); } if (chan.Population < 0) { Logger.WriteLine("Seems like Nexon didn't fix the negative bug: Channel {0} has {1} players online.", chan.ChannelName, chan.Population); chan.Population = Math.Abs(chan.Population); // Make it positive! } if (OldLoads.ContainsKey(chan.ChannelName)) { OldLoads[chan.ChannelName] = chan.Population; } else { OldLoads.Add(chan.ChannelName, chan.Population); } } HandleData(channelList); }
/// <summary> /// Used as IAsyncResult parser for ContinueReading(). /// </summary> /// <param name="pIAR">The result AsyncCallback makes</param> private void EndReading(IAsyncResult pIAR) { int amountReceived = 0; try { amountReceived = _socket.EndReceive(pIAR); } catch (Exception ex) { MWLR_Logging.Logger.WriteLine(TypeName + " : " + ex.ToString()); amountReceived = 0; } if (amountReceived == 0) { // We got a disconnection here! OnDisconnectINTERNAL(); return; } // Add amount of bytes received to _bufferpos so we know if we got everything. _bufferpos += amountReceived; try { // Check if we got all data. There is _no_ way we would have received more bytes than needed. Period. if (_bufferpos == _bufferlen) { // It seems we have all data we need // Now check if we got a header if (_header) { if (!_encryption && _receivingFromServer) { // Unencrypted packets have a short header with plain length. ushort length = (ushort)(_buffer[0] | _buffer[1] << 8); StartReading(length); } else { int length = GetHeaderLength(_buffer); StartReading(length); } } else { Packet packet; if (_encryption) { _buffer = Decrypt(_buffer, _mapleLocale == 1); packet = new Packet(_buffer); DoAction((date) => { try { OnPacketInbound(packet); } catch (Exception ex) { MWLR_Logging.Logger.WriteLine("Handling Packet Error: {0}", ex.ToString()); } }); } else { _encryption = true; // First packet received or sent is unencrypted. All others are. packet = new Packet(_buffer); _mapleVersion = packet.ReadUShort(); _maplePatchLocation = packet.ReadString(); _encryptIV = packet.ReadBytes(4); _decryptIV = packet.ReadBytes(4); _mapleLocale = packet.ReadByte(); MWLR_Logging.Logger.WriteLine(TypeName + " MapleVersion: {0}; Patch Location: {1}; Locale: {2}", _mapleVersion, _maplePatchLocation, _mapleLocale); if (_mapleLocale == 1) { int test = int.Parse(_maplePatchLocation); ushort t1 = (ushort)(test & 0x7FFF); int t2 = (test >> 15) & 1; int t3 = (test >> 16) & 0xFF; MWLR_Logging.Logger.WriteLine("Logging KMS connection. Version {0} | {1} | {2}", t1, t2, t3); _mapleVersion = t1; _maplePatchLocation = t3.ToString(); } else if (_mapleLocale == 8 && _mapleVersion >= 118) { if (!MWLR_Logging.GMSKeys.ContainsKey(_mapleVersion)) MWLR_Logging.GMSKeys.Initialize(); if (MWLR_Logging.GMSKeys.ContainsKey(_mapleVersion)) { SwitchAESByVersion(_mapleVersion); } else { MWLR_Logging.Logger.WriteLine("There's no key for this version, yet."); MWLR_Logging.TwitterClient.Instance.SendMessage("HEY, @Diamondo25! Update da keyzz!!"); Disconnect(); System.Threading.Thread.Sleep(15 * 60 * 1000); } } packet.Reset(); DoAction((date) => { try { OnHandshakeInbound(packet); } catch (Exception ex) { MWLR_Logging.Logger.WriteLine("Handling Packet Error: {0}", ex.ToString()); } }); } StartReading(4, true); } } else { ContinueReading(); } } catch (SocketException socketException) { MWLR_Logging.Logger.WriteLine(TypeName + " Socket Exception while receiving data: {0}", socketException.Message); OnDisconnectINTERNAL(); } catch (Exception ex) { MWLR_Logging.Logger.WriteLine(TypeName + " [ERROR] EndReading(): {0}", ex.ToString()); OnDisconnectINTERNAL(); } }