Mercurial > hg > rlgwebd
annotate rlgwebd.js @ 169:6f4b7e1b32e8
rlgwebd.js: clean up TermSession parameters.
Use the player name instead of a login key that has already been
verified and resolved to a player name.
| author | John "Elwin" Edwards | 
|---|---|
| date | Fri, 09 Jan 2015 09:43:21 -0500 | 
| parents | 0ceaca924b4c | 
| children | 50e4c9feeac2 | 
| 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 var http = require('http'); | 
| 28 
2ad2b6491aa9
rlgwebd.js: become a real daemon.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
27diff
changeset | 4 var net = require('net'); | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 5 var url = require('url'); | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 6 var path = require('path'); | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 7 var fs = require('fs'); | 
| 55 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 8 var events = require('events'); | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 9 var child_process = require('child_process'); | 
| 141 
1a156a7746a7
RLGWebD: use NODE_PATH to find modules.
 John "Elwin" Edwards parents: 
139diff
changeset | 10 // Dependencies | 
| 
1a156a7746a7
RLGWebD: use NODE_PATH to find modules.
 John "Elwin" Edwards parents: 
139diff
changeset | 11 var posix = require("posix"); | 
| 
1a156a7746a7
RLGWebD: use NODE_PATH to find modules.
 John "Elwin" Edwards parents: 
139diff
changeset | 12 var pty = require("pty.js"); | 
| 
1a156a7746a7
RLGWebD: use NODE_PATH to find modules.
 John "Elwin" Edwards parents: 
139diff
changeset | 13 var WebSocketServer = require("websocket").server; | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 14 | 
| 30 
b5570a594266
rlgwebd.js: listen on any address
 John "Elwin" Edwards <elwin@sdf.org> parents: 
29diff
changeset | 15 /* Configuration variables */ | 
| 139 | 16 // The first file is NOT in the chroot. | 
| 28 
2ad2b6491aa9
rlgwebd.js: become a real daemon.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
27diff
changeset | 17 var ctlsocket = "/var/local/rlgwebd/ctl"; | 
| 30 
b5570a594266
rlgwebd.js: listen on any address
 John "Elwin" Edwards <elwin@sdf.org> parents: 
29diff
changeset | 18 var httpPort = 8080; | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 19 var chrootDir = "/var/dgl/"; | 
| 157 
e7f809f06c5c
Use posix.getpwnam() to look up UID/GID to drop to.
 John "Elwin" Edwards parents: 
156diff
changeset | 20 var dropToUser = "rodney"; | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 21 var serveStaticRoot = "/var/www/"; // inside the chroot | 
| 30 
b5570a594266
rlgwebd.js: listen on any address
 John "Elwin" Edwards <elwin@sdf.org> parents: 
