AreaManager.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. using DeepCore;
  2. using DeepCore.GameData.Zone.ZoneEditor;
  3. using DeepCore.GameEvent;
  4. using DeepCore.IO;
  5. using DeepCore.Log;
  6. using DeepCrystal.RPC;
  7. using DeepMMO.Data;
  8. using DeepMMO.Protocol;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Threading.Tasks;
  14. using DeepCore.GameEvent.Message;
  15. using DeepCore.Net;
  16. using DeepMMO.Protocol.Client;
  17. using DeepMMO.Server.GameEvent;
  18. namespace DeepMMO.Server.AreaManager
  19. {
  20. public class AreaManager : IService
  21. {
  22. protected readonly Logger log;
  23. protected readonly Random random = new Random();
  24. private readonly int LINE_MAX = 50;//场景分线硬上限
  25. private IDisposable mTimer;
  26. public EventManager EventMgr { get; private set; }
  27. public string ServerGID { get; set; }
  28. public AreaManager(ServiceStartInfo start) : base(start)
  29. {
  30. ServerGID = start.Config["groupID"];
  31. this.log = LoggerFactory.GetLogger(GetType().Name);
  32. this.areas = new ValueSortedMap<string, ValueSortedMap<string, AreaInfo>>(AreaGroupComparison);
  33. Console.WriteLine("AreaManager 初始化 GroupID: " + start.Config["groupID"]);
  34. }
  35. protected override void OnDisposed()
  36. {
  37. Console.WriteLine("AreaManager OnDisposed GroupID: " + ServerGID);
  38. }
  39. protected override Task OnStartAsync()
  40. {
  41. EventMgr = EventManagerFactory.Instance.CreateEventManager(nameof(AreaManager), SelfAddress.ServiceName);
  42. if (EventMgr != null)
  43. {
  44. EventMgr.PutObject("Service", this);
  45. EventMgr.Start();
  46. mTimer = Provider.CreateTimer(OnEventTick, this,
  47. TimeSpan.FromSeconds(0),
  48. TimeSpan.FromSeconds(TimerConfig.timer_sec_EventUpdateTime));
  49. }
  50. return Task.FromResult(0);
  51. }
  52. //protected override async Task OnStartAsync()
  53. //{
  54. // EventMgr = EventManagerFactory.Instance.CreateEventManager(nameof(AreaManager), SelfAddress.ServiceName);
  55. // if (EventMgr != null)
  56. // {
  57. // EventMgr.PutObject("Service", this);
  58. // EventMgr.Start();
  59. // mTimer = Provider.CreateTimer(OnEventTick, this,
  60. // TimeSpan.FromSeconds(0),
  61. // TimeSpan.FromSeconds(TimerConfig.timer_sec_EventUpdateTime));
  62. // }
  63. // //请求动态创建场景
  64. // if (areas.Count == 0)
  65. // {
  66. // var getRemote = await ServerNames.GetOrCreateAreaServiceAsync(this, ServerGID);
  67. // if (getRemote != null)
  68. // {
  69. // var node = areas.GetOrAdd(getRemote.Address.ServiceNode, (n) => new ValueSortedMap<string, AreaInfo>(AreaComparison));
  70. // node.TryAddOrUpdate(getRemote.Address.ServiceName, new AreaInfo(getRemote));
  71. // }
  72. // }
  73. //}
  74. protected override Task OnStopAsync(ServiceStopInfo reason)
  75. {
  76. EventMgr?.Dispose();
  77. mTimer?.Dispose();
  78. return Task.FromResult(0);
  79. }
  80. private void OnEventTick(object state)
  81. {
  82. EventMgr?.Update();
  83. }
  84. public virtual void AreaSyncState(AreaStateNotify st)
  85. {
  86. if (areas.TryGetValue(st.areaNode, out var group))
  87. {
  88. areas.MarkSort();
  89. if (group.TryGetValue(st.areaName, out var area))
  90. {
  91. group.MarkSort();
  92. area.state = st;
  93. }
  94. }
  95. this.LogState();
  96. }
  97. public override bool GetState(TextWriter sb)
  98. {
  99. sb.WriteLine(CUtils.SequenceChar('-', 100));
  100. foreach (var group in areas.ToSortedArray())
  101. {
  102. foreach (var area in group.ToSortedArray())
  103. {
  104. area.WriteState(sb);
  105. }
  106. }
  107. sb.WriteLine(CUtils.SequenceChar('-', 100));
  108. return true;
  109. }
  110. //------------------------------------------------------------------------------------------------------------------------------------
  111. #region RPC
  112. [RpcHandler(typeof(BatchCreateZoneLineRequest), typeof(BatchCreateZoneLineResponse))]
  113. public virtual Task<BatchCreateZoneLineResponse> logic_rpc_Handle(BatchCreateZoneLineRequest create)
  114. {
  115. //log.Info(create);
  116. return BatchCreateZoneLine(create);
  117. }
  118. [RpcHandler(typeof(CreateZoneNodeRequest), typeof(CreateZoneNodeResponse))]
  119. public virtual Task<CreateZoneNodeResponse> logic_rpc_Handle(CreateZoneNodeRequest create)
  120. {
  121. //log.Info(create);
  122. return CreateZone(create);
  123. }
  124. [RpcHandler(typeof(DestoryZoneNodeRequest), typeof(DestoryZoneNodeResponse))]
  125. public virtual Task<DestoryZoneNodeResponse> logic_rpc_Handle(DestoryZoneNodeRequest stop)
  126. {
  127. //log.Info(stop);
  128. return DestoryZone(stop);
  129. }
  130. [RpcHandler(typeof(RoleEnterZoneRequest), typeof(RoleEnterZoneResponse))]
  131. public virtual Task<RoleEnterZoneResponse> logic_rpc_Handle(RoleEnterZoneRequest req)
  132. {
  133. //log.Info(req);
  134. return RoleEnter(req);
  135. }
  136. [RpcHandler(typeof(RoleLeaveZoneRequest), typeof(RoleLeaveZoneResponse))]
  137. public virtual Task<RoleLeaveZoneResponse> logic_rpc_Handle(RoleLeaveZoneRequest req)
  138. {
  139. //log.Info(req);
  140. return RoleLeave(req);
  141. }
  142. [RpcHandler(typeof(ServerGameEventNotify))]
  143. public virtual void rpc_event_notify(ServerGameEventNotify ntf)
  144. {
  145. EventMgr?.OnReceiveMessage(EventMessage.FromBytes(ntf.EventMessageData));
  146. }
  147. //------------------------------------------------------------------------------------------------------------------------------------
  148. /// <summary>
  149. /// 添加一个Area负载
  150. /// </summary>
  151. /// <returns></returns>
  152. [RpcHandler(typeof(RegistAreaRequest), typeof(RegistAreaResponse), ServerNames.AreaServiceType)]
  153. public virtual Task<RegistAreaResponse> area_rpc_RegistAreaAsync(RegistAreaRequest reg)
  154. {
  155. return AreaRegist(reg);
  156. }
  157. [RpcHandler(typeof(AreaStateNotify), ServerNames.AreaServiceType)]
  158. public virtual void area_rpc_AreaStateNotify(AreaStateNotify notify)
  159. {
  160. AreaSyncState(notify);
  161. }
  162. [RpcHandler(typeof(AreaZoneGameOverNotify), ServerNames.AreaServiceType)]
  163. public virtual void area_rpc_AreaGameOverHandle(AreaZoneGameOverNotify stop)
  164. {
  165. //log.Info("AreaMgr receive " + stop + " " + stop.zoneUUID);
  166. zones.SetZoneCloseFlag(stop.zoneUUID);
  167. }
  168. [RpcHandler(typeof(AreaZoneDestoryNotify), ServerNames.AreaServiceType)]
  169. public virtual void area_rpc_AreaGameOverHandle(AreaZoneDestoryNotify stop)
  170. {
  171. //TODO flag destory
  172. //log.Info("AreaMgr recive " + stop + " " + stop.zoneUUID);
  173. DestoryZone(stop);
  174. }
  175. //--------------------------------------------------
  176. [RpcHandler(typeof(RoleNameChangedNotify))]
  177. public virtual void logic_rpc_Handle(RoleNameChangedNotify ntf)
  178. {
  179. var role = GetRole(ntf.roleId);
  180. if (role != null)
  181. {
  182. role.enter.roleDisplayName = ntf.newName;
  183. }
  184. }
  185. //------------------------------------------------------------------------------------------------------------------------------------
  186. [RpcHandler(typeof(GetAllRoleRequest), typeof(GetAllRoleResponse))]
  187. public virtual void logic_rpc_Handle(GetAllRoleRequest req, OnRpcReturn<GetAllRoleResponse> cb)
  188. {
  189. RoleInfo[] roleList = GetAllRoles();
  190. HashMap<string, OnlinePlayerData> uuidMap = new HashMap<string, OnlinePlayerData>();
  191. for (int i = 0; i < roleList.Length; ++i)
  192. {
  193. var rold = roleList[i];
  194. uuidMap.Add(rold.uuid, new OnlinePlayerData()
  195. {
  196. name = rold.enter.roleDisplayName,
  197. serverGroupId = rold.enter.servergroupID
  198. });
  199. }
  200. cb(new GetAllRoleResponse() { uuidMap = uuidMap });
  201. }
  202. [RpcHandler(typeof(QueryZoneAreaNameRequest), typeof(QueryZoneAreaNameResponse))]
  203. public Task<QueryZoneAreaNameResponse> logic_rpc_Handle(QueryZoneAreaNameRequest req)
  204. {
  205. var zone = GetZone(req.zoneUUID);
  206. return Task.FromResult(new QueryZoneAreaNameResponse
  207. {
  208. s2c_code = zone != null ? Response.CODE_OK : Response.CODE_ERROR,
  209. areaName = zone?.area.key
  210. });
  211. }
  212. [RpcHandler(typeof(GetZonesInfoRequest), typeof(GetZonesInfoResponse))]
  213. public virtual void logic_rpc_Handle(GetZonesInfoRequest req, OnRpcReturn<GetZonesInfoResponse> cb)
  214. {
  215. GetZonesInfoResponse rsp = new GetZonesInfoResponse();
  216. //指定场景的所有线.
  217. var lt = GetZoneList(req.servergroupID, req.mapID);
  218. if (lt != null)
  219. {
  220. List<ZoneInfoSnap> snaps = new List<ZoneInfoSnap>();
  221. rsp.snaps = snaps;
  222. ZoneInfoSnap snap = null;
  223. ZoneInfo info = null;
  224. for (int i = 0; i < lt.Count; i++)
  225. {
  226. //获取所有线的信息.
  227. info = lt[i];
  228. if (info != null && info.close == false)
  229. {
  230. snap = new ZoneInfoSnap();
  231. snap.curPlayerCount = info.currentRoleCount;
  232. snap.playerMaxCount = info.map_data.max_players;
  233. snap.lineIndex = info.lineIndex;
  234. snap.playerFullCount = info.map_data.full_players;
  235. snap.uuid = info.uuid;
  236. snaps.Add(snap);
  237. }
  238. }
  239. }
  240. cb(rsp);
  241. }
  242. /// <summary>
  243. /// 批量获取场景分线
  244. /// </summary>
  245. /// <param name="req"></param>
  246. /// <param name="cb"></param>
  247. [RpcHandler(typeof(GetBatchZonesInfoRequest), typeof(GetBatchZonesInfoResponse))]
  248. public virtual void logic_rpc_Handle(GetBatchZonesInfoRequest req, OnRpcReturn<GetBatchZonesInfoResponse> cb)
  249. {
  250. GetBatchZonesInfoResponse rsp = new GetBatchZonesInfoResponse();
  251. rsp.snapDic = new HashMap<int, List<ZoneInfoSnap>>();
  252. foreach (var item in req.mapIDList)
  253. {
  254. var lt = GetZoneList(req.servergroupID, item);
  255. if (lt != null)
  256. {
  257. ZoneInfoSnap snap = null;
  258. ZoneInfo info = null;
  259. List<ZoneInfoSnap> snaps = new List<ZoneInfoSnap>();
  260. for (int i = 0; i < lt.Count; i++)
  261. {
  262. //获取所有线的信息.
  263. info = lt[i];
  264. if (info != null && info.close == false)
  265. {
  266. snap = new ZoneInfoSnap();
  267. snap.curPlayerCount = info.currentRoleCount;
  268. snap.playerMaxCount = info.map_data.max_players;
  269. snap.lineIndex = info.lineIndex;
  270. snap.playerFullCount = info.map_data.full_players;
  271. snap.uuid = info.uuid;
  272. snaps.Add(snap);
  273. }
  274. }
  275. rsp.snapDic.Add(item, snaps);
  276. }
  277. }
  278. cb(rsp);
  279. }
  280. [RpcHandler(typeof(GetRolePositionRequest), typeof(GetRolePositionResponse))]
  281. public virtual async Task<GetRolePositionResponse> logic_rpc_Handle(GetRolePositionRequest req)
  282. {
  283. if (roles.ContainsKey(req.roleUUID) == false)
  284. {
  285. return new GetRolePositionResponse()
  286. {
  287. s2c_code = GetRolePositionResponse.CODE_ROLE_NOT_EXIST
  288. };
  289. }
  290. var role = roles.Get(req.roleUUID);
  291. var zone = role.zone;
  292. if (zone == null)
  293. {
  294. return (new GetRolePositionResponse() { s2c_code = GetRolePositionResponse.CODE_ZONE_NOT_EXIST });
  295. }
  296. var resp = await zone.area.service.CallAsync<GetRolePositionResponse>(req);
  297. resp.line = zone.lineIndex;
  298. resp.zoneId = zone.map_data.id;
  299. resp.zoneUUID = zone.uuid;
  300. return resp;
  301. }
  302. #endregion
  303. //------------------------------------------------------------------------------------------------------------------------------------
  304. #region ZoneManager
  305. private readonly ValueSortedMap<string, ValueSortedMap<string, AreaInfo>> areas;
  306. private readonly HashMap<string, RoleInfo> roles = new HashMap<string, RoleInfo>();
  307. private readonly ZoneMap zones = new ZoneMap();
  308. public virtual async Task<RoleEnterZoneResponse> RoleEnter(RoleEnterZoneRequest req)
  309. {
  310. if (roles.ContainsKey(req.roleUUID))
  311. {
  312. return (new RoleEnterZoneResponse() { s2c_code = RoleEnterZoneResponse.CODE_ROLE_ALREADY_IN_ZONE });
  313. }
  314. var roleInfo = new RoleInfo(req.roleUUID, req);
  315. //先添加以防止二次进入//
  316. roles.Add(roleInfo.uuid, roleInfo);
  317. try
  318. {
  319. var zone = await this.LookingForExpectZone(req);
  320. if (zone == null || zone.close)
  321. {
  322. roles.Remove(req.roleUUID);
  323. return (new RoleEnterZoneResponse() { s2c_code = RoleEnterZoneResponse.CODE_ZONE_NOT_EXIST });
  324. }
  325. //--------------------------------------------------------------------------------
  326. //分配线.
  327. req.expectLineIndex = zone.lineIndex;
  328. req.expectZoneUUID = zone.uuid;
  329. zone.AddTeamID(req.teamID);
  330. //--------------------------------------------------------------------------------
  331. var rsp = await zone.area.service.CallAsync<RoleEnterZoneResponse>(req);
  332. if (Response.CheckSuccess(rsp))
  333. {
  334. zone.currentRoleCount++;
  335. zone.area.currentRoleCount++;
  336. roleInfo.zone = zone;
  337. }
  338. else
  339. {
  340. roles.Remove(req.roleUUID);
  341. log.Error(rsp);
  342. }
  343. return rsp;
  344. }
  345. catch (Exception err)
  346. {
  347. roles.Remove(req.roleUUID);
  348. return (new RoleEnterZoneResponse() { s2c_code = RoleEnterZoneResponse.CODE_ERROR, s2c_msg = err.Message });
  349. }
  350. }
  351. public virtual async Task<RoleLeaveZoneResponse> RoleLeave(RoleLeaveZoneRequest req)
  352. {
  353. var role = roles.RemoveByKey(req.roleID);
  354. if (role == null)
  355. {
  356. return (new RoleLeaveZoneResponse() { s2c_code = RoleLeaveZoneResponse.CODE_ROLE_NOT_EXIST });
  357. }
  358. var zone = role.zone;
  359. if (zone == null)
  360. {
  361. return (new RoleLeaveZoneResponse() { s2c_code = RoleLeaveZoneResponse.CODE_ZONE_NOT_EXIST });
  362. }
  363. //最后才删除//
  364. zone.currentRoleCount--;
  365. zone.area.currentRoleCount--;
  366. req.zoneUUID = zone.uuid;
  367. var rsp = await zone.area.service.CallAsync<RoleLeaveZoneResponse>(req);
  368. if (!Response.CheckSuccess(rsp))
  369. {
  370. log.Error(rsp);
  371. }
  372. zone.RemoveTeamID(role.enter.teamID);
  373. return rsp;
  374. }
  375. public virtual async Task<ZoneInfo> LookingForExpectZone(RoleEnterZoneRequest req)
  376. {
  377. ZoneInfo zone = null;
  378. #region 返回上一个场景.
  379. //返回上一次的场景,如果没有统一返回上一次的公共场景.
  380. if (!string.IsNullOrEmpty(req.expectZoneUUID))
  381. {
  382. //根据提供的UUID寻找场景//
  383. zone = GetZone(req.expectZoneUUID);
  384. if (zone != null && !zone.close)
  385. {
  386. if (zone.currentRoleCount < zone.map_data.max_players)
  387. {
  388. return (zone);
  389. }
  390. }
  391. return await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req);
  392. }
  393. #endregion
  394. else
  395. {
  396. var temp = RPGServerTemplateManager.Instance.GetMapTemplate(req.expectMapTemplateID);
  397. if (temp == null)//场景不存在,往公共场景扔.
  398. {
  399. return await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, new ZonePosition(), req);
  400. }
  401. //优先判断公会场景//
  402. if (!string.IsNullOrEmpty(req.guildUUID))
  403. {
  404. ZoneInfo guildZone = GetGuildZone(req.guildUUID);
  405. if (guildZone != null && !guildZone.close)
  406. {
  407. if (guildZone.currentRoleCount < guildZone.map_data.max_players)
  408. {
  409. return (guildZone);
  410. }
  411. else//公会场景人数大于人数时候,不再能进入场景.
  412. {
  413. return await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req);
  414. }
  415. }
  416. else //创建公会场景.
  417. {
  418. //新创建一个场景//
  419. var rsp = await this.CreateZone(new CreateZoneNodeRequest()
  420. {
  421. //serverID = req.serverID,
  422. serverGroupID = req.servergroupID,
  423. mapTemplateID = req.expectMapTemplateID,
  424. createRoleID = req.roleUUID,
  425. teamID = req.teamID,
  426. guildUUID = req.guildUUID,
  427. reason = "LookingForAreaRequest dispatch",
  428. expandData = RPGServerTemplateManager.Instance.GetCreateZoneExpandData(req),
  429. expectAreaNode = req.roleSessionNode,
  430. });
  431. if (Response.CheckSuccess(rsp))
  432. {
  433. return (GetZone(rsp.zoneUUID));
  434. }
  435. else
  436. {
  437. return await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req);
  438. }
  439. }
  440. }
  441. //ROOMKEY.
  442. if (!string.IsNullOrEmpty(req.roomKey))
  443. {
  444. zone = GetRoomZone(req.roomKey);
  445. if (zone != null && !zone.close)
  446. {
  447. return (zone);
  448. }
  449. }
  450. //分配至队伍场景/
  451. if (req.teamID != null)
  452. {
  453. zone = LookingForExpectServerGroupZone(req.servergroupID, z =>
  454. {
  455. return z.currentRoleCount < temp.max_players &&
  456. z.map_data.zone_template_id == req.expectMapTemplateID &&
  457. z.ContainTeamID(req.teamID);
  458. });
  459. if (zone != null && !zone.close)
  460. {
  461. return (zone);
  462. }
  463. }
  464. //根据EXPECT MAP来.
  465. if (RPGServerTemplateManager.Instance.IsPublicMap(temp))
  466. {
  467. return await LookingForPublicZone(null, req.expectMapTemplateID, req.roleScenePos, req);
  468. }
  469. else
  470. {
  471. //新创建一个场景//
  472. var rsp = await this.CreateZone(new CreateZoneNodeRequest()
  473. {
  474. //serverID = req.serverID,
  475. serverGroupID = req.servergroupID,
  476. mapTemplateID = temp.id,
  477. createRoleID = req.roleUUID,
  478. teamID = req.teamID,
  479. reason = "LookingForAreaRequest dispatch",
  480. expandData = RPGServerTemplateManager.Instance.GetCreateZoneExpandData(req),
  481. roomKey = req.roomKey,
  482. expectAreaNode = req.roleSessionNode,
  483. });
  484. if (Response.CheckSuccess(rsp))
  485. {
  486. return (GetZone(rsp.zoneUUID));
  487. }
  488. else
  489. {
  490. return await LookingForPublicZone(req.lastPublicMapUUID, req.lastPublicMapID, req.lastPublicPos, req);
  491. }
  492. }
  493. }
  494. }
  495. protected virtual async Task<ZoneInfo> LookingForPublicZone(string publicmapUUID, int publicmapID, ZonePosition pos, RoleEnterZoneRequest req)
  496. {
  497. //没有统一返回上一次的公共场景.
  498. req.roleScenePos = pos;
  499. ZoneInfo zone = GetZone(publicmapUUID);
  500. if (zone != null && !zone.close)
  501. {
  502. if (zone.currentRoleCount < zone.map_data.max_players)
  503. {
  504. return (zone);
  505. }
  506. }
  507. //找当前存在的公共场景.
  508. var temp = RPGServerTemplateManager.Instance.GetMapTemplate(publicmapID);
  509. if (temp == null)
  510. {
  511. temp = RPGServerTemplateManager.Instance.GetDefaultMapData(req);
  512. req.lastPublicPos = new ZonePosition();
  513. }
  514. zone = LookingForExpectServerGroupZone(req.servergroupID, z =>
  515. {
  516. return z.currentRoleCount < temp.full_players && z.map_data.zone_template_id == temp.id;
  517. }, (a, b) =>
  518. {
  519. if (req.roleSessionNode == a.nodeName) return -1;
  520. if (req.roleSessionNode == b.nodeName) return 1;
  521. return 0;
  522. });
  523. if (zone != null && !zone.close)
  524. {
  525. return (zone);
  526. }
  527. //创建一个公共场景.
  528. var rsp = await this.CreateZone(new CreateZoneNodeRequest()
  529. {
  530. serverGroupID = req.servergroupID,
  531. //serverID = req.serverID,
  532. mapTemplateID = temp.id,
  533. reason = "LookingForAreaRequest dispatch",
  534. expandData = RPGServerTemplateManager.Instance.GetCreateZoneExpandData(req),
  535. roomKey = req.roomKey,
  536. expectAreaNode = req.roleSessionNode,
  537. });
  538. if (Response.CheckSuccess(rsp))
  539. {
  540. return (GetZone(rsp.zoneUUID));
  541. }
  542. else
  543. {
  544. return (null);
  545. }
  546. }
  547. /// <summary>
  548. /// 根据地图ID,和Area名字选择合适Zone
  549. /// </summary>
  550. /// <param name="serverGroupID"></param>
  551. /// <param name="condition">必要条件</param>
  552. /// <param name="expect">可选条件</param>
  553. /// <returns></returns>
  554. protected ZoneInfo LookingForExpectServerGroupZone(string serverGroupID, Predicate<ZoneInfo> condition, Comparison<ZoneInfo> expect = null)
  555. {
  556. var map = zones.GetAllZones();
  557. if (map != null)
  558. {
  559. var zones = new List<ZoneInfo>(map);
  560. return LookingForExpectZone(zones, condition, expect);
  561. }
  562. return null;
  563. }
  564. /// <summary>
  565. /// 选取预期场景
  566. /// </summary>
  567. /// <param name="zones"></param>
  568. /// <param name="condition">必要条件</param>
  569. /// <param name="expect">可选条件</param>
  570. /// <returns></returns>
  571. protected virtual ZoneInfo LookingForExpectZone(List<ZoneInfo> zones, Predicate<ZoneInfo> condition, Comparison<ZoneInfo> expect = null)
  572. {
  573. for (int i = zones.Count - 1; i >= 0; --i)
  574. {
  575. var z = zones[i];
  576. if (z.close || !condition(z))
  577. {
  578. zones.RemoveAt(i);
  579. }
  580. }
  581. if (zones.Count > 0)
  582. {
  583. if (expect != null)
  584. {
  585. zones.Sort(expect);
  586. }
  587. return zones[0];
  588. }
  589. return null;
  590. }
  591. /// <summary>
  592. /// 负载均衡排序
  593. /// </summary>
  594. /// <param name="a"></param>
  595. /// <param name="b"></param>
  596. /// <returns></returns>
  597. public virtual int AreaComparison(AreaInfo a, AreaInfo b)
  598. {
  599. if (a.state == null) return -1;
  600. if (b.state == null) return 1;
  601. return a.state.roleCount - b.state.roleCount;
  602. }
  603. public virtual int AreaGroupComparison(ValueSortedMap<string, AreaInfo> a, ValueSortedMap<string, AreaInfo> b)
  604. {
  605. var ac = a.Values.Sum(area => area.currentRoleCount);
  606. var bc = b.Values.Sum(area => area.currentRoleCount);
  607. return ac - bc;
  608. }
  609. public virtual async Task<RegistAreaResponse> AreaRegist(RegistAreaRequest reg)
  610. {
  611. IRemoteService svc;
  612. try
  613. {
  614. svc = await base.Provider.GetAsync(new RemoteAddress(reg.areaName, reg.areaNode));
  615. if (svc != null)
  616. {
  617. Console.WriteLine(" AreaManager areas 添加节点:"+ svc.Address.ServiceNode+" Name:"+ svc.Address.ServiceName);
  618. var node = areas.GetOrAdd(svc.Address.ServiceNode, (n) => new ValueSortedMap<string, AreaInfo>(AreaComparison));
  619. node.TryAddOrUpdate(svc.Address.ServiceName, new AreaInfo(svc));
  620. return new RegistAreaResponse();
  621. }
  622. else
  623. {
  624. return new RegistAreaResponse() { s2c_code = RegistAreaResponse.CODE_ERROR };
  625. }
  626. }
  627. catch (Exception err)
  628. {
  629. log.Error(err.Message, err);
  630. throw;
  631. }
  632. }
  633. /// <summary>
  634. /// 分配一个空闲的Area
  635. /// </summary>
  636. /// <param name="expectAreaName"></param>
  637. /// <returns></returns>
  638. public virtual AreaInfo AreaDispatch(string expectNodeName)
  639. {
  640. ////请求动态创建场景
  641. //if (areas.Count == 0)
  642. //{
  643. // var getRemote = await ServerNames.GetOrCreateAreaServiceAsync(this, ServerGID);
  644. // if (getRemote != null)
  645. // {
  646. // var node = areas.GetOrAdd(getRemote.Address.ServiceNode, (n) => new ValueSortedMap<string, AreaInfo>(AreaComparison));
  647. // node.TryAddOrUpdate(getRemote.Address.ServiceName, new AreaInfo(getRemote));
  648. // }
  649. //}
  650. // TODO 场景最大人数负载
  651. if (areas.Count > 0)
  652. {
  653. if (expectNodeName != null && areas.TryGetValue(expectNodeName, out var group))
  654. {
  655. if (group.Count > 0)
  656. {
  657. return group.First;
  658. }
  659. }
  660. group = areas.First;
  661. if (group.Count > 0)
  662. {
  663. return group.First;
  664. }
  665. }
  666. throw new Exception("No Area !!!:::::"+ ServerGID);
  667. }
  668. /// <summary>
  669. /// 创建场景
  670. /// </summary>
  671. /// <param name="create"></param>
  672. /// <param name="cb"></param>
  673. public virtual async Task<CreateZoneNodeResponse> CreateZone(CreateZoneNodeRequest create)
  674. {
  675. //if (dungeon_scheduler.IsMapOpen(create.mapTemplateID))
  676. {
  677. var area = AreaDispatch(create.expectAreaNode);
  678. if (area != null)
  679. {
  680. create.managerZoneUUID = (Guid.NewGuid().ToString());
  681. //先添加以防止二次进入//
  682. var map_data = RPGServerTemplateManager.Instance.GetMapTemplate(create.mapTemplateID);
  683. var scene_data = RPGServerBattleManager.Instance.GetSceneAsCache(map_data.zone_template_id);
  684. ZoneInfo info = new ZoneInfo(create.managerZoneUUID, area, map_data, scene_data, create.serverGroupID, create.guildUUID, create.expectAreaNode)
  685. {
  686. roomKey = create.roomKey
  687. };
  688. zones.AddZone(info);
  689. area.currentZoneCount++;
  690. var rsp = await area.service.CallAsync<CreateZoneNodeResponse>(create);
  691. if (!Response.CheckSuccess(rsp))
  692. {
  693. zones.RemoveZone(create.managerZoneUUID);
  694. area.currentZoneCount--;
  695. }
  696. else
  697. {
  698. log.InfoFormat("CreateZone: {0} : TotalZoneCount={1}", scene_data, zones.Count);
  699. }
  700. return rsp;
  701. }
  702. else
  703. {
  704. return (new CreateZoneNodeResponse() { s2c_code = CreateZoneNodeResponse.CODE_ERROR, });
  705. }
  706. }
  707. }
  708. /// <summary>
  709. /// 销毁场景
  710. /// </summary>
  711. /// <param name="stop"></param>
  712. /// <param name="cb"></param>
  713. public virtual async Task<DestoryZoneNodeResponse> DestoryZone(DestoryZoneNodeRequest stop)
  714. {
  715. ZoneInfo zone = zones.RemoveZone(stop.zoneUUID);
  716. if (zone != null)
  717. {
  718. //log.Log("DestoryZone: " + stop.zoneUUID + " " + stop);
  719. zones.RemoveZone(stop.zoneUUID);
  720. zone.area.currentZoneCount--;
  721. return await zone.area.service.CallAsync<DestoryZoneNodeResponse>(stop);
  722. }
  723. else
  724. {
  725. return (new DestoryZoneNodeResponse() { s2c_code = Response.CODE_ERROR, });
  726. }
  727. }
  728. /// <summary>
  729. /// 批量创建场景分线
  730. /// </summary>
  731. /// <param name="create"></param>
  732. /// <returns></returns>
  733. public virtual async Task<BatchCreateZoneLineResponse> BatchCreateZoneLine(BatchCreateZoneLineRequest create)
  734. {
  735. BatchCreateZoneLineResponse response = new BatchCreateZoneLineResponse();
  736. response.zoneList = new List<ZoneInfoSnap>();
  737. foreach (var item in create.zoneList)
  738. {
  739. var result = await CreateZone(item);
  740. ZoneInfoSnap zone = new ZoneInfoSnap();
  741. zone.lineIndex = GetZone(result.zoneUUID).lineIndex;
  742. zone.TemplateID = result.TemplateID;
  743. zone.uuid = result.zoneUUID;
  744. response.zoneList.Add(zone);
  745. }
  746. return response;
  747. }
  748. public virtual bool DestoryZone(AreaZoneDestoryNotify stop)
  749. {
  750. try
  751. {
  752. ZoneInfo zone = zones.RemoveZone(stop.zoneUUID);
  753. if (zone != null)
  754. {
  755. //log.Log("DestoryZone: " + stop.zoneUUID + " " + stop);
  756. zone.area.currentZoneCount--;
  757. zone.area.service.Call<DestoryZoneNodeResponse>(new DestoryZoneNodeRequest()
  758. {
  759. reason = stop.reason,
  760. zoneUUID = stop.zoneUUID
  761. }, (rsp, err) =>
  762. {
  763. //log.Log("DestoryZone: " + stop.zoneUUID + " " + rsp);
  764. });
  765. return true;
  766. }
  767. }
  768. catch (Exception err)
  769. {
  770. log.Error(err.Message, err);
  771. throw err;
  772. }
  773. return false;
  774. }
  775. public virtual RoleInfo GetRole(string roleID)
  776. {
  777. RoleInfo ret;
  778. if (roleID != null && roles.TryGetValue(roleID, out ret))
  779. {
  780. return ret;
  781. }
  782. return null;
  783. }
  784. public virtual ZoneInfo GetZone(string zoneUUID)
  785. {
  786. return zones.GetZone(zoneUUID);
  787. }
  788. public virtual ZoneInfo GetZone(int mapId, int lineId)
  789. {
  790. return zones.GetZone(mapId, lineId);
  791. }
  792. public ZoneInfo GetGuildZone(string guildUUID)
  793. {
  794. return zones.GetGuildZone(guildUUID);
  795. }
  796. public ZoneInfo GetRoomZone(string roomKey)
  797. {
  798. return zones.GetRoomZone(roomKey);
  799. }
  800. public List<ZoneInfo> GetZoneList(string serverGroupID, int mapID)
  801. {
  802. return zones.GetZoneList(serverGroupID, mapID);
  803. }
  804. public RoleInfo[] GetAllRoles()
  805. {
  806. var ret = new List<RoleInfo>(roles.Values);
  807. return ret.ToArray();
  808. }
  809. public List<ZoneInfo> GetAllZones()
  810. {
  811. return zones.GetAllZones();
  812. }
  813. //------------------------------------------------------------------------------------------------------------------------------------
  814. public class AreaInfo
  815. {
  816. public readonly IRemoteService service;
  817. public readonly string key;
  818. public int currentRoleCount { get; internal set; }
  819. public int currentZoneCount { get; internal set; }
  820. public AreaStateNotify state { get; internal set; }
  821. public AreaInfo(IRemoteService svc)
  822. {
  823. this.service = svc;
  824. this.key = svc.Address.ServiceName;
  825. this.currentRoleCount = 0;
  826. this.currentZoneCount = 0;
  827. }
  828. public void WriteState(TextWriter sb)
  829. {
  830. sb.WriteLine("AreaState : " + service.Address.FullPath);
  831. sb.WriteLine(" role = " + currentRoleCount);
  832. sb.WriteLine(" zone = " + currentZoneCount);
  833. if (state != null)
  834. {
  835. sb.WriteLine(" cpu = " + state.cpuPercent);
  836. sb.WriteLine(" memory = " + state.memoryMB + "(MB)");
  837. }
  838. }
  839. }
  840. public class ZoneInfo
  841. {
  842. public readonly string uuid;
  843. public readonly AreaInfo area;
  844. public readonly MapTemplateData map_data;
  845. public readonly SceneData scene_data;
  846. public int currentRoleCount { get; internal set; }
  847. public string serverGroupID { get; internal set; }
  848. public int lineIndex { get; set; }
  849. public string guildUUID { get; set; }
  850. public string roomKey { get; internal set; }
  851. public bool close { get; internal set; }
  852. public string nodeName { get; internal set; }
  853. private HashMap<string, int> TeamIDData = new HashMap<string, int>();
  854. public ZoneInfo(string uuid, AreaInfo parent, MapTemplateData map_data, SceneData sdata, string serverGroupID, string guildUUID, string nodeName)
  855. {
  856. this.uuid = uuid;
  857. this.area = parent;
  858. this.map_data = map_data;
  859. this.scene_data = sdata;
  860. this.currentRoleCount = 0;
  861. this.serverGroupID = serverGroupID;
  862. this.guildUUID = guildUUID;
  863. this.lineIndex = 1;
  864. this.roomKey = roomKey;
  865. this.nodeName = nodeName;
  866. }
  867. public void AddTeamID(string teamID)
  868. {
  869. if (teamID == null) return;
  870. TeamIDData.TryGetValue(teamID, out var count);
  871. count++;
  872. TeamIDData.Put(teamID, count);
  873. }
  874. public bool ContainTeamID(string teamID)
  875. {
  876. if (teamID == null) return false;
  877. return TeamIDData.ContainsKey(teamID);
  878. }
  879. public void RemoveTeamID(string teamID)
  880. {
  881. if (teamID == null) return;
  882. TeamIDData.TryGetValue(teamID, out var count);
  883. count--;
  884. TeamIDData.Put(teamID, count);
  885. if (count <= 0)
  886. TeamIDData.Remove(teamID);
  887. }
  888. public List<string> GetTeamIDList()
  889. {
  890. return TeamIDData.Keys.ToList();
  891. }
  892. }
  893. public class RoleInfo
  894. {
  895. public readonly string uuid;
  896. public readonly RoleEnterZoneRequest enter;
  897. public ZoneInfo zone { get; internal set; }
  898. public RoleInfo(string uuid, RoleEnterZoneRequest req)
  899. {
  900. this.uuid = uuid;
  901. this.enter = req;
  902. }
  903. }
  904. public class ZoneMap
  905. {
  906. /// <summary>
  907. /// 所有场景信息<key:场景UID ,value:场景信息>
  908. /// </summary>
  909. private readonly Dictionary<string, ZoneInfo> zones = new Dictionary<string, ZoneInfo>();
  910. ///// <summary>
  911. ///// 所有场景信息<key:场景UID ,value:场景信息>
  912. ///// </summary>
  913. //private readonly Dictionary<string, ZoneInfo> zonesMap = new Dictionary<string, ZoneInfo>();
  914. /// <summary>
  915. /// 所有场景信息<key:场景Id,value:<key:分线ID,value:分线信息>>
  916. /// </summary>
  917. private readonly Dictionary<int, Dictionary<int, ZoneInfo>> zonesLineMap = new Dictionary<int, Dictionary<int, ZoneInfo>>();
  918. /// <summary>
  919. /// 公会场景集合<key:公会UID,value:<key:场景UID,场景信息>>
  920. /// </summary>
  921. private readonly Dictionary<string, Dictionary<string, ZoneInfo>> guildZones = new Dictionary<string, Dictionary<string, ZoneInfo>>();
  922. /// <summary>
  923. /// 特殊场景信息 <key: 房间所有这生成房间ID,value:场景信息>>
  924. /// </summary>
  925. private readonly Dictionary<string, ZoneInfo> roomZones = new Dictionary<string, ZoneInfo>();
  926. public int Count { get => zones.Count; }
  927. public void AddZone(ZoneInfo zone)
  928. {
  929. zones.Add(zone.uuid, zone);
  930. //---------------------------------------------------------------------------------------------
  931. if (RPGServerTemplateManager.Instance.IsPublicMap(zone.map_data))
  932. {
  933. Dictionary<int, ZoneInfo> lt = null;
  934. if (!zonesLineMap.TryGetValue(zone.map_data.id, out lt))
  935. {
  936. lt = new Dictionary<int, ZoneInfo>();
  937. zonesLineMap.Add(zone.map_data.id, lt);
  938. }
  939. AddLine(zone, lt);
  940. }
  941. //---------------------------------------------------------------------------------------------
  942. if (zone.guildUUID != null)
  943. {
  944. AddGuildZone(zone.guildUUID, zone);
  945. }
  946. if (!string.IsNullOrEmpty(zone.roomKey))
  947. {
  948. roomZones.Add(zone.roomKey, zone);
  949. }
  950. }
  951. public ZoneInfo GetRoomZone(string roomKey)
  952. {
  953. if (string.IsNullOrEmpty(roomKey))
  954. {
  955. return null;
  956. }
  957. if (roomZones.TryGetValue(roomKey, out var ret))
  958. {
  959. //if (ret.close != true)
  960. return ret;
  961. }
  962. return null;
  963. }
  964. public ZoneInfo RemoveZone(string uuid)
  965. {
  966. if (string.IsNullOrEmpty(uuid))
  967. return null;
  968. ZoneInfo info;
  969. string guildUUID = null;
  970. if (zones.TryGetValue(uuid, out info))
  971. {
  972. guildUUID = info.guildUUID;
  973. zones.Remove(uuid);
  974. //---------------------------------------------------------------------------------------------
  975. //分线表删除.
  976. zonesLineMap.TryGetValue(info.map_data.id, out var lt);
  977. RemoveLine(info.uuid, lt);
  978. //---------------------------------------------------------------------------------------------
  979. //公会场景表删除.
  980. RemoveGuildZone(uuid, guildUUID);
  981. if (!string.IsNullOrEmpty(info.roomKey))
  982. {
  983. roomZones.Remove(info.roomKey);
  984. }
  985. }
  986. return info;
  987. }
  988. public void Clear()
  989. {
  990. zones.Clear();
  991. zonesLineMap.Clear();
  992. roomZones.Clear();
  993. }
  994. // public Dictionary<string, ZoneInfo> Values()
  995. // {
  996. // return zones;
  997. // }
  998. public ZoneInfo GetZone(string uuid)
  999. {
  1000. ZoneInfo ret = null;
  1001. if (!string.IsNullOrEmpty(uuid) && zones.TryGetValue(uuid, out ret))
  1002. {
  1003. //if (ret.close != true)
  1004. return ret;
  1005. }
  1006. return null;
  1007. }
  1008. public ZoneInfo GetZone(int mapId, int lineId)
  1009. {
  1010. foreach (var item in zones)
  1011. {
  1012. if (item.Value.map_data.id == mapId && item.Value.lineIndex == lineId)
  1013. {
  1014. return item.Value;
  1015. }
  1016. }
  1017. return null;
  1018. }
  1019. public bool TryGetValue(string uuid, out ZoneInfo zoneinfo)
  1020. {
  1021. return zones.TryGetValue(uuid, out zoneinfo);
  1022. }
  1023. public void SetZoneCloseFlag(string uuid)
  1024. {
  1025. var zone = GetZone(uuid);
  1026. if (zone != null)
  1027. zone.close = true;
  1028. }
  1029. private void AddLine(ZoneInfo zone, Dictionary<int, ZoneInfo> lt)
  1030. {
  1031. if (lt == null)
  1032. {
  1033. lt = new Dictionary<int, ZoneInfo>();
  1034. zone.lineIndex = 1;
  1035. lt.Add(zone.lineIndex, zone);//默认分线1
  1036. return;
  1037. }
  1038. else
  1039. {
  1040. //遍历当前中所有分线信息
  1041. for (int i = 1; i <= lt.Count; i++)
  1042. {
  1043. //获取当前不存在的分线ID
  1044. if (!lt.ContainsKey(i))
  1045. {
  1046. zone.lineIndex = i;
  1047. lt.Add(zone.lineIndex, zone);
  1048. return;
  1049. }
  1050. }
  1051. //创建新的分线ID
  1052. zone.lineIndex = lt.Count + 1;
  1053. lt.Add(zone.lineIndex, zone);//默认分线1
  1054. return;
  1055. //bool insert = false;
  1056. //for (int i = 0; i < lt.Count; i++)
  1057. //{
  1058. // if (lt[i] == null)
  1059. // {
  1060. // insert = true;
  1061. // lt[i] = zone;
  1062. // zone.lineIndex = i + 1;
  1063. // break;
  1064. // }
  1065. //}
  1066. //if (insert == false)
  1067. //{
  1068. // lt.Add(zone.lineIndex, zone);
  1069. //}
  1070. }
  1071. }
  1072. private void RemoveLine(string uuid, Dictionary<int, ZoneInfo> lt)
  1073. {
  1074. if (lt == null || lt.Count == 0) return;
  1075. foreach (var item in lt)
  1076. {
  1077. if (item.Value.uuid == uuid)
  1078. {
  1079. lt.Remove(item.Key);
  1080. return;
  1081. }
  1082. }
  1083. }
  1084. private void AddGuildZone(string guildUUID, ZoneInfo zone)
  1085. {
  1086. if (!guildZones.TryGetValue(guildUUID, out var submap))
  1087. {
  1088. submap = new Dictionary<string, ZoneInfo>();
  1089. guildZones.Add(guildUUID, submap);
  1090. }
  1091. submap.Add(zone.uuid, zone);
  1092. }
  1093. private void RemoveGuildZone(string uuid, string guilduuid)
  1094. {
  1095. if (string.IsNullOrEmpty(guilduuid))
  1096. return;
  1097. if (string.IsNullOrEmpty(guilduuid) == false)
  1098. {
  1099. guildZones.TryGetValue(guilduuid, out var submap);
  1100. if (submap != null)
  1101. {
  1102. submap.Remove(uuid);
  1103. if (submap.Count == 0)
  1104. guildZones.Remove(guilduuid);
  1105. }
  1106. }
  1107. }
  1108. public ZoneInfo GetGuildZone(string uuid)
  1109. {
  1110. if (string.IsNullOrEmpty(uuid))
  1111. return null;
  1112. ZoneInfo ret;
  1113. if (guildZones.TryGetValue(uuid, out var submap))
  1114. {
  1115. foreach (var item in submap)
  1116. {
  1117. ret = item.Value;
  1118. //if (ret.close != true)
  1119. return ret;
  1120. }
  1121. }
  1122. return null;
  1123. }
  1124. /// <summary>
  1125. /// 获取当前Group内,指定场景的分线信息.
  1126. /// </summary>
  1127. /// <param name="serverGroupID"></param>
  1128. /// <param name="mapID"></param>
  1129. /// <returns></returns>
  1130. public List<ZoneInfo> GetZoneList(string serverGroupID, int mapID)
  1131. {
  1132. Dictionary<int, ZoneInfo> lt;
  1133. List<ZoneInfo> ret;
  1134. if (zonesLineMap.TryGetValue(mapID, out lt))
  1135. {
  1136. ret = new List<ZoneInfo>();
  1137. foreach (var item in lt)
  1138. {
  1139. ret.Add(item.Value);
  1140. }
  1141. return ret;
  1142. }
  1143. return null;
  1144. }
  1145. public List<ZoneInfo> GetZones(int templateID)
  1146. {
  1147. var all = new List<ZoneInfo>(this.zones.Values);
  1148. var ret = new List<ZoneInfo>();
  1149. foreach (var zoneInfo in all)
  1150. {
  1151. if (zoneInfo.map_data.id == templateID /*&& zoneInfo.close != true*/)
  1152. {
  1153. ret.Add(zoneInfo);
  1154. }
  1155. }
  1156. return ret;
  1157. }
  1158. public List<ZoneInfo> GetAllZones()
  1159. {
  1160. return new List<ZoneInfo>(this.zones.Values);
  1161. //var all = new List<ZoneInfo>(this.zones.Values);
  1162. //var ret = new List<ZoneInfo>();
  1163. //foreach (var zoneInfo in all)
  1164. //{
  1165. // // if (zoneInfo.close != true)
  1166. // {
  1167. // ret.Add(zoneInfo);
  1168. // }
  1169. //}
  1170. //return ret;
  1171. }
  1172. }
  1173. //------------------------------------------------------------------------------------------------------------------------------------
  1174. #endregion
  1175. //------------------------------------------------------------------------------------------------------------------------------------
  1176. }
  1177. }