BotClient.Gate.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. using pomelo.area;
  2. using pomelo.connector;
  3. using pomelo.login;
  4. using Pomelo.DotNetClient;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using XmdsCommon.EditorData;
  11. namespace XmdsBattleClientBot.Bot
  12. {
  13. // 游戏服相关 //
  14. partial class BotClient
  15. {
  16. static String s_robotPwd = "9cbf8a4dcb8e30682b927f352d6559a0";
  17. static int s_robotOS = 1984579230;
  18. static String s_robotModle = "Robot";
  19. static String s_robotMac = "lnkj89adasfadfaser2345234523458789dfu";
  20. public EntryResponse LastEntryResponse { get; private set; }
  21. public GetRandomNameResponse LastGetRandomNameResponse { get; private set; }
  22. public CreatePlayerResponse LastCreatePlayerResponse { get; private set; }
  23. public BindPlayerResponse LastBindPlayerResponse { get; private set; }
  24. public pomelo.player.Player PlayerData { get; private set; }
  25. public string PlayerUUID { get { return (PlayerData != null ? PlayerData.uid : null); } }
  26. private dynamic getServer(string json, int serverId)
  27. {
  28. dynamic arr = SimpleJson.SimpleJson.DeserializeObject(json);
  29. foreach (dynamic arr1 in arr)
  30. {
  31. foreach (dynamic arr2 in arr1)
  32. {
  33. string area = arr2.Key;
  34. foreach (dynamic arr3 in arr2.Value)
  35. {
  36. int sid = (int)arr3[0];
  37. if (sid == serverId)
  38. {
  39. return new
  40. {
  41. sid = sid,
  42. name = (string)arr3[1],
  43. ip = (string)arr3[2],
  44. port = (int)arr3[3]
  45. };
  46. }
  47. }
  48. }
  49. }
  50. return null;
  51. }
  52. public void login(Action on_login, Action<Exception> on_error = null)
  53. {
  54. int serverId = Config.ServerID;
  55. Client.GateSocket.loginHandler.loginRequest(2, config.Appid.ToString(), Account, s_robotPwd, "999", s_robotOS, s_robotModle, s_robotMac, config.ClientVersion,
  56. config.Channel.ToString(), (PomeloException exception, LoginResponse res) =>
  57. {
  58. if (res != null)
  59. {
  60. this.Sign = res.token;
  61. this.GetAreaServersAndStartGame(Account, on_login, on_error);
  62. //Sign = res.token;
  63. //dynamic server = getServer(res.board, serverId);
  64. //if (server != null)
  65. //{
  66. // ServerId = server.sid;
  67. // Host = server.ip;
  68. // Port = server.port;
  69. // on_login();
  70. //}
  71. //else
  72. //{
  73. // MessageBox.Show("AppId : " + Config.Appid + @" 登录不存在服务器ID : " + serverId);
  74. //}
  75. }
  76. else
  77. {
  78. if (on_error != null)
  79. {
  80. on_error(exception);
  81. }
  82. else
  83. {
  84. MessageBox.Show(exception.Message);
  85. }
  86. }
  87. });
  88. }
  89. /** 获取服务器列表 */
  90. public void GetAreaServersAndStartGame(String uid, Action on_login, Action<Exception> on_error = null)
  91. {
  92. int serverId = Config.ServerID;
  93. if(serverId == -1)
  94. {
  95. int uidNum = Convert.ToInt32(uid.Substring(6));
  96. serverId = 10001 + uidNum / 30;
  97. }
  98. Client.GateSocket.loginHandler.getAreaServerInfoRequest(80, 1,(PomeloException exception, GetAreaServerInfoResponse res) =>
  99. {
  100. if (res != null)
  101. {
  102. ServerInfo findSrv = null;
  103. foreach (ServerInfo srvInfo in res.svrInfos)
  104. {
  105. if(srvInfo.serverid == serverId)
  106. {
  107. findSrv = srvInfo;
  108. break;
  109. }
  110. }
  111. if (findSrv != null)
  112. {
  113. ServerId = findSrv.serverid;
  114. Host = findSrv.serverhost;
  115. Port = findSrv.serverport;
  116. on_login();
  117. }
  118. else
  119. {
  120. MessageBox.Show("AppId : " + Config.Appid + @" 登录不存在服务器ID : " + serverId);
  121. }
  122. }
  123. else
  124. {
  125. if (on_error != null)
  126. {
  127. on_error(exception);
  128. }
  129. else
  130. {
  131. MessageBox.Show(exception.Message);
  132. }
  133. }
  134. });
  135. }
  136. public void register(Action on_login, Action<Exception> on_error = null)
  137. {
  138. Client.GateSocket.loginHandler.registerRequest(config.Appid, Account, s_robotPwd, 999 /*config.Channel*/, s_robotOS, s_robotModle, s_robotMac,
  139. config.ClientVersion, (PomeloException exception, RegisterResponse res) =>
  140. {
  141. if (res != null)
  142. {
  143. this.Sign = res.token;
  144. this.GetAreaServersAndStartGame(Account, on_login, on_error);
  145. // int serverId = Config.ServerID;
  146. // Sign = res.token;
  147. // dynamic server = getServer(res.board, serverId);
  148. // if (server != null)
  149. // {
  150. // ServerId = server.sid;
  151. // Host = server.ip;
  152. // Port = server.port;
  153. // on_login();
  154. // }
  155. // else
  156. // {
  157. // if (on_error != null)
  158. // {
  159. // log.Error("AppId : " + Config.Appid + @" 注册不存在服务器ID : " + serverId);
  160. // }
  161. // else
  162. // {
  163. // MessageBox.Show("AppId : " + Config.Appid + @" 注册不存在服务器ID : " + serverId);
  164. // }
  165. // }
  166. }
  167. else
  168. {
  169. if (on_error != null)
  170. {
  171. on_error(exception);
  172. }
  173. else
  174. {
  175. MessageBox.Show(exception.Message);
  176. }
  177. }
  178. });
  179. }
  180. public void gate_EnterServer(Action<EntryResponse> callback, Action<Exception> error = null)
  181. {
  182. string sign = this.Sign;
  183. ulong time = 0;
  184. string mac = config.MacAddr;
  185. int ostype = config.OSType;
  186. string region = config.ClientRegion;
  187. string channel = config.Channel.ToString();
  188. string version = config.ClientVersion;
  189. this.Client.LoginHandler.Request_EntryServerNew(Account, sign, time, ServerId, Host, Port, mac, ostype, region, channel, version, (EntryResponse msg) =>
  190. {
  191. this.LastEntryResponse = msg;
  192. callback(msg);
  193. }, (err) =>
  194. {
  195. log.Error(err.Message);
  196. if (error != null) error.Invoke(err);
  197. });
  198. }
  199. public void gate_ReEnterServer(Action<EntryResponse> callback, Action<Exception> error = null)
  200. {
  201. gate_EnterServer(callback, error);
  202. }
  203. public void gate_GetRandomName(int pro, Action<GetRandomNameResponse> callback, Action<Exception> error = null)
  204. {
  205. this.Client.LoginHandler.Request_RandomName(pro, (GetRandomNameResponse msg) =>
  206. {
  207. this.LastGetRandomNameResponse = msg;
  208. callback(msg);
  209. }, (err) =>
  210. {
  211. log.Error(err.Message, err);
  212. if (error != null) error.Invoke(err);
  213. });
  214. }
  215. public void gate_CreateRole(int pro, string name, Action<CreatePlayerResponse> callback, Action<Exception> error = null)
  216. {
  217. this.Client.LoginHandler.Request_CreateRole(pro, name, 0, (CreatePlayerResponse msg) =>
  218. {
  219. this.LastCreatePlayerResponse = msg;
  220. callback(msg);
  221. }, (err) =>
  222. {
  223. log.Error(err.Message, err);
  224. if (error != null) error.Invoke(err);
  225. });
  226. }
  227. public void gate_BindPlayer(string playerId, Action<BindPlayerResponse> callback, Action<Exception> error = null)
  228. {
  229. this.Client.LoginHandler.Request_BindPlayer(playerId, (BindPlayerResponse msg) =>
  230. {
  231. this.LastBindPlayerResponse = msg;
  232. this.PlayerData = msg.s2c_player;
  233. callback_gate_BindPlayer(msg);
  234. callback(msg);
  235. //成功进入场景标记
  236. this._IsInScene = true;
  237. }, (err) =>
  238. {
  239. log.Error(err.Message, err);
  240. if (error != null) error.Invoke(err);
  241. });
  242. }
  243. //---------------------------------------------------------------------------------------------------------------
  244. private void callback_gate_BindPlayer(BindPlayerResponse msg)
  245. {
  246. this.CurrentSceneType = (CommonAI.Data.SceneType)msg.s2c_sceneType;
  247. this.CurrentQuestManager = new QuestManager(this);
  248. this.CurrentInventories = new InventoryManager(this);
  249. //this.CurrentChatManager = new ChatManager(this);
  250. }
  251. //---------------------------------------------------------------------------------------------------------------
  252. }
  253. }