Skip to content

Commit

Permalink
global commands read from flat file
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Slater committed Dec 29, 2011
1 parent df7f930 commit 0f0419d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions globals/say.js
@@ -0,0 +1 @@
say(p.slice(1).join(' '));
3 changes: 3 additions & 0 deletions globals/who.js
@@ -0,0 +1,3 @@
var users = getConnectedUsers();
for(name in users)
echo(users[name]);
4 changes: 4 additions & 0 deletions globals/who.js~
@@ -0,0 +1,4 @@
var users = getConnectedUsers();
for(name in users)
echo(users[name]);

14 changes: 14 additions & 0 deletions run.js
Expand Up @@ -41,6 +41,11 @@ var sandboxGen = function(nmud, user, params) {

var NodeMUD = function() {
this.db = JSON.parse(fs.readFileSync('db.json', 'utf-8'));

// Not sure whether to put this here (allows reloading) or in gen_db, this
// will do for now.
this.loadCommands();

this.connections = { };

this.server = net.createServer(function(socket) {
Expand Down Expand Up @@ -81,6 +86,15 @@ var NodeMUD = function() {
this.server.listen(1337, "127.0.0.1");
};

NodeMUD.prototype.loadCommands = function() {
fs.readdir('./globals/', function(err, files) {
for(file in files) {
this.db.globalCommands[file.split('.')[0]] =
fs.readFileSync(file, 'utf8');
}
});
};

NodeMUD.prototype.broadcast = function(text) {
for(index in this.connections) {
this.connections[index].socket.write('[' + text + ']\r\n');
Expand Down
2 changes: 0 additions & 2 deletions tools/gen_db.js
@@ -1,8 +1,6 @@
var fs = require('fs');
var db = {
"globalCommands": {
"say": "say(p.slice(1).join(' '));",
"who": "var users = getConnectedUsers(); for(name in users) echo(users[name]);"
},
"aliases": {
},
Expand Down

0 comments on commit 0f0419d

Please sign in to comment.