16
16
*/
17
17
18
18
19
- // Everything about the current game state that can be sent in a data packet
20
- // see also reset_game();
19
+ // Everything about the current game state
21
20
var state = {
22
- slots : 32 , // Maximum number of clients
21
+ slots : 32 , // Maximum number of clients
23
22
max_name_length : 25 , // Maximum number of characters in each player's name
24
23
clients : { } , // List of client data
25
24
pieces : { } , // List of piece properties
@@ -36,10 +35,13 @@ var state_keys_no_set = [
36
35
'nameplates' ,
37
36
'hands' ,
38
37
'slots' ,
38
+ 'max_name_length' ,
39
39
] ;
40
40
41
41
42
42
43
+ ///////////////////////////////////////////////// EXTERNAL LIBRARIES
44
+
43
45
// Versions included in external_scripts
44
46
pixi_version = 'pixi.min.js' ;
45
47
howler_version = 'howler.min.js' ;
@@ -51,18 +53,6 @@ var http = require('http').createServer(app); // listening
51
53
var io = require ( 'socket.io' ) ( http ) ; // fast input/output
52
54
var fun = require ( './common/fun' ) ; // My common functions
53
55
54
- // Set the initial state without messing up the clients
55
- function reset_game ( ) {
56
- fun . log_date ( 'Resetting game...' ) ;
57
-
58
- // Reset the key components
59
- state . pieces = { } ;
60
- state . hands = { } ;
61
-
62
- // Now send all the clients this info
63
- for ( id in state . clients ) send_state ( id ) ;
64
- }
65
- reset_game ( ) ;
66
56
67
57
68
58
// port upon which the server listens
@@ -129,10 +119,7 @@ function send_file(response, path) {
129
119
if ( full_path ) response . sendFile ( full_path ) ;
130
120
}
131
121
132
- function html_encode ( s ) {
133
- // Thanks Stack Exchange.
134
- return s . replace ( / [ \u00A0 - \u9999 < > \& ] / gim, function ( i ) { return '&#' + i . charCodeAt ( 0 ) + ';' ; } ) ;
135
- }
122
+
136
123
137
124
138
125
@@ -325,11 +312,8 @@ io.on('connection', function(socket) {
325
312
// Split it by space
326
313
var s = message . split ( ' ' ) ;
327
314
328
- // Reset to defaults
329
- if ( s [ 0 ] == '/reset' ) reset_game ( ) ;
330
-
331
- // Boot client by name
332
- else if ( s [ 0 ] == '/boot' ) {
315
+ // Special commands
316
+ if ( s [ 0 ] == '/boot' ) {
333
317
334
318
// Find the client by name and boot them
335
319
for ( var id in state . clients ) if ( state . clients [ id ] . name == s [ 1 ] ) {
@@ -364,7 +348,7 @@ io.on('connection', function(socket) {
364
348
} // end of "message starts with /"
365
349
366
350
// Send a normal chat
367
- else delay_send ( io , 'chat' , [ socket . id , html_encode ( message ) ] ) ;
351
+ else delay_send ( io , 'chat' , [ socket . id , message ] ) ;
368
352
}
369
353
socket . on ( 'chat' , function ( data ) { delay_function ( on_chat , data ) } ) ;
370
354
0 commit comments