Esempio n. 1
0
		void GetPackets() {
			Packet p;

			try {
				while (!stop) {
					var succ = comm.ReceivePacket(out p);

					if (succ == PacketCommunicatorReceiveResult.Timeout) {
						DumpPackets();
						continue;
					}
					else if (succ == PacketCommunicatorReceiveResult.BreakLoop)
						break;

					var ip = p.Ethernet.IpV4;
					var tcp = ip.Tcp;
					var data = tcp.Payload.ToMemoryStream();

					if (data.Length == 0) {
#if DEBUG
						//Console.WriteLine("Dropped packet of length 0");
#endif
						continue;
					}

#if DEBUG
					//Console.WriteLine($"Caught packet of length {data.Length} from {ip.Source}");
					//Console.WriteLine($"SEQ: {tcp.SequenceNumber}, ACK: {tcp.AcknowledgmentNumber}, Time: {p.Timestamp.Ticks}");
#endif

					var inc = IsIncoming(ip);
					var isl = IsLogin(tcp, inc);
					var isw = IsWorld(tcp, inc);
					var isc = IsChat(tcp, inc);
					var isa = IsAuction(tcp, inc);

					ushort port = (inc)
						? tcp.SourcePort
						: tcp.DestinationPort;

					ushort lport = (inc)
						? tcp.DestinationPort
						: tcp.SourcePort;

					if (!clientCrypt.ContainsKey(port) || ((isl && lport != ports[0]) || (isw && lport != ports[1]) || (isc && lport != ports[2] || (isa && lport != ports[3])))) {
#if DEBUG
						Console.WriteLine($"Creating new encryption instances for [{ip.Source} - {ip.Destination}]");
#endif
						clientCrypt[port] = new Cryption.Client();
						serverCrypt[port] = new Cryption.Server();

						if (isl) {
							ports[0] = lport;
							partil = null;
							partol = null;
						}
						else if (isw) {
							ports[1] = lport;
							partiw = null;
							partow = null;
						}
						else if (isc) {
							ports[2] = lport;
							partic = null;
							partoc = null;
						}
						else {
							ports[3] = lport;
							partia = null;
							partoa = null;
						}
					}

					var daemon =
						(isl) ? PacketInfo.Daemon.Login :
						(isw) ? PacketInfo.Daemon.World :
						(isc) ? PacketInfo.Daemon.Chat :
						PacketInfo.Daemon.Auction;

					AddPacket(tcp, inc, daemon, port);
				}
			}
			catch (Exception) { }
		}
Esempio n. 2
0
        void GetPackets()
        {
            Packet p;

            try {
                while (!stop)
                {
                    var succ = comm.ReceivePacket(out p);

                    if (succ == PacketCommunicatorReceiveResult.Timeout)
                    {
                        DumpPackets();
                        continue;
                    }
                    else if (succ == PacketCommunicatorReceiveResult.BreakLoop)
                    {
                        break;
                    }

                    var ip   = p.Ethernet.IpV4;
                    var tcp  = ip.Tcp;
                    var data = tcp.Payload.ToMemoryStream();

                    if (data.Length == 0)
                    {
#if DEBUG
                        //Console.WriteLine("Dropped packet of length 0");
#endif
                        continue;
                    }

#if DEBUG
                    //Console.WriteLine($"Caught packet of length {data.Length} from {ip.Source}");
                    //Console.WriteLine($"SEQ: {tcp.SequenceNumber}, ACK: {tcp.AcknowledgmentNumber}, Time: {p.Timestamp.Ticks}");
#endif

                    var inc = IsIncoming(ip);
                    var isl = IsLogin(tcp, inc);
                    var isw = IsWorld(tcp, inc);
                    var isc = IsChat(tcp, inc);
                    var isa = IsAuction(tcp, inc);

                    ushort port = (inc)
                                                ? tcp.SourcePort
                                                : tcp.DestinationPort;

                    ushort lport = (inc)
                                                ? tcp.DestinationPort
                                                : tcp.SourcePort;

                    if (!clientCrypt.ContainsKey(port) || ((isl && lport != ports[0]) || (isw && lport != ports[1]) || (isc && lport != ports[2] || (isa && lport != ports[3]))))
                    {
#if DEBUG
                        Console.WriteLine($"Creating new encryption instances for [{ip.Source} - {ip.Destination}]");
#endif
                        clientCrypt[port] = new Cryption.Client();
                        serverCrypt[port] = new Cryption.Server();

                        if (isl)
                        {
                            ports[0] = lport;
                            partil   = null;
                            partol   = null;
                        }
                        else if (isw)
                        {
                            ports[1] = lport;
                            partiw   = null;
                            partow   = null;
                        }
                        else if (isc)
                        {
                            ports[2] = lport;
                            partic   = null;
                            partoc   = null;
                        }
                        else
                        {
                            ports[3] = lport;
                            partia   = null;
                            partoa   = null;
                        }
                    }

                    var daemon =
                        (isl) ? PacketInfo.Daemon.Login :
                        (isw) ? PacketInfo.Daemon.World :
                        (isc) ? PacketInfo.Daemon.Chat :
                        PacketInfo.Daemon.Auction;

                    AddPacket(tcp, inc, daemon, port);
                }
            }
            catch (Exception) { }
        }