29diff
changeset | 22 | 
| 39 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
37diff
changeset | 23 /* Data on the games available. */ | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 24 var games = { | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 25 "rogue3": { | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 26 "name": "Rogue V3", | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 27 "uname": "rogue3", | 
| 42 
8f6bc0df58fa
rlgwebd.js: add a player status interface.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
40diff
changeset | 28 "suffix": ".r3sav", | 
| 144 
81a8e7aa4687
RLGWebD: game binaries have moved to /usr/bin.
 John "Elwin" Edwards parents: 
142diff
changeset | 29 "path": "/usr/bin/rogue3", | 
| 60 
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
55diff
changeset | 30 "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 | 31 }, | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 32 "rogue4": { | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 33 "name": "Rogue V4", | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 34 "uname": "rogue4", | 
| 42 
8f6bc0df58fa
rlgwebd.js: add a player status interface.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
40diff
changeset | 35 "suffix": ".r4sav", | 
| 144 
81a8e7aa4687
RLGWebD: game binaries have moved to /usr/bin.
 John "Elwin" Edwards parents: 
142diff
changeset | 36 "path": "/usr/bin/rogue4", | 
| 60 
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
55diff
changeset | 37 "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 | 38 }, | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 39 "rogue5": { | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 40 "name": "Rogue V5", | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 41 "uname": "rogue5", | 
| 42 
8f6bc0df58fa
rlgwebd.js: add a player status interface.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
40diff
changeset | 42 "suffix": ".r5sav", | 
| 144 
81a8e7aa4687
RLGWebD: game binaries have moved to /usr/bin.
 John "Elwin" Edwards parents: 
142diff
changeset | 43 "path": "/usr/bin/rogue5", | 
| 60 
31bb3cf4f25f
Make sure watchers start with completely drawn screens.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
55diff
changeset | 44 "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 | 45 }, | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 46 "srogue": { | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 47 "name": "Super-Rogue", | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 48 "uname": "srogue", | 
| 42 
8f6bc0df58fa
rlgwebd.js: add a player status interface.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
40diff
changeset | 49 "suffix": ".srsav", | 
| 144 
81a8e7aa4687
RLGWebD: game binaries have moved to /usr/bin.
 John "Elwin" Edwards parents: 
142diff
changeset | 50 "path": "/usr/bin/srogue", | 
| 121 
077adfeea038
Correct the clear sequence for srogue.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
120diff
changeset | 51 "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: 
113diff
changeset | 52 }, | 
| 
54979d35611a
Add support for Advanced Rogue 5.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
113diff
changeset | 53 "arogue5": { | 
| 
54979d35611a
Add support for Advanced Rogue 5.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
113diff
changeset | 54 "name": "Advanced Rogue 5", | 
| 
54979d35611a
Add support for Advanced Rogue 5.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
113diff
changeset | 55 "uname": "arogue5", | 
| 
54979d35611a
Add support for Advanced Rogue 5.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
113diff
changeset | 56 "suffix": ".ar5sav", | 
| 144 
81a8e7aa4687
RLGWebD: game binaries have moved to /usr/bin.
 John "Elwin" Edwards parents: 
142diff
changeset | 57 "path": "/usr/bin/arogue5", | 
| 120 
54979d35611a
Add support for Advanced Rogue 5.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
113diff
changeset | 58 "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 | 59 } | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 60 }; | 
| 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 61 | 
| 39 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
37diff
changeset | 62 /* Global state */ | 
| 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
37diff
changeset | 63 var logins = {}; | 
| 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
37diff
changeset | 64 var sessions = {}; | 
| 156 
127f9e256d02
Keep a list of dgamelaunch games and put it in the /status message.
 John "Elwin" Edwards parents: 
155diff
changeset | 65 var dglgames = {}; | 
| 39 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
37diff
changeset | 66 var allowlogin = true; | 
| 104 
7d444ba4739e
RLG-Web server: send status events over WebSockets.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
103diff
changeset | 67 var gamemux = new events.EventEmitter(); | 
| 39 
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
37diff
changeset | 68 | 
| 55 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 69 /* Constructor. A TermSession handles a pty and the game running on it. | 
| 169 
6f4b7e1b32e8
rlgwebd.js: clean up TermSession parameters.
 John "Elwin" Edwards parents: 
168diff
changeset | 70 * gname: (String) Name of the game to launch. | 
| 
6f4b7e1b32e8
rlgwebd.js: clean up TermSession parameters.
 John "Elwin" Edwards parents: 
168diff
changeset | 71 * pname: (String) The player's name. | 
| 55 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 72 * dims: (Array [Number, Number]) Height and width of the pty. | 
| 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 73 * handlers: (Object) Key-value pairs, event names and functions to | 
| 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 74 * install to handle them. | 
| 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 75 * Events: | 
| 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 76 * "data": Data generated by child. Parameters: buf (Buffer) | 
| 87 
bd2cf6dda28d
RLG-Web: use the pty module.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
85diff
changeset | 77 * "exit": Child terminated. Parameters: none | 
| 0 
bd412f63ce0d
Put this project under version control, finally.
 John "Elwin" Edwards <elwin@sdf.org> parents: diff
changeset | 78 */ | 
| 169 
6f4b7e1b32e8
rlgwebd.js: clean up TermSession parameters.
 John "Elwin" Edwards parents: 
168diff
changeset | 79 function TermSession(gname, pname, dims, handlers) { | 
| 55 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff
changeset | 80 var ss = this; | 
| 
96815eae4ebe
RLG-Web: make multiple watchers possible.
 John "Elwin" Edwards <elwin@sdf.org> parents: 
49diff | 
