Skip to content

Commit 57ed1a3

Browse files
committed
add --kiosk mode to go directly to game when possible
1 parent f2689aa commit 57ed1a3

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

public/game-login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<h1>HappyFunTimes</h1>
6565
<div id="hft-settings">
6666
<div class="hft-fullcenter">
67-
<div id="start" class="hft-menubutton"><div><a href="http://%(localhost)s/enter-name.html?sessionId=%(sessionId)s">Start</a></div></div>
67+
<div id="start" class="hft-menubutton"><div><a href="http://%(localhost)s%(firstPath)s?sessionId=%(sessionId)s">Start</a></div></div>
6868
</div>
6969
</div>
7070
</body>

server/apple-captive-portal-handler.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var AppleCaptivePortalHandler = function(options) {
8181
// return my redirection page the first time and apple's success page the second time
8282
this.sessions = {};
8383
this.options = options;
84+
this.firstPath = "/enter-name.html";
8485
};
8586

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

96+
/**
97+
* Sets the path we go to after the user picks `[Start]`
98+
* @param {string} path path to go to . Default is
99+
* "/enter-name.html"
100+
*/
101+
AppleCaptivePortalHandler.prototype.setFirstPath = function(path) {
102+
this.firstPath = path
103+
};
104+
95105
/**
96106
* Check if this request has something to do with captive portal
97107
* handling and if so handle it.
@@ -106,7 +116,7 @@ AppleCaptivePortalHandler.prototype.check = function(req, res) {
106116
var sessionId = filePath;
107117
var isCheckingForApple = req.headers["user-agent"] && strings.startsWith(req.headers["user-agent"], "CaptiveNetworkSupport");
108118
var isLoginURL = (filePath == "/game-login.html");
109-
var isIndexURL = (filePath == "/index.html" || filePath == "/" || filePath == "/enter-name.html");
119+
var isIndexURL = (filePath == "/index.html" || filePath == "/" || filePath == this.firstPath);
110120

111121
if (isIndexURL) {
112122
sessionId = parsedUrl.query.sessionId;
@@ -166,6 +176,7 @@ AppleCaptivePortalHandler.prototype.sendCaptivePortalHTML = function(req, res, s
166176
var params = {
167177
sessionId: sessionId,
168178
localhost: this.options.address + ":" + this.options.port,
179+
firstPath: this.firstPath,
169180
};
170181
str = strings.replaceParams(str, params);
171182
return str;

server/common-cli-options.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
"use strict";
3333

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

server/hft-server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ var HFTServer = function(options, startedCallback) {
310310
sendFileFn: sendFileResponse,
311311
});
312312

313+
if (!options.askName) {
314+
appleCaptivePortalHandler.setFirstPath("/index.html");
315+
}
316+
313317
// Send a file from a game.
314318
var sendGameRequestedFile = function(req, res) {
315319
var gamePrefixLength = 8; // "/games/" + the slash after the id
@@ -527,6 +531,14 @@ var HFTServer = function(options, startedCallback) {
527531
relayServer: relayServer,
528532
});
529533
relayServer.assignAsClientForGame({gameId: "__hft__", showInList: false}, hftGame.getClientForGame());
534+
relayServer.on('gameStarted', function(e) {
535+
if (options.kiosk && !options.askName) {
536+
var runtimeInfo = g.gameDB.getGameById(e.gameId);
537+
if (runtimeInfo) {
538+
appleCaptivePortalHandler.setFirstPath("/games/" + e.gameId + "/index.html");
539+
}
540+
}
541+
});
530542
startedCallback();
531543
}
532544
};

todo.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
To Do
22
=====
33

4-
* make --go-direct
4+
* fix samsung
5+
* fix android non-chrome?
6+
* fix windows phone
57
* add fullscreen to android
68
* add a session id to controller so you can continue where you left off
79

@@ -777,6 +779,7 @@ Runs Repo noid
777779
Done
778780
====
779781

782+
* make --kiosk
780783
* make games 'reload' if the server disconnects then reconnects
781784

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

0 commit comments

Comments
 (0)