Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

global commands read from flat file

  • Loading branch information...
commit 0f0419d2178c398294a8a3f459bc543155343829 1 parent df7f930
Luke Slater authored
View
1  globals/say.js
@@ -0,0 +1 @@
+say(p.slice(1).join(' '));
View
3  globals/who.js
@@ -0,0 +1,3 @@
+var users = getConnectedUsers();
+for(name in users)
+ echo(users[name]);
View
4 globals/who.js~
@@ -0,0 +1,4 @@
+var users = getConnectedUsers();
+for(name in users)
+ echo(users[name]);
+
View
14 run.js
@@ -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) {
@@ -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');
View
2  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": {
},
Please sign in to comment.
Something went wrong with that request. Please try again.