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