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