(function(){ var WebSocketServer=require('ws').Server; var wss=new WebSocketServer({port:8080}); var rooms=[{},{},{},{},{},{}]; var clients={}; var messages={ enter:function(index,nickname,avatar){ 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.config){ this.sendl('enterroomfailed'); } else{ this.owner=room.owner; this.owner.sendl('onconnection',this.wsid); } util.updaterooms(); } else{ room.owner=this; this.sendl('createroom'); } }, config:function(config){ var room=this.room; if(room&&room.owner==this){ room.config=config; } util.updaterooms(); }, send:function(id,message){ if(clients[id]&&clients[id].owner==this){ try{ clients[id].send(message); } catch(e){ clients[id].close(); } } }, close:function(id){ if(clients[id]&&clients[id].owner==this){ clients[id].close(); } }, }; var util={ sendl:function(){ var args=[]; for(var i=0;i