protected override void ProcessAccept(UDPPacket packet) { IPEndPoint remote = (IPEndPoint)packet.AsyncEventArgs.RemoteEndPoint; //Task.Run(() => //{ if (packet.BytesRecieved.Length < 6) { return; } BasePacket basePacket = new BasePacket(packet.BytesRecieved); try { //BytesRecieved[7] is nnpacket.PacketType. switch (basePacket.PacketType) { case NatPacketType.PreInit: //NatNegHandler.PreInitResponse(this, packet, nnpacket); break; case NatPacketType.Init: InitHandler.InitResponse(this, packet); break; case NatPacketType.AddressCheck: AddressHandler.AddressCheckResponse(this, packet); break; case NatPacketType.NatifyRequest: NatifyHandler.NatifyResponse(this, packet); break; case NatPacketType.ConnectAck: ConnectHandler.ConnectResponse(this, packet); break; case NatPacketType.Report: ReportHandler.ReportResponse(this, packet); break; default: LogWriter.Log.Write(LogLevel.Error, "{0,-8} [Recv] unknow data", ServerName); break; } } catch (Exception e) { LogWriter.Log.WriteException(e); } finally { if (Replied == true) { Release(packet.AsyncEventArgs); } } }
public static void Switch(NatNegServer server, byte[] message) { BasePacket basePacket = new BasePacket(message); try { //BytesRecieved[7] is nnpacket.PacketType. switch (basePacket.PacketType) { case NatPacketType.PreInit: //NatNegHandler.PreInitResponse(this, packet, nnpacket); break; case NatPacketType.Init: InitHandler.InitResponse(server, message); break; case NatPacketType.AddressCheck: AddressHandler.AddressCheckResponse(server, message); break; case NatPacketType.NatifyRequest: NatifyHandler.NatifyResponse(server, message); break; case NatPacketType.ConnectAck: ConnectHandler.ConnectResponse(server, message); break; case NatPacketType.Report: ReportHandler.ReportResponse(server, message); break; default: server.UnknownDataRecived(message); break; } } catch (Exception e) { LogWriter.Log.WriteException(e); } }