AJAX Commentary

Live chat enhancement built directly into the core commentary system (not a separate installable module — there's no "AJAX Commentary" entry in the module list because there's nothing to install or uninstall). Automatically refreshes commentary sections every 5 seconds, fixed, for every player, without a page reload. Plain JavaScript (no jQuery) polls for new comments and pauses automatically while the browser tab is hidden. Posts comments without refresh. Auto-pauses in sync with your session's inactivity timeout, which defaults to 15 minutes, not 6.

How It Works

Auto-Refresh System:

  • JavaScript timer polls the server every 5 seconds, flat — there's no setting to speed it up or slow it down, everyone gets the same cadence
  • Fetches new comments since last ID via AJAX call to /ajaxcommentary.php
  • Updates commentary div with new content (no page reload)
  • Automatically skips polling entirely while the browser tab is hidden (Page Visibility API), then polls immediately on refocus
  • Resets timer for next poll

Posting Comments:

  • Type comment in form
  • Submit via AJAX form submission (plain JavaScript, not jQuery)
  • Comment posted instantly without page reload
  • Form clears after successful post

Inactivity Detection:

  • Page time counter tracks time since last user interaction
  • Idle-pause timing is derived from your session's inactivity timeout (server setting, 15 minutes by default) — not a fixed 6-minute window
  • Message displayed near the timeout: a warning that your session is about to expire, with a link to stay logged in and keep polling
  • Click link → Resets the session timer and resumes auto-refresh

No User-Configurable Preferences

There is no "Live Chat" preferences panel and no refresh-speed dropdown. The 5-second poll interval is hardcoded for every player — you can't speed it up, slow it down, or turn it off from a settings page. The only thing you personally control is your session's inactivity timeout, and even that's a server-wide setting (default 15 minutes), not a per-user pref.

Technical Details

JavaScript:

  • Plain vanilla JavaScript — no jQuery dependency, no external libraries
  • Uses the browser's native fetch API; gracefully does nothing on ancient browsers that lack it

Database Table:

  • chatareakeys: Stores unique MD5 keys per commentary section
  • Columns: chatarea (section name), areakey (MD5 hash), settime (timestamp)
  • Purpose: Secure identification of commentary areas for AJAX calls

AJAX Endpoint:

  • URL: /ajaxcommentary.php
  • Modes: manualrefresh (fetch new comments), addcomment (post comment)
  • Parameters: lastid, acctid, section, areakey, talkline
  • Response: JSON with new commentary HTML, replaceform flag, lastid

Key Generation:

  • Per-area unique key generated from section name + timestamp + random.org 500 integers
  • MD5 hashed for security
  • Prevents unauthorized AJAX polling of commentary sections

Benefits

For Users:

  • Real-time chat experience without manual refresh
  • Faster conversation flow in village commentary
  • No lost text when typing during page refresh
  • Consistent, predictable update speed (5 seconds, same for everyone)

For Server:

  • Lower bandwidth than full page reloads
  • Polling stops entirely for hidden/background tabs, and idle-pauses in step with your session timeout, saving server resources
  • Efficient JSON responses vs full HTML pages

Limitations

  • Requires JavaScript: No live chat without JS enabled (falls back to manual refresh)
  • Fixed Refresh Rate: Everyone polls every 5 seconds; there's no way to speed it up or slow it down
  • No Offline Queuing: If connection lost, comments don't queue (user must refresh)
  • Session-Length Timeout: Polling idle-pauses on the same clock as your session's inactivity timeout (15 minutes by default), and you'll need to click through the "still there?" prompt to keep it going

Comparison to Manual Refresh

Without AJAX Commentary:

  • Must manually click "Refresh" or reload page
  • Lose typed text when refreshing
  • Full page reload every time
  • Slower conversation

With AJAX Commentary:

  • Auto-refresh every 5 seconds
  • Keep typed text during refresh
  • Only commentary section updates
  • Real-time chat feel

Strategy

What You Can Actually Control:

  • Nothing about the refresh rate — it's fixed at 5 seconds for every player, so there's no setting to tune here
  • Your session's inactivity timeout (server default: 15 minutes) governs when idle polling pauses; staying active in the game resets it naturally

If You Want to Avoid It:

  • Disable JavaScript in your browser (falls back to manual, page-reload-based commentary — with everything else that implies)
  • Otherwise, live polling is just how commentary sections behave now; there's no in-game toggle to turn it off

Hooks Used

  • viewcommentaryheader: Inject JavaScript and init code
  • viewcommentaryfooter: Start auto-refresh timer
  • commentarytalkline: Attach AJAX form submission handler

AJAX Commentary: where your browser polls the server every 5 seconds asking "any new messages? any new messages? any new messages?" like an impatient child on a road trip, and once your session's been idle long enough (15 minutes by default, not the urban legend of 6) the system makes you click a button to prove you're still awake. There's no dial to turn the chattiness up or down — 5 seconds is 5 seconds for everyone, and there was never a module to install in the first place; this has been quietly baked into the game's core since before you got here. At least you don't lose your carefully-typed insult when the page auto-refreshes.