fix chat error message broadcast
This commit is contained in:
parent
e427eeced0
commit
fbc564f588
|
@ -55,11 +55,13 @@ export class ChatProvider {
|
||||||
socketEvents.on('recvChatMessage', async (user, message, channelId) => {
|
socketEvents.on('recvChatMessage', async (user, message, channelId) => {
|
||||||
const errorMsg = await this.sendMessage(user, message, channelId);
|
const errorMsg = await this.sendMessage(user, message, channelId);
|
||||||
if (errorMsg) {
|
if (errorMsg) {
|
||||||
this.broadcastChatMessage(
|
socketEvents.broadcastSUChatMessage(
|
||||||
|
user.id,
|
||||||
'info',
|
'info',
|
||||||
errorMsg,
|
errorMsg,
|
||||||
channelId,
|
channelId,
|
||||||
this.infoUserId,
|
this.infoUserId,
|
||||||
|
'il',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -314,6 +316,10 @@ export class ChatProvider {
|
||||||
const { t } = user.ttag;
|
const { t } = user.ttag;
|
||||||
const name = user.getName();
|
const name = user.getName();
|
||||||
|
|
||||||
|
if (!name || !id) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!user.userlvl && await cheapDetector(user.ip)) {
|
if (!user.userlvl && await cheapDetector(user.ip)) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`${name} / ${user.ip} tried to send chat message with proxy`,
|
`${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`;
|
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) {
|
if (message.charAt(0) === '/' && user.userlvl) {
|
||||||
return this.adminCommands(message, channelId);
|
return this.adminCommands(message, channelId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class SocketEvents extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* broadcast chat message
|
* broadcast chat message to all users in channel
|
||||||
* @param name chatname
|
* @param name chatname
|
||||||
* @param message Message to send
|
* @param message Message to send
|
||||||
* @param sendapi If chat message should get boradcasted to api websockets
|
* @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
|
* broadcast Assigning chat channel to user
|
||||||
* @param userId numerical id of user
|
* @param userId numerical id of user
|
||||||
|
|
|
@ -119,6 +119,20 @@ class SocketServer {
|
||||||
socketEvents.on('pixelUpdate', this.broadcastPixelBuffer);
|
socketEvents.on('pixelUpdate', this.broadcastPixelBuffer);
|
||||||
socketEvents.on('reloadUser', this.reloadUser);
|
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', (
|
socketEvents.on('chatMessage', (
|
||||||
name,
|
name,
|
||||||
message,
|
message,
|
||||||
|
@ -338,11 +352,7 @@ class SocketServer {
|
||||||
/*
|
/*
|
||||||
* send chat message
|
* send chat message
|
||||||
*/
|
*/
|
||||||
socketEvents.recvChatMessage(
|
socketEvents.recvChatMessage(user, message, channelId);
|
||||||
user,
|
|
||||||
message,
|
|
||||||
channelId,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
logger.info('Got empty message or message from unidentified ws');
|
logger.info('Got empty message or message from unidentified ws');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user