🔨 changer pas mal de chose
continuous-integration/drone/push Build is passing Details

ServerDeployement
Rami KHEDAIR 2 years ago
parent ba0086a46d
commit 89f8b31cc0

@ -8,6 +8,7 @@ namespace DataBase.Entity
public string playerId { get; set; } public string playerId { get; set; }
public string name { get; set; } public string name { get; set; }
public int nbBallTouchTotal { get; set; } public int nbBallTouchTotal { get; set; }
public bool ready { get; set; } = false;
public int timePlayed { get; set; } public int timePlayed { get; set; }
} }
} }

@ -40,7 +40,7 @@ public class PongServer
if (data.Informations.Action == Shared.DTO.Action.Create) if (data.Informations.Action == Shared.DTO.Action.Create)
{ {
Room room = new Room(data.Data.playerID); Room room = new Room(data.Data.playerId);
room.playerHost = data.Data; room.playerHost = data.Data;
room.nbPlayer++; room.nbPlayer++;
Console.WriteLine("New connection from " + remoteEndPoint.ToString()); Console.WriteLine("New connection from " + remoteEndPoint.ToString());
@ -52,13 +52,12 @@ public class PongServer
UdpClient clientSocket = new UdpClient(clientEndPoint); UdpClient clientSocket = new UdpClient(clientEndPoint);
clients[remoteEndPoint] = clientSocket; clients[remoteEndPoint] = clientSocket;
// Send connection message to client // Send connection message to client
string connectionMessage = room.ID; byte[] connectionData = Encoding.ASCII.GetBytes(room.Id);
byte[] connectionData = Encoding.ASCII.GetBytes(connectionMessage);
serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint); serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint);
// Start thread to receive data from client // Start thread to receive data from client
Thread receiveThread = new Thread(() => ReceiveMessages(clientSocket)); Thread receiveThread = new Thread(() => Room.ReceiveMessages(clientSocket, data.Data));
receiveThread.Start(); receiveThread.Start();
} }
@ -91,15 +90,5 @@ public class PongServer
} }
} }
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);
}
}
} }

@ -2,25 +2,55 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Shared.DTO;
namespace Server namespace Server
{ {
public class Room public class Room
{ {
public Room(int id) public Room(string id)
{ {
ID = id; Id = id;
} }
public int ID { get; set; } public string Id { get; set; }
public Player playerHost; public Player playerHost;
public Player playerJoin; public Player playerJoin;
public int nbPlayer = 0; public int nbPlayer = 0;
public int Port { get; set; } public int Port { get; set; }
public static void ReceiveMessages(UdpClient clientSocket,Player player)
{
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);
if (receivedMessage.ToUpper().Equals("READY"))
{
player.ready = true;
}
while (true) //score
{
//cordinate paddel
receivedData = clientSocket.Receive(ref remoteEndPoint);
receivedMessage = Encoding.ASCII.GetString(receivedData);
}
}
}
} }
} }

@ -8,8 +8,9 @@ namespace Shared.DTO
{ {
public enum Action public enum Action
{ {
Start, Create,
Connect, Connect,
Join,
End End
} }
} }

Loading…
Cancel
Save