void RecvUnconnectedPacket(UdpStream buffer, UdpEndPoint ep) { UdpAssert.Assert(buffer.Ptr == 0); buffer.Ptr = HeaderBitSize; if (buffer.ReadByte(8) == (byte)UdpCommandType.Connect) { if (Config.AllowIncommingConnections && ((connLookup.Count + pendingConnections.Count) < Config.ConnectionLimit || Config.ConnectionLimit == -1)) { if (Config.AutoAcceptIncommingConnections) { AcceptConnection(ep, null); } else { if (pendingConnections.Add(ep)) { object obj = null; if (buffer.ReadByte(8) == UdpEvent.INTERNAL_COMMAND_HASOBJECT) { //they've also sent an object along with their connection request serializer.Unpack(buffer, ref obj); } Raise(UdpEvent.PUBLIC_CONNECT_REQUEST, ep, obj); } } } else { SendRefusedCommand(ep); } } }
void RecvUnconnectedPacket(UdpStream buffer, UdpEndPoint ep) { UdpAssert.Assert(buffer.Ptr == 0); buffer.Ptr = HeaderBitSize; if (buffer.ReadByte(8) == (byte)UdpCommandType.Connect) { if (Config.AllowIncommingConnections && ((connLookup.Count + pendingConnections.Count) < Config.ConnectionLimit || Config.ConnectionLimit == -1)) { if (Config.AutoAcceptIncommingConnections) { AcceptConnection(ep); } else { if (pendingConnections.Add(ep)) { Raise(UdpEvent.PUBLIC_CONNECT_REQUEST, ep); } } } else { SendRefusedCommand(ep); } } }
void OnCommandReceived(UdpStream buffer) { if (ParseHeader(buffer)) { buffer.Ptr = UdpSocket.HeaderBitSize; UdpCommandType cmd = (UdpCommandType)buffer.ReadByte(8); switch (cmd) { case UdpCommandType.Connect: OnCommandConnect(buffer); break; case UdpCommandType.Accepted: OnCommandAccepted(buffer); break; case UdpCommandType.Refused: OnCommandRefused(buffer); break; case UdpCommandType.Disconnected: OnCommandDisconnected(buffer); break; case UdpCommandType.Ping: OnCommandPing(buffer); break; default: ConnectionError(UdpConnectionError.IncorrectCommand); break; } } }