Files
@ r28598:1e46fbfcf2e6
Branch filter:
Location: cpp/openttd-patchpack/source/os/emscripten/pre.js - annotation
r28598:1e46fbfcf2e6
4.4 KiB
application/javascript
Codechange: Remove TKM string code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | r27843:9dff22cef669 r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r27697:240cfede70d1 r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r25457:3876e5f0edbe r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r27844:cf08d34d52cb r24439:3207de2680bf r27844:cf08d34d52cb r27844:cf08d34d52cb r27844:cf08d34d52cb r27844:cf08d34d52cb r27844:cf08d34d52cb r27844:cf08d34d52cb r27844:cf08d34d52cb r24439:3207de2680bf r27844:cf08d34d52cb r27844:cf08d34d52cb r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r27844:cf08d34d52cb r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r27844:cf08d34d52cb r24439:3207de2680bf r24439:3207de2680bf r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r27845:2ecc8f63d57a r24439:3207de2680bf r25313:a5c6f5530336 r24439:3207de2680bf r25313:a5c6f5530336 r25313:a5c6f5530336 r25313:a5c6f5530336 r25313:a5c6f5530336 r25313:a5c6f5530336 r25313:a5c6f5530336 r24439:3207de2680bf r24439:3207de2680bf r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24737:8b9686483288 r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf | Module.arguments.push('-mnull', '-snull', '-vsdl');
Module['websocket'] = { url: function(host, port, proto) {
/* openttd.org hosts a WebSocket proxy for the content service. */
if (host == "content.openttd.org" && port == 3978 && proto == "tcp") {
return "wss://bananas-server.openttd.org/";
}
/* Everything else just tries to make a default WebSocket connection.
* If you run your own server you can setup your own WebSocket proxy in
* front of it and let people connect to your server via the proxy. You
* are best to add another "if" statement as above for this. */
if (location.protocol === 'https:') {
/* Insecure WebSockets do not work over HTTPS, so we force
* secure ones. */
return 'wss://';
} else {
/* Use the default provided by Emscripten. */
return null;
}
} };
Module.preRun.push(function() {
personal_dir = '/home/web_user/.openttd';
content_download_dir = personal_dir + '/content_download'
/* Because of the "-c" above, all user-data is stored in /user_data. */
FS.mkdir(personal_dir);
FS.mount(IDBFS, {}, personal_dir);
Module.addRunDependency('syncfs');
FS.syncfs(true, function (err) {
Module.removeRunDependency('syncfs');
});
window.openttd_syncfs_shown_warning = false;
window.openttd_syncfs = function(callback) {
/* Copy the virtual FS to the persistent storage. */
FS.syncfs(false, function (err) {
/* On first time, warn the user about the volatile behaviour of
* persistent storage. */
if (!window.openttd_syncfs_shown_warning) {
window.openttd_syncfs_shown_warning = true;
Module.onWarningFs();
}
if (callback) callback();
});
}
window.openttd_exit = function() {
window.openttd_syncfs(Module.onExit);
}
window.openttd_abort = function() {
window.openttd_syncfs(Module.onAbort);
}
window.openttd_bootstrap = function(current, total) {
Module.onBootstrap(current, total);
}
window.openttd_bootstrap_failed = function() {
Module.onBootstrapFailed();
}
window.openttd_bootstrap_reload = function() {
window.openttd_syncfs(function() {
Module.onBootstrapReload();
setTimeout(function() {
location.reload();
}, 1000);
});
}
window.openttd_server_list = function() {
add_server = Module.cwrap("em_openttd_add_server", null, ["string"]);
/* Add servers that support WebSocket here. Examples:
* add_server("localhost");
* add_server("localhost:3979");
* add_server("127.0.0.1:3979");
* add_server("[::1]:3979");
*/
}
var leftButtonDown = false;
document.addEventListener("mousedown", e => {
if (e.button == 0) {
leftButtonDown = true;
}
});
document.addEventListener("mouseup", e => {
if (e.button == 0) {
leftButtonDown = false;
}
});
window.openttd_open_url = function(url, url_len) {
const url_string = UTF8ToString(url, url_len);
function openWindow() {
document.removeEventListener("mouseup", openWindow);
window.open(url_string, '_blank');
}
/* Trying to open the URL while the mouse is down results in the button getting stuck, so wait for the
* mouse to be released before opening it. However, when OpenTTD is lagging, the mouse can get released
* before the button click even registers, so check for that, and open the URL immediately if that's the
* case. */
if (leftButtonDown) {
document.addEventListener("mouseup", openWindow);
} else {
openWindow();
}
}
/* https://github.com/emscripten-core/emscripten/pull/12995 implements this
* properly. Till that time, we use a polyfill. */
SOCKFS.websocket_sock_ops.createPeer_ = SOCKFS.websocket_sock_ops.createPeer;
SOCKFS.websocket_sock_ops.createPeer = function(sock, addr, port)
{
let func = Module['websocket']['url'];
Module['websocket']['url'] = func(addr, port, (sock.type == 2) ? 'udp' : 'tcp');
let ret = SOCKFS.websocket_sock_ops.createPeer_(sock, addr, port);
Module['websocket']['url'] = func;
return ret;
}
});
|