Skip to content

Commit

Permalink
add --kiosk mode to go directly to game when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Oct 30, 2014
1 parent f2689aa commit 57ed1a3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion public/game-login.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<h1>HappyFunTimes</h1>
<div id="hft-settings">
<div class="hft-fullcenter">
<div id="start" class="hft-menubutton"><div><a href="http://%(localhost)s/enter-name.html?sessionId=%(sessionId)s">Start</a></div></div>
<div id="start" class="hft-menubutton"><div><a href="http://%(localhost)s%(firstPath)s?sessionId=%(sessionId)s">Start</a></div></div>
</div>
</div>
</body>
Expand Down
13 changes: 12 additions & 1 deletion server/apple-captive-portal-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var AppleCaptivePortalHandler = function(options) {
// return my redirection page the first time and apple's success page the second time
this.sessions = {};
this.options = options;
this.firstPath = "/enter-name.html";
};

/**
Expand All @@ -92,6 +93,15 @@ var AppleCaptivePortalHandler = function(options) {
* @property {string} baseDir path to portal files
*/

/**
* Sets the path we go to after the user picks `[Start]`
* @param {string} path path to go to . Default is
* "/enter-name.html"
*/
AppleCaptivePortalHandler.prototype.setFirstPath = function(path) {
this.firstPath = path
};

/**
* Check if this request has something to do with captive portal
* handling and if so handle it.
Expand All @@ -106,7 +116,7 @@ AppleCaptivePortalHandler.prototype.check = function(req, res) {
var sessionId = filePath;
var isCheckingForApple = req.headers["user-agent"] && strings.startsWith(req.headers["user-agent"], "CaptiveNetworkSupport");
var isLoginURL = (filePath == "/game-login.html");
var isIndexURL = (filePath == "/index.html" || filePath == "/" || filePath == "/enter-name.html");
var isIndexURL = (filePath == "/index.html" || filePath == "/" || filePath == this.firstPath);

if (isIndexURL) {
sessionId = parsedUrl.query.sessionId;
Expand Down Expand Up @@ -166,6 +176,7 @@ AppleCaptivePortalHandler.prototype.sendCaptivePortalHTML = function(req, res, s
var params = {
sessionId: sessionId,
localhost: this.options.address + ":" + this.options.port,
firstPath: this.firstPath,
};
str = strings.replaceParams(str, params);
return str;
Expand Down
19 changes: 10 additions & 9 deletions server/common-cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
"use strict";

exports.options = [
{ option: 'port', alias: 'p', type: 'Int', description: 'port. Default 18679'},
{ option: 'dns', type: 'Boolean', description: 'enable dns server'},
{ option: 'address', type: 'String', description: 'ip address for dns and controller url conversion'},
{ option: 'app-mode', type: 'Boolean', description: 'run as an app'},
{ option: 'show', type: 'String', description: 'html file to launch, default "games"'},
{ option: 'system-name', type: 'String', description: 'name used if multiple happyFunTimes servers are running on the same network. Default = computer name'},
{ option: 'ask-name', type: 'Boolean', description: 'ask for name on start, use --no-ask-name to set to false', default: "true"},
{ option: 'menu', type: 'Boolean', description: 'show menu icon on controller, use --no-menu to turn off', default: "true"},
{ option: 'minify', type: 'Boolean', description: 'minify -minify.js files', default: false},
{ option: 'port', alias: 'p', type: 'Int', description: 'port. Default 18679'},
{ option: 'dns', type: 'Boolean', description: 'enable dns server'},
{ option: 'address', type: 'String', description: 'ip address for dns and controller url conversion'},
{ option: 'app-mode', type: 'Boolean', description: 'run as an app'},
{ option: 'show', type: 'String', description: 'html file to launch, default "games"'},
{ option: 'system-name', type: 'String', description: 'name used if multiple happyFunTimes servers are running on the same network. Default = computer name'},
{ option: 'ask-name', type: 'Boolean', description: 'ask for name on start, use --no-ask-name to set to false', default: "true"},
{ option: 'menu', type: 'Boolean', description: 'show menu icon on controller, use --no-menu to turn off', default: "true"},
{ option: 'minify', type: 'Boolean', description: 'minify -minify.js files', default: false},
{ option: 'kiosk', type: 'Boolean', description: 'skip the index', default: false},
];

12 changes: 12 additions & 0 deletions server/hft-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ var HFTServer = function(options, startedCallback) {
sendFileFn: sendFileResponse,
});

if (!options.askName) {
appleCaptivePortalHandler.setFirstPath("/index.html");
}

// Send a file from a game.
var sendGameRequestedFile = function(req, res) {
var gamePrefixLength = 8; // "/games/" + the slash after the id
Expand Down Expand Up @@ -527,6 +531,14 @@ var HFTServer = function(options, startedCallback) {
relayServer: relayServer,
});
relayServer.assignAsClientForGame({gameId: "__hft__", showInList: false}, hftGame.getClientForGame());
relayServer.on('gameStarted', function(e) {
if (options.kiosk && !options.askName) {
var runtimeInfo = g.gameDB.getGameById(e.gameId);
if (runtimeInfo) {
appleCaptivePortalHandler.setFirstPath("/games/" + e.gameId + "/index.html");
}
}
});
startedCallback();
}
};
Expand Down
5 changes: 4 additions & 1 deletion todo.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
To Do
=====

* make --go-direct
* fix samsung
* fix android non-chrome?
* fix windows phone
* add fullscreen to android
* add a session id to controller so you can continue where you left off

Expand Down Expand Up @@ -777,6 +779,7 @@ Runs Repo noid
Done
====

* make --kiosk
* make games 'reload' if the server disconnects then reconnects

can we some how indicate to the game it's a reconnect? For example, set a local cookie.
Expand Down

0 comments on commit 57ed1a3

Please sign in to comment.