Test de communication de paquets entre un client et un serveur
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ServerHandle.cs 1.2KB

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