diff --git a/world/clientlist.cpp b/world/clientlist.cpp index 31eeb6d67..1671ca2ad 100644 --- a/world/clientlist.cpp +++ b/world/clientlist.cpp @@ -281,62 +281,107 @@ ClientListEntry* ClientList::FindCLEByCharacterID(uint32 iCharID) { return nullptr; } -void ClientList::SendCLEList(const int16& admin, const char* to, WorldTCPConnection* connection, const char* iName) { +void ClientList::SendCLEList(const int16& admin, const char* to, WorldTCPConnection* connection, const char* search_criteria) +{ LinkedListIterator iterator(clientlist); - int x = 0, y = 0; - int namestrlen = iName == 0 ? 0 : strlen(iName); - bool addnewline = false; - char newline[3]; - if (connection->IsConsole()) - strcpy(newline, "\r\n"); - else - strcpy(newline, "^"); - auto out = fmt::memory_buffer(); + int found_count = 0; + int total_count = 0; + int name_length = search_criteria ? strlen(search_criteria) : 0; + + const char* new_line = connection->IsConsole() ? "\r\n" : "^"; + bool add_new_line = false; + + std::string message; + iterator.Reset(); - while(iterator.MoreElements()) { + + while (iterator.MoreElements()) { ClientListEntry* cle = iterator.GetData(); - if (admin >= cle->Admin() && (iName == 0 || namestrlen == 0 || strncasecmp(cle->name(), iName, namestrlen) == 0 || strncasecmp(cle->AccountName(), iName, namestrlen) == 0 || strncasecmp(cle->LSName(), iName, namestrlen) == 0)) { - struct in_addr in; - in.s_addr = cle->GetIP(); - if (addnewline) { - fmt::format_to(std::back_inserter(out), fmt::runtime(newline)); + + struct in_addr in; + in.s_addr = cle->GetIP(); + + if ( + admin >= cle->Admin() && + ( + !search_criteria || + Strings::Contains(std::string(inet_ntoa(in)), search_criteria) || + Strings::Contains(cle->name(), search_criteria) == 0 || + Strings::Contains(cle->AccountName(), search_criteria) == 0 || + Strings::Contains(cle->LSName(), search_criteria) == 0 + ) + ) { + if (add_new_line) { + message += new_line; } - fmt::format_to(std::back_inserter(out), "ID: {} Acc# {} AccName: {} IP: {}", cle->GetID(), cle->AccountID(), cle->AccountName(), inet_ntoa(in)); - fmt::format_to(std::back_inserter(out), "{} Stale: {} Online: {} Admin: {}", newline, cle->GetStaleCounter(), static_cast(cle->Online()), cle->Admin()); - if (cle->LSID()) - fmt::format_to(std::back_inserter(out), "{} LSID: {} LSName: {} WorldAdmin: {}", newline, cle->LSID(), cle->LSName(), cle->WorldAdmin()); - if (cle->CharID()) - fmt::format_to(std::back_inserter(out), "{} CharID: {} CharName: {} Zone: {} ({})", newline, cle->CharID(), cle->name(), ZoneName(cle->zone()), cle->zone()); - if (out.size() >= 3072) { + + message += fmt::format( + "Account: {} ({}) | IP: {} | Admin: {}", + cle->AccountName(), + cle->AccountID(), + inet_ntoa(in), + cle->Admin() + ); + + if (cle->CharID()) { + message += fmt::format( + "{}Character: {} ({}) | Zone: {} ({})", + new_line, + cle->name(), + cle->CharID(), + ZoneLongName(cle->zone()), + cle->zone() + ); + } + + if (message.size() >= 3072) { connection->SendEmoteMessageRaw( to, 0, AccountStatus::Player, Chat::NPCQuestSay, - out.data() + message.c_str() ); - addnewline = false; - out.clear(); + message.clear(); + add_new_line = false; } else { - addnewline = true; + add_new_line = true; } - y++; + + found_count++; } + iterator.Advance(); - x++; + total_count++; } - fmt::format_to(std::back_inserter(out), "{}{} CLEs in memory. {} CLEs listed. numplayers = {}.", newline, x, y, numplayers); + + message += fmt::format( + "{}{}Player Count: {}", + new_line, + ( + found_count != total_count ? + fmt::format( + "Total: {} CLE{} | Found: {} CLE{} | ", + total_count, + (total_count != 1 ? "s" : ""), + found_count, + (found_count != 1 ? "s" : "") + ) : + "" + ), + numplayers + ); + connection->SendEmoteMessageRaw( to, 0, AccountStatus::Player, Chat::NPCQuestSay, - out.data() + message.c_str() ); } - void ClientList::CLEAdd( uint32 login_server_id, const char *login_server_name, diff --git a/world/clientlist.h b/world/clientlist.h index 64501f265..b158ad28d 100644 --- a/world/clientlist.h +++ b/world/clientlist.h @@ -45,7 +45,7 @@ public: void SendClientVersionSummary(const char *Name); void SendLFGMatches(ServerLFGMatchesRequest_Struct *LFGMatchesRequest); void ConsoleSendWhoAll(const char* to, int16 admin, Who_All_Struct* whom, WorldTCPConnection* connection); - void SendCLEList(const int16& admin, const char* to, WorldTCPConnection* connection, const char* iName = 0); + void SendCLEList(const int16& admin, const char* to, WorldTCPConnection* connection, const char* search_criteria = 0); bool SendPacket(const char* to, ServerPacket* pack); diff --git a/zone/gm_commands/show/ip_lookup.cpp b/zone/gm_commands/show/ip_lookup.cpp index b020541b4..aefcaeaf3 100644 --- a/zone/gm_commands/show/ip_lookup.cpp +++ b/zone/gm_commands/show/ip_lookup.cpp @@ -9,7 +9,7 @@ void ShowIPLookup(Client *c, const Seperator *sep) auto pack = new ServerPacket( ServerOP_IPLookup, - sizeof(ServerGenericWorldQuery_Struct) + ip_length + 1 + sizeof(ServerGenericWorldQuery_Struct) + ip_length ); auto s = (ServerGenericWorldQuery_Struct *) pack->pBuffer;