Fix wrong link in hosting-webclient.md and simplify hosting-flask.md by combining the 3 html template files into 1

This commit is contained in:
UnknownShadow200 2020-07-08 18:26:16 +10:00
parent eb68cb9026
commit 35ed41ab81
3 changed files with 72 additions and 104 deletions

View File

@ -2,8 +2,6 @@ The website will be structured like so:
```
websrv.py
templates/tmpl.html
templates/tmpl_lite.html
templates/play.html
static/classisphere.js
static/default.zip
@ -39,54 +37,31 @@ if __name__ == "__main__":
app.run()
```
#### templates/tmpl.html
```HTML
<html>
<head>
<meta name="viewport" content="width=device-width">
<link href="/static/style.css" rel="stylesheet">
<script src="/static/jquery.js"></script>
</head>
<body>
<div id="header">
<div class="row">
<a href="/"><h1 class="columns">Home</h1></a>
<a href="/play"><h1 class="columns">Play</h1></a>
</div>
</div>
<div id="body">
{% block main %} {% endblock %}
</div>
</body>
</html>
```
#### templates/tmpl_lite.html
```HTML
<html>
<head>
<meta name="viewport" content="width=device-width">
<link href="/static/style.css" rel="stylesheet">
<script src="/static/jquery.js"></script>
</head>
<body>
<div id="body">
{% block main %} {% endblock %}
</div>
</body>
</html>
```
#### templates/play.html
```HTML
{% set mobile_mode = request.user_agent.platform in ('android', 'iphone', 'ipad') %}
<html>
<head>
<meta name="viewport" content="width=device-width">
<link href="/static/style.css" rel="stylesheet">
<script src="/static/jquery.js"></script>
</head>
<body>
{% if mobile_mode %}
{% extends 'tmpl_lite.html' %}
<style>
#body {min-height: 0px;}
.sec {padding: 0px;}
.row {padding: 0px;}
</style>
{% else %}
{% extends 'tmpl.html' %}
<div id="header">
<div class="row">
<a href="/"><h1 class="columns">Home</h1></a>
<a href="/play"><h1 class="columns">Play</h1></a>
</div>
</div>
{% endif %}
{% block main %}
<div id="body">
<style>
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
#GameCanvas { display:block; box-sizing:border-box; border-width:0px !important; padding:0 !important; margin:0 auto; background-color: black; width:100%; height:auto; }
@ -124,60 +99,53 @@ if __name__ == "__main__":
if (canv_w % 2) { canv_w = canv_w - 1; }
{% if mobile_mode %}
var screen_h = window.outerHeight || window.innerHeight;
canv_h = Math.min(canv_h, screen_h);
var screen_h = window.outerHeight || window.innerHeight;
canv_h = Math.min(canv_h, screen_h);
{% endif %}
cc_canv[0].width = canv_w * dpi;
cc_canv[0].height = canv_h * dpi;
}
cc_canv[0].width = canv_w * dpi;
cc_canv[0].height = canv_h * dpi;
}
var Module = {
preRun: [ preloadIndexedDB, resizeGameCanvas ],
postRun: [],
arguments: {{game_args|safe}},
print: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
},
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function() { return document.getElementById('GameCanvas'); })(),
setStatus: function(text) {
console.log(text);
document.getElementById('logmsg').innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function(event) {
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
Module.setStatus('Exception thrown, see JavaScript console');
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
<script async type="text/javascript" src="/static/classisphere.js"></script>
{% if mobile_mode %}
<style>
#body {min-height: 0px;}
.sec {padding: 0px;}
.row {padding: 0px;}
</style>
{% else %}
{% endif %}
{% endblock %}
var Module = {
preRun: [ preloadIndexedDB, resizeGameCanvas ],
postRun: [],
arguments: {{game_args|safe}},
print: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
},
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function() { return document.getElementById('GameCanvas'); })(),
setStatus: function(text) {
console.log(text);
document.getElementById('logmsg').innerHTML = text;
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
Module.setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
Module.setStatus('Downloading...');
window.onerror = function(event) {
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
Module.setStatus('Exception thrown, see JavaScript console');
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
</script>
<script async type="text/javascript" src="/static/classisphere.js"></script>
</div>
</body>
</html>
```
#### static/classisphere.js
Download `classicube.s3.amazonaws.com/client/latest/ClassiCube.js` for this
Download `cs.classicube.net/c_client/latest/ClassiCube.js` for this
#### static/default.zip
Download `classicube.net/static/default.zip` for this
@ -226,7 +194,7 @@ Download some version of jQuery for this. Version 2.1.1 is known to work.
* If you don't want the game to resize to fit different resolutions, remove the `resizeGameCanvas` code.
* tmpl_lite.html and mobile_mode is used to deliver a minified page for mobile/tablet devices
* mobile_mode is used to deliver a minified page for mobile/tablet devices
## Results

