LoginServerModel.ts 1.1 KB

1234567891011121314151617181920212223242526272829
  1. import { eg } from "../frameWork/eg";
  2. import { GameServerConfig } from "../network/GameServerConfig";
  3. import { HttpClient as HttpClient_Browser, WsClient as WsClient_Browser } from 'tsrpc-browser';
  4. import { HttpClient as HttpClient_Miniapp, WsClient as WsClient_Miniapp } from 'tsrpc-miniapp';
  5. import { serviceProto as ServiceProtoRoom, ServiceType, ServiceType as ServiceTypeRoom } from "../shared/serviceProto";
  6. import IDataModel from "../frameWork/model/IDataModel";
  7. import UIHelp, { DialogParams } from "../logic/ui/UIHelp";
  8. /** 游戏服 */
  9. export class LoginServerModel extends IDataModel {
  10. /** 连接网关服务器 Http 客户端 */
  11. hcGate: HttpClient_Miniapp<ServiceTypeRoom> | HttpClient_Browser<ServiceTypeRoom> = null!;
  12. Init() {
  13. this.hcGate = eg.tspcNet.createLoginServer(GameServerConfig.LOGIN_SERVER);
  14. }
  15. /** 请求api */
  16. public async ReqApi<T extends string & keyof ServiceType['api']>(apiName: T, req: ServiceType['api'][T]['req']) {
  17. let ret = await this.hcGate.callApi(apiName, req);
  18. if (!ret.isSucc) {
  19. console.error(ret.err);
  20. }
  21. return ret;
  22. }
  23. }