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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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 = GetMessageOfAll();
  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 = GetMessageOfAll(); // 还没写
  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 int PlayerTypeToTeamID(Protobuf.PlayerType playerType)
  184. {
  185. if (playerType == PlayerType.StudentPlayer) return 0;
  186. if (playerType == PlayerType.TrickerPlayer) return 1;
  187. return -1;
  188. }
  189. private uint GetBirthPointIdx(long playerID) // 获取出生点位置
  190. {
  191. return (uint)playerID + 1; // ID从0-4,出生点从1-5
  192. }
  193. private bool ValidPlayerID(long playerID)
  194. {
  195. if (0 <= playerID && playerID < options.PlayerCountPerTeam + 1)
  196. return true;
  197. return false;
  198. }
  199. private MessageOfAll GetMessageOfAll()
  200. {
  201. MessageOfAll msg = new MessageOfAll();
  202. //msg.GameTime
  203. msg.SubjectLeft = GameData.numOfGeneratorRequiredForRepair - (int)game.GameMap.NumOfRepairedGenerators;
  204. //msg.StudentGraduated
  205. //msg.StudentQuited
  206. msg.StudentScore = 0;
  207. msg.TrickerScore = 0;
  208. game.GameMap.GameObjLockDict[GameObjType.Character].EnterReadLock();
  209. try
  210. {
  211. foreach (Character character in game.GameMap.GameObjDict[GameObjType.Character])
  212. {
  213. if (!character.IsGhost()) msg.StudentScore += character.Score;
  214. else msg.TrickerScore += character.Score;
  215. }
  216. }
  217. finally
  218. {
  219. game.GameMap.GameObjLockDict[GameObjType.Character].ExitReadLock();
  220. }
  221. //msg.GateOpened =
  222. //msg.HiddenGateRefreshed =
  223. //msg.HiddenGateOpened
  224. return msg;
  225. }
  226. private Protobuf.PlaceType IntToPlaceType(uint n)
  227. {
  228. switch (n)
  229. {
  230. case 0: return Protobuf.PlaceType.Land;
  231. case 6: return Protobuf.PlaceType.Wall;
  232. case 7: return Protobuf.PlaceType.Grass;
  233. case 8: return Protobuf.PlaceType.Classroom;
  234. case 9: return Protobuf.PlaceType.Gate;
  235. case 10: return Protobuf.PlaceType.HiddenGate;
  236. case 11: return Protobuf.PlaceType.Window;
  237. case 12: return Protobuf.PlaceType.Door3;
  238. case 13: return Protobuf.PlaceType.Door5;
  239. case 14: return Protobuf.PlaceType.Door6;
  240. case 15: return Protobuf.PlaceType.Chest;
  241. default: return Protobuf.PlaceType.NullPlaceType;
  242. }
  243. }
  244. private MessageOfObj MapMsg(uint[,] map)
  245. {
  246. MessageOfObj msgOfMap = new();
  247. msgOfMap.MapMessage = new();
  248. for (int i = 0; i < GameData.rows; i++)
  249. {
  250. msgOfMap.MapMessage.Row.Add(new MessageOfMap.Types.Row());
  251. for (int j = 0; j < GameData.cols; j++)
  252. {
  253. msgOfMap.MapMessage.Row[i].Col.Add(IntToPlaceType(map[i, j]));
  254. }
  255. }
  256. return msgOfMap;
  257. }
  258. public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context)
  259. {
  260. #if DEBUG
  261. Console.WriteLine($"TryConnection ID: {request.PlayerId}");
  262. #endif
  263. var onConnection = new BoolRes();
  264. lock (gameLock)
  265. {
  266. if (0 <= request.PlayerId && request.PlayerId < playerNum) // 注意修改
  267. {
  268. onConnection.ActSuccess = true;
  269. Console.WriteLine(onConnection.ActSuccess);
  270. return Task.FromResult(onConnection);
  271. }
  272. }
  273. onConnection.ActSuccess = false;
  274. return Task.FromResult(onConnection);
  275. }
  276. protected readonly object addPlayerLock = new();
  277. public override async Task AddPlayer(PlayerMsg request, IServerStreamWriter<MessageToClient> responseStream, ServerCallContext context)
  278. {
  279. Console.WriteLine($"AddPlayer: {request.PlayerId}");
  280. if (request.PlayerId >= spectatorMinPlayerID)
  281. {
  282. // 观战模式
  283. uint tp = (uint)request.PlayerId;
  284. if (!spectatorList.Contains(tp))
  285. {
  286. spectatorList.Add(tp);
  287. Console.WriteLine("A new spectator comes to watch this game.");
  288. }
  289. return;
  290. }
  291. if (game.GameMap.Timer.IsGaming)
  292. return;
  293. if (!ValidPlayerID(request.PlayerId)) //玩家id是否正确
  294. return;
  295. if (communicationToGameID[request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家
  296. return;
  297. Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null;
  298. if (request.PlayerType == PlayerType.StudentPlayer)
  299. characterType = CopyInfo.ToStudentType(request.StudentType);
  300. else if (request.PlayerType == PlayerType.TrickerPlayer)
  301. characterType = CopyInfo.ToTrickerType(request.TrickerType);
  302. lock (addPlayerLock)
  303. {
  304. Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerId), PlayerTypeToTeamID(request.PlayerType), request.PlayerId, characterType);
  305. long newPlayerID = game.AddPlayer(playerInitInfo);
  306. if (newPlayerID == GameObj.invalidID)
  307. return;
  308. communicationToGameID[request.PlayerId] = newPlayerID;
  309. // 内容待修改
  310. var temp = (new SemaphoreSlim(0, 1), new SemaphoreSlim(0, 1));
  311. bool start = false;
  312. Console.WriteLine($"Id: {request.PlayerId} joins.");
  313. lock (semaDict)
  314. {
  315. semaDict.Add(request.PlayerId, temp);
  316. start = semaDict.Count == playerNum;
  317. }
  318. if (start) StartGame();
  319. }
  320. do
  321. {
  322. semaDict[request.PlayerId].Item1.Wait();
  323. if (currentGameInfo != null)
  324. {
  325. await responseStream.WriteAsync(currentGameInfo);
  326. //Console.WriteLine("Send!");
  327. }
  328. semaDict[request.PlayerId].Item2.Release();
  329. } while (game.GameMap.Timer.IsGaming);
  330. }
  331. public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context)
  332. {
  333. #if DEBUG
  334. Console.WriteLine($"Attack ID: {request.PlayerId}");
  335. #endif
  336. var gameID = communicationToGameID[request.PlayerId];
  337. game.Attack(gameID, request.Angle);
  338. BoolRes boolRes = new();
  339. boolRes.ActSuccess = true;
  340. return Task.FromResult(boolRes);
  341. }
  342. public override Task<MoveRes> Move(MoveMsg request, ServerCallContext context)
  343. {
  344. #if DEBUG
  345. Console.WriteLine($"Move ID: {request.PlayerId}, TimeInMilliseconds: {request.TimeInMilliseconds}");
  346. #endif
  347. var gameID = communicationToGameID[request.PlayerId];
  348. MoveRes moveRes = new();
  349. game.MovePlayer(gameID, (int)request.TimeInMilliseconds, request.Angle);
  350. // 之后game.MovePlayer可能改为bool类
  351. moveRes.ActSuccess = true;
  352. if (!game.GameMap.Timer.IsGaming) moveRes.ActSuccess = false;
  353. return Task.FromResult(moveRes);
  354. }
  355. public override Task<BoolRes> SendMessage(SendMsg request, ServerCallContext context)
  356. {
  357. var boolRes = new BoolRes();
  358. if (!ValidPlayerID(request.PlayerId) || !ValidPlayerID(request.ToPlayerId)
  359. || PlayerIDToTeamID(request.PlayerId) != PlayerIDToTeamID(request.ToPlayerId) || request.PlayerId == request.ToPlayerId)
  360. {
  361. boolRes.ActSuccess = false;
  362. return Task.FromResult(boolRes);
  363. }
  364. if (request.Message.Length > 256)
  365. {
  366. #if DEBUG
  367. Console.WriteLine("Message string is too long!");
  368. #endif
  369. boolRes.ActSuccess = false;
  370. return Task.FromResult(boolRes);
  371. }
  372. else
  373. {
  374. MessageOfNews news = new();
  375. news.News = request.Message;
  376. news.FromId = request.PlayerId;
  377. news.ToId = request.ToPlayerId;
  378. lock (newsLock)
  379. {
  380. currentNews.Add(news);
  381. }
  382. #if DEBUG
  383. Console.WriteLine(news.News);
  384. #endif
  385. }
  386. boolRes.ActSuccess = true;
  387. return Task.FromResult(boolRes);
  388. }
  389. public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context)
  390. {
  391. #if DEBUG
  392. Console.WriteLine($"PickProp ID: {request.PlayerId}");
  393. #endif
  394. BoolRes boolRes = new();
  395. var gameID = communicationToGameID[request.PlayerId];
  396. boolRes.ActSuccess = game.PickProp(gameID, CopyInfo.ToPropType(request.PropType));
  397. return Task.FromResult(boolRes);
  398. }
  399. public override Task<BoolRes> UseProp(PropMsg request, ServerCallContext context)
  400. {
  401. #if DEBUG
  402. Console.WriteLine($"UseProp ID: {request.PlayerId}");
  403. #endif
  404. BoolRes boolRes = new();
  405. var gameID = communicationToGameID[request.PlayerId];
  406. //boolRes.ActSuccess = game.UseProp(gameID, CopyInfo.ToPropType(request.PropType));
  407. return Task.FromResult(boolRes);
  408. }
  409. public override Task<BoolRes> ThrowProp(PropMsg request, ServerCallContext context)
  410. {
  411. #if DEBUG
  412. Console.WriteLine($"ThrowProp ID: {request.PlayerId}");
  413. #endif
  414. BoolRes boolRes = new();
  415. var gameID = communicationToGameID[request.PlayerId];
  416. //boolRes.ActSuccess = game.ThrowProp(gameID, CopyInfo.ToPropType(request.PropType));
  417. return Task.FromResult(boolRes);
  418. }
  419. public override Task<BoolRes> UseSkill(SkillMsg request, ServerCallContext context)
  420. {
  421. #if DEBUG
  422. Console.WriteLine($"UseSkill ID: {request.PlayerId}");
  423. #endif
  424. BoolRes boolRes = new();
  425. var gameID = communicationToGameID[request.PlayerId];
  426. //boolRes.ActSuccess = game.UseActiveSkill(gameID, CopyInfo.ToPropType(request.PropType));
  427. return Task.FromResult(boolRes);
  428. }
  429. public override Task<BoolRes> Graduate(IDMsg request, ServerCallContext context)
  430. {
  431. #if DEBUG
  432. Console.WriteLine($"Graduate ID: {request.PlayerId}");
  433. #endif
  434. BoolRes boolRes = new();
  435. var gameID = communicationToGameID[request.PlayerId];
  436. boolRes.ActSuccess = game.Escape(gameID);
  437. return Task.FromResult(boolRes);
  438. }
  439. public override Task<BoolRes> StartRescueMate(IDMsg request, ServerCallContext context)
  440. {
  441. #if DEBUG
  442. Console.WriteLine($"StartRescueMate ID: {request.PlayerId}");
  443. #endif
  444. BoolRes boolRes = new();
  445. var gameID = communicationToGameID[request.PlayerId];
  446. //boolRes.ActSuccess = game.Rescue(gameID);
  447. return Task.FromResult(boolRes);
  448. }
  449. public override Task<BoolRes> StartTreatMate(IDMsg request, ServerCallContext context)
  450. {
  451. #if DEBUG
  452. Console.WriteLine($"StartTreatMate ID: {request.PlayerId}");
  453. #endif
  454. BoolRes boolRes = new();
  455. var gameID = communicationToGameID[request.PlayerId];
  456. //boolRes.ActSuccess = game.Treat(gameID);
  457. return Task.FromResult(boolRes);
  458. }
  459. public override Task<BoolRes> StartLearning(IDMsg request, ServerCallContext context)
  460. {
  461. #if DEBUG
  462. Console.WriteLine($"StartLearning ID: {request.PlayerId}");
  463. #endif
  464. BoolRes boolRes = new();
  465. var gameID = communicationToGameID[request.PlayerId];
  466. boolRes.ActSuccess = game.Fix(gameID);
  467. return Task.FromResult(boolRes);
  468. }
  469. public override Task<BoolRes> StartOpenChest(IDMsg request, ServerCallContext context)
  470. {
  471. #if DEBUG
  472. Console.WriteLine($"StartOpenChest ID: {request.PlayerId}");
  473. #endif
  474. BoolRes boolRes = new();
  475. var gameID = communicationToGameID[request.PlayerId];
  476. boolRes.ActSuccess = game.OpenChest(gameID);
  477. return Task.FromResult(boolRes);
  478. }
  479. public override Task<BoolRes> StartOpenGate(IDMsg request, ServerCallContext context)
  480. {
  481. #if DEBUG
  482. Console.WriteLine($"StartOpenGate ID: {request.PlayerId}");
  483. #endif
  484. BoolRes boolRes = new();
  485. var gameID = communicationToGameID[request.PlayerId];
  486. boolRes.ActSuccess = game.OpenDoorway(gameID);
  487. return Task.FromResult(boolRes);
  488. }
  489. public override Task<BoolRes> OpenDoor(IDMsg request, ServerCallContext context)
  490. {
  491. #if DEBUG
  492. Console.WriteLine($"OpenDoor ID: {request.PlayerId}");
  493. #endif
  494. BoolRes boolRes = new();
  495. var gameID = communicationToGameID[request.PlayerId];
  496. boolRes.ActSuccess = game.LockOrOpenDoor(gameID);
  497. return Task.FromResult(boolRes);
  498. }
  499. public override Task<BoolRes> CloseDoor(IDMsg request, ServerCallContext context)
  500. {
  501. #if DEBUG
  502. Console.WriteLine($"CloseDoor ID: {request.PlayerId}");
  503. #endif
  504. BoolRes boolRes = new();
  505. var gameID = communicationToGameID[request.PlayerId];
  506. boolRes.ActSuccess = game.LockOrOpenDoor(gameID);
  507. return Task.FromResult(boolRes);
  508. }
  509. public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext context)
  510. {
  511. #if DEBUG
  512. Console.WriteLine($"EndAllAction ID: {request.PlayerId}");
  513. #endif
  514. BoolRes boolRes = new();
  515. var gameID = communicationToGameID[request.PlayerId];
  516. boolRes.ActSuccess = game.Stop(gameID);
  517. return Task.FromResult(boolRes);
  518. }
  519. public override Task<BoolRes> SkipWindow(IDMsg request, ServerCallContext context)
  520. {
  521. #if DEBUG
  522. Console.WriteLine($"SkipWindow ID: {request.PlayerId}");
  523. #endif
  524. BoolRes boolRes = new();
  525. var gameID = communicationToGameID[request.PlayerId];
  526. boolRes.ActSuccess = game.ClimbingThroughWindow(gameID);
  527. return Task.FromResult(boolRes);
  528. }
  529. public GameServer(ArgumentOptions options)
  530. {
  531. this.options = options;
  532. //if (options.mapResource == DefaultArgumentOptions.MapResource)
  533. // this.game = new Game(MapInfo.defaultMap, options.TeamCount);
  534. //else
  535. {
  536. uint[,] map = new uint[GameData.rows, GameData.cols];
  537. try
  538. {
  539. string? line;
  540. int i = 0, j = 0;
  541. using (StreamReader sr = new StreamReader(options.mapResource))
  542. {
  543. while (!sr.EndOfStream && i < GameData.rows)
  544. {
  545. if ((line = sr.ReadLine()) != null)
  546. {
  547. string[] nums = line.Split(' ');
  548. foreach (string item in nums)
  549. {
  550. if (item.Length > 1)//以兼容原方案
  551. {
  552. map[i, j] = (uint)int.Parse(item);
  553. }
  554. else
  555. {
  556. //2022-04-22 by LHR 十六进制编码地图方案(防止地图编辑员瞎眼x
  557. map[i, j] = (uint)Preparation.Utility.MapEncoder.Hex2Dec(char.Parse(item));
  558. }
  559. j++;
  560. if (j >= GameData.cols)
  561. {
  562. j = 0;
  563. break;
  564. }
  565. }
  566. i++;
  567. }
  568. }
  569. }
  570. }
  571. catch
  572. {
  573. map = MapInfo.defaultMap;
  574. }
  575. finally { this.game = new Game(map, options.TeamCount); }
  576. }
  577. currentMapMsg = MapMsg(game.GameMap.ProtoGameMap);
  578. communicationToGameID = new long[options.PlayerCountPerTeam + 1];
  579. //创建server时先设定待加入人物都是invalid
  580. for (int i = 0; i < communicationToGameID.GetLength(0); i++)
  581. {
  582. communicationToGameID[i] = GameObj.invalidID;
  583. }
  584. if (options.FileName != DefaultArgumentOptions.FileName)
  585. {
  586. try
  587. {
  588. mwr = new MessageWriter(options.FileName, options.TeamCount, options.PlayerCountPerTeam);
  589. }
  590. catch
  591. {
  592. Console.WriteLine($"Error: Cannot create the playback file: {options.FileName}!");
  593. }
  594. }
  595. if (options.Url != DefaultArgumentOptions.Url && options.Token != DefaultArgumentOptions.Token)
  596. {
  597. //this.httpSender = new HttpSender(options.Url, options.Token, "PUT");
  598. }
  599. }
  600. }
  601. }