HttpMsgCallBack.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. CDebug.Log ("接受消息"+res.Code);
  46. switch (res.Code)
  47. {
  48. //获取角色信息
  49. case MsgConst.HTTP_MSG_LOGIN:
  50. OnRefLogin(res);
  51. break;
  52. //当前的课程信息
  53. case MsgConst.HTTP_MSG_GET_QUESTION:
  54. OnRefGetQuestionData(res);
  55. break;
  56. case MsgConst.HTTP_MSG_AUTO_LOGIN:
  57. OnRefLogin(res);
  58. break;
  59. default: break;
  60. }
  61. return false;
  62. }
  63. /// <summary>登录返回</summary>
  64. private void OnRefLogin(HttpResponse res)
  65. {
  66. int last_uid = GamePlayerData.Instance.user_id;
  67. GamePlayerData.Instance.user_id = res.ReadInt("user_id");
  68. GamePlayerData.Instance.school_id = res.ReadInt("school_id");
  69. GamePlayerData.Instance.is_create = res.ReadBool("is_create");
  70. GamePlayerData.Instance.school_name = res.ReadString("school_name");
  71. GamePlayerData.Instance.user_name = res.ReadString("user_name");
  72. GamePlayerData.Instance.user_type = res.ReadInt("user_type");
  73. GamePlayerData.Instance.school_name = res.ReadString("school_name");
  74. GamePlayerData.Instance.max_ct = res.ReadInt("MaxCt");
  75. GetConfigData(res);
  76. LitJson.JsonData has_Subject = res.ReadJsonData("has_Subject");
  77. LitJson.JsonData has_Course = res.ReadJsonData("has_Course");
  78. GameConfigData.Instance.course_data.InitHasSubJect(has_Subject);
  79. GameConfigData.Instance.course_data.InitHasCourse(has_Course);
  80. GamePlayerData.Instance.url_image_str = res.ReadString("image_root");
  81. GamePlayerData.Instance.isDebugAccount = res.ReadBool("debug");
  82. //GameCenterManager.Instance.mSocketMsgCenter.StartConnect();//启动Socket连接
  83. /*
  84. if (VoiceChat.Behaviour.VoiceChatSettings.Instance != null)
  85. {
  86. VoiceChat.Behaviour.VoiceChatSettings.Instance.Frequency = res.ReadInt("frequency");
  87. VoiceChat.Behaviour.VoiceChatSettings.Instance.SampleSize = res.ReadInt("sampleSize");
  88. VoiceChat.Behaviour.VoiceChatSettings.Instance.IsComb = res.ReadBool("isComb");
  89. VoiceChat.Behaviour.VoiceChatSettings.Instance.Compression = (VoiceChat.Base.VoiceChatCompression)res.ReadInt("compression");
  90. }
  91. */
  92. //IvChatManager.Instance.InitConfig(httpResponse.ReadJsonData("Audio_Dict"));
  93. //Socket服务器列表
  94. //address
  95. GameServerInfo.Instance.InitServerInfo();
  96. // GameServerInfo.Instance.AddServer("全国", res.ReadString("master_address"), res.ReadInt("master_prot"), ServerType.Public);
  97. GameServerInfo.Instance.AddServer(GamePlayerData.Instance.school_name, res.ReadString("sub_address"), res.ReadInt("sub_prot"), ServerType.Private);
  98. }
  99. //获取配置的
  100. private void GetConfigData(HttpResponse res)
  101. {
  102. LitJson.JsonData Subject_list_jsonData = res.ReadJsonData("Subject_list");
  103. GameConfigData.Instance.course_data.InitConfig(Subject_list_jsonData);
  104. LitJson.JsonData Course_list_jsonData = res.ReadJsonData("Course_list");
  105. GameConfigData.Instance.course_data.Init(Course_list_jsonData);
  106. }
  107. ///<summary>获取题库信息</summary>
  108. private void OnRefGetQuestionData(HttpResponse res)
  109. {
  110. GamePlayerData.Instance.eData = new ExperimentData();
  111. GamePlayerData.Instance.eData.MRAssetName = "MR_Game";
  112. LitJson.JsonData questionBasicList_jsonData = res.ReadJsonData("questionBasicList");
  113. LitJson.JsonData questionList_jsonData = res.ReadJsonData("questionList");
  114. LitJson.JsonData question_jsonData = res.ReadJsonData("question");
  115. //GamePlayerData.Instance.eData.InitQuestionBank(questionBasicList_jsonData, questionList_jsonData);
  116. GamePlayerData.Instance.eData.InitQuestionBank(question_jsonData);
  117. GamePlayerData.Instance.eData.InitCourseDesc(res.ReadString("course_desc"));
  118. GamePlayerData.Instance.eData.InitCourseMRDesc(res.ReadString("course_mr_desc"));
  119. GamePlayerData.Instance.eData.InitCourseResult(res.ReadString("course_summary"));
  120. GamePlayerData.Instance.eData.InitChapterItemConfig(res.ReadJsonData("chapterList"));
  121. //需要在题库初始化完成后再
  122. StudentTaskReceiveManager.Instance.InitManager();
  123. //MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_ENTER_COURSE);
  124. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK);
  125. }
  126. }