--- a/mdport.c +++ b/mdport.c @@ -55,9 +55,7 @@ #include #endif -#if defined(HAVE_PWD_H) #include -#endif #if defined(HAVE_SYS_UTSNAME) #include @@ -268,8 +266,12 @@ #elif defined(__PDCURSES__) return(TRUE); #else +#ifdef __EMSCRIPTEN__ + return(1); +#else return((CE != NULL) && (*CE != 0)); #endif +#endif } void @@ -421,6 +423,10 @@ { static char login[80]; char *l = NULL; +#ifdef __EMSCRIPTEN__ + /* fredygames.com: one player per browser; the name shows in the score list */ + return("adventurer"); +#endif #ifdef _WIN32 LPSTR mybuffer; DWORD size = UNLEN + 1; @@ -455,6 +461,10 @@ static char homedir[PATH_MAX]; char *h = NULL; size_t len; +#ifdef __EMSCRIPTEN__ + /* fredygames.com: the folder the page keeps in IndexedDB (save game and scores) */ + return("/rogue-saves/"); +#endif #if defined(_WIN32) TCHAR szPath[PATH_MAX]; #endif --- a/main.c +++ b/main.c @@ -12,6 +12,9 @@ #include #include #include +#ifdef __EMSCRIPTEN__ +#include +#endif #include #include "rogue.h" @@ -101,6 +104,17 @@ } init_check(); /* check for legal startup */ +#ifdef __EMSCRIPTEN__ + /* fredygames.com: saving ends the game, so the next visit picks the saved game up again */ + if (argc == 1 && access(file_name, R_OK) == 0) + { + static char *saved[2]; + saved[0] = argv[0]; + saved[1] = file_name; + argv = saved; + argc = 2; + } +#endif if (argc == 2) if (!restore(argv[1], envp)) /* Note: restore will never return */ my_exit(1); --- a/rip.c +++ b/rip.c @@ -270,7 +270,12 @@ score(purse, amulet ? 3 : 0, monst); printf("[Press return to continue]"); fflush(stdout); +#ifdef __EMSCRIPTEN__ + /* fredygames.com: there is no stdin; wait for Return on the page */ + { int c; do c = cw_getkey(-1); while (c != '\n' && c != '\r'); } +#else (void) fgets(prbuf,10,stdin); +#endif my_exit(0); }