Gestion du nombre de clients permits dans le server
continuous-integration/drone/push Build is failing Details

Server
Bruno DA COSTA CUNHA 2 years ago
parent ac074ed3d9
commit a20b02dc33

@ -1,12 +1,14 @@
using System; using System;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Collections.Generic;
class Program class Program
{ {
static int playerCount = 0; static int playerCount = 0;
static List<IPEndPoint> clientAddresses = new List<IPEndPoint>(); // Liste des adresses IP des clients connectés
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Welcome to LeapHit Multiplayer - Server"); Console.WriteLine("Welcome to LeapHit Multiplayer - Server");
@ -26,13 +28,21 @@ class Program
byte[] data = server.Receive(ref clientEndPoint); byte[] data = server.Receive(ref clientEndPoint);
string dataReceived = System.Text.Encoding.ASCII.GetString(data); string dataReceived = System.Text.Encoding.ASCII.GetString(data);
Console.WriteLine("Data received from client: " + dataReceived + " from " + clientEndPoint.ToString()); Console.WriteLine("Data received from client: " + dataReceived + " from " + clientEndPoint.ToString());
playerCount++;
if (playerCount == 2) if (!clientAddresses.Contains(clientEndPoint)) // Vérification si l'adresse IP est déjà présente dans la liste
{ {
Console.WriteLine("Deux joueurs connectés, le jeu va commencer..."); clientAddresses.Add(clientEndPoint); // Ajout de l'adresse IP à la liste
// On va mettre le code du pour demarrer le match ici playerCount++;
if (playerCount == 2)
{
Console.WriteLine("Deux joueurs connectés, le jeu va commencer...");
// On va mettre le code du pour demarrer le match ici
}
}
else
{
Console.WriteLine("Client with IP " + clientEndPoint.Address.ToString() + " has already sent a message and will not be counted.");
} }
} }

Loading…
Cancel
Save