This commit is contained in:
libccy 2016-04-18 11:13:31 +08:00
parent cb0a2029ce
commit 3ade3bab99
3 changed files with 77 additions and 30 deletions

View File

@ -27,9 +27,8 @@
break; break;
} }
} }
var index=window.location.href.indexOf('index.html?server='); if(window.location.href.indexOf('index.html?server')!=-1){
if(index!=-1){ window.isNonameServer=true;
window.isNonameServer=window.location.href.slice(index+18);
window.indexedDB=null; window.indexedDB=null;
} }
}()); }());
@ -11431,8 +11430,13 @@
delete _status.connectCallback; delete _status.connectCallback;
} }
if(game.online||game.onlineroom){ if(game.online||game.onlineroom){
localStorage.setItem(lib.configprefix+'directstart',true); if(game.servermode&&_status.over){
game.reload(); game.saveConfig('reconnect_room',game.roomId);
}
else{
localStorage.setItem(lib.configprefix+'directstart',true);
game.reload();
}
} }
else{ else{
game.saveConfig('reconnect_info'); game.saveConfig('reconnect_info');
@ -12053,7 +12057,7 @@
break; break;
} }
} }
this.send('init',this.id,lib.configOL,game.ip); this.send('init',this.id,lib.configOL,game.ip,window.isNonameServer,game.roomId);
} }
}, },
inited:function(){ inited:function(){
@ -12163,8 +12167,28 @@
// func.apply(this,args); // func.apply(this,args);
// } // }
}, },
log:function(){
var items=[];
try{
for(var i=0;i<arguments.length;i++){
eval('items.push('+arguments[i]+')');
}
}
catch(e){
this.send('log',['err']);
return;
}
this.send('log',items);
}
}, },
client:{ client:{
log:function(arr){
if(Array.isArray(arr)){
for(var i=0;i<arr.length;i++){
console.log(arr[i]);
}
}
},
opened:function(){ opened:function(){
game.send('init',lib.versionOL,{ game.send('init',lib.versionOL,{
id:game.onlineID, id:game.onlineID,
@ -12191,13 +12215,14 @@
} }
}, },
reloadroom:function(){ reloadroom:function(){
if(window.isNonameServer){ if(window.isNonameServer&&!_status.protectingroom){
game.reload(); game.reload();
} }
}, },
createroom:function(config,mode){ createroom:function(index,config,mode){
game.online=false; game.online=false;
game.onlineroom=true; game.onlineroom=true;
game.roomId=index;
lib.node={}; lib.node={};
if(config&&mode&&window.isNonameServer){ if(config&&mode&&window.isNonameServer){
game.switchMode(mode,config); game.switchMode(mode,config);
@ -12244,11 +12269,20 @@
},true); },true);
if(window.isNonameServer){ if(window.isNonameServer){
switch(window.isNonameServer){ var cfg='pagecfg'+game.roomId;
case 'identity':lib.configOL.mode='identity';game.send('server','enter','auto','服务器','xunyu');break; if(lib.config[cfg]){
case 'guozhan':lib.configOL.mode='guozhan';game.send('server','enter','auto','服务器','yuanshao');break; lib.configOL=lib.config[cfg][0];
case 'versus':lib.configOL.mode='versus';lib.config.mode_config.versus.connect_versus_mode='2v2';game.send('server','enter','auto','服务器','diaochan');break; game.send('server','enter',lib.config[cfg][1],lib.config[cfg][2],lib.config[cfg][3]);
default:game.send('server','server'); _status.protectingroom=true;
setTimeout(function(){
_status.protectingroom=false;
if(!lib.node||!lib.node.clients||!lib.node.clients.length){
game.reload();
}
},15000);
}
else{
game.send('server','server');
} }
} }
} }
@ -12286,10 +12320,12 @@
} }
} }
}, },
init:function(id,config,ip){ init:function(id,config,ip,servermode,roomId){
game.online=true; game.online=true;
game.onlineID=id; game.onlineID=id;
game.ip=ip; game.ip=ip;
game.servermode=servermode;
game.roomId=roomId;
game.saveConfig('reconnect_info',[_status.ip,id]); game.saveConfig('reconnect_info',[_status.ip,id]);
lib.config.recentIP.remove(_status.ip); lib.config.recentIP.remove(_status.ip);
lib.config.recentIP.unshift(_status.ip); lib.config.recentIP.unshift(_status.ip);
@ -12370,6 +12406,8 @@
clearTimeout(_status.createNodeTimeout); clearTimeout(_status.createNodeTimeout);
game.online=true; game.online=true;
game.ip=ip; game.ip=ip;
game.servermode=state.servermode;
game.roomId=state.roomId;
if(observe){ if(observe){
game.onlineID=null; game.onlineID=null;
} }
@ -12840,6 +12878,8 @@
if(!game.onlinezhu){ if(!game.onlinezhu){
game.onlinezhu=player.playerid; game.onlinezhu=player.playerid;
game.send('server','changeAvatar',player.nickname,player.avatar); game.send('server','changeAvatar',player.nickname,player.avatar);
_status.onlinenickname=player.nickname;
_status.onlineavatar=player.avatar;
} }
map[i]=[player.nickname,player.avatar,player.playerid]; map[i]=[player.nickname,player.avatar,player.playerid];
if(player.playerid==game.onlinezhu){ if(player.playerid==game.onlinezhu){
@ -15735,7 +15775,8 @@
game.addRecord(resultbool); game.addRecord(resultbool);
} }
if(window.isNonameServer){ if(window.isNonameServer){
setTimeout(game.reload,7000); game.saveConfig('pagecfg'+game.pageId,[lib.configOL,game.roomId,_status.onlinenickname,_status.onlineavatar]);
game.reload();
} }
}, },
loop:function(){ loop:function(){
@ -24869,7 +24910,9 @@
var state={ var state={
number:ui.arena.dataset.number, number:ui.arena.dataset.number,
players:{}, players:{},
mode:_status.mode mode:_status.mode,
servermode:window.isNonameServer,
roomId:game.roomId
}; };
for(var i in lib.playerOL){ for(var i in lib.playerOL){
state.players[i]=lib.playerOL[i].getState(); state.players[i]=lib.playerOL[i].getState();

View File

@ -4,6 +4,11 @@ page1.open('http://localhost/index.html?server=true', function(status) {
if(status !== 'success') { if(status !== 'success') {
console.log('Unable to access network'); console.log('Unable to access network');
} }
else{
page.evaluate(function(){
game.pageId=1;
});
}
}); });
var page2 = require('webpage').create(); var page2 = require('webpage').create();
@ -12,6 +17,11 @@ page2.open('http://localhost/index.html?server=true', function(status) {
if(status !== 'success') { if(status !== 'success') {
console.log('Unable to access network'); console.log('Unable to access network');
} }
else{
page.evaluate(function(){
game.pageId=2;
});
}
}); });
var page3 = require('webpage').create(); var page3 = require('webpage').create();
@ -20,4 +30,9 @@ page3.open('http://localhost/index.html?server=true', function(status) {
if(status !== 'success') { if(status !== 'success') {
console.log('Unable to access network'); console.log('Unable to access network');
} }
else{
page.evaluate(function(){
game.pageId=3;
});
}
}); });

