コード例 #1
0
ファイル: Server.cs プロジェクト: IMcNeany/TrackAttackClone
    public void UpdateMessagePump()
    {
        if (!server_started)
        {
            return;
        }

        int rec_host_id; //standalone vs web
        int client_id;   //user
        int channel_id;  //lane

        byte[] byte_buffer = new byte[BYTE_SIZE];
        int    data_size;

        NetworkEventType type = NetworkTransport.Receive(out rec_host_id, out client_id, out channel_id, byte_buffer, BYTE_SIZE, out data_size, out error);

        if (type != NetworkEventType.Nothing && type != NetworkEventType.BroadcastEvent)
        {
            //Debug.Log("Receive client ID: " + client_id);
        }

        switch (type)
        {
        case NetworkEventType.Nothing:
            break;

        case NetworkEventType.DataEvent:
            BinaryFormatter formatter     = new BinaryFormatter();
            MemoryStream    memory_stream = new MemoryStream(byte_buffer);
            NetworkMessage  message       = (NetworkMessage)formatter.Deserialize(memory_stream);
            OnDataRecieved(client_id, channel_id, host_id, message);
            break;

        case NetworkEventType.ConnectEvent:
            Debug.Log("User connected with ID: " + client_id);
            current_user_amount++;
            AssignClientID(client_id);
            if (lobby)
            {
                gameObject.GetComponent <PlayerManager>().AddPlayerToList(client_id, PlayerManager.PlayerType.PLAYER);    // add the player info to the list of players
                lobby.SetPlayerConnection(client_id, connection_status.connected);
            }

            break;

        case NetworkEventType.DisconnectEvent:
            Debug.Log("User Disconnected with ID: " + client_id);

            if (lobby)
            {
                gameObject.GetComponent <PlayerManager>().RemovePlayerFromList(client_id);    // remove player from the list of players
                lobby.SetPlayerConnection(client_id, connection_status.disconnected);
            }

            current_user_amount--;
            break;

        default:
        case NetworkEventType.BroadcastEvent:
            Debug.Log("Incorrect Data type");
            break;
        }
    }