Test de communication de paquets entre un client et un serveur
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ServerHandle.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ServerHandle
  5. {
  6. public static void WelcomeReceived(int _fromClient, Packet _packet)
  7. {
  8. int _clientIdCheck = _packet.ReadInt();
  9. string _username = _packet.ReadString();
  10. Debug.Log($"{Server.clients[_fromClient].tcp.socket.Client.RemoteEndPoint} connected successfully and is now player {_fromClient}.");
  11. if (_clientIdCheck != _fromClient)
  12. {
  13. Debug.Log($"Player \"{_username}\" (ID: {_fromClient}) has assumed the wrong client ID ({_clientIdCheck})!");
  14. }
  15. Server.clients[_fromClient].SendIntoGame(_username);
  16. }
  17. public static void PlayerMovement(int _fromClient, Packet _packet)
  18. {
  19. bool[] _inputs = new bool[_packet.ReadInt()];
  20. for (int i = 0; i < _inputs.Length; i++)
  21. {
  22. _inputs[i] = _packet.ReadBool();
  23. }
  24. Quaternion _rotation = _packet.ReadQuaternion();
  25. Server.clients[_fromClient].player.SetInput(_inputs, _rotation);
  26. }
  27. public static void PlayerShoot(int _fromClient, Packet _packet)
  28. {
  29. Vector3 shootDirection = _packet.ReadVector3();
  30. Server.clients[_fromClient].player.Shoot(shootDirection);
  31. }
  32. }