Improve websocket code.

This commit is contained in:
Li 2022-11-17 02:52:30 +13:00
parent e74f66a439
commit b9e3949b14
8 changed files with 186 additions and 79 deletions

View file

@ -109,29 +109,21 @@ namespace HISP.Server
}
public static void CreateClient(object sender, SocketAsyncEventArgs e)
{
#if !DEBUG
try
do
{
#endif
do
{
Socket clientSocket = e.AcceptSocket;
Socket clientSocket = e.AcceptSocket;
if (GameServer.ServerSocket == null)
return;
if (clientSocket == null)
continue;
if (clientSocket.RemoteEndPoint == null)
continue;
if (GameServer.ServerSocket == null)
return;
if (clientSocket == null)
continue;
if (clientSocket.RemoteEndPoint == null)
continue;
connectedClients.Add(new GameClient(clientSocket));
e.AcceptSocket = null;
connectedClients.Add(new GameClient(clientSocket));
e.AcceptSocket = null;
} while (!GameServer.ServerSocket.AcceptAsync(e));
#if !DEBUG
}
catch (ObjectDisposedException ex) { Logger.ErrorPrint("Server shutdown due to " + ex.Message); } // server shutdown
#endif
} while (!GameServer.ServerSocket.AcceptAsync(e));
}
private void timeoutTimerTick(object state)
{
@ -394,6 +386,7 @@ namespace HISP.Server
if (packet.Length < 1)
{
Logger.ErrorPrint("Received an invalid packet (size: "+packet.Length+")");
return;
}
byte identifier = packet[0];