View File

@ -6,15 +6,6 @@
var clients={}; var clients={};
var messages={ var messages={
enter:function(index,nickname,avatar,config,mode){ enter:function(index,nickname,avatar,config,mode){
if(index=='auto'){
index=0;
this.servermode='auto';
for(var i=0;i<rooms.length;i++){
if(!rooms[i].owner){
index=i;break;
}
}
}
this.nickname=nickname; this.nickname=nickname;
this.avatar=avatar; this.avatar=avatar;
var room=rooms[index]; var room=rooms[index];
@ -25,7 +16,7 @@
this.room=room; this.room=room;
if(room.owner){ if(room.owner){
if(room.servermode&&!room.owner._onconfig&&config&&mode){ if(room.servermode&&!room.owner._onconfig&&config&&mode){
room.owner.sendl('createroom',config,mode); room.owner.sendl('createroom',index,config,mode);
room.owner._onconfig=this; room.owner._onconfig=this;
room.owner.nickname=nickname; room.owner.nickname=nickname;
room.owner.avatar=avatar; room.owner.avatar=avatar;
@ -41,7 +32,7 @@
} }
else{ else{
room.owner=this; room.owner=this;
this.sendl('createroom'); this.sendl('createroom',index);
} }
}, },
changeAvatar:function(nickname,avatar){ changeAvatar:function(nickname,avatar){
@ -126,9 +117,7 @@
} }
else if(rooms[i].owner&&rooms[i].config){ else if(rooms[i].owner&&rooms[i].config){
if(rooms[i]._num==0){ if(rooms[i]._num==0){
if(rooms[i].owner.servermode!='auto'||rooms[i].config.gameStarted){ rooms[i].owner.sendl('reloadroom');
rooms[i].owner.sendl('reloadroom');
}
} }
roomlist[i]=[rooms[i].owner.nickname,rooms[i].owner.avatar, roomlist[i]=[rooms[i].owner.nickname,rooms[i].owner.avatar,
rooms[i].config,rooms[i]._num]; rooms[i].config,rooms[i]._num];