-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
34 lines (28 loc) · 1004 Bytes
/
server.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
var net = require('net');
var User = require('./User.js');
var LineParseStream = require('./LineParseStream.js');
var LoginServer = require('./LoginServer.js');
var CommandParseStream = require('./CommandParseStream.js');
var ChatServer = require('./ChatServer.js');
var users = {};
var rooms = {};
var server = net.createServer(function(socket) {
socket.setEncoding('utf8');
console.log('server connected');
var user = new User(socket);
var lineParseStream = new LineParseStream();
var loginServer = new LoginServer(user, users);
socket.pipe(lineParseStream).pipe(loginServer);
loginServer.on('login', function() {
lineParseStream.unpipe(loginServer);
var commandParseStream = new CommandParseStream();
var chatServer = new ChatServer(user, users, rooms);
lineParseStream.pipe(commandParseStream).pipe(chatServer);
socket.on('close', function() {
chatServer.emit('quit');
});
});
});
server.listen(9399, function() {
console.log('server bound');
});