private void MessageReceived(Message message)
 {
     switch (message.MessageType)
     {
     case MessageType.ServerCoordinates:
         var coordinates = ByteConverters.FromBytes <ServerCoordinatesMessage>(message.Data);
         _dispatcher.Invoke(() =>
         {
             for (var i = 0; i < coordinates.Count; i++)
             {
                 if (coordinates.Coordinates[i].Player == ConnectionInstance.Instance.Client.Id)
                 {
                     //Debug.Log("Me : " + coordinates.Rotations[i]);
                     continue;
                 }
                 else
                 {
                     _otherTransform.position = new Vector3(
                         coordinates.Coordinates[i].Position.X,
                         coordinates.Coordinates[i].Position.Y,
                         coordinates.Coordinates[i].Position.Z);
                     _otherTransform.rotation = new Quaternion(
                         coordinates.Coordinates[i].Rotation.X,
                         coordinates.Coordinates[i].Rotation.Y,
                         coordinates.Coordinates[i].Rotation.Z,
                         coordinates.Coordinates[i].Rotation.W);
                     //Debug.Log("Other : " + coordinates.Rotations[i]);
                 }
             }
         });
         break;
     }
 }
Beispiel #2
0
        public static GameNetworkClient Connect(IPEndPoint endPoint)
        {
            var tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            tcp.Connect(endPoint);

            var udp = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            udp.Bind(tcp.LocalEndPoint);
            udp.Connect(endPoint);

            var buffer                = new byte[1024];
            var idMessage             = tcp.Receive(buffer);
            var serverAcceptedMessage = ByteConverters.FromBytes <ServerAcceptanceMessage>(buffer);

            if (serverAcceptedMessage.DenyReason != 0)
            {
                throw new Exception("Server denied");
            }

            return(new GameNetworkClient(serverAcceptedMessage.Id, serverAcceptedMessage.ClientId, tcp, udp));
        }