using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Engine.Http;
public class HttpMsgCallBack : MonoBehaviour {
// Use this for initialization
private void Start () {
//Http消息响应
HttpManager.GetInstance().AddHttpMessageEvent(HandleHttpMessage);
}
/// Http消息响应
private bool HandleHttpMessage(HttpResponse res)
{
if (res == null)
{
return false;
}
if(!res.isSuccess)
{
//CDebug.Log("响应失败 " + httpResponse.ErrorString());
switch(res.ResponseStatu)
{
case -99999:
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ResponseMsg);
break;
case -8:
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_CODE_ERROR);//验证码错误的提示
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "请填写验证码激活账号");
break;
default:
if (res.Code != MsgConst.HTTP_MSG_AUTO_LOGIN)
{
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ErrorString());
}
else
{
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, res.ErrorString());
//重置登录
GamePlayerData.Instance.user_id = -1;
}
break;
}
return false;
}
CDebug.Log ("接受消息"+res.Code);
switch (res.Code)
{
//获取角色信息
case MsgConst.HTTP_MSG_LOGIN:
OnRefLogin(res);
break;
//当前的课程信息
case MsgConst.HTTP_MSG_GET_QUESTION:
OnRefGetQuestionData(res);
break;
case MsgConst.HTTP_MSG_AUTO_LOGIN:
OnRefLogin(res);
break;
default: break;
}
return false;
}
/// 登录返回
private void OnRefLogin(HttpResponse res)
{
int last_uid = GamePlayerData.Instance.user_id;
GamePlayerData.Instance.user_id = res.ReadInt("user_id");
GamePlayerData.Instance.school_id = res.ReadInt("school_id");
GamePlayerData.Instance.is_create = res.ReadBool("is_create");
GamePlayerData.Instance.school_name = res.ReadString("school_name");
GamePlayerData.Instance.user_name = res.ReadString("user_name");
GamePlayerData.Instance.user_type = res.ReadInt("user_type");
GamePlayerData.Instance.school_name = res.ReadString("school_name");
GamePlayerData.Instance.max_ct = res.ReadInt("MaxCt");
GetConfigData(res);
LitJson.JsonData has_Subject = res.ReadJsonData("has_Subject");
LitJson.JsonData has_Course = res.ReadJsonData("has_Course");
GameConfigData.Instance.course_data.InitHasSubJect(has_Subject);
GameConfigData.Instance.course_data.InitHasCourse(has_Course);
GamePlayerData.Instance.url_image_str = res.ReadString("image_root");
GamePlayerData.Instance.isDebugAccount = res.ReadBool("debug");
//GameCenterManager.Instance.mSocketMsgCenter.StartConnect();//启动Socket连接
/*
if (VoiceChat.Behaviour.VoiceChatSettings.Instance != null)
{
VoiceChat.Behaviour.VoiceChatSettings.Instance.Frequency = res.ReadInt("frequency");
VoiceChat.Behaviour.VoiceChatSettings.Instance.SampleSize = res.ReadInt("sampleSize");
VoiceChat.Behaviour.VoiceChatSettings.Instance.IsComb = res.ReadBool("isComb");
VoiceChat.Behaviour.VoiceChatSettings.Instance.Compression = (VoiceChat.Base.VoiceChatCompression)res.ReadInt("compression");
}
*/
//IvChatManager.Instance.InitConfig(httpResponse.ReadJsonData("Audio_Dict"));
//Socket服务器列表
//address
GameServerInfo.Instance.InitServerInfo();
// GameServerInfo.Instance.AddServer("全国", res.ReadString("master_address"), res.ReadInt("master_prot"), ServerType.Public);
GameServerInfo.Instance.AddServer(GamePlayerData.Instance.school_name, res.ReadString("sub_address"), res.ReadInt("sub_prot"), ServerType.Private);
}
//获取配置的
private void GetConfigData(HttpResponse res)
{
LitJson.JsonData Subject_list_jsonData = res.ReadJsonData("Subject_list");
GameConfigData.Instance.course_data.InitConfig(Subject_list_jsonData);
LitJson.JsonData Course_list_jsonData = res.ReadJsonData("Course_list");
GameConfigData.Instance.course_data.Init(Course_list_jsonData);
}
///获取题库信息
private void OnRefGetQuestionData(HttpResponse res)
{
GamePlayerData.Instance.eData = new ExperimentData();
GamePlayerData.Instance.eData.MRAssetName = "MR_Game";
LitJson.JsonData questionBasicList_jsonData = res.ReadJsonData("questionBasicList");
LitJson.JsonData questionList_jsonData = res.ReadJsonData("questionList");
LitJson.JsonData question_jsonData = res.ReadJsonData("question");
//GamePlayerData.Instance.eData.InitQuestionBank(questionBasicList_jsonData, questionList_jsonData);
GamePlayerData.Instance.eData.InitQuestionBank(question_jsonData);
GamePlayerData.Instance.eData.InitCourseDesc(res.ReadString("course_desc"));
GamePlayerData.Instance.eData.InitCourseMRDesc(res.ReadString("course_mr_desc"));
GamePlayerData.Instance.eData.InitCourseResult(res.ReadString("course_summary"));
GamePlayerData.Instance.eData.InitChapterItemConfig(res.ReadJsonData("chapterList"));
//需要在题库初始化完成后再
StudentTaskReceiveManager.Instance.InitManager();
//MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_ENTER_COURSE);
MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_HTTP_COURSE_DATA_BACK);
}
}