Skip to content

Commit

Permalink
Merge pull request #225 from GuoWQ222/dev
Browse files Browse the repository at this point in the history
fix: 🐛 Server阻塞
  • Loading branch information
GuoWQ222 authored Apr 13, 2024
2 parents 3a7c1c3 + a60ae63 commit 8ebd1ec
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions logic/Server/RpcServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,40 +178,41 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
}
}
bool exitFlag = false;
Ship? ship = game.GameMap.GameObjDict[GameObjType.Ship].Cast<Ship>()?.Find(
ship => ship.PlayerID == request.PlayerId);
do
{
Ship? ship = game.GameMap.GameObjDict[GameObjType.Ship].Cast<Ship>()?.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);
}

Expand Down

0 comments on commit 8ebd1ec

Please sign in to comment.