HttpMsgCallBack.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1.  using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Engine.Http;
  5. public class HttpMsgCallBack : MonoBehaviour {
  6. // Use this for initialization
  7. private void Start () {
  8. //Http消息响应
  9. HttpManager.GetInstance().AddHttpMessageEvent(HandleHttpMessage);
  10. }
  11. /// <summary>Http消息响应</summary>
  12. private bool HandleHttpMessage(HttpResponse res)
  13. {
  14. if (res == null)
  15. {
  16. return false;
  17. }
  18. if(!res.isSuccess)
  19. {
  20. //CDebug.Log("响应失败 " + httpResponse.ErrorString());
  21. switch(res.ResponseStatu)
  22. {
  23. case -99999:
  24. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ResponseMsg);
  25. break;
  26. case -8:
  27. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_CODE_ERROR);//验证码错误的提示
  28. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "请填写验证码激活账号");
  29. break;
  30. default:
  31. if (res.Code != MsgConst.HTTP_MSG_AUTO_LOGIN)
  32. {
  33. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ErrorString());
  34. }
  35. else
  36. {
  37. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ErrorString());
  38. //重置登录
  39. GamePlayerData.Instance.user_id = -1;
  40. }
  41. break;
  42. }
  43. return false;
  44. }
  45. switch (res.Code)
  46. {
  47. //获取角色信息
  48. case MsgConst.HTTP_MSG_LOGIN:
  49. OnRefLogin(res);
  50. break;
  51. //当前的课程信息
  52. case MsgConst.HTTP_MSG_GET_QUESTION:
  53. OnRefGetQuestionData(res);
  54. break;
  55. case MsgConst.HTTP_MSG_AUTO_LOGIN:
  56. OnRefLogin(res);
  57. break;
  58. default: break;
  59. }
  60. return false;
  61. }
  62. /// <summary>登录返回</summary>
  63. private void OnRefLogin(HttpResponse res)
  64. {
  65. int last_uid = GamePlayerData.Instance.user_id;
  66. GamePlayerData.Instance.user_id = res.ReadInt("user_id");
  67. GamePlayerData.Instance.school_id = res.ReadInt("school_id");
  68. GamePlayerData.Instance.is_create = res.ReadBool("is_create");
  69. GamePlayerData.Instance.school_name = res.ReadString("school_name");
  70. GamePlayerData.Instance.user_name = res.ReadString("user_name");
  71. GamePlayerData.Instance.user_type = res.ReadInt("user_type");
  72. GamePlayerData.Instance.school_name = res.ReadString("school_name");
  73. GamePlayerData.Instance.max_ct = res.ReadInt("MaxCt");
  74. GetConfigData(res);
  75. LitJson.JsonData has_Subject = res.ReadJsonData("has_Subject");
  76. LitJson.JsonData has_Course = res.ReadJsonData("has_Course");
  77. GameConfigData.Instance.course_data.InitHasSubJect(has_Subject);
  78. GameConfigData.Instance.course_data.InitHasCourse(has_Course);
  79. GamePlayerData.Instance.url_image_str = res.ReadString("image_root");
  80. GamePlayerData.Instance.isDebugAccount = res.ReadBool("debug");
  81. //GameCenterManager.Instance.mSocketMsgCenter.StartConnect();//启动Socket连接
  82. /*
  83. if (VoiceChat.Behaviour.VoiceChatSettings.Instance != null)
  84. {
  85. VoiceChat.Behaviour.VoiceChatSettings.Instance.Frequency = res.ReadInt("frequency");
  86. VoiceChat.Behaviour.VoiceChatSettings.Instance.SampleSize = res.ReadInt("sampleSize");
  87. VoiceChat.Behaviour.VoiceChatSettings.Instance.IsComb = res.ReadBool("isComb");
  88. VoiceChat.Behaviour.VoiceChatSettings.Instance.Compression = (VoiceChat.Base.VoiceChatCompression)res.ReadInt("compression");
  89. }
  90. */
  91. //IvChatManager.Instance.InitConfig(httpResponse.ReadJsonData("Audio_Dict"));
  92. //Socket服务器列表
  93. //address
  94. GameServerInfo.Instance.InitServerInfo();
  95. // GameServerInfo.Instance.AddServer("全国", res.ReadString("master_address"), res.ReadInt("master_prot"), ServerType.Public);
  96. GameServerInfo.Instance.AddServer(GamePlayerData.Instance.school_name, res.ReadString("sub_address"), res.ReadInt("sub_prot"), ServerType.Private);
  97. }
  98. //获取配置的
  99. private void GetConfigData(HttpResponse res)
  100. {
  101. LitJson.JsonData Subject_list_jsonData = res.ReadJsonData("Subject_list");
  102. GameConfigData.Instance.course_data.InitConfig(Subject_list_jsonData);
  103. LitJson.JsonData Course_list_jsonData = res.ReadJsonData("Course_list");
  104. GameConfigData.Instance.course_data.Init(Course_list_jsonData);
  105. }
  106. ///<summary>获取题库信息</summary>
  107. private void OnRefGetQuestionData(HttpResponse res)
  108. {
  109. GamePlayerData.Instance.eData = new ExperimentData();
  110. GamePlayerData.Instance.eData.MRAssetName = "MR_Game";
  111. LitJson.JsonData questionBasicList_jsonData = res.ReadJsonData("questionBasicList");
  112. LitJson.JsonData questionList_jsonData = res.ReadJsonData("questionList");
  113. LitJson.JsonData question_jsonData = res.ReadJsonData("question");
  114. //GamePlayerData.Instance.eData.InitQuestionBank(questionBasicList_jsonData, questionList_jsonData);
  115. GamePlayerData.Instance.eData.InitQuestionBank(question_jsonData);
  116. GamePlayerData.Instance.eData.InitCourseDesc(res.ReadString("course_desc"));
  117. GamePlayerData.Instance.eData.InitCourseMRDesc(res.ReadString("course_mr_desc"));
  118. GamePlayerData.Instance.eData.InitCourseResult(res.ReadString("course_summary"));
  119. GamePlayerData.Instance.eData.InitChapterItemConfig(res.ReadJsonData("chapterList"));
  120. //需要在题库初始化完成后再
  121. StudentTaskReceiveManager.Instance.InitManager();
  122. //MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_ENTER_COURSE);
  123. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK);
  124. }
  125. }