From ab94de2dcc2fdc27a1cb3655d3592b4f30992eaa Mon Sep 17 00:00:00 2001 From: exane Date: Thu, 18 Jun 2015 16:54:44 +0200 Subject: [PATCH] =?UTF-8?q?unstable=20server=20(=E2=95=AF=C2=B0=E2=96=A1?= =?UTF-8?q?=C2=B0=EF=BC=89=E2=95=AF=EF=B8=B5=20=E2=94=BB=E2=94=81=E2=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/Battle.js | 4 ++++ server/Connections.js | 2 ++ server/Room.js | 23 ++++++++++++++++++++--- server/User.js | 21 +++++++++++++++++++++ server/worker.js | 25 +++++++++++++++++++------ 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/server/Battle.js b/server/Battle.js index a354428..e658d05 100644 --- a/server/Battle.js +++ b/server/Battle.js @@ -225,6 +225,10 @@ var Battle = (function(){ } + r.shutDown = function() { + this.channel = null; + } + return Battle; })(); diff --git a/server/Connections.js b/server/Connections.js index a39a988..3815e1a 100644 --- a/server/Connections.js +++ b/server/Connections.js @@ -7,6 +7,7 @@ var Connections = (function(){ * constructor here */ this._connections = {}; + this.roomCollection = {}; }; var r = Connections.prototype; @@ -17,6 +18,7 @@ var Connections = (function(){ */ r._connections = null; + r.roomCollection = null; r.add = function(user) { this._connections[user.getID()] = user; diff --git a/server/Room.js b/server/Room.js index 957ce1a..212dd1c 100644 --- a/server/Room.js +++ b/server/Room.js @@ -16,6 +16,8 @@ var Room = (function(){ this._ready = {}; this.socket = scServer.global; + + console.log("room created: " + this.getID()); }; var r = Room.prototype; /** @@ -71,12 +73,27 @@ var Room = (function(){ return !!this._ready[this._users[0].getID()] && !!this._ready[this._users[1].getID()]; } - r.leave = function(user) { + r.leave = function(user){ var p = "p2"; - if(user.getID() === this._users[0].getID()) { + var i = 1; + if(user.getID() === this._users[0].getID()){ p = "p1"; + i = 0; } - this._battle.userLeft(p); + + this._users.splice(i, 1); + + if(this._battle){ + this._battle.userLeft(p); + } + + if(!this.hasUser()) { + connections.roomCollection[this.getID()] = null; + } + } + + r.hasUser = function() { + return this._users.length; } diff --git a/server/User.js b/server/User.js index a125218..1528c3f 100644 --- a/server/User.js +++ b/server/User.js @@ -23,7 +23,9 @@ var User = (function(){ r._id = null; r._name = null; r._rooms = null; + r._searching = false; r.socket = null; + r.disconnected = false; r.getID = function(){ return this._id; @@ -76,11 +78,30 @@ var User = (function(){ this._rooms.push(room); } + r.cleanUp = function() { + for(var i=0; i