Skip to content
Snippets Groups Projects
Commit 5c17bc5a authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Merge branch 'gttrivia_hosted_scores' into 'master'

Good Time Trivia: Hosted inter-BBS user scores (via JSON DB) is now possible.

See merge request !221
parents b98bdb18 ce3c8132
No related branches found
No related tags found
2 merge requests!463MRC mods by Codefenix (2024-10-20),!221Good Time Trivia: Hosted inter-BBS user scores (via JSON DB) is now possible.
......@@ -26,3 +26,10 @@ answerAfterIncorrect=G
[CATEGORY_ARS]
dirty_minds=AGE 18
[REMOTE_SERVER]
server=digitaldistortionbbs.com
port=10088
[SERVER]
deleteScoresOlderThanDays=182
This diff is collapsed.
// Gets the JSON service port number from services.ini (if possible)
function getJSONSvcPortFromServicesIni()
{
var portNum = 0;
var servicesIniFile = new File(system.ctrl_dir + "services.ini");
if (servicesIniFile.open("r"))
{
var sectionNamesToTry = [ "JSON_DB", "JSON-DB", "JSON" ];
for (var i = 0; i < sectionNamesToTry.length; ++i)
{
var jsonServerCfg = servicesIniFile.iniGetObject(sectionNamesToTry[i]);
if (jsonServerCfg != null && typeof(jsonServerCfg) === "object")
{
portNum = jsonServerCfg.Port;
break;
}
}
servicesIniFile.close();
}
return portNum;
}
\ No newline at end of file
......@@ -1426,7 +1426,7 @@ I'm a 4-letter word ending in UNT. You do me when you lose your balls. When you'
Hunt
10
I hang between your chest and knes. The older I am, the bigger I get. There's hair growing on my hole.
I hang between your chest and knees. The older I am, the bigger I get. There's hair growing on my hole.
Belly
10
......
......@@ -1347,7 +1347,7 @@ Zloty
10
How tall is the Empire State Building (without the spire and antenna)?
1,250 feet
1250 feet
10
Which country produces the most tea?
......
Good Time Trivia
Version 1.00
Release date: 2022-11-18
Version 1.01
Release date: 2022-11-25
by
......@@ -22,6 +22,9 @@ Contents
3. Installation & Setup
- Installation in SCFG
4. Configuration file
5. Optional: Configuring your BBS to host player scores
- Only do this if you would prefer to host scores on your BBS rather than
using the inter-BBS scores hosted on Digital Distortion
1. Disclaimer
......@@ -84,7 +87,11 @@ of the following files and directories:
3. gttrivia.asc The logo/startup screen to be shown to the user.
This is in Synchronet attribute code format.
4. qa This is a subdirectory that contains the trivia
4. install-xtrn.ini A configuration file for automated installation into
Synchronet's external programs section; for use with
install-xtrn.js. This is optional.
5. qa This is a subdirectory that contains the trivia
question & answer files. Each file contains a
collection of questions, answers, and number of
points for each question. Each filename must have
......@@ -93,6 +100,17 @@ of the following files and directories:
questions (underscores are required between each
word). The filename extension must be .qa .
6. server This directory contains a couple scripts that are
used if you enable the gttrivia JSON database (for
hosting game scores on a Synchronet BBS so that scores
from players on multiple BBSes can be hosted and
displayed). As of this writing, I host scores for
Good Time Trivia on my BBS (Digital Distortion), so
unless you really want to do your own score hosting,
you can have your installation of the game read
inter-BBS scores from Digital Distortion.
The trivia category files (in the qa directory, with filenames ending in .qa)
are plain text files and contain questions, their answers, and their number of
points. For eqch question in a category file, there are 3 lines:
......@@ -135,7 +153,8 @@ gttrivia.js.
Installation in SCFG
--------------------
This is an example of adding the game in one of your external programs sections
in SCFG:
in SCFG (note that the 'Native Executable/Script value doesn't matter for JS
scripts):
╔═════════════════════════════════════════════════════[< >]╗
║ Good Time Trivia ║
╠══════════════════════════════════════════════════════════╣
......@@ -149,7 +168,7 @@ in SCFG:
║ │Execution Requirements ║
║ │Multiple Concurrent Users Yes ║
║ │I/O Method FOSSIL or UART ║
║ │Native Executable/Script No
║ │Native Executable/Script Yes
║ │Use Shell or New Context No ║
║ │Modify User Data No ║
║ │Execute on Event No ║
......@@ -166,6 +185,7 @@ gttrivia.ini is the configuration file for the door game. There are 3 sections:
[BEHAVIOR], [COLORS], and [CATEGORY_ARS]. The settings are described below:
[BEHAVIOR] section
------------------
Setting Description
------- -----------
numQuestionsPerPlay The maximum number of trivia questions
......@@ -181,10 +201,12 @@ maxNumPlayerScoresToDisplay The maximum number of player scores to display
in the list of high scores
[COLORS] section
----------------
In this section, the color codes are simply specified by a string of color
(attribute) code characters (i.e., YH for yellow and high). See this page for
Synchronet attribute codes:
http://wiki.synchro.net/custom:ctrl-a_codes
Setting Element applied to
------- -------------------
error Errors
......@@ -211,6 +233,7 @@ clue Clue text
answerAfterIncorrect The answer printed after incorrect response
[CATEGORY_ARS] section
----------------------
In this section, the format is section_name=ARS string
section_name must match the part of a filename in the qa directory without the
filename extension. The ARS string is a string that Synchronet uses to describe
......@@ -220,3 +243,57 @@ categories that you may want age-restricted, for instance). See the following
web page for documentation on Synchronet's ARS strings:
http://wiki.synchro.net/access:requirements
[REMOTE_SERVER] section
-----------------------
This section is used for specifying a remote server to connect to. Currently,
this is used for writing & reading player scores on the remote system. Inter-
BBS scores (retrieved from the remote system) can be optionally viewed when a
user is viewing scores.
Setting Description
------- -----------
server The server hostname/IP address. The default
value can be used if you want to use Digital
Distortion BBS.
port The port number to use to connect to the
remote host. The default value is set for
Digital Distortion.
[SERVER] section
----------------
This section is only used if you decide to host scores for Good Time Trivia.
Setting Description
------- -----------
deleteScoresOlderThanDays The number of days to keep old player scores.
The background service will remove player
scores older than this number of days.
5. Optional: Configuring your BBS to host player scores
=======================================================
You should only do this if you would prefer to host scores on your BBS rather
than using the inter-BBS scores hosted on Digital Distortion.
If you want to host player scores for Good Time Trivia, first ensure you have a
section in your ctrl/services.ini configured to run json-service.js (usually
with a name of JSON, or JSON in the name):
[JSON]
Port=10088
Options=STATIC | LOOP
Command=json-service.js
Note that those settings configure it to run on port 10088. Also, you might
already have a similar section in your services.ini if you currently host any
JSON databases.
Then, open your ctrl/json-service.ini and add these lines to enable the gttrivia
JSON dtaabase:
[gttrivia]
dir=../xtrn/gttrivia/server/
It would then probably be a good idea to stop and re-start your Synchronet BBS
in order for it to recognize that you have a new JSON database configured.
......@@ -4,4 +4,11 @@ Revision History (change log)
=============================
Version Date Description
------- ---- -----------
1.01 2022-11-25 Added the ability to store & retrieve scores to/from a
server, so that scores from multiple BBSes can be
displayed. By default, it's configured to use Digital
Distortion as the host. There are also sysop functions
to remove players and users from the hosted inter-BBS
scores. Also, answer clues now don't mask spaces in the
answer.
1.00 2022-11-18 Initial version/release
\ No newline at end of file
this.QUERY = function(client, packet)
{
// Operations that are allowed by clients
var openOpers = [ "READ", "WRITE", "SUBSCRIBE", "UNSUBSCRIBE" ];
// The openOpers operations are okay to run; also, allow anything from the current machine
if (openOpers.indexOf(packet.oper) >= 0 || client.remote_ip_address === '127.0.0.1')
return false;
else
return true;
// Disallowed operations
//var invalidOps = [ "PUSH", "POP", "SHIFT", "UNSHIFT", "DELETE", "SLICE" ];
}
// For Good Time Trivia JSON database.
// This is a long-running background script.
// Values for JSON DB reading and writing
var JSON_DB_LOCK_READ = 1;
var JSON_DB_LOCK_WRITE = 2;
var JSON_DB_LOCK_UNLOCK = -1;
var NUM_SECONDS_PER_DAY = 86400;
// gRootTriviaScriptDir is the root directory where service.js is located
var gRootTriviaScriptDir = argv[0];
var requireFnExists = (typeof(require) === "function");
if (requireFnExists)
{
require("json-client.js", "JSONClient");
require(gRootTriviaScriptDir + "../lib.js", "getJSONSvcPortFromServicesIni");
}
else
{
load("json-client.js");
load(gRootTriviaScriptDir + "../lib.js");
}
var gSettings, gJSONClient;
function processUpdate(update)
{
log(LOG_INFO, "Good Time Trivia: Update");
if (gSettings.server.deleteScoresOlderThanDays > 0)
{
// Look through the server data for old scores that we might want to delete
try
{
var data = gJSONClient.read(gSettings.remoteServer.gtTriviaScope, "SCORES", JSON_DB_LOCK_READ);
// Example of scores from the server (as of data version 1.01):
/*
SCORES:
systems:
DIGDIST:
bbs_name: Digital Distortion
user_scores:
Nightfox:
category_stats:
0:
category_name: General
last_score: 20
last_time: 2022-11-24
total_score: 60
last_score: 20
last_trivia_category: General
last_time: 2022-11-24
*/
/*
if (typeof(data) === "string")
data = JSON.parse(data);
*/
// Sanity checking: Make sure the data is an object and has a "systems" property
if (typeof(data) !== "object")
return;
if (!data.hasOwnProperty("systems"))
return;
for (var BBS_ID in data.systems)
{
var now = time();
if (!data.systems[BBS_ID].hasOwnProperty("user_scores"))
continue;
for (var playerName in data.systems[BBS_ID].user_scores)
{
if (data.systems[BBS_ID].user_scores[playerName].last_time < now - (NUM_SECONDS_PER_DAY * gSettings.server.deleteScoresOlderThanDays))
{
// Delete this user's entry
var JSONLocation = format("SCORES.systems.%s.user_scores.%s", BBS_ID, playerName);
gJSONClient.remove(gtTriviaScope, JSONLocation, LOCK_WRITE);
}
}
}
}
catch (err)
{
log(LOG_ERR, "Good Time Trivia: Line " + err.lineNumber + ": " + err);
}
}
}
function init()
{
// Assuming this script is in a 'server' subdirectory, gttrivia.ini should be one directory up
gSettings = readSettings(gRootTriviaScriptDir + "../");
try
{
gJSONClient = new JSONClient("127.0.0.1", getJSONSvcPortFromServicesIni());
gJSONClient.subscribe(gSettings.remoteServer.gtTriviaScope, "SCORES");
gJSONClient.callback = processUpdate;
processUpdate();
log(LOG_INFO, "Good Time Trivia JSON DB service task initialized");
}
catch (error)
{
log(LOG_ERROR, error);
}
}
var readSettings = function(path)
{
var settings = {
readSuccessful: false
};
var iniFile = new File(path + "gttrivia.ini");
if (iniFile.open("r"))
{
settings.remoteServer = iniFile.iniGetObject("REMOTE_SERVER");
settings.server = iniFile.iniGetObject("SERVER");
iniFile.close();
settings.readSuccessful = true;
if (typeof(settings.remoteServer) !== "object")
settings.remoteServer = {};
if (!/^[0-9]+$/.test(settings.remoteServer.port))
settings.remoteServer.port = 0;
if (typeof(settings.server.deleteScoresOlderThanDays) !== "number")
settings.server.deleteScoresOlderThanDays = 0;
else if (settings.server.deleteScoresOlderThanDays < 0)
settings.server.deleteScoresOlderThanDays = 0;
// Other settings - Not read from the configuration file, but things we want to use in multiple places
// in this script
// JSON scope
settings.remoteServer.gtTriviaScope = "GTTRIVIA";
if (settings.server.deleteScoresOlderThanDays > 0)
log(LOG_INFO, "Good Time Trivia service: Will delete user scores older than " + settings.server.deleteScoresOlderThanDays + " days");
}
return settings;
}
function main()
{
while (!js.terminated)
{
mswait(5);
gJSONClient.cycle();
}
}
function cleanUp()
{
gJSONClient.disconnect();
}
try
{
init();
main();
cleanUp();
} catch (err) { }
exit();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment