(function(){ var WebSocketServer=require('ws').Server; var wss=new WebSocketServer({port:8080}); var rooms=[{},{},{},{},{},{}]; var clients={}; var messages={ enter:function(index,nickname,avatar,config,mode){ this.nickname=nickname; this.avatar=avatar; var room=rooms[index]; if(!room){ index=0; room=rooms[0]; } this.room=room; if(room.owner){ if(room.servermode&&!room.owner._onconfig&&config&&mode){ room.owner.sendl('createroom',index,config,mode); room.owner._onconfig=this; room.owner.nickname=nickname; room.owner.avatar=avatar; } else if(!room.config){ this.sendl('enterroomfailed'); } else{ this.owner=room.owner; this.owner.sendl('onconnection',this.wsid); } util.updaterooms(); } else{ room.owner=this; this.sendl('createroom',index); } }, changeAvatar:function(nickname,avatar){ this.nickname=nickname; this.avatar=avatar; util.updaterooms(); }, server:function(cfg){ if(cfg){ this.servermode=true; var room=rooms[cfg[0]]; if(!room||room.owner){ this.sendl('reloadroom',true); } else{ room.owner=this; this.room=room; this.nickname=cfg[1]; this.avatar=cfg[2]; this.sendl('createroom',cfg[0],{},'auto') } } else{ for(var i=0;i