From c3cd383aa02f021e20d7f76b8b3b30d29f09bc89 Mon Sep 17 00:00:00 2001 From: Linus Larsson Date: Wed, 20 Mar 2013 13:24:51 +0100 Subject: [PATCH 1/3] Error handling on websocket.send --- wpilots.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/wpilots.js b/wpilots.js index 7fff165..24f5748 100755 --- a/wpilots.js +++ b/wpilots.js @@ -341,7 +341,11 @@ function start_gameserver(maps, options, shared) { if (connection.last_ping + 2000 < time) { connection.last_ping = time; - connection.send(JSON.stringify([PING_PACKET])); + try { + connection.send(JSON.stringify([PING_PACKET])); + } catch (err) { + return; + } } if (update_tick % connection.update_rate != 0) { continue; @@ -431,7 +435,11 @@ function start_gameserver(maps, options, shared) { for(var id in connections) { var conn = connections[id]; if (conn.state == JOINED) { - conn.send(JSON.stringify([OP_WORLD_RECONNECT])); + try { + conn.send(JSON.stringify([OP_WORLD_RECONNECT])); + } catch (err) { + return; + } conn.set_state(HANDSHAKING); } } @@ -613,7 +621,11 @@ function start_gameserver(maps, options, shared) { } else { for(var id in connections) { var conn = connections[id]; - conn.send(JSON.stringify([OP_WORLD_RECONNECT])); + try{ + conn.send(JSON.stringify([OP_WORLD_RECONNECT])); + } catch (err) { + return; + } conn.set_state(HANDSHAKING); } } @@ -700,7 +712,12 @@ function start_gameserver(maps, options, shared) { */ conn.post = function(data) { var packet = JSON.stringify(data); - this.send(packet); + try { + this.send(packet); + } catch (err){ + return; + } + } /** From 14e194436b5f4d27f5ecae25b576950a118c5d87 Mon Sep 17 00:00:00 2001 From: Linus Larsson Date: Wed, 20 Mar 2013 13:45:02 +0100 Subject: [PATCH 2/3] ErAdded log message to ws.send error --- wpilots.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wpilots.js b/wpilots.js index 24f5748..1c458ff 100755 --- a/wpilots.js +++ b/wpilots.js @@ -90,7 +90,7 @@ const SWITCHES = [ const DEFAULT_OPTIONS = { debug: true, name: 'WPilot Server', - host: '127.0.0.1', + host: '10.0.1.3', region: 'n/a', admin_password: null, map: null, @@ -344,6 +344,7 @@ function start_gameserver(maps, options, shared) { try { connection.send(JSON.stringify([PING_PACKET])); } catch (err) { + log(connection + ' send error (Reason: ' + err + ')'); return; } } @@ -436,8 +437,9 @@ function start_gameserver(maps, options, shared) { var conn = connections[id]; if (conn.state == JOINED) { try { - conn.send(JSON.stringify([OP_WORLD_RECONNECT])); + conn.send(JSON.stringify([OP_WORLD_RECONNECT])); } catch (err) { + log(conn + ' send error (Reason: ' + err + ')'); return; } conn.set_state(HANDSHAKING); @@ -622,8 +624,9 @@ function start_gameserver(maps, options, shared) { for(var id in connections) { var conn = connections[id]; try{ - conn.send(JSON.stringify([OP_WORLD_RECONNECT])); + conn.send(JSON.stringify([OP_WORLD_RECONNECT])); } catch (err) { + log(conn + ' send error (Reason: ' + err + ')'); return; } conn.set_state(HANDSHAKING); @@ -713,8 +716,9 @@ function start_gameserver(maps, options, shared) { conn.post = function(data) { var packet = JSON.stringify(data); try { - this.send(packet); + this.send(packet); } catch (err){ + log(this + ' send error (Reason: ' + err + ')'); return; } @@ -739,6 +743,7 @@ function start_gameserver(maps, options, shared) { this.send('[' + GAME_PACKET + ',[' + packet_data.join(',') + ']]'); this.data_sent += data_sent; } catch (err) { + log(this + ' send error (Reason: ' + err + ')'); return; } From 0b05d290fedb396e2614a5b83bbe86c5ad24d424 Mon Sep 17 00:00:00 2001 From: Linus Larsson Date: Wed, 20 Mar 2013 13:54:16 +0100 Subject: [PATCH 3/3] reset host adressto local --- wpilots.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpilots.js b/wpilots.js index 1c458ff..92e25e2 100755 --- a/wpilots.js +++ b/wpilots.js @@ -90,7 +90,7 @@ const SWITCHES = [ const DEFAULT_OPTIONS = { debug: true, name: 'WPilot Server', - host: '10.0.1.3', + host: '127.0.0.1', region: 'n/a', admin_password: null, map: null,