🔨 Ajout condition des qu'il y a 2 players le jeu va demarrer.
continuous-integration/drone/push Build is failing Details

pull/7/head^2
Bruno DA COSTA CUNHA 2 years ago
parent 95fbe12aad
commit 997a626a7c

@ -7,9 +7,11 @@ using System.Threading;
using DataBase.Entity; using DataBase.Entity;
using Shared.DTO; using Shared.DTO;
using System.Text.Json; using System.Text.Json;
using Server;
class Program class Program
{ {
//sert juste à stocker les connexions pour l'instant
static Dictionary<IPEndPoint, UdpClient> clients = new Dictionary<IPEndPoint, UdpClient>(); static Dictionary<IPEndPoint, UdpClient> clients = new Dictionary<IPEndPoint, UdpClient>();
static int nextPort = 3132; static int nextPort = 3132;
@ -21,6 +23,7 @@ class Program
static void StartServer() static void StartServer()
{ {
Room room = new Room();
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, 3131); IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, 3131);
UdpClient serverSocket = new UdpClient(serverEndPoint); UdpClient serverSocket = new UdpClient(serverEndPoint);
Console.WriteLine("Server started, waiting for clients to connect..."); Console.WriteLine("Server started, waiting for clients to connect...");
@ -31,6 +34,8 @@ class Program
byte[] receivedData = serverSocket.Receive(ref remoteEndPoint); byte[] receivedData = serverSocket.Receive(ref remoteEndPoint);
string fileJson = Encoding.UTF8.GetString(receivedData); string fileJson = Encoding.UTF8.GetString(receivedData);
ObjectTransfert<Player> data = JsonSerializer.Deserialize<ObjectTransfert<Player>>(fileJson); ObjectTransfert<Player> data = JsonSerializer.Deserialize<ObjectTransfert<Player>>(fileJson);
room.MaxPlayers.Add(data.Data);
if (data.Informations.Action == Shared.DTO.Action.Connect) if (data.Informations.Action == Shared.DTO.Action.Connect)
@ -38,7 +43,7 @@ class Program
Console.WriteLine("New connection from " + remoteEndPoint.ToString()); Console.WriteLine("New connection from " + remoteEndPoint.ToString());
// Assign a unique port to the client // Assign a unique port to the client
IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, nextPort++); ; IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, nextPort++);
UdpClient clientSocket = new UdpClient(clientEndPoint); UdpClient clientSocket = new UdpClient(clientEndPoint);
clients[remoteEndPoint] = clientSocket; clients[remoteEndPoint] = clientSocket;
@ -51,6 +56,12 @@ class Program
Thread receiveThread = new Thread(()=>ReceiveMessages(clientSocket)); Thread receiveThread = new Thread(()=>ReceiveMessages(clientSocket));
receiveThread.Start(); receiveThread.Start();
if (room.MaxPlayers.Count == 2)
{
Console.WriteLine("Starting game...");
// Call a function to start the game
}
} }
} }
} }

Loading…
Cancel
Save