ServerNames.cs 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using DeepCore;
  2. using DeepCrystal.RPC;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace DeepMMO.Server
  9. {
  10. public static partial class ServerNames
  11. {
  12. public const string GateServerType /* */ = "GateServer";
  13. public const string ConnectServerType /* */ = "ConnectServer";
  14. public const string SessionServiceType /**/ = "SessionService";
  15. public const string AreaManagerType /* */ = "AreaManager";
  16. public const string AreaServiceType /* */ = "AreaService";
  17. public const string LogicServiceType /* */ = "LogicService";
  18. public const string RankingServiceType /* */ = "RankingService";
  19. public const string LogServiceType = "LogService"; //日志服务器
  20. public const string GuildServiceType = "GuildService";
  21. public static RemoteAddress LogService = new RemoteAddress("LogService", null, LogServiceType);
  22. public static RemoteAddress GateServer = new RemoteAddress("GateServer", null, GateServerType);
  23. public static RemoteAddress ConnectServer = new RemoteAddress("Connect:<Number>", null, ConnectServerType);
  24. public static RemoteAddress SessionService = new RemoteAddress("Session:<AccountID>", null, SessionServiceType);
  25. public static RemoteAddress AreaManager = new RemoteAddress("AreaManager", null, AreaManagerType);
  26. public static RemoteAddress AreaService = new RemoteAddress("Area:<Number>", null, AreaServiceType);
  27. public static RemoteAddress LogicService = new RemoteAddress("Logic:<RoleID>", null, LogicServiceType);
  28. public static RemoteAddress RankingService = new RemoteAddress("RankingService", null, RankingServiceType);
  29. public static RemoteAddress GuildService = new RemoteAddress("GuildService", null, GuildServiceType);
  30. public const string SessionPrefix = "Session:";
  31. public const string ConnectPrefix = "Connect:";
  32. public const string LogicPrefix = "Logic:";
  33. public const string AreaPrefix = "Area:";
  34. public static RemoteAddress CreateSessionServiceAddress(string accountID, RemoteAddress connectServer)
  35. {
  36. return new RemoteAddress(SessionPrefix + accountID, connectServer.ServiceNode, SessionService.ServiceType);
  37. }
  38. //动态创建场景管理器
  39. public static Task<IRemoteService> GetOrCreateAreaManagerServiceAsync(this IService prv, string GID)
  40. {
  41. var cfg = new HashMap<string, string>();
  42. cfg["groupID"] = GID;
  43. int groupId = Convert.ToInt32(GID);
  44. if (groupId>1000)
  45. {
  46. throw new Exception("服务器组ID 过大:"+groupId);
  47. }
  48. return prv.Provider.GetOrCreateAsync(new RemoteAddress(AreaManager.ServiceType + ":" + GID, prv.SelfAddress.ServiceNode, AreaManager.ServiceType), cfg);
  49. //var cfg = new HashMap<string, string>();
  50. //cfg["groupID"] = GID;
  51. //return prv.Provider.GetOrCreateAsync(new RemoteAddress(AreaService.ServiceType + ":" + GID, prv.SelfAddress.ServiceNode, AreaService.ServiceType), cfg);
  52. }
  53. //动态创建场景服务器
  54. public static Task<IRemoteService> GetOrCreateAreaServiceAsync(this IService prv, string GID)
  55. {
  56. var cfg = new HashMap<string, string>();
  57. cfg["groupID"] = GID;
  58. return prv.Provider.GetOrCreateAsync(new RemoteAddress(AreaService.ServiceType + ":" + GID, prv.SelfAddress.ServiceNode, AreaService.ServiceType), cfg);
  59. //var cfg = new HashMap<string, string>();
  60. //cfg["groupID"] = GID;
  61. //return prv.Provider.GetOrCreateAsync(new RemoteAddress(AreaService.ServiceType + ":" + GID, prv.SelfAddress.ServiceNode, AreaService.ServiceType), cfg);
  62. }
  63. /// <summary>
  64. /// 获取逻辑服务地址
  65. /// </summary>
  66. /// <param name="roleID"></param>
  67. /// <returns></returns>
  68. public static RemoteAddress GetLogicServiceAddress(string roleID, string logicNode = null)
  69. {
  70. return new RemoteAddress(LogicPrefix + roleID, logicNode, LogicService.ServiceType);
  71. }
  72. }
  73. }