remove server from the list when it quits (#1)

* remove server from the list when it quits

* remove whitespace
This commit is contained in:
CommonLoon102 2020-01-25 15:13:36 +00:00 committed by GitHub
parent cbccbcf0d2
commit dd95382d08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 0 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace Supervisor
{
@ -37,6 +38,9 @@ namespace Supervisor
case 'C':
ProcessFragsPacket(buffer);
break;
case 'D':
ProcessRemovePacket(message);
break;
default:
break;
}
@ -150,6 +154,27 @@ namespace Supervisor
});
}
private static void ProcessRemovePacket(string message)
{
string[] splitMessage = message.SplitMessage();
var packetData = new RemoveServer()
{
Port = int.Parse(splitMessage[0])
};
UpdateState(packetData);
}
private static void UpdateState(RemoveServer packetData)
{
bool isSuccess;
do
{
isSuccess = Program.State.Servers.TryRemove(packetData.Port, out _);
Thread.Sleep(TimeSpan.FromSeconds(1));
} while (!isSuccess);
}
private static string GetGameType(int gameType)
{
return gameType switch

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Supervisor
{
class RemoveServer : PacketData
{
public RemoveServer()
{
IsStarted = false;
}
}
}

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "3.1.0"
}
}
}

View File

@ -12,6 +12,7 @@
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\Supervisor\Supervisor.csproj" />
</ItemGroup>