diff --git a/game-client.js b/game-client.js index 6f0f51e..3af9bc4 100644 --- a/game-client.js +++ b/game-client.js @@ -29,6 +29,74 @@ if ( !window.requestAnimationFrame ) { })(); } +var norun = false; +function run() { + if (norun) + return; //Prevent multiple clicks. + norun = true; + $("#begin").css("display: none"); + $("#begin").animate({ + opacity: 0 + }, 1000); + + user = null; + deadFrames = 0; + + //Socket connection. + //, {transports: ['websocket'], upgrade: false} + connectServer(); + socket.emit('hello', { + name: $("#name").val(), + type: 0, //Free-for-all + gameid: -1 //Requested game-id, or -1 for anyone. + }, function(success) { + if (success) console.info("Connected to game!"); + else console.error("Unable to connect to game."); + }); +} + +$(function() { + var error = $("#error"); + + if (!window.WebSocket) + { + error.text("Your browser does not support WebSockets!"); + return; + } + + error.text("Loading..."); //TODO: show loading screen. + var success = false; + var socket = io('http://paper-io-thekidofarcrania.c9users.io:8081', { + 'forceNew': true, + upgrade: false, + transports: ['websocket'] + }); + + socket.on('connect_error', function() { + if (!success) + error.text("Cannot connect with server. This probably is due to misconfigured proxy server. (Try using a different browser)"); + }) + socket.emit("checkConn", function() { + success = true; + socket.disconnect(); + }); + setTimeout(function() { + if (!success) + error.text("Cannot connect with server. This probably is due to misconfigured proxy server. (Try using a different browser)"); + else + { + error.text(""); + $("input").keypress(function(evt) { + if (evt.which === 13) + requestAnimationFrame(run); + }); + $("button").click(function(evt) { + requestAnimationFrame(run); + }); + } + }, 2000); +}); + var user, socket, frame; //Event listeners @@ -61,32 +129,7 @@ $(document).keydown(function(e) { e.preventDefault(); }); -var norun = false; -window.run = run; -function run() { - if (norun) - return; //Prevent multiple clicks. - norun = true; - $("#begin").css("display: none"); - $("#begin").animate({ - opacity: 0 - }, 1000); - - user = null; - deadFrames = 0; - - //Socket connection. - //, {transports: ['websocket'], upgrade: false} - connectServer(); - socket.emit('hello', { - name: $("#name").val(), - type: 0, //Free-for-all - gameid: -1 //Requested game-id, or -1 for anyone. - }, function(success) { - if (success) console.info("Connected to game!"); - else console.error("Unable to connect to game."); - }); -} + var grid = renderer.grid; var timeout = undefined; @@ -99,7 +142,11 @@ var frameCache = []; //Frames after our request. function connectServer() { io.j = []; io.sockets = []; - socket = io('http://paper-io-thekidofarcrania.c9users.io:8081', {'forceNew': true}); + socket = io('http://paper-io-thekidofarcrania.c9users.io:8081', { + 'forceNew': true, + upgrade: false, + transports: ['websocket'] + }); socket.on('connect', function(){ console.info("Connected to server."); }); @@ -278,4 +325,4 @@ function paintLoop() renderer.update(); requestAnimationFrame(paintLoop); } -} +} \ No newline at end of file diff --git a/public/bundle.js b/public/bundle.js index ec80918..664ae5c 100644 --- a/public/bundle.js +++ b/public/bundle.js @@ -315,6 +315,74 @@ if ( !window.requestAnimationFrame ) { })(); } +var norun = false; +function run() { + if (norun) + return; //Prevent multiple clicks. + norun = true; + $("#begin").css("display: none"); + $("#begin").animate({ + opacity: 0 + }, 1000); + + user = null; + deadFrames = 0; + + //Socket connection. + //, {transports: ['websocket'], upgrade: false} + connectServer(); + socket.emit('hello', { + name: $("#name").val(), + type: 0, //Free-for-all + gameid: -1 //Requested game-id, or -1 for anyone. + }, function(success) { + if (success) console.info("Connected to game!"); + else console.error("Unable to connect to game."); + }); +} + +$(function() { + var error = $("#error"); + + if (!window.WebSocket) + { + error.text("Your browser does not support WebSockets!"); + return; + } + + error.text("Loading..."); //TODO: show loading screen. + var success = false; + var socket = io('http://paper-io-thekidofarcrania.c9users.io:8081', { + 'forceNew': true, + upgrade: false, + transports: ['websocket'] + }); + + socket.on('connect_error', function() { + if (!success) + error.text("Cannot connect with server. This probably is due to misconfigured proxy server. (Try using a different browser)"); + }) + socket.emit("checkConn", function() { + success = true; + socket.disconnect(); + }); + setTimeout(function() { + if (!success) + error.text("Cannot connect with server. This probably is due to misconfigured proxy server. (Try using a different browser)"); + else + { + error.text(""); + $("input").keypress(function(evt) { + if (evt.which === 13) + requestAnimationFrame(run); + }); + $("button").click(function(evt) { + requestAnimationFrame(run); + }); + } + }, 2000); +}); + var user, socket, frame; //Event listeners @@ -347,32 +415,7 @@ $(document).keydown(function(e) { e.preventDefault(); }); -var norun = false; -window.run = run; -function run() { - if (norun) - return; //Prevent multiple clicks. - norun = true; - $("#begin").css("display: none"); - $("#begin").animate({ - opacity: 0 - }, 1000); - - user = null; - deadFrames = 0; - - //Socket connection. - //, {transports: ['websocket'], upgrade: false} - connectServer(); - socket.emit('hello', { - name: $("#name").val(), - type: 0, //Free-for-all - gameid: -1 //Requested game-id, or -1 for anyone. - }, function(success) { - if (success) console.info("Connected to game!"); - else console.error("Unable to connect to game."); - }); -} + var grid = renderer.grid; var timeout = undefined; @@ -385,7 +428,11 @@ var frameCache = []; //Frames after our request. function connectServer() { io.j = []; io.sockets = []; - socket = io('http://paper-io-thekidofarcrania.c9users.io:8081', {'forceNew': true}); + socket = io('http://paper-io-thekidofarcrania.c9users.io:8081', { + 'forceNew': true, + upgrade: false, + transports: ['websocket'] + }); socket.on('connect', function(){ console.info("Connected to server."); }); @@ -564,8 +611,7 @@ function paintLoop() renderer.update(); requestAnimationFrame(paintLoop); } -} - +} },{"./game-consts.js":5,"./game-core.js":6,"./game-renderer.js":7,"./player.js":56,"socket.io-client":9}],5:[function(require,module,exports){ function constant(val) { diff --git a/public/index.html b/public/index.html index d35a265..f58a5c3 100644 --- a/public/index.html +++ b/public/index.html @@ -7,15 +7,17 @@ -
-
-
-

Paper.IO!

- Todo: replace ^^^ with a picture. Work in progress. -

Enter your name

- - +
+
+

Paper.IO!

+ Todo: replace ^^^ with a picture. Work in progress. +

Enter your name

+ + +
+ Your browser does not support JavaScript!
- +
+ \ No newline at end of file diff --git a/public/styles.css b/public/styles.css index 81c044b..09e98d2 100644 --- a/public/styles.css +++ b/public/styles.css @@ -9,7 +9,9 @@ body, html { color: white; font-family: "Changa", "Sans Serif"; } - +#error { + color: red; +} canvas { position: absolute; top: 0; diff --git a/server.js b/server.js index 5cecf9a..41c4de0 100644 --- a/server.js +++ b/server.js @@ -20,7 +20,7 @@ server.listen(8080); server = http.createServer(); var io = require('socket.io')(server); -//io.set('transports', ['websocket']); +io.set('transports', ['websocket']); var Game = require('./game-server.js'); var games = [new Game()]; @@ -30,6 +30,7 @@ io.on('connection', function(socket){ fn(true); games[0].addPlayer(socket, data.name); }); + socket.on("checkConn", function(fn) { fn(); }); }); server.listen(8081); @@ -38,4 +39,4 @@ function tick() { setTimeout(tick, 1000 / 60); } tick(); -//setTimeout(tick, 1000 / 60); +//setTimeout(tick, 1000 / 60); \ No newline at end of file