===============================================================================
 RGJS v1.00 - JavaScript BBS door host                    NewWave Software
===============================================================================

 RGJS runs Synchronet JavaScript doors - LORD/JS (Legend of the Red Dragon
 5.00 JS) and its IGMs, Star Trek, NewsCenter, and other native Synchronet
 JS doors - on
 a DOS or Win32 BBS, with NO Synchronet.  No jsexec.exe, no sbbs.dll, no
 SpiderMonkey (mozjs185), no NSPR.  Doors drop in and run unchanged.

 It is a DOOR32 door: RGFL/RGCOM (RGFOSSIL) start it with the caller's
 socket, it runs the script, and it exits when the door does or the caller
 hangs up.  Nothing stays resident.

 CONTENTS
   1. What's in the package
   2. Installing LORD/JS
   3. Running it from Renegade (RGFOSSIL) / other BBSes
   4. Command line
   5. Local / sysop testing
   6. How it works
   7. What is supported
   8. Troubleshooting
   

 1. WHAT'S IN THE PACKAGE
 ------------------------
   BIN\RGJS.EXE       the door host (Win32 console, 32-bit, Win7+)
   BIN\DUKTAPE.DLL    the JavaScript engine (Duktape 2.7.0, MIT license)
   BIN\LIB\           RGJS's JavaScript runtime - must sit beside RGJS.EXE:
       rgjs.js          File, file_*(), format(), strftime(), load(),
                        require(), js.exec(), exit(), INI reading ...
       dorkit.js        door kit: dk.console / dk.user / dk.connection
       recordfile.js    fixed-length record files (player.bin etc.)
       array.js         Array helpers some doors load()
       sbbs.js          console / bbs / system / user / client objects for
                        native Synchronet doors, plus Socket/ConnectedSocket
                        (outbound TCP + TLS) so http.js works
       e4x.js           SpiderMonkey's E4X XML objects (rss-atom.js etc.)
       http.js          wrapper around LIB\LOAD\http.js: follows redirects
                        (up to 5) and logs each request to RGJS.LOG
       lockfile.js      Lock()/Unlock() lock files (works in dorkit doors)
       json-client.js   local stand-in for Synchronet's JSON DB client -
                        scores/state are kept in the door's JSON\ folder
       LOAD\            Synchronet's plain-JS libraries (frame.js, sprite.js,
                        layout.js, event-timer.js, tree.js ...), unmodified

 RGJS's own JavaScript in LIB\ is new code.  LIB\LOAD\ holds Synchronet's
 library .js files unmodified (GPL - see LIB\LOAD\README.TXT) so doors that
 load() them work as written.  LIB\ is searched first, so RGJS's versions
 of dorkit.js, recordfile.js, array.js and json-client.js are the ones used.


 2. INSTALLING LORD/JS
 ---------------------
   1. Copy RGJS somewhere, e.g.  D:\DOORS\RGJS\
         RGJS.EXE, DUKTAPE.DLL and the LIB\ folder.
   2. Unpack LORD/JS to its own folder, e.g.  D:\DOORS\LORD\
      You can DELETE everything Synchronet from it - RGJS never uses them:
         jsexec.exe  sbbs.dll  sbbsexec.dll  mozjs185-1.0.dll  nspr4.dll
         cl32.dll  zlib1.dll  archive.dll  ftpsrvr.dll  mailsrvr.dll
         services.dll  websrvr.dll
   3. Edit LORD.INI as usual (days, fights, etc.).  Leave GameServer
      commented out (see section 7).
   4. IGMs: LORD's 3RDPARTY.LRD may list Synchronet paths such as
         \sync\xtrn\lord\barak\barak.js
      You don't have to fix them: RGJS drops leading folders until the
      script is found under the LORD folder (-> barak\barak.js).  Writing
      them the documented way, relative to the LORD folder, is fine too:
         barak/barak.js

   Existing PLAYER.BIN / STATE.BIN from a Synchronet LORD/JS game keep
   working - RGJS's record files use the same byte layout.


 3. RUNNING IT FROM RENEGADE (RGFOSSIL)
 --------------------------------------
 Renegade (DOS under NTVDM) writes DOOR.SYS.  RGFL turns it into
 DOOR32.SYS and asks the node's RGCOM to start RGJS.  RGCOM owns the
 socket, pauses the FOSSIL pipes, and starts RGJS in the node's console
 with the socket inherited - so RGJS talks straight to the caller.  When
 LORD ends, RGJS exits, RGCOM resumes the pipes, and RGFL returns to
 Renegade.

 Door menu command (one line), with the ^ shortcut for DOOR32.SYS:

   RGFL C:\RG\NODE%1 "D:\DOORS\RGJS\RGJS.EXE -D^ D:\DOORS\LORD\LORD.JS"

 or from a door batch file:

   @echo off
   cd /d D:\DOORS\LORD
   RGFL C:\RG\NODE%1 "D:\DOORS\RGJS\RGJS.EXE -D^ D:\DOORS\LORD\LORD.JS"

 RGFL options work as usual - e.g. /H to give LORD the caller's handle
 instead of the real name (LORD keys players by that name).

 The sysop view: RGJS draws the caller's screen in the node window (in
 its own console buffer, so the node window looks exactly as before when
 the door exits).  Alt+H in that window hangs the caller up.

 Any other BBS that can start a DOOR32 door with a DOOR32.SYS works the
 same way - just point it at RGJS.EXE -D<path to DOOR32.SYS> <script.js>.

 Other Win32 BBSes - no RGFOSSIL needed
 --------------------------------------
 RGFOSSIL is only for DOS BBSes (Renegade under NTVDM).  RGJS.EXE is a
 native Win32 DOOR32 door, so a Win32 BBS that writes DOOR32.SYS and hands
 the door its socket runs it directly:

   Mystic/32, WWIV 5, EleBBS/32, Maximus/32, BBBS, Enigma 1/2, etc.
     D:\DOORS\RGJS\RGJS.EXE -D<node dir>\DOOR32.SYS D:\DOORS\LORD\LORD.JS
     (use your BBS's code for the node folder, e.g. Mystic's %P)

   Synchronet runs these doors itself - it doesn't need RGJS.

 The BBS must let the door inherit the socket (all DOOR32 BBSes do).  RGJS
 never closes it, so the caller goes back to the BBS when the door ends.
 Linux: see README-LINUX.TXT in the LINUX folder (no RGFOSSIL there either).


 4. COMMAND LINE
 ---------------
   RGJS [options] <script.js> [script args...]

   -D<file>   dropfile.  DOOR32.SYS (normal - socket handle on line 2) or
              DOOR.SYS (52 line GAP format - local play only, it has no
              socket).  "-D file" with a space works too.
              Without -D: DOOR32.SYS, then DOOR.SYS, in the current folder.
   -L         local mode - the console is the caller; any socket is ignored
   -N         no sysop view (nothing drawn locally)
   -R         raw socket - no telnet IAC processing
   -A         use the caller's alias/handle as their name
   -V         verbose RGJS.LOG - everything, incl. each web request
   -Q         quiet - no RGJS.LOG at all

   Anything after the script name goes to the script as argv[], e.g.
   LORD's own maintenance switches:
      RGJS.EXE -L D:\DOORS\LORD\LORD.JS RESET
      RGJS.EXE -L D:\DOORS\LORD\LORD.JS +IGM barak/barak.js

   Errorlevel: the script's exit code (0 normal), 1 = RGJS could not
   start, 2 = the script stopped with an error, 3 = engine fatal error.


 5. LOCAL / SYSOP TESTING
 ------------------------
   cd /d D:\DOORS\LORD
   D:\DOORS\RGJS\RGJS.EXE -L -D C:\RG\NODE1\DOOR.SYS LORD.JS

 -L plays in the console window.  The player's name, security level,
 time left, ANSI and screen rows come from the dropfile (with no dropfile:
 "Sysop", level 10, 60 minutes, ANSI on).


 6. HOW IT WORKS
 ---------------
 RGJS.EXE embeds the Duktape JavaScript engine and gives it a few native
 functions (files, locks, time, the caller's socket, the local screen).
 Everything a Synchronet door expects - the File object, file_exists(),
 format(), strftime(), load()/require(), js.exec(), exit(), dorkit - is
 written in JavaScript on top of those, in BIN\LIB\.

 Characters are "byte strings": each JS character is one CP437 byte, just
 like under Synchronet, so ANSI art and the line-drawing characters go to
 the caller unchanged.

 IGMs (js.exec) run in their own global scope whose parent is LORD's, so
 an IGM sees LORD's globals (player, dk, lln() ...) while its own
 top-level variables (like `install`) stay in its scope - the same way
 they behave under Synchronet.

 Multi-node: PLAYER.BIN and friends use real Windows byte-range locks
 (LockFile).  Record reads are unbuffered so a node never trips over a
 record another node has locked; text files (.LRD) are read buffered.


 7. WHAT IS SUPPORTED
 --------------------
 Two kinds of Synchronet JS door, picked automatically per door:

   dorkit doors (they load("dorkit.js")) - e.g. LORD/JS.  Run on RGJS's
     dorkit.  No Synchronet objects are defined, which is what these
     doors expect when they're not on Synchronet.

   native doors (everything else) - e.g. Star Trek.  RGJS defines console,
     bbs, system, user and client before the door starts, and the door's
     load("frame.js") etc. come from LIB\LOAD.

 Synchronet's own door set (sbbs xtrn\ folder), checked 2026-11-14:
   Run: ansiview, avatar_chat, bublbogl, chickendelivery, dgnlance,
     dicewarz, druglord, fatfish, flight_sim, gooble, gttrivia, hamtest,
     kingdom, knk, lemons, life, lord, lord2, mc, minesweeper, oneliners,
     pisorama, postit, starstocks, startrek, synchess, syncwall,
     synkroban, synthkart, thirsty, ttrivia, tw2, uberblox, utopia, war.
   Live test needed (they talk to a remote server): jeopardized, go-for.
   TradeWars 2 (tw2): set Server=localhost in game.ini, then build the
     universe once from the door folder:  RGJS -L twint500.js
     (press Enter at "Which", answer Y to "Reset Game").
   Multiplayer rooms that need Synchronet's JSON service running the door's
     own service.js: dicewarz2, maze, synchronetris (shows its lobby only).
   Message-base doors (Synchronet message areas don't exist here):
     dovebowl, slyvote, bullshit.
   chess: needs commclient.js, which Synchronet no longer ships.

 Tested:
   LORD/JS 5.00 - intro, rankings, new players, town, forest fights, bank,
     inn, quitting, all five bundled IGMs (Pickles, Aragorn's Timer, Barak's
     House, The Grab Bag, Olodrin's Orphanage).  Existing Synchronet player
     files load as-is.
   LORD II: New World 1.01 (JS port) - intro, help, menus, new character,
     daily happenings, maps, quitting.
   Kannons and Katapults 5.0js (Davenport/Deuce) - intro, ANSI music
     detection, full turns, battles, quitting, scores (knk-best.asc etc.).
   Dragonlance 3.0 (Deuce) - credits, new players, fights, quitting,
     players.ini saved.  Note: its player.js treated a player who isn't in
     players.ini yet as "already died today" (fixed copy, marked RGJS fix).
   Star Trek (echicken) - splash, ship selection, sprites/combat, high
     scores (kept locally in STARTREK\JSON\STARTREK.JSON).
   NewsCenter 0.261002 (codefenix) - feed menu, Digital Distortion lightbar
     menus, RSS and Atom feeds over http and https, article view, full
     article text straight from the news site, feed status saved back to
     newsfeeds.json.  Works with or without curl (see 7a).
     Note: its rss-curl.js has a bug - when curl fails it never falls back
     to the built-in HTTP client.  Fixed copy: one line, marked "RGJS fix".
     Note: Star Trek itself has a bug on its very FIRST game (no scores yet)
     - scoreBoard() reads past the end of the list and stops with
     "cannot read property 'alias'".  It does the same on Synchronet.  The
     score is still saved, and every game after that works.

 Interbbs/network features become local: JSONClient reads and writes the
 door's own JSON\ folder, so scoreboards are per-BBS.

 Not supported:
   * LORD's InterBBS game server (GameServer= in LORD.INI / LORDSRV.JS).
   * load(true, ...) background threads, raw Socket networking.
   * Doors that run other BBS functions through Synchronet: bbs.exec()
     menus, message bases (MsgBase), file areas (FileBase), user editing.
     The calls exist so doors don't crash, but they do nothing.

 If a door stops with "X is not defined" / "unable to find X", RGJS.LOG has
 the line - send it to me and I'll add what's missing.  The error is also
 shown on screen for 3 seconds before RGJS exits.

 7a. INTERNET ACCESS (RSS, HTTP)
 -------------------------------
 Native doors can make outbound connections the Synchronet way (Socket,
 ConnectedSocket, and so http.js / rss-atom.js).  The CALLER's socket is
 never used for this.

   http://   works out of the box.
   https://  needs OpenSSL 3, 32-bit:  libssl-3.dll + libcrypto-3.dll
             copied beside RGJS.EXE (or anywhere on the PATH).  RGJS loads
             them the first time a door asks for https; without them that
             one request fails (logged as "https needs OpenSSL 3 ...") and
             the door carries on.  Certificates are not verified.
             Linux: uses the system's libssl.so.3.

 With -V every web request is logged:  HTTP <status> <bytes> <url>
 - if an article comes up blank, that line shows what the site sent.
 NewsCenter also keeps the last pages it fetched in its TEMP<node> folder
 (temp-news-ff.html = via FrogFind, temp-news-raw.html = the site itself).

 Doors can also run programs with system.exec() (cmd.exe /c on Windows);
 the caller's socket is NOT passed to them.  bbs.exec("?script.js ...")
 runs another JS script.

 NewsCenter: most of its feeds are https, so install the OpenSSL DLLs.  It
 tries the curl program first (curl.exe on the PATH or beside RGJS.EXE -
 Win7 doesn't ship one) and falls back to RGJS's own HTTP/HTTPS, so curl
 is optional.  Without xtrn/scroller it shows articles with a simple
 pager.

 8. TROUBLESHOOTING
 ------------------
 RGJS.LOG (beside RGJS.EXE) gets warnings and errors only - script error
 traces with file and line, socket problems, a door's own warnings.  A
 normal session writes nothing.  Add -V to the command line to log
 everything (start/exit, each web request); add -Q to turn the log off.

   "missing ...\LIB\rgjs.js"    the LIB folder isn't beside RGJS.EXE
   "script not found"          wrong path to LORD.JS
   socket ... failed getsockopt   logged as a warning; RGJS still tries
                               the socket.  If the caller sees nothing,
                               the door wasn't started by RGCOM with the
                               socket inherited - check the RGFL line and
                               that %NFNODE% and %SOCKET% are set.
   "load(): unable to find X"  a script needs a library RGJS doesn't
                               have - send me the name.
   Caller drops               the door saves the player and exits at once
                               (errorlevel 0).

 Key tracing: set RGJS_KEYLOG=1 and use -V; every key the door reads is
 logged with the script line that read it.


 Duktape is (c) Sami Vaarala and contributors, MIT license (DUK\LICENSE.TXT).
 LORD/JS is (c) its authors; RGJS only runs it.
===============================================================================
