Skip to content

Commit 01855d4

Browse files
authored
[Bug Fix] Fix log messages when players join channel (#2992)
* Fix log message when players join channels * Formatting * More formatting * Update CurrentPlayerChannels to use vector of channel names * Put log statement back in place * Remove channel limit in db query * Formatting tweak
1 parent 748602b commit 01855d4

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

ucs/chatchannel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ ChatChannel::ChatChannel(std::string inName, std::string inOwner, std::string in
4848
m_moderated = false;
4949

5050
LogDebug(
51-
"New ChatChannel created: Name: [{}], Owner: [{}], Password: [{}], MinStatus: [{}]",
52-
m_name.c_str(),
53-
m_owner.c_str(),
54-
m_password.c_str(),
51+
"New ChatChannel created: Name: [{}] Owner: [{}] Password: [{}] MinStatus: [{}]",
52+
m_name,
53+
m_owner,
54+
m_password,
5555
m_minimum_status
5656
);
5757

@@ -667,7 +667,7 @@ ChatChannel *ChatChannelList::RemoveClientFromChannel(const std::string& in_chan
667667
}
668668

669669
LogDebug("Client [{}] removed from channel [{}]. Channel is owned by {}. Command directed: {}", c->GetName(), channel_name, required_channel->GetOwnerName(), command_directed);
670-
if (c->GetName() == required_channel->GetOwnerName() && command_directed) { // Check if the client that is leaving is the the channel owner
670+
if (c->GetName() == required_channel->GetOwnerName() && command_directed) { // Check if the client that is leaving is the channel owner
671671
LogDebug("Owner left the channel [{}], removing channel from database...", channel_name);
672672
database.DeleteChatChannel(channel_name); // Remove the channel from the database.
673673
LogDebug("Flagging [{}] channel as temporary...", channel_name);

ucs/clientlist.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,10 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string command_string, boo
793793
case CommandJoin:
794794
if (!command_directed) {
795795
//Append saved channels to params
796-
parameters = parameters + ", " + database.CurrentPlayerChannels(c->GetName());
796+
const auto saved_channels = database.CurrentPlayerChannels(c->GetName());
797+
if (!saved_channels.empty()) {
798+
parameters += fmt::format(", {}", Strings::Join(saved_channels, ", "));
799+
}
797800
parameters = RemoveDuplicateChannels(parameters);
798801
}
799802
c->JoinChannels(parameters, command_directed);

ucs/database.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,17 @@ void UCSDatabase::DeleteChatChannel(const std::string& channel_name)
336336
LogInfo("Deleting channel [{}] from the database.", channel_name);
337337
}
338338

339-
std::string UCSDatabase::CurrentPlayerChannels(const std::string& player_name) {
340-
int current_player_channel_count = CurrentPlayerChannelCount(player_name);
341-
if (current_player_channel_count == 0) {
342-
return "";
339+
std::vector<std::string> UCSDatabase::CurrentPlayerChannels(const std::string& player_name) {
340+
auto rows = ChatchannelsRepository::GetWhere(*this, fmt::format("`owner` = '{}'", Strings::Escape(player_name)));
341+
if (rows.empty()) {
342+
return {};
343343
}
344-
const auto rquery = fmt::format("SELECT GROUP_CONCAT(`name` SEPARATOR ', ') FROM chatchannels WHERE `owner` = '{}'; ", Strings::Escape(player_name));
345-
auto results = QueryDatabase(rquery);
346-
auto row = results.begin();
347-
std::string channels = row[0];
348-
LogDebug("Player [{}] has the following permanent channels saved to the database: [{}].", player_name, channels);
344+
std::vector<std::string> channels = {};
345+
channels.reserve(rows.size());
346+
for (auto &e: rows) {
347+
channels.emplace_back(e.name);
348+
}
349+
LogDebug("Player [{}] has the following [{}] permanent channels saved to the database: [{}].", player_name, rows.size(), Strings::Join(channels, ", "));
349350
return channels;
350351
}
351352

ucs/database.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class UCSDatabase : public Database {
5252
void SaveChatChannel(const std::string& channel_name, const std::string& channel_owner, const std::string& channel_password, const uint16& min_status);
5353
void DeleteChatChannel(const std::string& channel_name);
5454
int CurrentPlayerChannelCount(const std::string& player_name);
55-
std::string CurrentPlayerChannels(const std::string& player_name);
55+
std::vector<std::string> CurrentPlayerChannels(const std::string& player_name);
5656
void GetAccountStatus(Client *c);
5757
void SetChannelPassword(const std::string& channel_name, const std::string& password);
5858
void SetChannelOwner(const std::string& channel_name, const std::string& owner);

0 commit comments

Comments
 (0)