🔨 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 name { get; set; }
public int nbBallTouchTotal { get; set; }
public bool ready { get; set; } = false;
public int timePlayed { get; set; }
}
}

@ -40,7 +40,7 @@ public class PongServer
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.nbPlayer++;
Console.WriteLine("New connection from " + remoteEndPoint.ToString());
@ -52,13 +52,12 @@ public class PongServer
UdpClient clientSocket = new UdpClient(clientEndPoint);
clients[remoteEndPoint] = clientSocket;
// Send connection message to client
string connectionMessage = room.ID;
byte[] connectionData = Encoding.ASCII.GetBytes(connectionMessage);
// Send connection message to client
byte[] connectionData = Encoding.ASCII.GetBytes(room.Id);
serverSocket.Send(connectionData, connectionData.Length, remoteEndPoint);
// Start thread to receive data from client
Thread receiveThread = new Thread(() => ReceiveMessages(clientSocket));
Thread receiveThread = new Thread(() => Room.ReceiveMessages(clientSocket, data.Data));
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.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Shared.DTO;
namespace Server
{
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 playerJoin;
public int nbPlayer = 0;
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
{
Start,
Create,
Connect,
Join,
End
}
}

Loading…
Cancel
Save