Update network.js
This commit is contained in:
parent
ef4482ca28
commit
34eb2ad914
656
fc/js/network.js
656
fc/js/network.js
@ -1,328 +1,328 @@
|
||||
var jsMatchvs = JCMatchVS
|
||||
var jcmsghandler = JCMsgHandler
|
||||
|
||||
|
||||
|
||||
nwm = function(){
|
||||
this.response = null;
|
||||
this.online = false;
|
||||
this.engine = null;
|
||||
this.roomUserInfoList = [];
|
||||
this.frames=[];
|
||||
this.inRoom = false;
|
||||
|
||||
|
||||
this.cleanCb = function(){
|
||||
this.cbOnLogin = null;
|
||||
this.cbOnCreateRoom =null;
|
||||
this.cbOnJoinRoom = null;
|
||||
this.cbjoinRoomNotify = null;
|
||||
this.cbleaveRoomNotify = null;
|
||||
this.cbRoomMerge = null;
|
||||
};
|
||||
this.clean = function(){
|
||||
this.online = false;
|
||||
this.frameIndex = 0;
|
||||
this.cleanCb();
|
||||
this.roomUserInfoList = [];
|
||||
if(this.engine){
|
||||
this.engine.loginOut();
|
||||
this.engine.reconnectcount = 999;
|
||||
this.engine.disconnect();
|
||||
this.engine = null;
|
||||
}
|
||||
|
||||
}
|
||||
this.init = function(){
|
||||
var response = new jcmsghandler();
|
||||
NetWorkHandle.NetWorkManage = this;
|
||||
var self = this;
|
||||
response.initResponse = function(res){
|
||||
if(res.status==0){
|
||||
self.engine.login();
|
||||
}
|
||||
}
|
||||
response.netResponse = function(res){
|
||||
if(res.status==0){
|
||||
console.log('net 成功');
|
||||
}
|
||||
}
|
||||
response.joinRoomResponse= function(res){
|
||||
// console.log(res);
|
||||
// if(res.status==0||res.status==-3){
|
||||
// for(var i=0;i<res.roomUserInfoList.length;i++){
|
||||
// var temp = res.roomUserInfoList[i];
|
||||
// temp.userProfile = JSON.parse(temp.userProfile);
|
||||
// self.roomUserInfoList.push(temp);
|
||||
// }
|
||||
// }
|
||||
if(self.cbOnJoinRoom){
|
||||
self.cbOnJoinRoom(res);
|
||||
}
|
||||
}
|
||||
response.joinRoomNotify= function(res){
|
||||
// var temp = res;
|
||||
// temp.userProfile = JSON.parse(temp.userProfile);
|
||||
// self.roomUserInfoList.push(temp);
|
||||
hideInviteMask();
|
||||
if(self.cbjoinRoomNotify){
|
||||
self.cbjoinRoomNotify(res);
|
||||
}
|
||||
}
|
||||
response.loginResponse = function(res){
|
||||
if(res.status==0){
|
||||
self.online = true;
|
||||
console.log('login成功');
|
||||
//console.log(res);
|
||||
|
||||
}
|
||||
if(self.cbOnLogin){
|
||||
self.cbOnLogin(res);//create or join
|
||||
}
|
||||
}
|
||||
response.createRoomResponse= function(res){
|
||||
if(res.status==0){
|
||||
console.log('createRoom成功');
|
||||
console.log(res.roomID);
|
||||
self.roomID = res.roomID;
|
||||
wx.miniProgram.postMessage({ data: self.roomID })
|
||||
showInviteMask();
|
||||
}
|
||||
if(self.cbOnCreateRoom){
|
||||
self.cbOnCreateRoom(res);
|
||||
}
|
||||
}
|
||||
response.sendEventResponse = function(res) {
|
||||
console.log('自己广播');
|
||||
res.srcUserId = SDKManage.account_id;
|
||||
console.log(res);
|
||||
NetWorkHandle.process(res);
|
||||
}
|
||||
response.sendRoomEvtNotify= function(res){
|
||||
console.log("收到广播")
|
||||
console.log(res);
|
||||
NetWorkHandle.process(res);
|
||||
}
|
||||
response.reconnectResponse = function(){
|
||||
|
||||
}
|
||||
|
||||
response.sendFrameEventResponse = function (res) {
|
||||
|
||||
}
|
||||
response.joinOverResponse = function(res) {
|
||||
console.log("joinOverResponse");
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
//自己离开房间回调
|
||||
response.leaveRoomResponse = function(res) {
|
||||
console.log('自己离开房间');
|
||||
console.log( res);
|
||||
}
|
||||
//其他成员离开房间回调
|
||||
response.leaveRoomNotify = function(res) {
|
||||
console.log('其他成员离开房间');
|
||||
console.log(res);
|
||||
for(var i = 0;i<self.roomUserInfoList.length;i++){
|
||||
if(self.roomUserInfoList[i].userId == res.userId){
|
||||
self.roomUserInfoList.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(self.cbleaveRoomNotify){
|
||||
self.cbleaveRoomNotify(res);
|
||||
}
|
||||
}
|
||||
response.logoutResponse = function(res) {
|
||||
console.log("登出")
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
response.gameStartResponse= function(res) {
|
||||
console.log("gameStart");
|
||||
console.log(res);
|
||||
self.engine.joinOver();
|
||||
self.engine.setFrameSync(10);
|
||||
}
|
||||
response.frameUpdate = function(res){
|
||||
res.isnet = true;
|
||||
self.frames.push(res);
|
||||
for(var i=0;i<5;i++){
|
||||
self.frames.push({frameIndex:res.frameIndex,isnet:false});
|
||||
}
|
||||
self.frameIndex = res.frameIndex;
|
||||
}
|
||||
response.setFrameSyncResponse= function(res){
|
||||
}
|
||||
response.joinOverRoomNotify = function(res){
|
||||
|
||||
}
|
||||
response.netWorkStateNotify= function(res){
|
||||
console.log(res);
|
||||
if(res.state ==1){
|
||||
for(var i = 0;i<self.roomUserInfoList.length;i++){
|
||||
if(self.roomUserInfoList[i].userId == res.userID){
|
||||
self.roomUserInfoList.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(self.cbleaveRoomNotify){
|
||||
self.cbleaveRoomNotify(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
response.joinOverResponse= function(res){
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
response.onSMSetRoomParam = function(res){
|
||||
console.log(res);
|
||||
}
|
||||
response.onSMRoomMergeNotify = function(res){
|
||||
console.log(res);
|
||||
self.roomUserInfoList = [];
|
||||
for(var i=0;i<res.target_room_user_info_list.length;i++){
|
||||
var temp = res.target_room_user_info_list[i];
|
||||
temp.userProfile = JSON.parse(temp.user_profile);
|
||||
temp.userId = temp.account_id;
|
||||
self.roomUserInfoList.push(temp);
|
||||
}
|
||||
if(self.cbRoomMerge){
|
||||
self.cbRoomMerge(res)
|
||||
}
|
||||
}
|
||||
response.destroyRoomNotify= function(res){
|
||||
self.frames = [];
|
||||
}
|
||||
response.onSMResetRoom= function(res){
|
||||
|
||||
}
|
||||
jcmsghandler.prototype.pushMsg = function(res){
|
||||
|
||||
}
|
||||
this.response = response;
|
||||
setInterval(function() {
|
||||
self.heart();
|
||||
},
|
||||
10000)
|
||||
};
|
||||
this.heart = function(dt){
|
||||
if(this.online&&this.engine){
|
||||
this.engine.heart();
|
||||
}
|
||||
}
|
||||
this.initengine = function(){
|
||||
this.clean();
|
||||
var engine = new jsMatchvs();
|
||||
engine.__classCreate();
|
||||
engine.init(this.response, 6001, 'beta', "1003", null);
|
||||
engine.setUserId((new Date()).getTime().toString());
|
||||
engine.setToken("");
|
||||
engine.reconnectmax = -1;
|
||||
this.engine = engine;
|
||||
return this.engine;
|
||||
};
|
||||
this.leaveRoom =function(){
|
||||
if(this.engine){
|
||||
this.engine.leaveRoom();
|
||||
}
|
||||
};
|
||||
this.joinOver=function(){
|
||||
if(this.engine){
|
||||
this.engine.joinOver();
|
||||
}
|
||||
};
|
||||
this.sendRoomEvent=function(v){
|
||||
if(this.engine){
|
||||
this.engine.sendRoomEvent(JSON.stringify(v));
|
||||
}
|
||||
}
|
||||
this.sendFrameEvent=function(v){
|
||||
if(this.engine){
|
||||
this.engine.sendFrameEvent(JSON.stringify(v));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.startGame = function(){
|
||||
var data = {
|
||||
m:NetEnum.STARTGAME,
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
this.playerCount = this.roomUserInfoList.length-Main.robotCount;
|
||||
}
|
||||
|
||||
this.enterGame =function(){
|
||||
var data = {
|
||||
m:NetEnum.ENTERGAME,
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
this.onEnter = function(){
|
||||
if(this.engine){
|
||||
this.engine.gameStart('go');
|
||||
}
|
||||
};
|
||||
this.gameStart= function(){
|
||||
this.engine.gameStart('go');
|
||||
};
|
||||
this.sendJump= function(){
|
||||
var data = {
|
||||
m:NetEnum.JUMP,
|
||||
}
|
||||
this.sendFrameEvent(data);
|
||||
};
|
||||
|
||||
this.useItem= function(itemid){
|
||||
var data = {
|
||||
m:NetEnum.USEITEM,
|
||||
v:itemid,
|
||||
}
|
||||
this.sendFrameEvent(data);
|
||||
};
|
||||
this.endItem= function(itemid){
|
||||
var data = {
|
||||
m:NetEnum.ENDITEM,
|
||||
v:itemid,
|
||||
}
|
||||
this.sendFrameEvent(data);
|
||||
};
|
||||
|
||||
this.changeCloth = function(cid){
|
||||
var data = {
|
||||
m:NetEnum.CHANGECLOTH,
|
||||
v:cid
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
this.startMatch = function(){
|
||||
var data = {
|
||||
m:NetEnum.STARTMATCH,
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
|
||||
this.setRobot = function(c){
|
||||
var data = {
|
||||
m:NetEnum.SETROBOT,
|
||||
v:c
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
this.setRoomParam =function(v){
|
||||
if(this.engine){
|
||||
this.engine.setRoomParam(v);
|
||||
}
|
||||
};
|
||||
|
||||
this.resetRoom =function(){
|
||||
if(this.engine){
|
||||
this.engine.resetRoom(0);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
NetWorkManage = new nwm();
|
||||
NetWorkManage.init();
|
||||
var jsMatchvs = JCMatchVS
|
||||
var jcmsghandler = JCMsgHandler
|
||||
|
||||
|
||||
|
||||
nwm = function(){
|
||||
this.response = null;
|
||||
this.online = false;
|
||||
this.engine = null;
|
||||
this.roomUserInfoList = [];
|
||||
this.frames=[];
|
||||
this.inRoom = false;
|
||||
|
||||
|
||||
this.cleanCb = function(){
|
||||
this.cbOnLogin = null;
|
||||
this.cbOnCreateRoom =null;
|
||||
this.cbOnJoinRoom = null;
|
||||
this.cbjoinRoomNotify = null;
|
||||
this.cbleaveRoomNotify = null;
|
||||
this.cbRoomMerge = null;
|
||||
};
|
||||
this.clean = function(){
|
||||
this.online = false;
|
||||
this.frameIndex = 0;
|
||||
this.cleanCb();
|
||||
this.roomUserInfoList = [];
|
||||
if(this.engine){
|
||||
this.engine.loginOut();
|
||||
this.engine.reconnectcount = 999;
|
||||
this.engine.disconnect();
|
||||
this.engine = null;
|
||||
}
|
||||
|
||||
}
|
||||
this.init = function(){
|
||||
var response = new jcmsghandler();
|
||||
NetWorkHandle.NetWorkManage = this;
|
||||
var self = this;
|
||||
response.initResponse = function(res){
|
||||
if(res.status==0){
|
||||
self.engine.login();
|
||||
}
|
||||
}
|
||||
response.netResponse = function(res){
|
||||
if(res.status==0){
|
||||
console.log('net 成功');
|
||||
}
|
||||
}
|
||||
response.joinRoomResponse= function(res){
|
||||
// console.log(res);
|
||||
// if(res.status==0||res.status==-3){
|
||||
// for(var i=0;i<res.roomUserInfoList.length;i++){
|
||||
// var temp = res.roomUserInfoList[i];
|
||||
// temp.userProfile = JSON.parse(temp.userProfile);
|
||||
// self.roomUserInfoList.push(temp);
|
||||
// }
|
||||
// }
|
||||
if(self.cbOnJoinRoom){
|
||||
self.cbOnJoinRoom(res);
|
||||
}
|
||||
}
|
||||
response.joinRoomNotify= function(res){
|
||||
// var temp = res;
|
||||
// temp.userProfile = JSON.parse(temp.userProfile);
|
||||
// self.roomUserInfoList.push(temp);
|
||||
hideInviteMask();
|
||||
if(self.cbjoinRoomNotify){
|
||||
self.cbjoinRoomNotify(res);
|
||||
}
|
||||
}
|
||||
response.loginResponse = function(res){
|
||||
if(res.status==0){
|
||||
self.online = true;
|
||||
console.log('login成功');
|
||||
//console.log(res);
|
||||
|
||||
}
|
||||
if(self.cbOnLogin){
|
||||
self.cbOnLogin(res);//create or join
|
||||
}
|
||||
}
|
||||
response.createRoomResponse= function(res){
|
||||
if(res.status==0){
|
||||
console.log('createRoom成功');
|
||||
console.log(res.roomID);
|
||||
self.roomID = res.roomID;
|
||||
wx.miniProgram.postMessage({ data: self.roomID })
|
||||
showInviteMask();
|
||||
}
|
||||
if(self.cbOnCreateRoom){
|
||||
self.cbOnCreateRoom(res);
|
||||
}
|
||||
}
|
||||
response.sendEventResponse = function(res) {
|
||||
console.log('自己广播');
|
||||
res.srcUserId = SDKManage.account_id;
|
||||
console.log(res);
|
||||
NetWorkHandle.process(res);
|
||||
}
|
||||
response.sendRoomEvtNotify= function(res){
|
||||
console.log("收到广播")
|
||||
console.log(res);
|
||||
NetWorkHandle.process(res);
|
||||
}
|
||||
response.reconnectResponse = function(){
|
||||
|
||||
}
|
||||
|
||||
response.sendFrameEventResponse = function (res) {
|
||||
|
||||
}
|
||||
response.joinOverResponse = function(res) {
|
||||
console.log("joinOverResponse");
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
//自己离开房间回调
|
||||
response.leaveRoomResponse = function(res) {
|
||||
console.log('自己离开房间');
|
||||
console.log( res);
|
||||
}
|
||||
//其他成员离开房间回调
|
||||
response.leaveRoomNotify = function(res) {
|
||||
console.log('其他成员离开房间');
|
||||
console.log(res);
|
||||
for(var i = 0;i<self.roomUserInfoList.length;i++){
|
||||
if(self.roomUserInfoList[i].userId == res.userId){
|
||||
self.roomUserInfoList.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(self.cbleaveRoomNotify){
|
||||
self.cbleaveRoomNotify(res);
|
||||
}
|
||||
}
|
||||
response.logoutResponse = function(res) {
|
||||
console.log("登出")
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
response.gameStartResponse= function(res) {
|
||||
console.log("gameStart");
|
||||
console.log(res);
|
||||
self.engine.joinOver();
|
||||
self.engine.setFrameSync(10);
|
||||
}
|
||||
response.frameUpdate = function(res){
|
||||
res.isnet = true;
|
||||
self.frames.push(res);
|
||||
for(var i=0;i<5;i++){
|
||||
self.frames.push({frameIndex:res.frameIndex,isnet:false});
|
||||
}
|
||||
self.frameIndex = res.frameIndex;
|
||||
}
|
||||
response.setFrameSyncResponse= function(res){
|
||||
}
|
||||
response.joinOverRoomNotify = function(res){
|
||||
|
||||
}
|
||||
response.netWorkStateNotify= function(res){
|
||||
console.log(res);
|
||||
if(res.state ==1){
|
||||
for(var i = 0;i<self.roomUserInfoList.length;i++){
|
||||
if(self.roomUserInfoList[i].userId == res.userID){
|
||||
self.roomUserInfoList.splice(i,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(self.cbleaveRoomNotify){
|
||||
self.cbleaveRoomNotify(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
response.joinOverResponse= function(res){
|
||||
console.log(res);
|
||||
}
|
||||
|
||||
response.onSMSetRoomParam = function(res){
|
||||
console.log(res);
|
||||
}
|
||||
response.onSMRoomMergeNotify = function(res){
|
||||
console.log(res);
|
||||
self.roomUserInfoList = [];
|
||||
for(var i=0;i<res.target_room_user_info_list.length;i++){
|
||||
var temp = res.target_room_user_info_list[i];
|
||||
temp.userProfile = JSON.parse(temp.user_profile);
|
||||
temp.userId = temp.account_id;
|
||||
self.roomUserInfoList.push(temp);
|
||||
}
|
||||
if(self.cbRoomMerge){
|
||||
self.cbRoomMerge(res)
|
||||
}
|
||||
}
|
||||
response.destroyRoomNotify= function(res){
|
||||
self.frames = [];
|
||||
}
|
||||
response.onSMResetRoom= function(res){
|
||||
|
||||
}
|
||||
jcmsghandler.prototype.pushMsg = function(res){
|
||||
|
||||
}
|
||||
this.response = response;
|
||||
setInterval(function() {
|
||||
self.heart();
|
||||
},
|
||||
10000)
|
||||
};
|
||||
this.heart = function(dt){
|
||||
if(this.online&&this.engine){
|
||||
this.engine.heart();
|
||||
}
|
||||
}
|
||||
this.initengine = function(){
|
||||
this.clean();
|
||||
var engine = new jsMatchvs();
|
||||
engine.__classCreate();
|
||||
engine.init(this.response, 6001, 'beta', "1003", null);
|
||||
engine.setUserId((new Date()).getTime().toString());
|
||||
engine.setToken("");
|
||||
engine.reconnectmax = -1;
|
||||
this.engine = engine;
|
||||
return this.engine;
|
||||
};
|
||||
this.leaveRoom =function(){
|
||||
if(this.engine){
|
||||
this.engine.leaveRoom();
|
||||
}
|
||||
};
|
||||
this.joinOver=function(){
|
||||
if(this.engine){
|
||||
this.engine.joinOver();
|
||||
}
|
||||
};
|
||||
this.sendRoomEvent=function(v){
|
||||
if(this.engine){
|
||||
this.engine.sendRoomEvent(JSON.stringify(v));
|
||||
}
|
||||
}
|
||||
this.sendFrameEvent=function(v){
|
||||
if(this.engine){
|
||||
this.engine.sendFrameEvent(JSON.stringify(v));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.startGame = function(){
|
||||
var data = {
|
||||
m:NetEnum.STARTGAME,
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
this.playerCount = this.roomUserInfoList.length-Main.robotCount;
|
||||
}
|
||||
|
||||
this.enterGame =function(){
|
||||
var data = {
|
||||
m:NetEnum.ENTERGAME,
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
this.onEnter = function(){
|
||||
if(this.engine){
|
||||
this.engine.gameStart('go');
|
||||
}
|
||||
};
|
||||
this.gameStart= function(){
|
||||
this.engine.gameStart('go');
|
||||
};
|
||||
this.sendJump= function(){
|
||||
var data = {
|
||||
m:NetEnum.JUMP,
|
||||
}
|
||||
this.sendFrameEvent(data);
|
||||
};
|
||||
|
||||
this.useItem= function(itemid){
|
||||
var data = {
|
||||
m:NetEnum.USEITEM,
|
||||
v:itemid,
|
||||
}
|
||||
this.sendFrameEvent(data);
|
||||
};
|
||||
this.endItem= function(itemid){
|
||||
var data = {
|
||||
m:NetEnum.ENDITEM,
|
||||
v:itemid,
|
||||
}
|
||||
this.sendFrameEvent(data);
|
||||
};
|
||||
|
||||
this.changeCloth = function(cid){
|
||||
var data = {
|
||||
m:NetEnum.CHANGECLOTH,
|
||||
v:cid
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
this.startMatch = function(){
|
||||
var data = {
|
||||
m:NetEnum.STARTMATCH,
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
|
||||
this.setRobot = function(c){
|
||||
var data = {
|
||||
m:NetEnum.SETROBOT,
|
||||
v:c
|
||||
}
|
||||
this.sendRoomEvent(data);
|
||||
}
|
||||
this.setRoomParam =function(v){
|
||||
if(this.engine){
|
||||
this.engine.setRoomParam(v);
|
||||
}
|
||||
};
|
||||
|
||||
this.resetRoom =function(){
|
||||
if(this.engine){
|
||||
this.engine.resetRoom(0);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
NetWorkManage = new nwm();
|
||||
NetWorkManage.init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user