void HandleConnectionlessInboundPacket(NetConnectionlessInboundPacket packet)
 {
     if (packet.Type == NetPacketType.ConnectionRequest)
     {
         NetConnectionRequest request = new NetConnectionRequest(packet);
         HandleConnectionRequest(request);
     }
     else if (packet.Type == NetPacketType.ConnectionApproved)
     {
         HandleConnectionApproved(packet.SenderIP);
     }
     else if (packet.Type == NetPacketType.ConnectionDenied)
     {
         NetDenialReason reason = (NetDenialReason)packet.ReadByte();
         HandleConnectionDenied(packet.SenderIP, reason);
     }
     else if (packet.Type == NetPacketType.ConnectionReady)
     {
         HandleConnectionReady(packet.SenderIP);
     }
     else
     {
         AddWatchedConnection(packet.SenderIP, string.Format("Sent invalid connectionless packet ({0})", packet.Type));
     }
 }
Exemplo n.º 2
0
 protected override void HandleConnectionRequest(NetConnectionRequest request)
 {
     // Check if the password is correct and if there is room
     if (Connections.Count < config.MaxConnections && (config.Password == null || config.Password == request.Password))
     {
         if (!connectingMessengers.Add(request.EndPoint))
         {
             NetLogger.LogWarning("Connection request from already connecting client @ {0}! (or an error occured)", request.EndPoint);
         }
         else
         {
             // Send approval
             NetOutboundPacket approvalPacket = new NetOutboundPacket(NetDeliveryMethod.Unreliable,
                                                                      NetPacketType.ConnectionApproved);
             SendInternalPacket(approvalPacket, request.EndPoint);
         }
     }
     else
     {
         // Send denial
         NetOutboundPacket denialPacket = new NetOutboundPacket(NetDeliveryMethod.Unreliable,
                                                                NetPacketType.ConnectionDenied);
         denialPacket.Write((byte)(Connections.Count < config.MaxConnections ? NetDenialReason.InvalidPassword : NetDenialReason.ServerFull));
         SendInternalPacket(denialPacket, request.EndPoint);
     }
 }
Exemplo n.º 3
0
 protected override void HandleConnectionRequest(NetConnectionRequest request)
 {
     AddWatchedConnection(request.EndPoint, "Client attempted to connect to this client");
 }
 protected abstract void HandleConnectionRequest(NetConnectionRequest request);