2023-09-21 06:48:44 -04:00
Hosting your own version of the ClassiCube webclient is relatively straightforward
Only the following 3 files are required:
1) A web page to initialise the game .js and display the game
2020-07-08 04:26:16 -04:00
2) The game .js file
2020-04-01 19:29:00 -04:00
3) The default texture pack
2023-09-21 06:48:44 -04:00
TODO: more advanced sample (authentication, custom game.js, skin server)
2020-04-01 19:29:00 -04:00
### Example setup
2023-09-21 06:48:44 -04:00
For example, let's assume your website is setup like this:
2020-04-01 19:29:00 -04:00
* `example.com/play.html`
* `example.com/static/classisphere.js`
* `example.com/static/default.zip`
For simplicitly,
2023-01-17 04:46:25 -05:00
1) Download `cs.classicube.net/client/latest/ClassiCube.js` , then upload it to `static/classisphere.js` on the webserver
2020-07-08 04:26:16 -04:00
2) Download `classicube.net/static/default.zip` , then upload it to `static/default.zip` on the webserver
2020-04-01 19:29:00 -04:00
2023-09-21 06:48:44 -04:00
The play.html page is the trickiest part, because how to implement this is website-specific. (depends on how the website is styled, what webserver is used, what programming language is used to generate the html, etc)
2020-04-01 19:29:00 -04:00
2024-01-09 03:56:39 -05:00
#### Changing where the game downloads the texture pack from
There should be this piece of code somewhere in the .JS file: `function _interop_AsyncDownloadTexturePack(rawPath) {`
A bit below that, there should be `var url = '/static/default.zip';` - change that to the desired URL.
2020-04-02 04:57:36 -04:00
#### Embedding the game in play.html
2020-04-01 19:29:00 -04:00
2023-09-21 06:48:44 -04:00
The following HTML code is required to be somewhere in the webpage:
2020-04-02 04:57:36 -04:00
```HTML
2020-08-22 02:18:39 -04:00
<!-- the canvas *must not* have any border or padding, or mouse coords will be wrong -->
2020-08-22 09:44:03 -04:00
< canvas id = "canvas" style = "display:block; border:0; padding:0; background-color: black;"
oncontextmenu="event.preventDefault()" tabindex=-1>< / canvas >
2020-04-02 04:57:36 -04:00
< span id = "logmsg" > < / span >
< script type = 'text/javascript' >
var Module = {
2022-09-12 06:23:31 -04:00
preRun: [],
2020-04-02 04:57:36 -04:00
postRun: [],
arguments: [ {username}, {mppass}, {server ip}, {server port} ],
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);
},
2020-08-22 02:18:39 -04:00
canvas: (function() { return document.getElementById('canvas'); })(),
2020-04-02 04:57:36 -04:00
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...');
2020-08-22 02:18:39 -04:00
window.onerror = function(msg) {
2020-04-02 04:57:36 -04:00
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
2020-08-22 02:18:39 -04:00
Module.setStatus('Exception thrown, see JavaScript console (' + msg + ')');
2020-04-02 04:57:36 -04:00
Module.setStatus = function(text) {
if (text) Module.printErr('[post-exception status] ' + text);
};
};
< / script >
< script async type = "text/javascript" src = "/static/classisphere.js" > < / script >
```
2020-08-22 09:44:03 -04:00
**To start in singleplayer instead, just use `arguments: [ {username} ],` instead**
2020-04-02 04:57:36 -04:00
##### Variables
* {username} - the player's username
* {mppass} - if server verifies names, [mppass ](https://wiki.vg/Classic_Protocol#User_Authentication ). Otherwise leave as `''` .
* {server ip} - the IP address of the server to connect to
* {server port} - the port on the server to connect on (usually `'25565'` )
2020-04-02 05:17:52 -04:00
### Complete example
2020-04-02 04:57:36 -04:00
2021-11-10 01:39:20 -05:00
The links below show how to integrate the webclient into a simple website
2020-04-03 23:50:14 -04:00
* [Flask (python webserver) ](hosting-flask.md )
2020-11-03 06:43:36 -05:00
### iOS / Android support
The webclient is compatible with Android / iOS devices and will show a touch based UI to these devices.
However, due to the limited screen size available on such devices, you should consider serving a webpage consisting of just the `<canvas>` to these devices - no header, footer or anything else.
Additionally, you will likely want to ensure zooming is disabled, viewport width is same as the device's width, and that 'add to device homescreen' is fully supported. You can accomplish that by adding these three HTML tags to the page:
```HTML
< meta name = "apple-mobile-web-app-capable" content = "yes" >
< meta name = "mobile-web-app-capable" content = "yes" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" >
```