fix chat error message broadcast

This commit is contained in:
HF 2021-07-10 20:10:36 +02:00
parent e427eeced0
commit fbc564f588
3 changed files with 45 additions and 12 deletions

View File

@ -55,11 +55,13 @@ export class ChatProvider {
socketEvents.on('recvChatMessage', async (user, message, channelId) => {
const errorMsg = await this.sendMessage(user, message, channelId);
if (errorMsg) {
this.broadcastChatMessage(
socketEvents.broadcastSUChatMessage(
user.id,
'info',
errorMsg,
channelId,
this.infoUserId,
'il',
);
}
});
@ -314,6 +316,10 @@ export class ChatProvider {
const { t } = user.ttag;
const name = user.getName();
if (!name || !id) {
return null;
}
if (!user.userlvl && await cheapDetector(user.ip)) {
logger.info(
`${name} / ${user.ip} tried to send chat message with proxy`,
@ -321,11 +327,6 @@ export class ChatProvider {
return t`You can not send chat messages with proxy`;
}
if (!name || !id) {
// eslint-disable-next-line max-len
return t`Couldn\'t send your message, pls log out and back in again.`;
}
if (message.charAt(0) === '/' && user.userlvl) {
return this.adminCommands(message, channelId);
}

View File

@ -52,7 +52,7 @@ class SocketEvents extends EventEmitter {
}
/*
* broadcast chat message
* broadcast chat message to all users in channel
* @param name chatname
* @param message Message to send
* @param sendapi If chat message should get boradcasted to api websockets
@ -77,6 +77,28 @@ class SocketEvents extends EventEmitter {
);
}
/*
* send chat message to a single user in channel
*/
broadcastSUChatMessage(
targetUserId: number,
name: string,
message: string,
channelId: number,
id: number,
country: string = 'xx',
) {
this.emit(
'suChatMessage',
targetUserId,
name,
message,
channelId,
id,
country || 'xx',
);
}
/*
* broadcast Assigning chat channel to user
* @param userId numerical id of user

View File

@ -119,6 +119,20 @@ class SocketServer {
socketEvents.on('pixelUpdate', this.broadcastPixelBuffer);
socketEvents.on('reloadUser', this.reloadUser);
socketEvents.on('suChatMessage', (
userId,
name,
message,
channelId,
id,
country,
) => {
this.findAllWsByUerId(userId).forEach((ws) => {
const text = JSON.stringify([name, message, country, channelId, id]);
ws.send(text);
});
});
socketEvents.on('chatMessage', (
name,
message,
@ -338,11 +352,7 @@ class SocketServer {
/*
* send chat message
*/
socketEvents.recvChatMessage(
user,
message,
channelId,
);
socketEvents.recvChatMessage(user, message, channelId);
} else {
logger.info('Got empty message or message from unidentified ws');
}