-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
41 lines (33 loc) · 887 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var rl = require('readline'),
mongoose = require('mongoose'),
transports = require('./transports'),
factory = require('./factory'),
world = require('./world'),
commands = require('./commands');
mongoose.connect('mongodb://localhost/nmud');
mongoose.connection.on('error', function(err) {
console.log('mongoose error:', err);
});
world.load(function(err) {
var player = factory.createPlayer({ name: 'Derp' });
var start = world.getRoom(0);
player.room = start;
player.room.add(player);
var handler = commands.createMobileHandler(player);
handler.defaultAll();
player.on('command', function(cmd) {
if (cmd === 'quit') {
t.disconnect();
mongoose.connection.close();
process.exit(0);
}
else {
handler(cmd);
}
});
handler.on('error', function(err) {
player.emit('invalid', err.message);
});
var t = transports.console(player);
t.connect();
});