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
No related branches found
No related tags found
No related merge requests found
/* **********************************
****** STAR STOCKS (2007) ******
*** for use with Synchronet v3.14 ***
*** by Matt Johnson **************
**********************************
SET TAB STOPS TO 4 FOR EDITING
*/
/*********************************
* STAR STOCKS (2007) *
* for Synchronet v3.15 *
* by Matt Johnson *
*********************************/
load("sbbsdefs.js");
load("commclient.js");
load("funclib.js");
load("graphic.js");
var root_dir=js.exec_dir;
var oldpass=console.ctrlkey_passthru;
var stream=argv[0];
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_";
bbs.sys_status|=SS_MOFF;
client.subscribe("starstocks.scores");
const root= root_dir;
const cfgname= "stars.cfg";
const high_score_file= "scores.dat";
const space= "\xFA";
var max_companies= 6;
var max_turns= 80;
const starting_cash= 10000;
const interest_rate= .05;
const ccolor= "\1w\1h"
var partial_company= "\1n+";
const interest_rate= .05;
const ccolor= "\1w\1h"
var partial_company= "\1n+";
var difficulty= 1;
var min_difficult= 20;
var max_difficult= 35;
var scores= [];
var border_row= 4;
var border_column= 1;
var menu_row= 1;
var menu_column= 63;
var scores= [];
var border_row= 4;
var border_column= 1;
var menu_row= 1;
var menu_column= 63;
var columns=
rows=
min_stars=
......@@ -45,12 +37,16 @@ var columns=
starcolor=
star=
scolor="";
loadSettings();
loadHighScores();
loadScores();
var min_normal= min_stars;
var max_normal= max_stars;
var game;
gameMenu();
client.unsubscribe("starstocks.scores");
quit();
//########################## MAIN FUNCTIONS ###################################
......@@ -109,81 +105,22 @@ function gameMenu()
case "Q":
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;
}
scores = client.read("starstocks.scores",1);
}
function storeHighScores(tempscore)
function storeScore(score)
{
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);
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
{
message("\1r\1hUnable to save scores");
return false;
}
client.lock("starstocks.scores",2);
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()
{
......@@ -263,14 +200,14 @@ function playGame()
{
pMenu.display();
displayHeader(turn);
if(!game.options.length && game.inProgress) game.generateCompanies();
if(!game.options.length && game.inProgress)
game.generateCompanies();
if(game.options.length)
{
message("\1r\1hChoose a location to start your company.");
}
var cmd=console.getkey(K_NOCRLF|K_NOSPIN|K_UPPER|K_NOECHO|K_COLD);
if(pMenu.disabled[cmd]);
else
if(!(pMenu.disabled[cmd]))
{
switch(cmd)
{
......@@ -324,8 +261,7 @@ function playGame()
{
console.home();
console.cleartoeol();
if(console.noyes("End this game?"));
else
if(!(console.noyes("End this game?")))
{
game.clearOptions();
clearRows(23);
......@@ -337,8 +273,10 @@ function playGame()
continue_game=false;
delete game;
}
if(continue_game) continue;
else break;
if(continue_game)
continue;
else
break;
default:
continue;
}
......@@ -363,30 +301,47 @@ function playGame()
displayStocks();
getMoney();
showMeTheMoney();
if(turn>max_turns) game.inProgress=false;
if(turn>max_turns)
game.inProgress=false;
}
cycle();
}
if(countCompanies(game.companies))
{
var tempscore=new Score(user.alias,game.networth,difficulty,system.datestr());
storeHighScores(tempscore);
notify();
var score=new Score(user.alias,game.networth,difficulty,system.datestr());
storeScore(score);
game.completed=true;
displaySummary();
}
}
//########################## DISPLAY FUNCTIONS #################################
function notify()
function cycle()
{
if(scores[difficulty].length<2) return false;
if(game.networth==scores[difficulty][0].score)
{
var localuser=system.matchuser(scores[difficulty][1].player,true);
if(!localuser>0 || localuser==user.number) return false;
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");
client.cycle();
}
function processUpdates(update)
{
switch(update.operation) {
case "ERROR":
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)
{
var newnum="";
......@@ -435,7 +390,7 @@ function sortScores(sort)
}
function viewHighScores()
{
loadHighScores();
loadScores();
var difficulties=["Easy", "Normal", "Difficult"];
for(df in scores)
{
......@@ -627,6 +582,7 @@ function sortCompanies()
sorted.sort();
return sorted;
}
//########################## MISC FUNCTIONS ###################################
function locked()
{
......@@ -787,8 +743,7 @@ function buyStockXpert(cmd)
}
function canBuyStocks()
{
for(cb in game.companies)
{
for(cb in game.companies) {
if(game.cash>=game.companies[cb].stock_value) return true;
}
return false;
......@@ -882,11 +837,10 @@ function processNearby(location,prox)
}
function quit()
{
if(stream) stream.close();
console.ctrlkey_passthru=oldpass;
bbs.sys_status&=~SS_MOFF;
console.clear();
var splash_filename=root_dir + "exit.bin";
var splash_filename=root + "exit.bin";
if(!file_exists(splash_filename)) exit();
var splash_size=file_size(splash_filename);
......@@ -900,7 +854,6 @@ function quit()
console.center("\1n\1c[\1hPress any key to continue\1n\1c]");
while(console.inkey(K_NOECHO|K_NOSPIN)==="");
console.clear();
return;
}
//########################## CLASSES #########################################
......
......@@ -8,12 +8,21 @@ with the latest files from the Synchronet CVS repository at:
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/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/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/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.
......@@ -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/*checkout*/exec/commservice.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/chateng.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/ctrl/filesync.ini
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/exec/json-service.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/json-sock.js
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/*checkout*/ctrl/json-service.ini
NOTE: Placing these files in their corresponding local equivalent locations
will make configuration much easier.
[COMMSERVICE.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
port of the main hub, which by default is the Broken Bubble BBS, on port 10088. If
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
[COMMCLIENT.JS]
This is the dedicated client that connects to the inter-BBS service. This file handles
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.
There is no further setup required for this to work (unless you changed the default 'Port' setting for the service
in SERVICES.INI).
[CHATENG.JS]
This handles all inbound/outbound chat messages, and packages them for delivery via the client and service.
This handles all inbound/outbound chat messages, and packages them for delivery via the irc protocol.
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
require this file to be present.
[JSON-DB.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.
[JSON-CLIENT.JS]
This file is the gateway to the program's interbbs server. It contains the methods needed to lock, unlock,
read, write and delete objects from the server database.
[JSON-SERVICE.JS]
This file acts as an interbbs server. It contains the methods needed to lock, unlock,
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
coming from the client and the service.
This file tells JSON-SERVICE.JS where a program's files are located.
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.
......@@ -88,9 +74,8 @@ this program in inter-BBS mode, and can be downloaded from the Synchronet CVS re
[SERVER.INI]
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
your program to function either as local-only, or as a server itself, depending on your setup
within the gaming service.
the host and port the program will be connecting to. Deleting this file will cause
your program not to function.
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
port=10088
autoupdate=true
\ No newline at end of file
/*
BUBBLE BOGGLE
for Synchronet v3.15+ (javascript)
by Matt Johnson (2009)
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");
/*********************************
* STAR STOCKS (2007) *
* for Synchronet v3.15 *
* by Matt Johnson *
*********************************/
load("json-client.js");
var root = js.exec_dir;
var stream = false;
var server_file=new File(root + "server.ini");
if(file_exists(server_file.name)) {
stream=new ServiceConnection("starstocks");
if(!file_exists(root + "server.ini")) {
throw("server initialization file missing");
}
var server_file = new File(root + "server.ini");
server_file.open('r',true);
//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.open('r',true);
var update=server_file.iniGetValue("autoupdate");
server_file.close();
if(update != true) {
if((user.compare_ars("SYSOP") || (bbs.sys_status&SS_TMPSYSOP))
&& console.yesno("Check for game updates?"))
update=true;
}
if(update) {
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);
var client=new JSONClient(serverAddr,serverPort);
/*
if(autoUpdate) {
console.putmsg("\r\n\1nChecking for updates...");
}
*/
load(root + "game.js",stream);
\ No newline at end of file
load(root + "game.js");
\ No newline at end of file
......@@ -43,19 +43,28 @@ NOTE: This program REQUIRES the associated service to be configured in order
*****UPDATING YOUR LOCAL LIBRARIES******
Before you attempt to install the inter-BBS service, it is recommended that you
update your relative 'EXEC/' and 'EXEC/LOAD/' paths
It is recommended that you update your relative 'EXEC/' and 'EXEC/LOAD/' paths
with the latest files from the Synchronet CVS repository at:
http://cvs.synchro.net/cgi-bin/viewcvs.cgi/
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/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/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/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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment