Update GM tickets weird char and set response text when close ticket (#139)

* Fix HandleGMTicketUpdateTextOpcode

* Add response text
This commit is contained in:
Elmsroth 2021-03-04 23:08:29 +01:00 committed by GitHub
parent a5dc2b0598
commit ff9e604e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 5 deletions

View File

@ -140,6 +140,10 @@ bool ChatHandler::HandleTicketCloseCommand(char* args)
return false; return false;
} }
if (*args) {
ticket->SetResponseText(args);
}
// Set reponse text if not existing // Set reponse text if not existing
if (!*ticket->GetResponse()) if (!*ticket->GetResponse())
{ {
@ -148,7 +152,7 @@ bool ChatHandler::HandleTicketCloseCommand(char* args)
if (m_session) if (m_session)
{ {
const char* format = "[System Message] This ticket was closed by <GM>%s without any mail response, perhaps it was resolved by direct chat."; const char* format = "[System Message] This ticket was closed by <GM> %s without any written response, perhaps it was resolved by direct chat.";
const char* buffer; const char* buffer;
snprintf(response, responseBufferSize, format, m_session->GetPlayer()->GetName()); snprintf(response, responseBufferSize, format, m_session->GetPlayer()->GetName());
} }

View File

@ -71,6 +71,12 @@ void WorldSession::HandleGMTicketUpdateTextOpcode(WorldPacket& recv_data)
std::string ticketText; std::string ticketText;
recv_data >> 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; GMTicketResponse responce = GMTICKET_RESPONSE_UPDATE_SUCCESS;
if (GMTicket* ticket = sTicketMgr.GetGMTicket(GetPlayer()->GetObjectGuid())) if (GMTicket* ticket = sTicketMgr.GetGMTicket(GetPlayer()->GetObjectGuid()))
{ {

View File

@ -1,5 +1,6 @@
#include "../botpch.h" #include "../botpch.h"
#include "playerbot.h" #include "playerbot.h"
#include "Util.h"
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <cctype> #include <cctype>
@ -77,10 +78,6 @@ uint64 extractGuid(WorldPacket& packet)
return guid; return guid;
} }
std::string &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
std::string &rtrim(std::string &s) { std::string &rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());

View File

@ -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) bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
{ {
try try

View File

@ -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. * @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); void utf8truncate(std::string& utf8str, size_t len);
/**
* @brief
*
* @param utf8str
* @param bytes
*/
size_t utf8limit(std::string& utf8str, size_t bytes);
/** /**
* @brief * @brief
* *