diff --git a/logic/Server/RpcServices.cs b/logic/Server/RpcServices.cs index d168bf86..22be93af 100755 --- a/logic/Server/RpcServices.cs +++ b/logic/Server/RpcServices.cs @@ -178,40 +178,41 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter()?.Find( - ship => ship.PlayerID == request.PlayerId); do { + Ship? ship = game.GameMap.GameObjDict[GameObjType.Ship].Cast()?.Find( + ship => ship.PlayerID == request.PlayerId); if (request.TeamId == 0) semaDict0[request.PlayerId].Item1.Wait(); else if (request.TeamId == 1) semaDict1[request.PlayerId].Item1.Wait(); - //if (ship != null && ship.IsRemoved != true) - //{ - try + if (request.PlayerId > 0 && (ship == null || ship.IsRemoved == true)) { - if (currentGameInfo != null && !exitFlag) - { - await responseStream.WriteAsync(currentGameInfo); - Console.WriteLine("Send!"); - } + Console.WriteLine($"Cannot find ship {request.PlayerId}!"); } - catch + else { - if (!exitFlag) + try { - Console.WriteLine($"The client {request.PlayerId} exited"); - exitFlag = true; + if (currentGameInfo != null && !exitFlag) + { + await responseStream.WriteAsync(currentGameInfo); + Console.WriteLine($"Send to Team {request.TeamId} Player{request.PlayerId}!"); + } + } + catch + { + if (!exitFlag) + { + Console.WriteLine($"The client {request.PlayerId} exited"); + exitFlag = true; + } } } - finally - { - if (request.TeamId == 0) - semaDict0[request.PlayerId].Item2.Release(); - else if (request.TeamId == 1) - semaDict1[request.PlayerId].Item2.Release(); - } - //} + if (request.TeamId == 0) + semaDict0[request.PlayerId].Item2.Release(); + else if (request.TeamId == 1) + semaDict1[request.PlayerId].Item2.Release(); } while (game.GameMap.Timer.IsGaming); }