Skip to content

Commit

Permalink
style: 🎨 style format
Browse files Browse the repository at this point in the history
  • Loading branch information
sigureling committed Apr 14, 2024
1 parent 23a1cb2 commit 1fa6839
Showing 1 changed file with 30 additions and 40 deletions.
70 changes: 30 additions & 40 deletions logic/Server/RpcServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ partial class GameServer : ServerBase
protected bool isSpectatorJoin = false;
protected bool IsSpectatorJoin
{
get
{
lock (spectatorLock)
return isSpectatorJoin;
get {
lock (spectatorLock) return isSpectatorJoin;
}

set
{
set {
lock (spectatorLock)
isSpectatorJoin = value;
}
Expand All @@ -29,7 +26,7 @@ public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext con
{
#if DEBUG
Console.WriteLine($"TRY TryConnection: Player {request.PlayerId} from Team {request.TeamId}");
#endif
#endif
var onConnection = new BoolRes();
lock (gameLock)
{
Expand All @@ -43,11 +40,11 @@ public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext con
onConnection.ActSuccess = false;
#if DEBUG
Console.WriteLine("END TryConnection");
#endif
#endif
return Task.FromResult(onConnection);
}

#region 游戏开局调用一次的服务
#region 游戏开局调用一次的服务

protected readonly object addPlayerLock = new();
public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<MessageToClient> responseStream, ServerCallContext context)
Expand All @@ -61,7 +58,7 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
Console.WriteLine($"TRY Add Spectator: Player {request.PlayerId}");
#endif
// 观战模式
lock (spectatorJoinLock) // 具体原因见另一个上锁的地方
lock (spectatorJoinLock) // 具体原因见另一个上锁的地方
{
if (semaDict0.TryAdd(request.PlayerId, (new SemaphoreSlim(0, 1), new SemaphoreSlim(0, 1))))
{
Expand Down Expand Up @@ -94,7 +91,9 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
semas.Item1.Release();
semas.Item2.Release();
}
catch { }
catch
{
}
Console.WriteLine($"The spectator {request.PlayerId} exited");
return;
}
Expand All @@ -109,7 +108,9 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
{
semaDict0[request.PlayerId].Item2.Release();
}
catch { }
catch
{
}
}
} while (game.GameMap.Timer.IsGaming);
#if DEBUG
Expand All @@ -133,9 +134,7 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
#endif
lock (addPlayerLock)
{
Game.PlayerInitInfo playerInitInfo = new(request.TeamId,
request.PlayerId,
Transformation.ShipTypeFromProto(request.ShipType));
Game.PlayerInitInfo playerInitInfo = new(request.TeamId, request.PlayerId, Transformation.ShipTypeFromProto(request.ShipType));
long newPlayerID = game.AddPlayer(playerInitInfo);
if (newPlayerID == GameObj.invalidID)
{
Expand Down Expand Up @@ -199,7 +198,7 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
}
else
{
if(firstTime)
if (firstTime)
firstTime = false;
try
{
Expand All @@ -217,7 +216,6 @@ public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<Mess
exitFlag = true;
}
}

}
(request.TeamId == 0 ? semaDict0 : semaDict1)[request.PlayerId].Item2.Release();
} while (game.GameMap.Timer.IsGaming);
Expand All @@ -231,11 +229,11 @@ public override Task<MessageOfMap> GetMap(NullRequest request, ServerCallContext
return Task.FromResult(MapMsg());
}

#endregion
#endregion

#region 游戏过程中玩家执行操作的服务
#region 游戏过程中玩家执行操作的服务

#region 船
#region 船

/*public override Task<BoolRes> Activate(ActivateMsg request, ServerCallContext context)
{
Expand Down Expand Up @@ -275,7 +273,8 @@ public override Task<MoveRes> Move(MoveMsg request, ServerCallContext context)
}
// var gameID = communicationToGameID[request.TeamId][request.PlayerId];
moveRes.ActSuccess = game.MoveShip(request.TeamId, request.PlayerId, (int)request.TimeInMilliseconds, request.Angle);
if (!game.GameMap.Timer.IsGaming) moveRes.ActSuccess = false;
if (!game.GameMap.Timer.IsGaming)
moveRes.ActSuccess = false;
#if DEBUG
Console.WriteLine($"END Move: {moveRes.ActSuccess}");
#endif
Expand Down Expand Up @@ -413,8 +412,7 @@ public override Task<BoolRes> Send(SendMsg request, ServerCallContext context)
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
MessageOfNews news = new()
{
MessageOfNews news = new() {
TextMessage = request.TextMessage,
FromId = request.PlayerId,
ToId = request.ToPlayerId
Expand Down Expand Up @@ -442,8 +440,7 @@ public override Task<BoolRes> Send(SendMsg request, ServerCallContext context)
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
MessageOfNews news = new()
{
MessageOfNews news = new() {
BinaryMessage = request.BinaryMessage,
FromId = request.PlayerId,
ToId = request.ToPlayerId
Expand All @@ -470,9 +467,9 @@ public override Task<BoolRes> Send(SendMsg request, ServerCallContext context)
}
}

#endregion
#endregion

#region 大本营
#region 大本营

public override Task<BoolRes> InstallModule(InstallMsg request, ServerCallContext context)
{
Expand Down Expand Up @@ -517,13 +514,9 @@ public override Task<BoolRes> BuildShip(BuildShipMsg request, ServerCallContext
#if DEBUG
Console.WriteLine($"TRY BuildShip: ShipType {request.ShipType} from Team {request.TeamId}");
#endif
BoolRes boolRes = new()
{
BoolRes boolRes = new() {
ActSuccess =
game.ActivateShip(request.TeamId,
Transformation.ShipTypeFromProto(request.ShipType),
request.BirthpointIndex)
!= GameObj.invalidID
game.ActivateShip(request.TeamId, Transformation.ShipTypeFromProto(request.ShipType), request.BirthpointIndex) != GameObj.invalidID
};
#if DEBUG
Console.WriteLine("END BuildShip");
Expand All @@ -536,11 +529,8 @@ public override Task<BuildShipRes> BuildShipRID(BuildShipMsg request, ServerCall
#if DEBUG
Console.WriteLine($"TRY BuildShipRID: ShipType {request.ShipType} from Team {request.TeamId}");
#endif
var playerId = game.ActivateShip(request.TeamId,
Transformation.ShipTypeFromProto(request.ShipType),
request.BirthpointIndex);
BuildShipRes buildShipRes = new()
{
var playerId = game.ActivateShip(request.TeamId, Transformation.ShipTypeFromProto(request.ShipType), request.BirthpointIndex);
BuildShipRes buildShipRes = new() {
ActSuccess = playerId != GameObj.invalidID,
PlayerId = playerId
};
Expand Down Expand Up @@ -569,8 +559,8 @@ public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext cont
return Task.FromResult(boolRes);
}

#endregion
#endregion

#endregion
#endregion
}
}

0 comments on commit 1fa6839

Please sign in to comment.