Merge branch 'master' of https://codefirst.iut.uca.fr/git/LeapHitTeam/LeapHitServer
continuous-integration/drone/push Build is passing Details

deployment
Hugo LIVET 2 years ago
commit ba0086a46d

@ -8,7 +8,7 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
builder.Services.AddScoped<DbDataManager>(); builder.Services.AddSingleton<DbDataManager>();
//builder.Services.AddSingleton<IDataManager, StubData>(); //builder.Services.AddSingleton<IDataManager, StubData>();
// Add logging // Add logging

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

@ -1,5 +1,3 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app WORKDIR /app
EXPOSE 80 EXPOSE 80
@ -14,6 +12,7 @@ RUN dotnet restore "ApiLeapHit/ApiLeapHit.csproj"
COPY . . COPY . .
WORKDIR "/src/ApiLeapHit" WORKDIR "/src/ApiLeapHit"
RUN dotnet build "ApiLeapHit.csproj" -c Release -o /app/build RUN dotnet build "ApiLeapHit.csproj" -c Release -o /app/build
RUN rm -rf /root/.nuget/packages/*
FROM build AS publish FROM build AS publish
RUN dotnet publish "ApiLeapHit.csproj" -c Release -o /app/publish RUN dotnet publish "ApiLeapHit.csproj" -c Release -o /app/publish

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

@ -0,0 +1,105 @@
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);
}
}
}

@ -0,0 +1,26 @@
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; }
}
}
Loading…
Cancel
Save