コード例 #1
0
 public static void Welcome(int clientId, string message)
 {
     LogPosition.Log("Package sent");
     using Packet packet = new Packet((int)PacketId.Welcome);
     packet.Write(message);
     packet.Write(clientId);
     SendTcpData(clientId, packet);
 }
コード例 #2
0
 public static void PlayerRotation(Player player)
 {
     LogPosition.Log("Package sent");
     using (Packet packet = new Packet((int)PacketId.PlayerRotation)) {
         packet.Write(player.Id);
         packet.Write(player.Rotation);
         SendUdpDataToAllClients(player.Id, packet);
     }
 }
コード例 #3
0
        public static void SpawnPlayer(int toClient, Player player)
        {
            LogPosition.Log("Package sent");
            using (Packet packet = new Packet((int)PacketId.SpawnPlayer)) {
                packet.Write(player.Id);
                packet.Write(player.Username);
                packet.Write(player.Position);
                packet.Write(player.Rotation);

                SendTcpData(toClient, packet);
            }
        }
コード例 #4
0
        public static void PlayerMovement(int clientId, Packet packet)
        {
            LogPosition.Log("Package Received");
            bool[] inputs = new bool[packet.ReadInt()];
            for (int i = 0; i < inputs.Length; i++)
            {
                inputs[i] = packet.ReadBool();
            }

            Quaternion rotation = packet.ReadRotation();

            Server._Clients[clientId].Player.SetInput(inputs, rotation);
        }
コード例 #5
0
        // Add new listener logic here
        public static void WelcomeReceived(int clientId, Package.Packet packet)
        {
            LogPosition.Log("Package Received");
            int    clientIdCheck = packet.ReadInt();
            string username      = packet.ReadString();

            Console.WriteLine($"\n### TCP WELCOME PACKAGE REPLY ### \n" +
                              $"REPLY: {Server._Clients[clientId].Tcp.socket.Client.RemoteEndPoint} " +
                              $"name: {username} " +
                              $"connected successfully and received the welcome package. " +
                              $"Client is now player {clientId}.");
            if (clientId != clientIdCheck)   // Should never be printed, something is very wrong if this is printed
            {
                Console.WriteLine($"Player '{username}' (ID: {clientId} has assumed the wrong client ID: {clientIdCheck}");
            }
            Server._Clients[clientId].SendIntoGame(username);

            // Todo: ### Send player into the game ### //
        }