Minor bug fixes and improvements
* Color help text a bit * Split lines for buffer so padding works - may need to do elsewhere also * Fix a couple crashes
This commit is contained in:
parent
c79e2bc971
commit
094385a150
84
core/mrc.js
84
core/mrc.js
|
@ -32,7 +32,7 @@ const FormIds = {
|
||||||
mrcChat : 0,
|
mrcChat : 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
var MciViewIds = {
|
const MciViewIds = {
|
||||||
mrcChat : {
|
mrcChat : {
|
||||||
chatLog : 1,
|
chatLog : 1,
|
||||||
inputArea : 2,
|
inputArea : 2,
|
||||||
|
@ -48,19 +48,20 @@ var MciViewIds = {
|
||||||
|
|
||||||
// TODO: this is a bit shit, could maybe do it with an ansi instead
|
// TODO: this is a bit shit, could maybe do it with an ansi instead
|
||||||
const helpText = `
|
const helpText = `
|
||||||
General Chat:
|
|15General Chat|08:
|
||||||
/rooms & /join <ro - List all or join a room
|
|03/|11rooms |08& |03/|11join |03<room> |08- |07List all or join a room
|
||||||
/pm <user> <message> - Send a private message
|
|03/|11pm |03<user> <message> |08- |07Send a private message
|
||||||
----
|
----
|
||||||
/whoon - Who's on what BBS
|
|03/|11whoon |08- |07Who's on what BBS
|
||||||
/chatters - Who's in what room
|
|03/|11chatters |08- |07Who's in what room
|
||||||
/topic <message> - Set the room topic
|
|03/|11clear |08- |07Clear back buffer
|
||||||
/bbses & /info <id> - Info about BBS's connected
|
|03/|11topic <message> |08- |07Set the room topic
|
||||||
/meetups - Info about MRC MeetUps
|
|03/|11bbses & |03/|11info <id> |08- |07Info about BBS's connected
|
||||||
|
|03/|11meetups |08- |07Info about MRC MeetUps
|
||||||
---
|
---
|
||||||
/l33t <your message> - l337 5p34k
|
|03/|11l33t <your message> |08- |07l337 5p34k
|
||||||
/kewl <your message> - BBS KeWL SPeaK
|
|03/|11kewl <your message> |08- |07BBS KeWL SPeaK
|
||||||
/rainbow <your message> - Crazy rainbow text
|
|03/|11rainbow <your message> |08- |07Crazy rainbow text
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
},
|
},
|
||||||
|
|
||||||
movementKeyPressed : (formData, extraArgs, cb) => {
|
movementKeyPressed : (formData, extraArgs, cb) => {
|
||||||
const bodyView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog); // :TODO: use const here vs magic #
|
const bodyView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog);
|
||||||
switch(formData.key.name) {
|
switch(formData.key.name) {
|
||||||
case 'down arrow' : bodyView.scrollDocumentUp(); break;
|
case 'down arrow' : bodyView.scrollDocumentUp(); break;
|
||||||
case 'up arrow' : bodyView.scrollDocumentDown(); break;
|
case 'up arrow' : bodyView.scrollDocumentDown(); break;
|
||||||
|
@ -108,9 +109,6 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
},
|
},
|
||||||
|
|
||||||
quit : (formData, extraArgs, cb) => {
|
quit : (formData, extraArgs, cb) => {
|
||||||
this.sendServerMessage('LOGOFF');
|
|
||||||
clearInterval(this.heartbeat);
|
|
||||||
this.state.socket.destroy();
|
|
||||||
return this.prevMenu(cb);
|
return this.prevMenu(cb);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -138,16 +136,19 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
|
|
||||||
// connect to multiplexer
|
// connect to multiplexer
|
||||||
this.state.socket = net.createConnection(connectOpts, () => {
|
this.state.socket = net.createConnection(connectOpts, () => {
|
||||||
const self = this;
|
this.client.once('end', () => {
|
||||||
// handshake with multiplexer
|
this.quitServer();
|
||||||
self.state.socket.write(`--DUDE-ITS--|${self.state.alias}\n`);
|
});
|
||||||
|
|
||||||
self.clientConnect();
|
// handshake with multiplexer
|
||||||
|
this.state.socket.write(`--DUDE-ITS--|${this.state.alias}\n`);
|
||||||
|
|
||||||
|
this.clientConnect();
|
||||||
|
|
||||||
// send register to central MRC and get stats every 60s
|
// send register to central MRC and get stats every 60s
|
||||||
self.heartbeat = setInterval(function () {
|
this.heartbeat = setInterval( () => {
|
||||||
self.sendHeartbeat();
|
this.sendHeartbeat();
|
||||||
self.sendServerMessage('STATS');
|
this.sendServerMessage('STATS');
|
||||||
}, 60000);
|
}, 60000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -167,12 +168,31 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leave() {
|
||||||
|
this.quitServer();
|
||||||
|
return super.leave();
|
||||||
|
}
|
||||||
|
|
||||||
|
quitServer() {
|
||||||
|
clearInterval(this.heartbeat);
|
||||||
|
|
||||||
|
if(this.state.socket) {
|
||||||
|
this.sendServerMessage('LOGOFF');
|
||||||
|
this.state.socket.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a message to the chat log on screen
|
* Adds a message to the chat log on screen
|
||||||
*/
|
*/
|
||||||
addMessageToChatLog(message) {
|
addMessageToChatLog(message) {
|
||||||
|
if(!Array.isArray(message)) {
|
||||||
|
message = [ message ];
|
||||||
|
}
|
||||||
|
|
||||||
|
message.forEach(msg => {
|
||||||
const chatLogView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog);
|
const chatLogView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog);
|
||||||
const messageLength = stripMciColorCodes(message).length;
|
const messageLength = stripMciColorCodes(msg).length;
|
||||||
const chatWidth = chatLogView.dimens.width;
|
const chatWidth = chatLogView.dimens.width;
|
||||||
let padAmount = 0;
|
let padAmount = 0;
|
||||||
let spaces = 2;
|
let spaces = 2;
|
||||||
|
@ -186,7 +206,8 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
if (padAmount < 0) padAmount = 0;
|
if (padAmount < 0) padAmount = 0;
|
||||||
|
|
||||||
const padding = ' |00' + ' '.repeat(padAmount);
|
const padding = ' |00' + ' '.repeat(padAmount);
|
||||||
chatLogView.addText(pipeToAnsi(message + padding));
|
chatLogView.addText(pipeToAnsi(msg + padding));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,7 +387,7 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
this.addMessageToChatLog(helpText);
|
this.addMessageToChatLog(helpText.split(/\n/g));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -385,17 +406,18 @@ exports.getModule = class mrcModule extends MenuModule {
|
||||||
sendMessageToMultiplexer(to_user, to_site, to_room, body) {
|
sendMessageToMultiplexer(to_user, to_site, to_room, body) {
|
||||||
|
|
||||||
const message = {
|
const message = {
|
||||||
|
to_user,
|
||||||
|
to_site,
|
||||||
|
to_room,
|
||||||
|
body,
|
||||||
from_user : this.state.alias,
|
from_user : this.state.alias,
|
||||||
from_room : this.state.room,
|
from_room : this.state.room,
|
||||||
to_user: to_user,
|
|
||||||
to_site: to_site,
|
|
||||||
to_room: to_room,
|
|
||||||
body: body
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: check socket still exists here
|
if(this.state.socket) {
|
||||||
this.state.socket.write(JSON.stringify(message) + '\n');
|
this.state.socket.write(JSON.stringify(message) + '\n');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends an MRC 'server' message
|
* Sends an MRC 'server' message
|
||||||
|
|
Loading…
Reference in New Issue