Skip to content

Commit

Permalink
fix small bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoWQ222 committed Apr 13, 2024
1 parent 92c8cf6 commit de9acb2
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions logic/Server/RpcServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,37 +177,43 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
StartGame();
}
}

bool exitFlag = false;
Ship? ship = game.GameMap.GameObjDict[GameObjType.Ship].Cast<Ship>()?.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");
Expand Down

0 comments on commit de9acb2

Please sign in to comment.