Commit ba07b9b9 authored by mcmlxxix's avatar mcmlxxix
Browse files

updated per json-client.js packet changes

parent 5831830b
if(!js.global.JSONClient)
if(!js.global.JSONClient)
load(js.global,"json-client.js");
function JSONChat(jsonclient) {
this.nick = new Nick(user.handle,system.name,user.ip_address);
function JSONChat(jsonclient,host,port,usernum) {
this.nick;
this.channels = {};
this.client = jsonclient;
if(!this.client)
this.client = new JSONClient();
if(!this.client) {
if(!host || isNaN(port))
throw("invalid client arguments");
this.client = new JSONClient(host,port);
}
this.connect = function() {
this.client.subscribe("chat.channels." + this.nick.name + ".messages");
var usr;
if(usernum > 0 && system.username(usernum))
usr = new User(usernum);
if(usr)
this.nick = new Nick(usr.handle,system.name,usr.ip_address);
else if(user && user.number > 0)
this.nick = new Nick(user.handle,system.name,user.ip_address);
if(this.nick)
this.client.subscribe("chat","channels." + this.nick.name + ".messages");
else
throw("invalid user number");
}
this.submit = function(target,str) {
var message = new Message(this.nick,str,Date.now());
this.client.write("chat.channels." + target + ".messages",message,2);
this.client.push("chat.channels." + target + ".history",message,2);
this.channels[target.toUpperCase()].messages.push(message);
var chan = this.channels[target.toUpperCase()];
this.client.write("chat","channels." + chan.name + ".messages",message,2);
this.client.push("chat","channels." + chan.name + ".history",message,2);
chan.messages.push(message);
}
this.clear = function(target) {
this.client.write("chat.channels." + target + ".history",[],2);
this.channels[target.toUpperCase()].messages = [];
var chan = this.channels[target.toUpperCase()];
this.client.write("chat","channels." + chan.name + ".history",[],2);
chan.messages = [];
}
this.join = function(target,str) {
this.client.subscribe("chat.channels." + target + ".messages");
this.client.subscribe("chat","channels." + target + ".messages");
this.channels[target.toUpperCase()] = new Channel(target);
var history = this.client.read("chat.channels." + target + ".history",1);
var history = this.client.read("chat","channels." + target + ".history",1);
var msgcount = 0;
for each(var m in history) {
this.channels[target.toUpperCase()].messages.push(m);
......@@ -36,21 +52,26 @@ function JSONChat(jsonclient) {
}
if(msgcount == 0)
this.clear(target);
this.channels[target.toUpperCase()].users = this.client.who("chat.channels." + target + ".messages");
this.channels[target.toUpperCase()].users = this.client.who("chat","channels." + target + ".messages");
}
this.part = function(target) {
this.client.unsubscribe("chat.channels." + target + ".messages");
var chan = this.channels[target.toUpperCase()];
this.client.unsubscribe("chat","channels." + chan.name + ".messages");
delete this.channels[target.toUpperCase()];
}
this.who = function(target,str) {
this.channels[target.toUpperCase()].users = this.client.who("chat.channels." + target + ".messages");
return this.channels[target.toUpperCase()].users;
var chan = this.channels[target.toUpperCase()];
chan.users = this.client.who("chat","channels." + chan.name + ".messages");
return chan.users;
}
this.disconnect = function() {
this.client.unsubscribe("chat." + this.nick.name + ".messages");
this.client.unsubscribe("chat","channels." + this.nick.name + ".messages");
for each(var c in this.channels)
this.client.unsubscribe("chat","channels." + c.name + ".messages");
this.channels = {};
}
/* pass any client update packets to this function to process inbound messages/status updates */
......@@ -90,6 +111,10 @@ function JSONChat(jsonclient) {
if(!cmdstr)
return false;
/* if the command has been passed with a leading '/' */
if(cmdstr[0] == "/")
cmdstr = cmdstr.substr(1);
cmdstr = cmdstr.split(" ");
switch(cmdstr[0].toUpperCase()) {
case "JOIN":
......@@ -155,4 +180,6 @@ function JSONChat(jsonclient) {
this.str = str;
this.time = time;
}
this.connect();
}
......@@ -11,6 +11,7 @@
*/
var oldpass=console.ctrl_key_passthru;
var game_id = "boggle";
load("graphic.js");
load("sbbsdefs.js");
......@@ -19,8 +20,8 @@ load("funclib.js");
load("calendar.js");
load(root + "timer.js");
client.subscribe(game_id,"players");
splashStart();
client.subscribe("boggle.players");
var wordvalues=[];
wordvalues[4]=1;
......@@ -46,7 +47,7 @@ var data = new GameData();
function boggle() {
function init()
{
client.write("boggle.players." + user.alias + ".laston",time(),2);
client.write(game_id,"players." + user.alias + ".laston",time(),2);
player=findUser(user.alias);
current=calendar.selected;
today=calendar.selected;
......@@ -120,7 +121,7 @@ function boggle() {
}
var k=console.inkey(K_NOCRLF|K_NOSPIN|K_NOECHO,5);
if(k){
switch(k.toUpperCase()) {
switch(k.toUpperCase()) {
case KEY_UP:
case KEY_DOWN:
case KEY_LEFT:
......@@ -505,7 +506,7 @@ function processUpdates(update) {
data.updated=true;
}
function splashStart() {
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_";
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ";
bbs.sys_status|=SS_MOFF;
bbs.sys_status |= SS_PAUSEOFF;
console.clear();
......@@ -540,21 +541,21 @@ client.callback=processUpdates;
function GameData() {
this.updated=false;
this.players=[];
this.boards=[];
this.winner=undefined;
this.players={};
this.boards={};
this.winner={};
this.month=date.getMonth();
this.init=function() {
client.lock("boggle.month",2);
var month = client.read("boggle.month");
client.lock(game_id,"month",2);
var month = client.read(game_id,"month");
if(month != this.month)
this.newMonth();
else
this.loadMonth();
client.unlock("boggle.month");
client.unlock(game_id,"month");
this.players = client.read("boggle.players",1);
this.players = client.read(game_id,"players",1);
if(!this.players[user.alias]) {
this.players[user.alias] = new Player();
this.storePlayer();
......@@ -563,16 +564,16 @@ function GameData() {
/* load this month's boggle boards */
this.loadMonth=function() {
console.putmsg("\rPlease wait. Loading puzzles for this month...\r\n");
this.winner=client.read("boggle.winner",1);
this.boards=client.read("boggle.boards",1);
this.winner=client.read(game_id,"winner",1);
this.boards=client.read(game_id,"boards",1);
}
/* save current player data to database */
this.storePlayer = function() {
client.write("boggle.players." + user.alias,this.players[user.alias],2);
client.write(game_id,"players." + user.alias,this.players[user.alias],2);
}
/* save this round's winner to the database */
this.storeRoundWinner=function() {
this.players = client.read("boggle.players",1);
this.players = client.read(game_id,"players",1);
for(p in this.players) {
if(!this.winner)
this.winner=this.players[p];
......@@ -581,26 +582,27 @@ function GameData() {
this.winner=this.players[p];
}
}
client.write("boggle.winner",this.winner,2);
client.write(game_id,"winner",this.winner,2);
}
/* generate a new month's list of boggle boards */
this.newMonth=function() {
this.storeRoundWinner();
client.write("boggle.month",this.month);
client.write("boggle.players",{},2);
client.write(game_id,"month",this.month);
client.write(game_id,"players",{},2);
console.putmsg("\rPlease wait. Creating puzzles for new month...\r\n");
client.lock("boggle.boards",2);
client.lock(game_id,"boards",2);
client.write(game_id,"boards",{});
this.boards=[];
var numdays=date.daysInMonth();
for(var dn=1;dn<=numdays;dn++) {
var board=this.newBoard();
this.boards[dn]=board;
client.write("boggle.boards." + dn,board);
client.write(game_id,"boards." + dn,board);
}
client.unlock("boggle.boards");
client.unlock(game_id,"boards");
}
/* generate a new boggle board */
this.newBoard=function() {
......@@ -905,7 +907,7 @@ function Score() {
}
boggle();
client.unsubscribe("boggle.players");
client.unsubscribe(game_id,"players");
splashExit();
......
/*********************************
* STAR STOCKS (2007) *
* for Synchronet v3.15 *
* by Matt Johnson *
*********************************/
* STAR STOCKS (2007) *
* for Synchronet v3.15 *
* by Matt Johnson *
*********************************/
load("sbbsdefs.js");
load("funclib.js");
load("graphic.js");
var oldpass=console.ctrlkey_passthru;
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_";
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ";
bbs.sys_status|=SS_MOFF;
client.subscribe("starstocks.scores");
client.subscribe("starstocks","scores");
const cfgname= "stars.cfg";
const space= "\xFA";
......@@ -46,7 +46,7 @@ var max_normal= max_stars;
var game;
gameMenu();
client.unsubscribe("starstocks.scores");
client.unsubscribe("starstocks","scores");
quit();
//########################## MAIN FUNCTIONS ###################################
......@@ -110,17 +110,17 @@ function gameMenu()
}
function loadScores()
{
scores = client.read("starstocks.scores",1);
scores = client.read("starstocks","scores",1);
}
function storeScore(score)
{
client.lock("starstocks.scores",2);
scores=client.read("starstocks.scores");
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");
client.write("starstocks","scores." + score.difficulty,scores[score.difficulty]);
client.unlock("starstocks","scores");
}
function loadSettings()
{
......
......@@ -12,8 +12,8 @@ load("sbbsdefs.js")
load("funclib.js");
splashStart();
client.subscribe("uberblox.players");
client.subscribe("uberblox.alltime");
client.subscribe("uberblox","players");
client.subscribe("uberblox","alltime");
var oldpass = console.ctrl_key_passthru;
var data = new GameData();
......@@ -54,7 +54,7 @@ function gotoxy(x,y)
}
function splashStart()
{
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ_";
console.ctrlkey_passthru="+ACGKLOPQRTUVWXYZ";
bbs.sys_status|=SS_MOFF;
bbs.sys_status|=SS_PAUSEOFF;
console.clear();
......@@ -84,8 +84,8 @@ function blox()
{
const columns=20;
const rows=11;
const bg=[BG_GREEN,BG_BLUE,BG_RED,BG_CYAN,BG_BROWN,BG_MAGENTA];
const fg=[LIGHTGREEN,LIGHTBLUE,LIGHTRED,LIGHTCYAN,YELLOW,LIGHTMAGENTA];
const bg=[BG_GREEN,BG_BLUE,BG_RED,BG_BROWN,BG_MAGENTA,LIGHTGRAY];
const fg=[LIGHTGREEN,LIGHTBLUE,LIGHTRED,YELLOW,LIGHTMAGENTA,WHITE];
var level;
var points;
......@@ -96,7 +96,7 @@ function blox()
const points_increment= 10;
const minimum_cluster= 3;
const colors= [3,3,3,4,4,4,5,5,5,6,6,6]; //COLORS PER MAP (DEFAULT ex.: levels 1-4 have 3 colors)
const tiles_per_color= [8,7,6,8,7,6,9,8,7,10,9,8]; //TARGET FOR LEVEL COMPLETION (DEFAULT ex. level 1 target: 220 total tiles minus 8 tiles per color times 3 colors = 196)
const tiles_per_color= [8,7,6,10,9,8,11,10,9,12,11,10]; //TARGET FOR LEVEL COMPLETION (DEFAULT ex. level 1 target: 220 total tiles minus 8 tiles per color times 3 colors = 196)
var lobby;
var logo;
......@@ -216,7 +216,7 @@ function blox()
}
function init()
{
client.write("uberblox.players." + user.alias + ".laston",time(),2);
client.write("uberblox","players." + user.alias + ".laston",time(),2);
logo=new Graphic(18,22);
logo.load(root + "blox.bin");
lobby=new Graphic(80,23);
......@@ -559,25 +559,25 @@ function GameData()
this.init=function()
{
client.lock("uberblox.month",2);
var month = client.read("uberblox.month");
client.lock("uberblox","month",2);
var month = client.read("uberblox","month");
if(month != this.month)
this.reset();
client.unlock("uberblox.month");
client.unlock("uberblox","month");
this.alltime = client.read("uberblox.alltime",1);
this.alltime = client.read("uberblox","alltime",1);
if(!this.alltime.name) {
this.alltime={
name:"no one",
score:0
}
client.write("uberblox.alltime",this.alltime,2);
client.write("uberblox","alltime",this.alltime,2);
}
this.players = client.read("uberblox.players",1);
this.players = client.read("uberblox","players",1);
if(!this.players[user.alias]) {
this.players[user.alias] = new Player();
client.write("uberblox.players." + user.alias,this.players[user.alias],2);
client.write("uberblox","players." + user.alias,this.players[user.alias],2);
}
}
this.formatDate=function(timet)
......@@ -595,23 +595,23 @@ function GameData()
}
this.reset=function()
{
client.write("uberblox.month",this.month);
client.write("uberblox.players",{},2);
client.write("uberblox","month",this.month);
client.write("uberblox","players",{},2);
}
this.storePlayer=function()
{
client.write("uberblox.players." + user.alias,this.players[user.alias],2);
client.write("uberblox","players." + user.alias,this.players[user.alias],2);
client.lock("uberblox.alltime",2);
client.lock("uberblox","alltime",2);
if(this.players[user.alias].score > this.alltime.score) {
this.alltime=client.read("uberblox.alltime");
this.alltime=client.read("uberblox","alltime");
if(this.players[user.alias].score > this.alltime.score) {
this.alltime.score = this.players[user.alias].score;
this.alltime.name = user.alias;
client.write("uberblox.alltime",this.alltime);
client.write("uberblox","alltime",this.alltime);
}
}
client.unlock("uberblox.alltime");
client.unlock("uberblox","alltime");
}
this.findUser=function(alias)
{
......@@ -652,6 +652,6 @@ function Tile(bg,fg)
}
blox();
client.unsubscribe("uberblox.players");
client.unsubscribe("uberblox.alltime");
client.unsubscribe("uberblox","players");
client.unsubscribe("uberblox","alltime");
splashExit();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment