Merge branch 'master' of github.com:azerothcore/azerothcore-wotlk into Playerbot

This commit is contained in:
Yunfan Li
2023-09-23 22:44:15 +08:00
154 changed files with 7913 additions and 4858 deletions

View File

@@ -1,6 +1,18 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2008+ TrinityCore <http://www.trinitycore.org/>
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _MAPDEFINES_H

View File

@@ -41,13 +41,6 @@
#include <unistd.h>
#endif
#if AC_COMPILER == AC_COMPILER_MICROSOFT
#define atoll _atoi64
#define llabs _abs64
#else
#define stricmp strcasecmp
#endif
#define STRINGIZE(a) #a
#define MAX_NETCLIENT_PACKET_SIZE (32767 - 1) // Client hardcap: int16 with trailing zero space otherwise crash on memory free

View File

@@ -32,6 +32,7 @@ namespace
std::vector<std::string> _additonalFiles;
std::vector<std::string> _args;
std::unordered_map<std::string /*name*/, std::string /*value*/> _configOptions;
std::unordered_map<std::string /*name*/, std::string /*value*/> _envVarCache;
std::mutex _configLock;
// Check system configs like *server.conf*
@@ -39,8 +40,9 @@ namespace
{
size_t foundAuth = fileName.find("authserver.conf");
size_t foundWorld = fileName.find("worldserver.conf");
size_t foundImport = fileName.find("dbimport.conf");
return foundAuth != std::string_view::npos || foundWorld != std::string_view::npos;
return foundAuth != std::string_view::npos || foundWorld != std::string_view::npos || foundImport != std::string_view::npos;
}
// Check logging system configs like Appender.* and Logger.*
@@ -119,7 +121,7 @@ namespace
auto const& itr = fileConfigs.find(confOption);
if (itr != fileConfigs.end())
{
PrintError(file, "> Config::LoadFile: Dublicate key name '{}' in config file '{}'", confOption, file);
PrintError(file, "> Config::LoadFile: Duplicate key name '{}' in config file '{}'", confOption, file);
return true;
}
@@ -282,9 +284,14 @@ namespace
return result;
}
std::string GetEnvVarName(std::string const& configName)
{
return "AC_" + IniKeyToEnvVarKey(configName);
}
Optional<std::string> EnvVarForIniKey(std::string const& key)
{
std::string envKey = "AC_" + IniKeyToEnvVarKey(key);
std::string envKey = GetEnvVarName(key);
char* val = std::getenv(envKey.c_str());
if (!val)
return std::nullopt;
@@ -329,6 +336,29 @@ bool ConfigMgr::Reload()
return true;
}
// Check the _envVarCache if the env var is there
// if not, check the env for the value
Optional<std::string> GetEnvFromCache(std::string const& configName, std::string const& envVarName)
{
auto foundInCache = _envVarCache.find(envVarName);
Optional<std::string> foundInEnv;
// If it's not in the cache
if (foundInCache == _envVarCache.end())
{
// Check the env itself
foundInEnv = EnvVarForIniKey(configName);
if (foundInEnv)
{
// If it's found in the env, put it in the cache
_envVarCache.emplace(envVarName, *foundInEnv);
}
// Return the result of checking env
return foundInEnv;
}
return foundInCache->second;
}
std::vector<std::string> ConfigMgr::OverrideWithEnvVariablesIfAny()
{
std::lock_guard<std::mutex> lock(_configLock);
@@ -356,29 +386,31 @@ template<class T>
T ConfigMgr::GetValueDefault(std::string const& name, T const& def, bool showLogs /*= true*/) const
{
std::string strValue;
auto const& itr = _configOptions.find(name);
if (itr == _configOptions.end())
bool notFound = itr == _configOptions.end();
auto envVarName = GetEnvVarName(name);
Optional<std::string> envVar = GetEnvFromCache(name, envVarName);
if (envVar)
{
Optional<std::string> envVar = EnvVarForIniKey(name);
if (!envVar)
// If showLogs and this key/value pair wasn't found in the currently saved config
if (showLogs && (notFound || itr->second != envVar->c_str()))
{
if (showLogs)
{
LOG_ERROR("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file.",
name, _filename, name, Acore::ToString(def));
}
return def;
}
if (showLogs)
{
LOG_WARN("server.loading", "Missing property {} in config file {}, recovered with environment '{}' value.",
name, _filename, envVar->c_str());
LOG_INFO("server.loading", "> Config: Found config value '{}' from environment variable '{}'.", name, envVarName );
AddKey(name, envVar->c_str(), "ENVIRONMENT", false, false);
}
strValue = *envVar;
}
else if (notFound)
{
if (showLogs)
{
LOG_ERROR("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
name, _filename, name, Acore::ToString(def), envVarName);
}
return def;
}
else
{
strValue = itr->second;
@@ -403,24 +435,26 @@ template<>
std::string ConfigMgr::GetValueDefault<std::string>(std::string const& name, std::string const& def, bool showLogs /*= true*/) const
{
auto const& itr = _configOptions.find(name);
if (itr == _configOptions.end())
bool notFound = itr == _configOptions.end();
auto envVarName = GetEnvVarName(name);
Optional<std::string> envVar = GetEnvFromCache(name, envVarName);
if (envVar)
{
Optional<std::string> envVar = EnvVarForIniKey(name);
if (envVar)
// If showLogs and this key/value pair wasn't found in the currently saved config
if (showLogs && (notFound || itr->second != envVar->c_str()))
{
if (showLogs)
{
LOG_WARN("server.loading", "Missing property {} in config file {}, recovered with environment '{}' value.",
name, _filename, envVar->c_str());
}
return *envVar;
LOG_INFO("server.loading", "> Config: Found config value '{}' from environment variable '{}'.", name, envVarName);
AddKey(name, *envVar, "ENVIRONMENT", false, false);
}
return *envVar;
}
else if (notFound)
{
if (showLogs)
{
LOG_ERROR("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file.",
name, _filename, name, def);
LOG_ERROR("server.loading", "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
name, _filename, name, def, envVarName);
}
return def;

View File

@@ -1,7 +1,19 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
*/
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "GitRevision.h"
#include "revision.h"

View File

@@ -1,7 +1,19 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
* Copyright (C) 2008-2018 TrinityCore <http://www.trinitycore.org/>
*/
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GITREVISION_H__
#define __GITREVISION_H__

View File

@@ -398,6 +398,4 @@ void Log::LoadFromConfig()
ReadAppendersFromConfig();
ReadLoggersFromConfig();
_debugLogMask = DebugLogFilters(sConfigMgr->GetOption<uint32>("DebugLogMask", LOG_FILTER_NONE, false));
}

View File

@@ -121,8 +121,6 @@ private:
Acore::Asio::IoContext* _ioContext;
Acore::Asio::Strand* _strand;
// Deprecated debug filter logs
DebugLogFilters _debugLogMask;
};
#define sLog Log::instance()

View File

@@ -46,6 +46,7 @@ enum AppenderType : uint8
APPENDER_INVALID = 0xFF // SKIP
};
// EnumUtils: DESCRIBE THIS
enum AppenderFlags : uint8
{
APPENDER_FLAGS_NONE = 0x00,
@@ -56,37 +57,4 @@ enum AppenderFlags : uint8
APPENDER_FLAGS_MAKE_FILE_BACKUP = 0x10
};
// Dprecated debug log filters need delte later
enum DebugLogFilters
{
LOG_FILTER_NONE = 0x00000000,
LOG_FILTER_UNITS = 0x00000001, // Anything related to units that doesn't fit in other categories. ie. creature formations
LOG_FILTER_PETS = 0x00000002,
LOG_FILTER_VEHICLES = 0x00000004,
LOG_FILTER_TSCR = 0x00000008, // C++ AI, instance scripts, etc.
LOG_FILTER_DATABASE_AI = 0x00000010, // SmartAI, EventAI, CreatureAI
LOG_FILTER_MAPSCRIPTS = 0x00000020,
LOG_FILTER_NETWORKIO = 0x00000040, // Anything packet/netcode related
LOG_FILTER_SPELLS_AURAS = 0x00000080,
LOG_FILTER_ACHIEVEMENTSYS = 0x00000100,
LOG_FILTER_CONDITIONSYS = 0x00000200,
LOG_FILTER_POOLSYS = 0x00000400,
LOG_FILTER_AUCTIONHOUSE = 0x00000800,
LOG_FILTER_BATTLEGROUND = 0x00001000, // Anything related to arena's and battlegrounds
LOG_FILTER_OUTDOORPVP = 0x00002000,
LOG_FILTER_CHATSYS = 0x00004000,
LOG_FILTER_LFG = 0x00008000,
LOG_FILTER_MAPS = 0x00010000, // Maps, instances, grids, cells, visibility
LOG_FILTER_PLAYER_LOADING = 0x00020000, // Debug output from Player::_Load functions
LOG_FILTER_PLAYER_ITEMS = 0x00040000, // Anything item related
LOG_FILTER_PLAYER_SKILLS = 0x00080000, // Skills related
LOG_FILTER_LOOT = 0x00100000, // Loot related
LOG_FILTER_GUILD = 0x00200000, // Guild related
LOG_FILTER_TRANSPORTS = 0x00400000, // Transport related
LOG_FILTER_WARDEN = 0x00800000, // Warden related
LOG_FILTER_BATTLEFIELD = 0x01000000, // Battlefield related
LOG_FILTER_MODULES = 0x02000000, // Modules debug
LOG_FILTER_CLOSE_SOCKET = 0x04000000, // Whenever KickPlayer() or CloseSocket() are called
};
#endif // LogCommon_h__

View File

@@ -121,4 +121,55 @@ AC_API_EXPORT size_t EnumUtils<AppenderType>::ToIndex(AppenderType value)
default: throw std::out_of_range("value");
}
}
/*****************************************************************\
|* data for enum 'AppenderFlags' in 'LogCommon.h' auto-generated *|
\*****************************************************************/
template <>
AC_API_EXPORT EnumText EnumUtils<AppenderFlags>::ToString(AppenderFlags value)
{
switch (value)
{
case APPENDER_FLAGS_NONE: return { "APPENDER_FLAGS_NONE", "APPENDER_FLAGS_NONE", "" };
case APPENDER_FLAGS_PREFIX_TIMESTAMP: return { "APPENDER_FLAGS_PREFIX_TIMESTAMP", "APPENDER_FLAGS_PREFIX_TIMESTAMP", "" };
case APPENDER_FLAGS_PREFIX_LOGLEVEL: return { "APPENDER_FLAGS_PREFIX_LOGLEVEL", "APPENDER_FLAGS_PREFIX_LOGLEVEL", "" };
case APPENDER_FLAGS_PREFIX_LOGFILTERTYPE: return { "APPENDER_FLAGS_PREFIX_LOGFILTERTYPE", "APPENDER_FLAGS_PREFIX_LOGFILTERTYPE", "" };
case APPENDER_FLAGS_USE_TIMESTAMP: return { "APPENDER_FLAGS_USE_TIMESTAMP", "APPENDER_FLAGS_USE_TIMESTAMP", "" };
case APPENDER_FLAGS_MAKE_FILE_BACKUP: return { "APPENDER_FLAGS_MAKE_FILE_BACKUP", "APPENDER_FLAGS_MAKE_FILE_BACKUP", "" };
default: throw std::out_of_range("value");
}
}
template <>
AC_API_EXPORT size_t EnumUtils<AppenderFlags>::Count() { return 6; }
template <>
AC_API_EXPORT AppenderFlags EnumUtils<AppenderFlags>::FromIndex(size_t index)
{
switch (index)
{
case 0: return APPENDER_FLAGS_NONE;
case 1: return APPENDER_FLAGS_PREFIX_TIMESTAMP;
case 2: return APPENDER_FLAGS_PREFIX_LOGLEVEL;
case 3: return APPENDER_FLAGS_PREFIX_LOGFILTERTYPE;
case 4: return APPENDER_FLAGS_USE_TIMESTAMP;
case 5: return APPENDER_FLAGS_MAKE_FILE_BACKUP;
default: throw std::out_of_range("index");
}
}
template <>
AC_API_EXPORT size_t EnumUtils<AppenderFlags>::ToIndex(AppenderFlags value)
{
switch (value)
{
case APPENDER_FLAGS_NONE: return 0;
case APPENDER_FLAGS_PREFIX_TIMESTAMP: return 1;
case APPENDER_FLAGS_PREFIX_LOGLEVEL: return 2;
case APPENDER_FLAGS_PREFIX_LOGFILTERTYPE: return 3;
case APPENDER_FLAGS_USE_TIMESTAMP: return 4;
case APPENDER_FLAGS_MAKE_FILE_BACKUP: return 5;
default: throw std::out_of_range("value");
}
}
}

