_gLinkArr = new Array(); function getFreeSocketID() { //输入参数名称 var res = 0; for(var i in _gLinkArr){ if(i == res) res++; } return res; } CSocketMission = cc.Class({ ctor:function () { this.m_MaxPortIndex = 3; }, init:function (url,port){ this.mSocketEngine = new cc.CSocketEngine(this); this.mUrl = url; this.mPort = port; this.mPortIndex = 0; }, start:function () { if (this.isAlive()){ this.onEventTCPSocketLink(); }else{ this.mSocketEngine.connect(this.mUrl, this.mPort+this.mPortIndex); } }, OnErr:function(){ this.mPortIndex++; if(window.LOG_NET_DATA)console.log("正在重新分配服务器 "+ this.mPortIndex); if(this.mPortIndex < this.m_MaxPortIndex){ this.start(); }else{ this.mPortIndex = 0; if(window.LOG_NET_DATA)console.log("连接失败!"); this.onEventLinkErr(); } }, stop:function () { this.mSocketEngine.disconnect(); }, isAlive:function () { return this.mSocketEngine.isAlive(); }, send:function (main,sub,data,size) { return this.mSocketEngine.send(main, sub, data, size); } }); CGPLoginMission = cc.Class({ extends: CSocketMission, ctor :function () { //设置回调接口 this.mIGPLoginMissionSink = arguments[0]; this.init(window.SOCKET_IP, LOGIN_SERVER_PORT); this.SendData(arguments[1],arguments[2],arguments[3],arguments[4]); }, SendData:function(wMain,wSub,DataStr,Length){ console.log("SendData发送 ",wMain,wSub) this.m_wMain = wMain; this.m_wSub = wSub; this.m_DataStr = DataStr; this.m_Length = Length; this.start(); }, onEventTCPSocketLink:function (event){ var cbData = gCByte.Str2Bytes(this.m_DataStr); if(this.m_Length==null) this.m_Length = cbData.length; this.send(this.m_wMain, this.m_wSub, cbData, this.m_Length); return true; }, onEventLinkErr:function (){ if (this.mIGPLoginMissionSink){ this.mIGPLoginMissionSink.OnEventLinkErr(); } return true; }, onEventTCPSocketShut :function(){ // if (this.mIGPLoginMissionSink){ // this.mIGPLoginMissionSink.StopLoading(); // } }, onEventTCPSocketRead :function(main,sub,data,size) { console.log("onEventTCPSocketRead "+main,sub) try { switch (main) { //登录消息 case MDM_GP_LOGON: return this.onSocketMainLogon(sub, data, size); //列表信息 case MDM_GP_SERVER_LIST: return this.onSocketMainServerList(sub, data, size); //用户服务 case MDM_GP_USER_SERVICE: return this.onSocketUserService(sub, data, size); case MDM_GP_USER: return ;//this.onSocketUserServer(sub, data, size); case MDM_GP_GET_SERVER: return this.onSocketQueryServer(sub, data, size); default: break; } if(window.LOG_NET_DATA)console.log("ERROR LoginMission:not case main!"); } catch (error) { if(window.LOG_NET_DATA)console.log("ERROR LoginMission:onEventTCPSocketRead !"); } return true; }, ////////////////////////////////////////////////////////////////////////// //登陆信息 onSocketMainLogon :function(sub, data, size){ switch (sub) { //登录成功 case SUB_GP_LOGON_SUCCESS: return this.onSocketSubLogonSuccess(data, size); //登录失败 case SUB_GP_LOGON_FAILURE: return this.onSocketSubLogonFailure(data, size); //升级提示 case SUB_GP_UPDATE_NOTIFY: return this.onSocketSubUpdateNotify(data, size); //登录完成 case SUB_GP_LOGON_FINISH: return this.onSocketSubLogonFinish(data, size); //俱乐部信息 case SBU_GP_CLUB_SERVER_INFO: return this.onSocketSubClubServerInfor(data, size); /*case SUB_GP_GROWLEVEL_CONFIG: case SUB_GP_VERIFY_CODE_RESULT: case SUB_GP_REAL_AUTH_CONFIG: */ default: //if(window.LOG_NET_DATA)console.log("onSocketMainLogon 未处理消息 "+sub) return true; } return false; }, //登录失败 onSocketSubLogonFailure :function (data,size){ var LogonError = new CMD_GP_LogonError(); gCByte.Bytes2Str(LogonError,data); //显示消息 if (this.mIGPLoginMissionSink) this.mIGPLoginMissionSink.onGPLoginFailure(LogonError.szErrorDescribe); //关闭处理 this.stop(); return true; }, //登录成功 onSocketSubLogonSuccess:function (data,dataSize){ //消息处理 var pLogonSuccess = new CMD_GP_LogonSuccess(); //效验数据 if (dataSize gCByte.Bytes2Str(Res, data)) return false; this.mIGPLoginMissionSink.OnBindSpreaderRes(Res.lResultCode, Res.szDescribeString); //关闭处理 this.stop(); return true; }, onSocketQueryFailed :function(data, size){ var Res = new CMD_GP_S_Failed(); if(size != gCByte.Bytes2Str(Res, data)) return false; this.stop(); this.mIGPLoginMissionSink.OnQueryFailed(Res); return true; }, onSocketQueryRes:function(data, size){ var Res = new CMD_GP_S_ReturnServer(); if(size != gCByte.Bytes2Str(Res, data)) return false; console.log("返回CMD_GP_S_ReturnServer",Res) this.stop(); this.mIGPLoginMissionSink.OnQueryServerRes(Res); return true; }, onSocketJoinRoomRes:function(data, size){ var Res = new CMD_GP_S_ReturnRoom(); if(size != gCByte.Bytes2Str(Res, data)) return false; this.stop(); this.mIGPLoginMissionSink.OnQueryRoomRes(Res); return true; }, onSocketCreatRoomRes:function(data, size){ var Res = new CMD_GP_S_CreatSuccess(); if(size != gCByte.Bytes2Str(Res, data)) return false; this.stop(); this.mIGPLoginMissionSink.OnCreatRoomRes(Res); return true; }, onSocketJoinRoomRes_G:function(data, size){ console.log("加入房间G 返回") var Res = new CMD_GP_S_CreatSuccess(); if(size != gCByte.Bytes2Str(Res, data)) return false; this.stop(); this.mIGPLoginMissionSink.OnCreatRoomRes(Res); return true; }, onSocketClubRevenueInfo:function(data, size){ var Res = new CMD_GP_S_ClubRevenueInfo(); gCByte.Bytes2Str(Res, data); this.mIGPLoginMissionSink.OnClubRevenueInfo(Res); return true; }, onSocketUpdateClubRoom:function(data, size){ var Res = new CMD_GP_S_ClubRoomInfo(); gCByte.Bytes2Str(Res, data); if(Res.wRoomCnt > 0){ Res.RoomInfo = new Array(); for(var i = 0;i 0){ Res.RoomInfo=new Array(); for(var i=0;i