Skip to content

Commit 90928db

Browse files
committed
more cleanup
1 parent 444862a commit 90928db

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

server.js

+9-25
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
*/
1717

1818

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
2120
var state = {
22-
slots : 32, // Maximum number of clients
21+
slots : 32, // Maximum number of clients
2322
max_name_length: 25, // Maximum number of characters in each player's name
2423
clients : {}, // List of client data
2524
pieces : {}, // List of piece properties
@@ -36,10 +35,13 @@ var state_keys_no_set = [
3635
'nameplates',
3736
'hands',
3837
'slots',
38+
'max_name_length',
3939
];
4040

4141

4242

43+
///////////////////////////////////////////////// EXTERNAL LIBRARIES
44+
4345
// Versions included in external_scripts
4446
pixi_version = 'pixi.min.js';
4547
howler_version = 'howler.min.js';
@@ -51,18 +53,6 @@ var http = require('http').createServer(app); // listening
5153
var io = require('socket.io')(http); // fast input/output
5254
var fun = require('./common/fun'); // My common functions
5355

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();
6656

6757

6858
// port upon which the server listens
@@ -129,10 +119,7 @@ function send_file(response, path) {
129119
if(full_path) response.sendFile(full_path);
130120
}
131121

132-
function html_encode(s) {
133-
// Thanks Stack Exchange.
134-
return s.replace(/[\u00A0-\u9999<>\&]/gim, function(i) {return '&#'+i.charCodeAt(0)+';';});
135-
}
122+
136123

137124

138125

@@ -325,11 +312,8 @@ io.on('connection', function(socket) {
325312
// Split it by space
326313
var s = message.split(' ');
327314

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') {
333317

334318
// Find the client by name and boot them
335319
for(var id in state.clients) if(state.clients[id].name == s[1]) {
@@ -364,7 +348,7 @@ io.on('connection', function(socket) {
364348
} // end of "message starts with /"
365349

366350
// Send a normal chat
367-
else delay_send(io, 'chat', [socket.id,html_encode(message)]);
351+
else delay_send(io, 'chat', [socket.id, message]);
368352
}
369353
socket.on('chat', function(data) {delay_function(on_chat, data)});
370354

0 commit comments

Comments
 (0)