private void net_Received(object sender, UdpPacketReceivedEventArgs e) { TS2Packet packet = new TS2Packet(); packet.ReadPacket(e.Response.Buffer); ClientID = packet.ClientID; RealClientID = packet.ClientID; Stream stream = null; BinaryReader reader = null; try { if (packet.Data == null) { packet.Data = new byte[] { 0x00 }; } stream = new MemoryStream(packet.Data); reader = new BinaryReader(stream); } catch (Exception err) { } switch (packet.Class) { case TS2.CONNECTION: switch (packet.Type) { case TS2.LOGINREPLY: LoginHandler(reader); break; case TS2.PING_REPLY: PingSequenceNumber = packet.SequenceNumber+1; break; default: Console.WriteLine("Unhandled Packet Type"); break; } break; case TS2.STANDARD: switch (packet.Type) { case TS2.PLAYERLIST: PlayerListHandler(reader); break; case TS2.CHANNELLIST: if (pingThread == null) { pingThread = new Thread(new ThreadStart(PingThread)); pingThread.Start(); } break; case TS2.NEWPLAYER: NewPlayerHandler(reader); break; case TS2.PLAYERQUIT: Console.WriteLine("Player left!"); PlayerQuitHandler(reader); break; default: break; } AckHandler(packet.SequenceNumber); break; case TS2.ACK: if (disconnectPending) { if (packet.SequenceNumber == this.dcSequenceNumber) { disconnectPending = false; } } AckHandler(packet.SequenceNumber); this.SequenceNumber = packet.SequenceNumber + 1; break; default: Console.WriteLine("Unknown Packet"); break; } }