Skip to content

Commit

Permalink
Fixed small bug causing server to crash
Browse files Browse the repository at this point in the history
  • Loading branch information
RowanHarley authored Aug 17, 2016
1 parent c567bd8 commit 72820cb
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,17 @@ function handleMessage (conn, data) {
var R = config['gameRadius'];
var r = (Math.pow((conn.snake.body.x - R), 2)) + (Math.pow((conn.snake.body.y - R), 2));
if (r > Math.pow(R, 2)) {
// console.log("[TEST] " + r + " < " + R^2);
// console.log("[TEST] " + r + " < " + R^2);
console.log('[DEBUG] Outside of Radius');
var arr = new Uint8Array(6);
message.writeInt8(2, arr, "s".charCodeAt(0));
message.writeInt16(3, arr, conn.id);
message.writeInt8(5, arr, 1);
broadcast(arr);
broadcast(messages.end.build(1));
broadcast(messages.end.build(0));
//sleep(1000);
delete clients[conn.id];
conn.close();
}
}

broadcast(messages.position.build(conn.id, conn.snake));
Expand Down Expand Up @@ -205,14 +204,6 @@ function broadcast (data) {
send(i, data);
}
}
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
function killPlayer (playerId, endType) {
broadcast(messages.end.build(endType));
}
Expand Down

0 comments on commit 72820cb

Please sign in to comment.