Skip to content
Snippets Groups Projects
Commit 66ce3766 authored by mcmlxxix's avatar mcmlxxix
Browse files

Update to use new service.

NOTE: It is no longer necessary to run commservice.js in services.ini to use the interbbs features of this game. See /exec/json-service.js if you wish to host your own server
parent c51da0e8
Branches
Tags
No related merge requests found
/* ********************************** /*********************************
****** STAR STOCKS (2007) ****** * STAR STOCKS (2007) *
*** for use with Synchronet v3.14 *** * for Synchronet v3.15 *
*** by Matt Johnson ************** * by Matt Johnson *
********************************** *********************************/
SET TAB STOPS TO 4 FOR EDITING
*/
load("sbbsdefs.js"); load("sbbsdefs.js");
load("commclient.js");
load("funclib.js"); load("funclib.js");
load("graphic.js"); load("graphic.js");
var root_dir=js.exec_dir;
var oldpass=console.ctrlkey_passthru; var oldpass=console.ctrlkey_passthru;
var stream=argv[0];
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_"; console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_";
bbs.sys_status|=SS_MOFF; bbs.sys_status|=SS_MOFF;
client.subscribe("starstocks.scores");
const root= root_dir;
const cfgname= "stars.cfg"; const cfgname= "stars.cfg";
const high_score_file= "scores.dat";
const space= "\xFA"; const space= "\xFA";
var max_companies= 6; var max_companies= 6;
var max_turns= 80; var max_turns= 80;
...@@ -45,12 +37,16 @@ var columns= ...@@ -45,12 +37,16 @@ var columns=
starcolor= starcolor=
star= star=
scolor=""; scolor="";
loadSettings(); loadSettings();
loadHighScores(); loadScores();
var min_normal= min_stars; var min_normal= min_stars;
var max_normal= max_stars; var max_normal= max_stars;
var game; var game;
gameMenu(); gameMenu();
client.unsubscribe("starstocks.scores");
quit(); quit();
//########################## MAIN FUNCTIONS ################################### //########################## MAIN FUNCTIONS ###################################
...@@ -109,81 +105,22 @@ function gameMenu() ...@@ -109,81 +105,22 @@ function gameMenu()
case "Q": case "Q":
return; return;
} }
cycle();
} }
} }
function loadHighScores() function loadScores()
{
for(diff=0;diff<3;diff++) scores[diff]=[];
var sfile=new File(root + high_score_file);
if(!file_exists(sfile.name)) return false;
sfile.open('r', true);
var count=0;
var timeout=200;
while(!sfile.is_open && count<timeout)
{
mswait(5);
count++;
sfile.open('r', true);
}
if(sfile.is_open)
{
for(sc=0;!(sfile.eof);sc++)
{
player=sfile.readln();
if(player==undefined || player=="") break;
score=parseFloat(sfile.readln());
diff=parseInt(sfile.readln());
date=sfile.readln();
scores[diff].push(new Score(player,score,diff,date));
}
sfile.close();
return true;
}
else
{
log("\1r\1hUnable to load scores");
return false;
}
}
function storeHighScores(tempscore)
{
loadHighScores();
scores[tempscore.difficulty].push(tempscore);
var sfile=new File(root + high_score_file);
var count=0;
var timeout=200;
while(locked() && count<timeout)
{
mswait(5);
count++;
}
if(!locked())
{
lock();
sfile.open('w+', false);
for(d in scores)
{
scores[d]=sortScores(scores[d]);
for(score in scores[d])
{ {
sfile.writeln(scores[d][score].player); scores = client.read("starstocks.scores",1);
sfile.writeln(scores[d][score].score);
sfile.writeln(scores[d][score].difficulty);
sfile.writeln(scores[d][score].date);
if(score==9) break;
}
}
sfile.close();
if(stream) sendFiles(high_score_file);
unlock();
return true;
} }
else function storeScore(score)
{ {
message("\1r\1hUnable to save scores"); client.lock("starstocks.scores",2);
return false; scores=client.read("starstocks.scores");
} if(!scores[score.difficulty])
scores[score.difficulty] = [];
scores[score.difficulty].push(score);
client.write("starstocks.scores." + score.difficulty,scores[score.difficulty]);
client.unlock("starstocks.scores");
} }
function loadSettings() function loadSettings()
{ {
...@@ -263,14 +200,14 @@ function playGame() ...@@ -263,14 +200,14 @@ function playGame()
{ {
pMenu.display(); pMenu.display();
displayHeader(turn); displayHeader(turn);
if(!game.options.length && game.inProgress) game.generateCompanies(); if(!game.options.length && game.inProgress)
game.generateCompanies();
if(game.options.length) if(game.options.length)
{ {
message("\1r\1hChoose a location to start your company."); message("\1r\1hChoose a location to start your company.");
} }
var cmd=console.getkey(K_NOCRLF|K_NOSPIN|K_UPPER|K_NOECHO|K_COLD); var cmd=console.getkey(K_NOCRLF|K_NOSPIN|K_UPPER|K_NOECHO|K_COLD);
if(pMenu.disabled[cmd]); if(!(pMenu.disabled[cmd]))
else
{ {
switch(cmd) switch(cmd)
{ {
...@@ -324,8 +261,7 @@ function playGame() ...@@ -324,8 +261,7 @@ function playGame()
{ {
console.home(); console.home();
console.cleartoeol(); console.cleartoeol();
if(console.noyes("End this game?")); if(!(console.noyes("End this game?")))
else
{ {
game.clearOptions(); game.clearOptions();
clearRows(23); clearRows(23);
...@@ -337,8 +273,10 @@ function playGame() ...@@ -337,8 +273,10 @@ function playGame()
continue_game=false; continue_game=false;
delete game; delete game;
} }
if(continue_game) continue; if(continue_game)
else break; continue;
else
break;
default: default:
continue; continue;
} }
...@@ -363,30 +301,47 @@ function playGame() ...@@ -363,30 +301,47 @@ function playGame()
displayStocks(); displayStocks();
getMoney(); getMoney();
showMeTheMoney(); showMeTheMoney();
if(turn>max_turns) game.inProgress=false; if(turn>max_turns)
game.inProgress=false;
} }
cycle();
} }
if(countCompanies(game.companies)) if(countCompanies(game.companies))
{ {
var tempscore=new Score(user.alias,game.networth,difficulty,system.datestr()); var score=new Score(user.alias,game.networth,difficulty,system.datestr());
storeHighScores(tempscore); storeScore(score);
notify();
game.completed=true; game.completed=true;
displaySummary(); displaySummary();
} }
} }
function cycle()
//########################## DISPLAY FUNCTIONS #################################
function notify()
{ {
if(scores[difficulty].length<2) return false; client.cycle();
if(game.networth==scores[difficulty][0].score) }
function processUpdates(update)
{ {
var localuser=system.matchuser(scores[difficulty][1].player,true); switch(update.operation) {
if(!localuser>0 || localuser==user.number) return false; case "ERROR":
system.put_telegram(scores[difficulty][1].player, "\1r\1h" + scores[difficulty][0].player + " \1c\1hbeat your High Score in Star Stocks!\r\n\r\n"); throw(update.error_desc);
break;
case "UPDATE":
var p=update.location.split(".");
/* if we received something for a different game? */
if(p.shift().toUpperCase() != "STARSTOCKS")
return;
var obj=scores;
p.shift();
while(p.length > 1) {
var child=p.shift();
obj=obj[child];
}
obj[p.shift()] = update.data;
break;
} }
} }
client.callback=processUpdates;
//########################## DISPLAY FUNCTIONS #################################
function shortNumber(number) function shortNumber(number)
{ {
var newnum=""; var newnum="";
...@@ -435,7 +390,7 @@ function sortScores(sort) ...@@ -435,7 +390,7 @@ function sortScores(sort)
} }
function viewHighScores() function viewHighScores()
{ {
loadHighScores(); loadScores();
var difficulties=["Easy", "Normal", "Difficult"]; var difficulties=["Easy", "Normal", "Difficult"];
for(df in scores) for(df in scores)
{ {
...@@ -627,6 +582,7 @@ function sortCompanies() ...@@ -627,6 +582,7 @@ function sortCompanies()
sorted.sort(); sorted.sort();
return sorted; return sorted;
} }
//########################## MISC FUNCTIONS ################################### //########################## MISC FUNCTIONS ###################################
function locked() function locked()
{ {
...@@ -787,8 +743,7 @@ function buyStockXpert(cmd) ...@@ -787,8 +743,7 @@ function buyStockXpert(cmd)
} }
function canBuyStocks() function canBuyStocks()
{ {
for(cb in game.companies) for(cb in game.companies) {
{
if(game.cash>=game.companies[cb].stock_value) return true; if(game.cash>=game.companies[cb].stock_value) return true;
} }
return false; return false;
...@@ -882,11 +837,10 @@ function processNearby(location,prox) ...@@ -882,11 +837,10 @@ function processNearby(location,prox)
} }
function quit() function quit()
{ {
if(stream) stream.close();
console.ctrlkey_passthru=oldpass; console.ctrlkey_passthru=oldpass;
bbs.sys_status&=~SS_MOFF; bbs.sys_status&=~SS_MOFF;
console.clear(); console.clear();
var splash_filename=root_dir + "exit.bin"; var splash_filename=root + "exit.bin";
if(!file_exists(splash_filename)) exit(); if(!file_exists(splash_filename)) exit();
var splash_size=file_size(splash_filename); var splash_size=file_size(splash_filename);
...@@ -900,7 +854,6 @@ function quit() ...@@ -900,7 +854,6 @@ function quit()
console.center("\1n\1c[\1hPress any key to continue\1n\1c]"); console.center("\1n\1c[\1hPress any key to continue\1n\1c]");
while(console.inkey(K_NOECHO|K_NOSPIN)===""); while(console.inkey(K_NOECHO|K_NOSPIN)==="");
console.clear(); console.clear();
return;
} }
//########################## CLASSES ######################################### //########################## CLASSES #########################################
......
...@@ -8,12 +8,21 @@ with the latest files from the Synchronet CVS repository at: ...@@ -8,12 +8,21 @@ with the latest files from the Synchronet CVS repository at:
RECOMMENDED UPDATES: RECOMMENDED UPDATES:
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/irc_protocol.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/socket_bg.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/layout.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/inputline.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/funclib.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/funclib.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/calendar.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/calendar.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/event-timer.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/timer.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/timer.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/clock.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/clock.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/msgwndw.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/msgwndw.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/scrollbar.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/scrollbar.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/cvs.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/json-sock.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/json-client.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/chateng.js
NOTE: Replace any outdated local copies with the latest release from the links. NOTE: Replace any outdated local copies with the latest release from the links.
...@@ -25,62 +34,39 @@ this program in inter-BBS mode, and can be downloaded from the Synchronet CVS re ...@@ -25,62 +34,39 @@ this program in inter-BBS mode, and can be downloaded from the Synchronet CVS re
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/ http://cvs.synchro.net/cgi-bin/viewcvs.cgi/
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/commservice.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/json-service.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/commclient.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/json-db.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/chateng.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/json-sock.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/ctrl/filesync.ini http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/ctrl/json-service.ini
NOTE: Placing these files in their corresponding local equivalent locations NOTE: Placing these files in their corresponding local equivalent locations
will make configuration much easier. will make configuration much easier.
[COMMSERVICE.JS] [CHATENG.JS]
This is a static service that must be included in /ctrl/services.ini in order to
accept connections and relay information to and from the main hub. It is critical
for this to be set up properly, for the programs that depend on it will not function
properly without it.
This file must be placed in your relative 'EXEC/' or 'MODS/' path (typically '/SBBS/EXEC/').
Once the file is in place, you must add the following to your 'CTRL/SERVICES.INI' file:
[Commserv]
Port=10088
Options=STATIC
Command=commservice.js bbs.thebrokenbubble.com 10088
NOTE: there are two arguments on the command line that tell the service the address and This handles all inbound/outbound chat messages, and packages them for delivery via the irc protocol.
port of the main hub, which by default is the Broken Bubble BBS, on port 10088. If this also contains the necessary objects to implement a chat room (windowed or fullscreen).
you wish to act as your own hub (e.g. start your own league), simple remove both
arguments from the command line, and direct league nodes to add your URL and port
to their SERVICES.INI file. If your system operates on multiple machines and you wish
to share data between local nodes ONLY, setting up this service as a hub makes
this possible as well.
NOTE: You should also double check to make sure that your services are running [JSON-DB.JS]
[COMMCLIENT.JS] This file acts as a JSON object database, which is used by JSON-SERVICE, but can be used
on the client side as well.
This is the dedicated client that connects to the inter-BBS service. This file handles [JSON-CLIENT.JS]
the transmission of data to and from the service, as well as managing file synchronization
for the client (this program). This file is critical for the successful operation of this program
in inter-BBS mode.
The file must be placed in your relative 'EXEC/LOAD/' path. This file is the gateway to the program's interbbs server. It contains the methods needed to lock, unlock,
There is no further setup required for this to work (unless you changed the default 'Port' setting for the service read, write and delete objects from the server database.
in SERVICES.INI).
[CHATENG.JS] [JSON-SERVICE.JS]
This handles all inbound/outbound chat messages, and packages them for delivery via the client and service.
this also contains the necessary objects to implement a chat room (windowed or fullscreen).
NOTE: while this particular program may not have chat features, the service itself still may This file acts as an interbbs server. It contains the methods needed to lock, unlock,
require this file to be present. read, write and delete objects from the server database, and also accepts JSON-CLIENT connections
and acts as the main source for all dynamic program data. The file contains instructions for
setting up a server.
[FILESYNC.INI] [JSON-SERVICE.INI]
This file tells FILESYNC.JS and COMMCLIENT.JS where to store/retrieve inbound/outbound transfers This file tells JSON-SERVICE.JS where a program's files are located.
coming from the client and the service.
This file is critical for the service to operate properly. If you have installed the programs that This file is critical for the service to operate properly. If you have installed the programs that
use this service to their default locations, no additional configuration should be required. use this service to their default locations, no additional configuration should be required.
...@@ -88,9 +74,8 @@ this program in inter-BBS mode, and can be downloaded from the Synchronet CVS re ...@@ -88,9 +74,8 @@ this program in inter-BBS mode, and can be downloaded from the Synchronet CVS re
[SERVER.INI] [SERVER.INI]
This file should be located in the program's working directory, as it contains information for This file should be located in the program's working directory, as it contains information for
the host, port, and any "auth" the program's server might require. Deleting this file will cause the host and port the program will be connecting to. Deleting this file will cause
your program to function either as local-only, or as a server itself, depending on your setup your program not to function.
within the gaming service.
Please report any bugs, issues or questions to: mcmlxxix at bbs dot thebrokenbubble dot com Please report any bugs, issues or questions to: mcmlxxix at bbs dot thebrokenbubble dot com
......
;if you want to offer this game as local-only,
;or if you want your system to be a league hub, delete this file
host=bbs.thebrokenbubble.com host=bbs.thebrokenbubble.com
port=10088 port=10088
autoupdate=true autoupdate=true
\ No newline at end of file
/* /*********************************
BUBBLE BOGGLE * STAR STOCKS (2007) *
for Synchronet v3.15+ (javascript) * for Synchronet v3.15 *
by Matt Johnson (2009) * by Matt Johnson *
*********************************/
Game uses standard "Big Boggle" rules, scoring, and dice
Dictionary files created from ENABLe gaming dictionary
for customization or installation help contact:
Matt Johnson ( MCMLXXIX@BBS.THEBROKENBUBBLE.COM )
*/
load("commclient.js");
load("json-client.js");
var root = js.exec_dir; var root = js.exec_dir;
var stream = false;
var server_file=new File(root + "server.ini"); if(!file_exists(root + "server.ini")) {
if(file_exists(server_file.name)) { throw("server initialization file missing");
stream=new ServiceConnection("starstocks"); }
var server_file = new File(root + "server.ini");
server_file.open('r',true); server_file.open('r',true);
var update=server_file.iniGetValue("autoupdate"); //var autoUpdate=server_file.iniGetValue(null,"autoUpdate");
var serverAddr=server_file.iniGetValue(null,"serverAddr");
var serverPort=server_file.iniGetValue(null,"serverPort");
server_file.close(); server_file.close();
if(update != true) { var client=new JSONClient(serverAddr,serverPort);
if((user.compare_ars("SYSOP") || (bbs.sys_status&SS_TMPSYSOP))
&& console.yesno("Check for game updates?"))
update=true;
}
if(update) { /*
if(autoUpdate) {
console.putmsg("\r\n\1nChecking for updates..."); console.putmsg("\r\n\1nChecking for updates...");
stream.recvfile("*.bin");
stream.recvfile("*.js");
stream.recvfile("starstocks.ans");
stream.recvfile("interbbs.doc");
stream.recvfile("stars.doc");
stream.recvfile("sysop.doc",true);
}
console.putmsg("\r\n\1nSynchronizing data files...");
stream.recvfile("stars.cfg");
stream.recvfile("scores.dat",true);
} }
*/
load(root + "game.js",stream); load(root + "game.js");
\ No newline at end of file \ No newline at end of file
...@@ -43,19 +43,28 @@ NOTE: This program REQUIRES the associated service to be configured in order ...@@ -43,19 +43,28 @@ NOTE: This program REQUIRES the associated service to be configured in order
*****UPDATING YOUR LOCAL LIBRARIES****** *****UPDATING YOUR LOCAL LIBRARIES******
Before you attempt to install the inter-BBS service, it is recommended that you It is recommended that you update your relative 'EXEC/' and 'EXEC/LOAD/' paths
update your relative 'EXEC/' and 'EXEC/LOAD/' paths
with the latest files from the Synchronet CVS repository at: with the latest files from the Synchronet CVS repository at:
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/ http://cvs.synchro.net/cgi-bin/viewcvs.cgi/
RECOMMENDED UPDATES: RECOMMENDED UPDATES:
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/irc_protocol.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/socket_bg.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/layout.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/inputline.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/funclib.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/funclib.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/calendar.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/calendar.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/event-timer.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/timer.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/clock.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/clock.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/msgwndw.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/msgwndw.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/scrollbar.js http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/scrollbar.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/cvs.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/json-sock.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/json-client.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/load/chateng.js
NOTE: Replace any outdated local copies with the latest releases from these links. NOTE: Replace any outdated local copies with the latest releases from these links.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment