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