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); }
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); } }
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); } }
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); }
// 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 ### // }