View File

@ -1,6 +1,6 @@
So you want to host your own version of the webclient? It's pretty easy to do, you need 3 files:
1) The game .js file
2) A web page to initialise the .js and display the game
1) A web page to initialise the .js and display the game
2) The game .js file
3) The default texture pack
### Example setup
@ -11,8 +11,8 @@ For example, let's assume our site is setup like this:
* `example.com/static/default.zip`
For simplicitly,
1) Download `classicube.net/static/classicube.js`, then upload it to `static/classisphere.js` on the webserver
2) Download `classicube.net/static/default.zip`, then upload it to `static/default.zip` on the webserver
1) Download `cs.classicube.net/c_client/latest/classicube.js`, then upload it to `static/classisphere.js` on the webserver
2) Download `classicube.net/static/default.zip`, then upload it to `static/default.zip` on the webserver
The play.html page is the trickiest part, because how to implement this is website-specific. (depends on how your website is styled, what webserver you use, what programming language is used to generate the html, etc)

View File

@ -651,31 +651,31 @@ void Logger_Abort2(cc_result result, const char* raw_msg) {
AbortCommon(result, raw_msg, NULL);
}
#elif defined CC_BUILD_WIN
static LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS* pInfo) {
static LONG WINAPI UnhandledFilter(struct _EXCEPTION_POINTERS* info) {
String msg; char msgBuffer[128 + 1];
cc_uint32 code;
cc_uintptr addr;
DWORD i, numArgs;
code = (cc_uint32)pInfo->ExceptionRecord->ExceptionCode;
addr = (cc_uintptr)pInfo->ExceptionRecord->ExceptionAddress;
code = (cc_uint32)info->ExceptionRecord->ExceptionCode;
addr = (cc_uintptr)info->ExceptionRecord->ExceptionAddress;
String_InitArray_NT(msg, msgBuffer);
String_Format2(&msg, "Unhandled exception 0x%h at 0x%x", &code, &addr);
numArgs = pInfo->ExceptionRecord->NumberParameters;
numArgs = info->ExceptionRecord->NumberParameters;
if (numArgs) {
numArgs = min(numArgs, EXCEPTION_MAXIMUM_PARAMETERS);
String_AppendConst(&msg, " [");
for (i = 0; i < numArgs; i++) {
String_Format1(&msg, "0x%x,", &pInfo->ExceptionRecord->ExceptionInformation[i]);
String_Format1(&msg, "0x%x,", &info->ExceptionRecord->ExceptionInformation[i]);
}
String_Append(&msg, ']');
}
msg.buffer[msg.length] = '\0';
AbortCommon(0, msg.buffer, pInfo->ContextRecord);
AbortCommon(0, msg.buffer, info->ContextRecord);
return EXCEPTION_EXECUTE_HANDLER; /* TODO: different flag */
}
void Logger_Hook(void) { SetUnhandledExceptionFilter(UnhandledFilter); }