Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Passphrases are supported (they are completely optional.)

  • Loading branch information...
commit f0c04f2aa1b600db63d4984db654f37c4552cb0a 1 parent 07aaebe
@supernovus authored
Showing with 69 additions and 18 deletions.
  1. +7 −2 README
  2. +3 −2 game.json
  3. +8 −0 lib/Client.js
  4. +51 −14 lib/World.js
View
9 README
@@ -18,7 +18,7 @@ you can say "oh". That said, it works, in a limited sort of way.
* Basic navigation ("go north" or "n")
* Mixins
* Basic world config
- * Login based users (no passwords yet though.)
+ * Login based users (with optional passphrases.)
* Simple permissions (build, admin, etc.)
* Built-in default god user (cannot be killed, can always grant, etc.)
@@ -28,10 +28,15 @@ you can say "oh". That said, it works, in a limited sort of way.
* Inventory
* Light / Visibility
* Stats
- * Passwords
* Persistence (saving Rooms and Clients to disk.)
+ * Color/ANSI terminal effects.
* Lots of other stuff
+= Future =
+
+Expanding it beyond a traditional MUD/MOO, such as an optional web interface,
+more gaming abilities, etc.
+
= Author =
Tim Totten
View
5 game.json
@@ -34,12 +34,13 @@
}
},
"clients" : {
- "Admin" : {
+ "Admin" : {
"god" : true,
"can" : {
"build" : true,
"admin" : true
- }
+ },
+ "pass" : "fork"
}
}
}
View
8 lib/Client.js
@@ -34,6 +34,11 @@ function Client (socket, username, init) {
// The ultimate permission, cannot be "granted" or "revoked".
if (init && init.god)
this.god = init.god;
+
+ // Passphrase support
+ if (init && init.pass)
+ this.pass = init.pass;
+
}
Client.prototype.gotoRoom = function (roomid) {
@@ -205,6 +210,9 @@ Client.prototype.parse = function (data) {
else
this.youCant();
}
+ else if (matches = str.match(/^passwd (\w+)/)) {
+ this.pass = matches[1];
+ }
else if (str == 'hi') this.say("hello");
else if (str == 'bye') this.say("goodbye");
else
View
65 lib/World.js
@@ -40,25 +40,62 @@ World.prototype.login = function (socket) {
socket.write("Enter your username: ");
// Below we use "world" instead of "this" for disabiguity.
var loginHandler = function (data) {
- var username = world.dataString(data);
- var client = world.getUser(username);
- if (client) {
- if (client.connected)
- { username += ' ' + world.usercount;
- socket.write("Sorry, that name is in use, we'll call you "+username+nl);
- client = world.newClient(socket, username);
- }
- else {
+ var client;
+ var checkpass = false;
+ if (socket.worldClient) { // We have a pass-phrase.
+ checkpass = true;
+ var passphrase = world.dataString(data);
+ client = socket.worldClient;
+ if (passphrase == client.pass) {
client.socket = socket;
client.connected = true;
+ checkpass = false;
+ }
+ else {
+ if (socket.worldTries == 3) {
+ socket.write("Sorry, goodbye."+nl);
+ socket.end();
+ }
+ else {
+ socket.worldTries++;
+ socket.write("Try again: ");
+ }
+ }
+ }
+ else {
+ // By default we assume users have no pass-phrase.
+ var username = world.dataString(data);
+ client = world.getUser(username);
+ socket.worldClient = client; // Save in case of pass-phrases.
+ if (client) {
+ if (client.connected)
+ { username += ' ' + world.usercount;
+ socket.write("Sorry, that name is in use, we'll call you "+username+nl);
+ client = world.newClient(socket, username);
+
+ }
+ else {
+ if (client.pass) {
+ socket.worldTries = 0;
+ socket.write("Enter your passphrase: ");
+ checkpass = true;
+ }
+ else {
+ client.socket = socket;
+ client.connected = true;
+ }
+ }
}
+ else
+ client = world.newClient(socket, username);
+ }
+ if (!checkpass) {
+ client.showPrompt();
+ socket.removeAllListeners('data');
+ socket.on('data', function (data) { client.parse(data); });
}
- else
- client = world.newClient(socket, username);
- client.showPrompt();
- socket.on('data', function (data) { client.parse(data); });
}
- socket.once('data', loginHandler);
+ socket.on('data', loginHandler);
}
// Add a new client to the client list.
Please sign in to comment.
Something went wrong with that request. Please try again.