View File

@@ -1,6 +1,18 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
* Copyright (C) 2008-2021 TrinityCore <http://www.trinitycore.org/>
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EnumFlag_h__

View File

@@ -15,8 +15,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_SMARTENUM_H
#define TRINITY_SMARTENUM_H
#ifndef AC_SMARTENUM_H
#define AC_SMARTENUM_H
#include "IteratorPair.h"
#include <iterator>
@@ -130,4 +130,4 @@ public:
static char const* ToDescription(Enum value) { return ToString(value).Description; }
};
#endif
#endif // AC_SMART_ENUM_H

View File

@@ -72,8 +72,22 @@ namespace Acore
std::string const& logger, std::string const& input,
bool secure)
{
#if AC_COMPILER == AC_COMPILER_MICROSOFT
#pragma warning(push)
#pragma warning(disable:4297)
/*
Silence warning with boost 1.83
boost/process/pipe.hpp(132,5): warning C4297: 'boost::process::basic_pipebuf<char,std::char_traits<char>>::~basic_pipebuf': function assumed not to throw an exception but does
boost/process/pipe.hpp(132,5): message : destructor or deallocator has a (possibly implicit) non-throwing exception specification
boost/process/pipe.hpp(124,6): message : while compiling class template member function 'boost::process::basic_pipebuf<char,std::char_traits<char>>::~basic_pipebuf(void)'
boost/process/pipe.hpp(304,42): message : see reference to class template instantiation 'boost::process::basic_pipebuf<char,std::char_traits<char>>' being compiled
*/
#endif
ipstream outStream;
ipstream errStream;
#if AC_COMPILER == AC_COMPILER_MICROSOFT
#pragma warning(pop)
#endif
if (!secure)
{

View File

@@ -1,6 +1,18 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2008+ TrinityCore <http://www.trinitycore.org/>
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TaskScheduler.h"

View File

@@ -1,6 +1,18 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2008+ TrinityCore <http://www.trinitycore.org/>
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TASK_SCHEDULER_H_
@@ -432,11 +444,11 @@ public:
: _task(right._task), _owner(right._owner), _consumed(right._consumed) { }
// Move construct
TaskContext(TaskContext&& right)
TaskContext(TaskContext&& right) noexcept
: _task(std::move(right._task)), _owner(std::move(right._owner)), _consumed(std::move(right._consumed)) { }
// Copy assign
TaskContext& operator= (TaskContext const& right)
TaskContext& operator= (TaskContext const& right) noexcept
{
_task = right._task;
_owner = right._owner;
@@ -445,7 +457,7 @@ public:
}
// Move assign
TaskContext& operator= (TaskContext&& right)
TaskContext& operator= (TaskContext&& right) noexcept
{
_task = std::move(right._task);
_owner = std::move(right._owner);