Skip to content
Snippets Groups Projects
Commit 91babf1d authored by Eric Oulashin's avatar Eric Oulashin Committed by Rob Swindell
Browse files

Good Time Trivia: Make a copy of js.exec_dir on startup and use the copy,...

Good Time Trivia: Make a copy of js.exec_dir on startup and use the copy, since js.exec_dir could change indirectly (i.e., console.yesno() running yesnobar.js in sbbs/exec)
parent d8a0991c
Branches
Tags
2 merge requests!455Update branch with changes from master,!430Good Time Trivia: Make a copy of js.exec_dir on startup and use the copy, since js.exec_dir could change indirectly (i.e., console.yesno() running yesnobar.js in sbbs/exec)
...@@ -34,6 +34,9 @@ Date Author Description ...@@ -34,6 +34,9 @@ Date Author Description
2024-03-26 Eric Oulashin Version 1.04 2024-03-26 Eric Oulashin Version 1.04
Formatting fix for sysop menu when the server scores file is missing. Formatting fix for sysop menu when the server scores file is missing.
Allow showing help when playing a game by entering ? Allow showing help when playing a game by entering ?
2024-03-29 Eric Oulashin Version 1.05
Ensure the correct script startup directory is always used (make
a copy of js.exec_dir on startup, since js.exec_dir could change)
*/ */
"use strict"; "use strict";
...@@ -59,8 +62,8 @@ if (system.version_num < 31500) ...@@ -59,8 +62,8 @@ if (system.version_num < 31500)
} }
// Version information // Version information
var GAME_VERSION = "1.04"; var GAME_VERSION = "1.05";
var GAME_VER_DATE = "2024-03-26"; var GAME_VER_DATE = "2024-03-29";
// Load required .js libraries // Load required .js libraries
var requireFnExists = (typeof(require) === "function"); var requireFnExists = (typeof(require) === "function");
...@@ -77,6 +80,12 @@ else ...@@ -77,6 +80,12 @@ else
load(js.exec_dir + "lib.js"); load(js.exec_dir + "lib.js");
} }
// Make a copy of js.exec_dir. js.exec_dir could be changed indirectly
// due to another JS script running (for instance, via console.yesno(),
// which would run yesnobar.js in sbbs/exec).
const gScriptExecDir = js.exec_dir;
// Characters for display // Characters for display
// Box-drawing/border characters: Single-line // Box-drawing/border characters: Single-line
...@@ -127,10 +136,10 @@ var LOWER_CENTER_BLOCK = "\xDC"; ...@@ -127,10 +136,10 @@ var LOWER_CENTER_BLOCK = "\xDC";
// Maximum Levenshtein distance (inclusive) to consisder an answer matching (when appropriate) // Maximum Levenshtein distance (inclusive) to consisder an answer matching (when appropriate)
var MAX_LEVENSHTEIN_DISTANCE = 2; var MAX_LEVENSHTEIN_DISTANCE = 2;
// Scores filename // Scores filename
var SCORES_FILENAME = js.exec_dir + "scores.json"; var SCORES_FILENAME = gScriptExecDir + "scores.json";
// Semaphore filename to use when saving the user's score to try to prevent multiple instances // Semaphore filename to use when saving the user's score to try to prevent multiple instances
// from overwriting the score on each other // from overwriting the score on each other
var SCORES_SEMAPHORE_FILENAME = js.exec_dir + "SCORES_SEMAPHORE.tmp"; var SCORES_SEMAPHORE_FILENAME = gScriptExecDir + "SCORES_SEMAPHORE.tmp";
// Main menu actions // Main menu actions
var ACTION_PLAY = 0; var ACTION_PLAY = 0;
var ACTION_SHOW_HELP_SCREEN = 1; var ACTION_SHOW_HELP_SCREEN = 1;
...@@ -545,7 +554,7 @@ function loadSettings() ...@@ -545,7 +554,7 @@ function loadSettings()
answerFact: "G" answerFact: "G"
} }
}; };
var cfgFileName = genFullPathCfgFilename("gttrivia.ini", js.exec_dir); var cfgFileName = genFullPathCfgFilename("gttrivia.ini", gScriptExecDir);
var iniFile = new File(cfgFileName); var iniFile = new File(cfgFileName);
if (iniFile.open("r")) if (iniFile.open("r"))
{ {
...@@ -698,7 +707,7 @@ function displayProgramLogo(pClearScreenFirst, pPauseAfter) ...@@ -698,7 +707,7 @@ function displayProgramLogo(pClearScreenFirst, pPauseAfter)
if (typeof(pClearScreenFirst) === "boolean" && pClearScreenFirst) if (typeof(pClearScreenFirst) === "boolean" && pClearScreenFirst)
console.clear("\x01n"); console.clear("\x01n");
console.printfile(js.exec_dir + "gttrivia.asc", P_NONE, 80); console.printfile(gScriptExecDir + "gttrivia.asc", P_NONE, 80);
if (typeof(pPauseAfter) === "boolean" && pPauseAfter) if (typeof(pPauseAfter) === "boolean" && pPauseAfter)
console.pause(); console.pause();
...@@ -760,7 +769,7 @@ function doMainMenu() ...@@ -760,7 +769,7 @@ function doMainMenu()
function getQACategoriesAndFilenames() function getQACategoriesAndFilenames()
{ {
var sectionsAndFilenames = []; var sectionsAndFilenames = [];
var QAFilenames = directory(js.exec_dir + "qa/*.qa"); var QAFilenames = directory(gScriptExecDir + "qa/*.qa");
for (var i = 0; i < QAFilenames.length; ++i) for (var i = 0; i < QAFilenames.length; ++i)
{ {
// Get the section name - Start by removing the .qa filename extension // Get the section name - Start by removing the .qa filename extension
...@@ -1427,7 +1436,7 @@ function showScores() ...@@ -1427,7 +1436,7 @@ function showScores()
// Shows the locally saved scores (on the current BBS) // Shows the locally saved scores (on the current BBS)
function showLocalScores() function showLocalScores()
{ {
console.print("\x01n"); console.attributes = "N";
console.crlf(); console.crlf();
var sortedScores = []; var sortedScores = [];
// Read the scores file to see if the user has an existing score in there already // Read the scores file to see if the user has an existing score in there already
...@@ -1508,13 +1517,23 @@ function showServerScores() ...@@ -1508,13 +1517,23 @@ function showServerScores()
console.attributes = "N" + gSettings.colors.error; console.attributes = "N" + gSettings.colors.error;
console.print("Invalid scores data was received from the server\x01n"); console.print("Invalid scores data was received from the server\x01n");
console.crlf(); console.crlf();
if (user.is_sysop)
{
console.print("Expected an object. It's actually: " + typeof(data) + "\r\n");
//gSettings.remoteServer.server, gSettings.remoteServer.port
console.print(" Server: " + gSettings.remoteServer.server + "\r\n");
console.print(" Port: " + gSettings.remoteServer.port + "\r\n");
console.print("JSON scope: " + gSettings.remoteServer.gtTriviaScope + "\r\n");
}
return; return;
} }
if (!data.hasOwnProperty("systems")) if (!data.hasOwnProperty("systems"))
{ {
console.attributes = "N" + gSettings.colors.error; console.attributes = "N" + gSettings.colors.error;
console.print("Invalid scores data was received from the server\x01n"); console.print("Invalid scores data was received from the server (2)\x01n");
console.crlf(); console.crlf();
if (user.is_sysop)
console.print("The JSON data doesn't have a 'systems' element.\r\n");
return; return;
} }
...@@ -1860,7 +1879,7 @@ function doSysopMenu() ...@@ -1860,7 +1879,7 @@ function doSysopMenu()
console.print("\x01c1\x01y\x01h) \x01bClear high scores\x01n"); console.print("\x01c1\x01y\x01h) \x01bClear high scores\x01n");
console.print(" \x01cQ\x01y\x01h)\x01buit\x01n"); console.print(" \x01cQ\x01y\x01h)\x01buit\x01n");
// If there is an inter-BBS scores JSON file, then add some options to manage that // If there is an inter-BBS scores JSON file, then add some options to manage that
if (file_exists(js.exec_dir + "server/" + "gttrivia.json")) if (file_exists(gScriptExecDir + "server/" + "gttrivia.json"))
{ {
validKeys += "23"; validKeys += "23";
console.crlf(); console.crlf();
......
Good Time Trivia Good Time Trivia
Version 1.04 Version 1.05
Release date: 2024-03-26 Release date: 2024-03-29
by by
......
...@@ -4,7 +4,10 @@ Revision History (change log) ...@@ -4,7 +4,10 @@ Revision History (change log)
============================= =============================
Version Date Description Version Date Description
------- ---- ----------- ------- ---- -----------
1.03 2024-03-26 Formatting fix for sysop menu when the server scores file 1.05 2024-03-29 Ensure the correct script startup directory is always used
(make a copy of js.exec_dir on startup, since js.exec_dir
could change)
1.04 2024-03-26 Formatting fix for sysop menu when the server scores file
is missing. is missing.
Allow showing help when playing a game by entering ? Allow showing help when playing a game by entering ?
1.03 2023-01-14 Question sets (in the .qa files) may now have a section 1.03 2023-01-14 Question sets (in the .qa files) may now have a section
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment