|
|
@ -62,17 +62,16 @@ public class PongServer
|
|
|
|
Console.WriteLine("Connection " + choisenRoom.Key);
|
|
|
|
Console.WriteLine("Connection " + choisenRoom.Key);
|
|
|
|
if (choisenRoom.Value != default )
|
|
|
|
if (choisenRoom.Value != default )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread join = new Thread(() => Join(data, remoteEndPoint, serverSocket, choisenRoom.Value));
|
|
|
|
Join(data, remoteEndPoint, serverSocket, choisenRoom.Value);
|
|
|
|
join.Start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Thread host = new Thread(() => Host(data, remoteEndPoint, serverSocket, true));
|
|
|
|
Host(data, remoteEndPoint, serverSocket, true);
|
|
|
|
host.Start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -80,11 +79,22 @@ public class PongServer
|
|
|
|
|
|
|
|
|
|
|
|
private void Host(ObjectTransfert<Player> data, IPEndPoint remoteEndPoint, UdpClient serverSocket, bool availaible)
|
|
|
|
private void Host(ObjectTransfert<Player> data, IPEndPoint remoteEndPoint, UdpClient serverSocket, bool availaible)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var choisenRoom = rooms.FirstOrDefault(room => room.Value.Free);
|
|
|
|
|
|
|
|
var chosenPort = nextPort;
|
|
|
|
|
|
|
|
if (choisenRoom.Value != default)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
chosenPort= choisenRoom.Value.Port;
|
|
|
|
|
|
|
|
choisenRoom.Value.playerHost.Value.Close();
|
|
|
|
|
|
|
|
choisenRoom.Value.playerJoin.Value.Close();
|
|
|
|
|
|
|
|
rooms.Remove(choisenRoom.Key);
|
|
|
|
|
|
|
|
choisenRoom = default;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Room room = new Room(data.Data.playerId, availaible);
|
|
|
|
Room room = new Room(data.Data.playerId, availaible);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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, chosenPort);
|
|
|
|
UdpClient clientSocket = new UdpClient(clientEndPoint);
|
|
|
|
UdpClient clientSocket = new UdpClient(clientEndPoint);
|
|
|
|
|
|
|
|
|
|
|
|
room.playerHost = new KeyValuePair<Player,UdpClient>(data.Data,clientSocket);
|
|
|
|
room.playerHost = new KeyValuePair<Player,UdpClient>(data.Data,clientSocket);
|
|
|
@ -95,8 +105,12 @@ public class PongServer
|
|
|
|
Console.WriteLine("New connection Host From " + remoteEndPoint.ToString());
|
|
|
|
Console.WriteLine("New connection Host From " + remoteEndPoint.ToString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
room.Port = nextPort;
|
|
|
|
room.Port = chosenPort;
|
|
|
|
nextPort++;
|
|
|
|
if(chosenPort==nextPort)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
nextPort++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tuple<int, bool> dataToSend = new Tuple<int, bool>(room.Port, true);
|
|
|
|
Tuple<int, bool> dataToSend = new Tuple<int, bool>(room.Port, true);
|
|
|
@ -107,7 +121,7 @@ public class PongServer
|
|
|
|
serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint);
|
|
|
|
serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint);
|
|
|
|
|
|
|
|
|
|
|
|
rooms[data.Data.playerId] = room;
|
|
|
|
rooms[data.Data.playerId] = room;
|
|
|
|
room.PropertyChanged += room.OnReadyChanged;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("FIN HOST...............");
|
|
|
|
Console.WriteLine("FIN HOST...............");
|
|
|
|
|
|
|
|
|
|
|
|