Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Passphrases are supported (they are completely optional.)
Browse files Browse the repository at this point in the history
  • Loading branch information
supernovus committed Aug 3, 2011
1 parent 07aaebe commit f0c04f2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
9 changes: 7 additions & 2 deletions README
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ you can say "oh". That said, it works, in a limited sort of way.
* Basic navigation ("go north" or "n") * Basic navigation ("go north" or "n")
* Mixins * Mixins
* Basic world config * Basic world config
* Login based users (no passwords yet though.) * Login based users (with optional passphrases.)
* Simple permissions (build, admin, etc.) * Simple permissions (build, admin, etc.)
* Built-in default god user (cannot be killed, can always grant, etc.) * Built-in default god user (cannot be killed, can always grant, etc.)


Expand All @@ -28,10 +28,15 @@ you can say "oh". That said, it works, in a limited sort of way.
* Inventory * Inventory
* Light / Visibility * Light / Visibility
* Stats * Stats
* Passwords
* Persistence (saving Rooms and Clients to disk.) * Persistence (saving Rooms and Clients to disk.)
* Color/ANSI terminal effects.
* Lots of other stuff * Lots of other stuff


= Future =

Expanding it beyond a traditional MUD/MOO, such as an optional web interface,
more gaming abilities, etc.

= Author = = Author =


Tim Totten Tim Totten
Expand Down
5 changes: 3 additions & 2 deletions game.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
} }
}, },
"clients" : { "clients" : {
"Admin" : { "Admin" : {
"god" : true, "god" : true,
"can" : { "can" : {
"build" : true, "build" : true,
"admin" : true "admin" : true
} },
"pass" : "fork"
} }
} }
} }
8 changes: 8 additions & 0 deletions lib/Client.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ function Client (socket, username, init) {
// The ultimate permission, cannot be "granted" or "revoked". // The ultimate permission, cannot be "granted" or "revoked".
if (init && init.god) if (init && init.god)
this.god = init.god; this.god = init.god;

// Passphrase support
if (init && init.pass)
this.pass = init.pass;

} }


Client.prototype.gotoRoom = function (roomid) { Client.prototype.gotoRoom = function (roomid) {
Expand Down Expand Up @@ -205,6 +210,9 @@ Client.prototype.parse = function (data) {
else else
this.youCant(); this.youCant();
} }
else if (matches = str.match(/^passwd (\w+)/)) {
this.pass = matches[1];
}
else if (str == 'hi') this.say("hello"); else if (str == 'hi') this.say("hello");
else if (str == 'bye') this.say("goodbye"); else if (str == 'bye') this.say("goodbye");
else else
Expand Down
65 changes: 51 additions & 14 deletions lib/World.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,25 +40,62 @@ World.prototype.login = function (socket) {
socket.write("Enter your username: "); socket.write("Enter your username: ");
// Below we use "world" instead of "this" for disabiguity. // Below we use "world" instead of "this" for disabiguity.
var loginHandler = function (data) { var loginHandler = function (data) {
var username = world.dataString(data); var client;
var client = world.getUser(username); var checkpass = false;
if (client) { if (socket.worldClient) { // We have a pass-phrase.
if (client.connected) checkpass = true;
{ username += ' ' + world.usercount; var passphrase = world.dataString(data);
socket.write("Sorry, that name is in use, we'll call you "+username+nl); client = socket.worldClient;
client = world.newClient(socket, username); if (passphrase == client.pass) {
}
else {
client.socket = socket; client.socket = socket;
client.connected = true; 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. // Add a new client to the client list.
Expand Down

0 comments on commit f0c04f2

Please sign in to comment.