diff --git a/src/game/ChatCommands/GMTicketCommands.cpp b/src/game/ChatCommands/GMTicketCommands.cpp index 2138a8a7..eeaee938 100644 --- a/src/game/ChatCommands/GMTicketCommands.cpp +++ b/src/game/ChatCommands/GMTicketCommands.cpp @@ -140,6 +140,10 @@ bool ChatHandler::HandleTicketCloseCommand(char* args) return false; } + if (*args) { + ticket->SetResponseText(args); + } + // Set reponse text if not existing if (!*ticket->GetResponse()) { @@ -148,7 +152,7 @@ bool ChatHandler::HandleTicketCloseCommand(char* args) if (m_session) { - const char* format = "[System Message] This ticket was closed by %s without any mail response, perhaps it was resolved by direct chat."; + const char* format = "[System Message] This ticket was closed by %s without any written response, perhaps it was resolved by direct chat."; const char* buffer; snprintf(response, responseBufferSize, format, m_session->GetPlayer()->GetName()); } diff --git a/src/game/WorldHandlers/GMTicketHandler.cpp b/src/game/WorldHandlers/GMTicketHandler.cpp index e2891ffd..2483406e 100644 --- a/src/game/WorldHandlers/GMTicketHandler.cpp +++ b/src/game/WorldHandlers/GMTicketHandler.cpp @@ -71,6 +71,12 @@ void WorldSession::HandleGMTicketUpdateTextOpcode(WorldPacket& recv_data) std::string ticketText; recv_data >> ticketText; + // When updating the ticket , the client adds a leading '\a' char ! so we need to remove it + stripLineInvisibleChars(ticketText); + + // Since invisible char are replaced with a ' ' if any leading space is added we remove it : + ltrim(ticketText); + GMTicketResponse responce = GMTICKET_RESPONSE_UPDATE_SUCCESS; if (GMTicket* ticket = sTicketMgr.GetGMTicket(GetPlayer()->GetObjectGuid())) { diff --git a/src/modules/Bots/playerbot/Helpers.cpp b/src/modules/Bots/playerbot/Helpers.cpp index 3eda258a..46e1ed9c 100644 --- a/src/modules/Bots/playerbot/Helpers.cpp +++ b/src/modules/Bots/playerbot/Helpers.cpp @@ -1,5 +1,6 @@ #include "../botpch.h" #include "playerbot.h" +#include "Util.h" #include #include #include @@ -77,10 +78,6 @@ uint64 extractGuid(WorldPacket& packet) return guid; } -std::string <rim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun(std::isspace)))); - return s; -} std::string &rtrim(std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun(std::isspace))).base(), s.end()); diff --git a/src/shared/Utilities/Util.cpp b/src/shared/Utilities/Util.cpp index a8750bc2..6928ffca 100644 --- a/src/shared/Utilities/Util.cpp +++ b/src/shared/Utilities/Util.cpp @@ -327,6 +327,33 @@ void utf8truncate(std::string& utf8str, size_t len) } } +size_t utf8limit(std::string& utf8str, size_t bytes) +{ + if (utf8str.size() > bytes) + { + try + { + auto end = (utf8str.cbegin() + bytes); + auto itr = utf8::find_invalid(utf8str.cbegin(), end); + + // Fix UTF8 if it was corrupted by bytes truncated + if (itr != end) + bytes = std::distance(utf8str.cbegin(), itr); + + utf8str.resize(bytes); + utf8str.shrink_to_fit(); + + return bytes; + } + catch (const std::exception&) + { + utf8str = ""; + } + } + + return 0; +} + bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize) { try diff --git a/src/shared/Utilities/Util.h b/src/shared/Utilities/Util.h index f74792ea..61b6be5c 100644 --- a/src/shared/Utilities/Util.h +++ b/src/shared/Utilities/Util.h @@ -115,6 +115,13 @@ inline uint32 secsToTimeBitFields(time_t secs) } +inline std::string ltrim(std::string& s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); + return s; +} + /** * @brief Return a random number in the range min..max; (max-min) must be smaller than 32768. * @@ -328,6 +335,14 @@ size_t utf8length(std::string& utf8str); // set string to "" */ void utf8truncate(std::string& utf8str, size_t len); +/** + * @brief + * + * @param utf8str + * @param bytes + */ +size_t utf8limit(std::string& utf8str, size_t bytes); + /** * @brief *