You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

GameServer.cs 25 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. using Grpc.Core;
  2. using Protobuf;
  3. using System.Threading;
  4. using Timothy.FrameRateTask;
  5. using System;
  6. using System.Net.Http.Headers;
  7. using Gaming;
  8. using GameClass.GameObj;
  9. using Preparation.Utility;
  10. using Playback;
  11. using Newtonsoft.Json;
  12. using Newtonsoft.Json.Linq;
  13. using Preparation.Interface;
  14. namespace Server
  15. {
  16. public class GameServer : AvailableService.AvailableServiceBase
  17. {
  18. private Dictionary<long, (SemaphoreSlim, SemaphoreSlim)> semaDict = new();
  19. protected readonly ArgumentOptions options;
  20. private HttpSender? httpSender;
  21. private object gameLock = new();
  22. private MessageToClient currentGameInfo = new();
  23. private MessageOfObj currentMapMsg = new();
  24. private object newsLock = new();
  25. private List<MessageOfNews> currentNews = new();
  26. private SemaphoreSlim endGameSem = new(0);
  27. protected readonly Game game;
  28. private uint spectatorMinPlayerID = 2023;
  29. private List<uint> spectatorList = new List<uint>();
  30. public int playerNum;
  31. public int TeamCount => options.TeamCount;
  32. protected long[] communicationToGameID; // 通信用的ID映射到游戏内的ID,通信中0-3为Student,4为Tricker
  33. private readonly object messageToAllClientsLock = new();
  34. public static readonly long SendMessageToClientIntervalInMilliseconds = 50;
  35. private MessageWriter? mwr = null;
  36. public void StartGame()
  37. {
  38. if (game.GameMap.Timer.IsGaming) return;
  39. /*foreach (var id in communicationToGameID)
  40. {
  41. if (id == GameObj.invalidID) return; //如果有未初始化的玩家,不开始游戏
  42. }*/ //测试时人数不够
  43. Console.WriteLine("Game starts!");
  44. game.StartGame((int)options.GameTimeInSecond * 1000);
  45. Thread.Sleep(1);
  46. new Thread(() =>
  47. {
  48. bool flag = true;
  49. new FrameRateTaskExecutor<int>
  50. (
  51. () => game.GameMap.Timer.IsGaming,
  52. () =>
  53. {
  54. if (flag == true)
  55. {
  56. ReportGame(GameState.GameStart);
  57. game.AllPlayerUsePassiveSkill();
  58. flag = false;
  59. }
  60. else ReportGame(GameState.GameRunning);
  61. },
  62. SendMessageToClientIntervalInMilliseconds,
  63. () =>
  64. {
  65. ReportGame(GameState.GameEnd); // 最后发一次消息,唤醒发消息的线程,防止发消息的线程由于有概率处在 Wait 状态而卡住
  66. OnGameEnd();
  67. return 0;
  68. }
  69. ).Start();
  70. })
  71. { IsBackground = true }.Start();
  72. }
  73. public void WaitForEnd()
  74. {
  75. this.endGameSem.Wait();
  76. mwr?.Dispose();
  77. }
  78. private void SaveGameResult(string path)
  79. {
  80. Dictionary<string, int> result = new Dictionary<string, int>();
  81. for (int i = 0; i < TeamCount; i++)
  82. {
  83. result.Add("Team" + i.ToString(), GetTeamScore(i)); //Team待修改
  84. }
  85. JsonSerializer serializer = new JsonSerializer();
  86. using (StreamWriter sw = new StreamWriter(path))
  87. {
  88. using (JsonWriter writer = new JsonTextWriter(sw))
  89. {
  90. serializer.Serialize(writer, result);
  91. }
  92. }
  93. }
  94. protected virtual void SendGameResult() // 天梯的 Server 给网站发消息记录比赛结果
  95. {
  96. var scores = new JObject[options.TeamCount];
  97. for (ushort i = 0; i < options.TeamCount; ++i)
  98. {
  99. scores[i] = new JObject { ["team_id"] = i.ToString(), ["score"] = GetTeamScore(i) };
  100. } // Team待修改
  101. httpSender?.SendHttpRequest
  102. (
  103. new JObject
  104. {
  105. ["result"] = new JArray(scores)
  106. }
  107. );
  108. }
  109. private void OnGameEnd()
  110. {
  111. game.ClearAllLists();
  112. mwr?.Flush();
  113. if (options.ResultFileName != DefaultArgumentOptions.FileName)
  114. SaveGameResult(options.ResultFileName + ".json");
  115. SendGameResult();
  116. this.endGameSem.Release();
  117. }
  118. public void ReportGame(GameState gameState, bool requiredGaming = true)
  119. {
  120. var gameObjList = game.GetGameObj();
  121. currentGameInfo = new();
  122. lock (messageToAllClientsLock)
  123. {
  124. switch (gameState)
  125. {
  126. case GameState.GameRunning:
  127. case GameState.GameEnd:
  128. case GameState.GameStart:
  129. currentGameInfo.ObjMessage.Add(currentMapMsg);
  130. foreach (GameObj gameObj in gameObjList)
  131. {
  132. MessageOfObj? msg = CopyInfo.Auto(gameObj);
  133. if (msg != null) currentGameInfo.ObjMessage.Add(CopyInfo.Auto(gameObj));
  134. }
  135. lock (newsLock)
  136. {
  137. foreach (var news in currentNews)
  138. {
  139. MessageOfObj? msg = CopyInfo.Auto(news);
  140. if (msg != null) currentGameInfo.ObjMessage.Add(CopyInfo.Auto(news));
  141. }
  142. currentNews.Clear();
  143. }
  144. currentGameInfo.GameState = gameState;
  145. currentGameInfo.AllMessage = GetMessageOfAll();
  146. mwr?.WriteOne(currentGameInfo);
  147. break;
  148. default:
  149. break;
  150. }
  151. }
  152. foreach (var kvp in semaDict)
  153. {
  154. kvp.Value.Item1.Release();
  155. }
  156. foreach (var kvp in semaDict)
  157. {
  158. kvp.Value.Item2.Wait();
  159. }
  160. }
  161. public int GetTeamScore(long teamID)
  162. {
  163. return game.GetTeamScore(teamID);
  164. }
  165. private int PlayerIDToTeamID(long playerID)
  166. {
  167. if (0 <= playerID && playerID < options.StudentCount) return 0;
  168. if (options.MaxStudentCount <= playerID && playerID < options.MaxStudentCount + options.TrickerCount) return 1;
  169. return -1;
  170. }
  171. private int PlayerTypeToTeamID(Protobuf.PlayerType playerType)
  172. {
  173. if (playerType == PlayerType.StudentPlayer) return 0;
  174. if (playerType == PlayerType.TrickerPlayer) return 1;
  175. return -1;
  176. }
  177. private uint GetBirthPointIdx(long playerID) // 获取出生点位置
  178. {
  179. return (uint)playerID + 1; // ID从0-4,出生点从1-5
  180. }
  181. private bool ValidPlayerID(long playerID)
  182. {
  183. if ((0 <= playerID && playerID < options.StudentCount) || (options.MaxStudentCount <= playerID && playerID < options.MaxStudentCount + options.TrickerCount))
  184. return true;
  185. return false;
  186. }
  187. private MessageOfAll GetMessageOfAll()
  188. {
  189. MessageOfAll msg = new MessageOfAll();
  190. //msg.GameTime
  191. msg.SubjectFinished = (int)game.GameMap.NumOfRepairedGenerators;
  192. //msg.StudentGraduated
  193. //msg.StudentQuited
  194. msg.StudentScore = 0;
  195. msg.TrickerScore = 0;
  196. game.GameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  197. try
  198. {
  199. foreach (Character character in game.GameMap.GameObjDict[GameObjType.Character])
  200. {
  201. if (!character.IsGhost()) msg.StudentScore += character.Score;
  202. else msg.TrickerScore += character.Score;
  203. }
  204. }
  205. finally
  206. {
  207. game.GameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  208. }
  209. //msg.GateOpened
  210. //msg.HiddenGateRefreshed
  211. //msg.HiddenGateOpened
  212. return msg;
  213. }
  214. private Protobuf.PlaceType IntToPlaceType(uint n)
  215. {
  216. switch (n)
  217. {
  218. case 0:
  219. case 1:
  220. case 2:
  221. case 3:
  222. case 4:
  223. case 5:
  224. return Protobuf.PlaceType.Land;
  225. case 6: return Protobuf.PlaceType.Wall;
  226. case 7: return Protobuf.PlaceType.Grass;
  227. case 8: return Protobuf.PlaceType.Classroom;
  228. case 9: return Protobuf.PlaceType.Gate;
  229. case 10: return Protobuf.PlaceType.HiddenGate;
  230. case 11: return Protobuf.PlaceType.Window;
  231. case 12: return Protobuf.PlaceType.Door3;
  232. case 13: return Protobuf.PlaceType.Door5;
  233. case 14: return Protobuf.PlaceType.Door6;
  234. case 15: return Protobuf.PlaceType.Chest;
  235. default: return Protobuf.PlaceType.NullPlaceType;
  236. }
  237. }
  238. private MessageOfObj MapMsg(uint[,] map)
  239. {
  240. MessageOfObj msgOfMap = new();
  241. msgOfMap.MapMessage = new();
  242. for (int i = 0; i < GameData.rows; i++)
  243. {
  244. msgOfMap.MapMessage.Row.Add(new MessageOfMap.Types.Row());
  245. for (int j = 0; j < GameData.cols; j++)
  246. {
  247. msgOfMap.MapMessage.Row[i].Col.Add(IntToPlaceType(map[i, j]));
  248. }
  249. }
  250. return msgOfMap;
  251. }
  252. public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context)
  253. {
  254. #if DEBUG
  255. Console.WriteLine($"TryConnection ID: {request.PlayerId}");
  256. #endif
  257. var onConnection = new BoolRes();
  258. lock (gameLock)
  259. {
  260. if (0 <= request.PlayerId && request.PlayerId < playerNum) // 注意修改
  261. {
  262. onConnection.ActSuccess = true;
  263. Console.WriteLine(onConnection.ActSuccess);
  264. return Task.FromResult(onConnection);
  265. }
  266. }
  267. onConnection.ActSuccess = false;
  268. return Task.FromResult(onConnection);
  269. }
  270. protected readonly object addPlayerLock = new();
  271. public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<MessageToClient> responseStream, ServerCallContext context)
  272. {
  273. Console.WriteLine($"AddPlayer: {request.PlayerId}");
  274. if (request.PlayerId >= spectatorMinPlayerID)
  275. {
  276. // 观战模式
  277. uint tp = (uint)request.PlayerId;
  278. if (!spectatorList.Contains(tp))
  279. {
  280. spectatorList.Add(tp);
  281. Console.WriteLine("A new spectator comes to watch this game.");
  282. }
  283. return;
  284. }
  285. if (game.GameMap.Timer.IsGaming)
  286. return;
  287. if (!ValidPlayerID(request.PlayerId)) //玩家id是否正确
  288. return;
  289. if (communicationToGameID[request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家
  290. return;
  291. Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null;
  292. if (request.PlayerType == PlayerType.StudentPlayer)
  293. characterType = CopyInfo.ToStudentType(request.StudentType);
  294. else if (request.PlayerType == PlayerType.TrickerPlayer)
  295. characterType = CopyInfo.ToTrickerType(request.TrickerType);
  296. lock (addPlayerLock)
  297. {
  298. Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerId), PlayerTypeToTeamID(request.PlayerType), request.PlayerId, characterType);
  299. long newPlayerID = game.AddPlayer(playerInitInfo);
  300. if (newPlayerID == GameObj.invalidID)
  301. return;
  302. communicationToGameID[request.PlayerId] = newPlayerID;
  303. // 内容待修改
  304. var temp = (new SemaphoreSlim(0, 1), new SemaphoreSlim(0, 1));
  305. bool start = false;
  306. Console.WriteLine($"Id: {request.PlayerId} joins.");
  307. lock (semaDict)
  308. {
  309. semaDict.Add(request.PlayerId, temp);
  310. start = semaDict.Count == playerNum;
  311. }
  312. if (start) StartGame();
  313. }
  314. do
  315. {
  316. semaDict[request.PlayerId].Item1.Wait();
  317. if (currentGameInfo != null)
  318. {
  319. await responseStream.WriteAsync(currentGameInfo);
  320. //Console.WriteLine("Send!");
  321. }
  322. semaDict[request.PlayerId].Item2.Release();
  323. } while (game.GameMap.Timer.IsGaming);
  324. }
  325. public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context)
  326. {
  327. #if DEBUG
  328. Console.WriteLine($"Attack ID: {request.PlayerId}");
  329. #endif
  330. var gameID = communicationToGameID[request.PlayerId];
  331. game.Attack(gameID, request.Angle);
  332. BoolRes boolRes = new();
  333. boolRes.ActSuccess = true;
  334. return Task.FromResult(boolRes);
  335. }
  336. public override Task<MoveRes> Move(MoveMsg request, ServerCallContext context)
  337. {
  338. #if DEBUG
  339. Console.WriteLine($"Move ID: {request.PlayerId}, TimeInMilliseconds: {request.TimeInMilliseconds}");
  340. #endif
  341. var gameID = communicationToGameID[request.PlayerId];
  342. MoveRes moveRes = new();
  343. game.MovePlayer(gameID, (int)request.TimeInMilliseconds, request.Angle);
  344. // 之后game.MovePlayer可能改为bool类
  345. moveRes.ActSuccess = true;
  346. if (!game.GameMap.Timer.IsGaming) moveRes.ActSuccess = false;
  347. return Task.FromResult(moveRes);
  348. }
  349. public override Task<BoolRes> SendMessage(SendMsg request, ServerCallContext context)
  350. {
  351. var boolRes = new BoolRes();
  352. if (!ValidPlayerID(request.PlayerId) || !ValidPlayerID(request.ToPlayerId)
  353. || PlayerIDToTeamID(request.PlayerId) != PlayerIDToTeamID(request.ToPlayerId) || request.PlayerId == request.ToPlayerId)
  354. {
  355. boolRes.ActSuccess = false;
  356. return Task.FromResult(boolRes);
  357. }
  358. if (request.Message.Length > 256)
  359. {
  360. #if DEBUG
  361. Console.WriteLine("Message string is too long!");
  362. #endif
  363. boolRes.ActSuccess = false;
  364. return Task.FromResult(boolRes);
  365. }
  366. else
  367. {
  368. MessageOfNews news = new();
  369. news.News = request.Message;
  370. news.FromId = request.PlayerId;
  371. news.ToId = request.ToPlayerId;
  372. lock (newsLock)
  373. {
  374. currentNews.Add(news);
  375. }
  376. #if DEBUG
  377. Console.WriteLine(news.News);
  378. #endif
  379. }
  380. boolRes.ActSuccess = true;
  381. return Task.FromResult(boolRes);
  382. }
  383. public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context)
  384. {
  385. #if DEBUG
  386. Console.WriteLine($"PickProp ID: {request.PlayerId}");
  387. #endif
  388. BoolRes boolRes = new();
  389. var gameID = communicationToGameID[request.PlayerId];
  390. boolRes.ActSuccess = game.PickProp(gameID, CopyInfo.ToPropType(request.PropType));
  391. return Task.FromResult(boolRes);
  392. }
  393. public override Task<BoolRes> UseProp(PropMsg request, ServerCallContext context)
  394. {
  395. #if DEBUG
  396. Console.WriteLine($"UseProp ID: {request.PlayerId}");
  397. #endif
  398. BoolRes boolRes = new();
  399. var gameID = communicationToGameID[request.PlayerId];
  400. game.UseProp(gameID, CopyInfo.ToPropType(request.PropType));
  401. boolRes.ActSuccess = true;
  402. return Task.FromResult(boolRes);
  403. }
  404. public override Task<BoolRes> ThrowProp(PropMsg request, ServerCallContext context)
  405. {
  406. #if DEBUG
  407. Console.WriteLine($"ThrowProp ID: {request.PlayerId}");
  408. #endif
  409. BoolRes boolRes = new();
  410. var gameID = communicationToGameID[request.PlayerId];
  411. game.ThrowProp(gameID, CopyInfo.ToPropType(request.PropType));
  412. boolRes.ActSuccess = true;
  413. return Task.FromResult(boolRes);
  414. }
  415. public override Task<BoolRes> UseSkill(SkillMsg request, ServerCallContext context)
  416. {
  417. #if DEBUG
  418. Console.WriteLine($"UseSkill ID: {request.PlayerId}");
  419. #endif
  420. BoolRes boolRes = new();
  421. var gameID = communicationToGameID[request.PlayerId];
  422. boolRes.ActSuccess = game.UseActiveSkill(gameID, request.SkillId);
  423. return Task.FromResult(boolRes);
  424. }
  425. public override Task<BoolRes> Graduate(IDMsg request, ServerCallContext context)
  426. {
  427. #if DEBUG
  428. Console.WriteLine($"Graduate ID: {request.PlayerId}");
  429. #endif
  430. BoolRes boolRes = new();
  431. var gameID = communicationToGameID[request.PlayerId];
  432. boolRes.ActSuccess = game.Escape(gameID);
  433. return Task.FromResult(boolRes);
  434. }
  435. public override Task<BoolRes> StartRescueMate(TreatAndRescueMsg request, ServerCallContext context)
  436. {
  437. #if DEBUG
  438. Console.WriteLine($"StartRescueMate ID: {request.PlayerId}");
  439. #endif
  440. BoolRes boolRes = new();
  441. var gameID = communicationToGameID[request.PlayerId];
  442. var toGameID = communicationToGameID[request.ToPlayerId];
  443. boolRes.ActSuccess = game.Rescue(gameID, toGameID);
  444. return Task.FromResult(boolRes);
  445. }
  446. public override Task<BoolRes> StartTreatMate(TreatAndRescueMsg request, ServerCallContext context)
  447. {
  448. #if DEBUG
  449. Console.WriteLine($"StartTreatMate ID: {request.PlayerId}");
  450. #endif
  451. BoolRes boolRes = new();
  452. var gameID = communicationToGameID[request.PlayerId];
  453. var toGameID = communicationToGameID[request.ToPlayerId];
  454. boolRes.ActSuccess = game.Treat(gameID, toGameID);
  455. return Task.FromResult(boolRes);
  456. }
  457. public override Task<BoolRes> StartLearning(IDMsg request, ServerCallContext context)
  458. {
  459. #if DEBUG
  460. Console.WriteLine($"StartLearning ID: {request.PlayerId}");
  461. #endif
  462. BoolRes boolRes = new();
  463. var gameID = communicationToGameID[request.PlayerId];
  464. boolRes.ActSuccess = game.Fix(gameID);
  465. return Task.FromResult(boolRes);
  466. }
  467. public override Task<BoolRes> StartOpenChest(IDMsg request, ServerCallContext context)
  468. {
  469. #if DEBUG
  470. Console.WriteLine($"StartOpenChest ID: {request.PlayerId}");
  471. #endif
  472. BoolRes boolRes = new();
  473. var gameID = communicationToGameID[request.PlayerId];
  474. boolRes.ActSuccess = game.OpenChest(gameID);
  475. return Task.FromResult(boolRes);
  476. }
  477. public override Task<BoolRes> StartOpenGate(IDMsg request, ServerCallContext context)
  478. {
  479. #if DEBUG
  480. Console.WriteLine($"StartOpenGate ID: {request.PlayerId}");
  481. #endif
  482. BoolRes boolRes = new();
  483. var gameID = communicationToGameID[request.PlayerId];
  484. boolRes.ActSuccess = game.OpenDoorway(gameID);
  485. return Task.FromResult(boolRes);
  486. }
  487. public override Task<BoolRes> OpenDoor(IDMsg request, ServerCallContext context)
  488. {
  489. #if DEBUG
  490. Console.WriteLine($"OpenDoor ID: {request.PlayerId}");
  491. #endif
  492. BoolRes boolRes = new();
  493. var gameID = communicationToGameID[request.PlayerId];
  494. boolRes.ActSuccess = game.LockOrOpenDoor(gameID);
  495. return Task.FromResult(boolRes);
  496. }
  497. public override Task<BoolRes> CloseDoor(IDMsg request, ServerCallContext context)
  498. {
  499. #if DEBUG
  500. Console.WriteLine($"CloseDoor ID: {request.PlayerId}");
  501. #endif
  502. BoolRes boolRes = new();
  503. var gameID = communicationToGameID[request.PlayerId];
  504. boolRes.ActSuccess = game.LockOrOpenDoor(gameID);
  505. return Task.FromResult(boolRes);
  506. }
  507. public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext context)
  508. {
  509. #if DEBUG
  510. Console.WriteLine($"EndAllAction ID: {request.PlayerId}");
  511. #endif
  512. BoolRes boolRes = new();
  513. var gameID = communicationToGameID[request.PlayerId];
  514. boolRes.ActSuccess = game.Stop(gameID);
  515. return Task.FromResult(boolRes);
  516. }
  517. public override Task<BoolRes> SkipWindow(IDMsg request, ServerCallContext context)
  518. {
  519. #if DEBUG
  520. Console.WriteLine($"SkipWindow ID: {request.PlayerId}");
  521. #endif
  522. BoolRes boolRes = new();
  523. var gameID = communicationToGameID[request.PlayerId];
  524. boolRes.ActSuccess = game.ClimbingThroughWindow(gameID);
  525. return Task.FromResult(boolRes);
  526. }
  527. public GameServer(ArgumentOptions options)
  528. {
  529. this.options = options;
  530. if (options.mapResource == DefaultArgumentOptions.MapResource)
  531. this.game = new Game(MapInfo.defaultMap, options.TeamCount);
  532. else
  533. {
  534. uint[,] map = new uint[GameData.rows, GameData.cols];
  535. try
  536. {
  537. string? line;
  538. int i = 0, j = 0;
  539. using (StreamReader sr = new StreamReader(options.mapResource))
  540. {
  541. while (!sr.EndOfStream && i < GameData.rows)
  542. {
  543. if ((line = sr.ReadLine()) != null)
  544. {
  545. string[] nums = line.Split(' ');
  546. foreach (string item in nums)
  547. {
  548. if (item.Length > 1)//以兼容原方案
  549. {
  550. map[i, j] = (uint)int.Parse(item);
  551. }
  552. else
  553. {
  554. //2022-04-22 by LHR 十六进制编码地图方案(防止地图编辑员瞎眼x
  555. map[i, j] = (uint)Preparation.Utility.MapEncoder.Hex2Dec(char.Parse(item));
  556. }
  557. j++;
  558. if (j >= GameData.cols)
  559. {
  560. j = 0;
  561. break;
  562. }
  563. }
  564. i++;
  565. }
  566. }
  567. }
  568. }
  569. catch
  570. {
  571. map = MapInfo.defaultMap;
  572. }
  573. finally { this.game = new Game(map, options.TeamCount); }
  574. }
  575. playerNum = options.StudentCount + options.TrickerCount;
  576. currentMapMsg = MapMsg(game.GameMap.ProtoGameMap);
  577. communicationToGameID = new long[options.MaxStudentCount + options.TrickerCount];
  578. //创建server时先设定待加入人物都是invalid
  579. for (int i = 0; i < communicationToGameID.GetLength(0); i++)
  580. {
  581. communicationToGameID[i] = GameObj.invalidID;
  582. }
  583. if (options.FileName != DefaultArgumentOptions.FileName)
  584. {
  585. try
  586. {
  587. mwr = new MessageWriter(options.FileName, options.TeamCount, options.StudentCount);
  588. }
  589. catch
  590. {
  591. Console.WriteLine($"Error: Cannot create the playback file: {options.FileName}!");
  592. }
  593. }
  594. if (options.Url != DefaultArgumentOptions.Url && options.Token != DefaultArgumentOptions.Token)
  595. {
  596. this.httpSender = new HttpSender(options.Url, options.Token, "PUT");
  597. }
  598. }
  599. }
  600. }