diff --git a/ucs/chatchannel.cpp b/ucs/chatchannel.cpp index 7dd86a38a..123c4aa99 100644 --- a/ucs/chatchannel.cpp +++ b/ucs/chatchannel.cpp @@ -48,10 +48,10 @@ ChatChannel::ChatChannel(std::string inName, std::string inOwner, std::string in m_moderated = false; LogDebug( - "New ChatChannel created: Name: [{}], Owner: [{}], Password: [{}], MinStatus: [{}]", - m_name.c_str(), - m_owner.c_str(), - m_password.c_str(), + "New ChatChannel created: Name: [{}] Owner: [{}] Password: [{}] MinStatus: [{}]", + m_name, + m_owner, + m_password, m_minimum_status ); @@ -667,7 +667,7 @@ ChatChannel *ChatChannelList::RemoveClientFromChannel(const std::string& in_chan } LogDebug("Client [{}] removed from channel [{}]. Channel is owned by {}. Command directed: {}", c->GetName(), channel_name, required_channel->GetOwnerName(), command_directed); - if (c->GetName() == required_channel->GetOwnerName() && command_directed) { // Check if the client that is leaving is the the channel owner + if (c->GetName() == required_channel->GetOwnerName() && command_directed) { // Check if the client that is leaving is the channel owner LogDebug("Owner left the channel [{}], removing channel from database...", channel_name); database.DeleteChatChannel(channel_name); // Remove the channel from the database. LogDebug("Flagging [{}] channel as temporary...", channel_name); diff --git a/ucs/clientlist.cpp b/ucs/clientlist.cpp index 2886edee3..070c962cc 100644 --- a/ucs/clientlist.cpp +++ b/ucs/clientlist.cpp @@ -793,7 +793,10 @@ void Clientlist::ProcessOPMailCommand(Client *c, std::string command_string, boo case CommandJoin: if (!command_directed) { //Append saved channels to params - parameters = parameters + ", " + database.CurrentPlayerChannels(c->GetName()); + const auto saved_channels = database.CurrentPlayerChannels(c->GetName()); + if (!saved_channels.empty()) { + parameters += fmt::format(", {}", Strings::Join(saved_channels, ", ")); + } parameters = RemoveDuplicateChannels(parameters); } c->JoinChannels(parameters, command_directed); diff --git a/ucs/database.cpp b/ucs/database.cpp index 0adc03a30..ee69cf1c3 100644 --- a/ucs/database.cpp +++ b/ucs/database.cpp @@ -336,16 +336,17 @@ void UCSDatabase::DeleteChatChannel(const std::string& channel_name) LogInfo("Deleting channel [{}] from the database.", channel_name); } -std::string UCSDatabase::CurrentPlayerChannels(const std::string& player_name) { - int current_player_channel_count = CurrentPlayerChannelCount(player_name); - if (current_player_channel_count == 0) { - return ""; +std::vector UCSDatabase::CurrentPlayerChannels(const std::string& player_name) { + auto rows = ChatchannelsRepository::GetWhere(*this, fmt::format("`owner` = '{}'", Strings::Escape(player_name))); + if (rows.empty()) { + return {}; } - const auto rquery = fmt::format("SELECT GROUP_CONCAT(`name` SEPARATOR ', ') FROM chatchannels WHERE `owner` = '{}'; ", Strings::Escape(player_name)); - auto results = QueryDatabase(rquery); - auto row = results.begin(); - std::string channels = row[0]; - LogDebug("Player [{}] has the following permanent channels saved to the database: [{}].", player_name, channels); + std::vector channels = {}; + channels.reserve(rows.size()); + for (auto &e: rows) { + channels.emplace_back(e.name); + } + LogDebug("Player [{}] has the following [{}] permanent channels saved to the database: [{}].", player_name, rows.size(), Strings::Join(channels, ", ")); return channels; } diff --git a/ucs/database.h b/ucs/database.h index 0b4bfe268..aea426599 100644 --- a/ucs/database.h +++ b/ucs/database.h @@ -52,7 +52,7 @@ public: void SaveChatChannel(const std::string& channel_name, const std::string& channel_owner, const std::string& channel_password, const uint16& min_status); void DeleteChatChannel(const std::string& channel_name); int CurrentPlayerChannelCount(const std::string& player_name); - std::string CurrentPlayerChannels(const std::string& player_name); + std::vector CurrentPlayerChannels(const std::string& player_name); void GetAccountStatus(Client *c); void SetChannelPassword(const std::string& channel_name, const std::string& password); void SetChannelOwner(const std::string& channel_name, const std::string& owner);