Browse Source

feat: 🐛 add ArgumentOptions.spectator to determine whether spectator is allowed

tags/0.1.0
gsy1519 2 years ago
parent
commit
173bf01591
4 changed files with 16 additions and 6 deletions
  1. +7
    -1
      logic/Server/ArgumentOption.cs
  2. +7
    -3
      logic/Server/GameServer.cs
  3. +1
    -1
      logic/Server/PlaybackServer.cs
  4. +1
    -1
      logic/Server/RpcServices.cs

+ 7
- 1
logic/Server/ArgumentOption.cs View File

@@ -28,7 +28,10 @@ namespace Server
public ushort TrickerCount { get; set; } = 1;

[Option("maxStudentCount", Required = false, HelpText = "The max number of students, 4 by default")]
public ushort MaxStudentCount { get; set; } = 4;
public ushort MaxStudentCount { get; } = 4;

[Option("maxTrickerCount", Required = false, HelpText = "The max number of trickers, 1 by default")]
public ushort MaxTrickerCount { get; } = 1;

[Option('g', "gameTimeInSecond", Required = false, HelpText = "The time of the game in second, 10 minutes by default")]
public uint GameTimeInSecond { get; set; } = 10 * 60;
@@ -36,6 +39,9 @@ namespace Server
[Option('f', "fileName", Required = false, HelpText = "The file to store playback file or to read file.")]
public string FileName { get; set; } = DefaultArgumentOptions.FileName;

[Option('s', "spectator", Required = false, HelpText = "Whether allow a spectator to watch the game.")]
public bool spectator { get; set; } = true;

[Option('b', "playback", Required = false, HelpText = "Whether open the server in a playback mode.")]
public bool Playback { get; set; } = false;



+ 7
- 3
logic/Server/GameServer.cs View File

@@ -40,10 +40,10 @@ namespace Server
public void StartGame()
{
if (game.GameMap.Timer.IsGaming) return;
/*foreach (var id in communicationToGameID)
foreach (var id in communicationToGameID)
{
if (id == GameObj.invalidID) return; //如果有未初始化的玩家,不开始游戏
}*/ //测试时人数不够
}
Console.WriteLine("Game starts!");
game.StartGame((int)options.GameTimeInSecond * 1000);
Thread.Sleep(1);
@@ -319,7 +319,11 @@ namespace Server
currentMapMsg = MapMsg(game.GameMap.ProtoGameMap);
communicationToGameID = new long[options.MaxStudentCount + options.TrickerCount];
//创建server时先设定待加入人物都是invalid
for (int i = 0; i < communicationToGameID.GetLength(0); i++)
for (int i = 0; i < options.StudentCount; i++)
{
communicationToGameID[i] = GameObj.invalidID;
}
for (int i = options.MaxStudentCount; i < options.MaxStudentCount + options.TrickerCount; i++)
{
communicationToGameID[i] = GameObj.invalidID;
}


+ 1
- 1
logic/Server/PlaybackServer.cs View File

@@ -192,7 +192,7 @@ namespace Server
if (item.StudentMessage != null)
teamScore[0, item.StudentMessage.PlayerId] = item.StudentMessage.Score;
if (item.TrickerMessage != null)
teamScore[1, item.TrickerMessage.PlayerId - mr.playerCount] = item.TrickerMessage.Score;
teamScore[1, item.TrickerMessage.PlayerId - options.MaxStudentCount] = item.TrickerMessage.Score; // 这里默认 Tricker 的 PlayerId 从 MaxStudentCount = 4 开始
}
}



+ 1
- 1
logic/Server/RpcServices.cs View File

@@ -56,7 +56,7 @@ namespace Server
{

Console.WriteLine($"AddPlayer: {request.PlayerId}");
if (request.PlayerId >= spectatorMinPlayerID)
if (request.PlayerId >= spectatorMinPlayerID && options.spectator == true)
{
// 观战模式
uint tp = (uint)request.PlayerId;


Loading…
Cancel
Save