Mercurial > hg > rlgwebd
annotate rlgterm.js @ 192:addc4e3456c4
Begin adding systemd compatibility.
The Makefile can be used to build and install rlgwebd. On systems with
systemd, the unit file controls starting and stopping the service, and
the shell script is not needed.
The unit file uses KillMode=none because socat does not actually stop
rlgwebd, it only asks it to stop and exits without waiting for a
response. Until a better stopping method is introduced, this setting
prevents systemd from killing all the rlgwebd processes as soon as
socat exits.
author | John "Elwin" Edwards |
---|---|
date | Fri, 01 Jan 2016 16:11:34 -0500 |
parents | 9758ca68e7f1 |
children | f3843245a35e |
rev | line source |
---|---|
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
1 /* rlgterm.js: Roguelike Gallery's driver for termemu.js */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
2 |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
3 /* Data on the available games. */ |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
4 var games = { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
5 "rogue3": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
6 "name": "Rogue V3", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
7 "uname": "rogue3" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
8 }, |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
9 "rogue4": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
10 "name": "Rogue V4", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
11 "uname": "rogue4" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
12 }, |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
13 "rogue5": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
14 "name": "Rogue V5", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
15 "uname": "rogue5" |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
16 }, |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
17 "srogue": { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
18 "name": "Super-Rogue", |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
19 "uname": "srogue" |
120
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
118
diff
changeset
|
20 }, |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
118
diff
changeset
|
21 "arogue5": { |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
118
diff
changeset
|
22 "name": "Advanced Rogue 5", |
54979d35611a
Add support for Advanced Rogue 5.
John "Elwin" Edwards <elwin@sdf.org>
parents:
118
diff
changeset
|
23 "uname": "arogue5" |
191
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
24 }, |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
25 "arogue7": { |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
26 "name": "Advanced Rogue 7", |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
27 "uname": "arogue7" |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
28 }, |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
29 "xrogue": { |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
30 "name": "XRogue", |
9758ca68e7f1
Add support for Advanced Rogue 7 and XRogue.
John "Elwin" Edwards
parents:
187
diff
changeset
|
31 "uname": "xrogue" |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
32 } |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
33 }; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
34 |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
35 var session = { |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
36 /* The session id assigned by the server. */ |
159 | 37 connect: false, |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
38 /* Login name and key are now in sessionStorage. */ |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
39 /* Whether the game is being played or just watched. */ |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
40 playing: false, |
186
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
41 /* If watching, the name of the player. */ |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
42 playername: null, |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
43 /* Whether the Stop button was pushed. */ |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
44 leaving: false, |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
45 /* WebSocket for communication */ |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
46 sock: null |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
47 }; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
48 |
73
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
49 /* The interval ID for checking the status of current games. */ |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
50 var statInterval = null; |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
51 /* How frequently to check. */ |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
52 var statDelta = 8000; |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
53 /* A WebSocket to listen for status events. */ |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
54 var statsock = null; |
163
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
55 /* List of currently active games. */ |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
56 var currentList = []; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
57 /* Last time the list was updated. */ |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
58 var currentTS = null; |
73
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
59 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
60 function writeData(hexstr) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
61 var codenum; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
62 var codes = []; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
63 var nc; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
64 var u8wait = 0; /* Stores bits from previous bytes of multibyte sequences. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
65 var expect = 0; /* The number of 10------ bytes expected. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
66 /* UTF-8 translation. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
67 for (var i = 0; i < hexstr.length; i += 2) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
68 nc = Number("0x" + hexstr.substr(i, 2)); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
69 if (nc < 0x7F) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
70 /* 0------- */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
71 codes.push(nc); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
72 /* Any incomplete sequence will be discarded. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
73 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
74 expect = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
75 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
76 else if (nc < 0xC0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
77 /* 10------ : part of a multibyte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
78 if (expect > 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
79 u8wait <<= 6; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
80 u8wait += (nc & 0x3F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
81 expect--; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
82 if (expect == 0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
83 codes.push(u8wait); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
84 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
85 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
86 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
87 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
88 /* Assume an initial byte was missed. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
89 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
90 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
91 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
92 /* These will all discard any incomplete sequence. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
93 else if (nc < 0xE0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
94 /* 110----- : introduces 2-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
95 u8wait = (nc & 0x1F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
96 expect = 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
97 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
98 else if (nc < 0xF0) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
99 /* 1110---- : introduces 3-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
100 u8wait = (nc & 0x0F); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
101 expect = 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
102 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
103 else if (nc < 0xF8) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
104 /* 11110--- : introduces 4-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
105 u8wait = (nc & 0x07); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
106 expect = 3; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
107 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
108 else if (nc < 0xFC) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
109 /* 111110-- : introduces 5-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
110 u8wait = (nc & 0x03); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
111 expect = 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
112 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
113 else if (nc < 0xFE) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
114 /* 1111110- : introduces 6-byte sequence */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
115 u8wait = (nc & 0x01); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
116 expect = 5; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
117 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
118 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
119 /* 1111111- : should never appear */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
120 u8wait = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
121 expect = 0; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
122 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
123 /* Supporting all 31 bits is probably overkill... */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
124 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
125 termemu.write(codes); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
126 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
127 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
128 |
75
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
129 function errHandler() { |
96
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
130 message("Unable to connect to the server.", "warn"); |
75
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
131 } |
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
132 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
133 function sendback(str) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
134 /* For responding to terminal queries. */ |
159 | 135 if (session.sock) { |
136 session.sock.send(JSON.stringify({"t": "d", "d": str})); | |
137 } | |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
138 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
139 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
140 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
141 function sendkey(ev) { |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
142 if (!session.playing) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
143 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
144 var keynum = ev.keyCode; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
145 var code; |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
67
diff
changeset
|
146 if (keynum >= 65 && keynum <= 90) { |
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
67
diff
changeset
|
147 /* Letters. */ |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
148 if (ev.ctrlKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
149 keynum -= 64; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
150 else if (!ev.shiftKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
151 keynum += 32; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
152 code = keynum.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
153 if (code.length < 2) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
154 code = "0" + code; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
155 } |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
67
diff
changeset
|
156 else if (keynum >= 48 && keynum <= 57) { |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
157 /* The number row, NOT the numpad. */ |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
158 if (ev.shiftKey) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
159 code = numShifts[keynum - 48].toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
160 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
161 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
162 code = keynum.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
163 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
164 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
165 else if (keynum in keyHexCodes) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
166 if (ev.shiftKey) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
167 code = keyHexCodes[keynum][1]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
168 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
169 code = keyHexCodes[keynum][0]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
170 } |
70
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
67
diff
changeset
|
171 else if (keynum >= 16 && keynum <= 20) { |
d7eb63cd7a16
Try to get some compatibility for keys.
John "Elwin" Edwards <elwin@sdf.org>
parents:
67
diff
changeset
|
172 /* Shift, Cntl, Alt, CAPSLOCK */ |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
173 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
174 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
175 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
176 debug(1, "Ignoring keycode " + keynum); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
177 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
178 } |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
179 ev.preventDefault(); |
108
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
180 if (session.sock) { |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
181 session.sock.send(JSON.stringify({"t": "d", "d": code})); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
182 } |
159 | 183 /* Otherwise it is disconnected */ |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
184 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
185 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
186 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
187 var charshifts = { '-': "5f", '=': "2b", '[': "7b", ']': "7d", '\\': "7c", |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
188 ';': "3a", '\'': "22", ',': "3c", '.': "3e", '/': "3f", '`': "7e" |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
189 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
190 |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
191 var kpkeys = { "KP1": "1b4f46", "KP2": "1b4f42", "KP3": "1b5b367e", |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
192 "KP4": "1b4f44", "KP5": "1b5b45", "KP6": "1b4f43", |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
193 "KP7": "1b4f48", "KP8": "1b4f41", "KP9": "1b5b357e" }; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
194 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
195 function vkey(c) { |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
196 if (!session.playing) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
197 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
198 var keystr; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
199 if (c.match(/^[a-z]$/)) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
200 if (termemu.ctrlp()) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
201 var n = c.charCodeAt(0) - 96; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
202 keystr = n.toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
203 if (keystr.length < 2) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
204 keystr = "0" + keystr; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
205 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
206 else if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
207 keystr = c.toUpperCase().charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
208 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
209 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
210 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
211 else if (c.match(/^[0-9]$/)) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
212 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
213 keystr = numShifts[c.charCodeAt(0) - 48].toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
214 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
215 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
216 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
217 else if (c == '\n') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
218 keystr = "0a"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
219 else if (c == '\t') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
220 keystr = "09"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
221 else if (c == '\b') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
222 keystr = "08"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
223 else if (c == ' ') |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
224 keystr = "20"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
225 else if (c in charshifts) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
226 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
227 keystr = charshifts[c]; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
228 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
229 keystr = c.charCodeAt(0).toString(16); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
230 } |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
231 else if (c in kpkeys) { |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
232 keystr = kpkeys[c]; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
233 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
234 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
235 return; |
108
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
236 if (session.sock) { |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
237 session.sock.send(JSON.stringify({"t": "d", "d": keystr})); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
238 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
239 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
240 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
241 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
242 function setup() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
243 keyHexCodes.init(); |
4
ee22eb9ab009
Client: don't assume the terminal is 24x80.
John "Elwin" Edwards <elwin@sdf.org>
parents:
0
diff
changeset
|
244 termemu.init("termwrap", 24, 80); |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
245 /* Is someone already logged in? */ |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
246 if ("lcred" in sessionStorage) { |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
247 setmode("choose"); |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
248 message("You are logged in as " + sessionStorage.getItem("lname") + "."); |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
249 } |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
250 else |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
251 setmode("login"); |
78
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
252 /* Set up the text size. */ |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
253 var cssSize = termemu.view.style.fontSize; |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
254 var match = cssSize.match(/\d*/); |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
255 if (!match) { |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
256 return; |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
257 } |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
258 var csize = Number(match[0]); |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
259 var allscreen = document.getElementById("termwrap"); |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
260 while (csize > 9 && csize < 48) { |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
261 if (allscreen.scrollWidth * 1.2 > window.innerWidth) { |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
262 csize = textsize(false); |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
263 } |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
264 else if (allscreen.scrollWidth * 2 < window.innerWidth) { |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
265 csize = textsize(true); |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
266 } |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
267 else |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
268 break; |
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
269 } |
116
d7d7cdcba3b4
Fix WebSocket support checking.
John "Elwin" Edwards <elwin@sdf.org>
parents:
112
diff
changeset
|
270 if (!window.WebSocket) { |
159 | 271 message("Your browser does not support WebSockets. " + |
272 "This Web app will not work.", "warn"); | |
109
67b393f10c2b
RLG-Web: improve taking over sessions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
108
diff
changeset
|
273 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
274 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
275 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
276 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
277 function toggleshift() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
278 termemu.toggleshift(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
279 keydiv = document.getElementById("shiftkey"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
280 if (termemu.shiftp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
281 keydiv.className = "keysel"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
282 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
283 keydiv.className = "key"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
284 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
285 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
286 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
287 function togglectrl() { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
288 termemu.togglectrl(); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
289 keydiv = document.getElementById("ctrlkey"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
290 if (termemu.ctrlp()) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
291 keydiv.className = "keysel"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
292 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
293 keydiv.className = "key"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
294 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
295 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
296 |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
297 function formlogin(ev) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
298 ev.preventDefault(); |
159 | 299 /* What to do if logged in already? */ |
16
ef6127ed6da3
RLGWeb: switch to JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
300 var loginmsg = {}; |
ef6127ed6da3
RLGWeb: switch to JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
301 loginmsg["name"] = document.getElementById("input_name").value; |
ef6127ed6da3
RLGWeb: switch to JSON protocol.
John "Elwin" Edwards <elwin@sdf.org>
parents:
9
diff
changeset
|
302 loginmsg["pw"] = document.getElementById("input_pw").value; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
303 var req = new XMLHttpRequest(); |
75
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
304 req.onerror = errHandler; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
305 req.onreadystatechange = function () { |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
306 if (req.readyState != 4 || req.status != 200) |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
307 return; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
308 var reply = JSON.parse(req.responseText); |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
309 if (reply.t == 'l') { |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
310 /* Success */ |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
311 sessionStorage.setItem("lcred", reply.k); |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
312 sessionStorage.setItem("lname", reply.u); |
89
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
313 message("You are now logged in as " + reply.u + "."); |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
314 setmode("choose"); |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
315 } |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
316 else if (reply.t == 'E') { |
96
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
317 var failmsg = "Logging in failed. "; |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
318 if (reply.c == 2) |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
319 failmsg += reply.s.match(/Invalid data: (.*)/)[1]; |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
320 else if (reply.c == 3) |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
321 failmsg += "The username or password was incorrect."; |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
322 else if (reply.c == 6) |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
323 failmsg += "The server is shutting down."; |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
324 message(failmsg, "warn"); |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
325 document.getElementById("input_name").value = ""; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
326 document.getElementById("input_pw").value = ""; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
327 } |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
328 }; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
329 req.open('POST', '/login', true); |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
330 req.send(JSON.stringify(loginmsg)); |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
331 return; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
332 } |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
333 |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
334 function tableCurrent(gamelist) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
335 var gamediv = document.getElementById("gametable"); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
336 while (gamediv.children.length > 2) |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
337 gamediv.removeChild(gamediv.children[2]); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
338 if (gamelist.length === 0) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
339 gamediv.style.display = "none"; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
340 document.getElementById("nogames").style.display = "block"; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
341 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
342 else { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
343 gamediv.style.display = "table"; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
344 document.getElementById("nogames").style.display = "none"; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
345 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
346 for (var i = 0; i < gamelist.length; i++) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
347 var row = document.createElement("div"); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
348 var cell1 = document.createElement("div"); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
349 var cell2 = document.createElement("div"); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
350 var cell3 = document.createElement("div"); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
351 var cell4 = document.createElement("div"); |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
352 var cell5 = document.createElement("div"); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
353 cell1.appendChild(document.createTextNode(gamelist[i].p)); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
354 var uname = gamelist[i].g; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
355 if (uname in games) |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
356 cell2.appendChild(document.createTextNode(games[uname].name)); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
357 else { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
358 continue; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
359 } |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
360 var srcstr = "VR"; |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
361 if (gamelist[i].c == "rlg") |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
362 srcstr = "Web"; |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
363 else if (gamelist[i].c == "dgl") |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
364 srcstr = "SSH"; |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
365 cell3.appendChild(document.createTextNode(srcstr)); |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
366 cell4.appendChild(document.createTextNode(idlestr(gamelist[i].i))); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
367 var button = document.createElement("span"); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
368 button.appendChild(document.createTextNode("Watch")); |
161 | 369 button.onclick = makeWatcher(uname + "/" + gamelist[i].p); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
370 button.className = "ibutton"; |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
371 cell5.appendChild(button); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
372 row.appendChild(cell1); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
373 row.appendChild(cell2); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
374 row.appendChild(cell3); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
375 row.appendChild(cell4); |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
376 row.appendChild(cell5); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
377 gamediv.appendChild(row); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
378 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
379 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
380 |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
381 /* Handles the status socket, opening and closing it when necessary. */ |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
382 function wsCurrent() { |
116
d7d7cdcba3b4
Fix WebSocket support checking.
John "Elwin" Edwards <elwin@sdf.org>
parents:
112
diff
changeset
|
383 if (!window.WebSocket) |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
384 return; |
159 | 385 if (session.connect) { |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
386 /* Don't bother with status if already playing/watching. */ |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
387 if (statsock) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
388 statsock.close(); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
389 statsock = null; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
390 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
391 return; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
392 } |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
393 if ("lcred" in sessionStorage) { |
112
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
394 /* When starting the socket, the choices list might not be initialized. */ |
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
395 getchoices(); |
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
396 } |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
397 if (statsock) |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
398 return; |
106
dc1414faee19
RLG-Web client: determine the host for WebSocket connections.
John "Elwin" Edwards <elwin@sdf.org>
parents:
105
diff
changeset
|
399 statsock = new WebSocket("ws://" + window.location.host + "/status"); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
400 statsock.onmessage = function (ev) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
401 var msg; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
402 try { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
403 msg = JSON.parse(ev.data); |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
404 } catch (e) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
405 if (e instanceof SyntaxError) |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
406 return; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
407 } |
112
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
408 if (msg.t == "t") { |
163
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
409 currentList = msg.g; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
410 currentTS = new Date(); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
411 tableCurrent(currentList); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
412 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
413 else if (msg.t == "p") { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
414 var now = new Date(); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
415 var idletimes = {}; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
416 for (var i = 0; i < msg.g.length; i++) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
417 var tag = msg.g[i].g + "/" + msg.g[i].p; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
418 idletimes[tag] = msg.g[i].i; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
419 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
420 for (var i = 0; i < currentList.length; i++) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
421 var tag = currentList[i].g + "/" + currentList[i].p; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
422 if (tag in idletimes) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
423 currentList[i].i = idletimes[tag]; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
424 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
425 else { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
426 currentList[i].i += now - currentTS; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
427 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
428 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
429 currentTS = now; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
430 tableCurrent(currentList); |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
431 } |
163
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
432 else if (msg.t == "b") { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
433 var justbegun = {}; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
434 justbegun.g = msg.g; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
435 justbegun.p = msg.p; |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
436 justbegun.c = msg.c; |
163
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
437 justbegun.i = 0; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
438 currentList.push(justbegun); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
439 tableCurrent(currentList); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
440 if (msg.p == sessionStorage.getItem("lname")) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
441 getchoices(); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
442 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
443 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
444 else if (msg.t == "e") { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
445 var i = 0; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
446 while (i < currentList.length) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
447 if (currentList[i].g == msg.g && currentList[i].p == msg.p) |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
448 break; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
449 i++; |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
450 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
451 if (i < currentList.length) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
452 currentList.splice(i, 1); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
453 } |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
454 tableCurrent(currentList); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
455 if (msg.p == sessionStorage.getItem("lname")) { |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
456 getchoices(); |
0f6da35b27a0
RLGWebD: overhaul the list of current games.
John "Elwin" Edwards
parents:
161
diff
changeset
|
457 } |
112
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
458 } |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
459 }; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
460 statsock.onclose = function (ev) { |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
461 statsock = null; |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
462 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
463 } |
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
464 |
159 | 465 /* FIXME gamelist API has changed */ |
73
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
466 function getcurrent(clear) { |
116
d7d7cdcba3b4
Fix WebSocket support checking.
John "Elwin" Edwards <elwin@sdf.org>
parents:
112
diff
changeset
|
467 if (window.WebSocket) { |
112
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
468 return; |
4f2b89e6fde2
RLG-Web: improvements to choices and status messaging.
John "Elwin" Edwards <elwin@sdf.org>
parents:
111
diff
changeset
|
469 } |
159 | 470 if (session.connect || clear) { |
73
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
471 if (statInterval) { |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
472 window.clearInterval(statInterval); |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
473 statInterval = null; |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
474 } |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
475 return; |
73
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
476 } |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
477 if (!statInterval) { |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
478 statInterval = window.setInterval(getcurrent, statDelta); |
d084610a89b5
Automatically update the lists of current games and actions.
John "Elwin" Edwards <elwin@sdf.org>
parents:
70
diff
changeset
|
479 } |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
480 if ("lcred" in sessionStorage) |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
481 getchoices(); |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
482 var req = new XMLHttpRequest(); |
75
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
483 req.onerror = errHandler; |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
484 req.onreadystatechange = function () { |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
485 if (req.readyState != 4 || req.status != 200) |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
486 return; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
487 var reply; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
488 try { |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
489 reply = JSON.parse(req.responseText); |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
490 } catch (e) { |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
491 if (e instanceof SyntaxError) |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
492 return; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
493 } |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
494 if (!reply.s) { |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
495 return; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
496 } |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
497 tableCurrent(reply.g); |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
498 }; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
499 req.open('GET', '/status', true); |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
500 req.send(); |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
501 return; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
502 } |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
503 |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
504 function getchoices() { |
159 | 505 if (session.connect || !("lcred" in sessionStorage)) |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
506 return; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
507 var req = new XMLHttpRequest(); |
75
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
508 req.onerror = errHandler; |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
509 req.onreadystatechange = function () { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
510 if (req.readyState != 4 || req.status != 200) |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
511 return; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
512 var reply; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
513 try { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
514 reply = JSON.parse(req.responseText); |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
515 } catch (e) { |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
516 if (e instanceof SyntaxError) |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
517 return; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
518 } |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
519 if (!("name" in reply) || reply["name"] != sessionStorage.getItem("lname") |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
520 || !("stat" in reply)) |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
521 return; |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
522 var optdiv = document.getElementById("opttable"); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
523 /* Don't remove the first child, it's the header. */ |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
524 while (optdiv.childNodes.length > 1) |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
525 optdiv.removeChild(optdiv.childNodes[1]); |
64
e3082fd06520
Some status improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
63
diff
changeset
|
526 for (var gname in games) { |
e3082fd06520
Some status improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
63
diff
changeset
|
527 if (!(gname in reply.stat)) |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
528 continue; |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
529 var acttext; |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
530 if (reply.stat[gname] == "s") |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
531 acttext = "Resume your game"; |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
532 else if (reply.stat[gname] == "0") |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
533 acttext = "Start a game"; |
111
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
534 else if (reply.stat[gname] == "p" || reply.stat[gname] == "d") |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
535 acttext = "Force save"; |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
536 else |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
537 continue; |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
538 var button = document.createElement("span"); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
539 button.appendChild(document.createTextNode(acttext)); |
111
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
540 if ("s0".indexOf(reply.stat[gname]) >= 0) { |
46
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
541 button.onclick = makeStarter(gname); |
51
2eda3909f6a3
rlgterm.js: don't make nonfunctional button.
John "Elwin" Edwards <elwin@sdf.org>
parents:
47
diff
changeset
|
542 button.className = "ibutton"; |
46
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
543 } |
111
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
544 else { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
545 button.onclick = makeStopper(gname); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
546 button.className = "ibutton"; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
547 } |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
548 var actdiv = document.createElement("div"); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
549 actdiv.appendChild(button); |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
550 var gamediv = document.createElement("div"); |
45
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
551 gamediv.appendChild(document.createTextNode(games[gname].name)); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
552 var rowdiv = document.createElement("div"); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
553 rowdiv.appendChild(gamediv); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
554 rowdiv.appendChild(actdiv); |
1bbd0e76ba92
RLG-Web: put the game options into a table.
John "Elwin" Edwards <elwin@sdf.org>
parents:
44
diff
changeset
|
555 optdiv.appendChild(rowdiv); |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
556 } |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
557 }; |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
558 req.open('GET', '/pstatus/' + sessionStorage.getItem("lname"), true); |
44
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
559 req.send(); |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
560 return; |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
561 } |
b848cb50cd69
rlgterm.js: present game options to the player.
John "Elwin" Edwards <elwin@sdf.org>
parents:
41
diff
changeset
|
562 |
46
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
563 /* This can't be in the loop in getchoices(), or the closure's scope will |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
564 * get overwritten on the next iteration, and then all the games end up |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
565 * being Super-Rogue. |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
566 */ |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
567 function makeStarter(gname) { |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
568 if (!(gname in games)) |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
569 return null; |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
570 var game = games[gname]; |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
571 function starter(ev) { |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
572 startgame(game); |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
573 } |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
574 return starter; |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
575 } |
59ecd99845eb
rlgterm.js: make the options table functional.
John "Elwin" Edwards <elwin@sdf.org>
parents:
45
diff
changeset
|
576 |
111
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
577 function makeStopper(gname) { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
578 if (!(gname in games)) |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
579 return null; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
580 var game = games[gname]; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
581 function stopper(ev) { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
582 stopgame(game); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
583 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
584 return stopper; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
585 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
586 |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
587 function stopgame(game) { |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
588 if (!("lcred" in sessionStorage)) |
111
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
589 return; |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
590 var stopmsg = {"key": sessionStorage.getItem("lcred"), "g": game.uname}; |
111
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
591 var req = new XMLHttpRequest(); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
592 req.onerror = errHandler; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
593 req.onreadystatechange = function () { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
594 if (req.readyState != 4 || req.status != 200) |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
595 return; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
596 var reply = JSON.parse(req.responseText); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
597 if (reply.t == 'E') { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
598 if (reply.c == 7) |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
599 message("That game has already stopped."); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
600 else if (reply.c == 1) { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
601 logout(); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
602 message("The server forgot about you, please log in again.", "warn"); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
603 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
604 else { |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
605 message("That game could not be stopped because: " + reply.s + |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
606 "This might be a bug.", "warn"); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
607 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
608 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
609 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
610 req.open('POST', '/quit', true); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
611 req.send(JSON.stringify(stopmsg)); |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
612 return; |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
613 } |
f56fdfeed01a
Replace taking over games with forced saves.
John "Elwin" Edwards <elwin@sdf.org>
parents:
109
diff
changeset
|
614 |
159 | 615 function startgame(game) { |
616 if (!("lcred" in sessionStorage) || session.connect) | |
617 return; | |
618 if (!window.WebSocket) { | |
619 return; | |
620 } | |
108
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
621 var sockurl = "ws://" + window.location.host + "/play/" + game.uname; |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
622 sockurl += "?key=" + sessionStorage.getItem("lcred") + "&w=80&h=24"; |
108
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
623 ws = new WebSocket(sockurl); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
624 ws.onopen = function (event) { |
159 | 625 session.connect = true; |
108
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
626 session.playing = true; |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
627 session.sock = ws; |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
628 setmode("play"); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
629 }; |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
630 ws.onmessage = function (event) { |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
631 var msgObject = JSON.parse(event.data); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
632 if (msgObject.t == 's') { |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
633 termemu.resize(msgObject.h, msgObject.w); |
118
56a756695740
rlgterm.js: display the game's proper name when starting.
John "Elwin" Edwards <elwin@sdf.org>
parents:
116
diff
changeset
|
634 message("You are now playing " + games[msgObject.g].name + "."); |
108
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
635 } |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
636 else if (msgObject.t == 'd') { |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
637 writeData(msgObject.d); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
638 } |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
639 }; |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
640 ws.onclose = function (event) { |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
641 session.sock = null; |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
642 gameover(); |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
643 }; |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
644 } |
86a458080e80
RLG-Web client: add playing through WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
106
diff
changeset
|
645 |
159 | 646 function makeWatcher(t) { |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
647 function watcher(ev) { |
159 | 648 startwatching(t); |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
649 } |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
650 return watcher; |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
651 } |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
652 |
159 | 653 function startwatching(tag) { |
654 if (session.connect) | |
655 return; | |
656 var sockurl = "ws://" + window.location.host + "/watch/" + tag; | |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
657 var ws = new WebSocket(sockurl); |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
658 ws.onopen = function (event) { |
159 | 659 session.connect = true; |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
660 session.sock = ws; |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
661 setmode("watch"); |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
662 }; |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
663 ws.onmessage = function (event) { |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
664 var msgObject = JSON.parse(event.data); |
101
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
665 if (msgObject.t == 'w') { |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
666 termemu.resize(msgObject.h, msgObject.w); |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
667 termemu.reset(); |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
668 termemu.toAltBuf(); |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
669 var pname = msgObject.p; |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
670 var gname = games[msgObject.g].name; |
186
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
671 session.playername = pname; |
101
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
672 message("You are now watching " + pname + " play " + gname + "."); |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
673 } |
e59d68082664
RLG-Web: Complete the WebSocket watcher.
John "Elwin" Edwards <elwin@sdf.org>
parents:
100
diff
changeset
|
674 else if (msgObject.t == 'd') { |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
675 writeData(msgObject.d); |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
676 } |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
677 }; |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
678 ws.onclose = function (event) { |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
679 session.sock = null; |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
680 gameover(); |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
681 }; |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
682 } |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
683 |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
684 function formreg(ev) { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
685 ev.preventDefault(); |
159 | 686 /* This ought to check for being logged in instead. */ |
687 if (session.connect) | |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
688 return; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
689 var regmsg = {}; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
690 regmsg["name"] = document.getElementById("regin_name").value; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
691 regmsg["pw"] = document.getElementById("regin_pw").value; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
692 regmsg["email"] = document.getElementById("regin_email").value; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
693 var req = new XMLHttpRequest(); |
75
2984604ce3e6
Begin handling XMLHttpRequest errors.
John "Elwin" Edwards <elwin@sdf.org>
parents:
73
diff
changeset
|
694 req.onerror = errHandler; |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
695 req.onreadystatechange = function () { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
696 if (req.readyState != 4 || req.status != 200) |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
697 return; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
698 var reply = JSON.parse(req.responseText); |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
699 if (reply.t == 'r') { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
700 /* Success */ |
89
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
701 message("Welcome " + reply.u + ", you are now registered."); |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
702 sessionStorage.setItem("lcred", reply.k); |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
703 sessionStorage.setItem("lname", reply.u); |
89
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
704 message("You are now logged in as " + reply.u + "."); |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
705 setmode("choose"); |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
706 } |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
707 else if (reply.t == 'E') { |
93
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
708 var failmsg = "Registration failed."; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
709 if (reply.c == 2) { |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
710 var errdesc = reply.s.match(/Invalid data: (.*)/)[1]; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
711 if (errdesc.match(/No name/)) |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
712 failmsg += " You need to choose a name."; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
713 else if (errdesc.match(/No password/)) |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
714 failmsg += " You need to choose a password."; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
715 else if (errdesc.match(/Invalid/)) { |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
716 failmsg += " Names must be letters and numbers. E-mail addresses " + |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
717 "can also contain these characters: @.-_"; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
718 } |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
719 else if (errdesc.match(/Username/)) |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
720 failmsg += " Someone else is already using that name."; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
721 else |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
722 failmsg += " This is probably a bug."; |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
723 } |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
724 else |
104409bf5f03
rlgterm.js: improve registration failure messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
92
diff
changeset
|
725 failmsg += " This is probably a bug."; |
96
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
726 message(failmsg, "warn"); |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
727 document.getElementById("regin_name").value = ""; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
728 document.getElementById("regin_pw").value = ""; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
729 document.getElementById("regin_email").value = ""; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
730 } |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
731 }; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
732 req.open('POST', '/addacct', true); |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
733 req.send(JSON.stringify(regmsg)); |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
734 return; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
735 } |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
736 |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
737 function gameover() { |
159 | 738 if (!session.connect) |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
739 return; |
38
b06a14876645
RLG-Web: reduce polling further.
John "Elwin" Edwards <elwin@sdf.org>
parents:
35
diff
changeset
|
740 /* TODO IFACE2 If the end was unexpected, tell player the game was saved. */ |
186
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
741 if (session.playing) { |
90
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
742 message("Finished playing."); |
186
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
743 } |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
744 else { |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
745 if (session.leaving) { |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
746 /* Client-initiated: the user stopped watching. */ |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
747 message("Finished watching " + session.playername + "."); |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
748 } |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
749 else { |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
750 /* Server-initiated: end of game. */ |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
751 message(session.playername + " has finished playing."); |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
752 } |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
753 session.playername = null; |
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
754 } |
159 | 755 session.connect = false; |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
756 session.playing = false; |
186
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
757 session.leaving = false; |
61
071ec6b1ec03
RLG-Web client: initialize and restore the terminal when watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
59
diff
changeset
|
758 termemu.toNormBuf(); |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
759 if ("lcred" in sessionStorage) |
59
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
760 setmode("choose"); |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
761 else |
00b985b8ba6a
RLG-Web client: implement watching.
John "Elwin" Edwards <elwin@sdf.org>
parents:
58
diff
changeset
|
762 setmode("login"); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
763 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
764 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
765 |
47
27b7f0c8b9f0
RLG-Web: make login sessions time out.
John "Elwin" Edwards <elwin@sdf.org>
parents:
46
diff
changeset
|
766 function logout() { |
127
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
767 sessionStorage.removeItem("lcred"); |
e54018b26ed8
RLG-Web client: store login key in DOM Storage.
John "Elwin" Edwards <elwin@sdf.org>
parents:
120
diff
changeset
|
768 sessionStorage.removeItem("lname"); |
47
27b7f0c8b9f0
RLG-Web: make login sessions time out.
John "Elwin" Edwards <elwin@sdf.org>
parents:
46
diff
changeset
|
769 setmode("login"); |
27b7f0c8b9f0
RLG-Web: make login sessions time out.
John "Elwin" Edwards <elwin@sdf.org>
parents:
46
diff
changeset
|
770 } |
27b7f0c8b9f0
RLG-Web: make login sessions time out.
John "Elwin" Edwards <elwin@sdf.org>
parents:
46
diff
changeset
|
771 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
772 function stop() { |
159 | 773 if (!session.connect) |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
774 return; |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
775 if (session.sock) { |
186
674e8899703b
Client: improve messages at the end of watching a game.
John "Elwin" Edwards
parents:
176
diff
changeset
|
776 session.leaving = true; |
100
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
777 session.sock.close(); |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
778 return; |
3dbfdaf62623
RLG-Web: begin converting to WebSockets.
John "Elwin" Edwards <elwin@sdf.org>
parents:
97
diff
changeset
|
779 } |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
780 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
781 |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
782 function setmode(mode, ev) { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
783 if (ev) |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
784 ev.preventDefault(); |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
785 if (mode == "play") { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
786 document.getElementById("keyboard").style.display = "block"; |
90
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
787 document.getElementById("playctl").style.display = "block"; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
788 document.getElementById("startgame").style.display = "none"; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
789 document.getElementById("login").style.display = "none"; |
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
790 document.getElementById("register").style.display = "none"; |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
791 document.getElementById("current").style.display = "none"; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
792 } |
90
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
793 else if (mode == "watch") { |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
794 document.getElementById("keyboard").style.display = "none"; |
90
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
795 document.getElementById("playctl").style.display = "block"; |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
796 document.getElementById("startgame").style.display = "none"; |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
797 document.getElementById("login").style.display = "none"; |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
798 document.getElementById("register").style.display = "none"; |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
799 document.getElementById("current").style.display = "none"; |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
800 } |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
801 else if (mode == "choose") { |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
802 document.getElementById("keyboard").style.display = "none"; |
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
803 document.getElementById("playctl").style.display = "none"; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
804 document.getElementById("startgame").style.display = "block"; |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
805 document.getElementById("login").style.display = "none"; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
806 document.getElementById("register").style.display = "none"; |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
807 document.getElementById("current").style.display = "block"; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
808 getcurrent(); |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
809 } |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
810 else if (mode == "login") { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
811 document.getElementById("keyboard").style.display = "none"; |
90
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
812 document.getElementById("playctl").style.display = "none"; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
813 document.getElementById("startgame").style.display = "none"; |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
814 document.getElementById("login").style.display = "block"; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
815 document.getElementById("register").style.display = "none"; |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
816 document.getElementById("current").style.display = "block"; |
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
817 getcurrent(); |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
818 } |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
819 else if (mode == "register") { |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
820 document.getElementById("keyboard").style.display = "none"; |
90
6c6a6e4f1e5b
RLG-Web client: distinguish playing and watching in UI.
John "Elwin" Edwards <elwin@sdf.org>
parents:
89
diff
changeset
|
821 document.getElementById("playctl").style.display = "none"; |
39
e8ac0e3d2614
RLG-Web: separate logging in and starting a game.
John "Elwin" Edwards <elwin@sdf.org>
parents:
38
diff
changeset
|
822 document.getElementById("startgame").style.display = "none"; |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
823 document.getElementById("login").style.display = "none"; |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
824 document.getElementById("register").style.display = "block"; |
56
7f3ca16409fe
RLG-Web client: display a list of current games.
John "Elwin" Edwards <elwin@sdf.org>
parents:
55
diff
changeset
|
825 document.getElementById("current").style.display = "none"; |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
826 } |
105
a9371002aecc
RLG-Web client: use WebSockets for game lists.
John "Elwin" Edwards <elwin@sdf.org>
parents:
101
diff
changeset
|
827 wsCurrent(); |
19
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
828 } |
188bbd857124
RLG-Web: add user registration
John "Elwin" Edwards <elwin@sdf.org>
parents:
16
diff
changeset
|
829 |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
830 function toggleBlock(id) { |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
831 var element = document.getElementById(id); |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
832 if (!element) |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
833 return; |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
834 if (element.style.display != "block") |
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
835 element.style.display = "block"; |
67
b6a3b26fe0dc
RLG-Web client: some visual improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
66
diff
changeset
|
836 else |
76
a497ecd116d9
Improvements to the keyboard.
John "Elwin" Edwards <elwin@sdf.org>
parents:
75
diff
changeset
|
837 element.style.display = "none"; |
67
b6a3b26fe0dc
RLG-Web client: some visual improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
66
diff
changeset
|
838 } |
b6a3b26fe0dc
RLG-Web client: some visual improvements.
John "Elwin" Edwards <elwin@sdf.org>
parents:
66
diff
changeset
|
839 |
96
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
840 function message(msg, mtype) { |
89
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
841 var msgdiv = document.createElement("div"); |
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
842 var msgtext = document.createTextNode(msg); |
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
843 msgdiv.appendChild(msgtext); |
96
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
844 if (mtype) { |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
845 msgdiv.className = mtype; |
7bb634f6995c
RLG-Web client: improvements to UI messages.
John "Elwin" Edwards <elwin@sdf.org>
parents:
94
diff
changeset
|
846 } |
89
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
847 var msgcontainer = document.getElementById("messages"); |
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
848 msgcontainer.insertBefore(msgdiv, msgcontainer.firstChild); |
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
849 } |
6145e1ea7ace
RLG-Web: add a new message framework.
John "Elwin" Edwards <elwin@sdf.org>
parents:
88
diff
changeset
|
850 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
851 function debug(level, msg) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
852 if (level < debugSuppress) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
853 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
854 var msgdiv = document.createElement("div"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
855 var msgtext = document.createTextNode(msg); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
856 msgdiv.appendChild(msgtext); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
857 document.getElementById("debug").appendChild(msgdiv); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
858 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
859 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
860 |
92
a4d3ecf188b7
RLG-Web client: replace setTitle() with message().
John "Elwin" Edwards <elwin@sdf.org>
parents:
91
diff
changeset
|
861 function setTitle(tstr) { |
a4d3ecf188b7
RLG-Web client: replace setTitle() with message().
John "Elwin" Edwards <elwin@sdf.org>
parents:
91
diff
changeset
|
862 message(tstr); |
a4d3ecf188b7
RLG-Web client: replace setTitle() with message().
John "Elwin" Edwards <elwin@sdf.org>
parents:
91
diff
changeset
|
863 } |
a4d3ecf188b7
RLG-Web client: replace setTitle() with message().
John "Elwin" Edwards <elwin@sdf.org>
parents:
91
diff
changeset
|
864 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
865 function textsize(larger) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
866 var cssSize = termemu.view.style.fontSize; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
867 if (!cssSize) { |
78
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
868 return null; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
869 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
870 var match = cssSize.match(/\d*/); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
871 if (!match) { |
78
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
872 return null; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
873 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
874 var csize = Number(match[0]); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
875 var nsize; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
876 if (larger) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
877 if (csize >= 48) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
878 nsize = 48; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
879 else if (csize >= 20) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
880 nsize = csize + 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
881 else if (csize >= 12) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
882 nsize = csize + 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
883 else if (csize >= 8) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
884 nsize = csize + 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
885 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
886 nsize = 8; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
887 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
888 else { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
889 if (csize <= 8) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
890 nsize = 8; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
891 else if (csize <= 12) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
892 nsize = csize - 1; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
893 else if (csize <= 20) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
894 nsize = csize - 2; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
895 else if (csize <= 48) |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
896 nsize = csize - 4; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
897 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
898 nsize = 48; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
899 } |
77
f8bb37f48d58
Make font resizing affect the keyboard too.
John "Elwin" Edwards <elwin@sdf.org>
parents:
76
diff
changeset
|
900 var cssvalstr = nsize.toString() + "px"; |
f8bb37f48d58
Make font resizing affect the keyboard too.
John "Elwin" Edwards <elwin@sdf.org>
parents:
76
diff
changeset
|
901 document.getElementById("term").style.fontSize = cssvalstr; |
f8bb37f48d58
Make font resizing affect the keyboard too.
John "Elwin" Edwards <elwin@sdf.org>
parents:
76
diff
changeset
|
902 document.getElementById("keys").style.fontSize = cssvalstr; |
9
826a7ced69f8
Make the emulator screen resizable.
John "Elwin" Edwards <elwin@sdf.org>
parents:
6
diff
changeset
|
903 termemu.fixsize(); |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
904 debug(1, "Changing font size to " + nsize.toString()); |
78
06375a159188
Try to guess a good text size.
John "Elwin" Edwards <elwin@sdf.org>
parents:
77
diff
changeset
|
905 return nsize; |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
906 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
907 |
66
57bf0dcd080e
Display idle time of games in progress.
John "Elwin" Edwards <elwin@sdf.org>
parents:
65
diff
changeset
|
908 function idlestr(ms) { |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
909 /* Minute accuracy is good enough. */ |
66
57bf0dcd080e
Display idle time of games in progress.
John "Elwin" Edwards <elwin@sdf.org>
parents:
65
diff
changeset
|
910 if (typeof(ms) != "number") |
57bf0dcd080e
Display idle time of games in progress.
John "Elwin" Edwards <elwin@sdf.org>
parents:
65
diff
changeset
|
911 return "?"; |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
912 var minutes = Math.round(ms / 60000); |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
913 if (minutes < 60) |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
914 return String(minutes) + " min"; |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
915 var hours = Math.floor(minutes / 60); |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
916 if (hours < 24) |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
917 return String(hours) + " hr " + String(minutes % 60) + " min"; |
187 | 918 var days = Math.floor(hours / 24); |
176
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
919 if (days == 1) |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
920 return "1 day " + String(hours % 24) + " hr"; |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
921 else |
bf518a00190b
Add client-side support for watching dgamelaunch games.
John "Elwin" Edwards
parents:
163
diff
changeset
|
922 return String(days) + " days " + String(hours % 24) + " hr"; |
66
57bf0dcd080e
Display idle time of games in progress.
John "Elwin" Edwards <elwin@sdf.org>
parents:
65
diff
changeset
|
923 } |
57bf0dcd080e
Display idle time of games in progress.
John "Elwin" Edwards <elwin@sdf.org>
parents:
65
diff
changeset
|
924 |
0
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
925 function bell(on) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
926 var imgnode = document.getElementById("bell"); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
927 if (on) { |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
928 imgnode.style.visibility = "visible"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
929 window.setTimeout(bell, 1500, false); |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
930 } |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
931 else |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
932 imgnode.style.visibility = "hidden"; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
933 return; |
bd412f63ce0d
Put this project under version control, finally.
John "Elwin" Edwards <elwin@sdf.org>
parents:
diff
changeset
|
934 } |