Mercurial > hg > rlgwebd
annotate rlgwebd.js @ 132:823e878e5840
Logins don't time out anymore.
No more login timestamps either.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Wed, 12 Sep 2012 15:48:41 -0700 |
parents | 3e3824711791 |
children | dcd07c1d846a |
rev | line source |
---|---|
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
1 #!/usr/bin/env node |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
2 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
3 // If you can't quite trust node to find it on its own |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
4 var localModules = '/usr/local/lib/node_modules/'; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
5 var http = require('http'); |
28
2ad2b6491aa9
rlgwebd.js: become a real daemon.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
6 var net = require('net'); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
7 var url = require('url'); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
8 var path = require('path'); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
9 var fs = require('fs'); |
55
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
10 var events = require('events'); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
11 var child_process = require('child_process'); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
12 var daemon = require(path.join(localModules, "daemon")); |
87
bd2cf6dda28d
RLG-Web: use the pty module.
John "Elwin" Edwards <elwin@sdf.org>
parents:
85
diff
changeset
|
13 var pty = require(path.join(localModules, "pty.js")); |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
14 var WebSocketServer = require(path.join(localModules, "websocket")).server; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
15 |
30
b5570a594266
rlgwebd.js: listen on any address
John "Elwin" Edwards <elwin@sdf.org>
parents:
29
diff
changeset
|
16 /* Configuration variables */ |
28
2ad2b6491aa9
rlgwebd.js: become a real daemon.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
17 // These first two files are NOT in the chroot. |
2ad2b6491aa9
rlgwebd.js: become a real daemon.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
18 var ctlsocket = "/var/local/rlgwebd/ctl"; |
2ad2b6491aa9
rlgwebd.js: become a real daemon.
John "Elwin" Edwards <elwin@sdf.org>
parents:
27
diff
changeset
|
19 var logfile = "/var/local/rlgwebd/log"; |
30
b5570a594266
rlgwebd.js: listen on any address
John "Elwin" Edwards <elwin@sdf.org>
parents:
29
diff
changeset
|
20 var httpPort = 8080; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
21 var chrootDir = "/var/dgl/"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
22 var dropToUID = 501; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
23 var dropToGID = 501; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
24 var serveStaticRoot = "/var/www/"; // inside the chroot |
36
a0387f112bcf
RLG-Web: autosave idle games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
34
diff
changeset
|
25 var playtimeout = 3600000; // Idle time before games are autosaved, in ms |
30
b5570a594266
rlgwebd.js: listen on any address
John "Elwin" Edwards <elwin@sdf.org>
parents:
29
diff
changeset
|
26 |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
37
diff
changeset
|
27 /* Data on the games available. */ |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
28 var games = { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
29 "rogue3": { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
30 "name": "Rogue V3", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
31 "uname": "rogue3", |
42
8f6bc0df58fa
rlgwebd.js: add a player status interface.
John "Elwin" Edwards <elwin@sdf.org>
parents:
40
diff
changeset
|
32 "suffix": ".r3sav", |
60
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
33 "path": "/bin/rogue3", |
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
34 "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
35 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
36 "rogue4": { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
37 "name": "Rogue V4", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
38 "uname": "rogue4", |
42
8f6bc0df58fa
rlgwebd.js: add a player status interface.
John "Elwin" Edwards <elwin@sdf.org>
parents:
40
diff
changeset
|
39 "suffix": ".r4sav", |
60
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
40 "path": "/bin/rogue4", |
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
41 "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
42 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
43 "rogue5": { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
44 "name": "Rogue V5", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
45 "uname": "rogue5", |
42
8f6bc0df58fa
rlgwebd.js: add a player status interface.
John "Elwin" Edwards <elwin@sdf.org>
parents:
40
diff
changeset
|
46 "suffix": ".r5sav", |
60
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
47 "path": "/bin/rogue5", |
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
48 "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
49 }, |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
50 "srogue": { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
51 "name": "Super-Rogue", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
52 "uname": "srogue", |
42
8f6bc0df58fa
rlgwebd.js: add a player status interface.
John "Elwin" Edwards <elwin@sdf.org>
parents:
40
diff
changeset
|
53 "suffix": ".srsav", |
60
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
54 "path": "/bin/srogue", |
121
077adfeea038
Correct the clear sequence for srogue.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
55 "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J |
120
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
56 }, |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
57 "arogue5": { |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
58 "name": "Advanced Rogue 5", |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
59 "uname": "arogue5", |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
60 "suffix": ".ar5sav", |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
61 "path": "/bin/arogue5", |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
113
diff
changeset
|
62 "clear": new Buffer([27, 91, 72, 27, 91, 50, 74]) // CSI H CSI 2J |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
63 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
64 }; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
65 |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
37
diff
changeset
|
66 /* Global state */ |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
37
diff
changeset
|
67 var logins = {}; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
37
diff
changeset
|
68 var sessions = {}; |
55
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
69 var clients = {}; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
37
diff
changeset
|
70 var allowlogin = true; |
55
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
71 var nextsession = 0; |
104
7d444ba4739e
RLG-Web server: send status events over WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
103
diff
changeset
|
72 var gamemux = new events.EventEmitter(); |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
37
diff
changeset
|
73 |
55
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
74 /* Constructor. A TermSession handles a pty and the game running on it. |
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
75 * game: (String) Name of the game to launch. |
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
76 * lkey: (String, key) The user's id, a key into logins. |
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
77 * dims: (Array [Number, Number]) Height and width of the pty. |
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
78 * handlers: (Object) Key-value pairs, event names and functions to |
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
79 * install to handle them. |
96815eae4ebe
RLG-Web: make multiple watchers possible.
John "Elwin" Edwards <elwin@sdf.org>
parents:
49
diff
changeset
|
80 * Events: |