feat(Core/Chat): new argument parsing and unify chat hyperlink parsing (#6243)

This commit is contained in:
Kargatum
2021-10-23 15:15:42 +07:00
committed by GitHub
parent 1101f9dd2a
commit bc9473482e
90 changed files with 4280 additions and 2508 deletions

View File

@@ -35,28 +35,22 @@ class WorldSession;
class Player;
/// Storage class for commands issued for delayed execution
struct CliCommandHolder
struct AC_GAME_API CliCommandHolder
{
typedef void Print(void*, const char*);
typedef void CommandFinished(void*, bool success);
using Print = void(*)(void*, std::string_view);
using CommandFinished = void(*)(void*, bool success);
void* m_callbackArg;
char* m_command;
Print* m_print;
Print m_print;
CommandFinished m_commandFinished;
CommandFinished* m_commandFinished;
CliCommandHolder(void* callbackArg, char const* command, Print zprint, CommandFinished commandFinished);
~CliCommandHolder();
CliCommandHolder(void* callbackArg, const char* command, Print* zprint, CommandFinished* commandFinished)
: m_callbackArg(callbackArg), m_print(zprint), m_commandFinished(commandFinished)
{
// TODO: fix Codacy warning
// "Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126)."
size_t len = strlen(command) + 1;
m_command = new char[len];
memcpy(m_command, command, len);
}
~CliCommandHolder() { delete[] m_command; }
private:
CliCommandHolder(CliCommandHolder const& right) = delete;
CliCommandHolder& operator=(CliCommandHolder const& right) = delete;
};
typedef std::unordered_map<uint32, WorldSession*> SessionMap;

View File

@@ -1944,6 +1944,9 @@ void World::SetInitialWorldSettings()
LOG_INFO("server.loading", " ");
sObjectMgr->InitializeSpellInfoPrecomputedData();
LOG_INFO("server.loading", "Initialize commands...");
Acore::ChatCommands::LoadCommandMap();
///- Initialize game time and timers
LOG_INFO("server.loading", "Initialize game time and timers");
LOG_INFO("server.loading", " ");
@@ -2760,7 +2763,7 @@ void World::UpdateSessions(uint32 diff)
// This handles the issued and queued CLI commands
void World::ProcessCliCommands()
{
CliCommandHolder::Print* zprint = nullptr;
CliCommandHolder::Print zprint = nullptr;
void* callbackArg = nullptr;
CliCommandHolder* command = nullptr;
while (cliCmdQueue.next(command))
@@ -3505,3 +3508,13 @@ void World::FinalizePlayerWorldSession(WorldSession* session)
session->SendClientCacheVersion(cacheVersion);
session->SendTutorialsData();
}
CliCommandHolder::CliCommandHolder(void* callbackArg, char const* command, Print zprint, CommandFinished commandFinished)
: m_callbackArg(callbackArg), m_command(strdup(command)), m_print(zprint), m_commandFinished(commandFinished)
{
}
CliCommandHolder::~CliCommandHolder()
{
free(m_command);
}