Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue on URL resolver message #552

Merged
merged 4 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 50 additions & 18 deletions core/mrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,7 @@ exports.getModule = class mrcModule extends MenuModule {
const chatLogView = this.viewControllers.mrcChat.getView(
MciViewIds.mrcChat.chatLog
);
const messageLength = stripMciColorCodes(msg).length;
const chatWidth = chatLogView.dimens.width;
let padAmount = 0;
let spaces = 2;

if (messageLength > chatWidth) {
padAmount = chatWidth - (messageLength % chatWidth) - spaces;
} else {
padAmount = chatWidth - messageLength - spaces;
}

if (padAmount < 0) padAmount = 0;

const padding = ' |00' + ' '.repeat(padAmount);
chatLogView.addText(pipeToAnsi(msg + padding));
chatLogView.addText(pipeToAnsi(msg));
Copy link
Owner

@NuSkooler NuSkooler Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this will work correctly, I'll have to do some testing. This MR just got a bit bigger

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the latest client and it worked fine on my end. All the padding appeared to be from an older way of drawing the screen which appeared to have changed since it was first implemented (assumption here). On my end, it was working pretty well without it and fixed an issue with text wrapping on certain cases. Let me know if there is anything I missed.


if (chatLogView.getLineCount() > this.config.maxScrollbackLines) {
chatLogView.deleteLine(0);
Expand Down Expand Up @@ -380,7 +366,7 @@ exports.getModule = class mrcModule extends MenuModule {

// Deliver PrivMsg
else if (
message.to_user.toLowerCase() == this.state.alias.toLowerCase()
message.to_user.toUpperCase() == this.state.alias.toUpperCase()
) {
const currentTime = moment().format(
this.client.currentTheme.helpers.getTimeFormat()
Expand Down Expand Up @@ -450,6 +436,14 @@ exports.getModule = class mrcModule extends MenuModule {
} else {
// pm
formattedMessage = stringFormat(privateMessageFormat, textFormatObj);

// Echo PrivMSG to chat log (the server does not echo it back)
const currentTime =moment().format(
this.client.currentTheme.helpers.getTimeFormat()
);
this.addMessageToChatLog(
'|08' + currentTime + '|00 ' + formattedMessage + '|00'
);
}

try {
Expand Down Expand Up @@ -562,6 +556,7 @@ exports.getModule = class mrcModule extends MenuModule {
/**
* Process known additional server commands directly
*/

case 'afk':
this.sendServerMessage(`AFK ${message.substr(5)}`);
break;
Expand Down Expand Up @@ -594,6 +589,30 @@ exports.getModule = class mrcModule extends MenuModule {
this.sendServerMessage(cmd[0].toUpperCase());
break;

/**
* MRC Trust commands
*/

case 'trust':
this.sendServerMessage(`REGISTER ${message.substr(7)}`);
break;

case 'register':
this.sendServerMessage(`REGISTER ${message.substr(10)}`);
break;

case 'identify':
this.sendServerMessage(`IDENTIFY ${message.substr(10)}`);
break;

case 'update':
this.sendServerMessage(`UPDATE ${message.substr(8)}`);
break;

/**
* Local client commands
*/

case 'quit':
return this.prevMenu();

Expand Down Expand Up @@ -665,13 +684,26 @@ exports.getModule = class mrcModule extends MenuModule {
this.sendServerMessage('USERLIST');
}

/**
* MRC Server flood protection requires messages to be spaced in time
*/
msgDelay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

/**
* Things that happen when a local user connects to the MRC multiplexer
*/
clientConnect() {
async clientConnect() {
this.sendHeartbeat();
await this.msgDelay(100);

this.sendServerMessage('MOTD');
await this.msgDelay(100);

this.joinRoom('lobby');
await this.msgDelay(100);

this.sendServerMessage('STATS');
this.sendHeartbeat();
}
};
11 changes: 7 additions & 4 deletions core/servers/chat/mrc_multiplexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const os = require('os');

// MRC
const clientVersion = '1.3.1';
const lineDelimiter = new RegExp('\r\n|\r|\n'); // eslint-disable-line no-control-regex
const lineDelimiter = new RegExp('\r\n|\r|\n|\n\r'); // eslint-disable-line no-control-regex

const ModuleInfo = (exports.moduleInfo = {
name: 'MRC',
Expand Down Expand Up @@ -245,8 +245,7 @@ exports.getModule = class MrcModule extends ServerModule {
connectedSockets.forEach(client => {
if (
message.to_user == '' ||
// Fix PrivMSG delivery on case mismatch
message.to_user.toUpperCase() == client.username.toUpperCase() ||
message.to_user == client.username.toUpperCase() ||
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These would technically be better using localeCompare with sensitivity 'accent'.

message.to_user == 'CLIENT' ||
message.from_user == client.username ||
message.to_user == 'NOTME'
Expand Down Expand Up @@ -328,14 +327,18 @@ exports.getModule = class MrcModule extends ServerModule {
* Takes an MRC message and parses it into something usable
*/
parseMessage(line) {
const [from_user, from_site, from_room, to_user, to_site, to_room, body] =
let [from_user, from_site, from_room, to_user, to_site, to_room, body] =
line.split('~');

// const msg = line.split('~');
// if (msg.length < 7) {
// return;
// }

// Make sure to_user and from_user are always uppercase
to_user = (to_user || '').toUpperCase();
from_user = (from_user || '').toUpperCase();

return { from_user, from_site, from_room, to_user, to_site, to_room, body };
}

Expand Down
Loading