diff --git a/src/config.h b/src/config.h index 1d6922a..e48a034 100644 --- a/src/config.h +++ b/src/config.h @@ -84,7 +84,9 @@ * * This will handle "gids" correctly once the permissions are set right. */ +#ifndef __EMSCRIPTEN__ /* the browser has no user ids to drop */ #define SAFE_SETUID +#endif /* * This flag enables the "POSIX" methods for "SAFE_SETUID". diff --git a/src/init2.c b/src/init2.c index c334a9a..eff3c1f 100644 --- a/src/init2.c +++ b/src/init2.c @@ -12,6 +12,10 @@ #include "init.h" +#ifdef __EMSCRIPTEN__ +#include +#endif + #ifdef RUNTIME_PRIVATE_USER_PATH /* * This is a hook so the main program can set a runtime value for the private @@ -212,6 +216,25 @@ void init_file_paths(char* path) #endif /* VM */ +#ifdef __EMSCRIPTEN__ + /* The browser build: the game files are preloaded in /sil/lib/ (read only); the saved games, the high + * scores and the user files are in /sil-user/, which the page keeps in the browser (IndexedDB); the raw + * data files are made on every start, in memory (/sil-data/). */ + string_free(ANGBAND_DIR_DATA); + string_free(ANGBAND_DIR_APEX); + string_free(ANGBAND_DIR_SAVE); + string_free(ANGBAND_DIR_USER); + ANGBAND_DIR_DATA = string_make("/sil-data/"); + ANGBAND_DIR_APEX = string_make("/sil-user/apex/"); + ANGBAND_DIR_SAVE = string_make("/sil-user/save/"); + ANGBAND_DIR_USER = string_make("/sil-user/user/"); + mkdir("/sil-data", 0755); + mkdir("/sil-user", 0755); + mkdir("/sil-user/apex", 0755); + mkdir("/sil-user/save", 0755); + mkdir("/sil-user/user", 0755); +#endif /* __EMSCRIPTEN__ */ + #ifdef NeXT /* Allow "fat binary" usage with NeXT */ diff --git a/src/main.c b/src/main.c index 94600f7..f480827 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,10 @@ #include "main.h" +#ifdef __EMSCRIPTEN__ +extern void cw_set_nokeypad_keys(const char* keys); /* curses-web/curses.h */ +#endif + /* * Sil-y: game in progress */ @@ -373,6 +377,11 @@ int main(int argc, char* argv[]) /* Save the "program name" XXX XXX XXX */ argv0 = argv[0]; +#ifdef __EMSCRIPTEN__ + /* The arrow keys and Home/End/PageUp/PageDown walk (the curses layer sends these digits for them) */ + cw_set_nokeypad_keys("82467193"); +#endif + #ifdef USE_286 /* Attempt to use XMS (or EMS) memory for swap space */ if (_OvrInitExt(0L, 0L)) diff --git a/src/util.c b/src/util.c index bdc0c1d..408896c 100644 --- a/src/util.c +++ b/src/util.c @@ -60,6 +60,13 @@ void user_name(char* buf, size_t len, int id) { struct passwd* pw; +#ifdef __EMSCRIPTEN__ + /* the browser has no user names */ + (void)id; + my_strcpy(buf, "Player", len); + return; +#endif + /* Look up the user name */ if ((pw = getpwuid(id))) {