Skip to content
Snippets Groups Projects
Commit 82f15ae4 authored by echicken's avatar echicken
Browse files

Take ANSIEdit's cursor into account when updating the display.

Looks like I had some other local changes stashed ... I dunno, formatting.
parent 42e614b3
No related branches found
No related tags found
No related merge requests found
...@@ -12,10 +12,9 @@ var attr, systemStatus, users, systems, months, ...@@ -12,10 +12,9 @@ var attr, systemStatus, users, systems, months,
editor, jsonClient, timer, timedEvent, editor, jsonClient, timer, timedEvent,
lastUser = -1, lastSystem = -1; lastUser = -1, lastSystem = -1;
var updateStatus = function(u, s, altUsers, altSystems) { function updateStatus(u, s, altUsers, altSystems) {
if(u == lastUser && s == lastSystem) if (u == lastUser && s == lastSystem) return;
return;
// Derp, how does I scope? Too late, too much drinkings yesno? // Derp, how does I scope? Too late, too much drinkings yesno?
var usrs = (typeof altUsers == "undefined") ? users : altUsers; var usrs = (typeof altUsers == "undefined") ? users : altUsers;
...@@ -28,12 +27,9 @@ var updateStatus = function(u, s, altUsers, altSystems) { ...@@ -28,12 +27,9 @@ var updateStatus = function(u, s, altUsers, altSystems) {
lastUser = u; lastUser = u;
lastSystem = s; lastSystem = s;
editor.cycle(true); editor.cycle(true);
if(typeof timedEvent != "undefined") if (typeof timedEvent != "undefined") timedEvent.abort = true;
timedEvent.abort = true;
timedEvent = timer.addEvent( timedEvent = timer.addEvent(
5000, 5000, false, function () {
false,
function() {
statusFrame.clear(); statusFrame.clear();
lastUser = -1; lastUser = -1;
lastSystem = -1; lastSystem = -1;
...@@ -43,12 +39,12 @@ var updateStatus = function(u, s, altUsers, altSystems) { ...@@ -43,12 +39,12 @@ var updateStatus = function(u, s, altUsers, altSystems) {
} }
var fetchHistory = function(month) { function fetchHistory(month) {
try { try {
var historyDir = js.exec_dir + "history"; var historyDir = js.exec_dir + "history";
if(!file_exists(historyDir) || !file_isdir(historyDir)) if (!file_exists(historyDir) || !file_isdir(historyDir)) {
mkdir(historyDir); mkdir(historyDir);
}
var fn = month.split("/"); var fn = month.split("/");
fn = historyDir + "/" + fn[fn.length - 1]; fn = historyDir + "/" + fn[fn.length - 1];
if (!file_exists(fn)) { if (!file_exists(fn)) {
...@@ -63,10 +59,9 @@ var fetchHistory = function(month) { ...@@ -63,10 +59,9 @@ var fetchHistory = function(month) {
} catch (err) { } catch (err) {
log(LOG_ERR, "SyncWall error: " + err); log(LOG_ERR, "SyncWall error: " + err);
} }
} }
var loadLocalHistory = function(fn) { function loadLocalHistory(fn) {
var f = new File(fn); var f = new File(fn);
f.open("r"); f.open("r");
var history = JSON.parse(f.read()); var history = JSON.parse(f.read());
...@@ -100,12 +95,9 @@ var loadLocalHistory = function(fn) { ...@@ -100,12 +95,9 @@ var loadLocalHistory = function(fn) {
loadState(history.STATE); loadState(history.STATE);
break; break;
} }
if (h < history.SEQUENCE.length - 1) mswait(delay);
if(h < history.SEQUENCE.length - 1)
mswait(delay);
} }
} }
promptFrame.bottom(); promptFrame.bottom();
statusFrame.clear(); statusFrame.clear();
statusFrame.putmsg("Hit any key to continue"); statusFrame.putmsg("Hit any key to continue");
...@@ -114,22 +106,15 @@ var loadLocalHistory = function(fn) { ...@@ -114,22 +106,15 @@ var loadLocalHistory = function(fn) {
console.getkey(); console.getkey();
statusFrame.clear(); statusFrame.clear();
loadState(); loadState();
} }
var loadHistory = function() { function loadHistory() {
promptFrame.putmsg(" Hit <SPACE> to skip"); promptFrame.putmsg(" Hit <SPACE> to skip");
var len = jsonClient.read(dbName, "SEQUENCE.length", 1); var len = jsonClient.read(dbName, "SEQUENCE.length", 1);
pageLoop: pageLoop:
for (var i = 0; i < len; i = i + ((len - i > page) ? page : len - i)) { for (var i = 0; i < len; i = i + ((len - i > page) ? page : len - i)) {
var history = jsonClient.slice( var history = jsonClient.slice(
dbName, dbName, "SEQUENCE", i, ((len - i > page) ? i + page : len), 1
"SEQUENCE",
i,
((len - i > page) ? i + page : len),
1
); );
for (var h = 0; h < history.length; h++) { for (var h = 0; h < history.length; h++) {
if (history[h].c == "CLEAR") { if (history[h].c == "CLEAR") {
...@@ -151,22 +136,20 @@ var loadHistory = function() { ...@@ -151,22 +136,20 @@ var loadHistory = function() {
break pageLoop; break pageLoop;
} }
// Loading the next 'page' history elements will delay us anyhow. // Loading the next 'page' history elements will delay us anyhow.
if(h < history.length - 1) if (h < history.length - 1) mswait(delay);
mswait(delay);
} }
} }
promptFrame.bottom(); promptFrame.bottom();
statusFrame.clear(); statusFrame.clear();
editor.cycle(true); editor.cycle(true);
lastUser = -1; lastUser = -1;
lastSystem = -1; lastSystem = -1;
} }
var loadState = function(state) { function loadState(state) {
if(typeof state == "undefined") if (typeof state == "undefined") {
var state = jsonClient.read(dbName, "STATE", 1); var state = jsonClient.read(dbName, "STATE", 1);
}
editor.clear(); editor.clear();
for(var y in state) { for(var y in state) {
for(var x in state[y]) { for(var x in state[y]) {
...@@ -181,30 +164,24 @@ var loadState = function(state) { ...@@ -181,30 +164,24 @@ var loadState = function(state) {
} }
} }
var sendUpdate = function(ch) { function sendUpdate(ch) {
jsonClient.write( jsonClient.write(
dbName, dbName, "LATEST", {
"LATEST", 'x' : ch.x,
{ 'x' : ch.x,
'y' : ch.y, 'y' : ch.y,
'c' : ch.ch, 'c' : ch.ch,
'a' : ch.attr, 'a' : ch.attr,
'u' : users.indexOf(user.alias), 'u' : users.indexOf(user.alias),
's' : systems.indexOf(system.name) 's' : systems.indexOf(system.name)
}, }, 2
2
); );
} }
var processUpdate = function(update) { function processUpdate(update) {
if(update.oper != "WRITE") if (update.oper != "WRITE") return;
return;
var location = update.location.split("."); var location = update.location.split(".");
if (location[0] == "USERS") { if (location[0] == "USERS") {
users.push(update.data[update.data.length - 1]); users.push(update.data[update.data.length - 1]);
} else if (location[0] == "SYSTEMS") { } else if (location[0] == "SYSTEMS") {
...@@ -226,16 +203,14 @@ var processUpdate = function(update) { ...@@ -226,16 +203,14 @@ var processUpdate = function(update) {
} }
var initDisplay = function() { function initDisplay() {
attr = console.attributes; attr = console.attributes;
systemStatus = bbs.sys_status; systemStatus = bbs.sys_status;
bbs.sys_status |= SS_MOFF; bbs.sys_status |= SS_MOFF;
console.clear(LIGHTGRAY); console.clear(LIGHTGRAY);
} }
var initFrames = function() { function initFrames() {
frame = new Frame( frame = new Frame(
1, 1,
...@@ -246,51 +221,34 @@ var initFrames = function() { ...@@ -246,51 +221,34 @@ var initFrames = function() {
); );
titleFrame = new Frame( titleFrame = new Frame(
frame.x, frame.x, frame.y, frame.width, 1, BG_BLUE|WHITE, frame
frame.y,
frame.width,
1,
BG_BLUE|WHITE,
frame
); );
titleFrame.putmsg( titleFrame.putmsg(
"\1h\1w.: SyncWall InterBBS Graffiti Wall :. Hit [ESC] to exit" "\1h\1w.: SyncWall InterBBS Graffiti Wall :. Hit [ESC] to exit"
); );
titleFrame.gotoxy(titleFrame.width - 10, 1); titleFrame.gotoxy(titleFrame.width - 10, 1);
titleFrame.putmsg("\1h\1bby echicken"); // Aww yeah, bby. :| titleFrame.putmsg("\1h\1bby echicken");
statusFrame = new Frame( statusFrame = new Frame(
frame.x, frame.x, frame.y + frame.height - 1,
frame.y + frame.height - 1, frame.width, 1, BG_BLUE|WHITE, frame
frame.width,
1,
BG_BLUE|WHITE,
frame
); );
promptFrame = new Frame( promptFrame = new Frame(
statusFrame.width - 20, statusFrame.width - 20, statusFrame.y, 21, 1, BG_BLUE|WHITE, statusFrame
statusFrame.y,
21,
1,
BG_BLUE|WHITE,
statusFrame
); );
editorFrame = new Frame( editorFrame = new Frame(
frame.x, frame.x, titleFrame.y + titleFrame.height,
titleFrame.y + titleFrame.height, frame.width, frame.height - titleFrame.height - statusFrame.height,
frame.width, LIGHTGRAY, frame
frame.height - titleFrame.height - statusFrame.height,
LIGHTGRAY,
frame
); );
frame.open(); frame.open();
} }
var initEditor = function() { function initEditor() {
editor = new ANSIEdit( editor = new ANSIEdit(
{ 'x' : editorFrame.x, { 'x' : editorFrame.x,
...@@ -314,29 +272,25 @@ var initEditor = function() { ...@@ -314,29 +272,25 @@ var initEditor = function() {
} }
var initUsers = function() { function initUsers() {
users = jsonClient.read(dbName, "USERS", 1); users = jsonClient.read(dbName, "USERS", 1);
if (!users || users.indexOf(user.alias) < 0) { if (!users || users.indexOf(user.alias) < 0) {
jsonClient.push(dbName, "USERS", user.alias, 2); jsonClient.push(dbName, "USERS", user.alias, 2);
users = jsonClient.read(dbName, "USERS", 1); users = jsonClient.read(dbName, "USERS", 1);
} }
jsonClient.subscribe(dbName, "USERS"); jsonClient.subscribe(dbName, "USERS");
} }
var initSystems = function() { function initSystems() {
systems = jsonClient.read(dbName, "SYSTEMS", 1); systems = jsonClient.read(dbName, "SYSTEMS", 1);
if (!systems || systems.indexOf(system.name) < 0) { if (!systems || systems.indexOf(system.name) < 0) {
jsonClient.push(dbName, "SYSTEMS", system.name, 2); jsonClient.push(dbName, "SYSTEMS", system.name, 2);
systems = jsonClient.read(dbName, "SYSTEMS", 1); systems = jsonClient.read(dbName, "SYSTEMS", 1);
} }
jsonClient.subscribe(dbName, "SYSTEMS"); jsonClient.subscribe(dbName, "SYSTEMS");
} }
var initJSON = function() { function initJSON() {
if (file_exists(js.exec_dir + "server.ini")) { if (file_exists(js.exec_dir + "server.ini")) {
var f = new File(js.exec_dir + "server.ini"); var f = new File(js.exec_dir + "server.ini");
...@@ -351,8 +305,7 @@ var initJSON = function() { ...@@ -351,8 +305,7 @@ var initJSON = function() {
var ini = f.iniGetObject("JSON"); var ini = f.iniGetObject("JSON");
f.close(); f.close();
// services.ini normally uses "Port" rather than "port", but it's actually not case sensitive // services.ini normally uses "Port" rather than "port", but it's actually not case sensitive
if(ini.port == undefined && ini.Port != undefined) if (ini.port == undefined && ini.Port != undefined) ini.port = ini.Port;
ini.port = ini.Port;
var host = "localhost"; var host = "localhost";
var port = (ini === null) ? 10088 : Number(ini.port); var port = (ini === null) ? 10088 : Number(ini.port);
} }
...@@ -360,15 +313,12 @@ var initJSON = function() { ...@@ -360,15 +313,12 @@ var initJSON = function() {
jsonClient.callback = processUpdate; jsonClient.callback = processUpdate;
jsonClient.subscribe(dbName, "LATEST"); jsonClient.subscribe(dbName, "LATEST");
months = jsonClient.read(dbName, "MONTHS", 1); months = jsonClient.read(dbName, "MONTHS", 1);
if(!months) if (!months) months = [];
months = [];
} }
var init = function() { function init() {
timer = new Timer(); timer = new Timer();
initDisplay(); initDisplay();
initJSON(); initJSON();
initFrames(); initFrames();
...@@ -376,46 +326,35 @@ var init = function() { ...@@ -376,46 +326,35 @@ var init = function() {
initUsers(); initUsers();
initSystems(); initSystems();
loadHistory(); loadHistory();
} }
var cycle = function() { function cycle() {
frame.cycle();
editor.cycle(); editor.cycle();
jsonClient.cycle(); jsonClient.cycle();
timer.cycle(); timer.cycle();
if (frame.cycle()) console.gotoxy(console.screen_columns, console.screen_rows);
} }
var input = function() { function input() {
var userInput = console.inkey(K_NONE, 5); var userInput = console.inkey(K_NONE, 5);
if(userInput == "") if (userInput == "") return true;
return true; if (ascii(userInput) == 27) return false;
if(ascii(userInput) == 27)
return false;
var ret = editor.getcmd(userInput); var ret = editor.getcmd(userInput);
if (ret.ch != false || ascii(ret.ch) == 32) { if (ret.ch != false || ascii(ret.ch) == 32) {
updateStatus(users.indexOf(user.alias), systems.indexOf(system.name)); updateStatus(users.indexOf(user.alias), systems.indexOf(system.name));
sendUpdate(ret); sendUpdate(ret);
} }
return true; return true;
} }
var main = function() { function main() {
while(!js.terminated) { while(!js.terminated) {
if(!input()) if(!input()) break;
break;
cycle(); cycle();
} }
} }
var cleanUp = function() { function cleanUp() {
jsonClient.disconnect(); jsonClient.disconnect();
editor.close(); editor.close();
frame.close(); frame.close();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment