예제 #1
0
파일: Client.cs 프로젝트: DeinFreund/Cyubey
    void receiveUDP(byte[] data)
    {
        try
        {
            //Debug.Log("Received udp for client " + (tcpClient.Client.RemoteEndPoint as IPEndPoint));
            UDPNetworkMessage message = UDPNetworkMessage.DeserializeObject <UDPNetworkMessage>(data);
            //Debug.Log("UDP Received message of id " + message.getMessageID());
            switch (message.getMessageID())
            {
            case PositionUpdate.ID:
                updatePosition((PositionUpdate)message);
                break;

            default:
                Debug.LogWarning("Unknown network message with id " + message.getMessageID());
                break;
            }
        }
        catch (Exception ex)
        {
            Debug.LogError("Error parsing UDP message " + ex);
        }
    }
예제 #2
0
    private static void receiveUDP(byte[] data)
    {
        try
        {
            //Debug.Log("Received udp from server at " + (tcpClient.Client.RemoteEndPoint as IPEndPoint));
            UDPNetworkMessage message = UDPNetworkMessage.DeserializeObject <UDPNetworkMessage>(data);
            //Debug.Log("UDP Received message of id " + message.getMessageID());
            switch (message.getMessageID())
            {
            case PositionUpdate.ID:
                MainThread.runAction(() =>
                {
                    lock (playersByID)
                    {
                        PositionUpdate posUpdate = (PositionUpdate)message;
                        if (playersByID.ContainsKey(posUpdate.affectedPlayer))
                        {
                            playersByID[posUpdate.affectedPlayer].updatePosition(posUpdate);
                        }
                    }
                });
                break;

            case ChunkData.ID:
                ChunkData chunkData = (ChunkData)message;
                receiveChunk(chunkData);
                break;

            default:
                Debug.LogWarning("Unknown network message with id " + message.getMessageID());
                break;
            }
        }catch (Exception ex)
        {
            Debug.LogError("Error parsing UDP message " + ex);
        }
    }