Skip to content

Commit

Permalink
Check welcome message length
Browse files Browse the repository at this point in the history
To not try sending a null message to newly connected users if it's too
long. This is really unlikely to happen in practice, but better to do
so.
  • Loading branch information
askmeaboutlo0m committed Dec 3, 2024
1 parent 15c6bc6 commit 155fd33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/libserver/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,11 +689,16 @@ void Client::sendDirectMessages(const net::MessageList &msgs)
}
}

void Client::sendSystemChat(const QString &message, bool alert)
bool Client::sendSystemChat(const QString &message, bool alert)
{
d->msgqueue->send(
alert ? net::ServerReply::makeAlert(message)
: net::ServerReply::makeMessage(message));
net::Message msg = alert ? net::ServerReply::makeAlert(message)
: net::ServerReply::makeMessage(message);
if(msg.isNull()) {
return false;
} else {
d->msgqueue->send(msg);
return true;
}
}

void Client::receiveMessages()
Expand Down
2 changes: 1 addition & 1 deletion src/libserver/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class Client : public QObject {
* @brief Send a message from the server directly to this user
* @param message
*/
void sendSystemChat(const QString &message, bool alert = false);
bool sendSystemChat(const QString &message, bool alert = false);

bool isWebSocket() const;

Expand Down
6 changes: 4 additions & 2 deletions src/libserver/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ void Session::joinUser(Client *user, bool host)

const QString welcomeMessage =
m_config->getConfigString(config::WelcomeMessage);
if(!welcomeMessage.isEmpty()) {
user->sendSystemChat(welcomeMessage);
if(!welcomeMessage.isEmpty() && !user->sendSystemChat(welcomeMessage)) {
user->log(Log()
.about(Log::Level::Error, Log::Topic::Status)
.message(QStringLiteral("Welcome message too long")));
}

// Make sure everyone is up to date
Expand Down

0 comments on commit 155fd33

Please sign in to comment.