Permalink
Browse files

Merge branch 'master' of github.com:nko/hms-dreadnode

  • Loading branch information...
2 parents f0ac3e9 + a3cda57 commit af90aeb83570cb083cc9e2e81970f2256414ccc2 @teleject teleject committed Aug 29, 2010
Showing with 18 additions and 8 deletions.
  1. +12 −2 lib/gamemanager.js
  2. +1 −1 public/index.html
  3. +0 −2 public/js/socket.js
  4. +2 −0 public/login.html
  5. +3 −3 server.js
View
@@ -78,10 +78,15 @@ GameManager.prototype.addUser = function(client, username) {
// Check if username is already in use
if (this.usernames.indexOf(username) !== -1) {
- return false;
+ return {success: false, reason: "User exists"};
}
var existingGame = this.getCurrentGame();
+ // Is the game full?
+ if (existingGame.isFull()) {
+ return {success: false, reason: "Game is full"};
+ }
+
this.usernames.push(username);
var playa = new Playa(username, existingGame);
existingGame.addPlayer(playa);
@@ -91,7 +96,7 @@ GameManager.prototype.addUser = function(client, username) {
this.connections[username] = connection;
this.emit("newuser", connection);
- return true;
+ return {success: true};
};
GameManager.prototype.getUsers = function() {
@@ -307,6 +312,7 @@ function Game() {
this.name = this.battleNames[Math.floor(Math.random()*this.battleNames.length)];
this.playas = [];
this.currentPlaya = 0;
+ this.maxPlayers = 5;
// listeners
this.on("winner", function () {
@@ -316,6 +322,10 @@ function Game() {
Game.prototype = new process.EventEmitter();
+Game.prototype.isFull = function () {
+ return this.playas.length >= this.maxPlayers;
+};
+
Game.prototype.addPlayer = function (player) {
this.playas.push(player);
};
View
@@ -20,7 +20,7 @@
<a href="#" onClick="APPVIEW.next_page();return false;"><img src="images/main-screen.png" alt="Man the GUNS! Your crew needs you!"></a>
</section>
<section class="buttons">
- <button class="large">Rules</button>
+ <!--<button class="large">Rules</button> No rules brother. -->
<button class="large orangellow" onClick="APPVIEW.next_page();">Play Now!</button>
</section>
<section class="mod about">
View
@@ -37,7 +37,6 @@
destroyed : function(message) {
var msg = message.msg;
console.log(msg);
- // TODO: flag loss : FAILURE
global.APPVIEW.next_page();
},
// not implemented
@@ -79,7 +78,6 @@
win : function(message) {
var msg = message.msg;
console.log(msg);
- // TODO: flag win : WINNER WINNER CHICKEN DINNER
global.APPVIEW.next_page();
},
yourturn : function(message) {
View
@@ -34,8 +34,10 @@
<label for="uname">Username</label>
<input type="text" id="uname">
+ <!-- :( ran out of time for Gravatarity
<label for="gravatar">Email Address (for Gravatar)</label>
<input type="text" id="gravatar">
+ -->
<!-- Don't need no stinkin' passwords
<label for="pword">Password</label>
View
@@ -55,15 +55,15 @@ var dispatch = {
response.msg = "NOOOOOOOOOOO!";
} else {
var username = message.msg;
- var success = manager.addUser(client, username);
- if (success) {
+ var couldAddUser = manager.addUser(client, username);
+ if (couldAddUser["success"]) {
response.type = "auth";
response.status = "success";
response.msg = "Welcome "+username;
} else {
response.type = "auth";
response.status = "ufail";
- response.msg = "Username taken";
+ response.msg = couldAddUser["reason"];
}
}
client.send(JSON.stringify(response));

0 comments on commit af90aeb

Please sign in to comment.