예제 #1
0
    // Start
    void Start()
    {
        NetworkTransport.Init();

        reliableChannel   = config.AddChannel(QosType.Reliable);
        unreliableChannel = config.AddChannel(QosType.Unreliable);

        var hostTopology = new HostTopology(config, maxConnections);

        hostId = NetworkTransport.AddHost(hostTopology, port);

        receiveBuffer = new byte[bufferSize];

        onConnect += (connectionId) => {
            Debug.Log("Player " + connectionId + " connected.");

            var player = new NetworkTarget(connectionId);
            NetworkPlayers.Add(player);

            // Send connected message
            player.Send(ServerMessage.Connected);
        };

        onDisconnect += (connectionId) => {
            Debug.Log("Player " + connectionId + " disconnected.");
            NetworkPlayers.Remove(NetworkPlayers.Find(connectionId));
        };

        isStarted = true;
    }
예제 #2
0
 // Only called by Unity on server
 public void uLink_OnPlayerDisconnected(uLink.NetworkPlayer player)
 {
     uLink.Network.RemoveRPCs(player);
     uLink.Network.DestroyPlayerObjects(player);
     NetworkPlayers.Remove(player);
 }