QDTapTapManager.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using ET;
  2. using TapTap.Bootstrap;
  3. using TapTap.Common;
  4. using TapTap.TapDB;
  5. using Plugins.AntiAddictionUIKit;
  6. using System;
  7. using System.Threading.Tasks;
  8. namespace GFGGame
  9. {
  10. public class QDTapTapManager : SingletonBase<QDTapTapManager>
  11. {
  12. private readonly string ClientID = "K7bDyPGYlVx2AAtk6q";
  13. public void InitSDK()
  14. {
  15. Log.Debug($"tap InitSDK");
  16. if (!QDManager.IsTaptap)
  17. {
  18. return;
  19. }
  20. var config = new TapConfig.Builder()
  21. .ClientID(ClientID)
  22. .ClientToken("fjwWBtibB4Dj3UjyRQxK2tZ3f8fGNgg14tcRW38D")
  23. .ServerURL("https://k7bdypgy.cloud.tds1.tapapis.cn")
  24. .RegionType(RegionType.CN)
  25. .TapDBConfig(true, "tap", null, true)
  26. .ConfigBuilder();
  27. TapBootstrap.Init(config);
  28. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_INITED, true);
  29. }
  30. public async Task<bool> Login()
  31. {
  32. Log.Debug($"tap login");
  33. if (!QDManager.IsTaptap)
  34. {
  35. return false;
  36. }
  37. ViewManager.Show<ModalStatusView>("登录中...");
  38. TDSUser tdsUser = await TDSUser.GetCurrent();
  39. if (null != tdsUser)
  40. {
  41. InitAntiAddiction(tdsUser.ObjectId);
  42. return true;
  43. }
  44. try
  45. {
  46. tdsUser = await TDSUser.LoginWithTapTap();
  47. Log.Debug($"tap login Success:{tdsUser}");
  48. InitAntiAddiction(tdsUser.ObjectId);
  49. return true;
  50. }
  51. catch (Exception e)
  52. {
  53. if (e is TapException tapError)
  54. {
  55. if (tapError.code == (int)TapErrorCode.ERROR_CODE_BIND_CANCEL) // 取消登录
  56. {
  57. Log.Debug("登录取消");
  58. }
  59. else
  60. {
  61. Log.Error($"Login Error:{tapError.code} message:{tapError.message}");
  62. PromptController.Instance.ShowFloatTextPrompt(tapError.message);
  63. }
  64. }
  65. else
  66. {
  67. Log.Error($"Login Error:{e}");
  68. PromptController.Instance.ShowFloatTextPrompt("登录异常");
  69. }
  70. }
  71. ViewManager.Hide<ModalStatusView>();
  72. return false;
  73. }
  74. public void InitAntiAddiction(string objectId)
  75. {
  76. Log.Debug($"tap InitAntiAddiction objectId {objectId}");
  77. string gameIdentifier = ClientID;
  78. // 是否启用时长限制功能
  79. bool useTimeLimit = true;
  80. // 是否启用消费限制功能
  81. bool usePaymentLimit = false;
  82. // 是否显示切换账号按钮
  83. bool showSwitchAccount = true;
  84. AntiAddictionUIKit.Init(gameIdentifier, useTimeLimit, usePaymentLimit, showSwitchAccount,
  85. (antiAddictionCallbackData) =>
  86. {
  87. int code = antiAddictionCallbackData.code;
  88. MsgExtraParams extras = antiAddictionCallbackData.extras;
  89. Log.Debug($"tap antiAddictionCallbackData code {code} extras title \n{extras?.title} description \n{extras?.description}");
  90. // 根据 code 不同提示玩家不同信息,详见下面的说明
  91. if (code == 500)
  92. {
  93. ET.Log.Debug("玩家登录后判断当前玩家可以进行游戏");
  94. // 开始计时
  95. AntiAddictionUIKit.EnterGame();
  96. EventAgent.DispatchEvent(ConstMessage.ON_PLATFORM_SDK_LOGINED, objectId);
  97. }
  98. else if(code == 1030)
  99. {
  100. ET.Log.Debug("未成年玩家当前无法进行游戏");
  101. }
  102. else if (code == 1095)
  103. {
  104. ET.Log.Debug("未成年允许游戏弹窗");
  105. }
  106. else if (code == 1000)
  107. {
  108. ET.Log.Debug("退出账号");
  109. }
  110. else if (code == 9002)
  111. {
  112. ET.Log.Debug("实名过程中点击了关闭实名窗");
  113. AntiAddictionUIKit.Startup(true, objectId);
  114. }
  115. else if (code == 1001)
  116. {
  117. ET.Log.Debug("点击切换账号按钮(v1.0.2 新增)");
  118. GameController.QuitToLoginView(true);
  119. }
  120. },
  121. (exception) =>
  122. {
  123. // 处理异常
  124. Log.Debug($"tap exception {exception.ToString()}");
  125. }
  126. );
  127. AntiAddictionUIKit.Startup(true, objectId);
  128. }
  129. public void OnEnterGame()
  130. {
  131. Log.Debug($"tap OnEnterGame");
  132. if (!QDManager.IsTaptap)
  133. {
  134. return;
  135. }
  136. var serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  137. var accountInfoComponent = GameGlobal.zoneScene.GetComponent<AccountInfoComponent>();
  138. var roleInfosComponent = GameGlobal.zoneScene.GetComponent<RoleInfosComponent>();
  139. var currentRole = roleInfosComponent.GetCurrentRole();
  140. TapDB.SetUser(accountInfoComponent.Account);
  141. TapDB.SetName(currentRole.Name);
  142. TapDB.SetLevel(RoleDataManager.lvl);
  143. TapDB.SetServer(serverInfosComponent.GetCurrentServerInfo().ServerName);
  144. Log.Debug($"tap TapDB \nSetUser {accountInfoComponent.Account} \nSetName {currentRole.Name} \nSetLevel {RoleDataManager.lvl} \nSetServer {serverInfosComponent.GetCurrentServerInfo().ServerName}");
  145. }
  146. public void OnQuitToLoginView()
  147. {
  148. Log.Debug($"tap OnQuitGame");
  149. if (!QDManager.IsTaptap)
  150. {
  151. return;
  152. }
  153. TapDB.ClearUser();
  154. AntiAddictionUIKit.LeaveGame();
  155. AntiAddictionUIKit.Logout();
  156. }
  157. }
  158. }