var Net = Net||{}; Net.tcp = {}; Net.tcp.isConnected = false;//已有连接连上 Net.tcp.tcpIDAva = 1;//用过的ID的最大值 Net.tcp.tcpIDList = [];//TCP ID列表 Net.tcp.connectCount = 3;//同时最多连接个数 Net.tcp.connectList = [];//tcp连接对象池 Net.tcp.connect = function(_id,ws){ } Net.ws_tcp; Net._SendData = function(_app,_route,_rpc,_data){ var _msg = {}; _msg.app = _app, _msg.route = _route; _msg.rpc = _rpc; _msg.data = _data; if(ConstVal.netType == 0){ Net.ws_tcp.send(JSON.stringify(_msg)); }else{ Func.AjaxHttp2(GameData.Server,JSON.stringify(_msg), function(cbData){ console.log(cbData); },function(){ GameUI.OpenTips("网络状况不好"); }); } if(Game_Config.Debugger.isDebugger){ console.log("发送数据:"+JSON.stringify(_msg)); } } Net.submit_error = function(_packet,_msg){ //提交错误 if(GameData.errorMsg != _msg){ GameData.errorMsg = _msg; }else { return; } var msg = { app:"youle", route:"agent", rpc:"submit_error", data:{ packet:_packet, msg:_msg, playerid:C_Player.playerid, agentid:GameData.AgentId, gameid:GameData.GameId, } } try{ Net.ws_tcp.send(JSON.stringify(msg)); }catch(e){ } } Net.submit_log = function(_packet,_msg){ var msg = { app:"youle", route:"agent", rpc:"submit_error", data:{ packet:_packet, msg:_msg, playerid:C_Player.playerid, agentid:GameData.AgentId, gameid:GameData.GameId } } console.log(_packet); console.log(_msg); try{ Net.ws_tcp.send(JSON.stringify(msg)); }catch(e){ } } //发送创建房间 Net.Send_create_room = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.create_room,_data); } //接收创建房间 Net.create_room = function(_msg){ //Logic.CreateRoom(_msg.data); Desk.create_room(_msg); GameUI.EndLoad(); Game_Modify.createRoom(_msg.roomtype,_msg.data.infinite); if(Game_Modify.onCreateRoom){ Game_Modify.onCreateRoom(_msg.data); } } //发送登录请求 Net.Send_login = function(_data){ //console.log(returnCitySN); if(typeof returnCitySN != "undefined"){ _data.ip = returnCitySN.cip; } _data.machineid = Logic.getMachineId(); _data.machineroom = Utl.getRoomcode(); //alert("进入Net.Send_login方法"); GameUI.StartLoad(); var _playerid = Logic.readPlayerId(); if(_playerid){ _data.playerid = _playerid; } GameData.loginList.push(GameData.TcpID); GameData.isSendLoginState = true; GameData.sendLoginTimes++; if(GameData.sendLoginTimer == null){ GameData.isSendLoginTimer = setTimeout(function(){ GameData.ConnectType = false; GameData.disType = true; GameData.NetType=1; GameUI.StartLoad(); GameData.isClose = true; Net.ws_tcp.close(); GameData.isCloseTimer = setInterval(function(){ if(GameData.isClose){ Net.ws_tcp.close(); } },5000); },4000); } if(GameData.sendLoginTimes>=2){ if(GameData.isSendLoginTimer){ window.clearTimeout(GameData.isSendLoginTimer); GameData.isSendLoginTimer = null; } if(GameData.isClose){ GameData.isClose = false; window.clearTimeout(GameData.isCloseTimer); } if(GameData.sendLoginTimer){ window.clearTimeout(GameData.sendLoginTimer); GameData.sendLoginTimer = null; } GameUI.EndLoad(); GameUI.OpenKick("网络繁忙,请退出游戏,稍后登录! "); } Net._SendData(AppList.app,RouteList.agent,RpcList.player_login,_data); } //接收登录 Net.player_login = function(_msg){ GameUI.EndLoad(); Desk.login(_msg); } //发送玩家自己进入房间请求 Net.Send_self_join_room = function(_data){ GameUI.StartLoad(); GameData.shortCode = _data.roomcode; this._SendData(AppList.app,RouteList.agent,RpcList.self_join_room,_data); } //接收玩家自己进入房间请求 Net.self_join_room = function(_msg){ Desk.self_join_room(_msg); GameUI.EndLoad(); } //发送未开局之前房主自己解散房间 Net.Send_self_break_room = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.self_break_room,_data); } //接收未开局之前房主自己解散房间 Net.self_break_room = function(_msg){ Desk.self_break_room(_msg); GameUI.EndLoad(); } //接收未开局之前他人房主解散房间 Net.other_break_room = function(_msg){ Desk.other_break_room(_msg); } //接收其他玩家加入房间 Net.other_join_room = function(_msg){ Desk.other_join_room(_msg); GameUI.EndLoad(); } //发送未开局之前自己退出房间 Net.Send_self_exit_room = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.self_exit_room,_data); } //接收未开局之前自己退出房间 Net.self_exit_room = function(_msg){ GameUI.closeCheck(); Desk.self_exit_room(_msg); GameUI.EndLoad(); } //接收未开局之前其他玩家退出房间 Net.other_exit_room = function(_msg){ Desk.other_exit_room(_msg); } //发送开局之后自己申请解散房间 Net.Send_self_apply_free_room = function(_data){ //GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.self_apply_free_room,_data); } //接收开局之后自己申请解散房间 Net.self_apply_free_room = function(_msg){ Desk.self_apply_free_room(_msg); GameUI.EndLoad(); } //接收开局之后其他玩家申请解散房间 Net.other_apply_free_room = function(_msg){ Desk.other_apply_free_room(_msg); } //发送自己同意解散房间 Net.Send_self_agree_free_room = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.self_agree_free_room,_data); } //接收自己同意解散房间 Net.self_agree_free_room = function(_msg){ Desk.self_agree_free_room(_msg); GameUI.EndLoad(); } //接收其他玩家同意解散房间 Net.other_agree_free_room = function(_msg){ Desk.other_agree_free_room(_msg); GameUI.EndLoad(); } //发送自己拒绝解散房间 Net.Send_self_refuse_free_room = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.self_refuse_free_room,_data); } //接收自己拒绝解散房间 Net.self_refuse_free_room = function(_msg){ Desk.self_refuse_free_room(_msg); GameUI.EndLoad(); } //接收其他玩家拒绝解散房间 Net.other_refuse_free_room = function(_msg){ Desk.other_refuse_free_room(_msg); GameUI.EndLoad(); } //接收解散房间 Net.free_room = function(_msg){ Desk.free_room(_msg); GameUI.EndLoad(); } //发送获取战绩 Net.Send_get_player_grade1 = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_player_grade1,_data); } //接收获取战绩 Net.get_player_grade1 = function(_msg){ Game_Modify.get_player_grade1(_msg); GameUI.EndLoad(); //Logic.SetCombatInfo(_msg.data); //GameUI.OpenCombat(); } //发送获取战绩2 Net.Send_get_player_grade2 = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_player_grade2,_data); } //接收获取战绩2 Net.get_player_grade2 = function(_msg){ Game_Modify.get_player_grade2(_msg); GameUI.EndLoad(); } //接收修改房卡 Net.update_roomcard = function(_msg){ C_Player.UpdateRoomcard(_msg); } //接收其他玩家离线 Net.other_offline = function(_msg){ Desk.other_offline(_msg); } //接收其他玩家上线 Net.other_online = function(_msg){ Desk.other_online(_msg); } //发送发送聊天消息 Net.Send_send_text = function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.send_text,_data); } //接收发送聊天消息 Net.send_text = function(_msg){ Desk.send_text(_msg); } //发送获取任务列表 Net.Send_get_player_task = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_player_task,_data); } //接收获取任务列表 Net.get_player_task = function(_msg){ Desk.get_player_task(_msg); //GameUI.SetTaskInfo(_msg); GameUI.EndLoad(); } //发送完成任务 Net.Send_player_finish_task = function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.player_finish_task,_data); } //接收完成任务 Net.player_finish_task = function(_msg){ C_Player.player_finish_task(_msg); } //发送领取任务奖励 Net.Send_get_task_award = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_task_award,_data); } //接收领取任务奖励 Net.get_task_award = function(_msg){ C_Player.get_task_award(_msg); GameUI.EndLoad(); } //发送有任务可领取 Net.Send_can_award = function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.refresh_task_state,_data); } //接收有任务可领取 Net.can_award = function(_msg){ C_Player.can_award(_msg); } //接收踢下线 Net.kick_offline = function(_msg){ Desk.kick_offline(_msg); } //发送自己打电话 Net.Send_call_phone = function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.call_phone,_data); } //接收自己打电话 Net.call_phone = function(_msg){ Desk.call_phone(_msg); } //发送自己挂断电话 Net.Send_hangup_phone = function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.hangup_phone,_data); } //接自己收挂断打电话 Net.hangup_phone = function(_msg){ Desk.hangup_phone(_msg); } //发送房主开局 Net.Send_self_makewar = function(_data){ //GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.self_makewar,_data); } //接收房主开局 Net.self_makewar = function(_msg){ Desk.self_makewar(_msg); //GameUI.EndLoad(); } //接收房主开局 Net.other_makewar = function(_msg){ Desk.makewar(_msg); } //自己发送互动 Net.Send_send_gift=function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.send_gift,_data); } Net.send_gift=function(_msg){ Desk.send_gift(_msg); } //自己发送语音 Net.Send_send_voice=function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.send_voice,_data); } Net.send_voice=function(_msg){ Desk.send_voice(_msg); } //发送切换至房间服务器 Net.Send_connect_roomserver=function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.connect_roomserver,_data); } Net.connect_roomserver=function(_msg){ GameData.ConnectType=true; GameData.disType =false; GameData.ConnectPack = _msg.data; GameData.ConnectRpc = RpcList.connect_roomserver; GameData.Server=_msg.data.roomserver; //Logic.Connect(); Net.ws_tcp.close(); } //发送切换至大厅服务器 Net.Send_connect_agentserver=function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.connect_agentserver,_data); } Net.connect_agentserver=function(_msg){ if(_msg.data.opt == RpcList.other_break_room || _msg.data.opt == RpcList.free_room){ GameUI.StartLoad(); } GameData.ConnectType=true; GameData.disType =false; GameData.ConnectRpc = RpcList.connect_agentserver; GameData.ConnectPack = _msg.data; GameData.Server=_msg.data.agentserver; //Logic.Connect(); Net.ws_tcp.close(); } Net.Send_broadcast=function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.broadcast,_data); } //接收即时信息 Net.broadcast=function(_msg){ // Desk.broadcast(_msg); } //发送互动 Net.Send_send_phiz=function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.send_phiz,_data); } //接收互动 Net.send_phiz=function(_msg){ Desk.send_phiz(_msg); } //提交反馈 Net.Send_submit_opinion=function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.submit_opinion,_data); } //接收反馈 Net.submit_opinion=function(_msg){ Desk.submit_opinion(_msg); } //踢出玩家 Net.Send_kick_server=function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.kick_server,_data); } Net.kick_server=function(_msg){ Desk.kick_server(_msg); } //获取支付列表 Net.Send_get_paylist=function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_paylist,_data); } //接收支付列表 Net.get_paylist=function(_msg){ GameData.payList = _msg.data.paylist; GameUI.OpenPay(); GameUI.EndLoad(); } //支付成功后通知服务器 Net.Send_pay_succ=function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.pay_succ,_data); } //提交位置信息 Net.Send_submit_location=function(_data){ this._SendData(AppList.app,RouteList.agent,RpcList.submit_location,_data); } //提交位置信息 Net.submit_location=function(_msg){ Game.submit_location(_msg); } //发送绑定 Net.Send_binding_invitecode=function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.binding_invitecode,_data); } //接收绑定 Net.binding_invitecode=function(_msg){ GameUI.EndLoad(); C_Player.binding_invitecode(_msg); } //接收修改豆豆 Net.update_bean = function(_msg){ //C_Player.update_bean(_msg); Desk.update_bean(_msg); } Net.Send_get_player_invitecode = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_player_invitecode,_data); } Net.get_player_invitecode = function(_msg){ GameUI.EndLoad(); C_Player.setInvitecod(_msg.data.invitecode); GameUI.OpenBind(); } Net.Send_beanroom_surrender = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.beanroom_surrender,_data); } Net.beanroom_surrender = function(_msg){ GameUI.EndLoad(); GameUI.closeCheck(); if(_msg.data.state==0){ Game_Modify.onSurrender(_msg); }else{//失败 if(_msg.data.showerror==1){ GameUI.OpenTips(_msg.data.error); } } } Net.Send_player_prepare = function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.player_prepare,_data); } Net.player_prepare = function(_msg){ Desk.player_prepare(_msg); } Net.Send_share_room = function(_data){ this._SendData(AppList.app,RouteList.room,RpcList.share_room,_data); } Net.share_room = function(_msg){ Desk.share_room(_msg); } Net.Send_get_share_room = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.get_share_room,_data); } Net.get_share_room = function(_msg){ Desk.get_share_room(_msg); GameUI.EndLoad(); } Net.Send_quick_enter_share_room = function(_data){ console.log(_data); this._SendData(AppList.app,RouteList.agent,RpcList.quick_enter_share_room,_data); } Net.show_message = function(_msg){ GameUI.EndLoad(); Desk.show_message(_msg); } Net.Send_advanced_roomlist = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.advanced_roomlist,_data); } Net.advanced_roomlist = function(_msg){ GameUI.EndLoad(); Desk.advanced_roomlist(_msg); } Net.Send_advanced_createroom = function(_data){ GameUI.StartLoad(); this._SendData(AppList.app,RouteList.agent,RpcList.advanced_createroom,_data); } Net.advanced_createroom = function(_msg){ GameUI.EndLoad(); Desk.advanced_createroom(_msg); } Net.Send_change_room = function(_data){ //GameUI.StartLoad(); this._SendData(AppList.app,RouteList.room,RpcList.change_room,_data); }