Modify LobbyServer

This commit is contained in:
2019-05-04 17:51:19 +02:00
parent ed1771664b
commit 6c0e8a83a5
4 changed files with 24 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
namespace LobbyServer
{
@@ -9,6 +10,7 @@ namespace LobbyServer
public ChatManager()
{
_messages = new List<Message>();
Add(new Message("13:37", "QuadraLudi", "Bienvenue dans QuadraLudi, amusez-vous bien!\nGit: https://eveldee.ddns.net:1342/Eveldee/Quadraludi"));
}
public void Add(Message message)

View File

@@ -38,6 +38,15 @@ namespace LobbyServer
}
}
public void Stop()
{
Console.WriteLine("Stopping LobbyServer...");
ScoresManager.Save();
Console.WriteLine("LobbyServer stopped");
}
public void ClientLoop(TcpClient client)
{
Console.WriteLine($"Client connected: {client.Client.RemoteEndPoint}");
@@ -49,6 +58,7 @@ namespace LobbyServer
try
{
var packet = stream.Receive();
Console.WriteLine(packet);
switch (packet.Command)
{
@@ -71,6 +81,7 @@ namespace LobbyServer
catch (Exception e)
{
Console.WriteLine($"Client disconnected: {e.Message}");
break;
}
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using System;
namespace LobbyServer
{
@@ -6,7 +7,12 @@ namespace LobbyServer
{
static void Main(string[] args)
{
new LobbyServer().Start();
var lobbyServer = new LobbyServer();
Task.Run(() => lobbyServer.Start());
while (Console.ReadLine() != "stop");
lobbyServer.Stop();
}
}
}

View File

@@ -1,3 +1,5 @@
using Newtonsoft.Json;
namespace LobbyServer
{
public class ScoreEntry
@@ -5,12 +7,12 @@ namespace LobbyServer
public string Pseudo { get; }
public int Score { get; }
[JsonConstructor]
public ScoreEntry(string pseudo, int score)
{
Pseudo = pseudo;
Score = score;
}
public ScoreEntry(string serialized)
{
var split = serialized.Split(';');