Compare commits

..

No commits in common. 'af59b19b431500a95900d4db8e27e1fa7dfbbc30' and 'ad24c90aad19514f0bb97a6cdce8296a631efddf' have entirely different histories.

@ -13,7 +13,7 @@ class Program
static void StartClient()
{
IPEndPoint serverEndPoint = new IPEndPoint(Dns.GetHostAddresses("hulivet.fr").FirstOrDefault(), 3131);
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3131);
UdpClient client = new UdpClient();
// Send connection message to server
@ -31,7 +31,7 @@ class Program
string message = "";
while (message != "exit")
{
serverEndPoint = new IPEndPoint(Dns.GetHostAddresses("hulivet.fr").FirstOrDefault(), int.Parse(receivedPort));
serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), int.Parse(receivedPort));
Console.Write("Enter message to send (or 'exit' to quit): ");
message = Console.ReadLine();

@ -17,8 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{12A97D16-3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientConsole", "ClientConsole\ClientConsole.csproj", "{33F7C629-F92B-459C-BCC5-6A4601D6D9EA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{CA1465F2-A006-4AF6-8231-59DB00963BD0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -49,10 +47,6 @@ Global
{33F7C629-F92B-459C-BCC5-6A4601D6D9EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33F7C629-F92B-459C-BCC5-6A4601D6D9EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33F7C629-F92B-459C-BCC5-6A4601D6D9EA}.Release|Any CPU.Build.0 = Release|Any CPU
{CA1465F2-A006-4AF6-8231-59DB00963BD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA1465F2-A006-4AF6-8231-59DB00963BD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA1465F2-A006-4AF6-8231-59DB00963BD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA1465F2-A006-4AF6-8231-59DB00963BD0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -1,105 +0,0 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using DataBase.Entity;
using Shared.DTO;
using System.Text.Json;
using Server;
public class PongServer
{
//sert juste à stocker les connexions pour l'instant
static Dictionary<IPEndPoint, UdpClient> clients = new Dictionary<IPEndPoint, UdpClient>();
Dictionary<string, Room> rooms = new Dictionary<string, Room>();
int nextPort;
int listenPort;
public PongServer(int port = 3131)
{
nextPort = port + 1;
listenPort = port;
}
public void StartServer()
{
IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, listenPort);
UdpClient serverSocket = new UdpClient(serverEndPoint);
Console.WriteLine("Server started, waiting for clients to connect...");
while (true)
{
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] receivedData = serverSocket.Receive(ref remoteEndPoint);
string fileJson = Encoding.UTF8.GetString(receivedData);
ObjectTransfert<Player> data = JsonSerializer.Deserialize<ObjectTransfert<Player>>(fileJson);
if (data.Informations.Action == Shared.DTO.Action.Create)
{
Room room = new Room(data.Data.playerID);
room.playerHost = data.Data;
room.nbPlayer++;
Console.WriteLine("New connection from " + remoteEndPoint.ToString());
// Assign a unique port to the client
IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, nextPort);
room.Port = nextPort;
nextPort++;
UdpClient clientSocket = new UdpClient(clientEndPoint);
clients[remoteEndPoint] = clientSocket;
// Send connection message to client
string connectionMessage = room.ID;
byte[] connectionData = Encoding.ASCII.GetBytes(connectionMessage);
serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint);
// Start thread to receive data from client
Thread receiveThread = new Thread(() => ReceiveMessages(clientSocket));
receiveThread.Start();
}
if (data.Informations.Action == Shared.DTO.Action.Join)
{
Console.WriteLine("New connection from " + remoteEndPoint.ToString());
// Assign a unique port to the client
IPEndPoint clientEndPoint = new IPEndPoint(IPAddress.Any, nextPort++);
UdpClient clientSocket = new UdpClient(clientEndPoint);
clients[remoteEndPoint] = clientSocket;
// Send connection message to client
string connectionMessage = clientEndPoint.Port.ToString();
byte[] connectionData = Encoding.ASCII.GetBytes(connectionMessage);
serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint);
// Start thread to receive data from client
Thread receiveThread = new Thread(() => ReceiveMessages(clientSocket));
receiveThread.Start();
}
if (room.MaxPlayers.Count == 2)
{
Console.WriteLine("Starting game...");
// Call a function to start the game
}
}
}
static void ReceiveMessages(UdpClient clientSocket)
{
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
while (true)
{
byte[] receivedData = clientSocket.Receive(ref remoteEndPoint);
string receivedMessage = Encoding.ASCII.GetString(receivedData);
Console.WriteLine("Received from " + remoteEndPoint.ToString() + ": " + receivedMessage);
}
}
}

@ -1,26 +0,0 @@
using DataBase.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Server
{
public class Room
{
public Room(int id)
{
ID = id;
}
public int ID { get; set; }
public Player playerHost;
public Player playerJoin;
public int nbPlayer = 0;
public int Port { get; set; }
}
}

@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DataBase\DataBase.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataBase\DataBase.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTO
{
public enum Action
{
Start,
Connect,
End
}
}

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTO
{
public class Informations
{
public Action Action { get; set; }
}
}

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shared.DTO
{
public class ObjectTransfert<T>
{
public Informations Informations { get; set; }
public T Data { get; set; }
}
}

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Loading…
Cancel
Save