diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index a0903685..80830dbe 100755 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -177,37 +177,43 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter()?.Find( + ship => ship.PlayerID == request.PlayerId); do { if (request.TeamId == 0) semaDict0[request.PlayerId].Item1.Wait(); else if (request.TeamId == 1) semaDict1[request.PlayerId].Item1.Wait(); - try + if (ship == null || ship.IsRemoved == true) + { } + else { - if (currentGameInfo != null && !exitFlag) + try { - await responseStream.WriteAsync(currentGameInfo); - Console.WriteLine("Send!"); + if (currentGameInfo != null && !exitFlag) + { + await responseStream.WriteAsync(currentGameInfo); + Console.WriteLine("Send!"); + } } - } - catch - { - if (!exitFlag) + catch + { + if (!exitFlag) + { + Console.WriteLine($"The client {request.PlayerId} exited"); + exitFlag = true; + } + } + finally { - Console.WriteLine($"The client {request.PlayerId} exited"); - exitFlag = true; + if (request.TeamId == 0) + semaDict0[request.PlayerId].Item2.Release(); + else if (request.TeamId == 1) + semaDict1[request.PlayerId].Item2.Release(); } } - finally - { - if (request.TeamId == 0) - semaDict0[request.PlayerId].Item2.Release(); - else if (request.TeamId == 1) - semaDict1[request.PlayerId].Item2.Release(); - } } while (game.GameMap.Timer.IsGaming); #if DEBUG Console.WriteLine("END Add Player");