Skip to content

Commit

Permalink
add --no-ask-name
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Oct 1, 2014
1 parent c7a3db1 commit 7965444
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 23 deletions.
5 changes: 5 additions & 0 deletions docs/api-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,10 @@ the correct version
you'd like other files to have info inserted you can add a
`happyFunTimes.templateUrls` field to your `package.json`

* --no-ask-name

For installations where you don't need to display the user's name
you can add --no-ask-name when you start the system and players
will not be asked enter their name.


2 changes: 1 addition & 1 deletion public/enter-name.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<div class="center"><div class="button-like" id="okay">Okay</div></div>
</div>
</body>
<script data-main="scripts/enter-name.js" src="3rdparty/require.js"></script>
<script data-main="%(enterNameScript)s" src="3rdparty/require.js"></script>
<script>
requirejs.config({
paths: {
Expand Down
26 changes: 13 additions & 13 deletions public/scripts/enter-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@

"use strict";

var main = function(Cookie, Misc, MobileHacks) {

// Start the main app logic.
requirejs(
[ 'hft/misc/cookies',
'hft/misc/misc',
'hft/misc/mobilehacks',
'hft/io',
], function(
Cookie,
Misc,
MobileHacks,
IO) {

var $ = function(id) {
return document.getElementById(id);
Expand Down Expand Up @@ -98,17 +109,6 @@ var main = function(Cookie, Misc, MobileHacks) {
}


};

// Start the main app logic.
requirejs(
[ 'hft/misc/cookies',
'hft/misc/misc',
'hft/misc/mobilehacks',
'hft/io',
],
main
);

});


34 changes: 34 additions & 0 deletions public/scripts/go-to-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2014, Gregg Tavares.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Gregg Tavares. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

window.location.href = "/";


1 change: 1 addition & 0 deletions server/common-cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ exports.options = [
{ 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"},
];

42 changes: 33 additions & 9 deletions server/hft-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,21 @@ var HFTServer = function(options, startedCallback) {
sendRequestedFile(req, res);
};

var sendRequestedFileFullPath = function(req, res, fullPath, runtimeInfo) {
// Send Templated File
var sendTemplatedFile = function(req, res) {
sendRequestedFile(req, res, {
params: {
"enterNameScript": (options.askName ? "scripts/enter-name.js" : "scripts/go-to-index.js"),
},
});
};

// Blargs! What a mess. This needs to be cleaned up
var sendRequestedFileFullPath = function(req, res, fullPath, runtimeInfo, options) {
var options = options || {};
var parsedUrl = url.parse(req.url);
var filePath = parsedUrl.pathname;
var isTemplate = runtimeInfo && runtimeInfo.templateUrls[filePath];
var isTemplate = (runtimeInfo && runtimeInfo.templateUrls[filePath]) || options.params;
var isQuery = parsedUrl.query !== null;
var isAnchor = parsedUrl.hash !== null;
if (runtimeInfo && runtimeInfo.features.es6 && es6Support.isES6(fullPath)) {
Expand All @@ -348,19 +359,32 @@ var HFTServer = function(options, startedCallback) {
fullPath += "index.html";
}
}
var prepFn = isTemplate ? function(str) {
return strings.replaceParams(str, [{
var prepFn = isTemplate ? (function() {
var params = [{
localhost: g.address,
}, runtimeInfo]);
} : undefined;
}];
if (runtimeInfo) {
params.push([runtimeInfo]);
}
if (options.params) {
if (options.params.length) {
params = params.concat(options.params);
} else {
params.push(options.params);
}
};
return function(str) {
return strings.replaceParams(str, params);
}
}()) : undefined;
sendFileResponse(req, res, fullPath, prepFn, runtimeInfo);
};

var sendRequestedFile = function(req, res) {
var sendRequestedFile = function(req, res, options) {
var parsedUrl = url.parse(req.url);
var filePath = parsedUrl.pathname;
var fullPath = path.normalize(path.join(g.cwd, g.baseDir, filePath));
sendRequestedFileFullPath(req, res, fullPath);
sendRequestedFileFullPath(req, res, fullPath, undefined, options);
};

var send404 = function(res, msg) {
Expand Down Expand Up @@ -433,7 +457,7 @@ var HFTServer = function(options, startedCallback) {
sendRequestedFileFullPath(req, res, nonPath);
});
app.get(/^\/games\/(.*?)\//, sendGameRequestedFile);

app.get(/^\/enter-name.html/, sendTemplatedFile);
app.get(/.*/, sendSystemRequestedFile);
app.post(/.*/, handlePOST);
app.options(/.*/, handleOPTIONS);
Expand Down

0 comments on commit 7965444

Please sign in to comment.