Move realmd packet structures to packets/ subfolder and de-submodule realmd

Co-authored-by: billy1arm <2219118+billy1arm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-05 23:41:49 +00:00
parent fb02e9512f
commit 35f71b8e91
17 changed files with 3635 additions and 4 deletions

3
.gitmodules vendored
View file

@ -1,9 +1,6 @@
[submodule "dep"]
path = dep
url = https://github.com/mangos/mangosDeps
[submodule "src/realmd"]
path = src/realmd
url = https://github.com/mangos/realmd
[submodule "src/modules/SD3"]
path = src/modules/SD3
url = https://github.com/mangos/ScriptDev3.git

@ -1 +0,0 @@
Subproject commit 42614f4eaeb5cbab808acaaf17483b7e89e825c2

109
src/realmd/Auth/AuthCodes.h Normal file
View file

@ -0,0 +1,109 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/** \file
\ingroup realmd
*/
#ifndef MANGOS_H_AUTHCODES
#define MANGOS_H_AUTHCODES
/**
* @brief
*
*/
enum eAuthCmd
{
CMD_AUTH_LOGON_CHALLENGE = 0x00,
CMD_AUTH_LOGON_PROOF = 0x01,
CMD_AUTH_RECONNECT_CHALLENGE = 0x02,
CMD_AUTH_RECONNECT_PROOF = 0x03,
CMD_REALM_LIST = 0x10,
CMD_XFER_INITIATE = 0x30,
CMD_XFER_DATA = 0x31,
// these opcodes no longer exist in currently supported client
CMD_XFER_ACCEPT = 0x32,
CMD_XFER_RESUME = 0x33,
CMD_XFER_CANCEL = 0x34
};
/**
* @brief not used by us currently
*
*/
enum eAuthSrvCmd
{
CMD_GRUNT_AUTH_CHALLENGE = 0x0,
CMD_GRUNT_AUTH_VERIFY = 0x2,
CMD_GRUNT_CONN_PING = 0x10,
CMD_GRUNT_CONN_PONG = 0x11,
CMD_GRUNT_HELLO = 0x20,
CMD_GRUNT_PROVESESSION = 0x21,
CMD_GRUNT_KICK = 0x24,
CMD_GRUNT_PCWARNING = 0x29,
CMD_GRUNT_STRINGS = 0x41,
CMD_GRUNT_SUNKENUPDATE = 0x44,
CMD_GRUNT_SUNKEN_ONLINE = 0x46
};
/**
* @brief
*
*/
enum AuthResult
{
WOW_SUCCESS = 0x00,
WOW_FAIL_UNKNOWN0 = 0x01, ///< ? Unable to connect
WOW_FAIL_UNKNOWN1 = 0x02, ///< ? Unable to connect
WOW_FAIL_BANNED = 0x03, ///< This <game> account has been closed and is no longer available for use. Please go to <site>/banned.html for further information.
WOW_FAIL_UNKNOWN_ACCOUNT = 0x04, ///< The information you have entered is not valid. Please check the spelling of the account name and password. If you need help in retrieving a lost or stolen password, see <site> for more information
WOW_FAIL_INCORRECT_PASSWORD = 0x05, ///< The information you have entered is not valid. Please check the spelling of the account name and password. If you need help in retrieving a lost or stolen password, see <site> for more information
// client reject next login attempts after this error, so in code used WOW_FAIL_UNKNOWN_ACCOUNT for both cases
WOW_FAIL_ALREADY_ONLINE = 0x06, ///< This account is already logged into <game>. Please check the spelling and try again.
WOW_FAIL_NO_TIME = 0x07, ///< You have used up your prepaid time for this account. Please purchase more to continue playing
WOW_FAIL_DB_BUSY = 0x08, ///< Could not log in to <game> at this time. Please try again later.
WOW_FAIL_VERSION_INVALID = 0x09, ///< Unable to validate game version. This may be caused by file corruption or interference of another program. Please visit <site> for more information and possible solutions to this issue.
WOW_FAIL_VERSION_UPDATE = 0x0A, ///< Downloading
WOW_FAIL_INVALID_SERVER = 0x0B, ///< Unable to connect
WOW_FAIL_SUSPENDED = 0x0C, ///< This <game> account has been temporarily suspended. Please go to <site>/banned.html for further information
WOW_FAIL_FAIL_NOACCESS = 0x0D, ///< Unable to connect
WOW_SUCCESS_SURVEY = 0x0E, ///< Connected.
WOW_FAIL_PARENTCONTROL = 0x0F, ///< Access to this account has been blocked by parental controls. Your settings may be changed in your account preferences at <site>
// TBC+
WOW_FAIL_LOCKED_ENFORCED = 0x10, ///< You have applied a lock to your account. You can change your locked status by calling your account lock phone number.
// WOTLK+
WOW_FAIL_TRIAL_ENDED = 0x11, ///< Your trial subscription has expired. Please visit <site> to upgrade your account.
WOW_FAIL_USE_BATTLENET = 0x12, ///< This account is now attached to a Battle.net account. Please login with your Battle.net account email address and password.
WOW_FAIL_ANTI_INDULGENCE = 0x13, ///< Unable to connect
WOW_FAIL_EXPIRED = 0x14, ///< Unable to connect
WOW_FAIL_NO_GAME_ACCOUNT = 0x15, ///< Unable to connect
WOW_FAIL_CHARGEBACK = 0x16, ///< This World of Warcraft account has been temporary closed due to a chargeback on its subscription. Please refer to this <site> for further information.
WOW_FAIL_IGR_WITHOUT_BNET = 0x17, ///< In order to log in to World of Warcraft using IGR time, this World of Warcraft account must first be merged with a Battle.net account. Please visit <site> to merge this account.
WOW_FAIL_GAME_ACCOUNT_LOCKED = 0x18, ///< Access to your account has been temporarily disabled.
WOW_FAIL_UNLOCKABLE_LOCK = 0x19, ///< Your account has been locked but can be unlocked.
WOW_FAIL_CONVERSION_REQUIRED = 0x20, ///< This account needs to be converted to a Battle.net account. Please [Click Here] or go to: <site> to begin conversion.
WOW_FAIL_DISCONNECTED = 0xFF
};
#endif

1142
src/realmd/Auth/AuthSocket.cpp Executable file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,181 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/// \addtogroup realmd
/// @{
/// \file
#ifndef MANGOS_H_AUTHSOCKET
#define MANGOS_H_AUTHSOCKET
#include "Common.h"
#include "Auth/BigNumber.h"
#include "Auth/Sha1.h"
#include "ByteBuffer.h"
#include "Utilities/Util.h"
#include "SocketBuffer/BufferedSocket.h"
class ACE_INET_Addr;
struct Realm;
/**
* @brief Handle login commands
*
*/
class AuthSocket: public BufferedSocket
{
public:
const static int s_BYTE_SIZE = 32; /**< TODO */
/**
* @brief
*
*/
AuthSocket();
/**
* @brief
*
*/
~AuthSocket();
/**
* @brief
*
*/
void OnAccept() override;
/**
* @brief
*
*/
void OnRead() override;
/**
* @brief
*
* @param sha
*/
void SendProof(Sha1Hash sha);
/**
* @brief
*
* @param pkt
* @param acctid
*/
void LoadRealmlist(ByteBuffer& pkt, uint32 acctid);
static ACE_INET_Addr const& GetAddressForClient(Realm const& realm, ACE_INET_Addr const& clientAddr);
/**
* @brief
*
* @return bool
*/
bool _HandleLogonChallenge();
/**
* @brief
*
* @return bool
*/
bool _HandleLogonProof();
/**
* @brief
*
* @return bool
*/
bool _HandleReconnectChallenge();
/**
* @brief
*
* @return bool
*/
bool _HandleReconnectProof();
/**
* @brief
*
* @return bool
*/
bool _HandleRealmList();
/**
* @brief data transfer handle for patch
*
* @return bool
*/
bool _HandleXferResume();
/**
* @brief
*
* @return bool
*/
bool _HandleXferCancel();
/**
* @brief
*
* @return bool
*/
bool _HandleXferAccept();
/**
* @brief
*
* @param rI
*/
void _SetVSFields(const std::string& rI);
private:
enum eStatus
{
STATUS_CHALLENGE,
STATUS_LOGON_PROOF,
STATUS_RECON_PROOF,
STATUS_PATCH,
STATUS_AUTHED,
STATUS_CLOSED
};
BigNumber N, s, g, v; /**< TODO */
BigNumber b, B; /**< TODO */
BigNumber K; /**< TODO */
BigNumber _reconnectProof; /**< TODO */
eStatus _status; /**< TODO */
std::string _login; /**< TODO */
std::string _safelogin; /**< TODO */
std::string _localizationName; /**< Since GetLocaleByName() is _NOT_ bijective, we have to store the locale as a string. Otherwise we can't differ between enUS and enGB, which is important for the patch system */
std::string _os;
uint16 _build; /**< TODO */
AccountTypes _accountSecurityLevel; /**< TODO */
ACE_HANDLE patch_; /**< TODO */
/**
* @brief
*
*/
void InitPatch();
};
#endif
/// @}

104
src/realmd/CMakeLists.txt Normal file
View file

@ -0,0 +1,104 @@
#/**
# * MaNGOS is a full featured server for World of Warcraft, supporting
# * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
# *
# * Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 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 General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# *
# * World of Warcraft, and all World of Warcraft or Warcraft art, images,
# * and lore are copyrighted by Blizzard Entertainment, Inc.
# */
#Auth Files
file(GLOB_RECURSE SRC_GRP_AUTH Auth/*.cpp Auth/*.h)
source_group("Authentication" FILES ${SRC_GRP_AUTH})
#Packet Files
file(GLOB_RECURSE SRC_GRP_PACKETS packets/*.h)
source_group("Packets" FILES ${SRC_GRP_PACKETS})
#Patch Files
file(GLOB_RECURSE SRC_GRP_PATCH Patch/*.cpp Patch/*.h)
source_group("Patch" FILES ${SRC_GRP_PATCH})
#Realm Files
file(GLOB_RECURSE SRC_GRP_REALM Realm/*.cpp Realm/*.h)
source_group("Realmlist" FILES ${SRC_GRP_REALM})
#Socket Buffer Files
file(GLOB_RECURSE SRC_GRP_SOCKB SocketBuffer/*.cpp SocketBuffer/*.h)
source_group("Socket Buffer" FILES ${SRC_GRP_SOCKB})
configure_file(realmd.conf.dist.in ${CMAKE_CURRENT_BINARY_DIR}/realmd.conf.dist)
if(WIN32)
set(PRODUCT_NAME "realmd.exe")
set(PRODUCT_ICON ${CMAKE_CURRENT_SOURCE_DIR}/realmd.ico)
set(PRODUCT_DESCRIPTION "MaNGOS Authentication Daemon")
configure_file(${CMAKE_SOURCE_DIR}/cmake/win/VersionInfo.h.in ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h)
endif()
add_executable(realmd
${SRC_GRP_AUTH}
${SRC_GRP_PACKETS}
${SRC_GRP_PATCH}
${SRC_GRP_REALM}
${SRC_GRP_SOCKB}
Main.cpp
$<$<BOOL:${WIN32}>:
${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h
${CMAKE_SOURCE_DIR}/cmake/win/VersionInfo.rc
>
)
target_compile_features(realmd PUBLIC cxx_std_17)
set_target_properties(realmd PROPERTIES CXX_EXTENSIONS OFF)
target_include_directories(realmd
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h
${OPENSSL_INCLUDE_DIR}
)
target_link_libraries(realmd
PUBLIC
shared
Threads::Threads
${OPENSSL_LIBRARIES}
#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3)
OpenSSL::Crypto
#endif()
)
install(
TARGETS realmd
DESTINATION ${BIN_DIR}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/realmd.conf.dist
DESTINATION ${CONF_INSTALL_DIR}
)
if(WIN32 AND MSVC)
install(
FILES $<TARGET_PDB_FILE:realmd>
DESTINATION ${BIN_DIR}
OPTIONAL
)
endif()

498
src/realmd/Main.cpp Normal file
View file

@ -0,0 +1,498 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,r
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/// \addtogroup realmd Realm Daemon
/// @{
/// \file
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "Realm/RealmList.h"
#include "Config/Config.h"
#include "GitRevision.h"
#include "Log.h"
#include "Auth/AuthSocket.h"
#include "SystemConfig.h"
#include "revision_data.h"
#include "Util.h"
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
# include <openssl/provider.h>
#endif
#include <ace/Get_Opt.h>
#include <ace/Dev_Poll_Reactor.h>
#include <ace/TP_Reactor.h>
#include <ace/ACE.h>
#include <ace/Acceptor.h>
#include <ace/SOCK_Acceptor.h>
#ifdef WIN32
#include "ServiceWin32.h"
char serviceName[] = "realmd";
char serviceLongName[] = "MaNGOS realmd service";
char serviceDescription[] = "Massive Network Game Object Server";
/*
* -1 - not in service mode
* 0 - stopped
* 1 - running
* 2 - paused
*/
int m_ServiceStatus = -1;
#else
#include "PosixDaemon.h"
#endif
bool StartDB();
void UnhookSignals();
void HookSignals();
bool stopEvent = false; ///< Setting it to true stops the server
DatabaseType LoginDatabase; ///< Accessor to the realm server database
/// Print out the usage string for this program on the console.
void usage(const char* prog)
{
sLog.outString("Usage: \n %s [<options>]\n"
" -v, --version print version and exist\n\r"
" -c config_file use config_file as configuration file\n\r"
#ifdef WIN32
" Running as service functions:\n\r"
" -s run run as service\n\r"
" -s install install service\n\r"
" -s uninstall uninstall service\n\r"
#else
" Running as daemon functions:\n\r"
" -s run run as daemon\n\r"
" -s stop stop daemon\n\r"
#endif
, prog);
}
/// Launch the realm server
extern int main(int argc, char** argv)
{
///- Command line parsing
char const* cfg_file = REALMD_CONFIG_LOCATION;
char const* options = ":c:s:";
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option("version", 'v');
char serviceDaemonMode = '\0';
int option;
while ((option = cmd_opts()) != EOF)
{
switch (option)
{
case 'c':
cfg_file = cmd_opts.opt_arg();
break;
case 'v':
printf("%s\n", GitRevision::GetProjectRevision());
return 0;
case 's':
{
const char* mode = cmd_opts.opt_arg();
if (!strcmp(mode, "run"))
{
serviceDaemonMode = 'r';
}
#ifdef WIN32
else if (!strcmp(mode, "install"))
{
serviceDaemonMode = 'i';
}
else if (!strcmp(mode, "uninstall"))
{
serviceDaemonMode = 'u';
}
#else
else if (!strcmp(mode, "stop"))
{
serviceDaemonMode = 's';
}
#endif
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
break;
}
case ':':
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
default:
sLog.outError("Runtime-Error: bad format of commandline arguments");
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
}
#ifdef WIN32 // windows service command need execute before config read
switch (serviceDaemonMode)
{
case 'i':
if (WinServiceInstall())
{
sLog.outString("Installing service");
}
return 1;
case 'u':
if (WinServiceUninstall())
{
sLog.outString("Uninstalling service");
}
return 1;
case 'r':
WinServiceRun();
break;
}
#endif
if (!sConfig.SetSource(cfg_file))
{
// Try current folder as fallback if SYSCONFDIR path fails
if (!sConfig.SetSource(REALMD_CONFIG_NAME))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
Log::WaitBeforeContinueIfNeed();
return 1;
}
cfg_file = REALMD_CONFIG_NAME;
}
#ifndef WIN32 // posix daemon commands need apply after config read
switch (serviceDaemonMode)
{
case 'r':
startDaemon();
break;
case 's':
stopDaemon();
break;
}
#endif
sLog.Initialize();
sLog.outString("%s [realm-daemon]", GitRevision::GetProjectRevision());
sLog.outString("%s", GitRevision::GetFullRevision());
sLog.outString("<Ctrl-C> to stop.\n");
sLog.outString("Using configuration file %s.", cfg_file);
///- Check the version of the configuration file
uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0);
if (confVersion < REALMD_CONFIG_VERSION)
{
sLog.outError("*****************************************************************************");
sLog.outError(" WARNING: Your realmd.conf version indicates your conf file is out of date!");
sLog.outError(" Please check for updates, as your current default values may cause");
sLog.outError(" strange behavior.");
sLog.outError("*****************************************************************************");
Log::WaitBeforeContinueIfNeed();
}
DETAIL_LOG("Using SSL version: %s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
#if defined(OPENSSL_VERSION_MAJOR) && (OPENSSL_VERSION_MAJOR >= 3)
OSSL_PROVIDER* legacy;
OSSL_PROVIDER* deflt;
/* Load Multiple providers into the default (NULL) library context */
legacy = OSSL_PROVIDER_load(NULL, "legacy");
if (legacy == NULL)
{
sLog.outError("Failed to load OpenSSL 3.x Legacy provider\n");
#ifdef WIN32
sLog.outError("\nPlease check you have set the following Enviroment Varible:\n");
sLog.outError("OPENSSL_MODULES=C:\\OpenSSL-Win64\\bin\n");
sLog.outError("(where C:\\OpenSSL-Win64\\bin is the location you installed OpenSSL\n");
#endif
Log::WaitBeforeContinueIfNeed();
return 0;
}
deflt = OSSL_PROVIDER_load(NULL, "default");
if (deflt == NULL)
{
sLog.outError("Failed to load OpenSSL 3.x Default provider\n");
OSSL_PROVIDER_unload(legacy);
Log::WaitBeforeContinueIfNeed();
return 0;
}
#else
if (SSLeay() < 0x10100000L || SSLeay() > 0x10200000L)
{
DETAIL_LOG("WARNING: OpenSSL version may be out of date or unsupported. Logins to server may not work!");
DETAIL_LOG("WARNING: Minimal required version [OpenSSL 1.1.x] and Maximum supported version [OpenSSL 1.2]");
}
#endif
DETAIL_LOG("Using ACE: %s", ACE_VERSION);
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
#else
ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true);
#endif
sLog.outBasic("Max allowed open files is %d", ACE::max_handles());
/// realmd PID file creation
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
if (!pidfile.empty())
{
uint32 pid = CreatePIDFile(pidfile);
if (!pid)
{
sLog.outError("Can not create PID file %s.\n", pidfile.c_str());
Log::WaitBeforeContinueIfNeed();
return 1;
}
sLog.outString("Daemon PID: %u\n", pid);
}
///- Initialize the database connection
if (!StartDB())
{
Log::WaitBeforeContinueIfNeed();
return 1;
}
///- Get the list of realms for the server
sRealmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20));
if (sRealmList.size() == 0)
{
sLog.outError("No valid realms specified.");
Log::WaitBeforeContinueIfNeed();
return 1;
}
// cleanup query
// set expired bans to inactive
LoginDatabase.BeginTransaction();
LoginDatabase.Execute("UPDATE `account_banned` SET `active` = 0 WHERE `unbandate`<=UNIX_TIMESTAMP() AND `unbandate`<>`bandate`");
LoginDatabase.Execute("DELETE FROM `ip_banned` WHERE `unbandate`<=UNIX_TIMESTAMP() AND `unbandate`<>`bandate`");
LoginDatabase.CommitTransaction();
///- Launch the listening network socket
ACE_Acceptor<AuthSocket, ACE_SOCK_Acceptor> acceptor;
uint16 rmport = sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT);
std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0");
ACE_INET_Addr bind_addr(rmport, bind_ip.c_str());
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
sLog.outError("MaNGOS realmd can not bind to %s:%d", bind_ip.c_str(), rmport);
Log::WaitBeforeContinueIfNeed();
return 1;
}
///- Catch termination signals
HookSignals();
///- Handle affinity for multiple processors and process priority on Windows
#ifdef WIN32
{
HANDLE hProcess = GetCurrentProcess();
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
if (Aff > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
if (!curAff)
{
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x", Aff, appAff);
}
else
{
if (SetProcessAffinityMask(hProcess, curAff))
{
sLog.outString("Using processors (bitmask, hex): %x", curAff);
}
else
{
sLog.outError("Can't set used processors (hex): %x", curAff);
}
}
}
sLog.outString();
}
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
if (Prio)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
{
sLog.outString("realmd process priority class set to HIGH");
}
else
{
sLog.outError("Can't set realmd process priority class.");
}
sLog.outString();
}
}
#endif
// server has started up successfully => enable async DB requests
LoginDatabase.AllowAsyncTransactions();
// maximum counter for next ping
uint32 numLoops = (sConfig.GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
#ifndef WIN32
detachDaemon();
#endif
///- Wait for termination signal
while (!stopEvent)
{
// dont move this outside the loop, the reactor will modify it
ACE_Time_Value interval(0, 100000);
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
{
break;
}
if ((++loopCounter) == numLoops)
{
loopCounter = 0;
DETAIL_LOG("Ping MySQL to keep connection alive");
LoginDatabase.Ping();
}
#ifdef WIN32
if (m_ServiceStatus == 0)
{
stopEvent = true;
}
while (m_ServiceStatus == 2) { Sleep(1000); }
#endif
}
///- Wait for the delay thread to exit
LoginDatabase.HaltDelayThread();
///- Remove signal handling before leaving
UnhookSignals();
sLog.outString("Halting process...");
return 0;
}
/// Handle termination signals
/** Put the global variable stopEvent to 'true' if a termination signal is caught **/
void OnSignal(int s)
{
switch (s)
{
case SIGINT:
case SIGTERM:
stopEvent = true;
break;
#ifdef _WIN32
case SIGBREAK:
stopEvent = true;
break;
#endif
}
signal(s, OnSignal);
}
/// Initialize connection to the database
bool StartDB()
{
std::string dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
if (dbstring.empty())
{
sLog.outError("Database not specified");
return false;
}
sLog.outString("Login Database total connections: %i", 1 + 1);
if (!LoginDatabase.Initialize(dbstring.c_str()))
{
sLog.outError("Can not connect to database");
return false;
}
if (!LoginDatabase.CheckDatabaseVersion(DATABASE_REALMD))
{
///- Wait for already started DB delay threads to end
LoginDatabase.HaltDelayThread();
return false;
}
return true;
}
/// Define hook 'OnSignal' for all termination signals
void HookSignals()
{
signal(SIGINT, OnSignal);
signal(SIGTERM, OnSignal);
#ifdef _WIN32
signal(SIGBREAK, OnSignal);
#endif
}
/// Unhook the signals before leaving
void UnhookSignals()
{
signal(SIGINT, 0);
signal(SIGTERM, 0);
#ifdef _WIN32
signal(SIGBREAK, 0);
#endif
}
/// @}

View file

@ -0,0 +1,217 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/** \file
\ingroup realmd
*/
#include "Common.h"
#include "PatchHandler.h"
#include "Auth/AuthCodes.h"
#include "Log.h"
#include "packets/AuthPackets.h"
#include <ace/OS_NS_sys_socket.h>
#include <ace/OS_NS_dirent.h>
#include <ace/OS_NS_errno.h>
#include <ace/OS_NS_unistd.h>
#include <ace/os_include/netinet/os_tcp.h>
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
PatchHandler::PatchHandler(ACE_HANDLE socket, ACE_HANDLE patch)
{
reactor(NULL);
set_handle(socket);
patch_fd_ = patch;
}
PatchHandler::~PatchHandler()
{
if (patch_fd_ != ACE_INVALID_HANDLE)
{
ACE_OS::close(patch_fd_);
}
}
int PatchHandler::open(void*)
{
if (get_handle() == ACE_INVALID_HANDLE || patch_fd_ == ACE_INVALID_HANDLE)
{
return -1;
}
int nodelay = 0;
if (-1 == peer().set_option(ACE_IPPROTO_TCP,
TCP_NODELAY,
&nodelay,
sizeof(nodelay)))
{
return -1;
}
#if defined(TCP_CORK)
int cork = 1;
if (-1 == peer().set_option(ACE_IPPROTO_TCP,
TCP_CORK,
&cork,
sizeof(cork)))
{
return -1;
}
#endif // TCP_CORK
(void) peer().disable(ACE_NONBLOCK);
return activate(THR_NEW_LWP | THR_DETACHED | THR_INHERIT_SCHED);
}
int PatchHandler::svc(void)
{
// Do 1 second sleep, similar to the one in game/WorldSocket.cpp
// Seems client have problems with too fast sends.
ACE_OS::sleep(1);
int flags = MSG_NOSIGNAL;
Chunk data;
data.cmd = CMD_XFER_DATA;
ssize_t r;
while ((r = ACE_OS::read(patch_fd_, data.data, sizeof(data.data))) > 0)
{
data.data_size = (ACE_UINT16)r;
if (peer().send((const char*)&data,
((size_t) r) + sizeof(data) - sizeof(data.data),
flags) == -1)
{
return -1;
}
}
if (r == -1)
{
return -1;
}
return 0;
}
PatchCache::~PatchCache()
{
for (Patches::iterator i = patches_.begin(); i != patches_.end(); ++i)
{
delete i->second;
}
}
PatchCache::PatchCache()
{
LoadPatchesInfo();
}
PatchCache* PatchCache::instance()
{
return ACE_Singleton<PatchCache, ACE_Thread_Mutex>::instance();
}
void PatchCache::LoadPatchMD5(const char* szFileName)
{
// Try to open the patch file
std::string path = "./patches/";
path += szFileName;
FILE* pPatch = fopen(path.c_str(), "rb");
sLog.outDebug("Loading patch info from %s", path.c_str());
if (!pPatch)
{
return;
}
// Calculate the MD5 hash
MD5_CTX ctx;
MD5_Init(&ctx);
const size_t check_chunk_size = 4 * 1024;
ACE_UINT8 buf[check_chunk_size];
while (!feof(pPatch))
{
size_t read = fread(buf, 1, check_chunk_size, pPatch);
MD5_Update(&ctx, buf, read);
}
fclose(pPatch);
// Store the result in the internal patch hash map
patches_[path] = new PATCH_INFO;
MD5_Final((ACE_UINT8*) & patches_[path]->md5, &ctx);
}
bool PatchCache::GetHash(const char* pat, ACE_UINT8 mymd5[MD5_DIGEST_LENGTH])
{
for (Patches::iterator i = patches_.begin(); i != patches_.end(); ++i)
if (!stricmp(pat, i->first.c_str()))
{
memcpy(mymd5, i->second->md5, MD5_DIGEST_LENGTH);
return true;
}
return false;
}
void PatchCache::LoadPatchesInfo()
{
ACE_DIR* dirp = ACE_OS::opendir(ACE_TEXT("./patches/"));
if (!dirp)
{
return;
}
ACE_DIRENT* dp;
while ((dp = ACE_OS::readdir(dirp)) != NULL)
{
int l = strlen(dp->d_name);
if (l < 8)
{
continue;
}
if (!memcmp(&dp->d_name[l - 4], ".mpq", 4))
{
LoadPatchMD5(dp->d_name);
}
}
ACE_OS::closedir(dirp);
}

View file

@ -0,0 +1,164 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/** \file
\ingroup realmd
*/
#ifndef MANGOS_H_PATCHHANDLER
#define MANGOS_H_PATCHHANDLER
#include <ace/Basic_Types.h>
#include <ace/Synch_Traits.h>
#include <ace/Svc_Handler.h>
#include <ace/SOCK_Stream.h>
#include <ace/Message_Block.h>
#include <ace/Auto_Ptr.h>
#include <map>
#include <openssl/bn.h>
#include <openssl/md5.h>
/**
* @brief Caches MD5 hash of client patches present on the server
*
*/
class PatchCache
{
public:
/**
* @brief
*
*/
~PatchCache();
/**
* @brief
*
*/
PatchCache();
/**
* @brief
*
* @return PatchCache
*/
static PatchCache* instance();
/**
* @brief
*
*/
struct PATCH_INFO
{
ACE_UINT8 md5[MD5_DIGEST_LENGTH]; /**< TODO */
};
/**
* @brief
*
*/
typedef std::map<std::string, PATCH_INFO*> Patches;
/**
* @brief
*
* @return Patches::const_iterator
*/
Patches::const_iterator begin() const
{
return patches_.begin();
}
/**
* @brief
*
* @return Patches::const_iterator
*/
Patches::const_iterator end() const
{
return patches_.end();
}
/**
* @brief
*
* @param
*/
void LoadPatchMD5(const char*);
/**
* @brief
*
* @param pat
* @param mymd5[]
* @return bool
*/
bool GetHash(const char* pat, ACE_UINT8 mymd5[MD5_DIGEST_LENGTH]);
private:
/**
* @brief
*
*/
void LoadPatchesInfo();
Patches patches_; /**< TODO */
};
/**
* @brief
*
*/
class PatchHandler: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
protected:
/**
* @brief
*
*/
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
public:
/**
* @brief
*
* @param socket
* @param patch
*/
PatchHandler(ACE_HANDLE socket, ACE_HANDLE patch);
/**
* @brief
*
*/
virtual ~PatchHandler();
int open(void* = 0) override;
protected:
int svc(void) override;
private:
ACE_HANDLE patch_fd_; /**< TODO */
};
#endif /* _BK_PATCHHANDLER_H__ */

4
src/realmd/README.md Normal file
View file

@ -0,0 +1,4 @@
Mangos Realmd
======
Central repository for Realmd for all cores.

View file

@ -0,0 +1,288 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/** \file
\ingroup realmd
*/
#include "Common.h"
#include "RealmList.h"
#include "Auth/AuthCodes.h"
#include "Util.h" // for Tokens typedef
#include "Policies/Singleton.h"
#include "Database/DatabaseEnv.h"
INSTANTIATE_SINGLETON_1(RealmList);
extern DatabaseType LoginDatabase;
// will only support WoW 1.12.1/1.12.2/1.12.3, WoW:TBC 2.4.3, WoW:WotLK 3.3.5a and official release for WoW:Cataclysm and later, client builds 15595, 10505, 8606, 6005, 5875
// if you need more from old build then add it in cases in realmd sources code
// list sorted from high to low build and first build used as low bound for accepted by default range (any > it will accepted by realmd at least)
static const RealmBuildInfo ExpectedRealmdClientBuilds[] =
{
// highest supported build, also auto accept all above for simplify future supported builds testing
{40000, 9, 0, 0, ' '}, // SHADOWLANDS
{35662, 8, 3, 7, ' '}, // BFA
{26972, 7, 3, 5, ' '}, // Legion
{21742, 6, 2, 4, ' '}, // WOD
{18414, 5, 4, 8, ' '}, // MOP
{18273, 5, 4, 8, ' '}, // MOP
{15595, 4, 3, 4, ' '}, // CATA
{12340, 3, 3, 5, 'a'}, // WOTLK
{8606, 2, 4, 3, ' '}, // TBC
{6141, 1, 12, 3, ' '}, // Vanilla - Chinese
{6005, 1, 12, 2, ' '}, // Vanilla - Spanish
{5875, 1, 12, 1, ' '}, // Vanilla
{0, 0, 0, 0, ' '} // terminator
};
RealmBuildInfo const* FindBuildInfo(uint16 _build)
{
// first build is low bound of always accepted range
if (_build >= ExpectedRealmdClientBuilds[0].build)
{
return &ExpectedRealmdClientBuilds[0];
}
// continue from 1 with explicit equal check
for (int i = 1; ExpectedRealmdClientBuilds[i].build; ++i)
if (_build == ExpectedRealmdClientBuilds[i].build)
{
return &ExpectedRealmdClientBuilds[i];
}
// none appropriate build
return NULL;
}
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
{
}
RealmList& sRealmList
{
static RealmList realmlist;
return realmlist;
}
RealmVersion RealmList::BelongsToVersion(uint32 build) const
{
RealmBuildVersionMap::const_iterator it;
if ((it = m_buildToVersion.find(build)) != m_buildToVersion.end())
{
return it->second;
}
else
{
return REALM_VERSION_VANILLA;
}
}
RealmList::RealmListIterators RealmList::GetIteratorsForBuild(uint32 build) const
{
RealmVersion version = BelongsToVersion(build);
if (version >= REALM_VERSION_COUNT)
{
return RealmListIterators(
m_realmsByVersion[0].end(),
m_realmsByVersion[0].end()
);
}
return RealmListIterators(
m_realmsByVersion[uint32(version)].begin(),
m_realmsByVersion[uint32(version)].end()
);
}
/// Load the realm list from the database
void RealmList::Initialize(uint32 updateInterval)
{
m_UpdateInterval = updateInterval;
InitBuildToVersion();
///- Get the content of the realmlist table in the database
UpdateRealms(true);
}
uint32 RealmList::NumRealmsForBuild(uint32 build) const
{
return m_realmsByVersion[BelongsToVersion(build)].size();
}
void RealmList::AddRealmToBuildList(const Realm& realm)
{
RealmBuilds builds = realm.realmbuilds;
int buildNumber = *(builds.begin());
m_realmsByVersion[BelongsToVersion(buildNumber)].push_back(&realm);
}
void RealmList::InitBuildToVersion()
{
m_buildToVersion[5875] = REALM_VERSION_VANILLA;
m_buildToVersion[6005] = REALM_VERSION_VANILLA;
m_buildToVersion[6141] = REALM_VERSION_VANILLA;
m_buildToVersion[8606] = REALM_VERSION_TBC;
m_buildToVersion[12340] = REALM_VERSION_WOTLK;
m_buildToVersion[15595] = REALM_VERSION_CATA;
m_buildToVersion[18273] = REALM_VERSION_MOP;
m_buildToVersion[18414] = REALM_VERSION_MOP;
m_buildToVersion[21742] = REALM_VERSION_WOD;
m_buildToVersion[26972] = REALM_VERSION_LEGION;
m_buildToVersion[35662] = REALM_VERSION_BFA;
m_buildToVersion[40000] = REALM_VERSION_SHADOWLANDS;
}
void RealmList::UpdateRealm(uint32 ID, const std::string& name, ACE_INET_Addr const& address, ACE_INET_Addr const& localAddr, ACE_INET_Addr const& localSubmask, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const std::string& builds)
{
///- Create new if not exist or update existed
Realm& realm = m_realms[name];
realm.m_ID = ID;
realm.name = name;
realm.icon = icon;
realm.realmflags = realmflags;
realm.timezone = timezone;
realm.allowedSecurityLevel = allowedSecurityLevel;
realm.populationLevel = popu;
Tokens tokens = StrSplit(builds, " ");
Tokens::iterator iter;
for (iter = tokens.begin(); iter != tokens.end(); ++iter)
{
uint32 build = atol((*iter).c_str());
realm.realmbuilds.insert(build);
}
uint16 first_build = !realm.realmbuilds.empty() ? *realm.realmbuilds.begin() : 0;
if (first_build)
{
AddRealmToBuildList(realm);
}
else
{
sLog.outError("You don't seem to have added any allowed realmbuilds to the realm: %s"
" and therefore it will not be listed to anyone", name.c_str());
}
realm.realmBuildInfo.build = first_build;
realm.realmBuildInfo.major_version = 0;
realm.realmBuildInfo.minor_version = 0;
realm.realmBuildInfo.bugfix_version = 0;
realm.realmBuildInfo.hotfix_version = ' ';
if (first_build)
if (RealmBuildInfo const* bInfo = FindBuildInfo(first_build))
if (bInfo->build == first_build)
{
realm.realmBuildInfo = *bInfo;
}
///- Append port to IP address.
realm.ExternalAddress = address;
realm.LocalAddress = localAddr;
realm.LocalSubnetMask = localSubmask;
}
void RealmList::UpdateIfNeed()
{
// maybe disabled or updated recently
if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
{
return;
}
m_NextUpdateTime = time(NULL) + m_UpdateInterval;
// Clears Realm list
m_realms.clear();
for (int i = 0; i < REALM_VERSION_COUNT; ++i)
{
m_realmsByVersion[i].clear();
}
// Get the content of the realmlist table in the database
UpdateRealms(false);
}
void RealmList::UpdateRealms(bool init)
{
DETAIL_LOG("Updating Realm List...");
//// 0 1 2 3 4 5 6 7 8 9 10 11
QueryResult* result = LoginDatabase.Query("SELECT `id`, `name`, `address`, `localAddress`, `localSubnetMask`, `port`, `icon`, `realmflags`, `timezone`, `allowedSecurityLevel`, `population`, `realmbuilds` FROM `realmlist` WHERE (`realmflags` & 1) = 0 ORDER BY `name`");
///- Circle through results and add them to the realm map
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 Id = fields[0].GetUInt32();
std::string name = fields[1].GetString();
std::string externalAddress = fields[2].GetString();
std::string localAddress = fields[3].GetString();
std::string localSubmask = fields[4].GetString();
uint32 port = fields[5].GetUInt32();
uint8 icon = fields[6].GetUInt8();
uint8 realmflags = fields[7].GetUInt8();
uint8 timezone = fields[8].GetUInt8();
uint8 allowedSecurityLevel = fields[9].GetUInt8();
float population = fields[10].GetFloat();
std::string realmbuilds = fields[11].GetString();
ACE_INET_Addr externalAddr(port, externalAddress.c_str(), AF_INET);
ACE_INET_Addr localAddr(port, localAddress.c_str(), AF_INET);
ACE_INET_Addr submask(0, localSubmask.c_str(), AF_INET);
if (realmflags & ~(REALM_FLAG_OFFLINE | REALM_FLAG_NEW_PLAYERS | REALM_FLAG_RECOMMENDED | REALM_FLAG_SPECIFYBUILD))
{
sLog.outError("Realm (id %u, name '%s') can only be flagged as OFFLINE (mask 0x02), NEWPLAYERS (mask 0x20), RECOMMENDED (mask 0x40), or SPECIFICBUILD (mask 0x04) in DB", Id, name.c_str());
realmflags &= (REALM_FLAG_OFFLINE | REALM_FLAG_NEW_PLAYERS | REALM_FLAG_RECOMMENDED | REALM_FLAG_SPECIFYBUILD);
}
UpdateRealm(Id, name, externalAddr, localAddr, submask, port, icon, RealmFlags(realmflags), timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), population, realmbuilds);
if (init)
{
sLog.outString("Added realm id %u, name '%s'", Id, name.c_str());
}
}
while (result->NextRow());
delete result;
}
}

View file

@ -0,0 +1,207 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/// \addtogroup realmd
/// @{
/// \file
#ifndef MANGOS_H_REALMLIST
#define MANGOS_H_REALMLIST
#include <ace/Singleton.h>
#include <ace/Null_Mutex.h>
#include <ace/INET_Addr.h>
#include "Common.h"
/**
* @brief
*
*/
struct RealmBuildInfo
{
int build; /**< TODO */
int major_version; /**< TODO */
int minor_version; /**< TODO */
int bugfix_version; /**< TODO */
int hotfix_version; /**< TODO */
};
enum RealmVersion
{
REALM_VERSION_VANILLA = 0,
REALM_VERSION_TBC = 1,
REALM_VERSION_WOTLK = 2,
REALM_VERSION_CATA = 3,
REALM_VERSION_MOP = 4,
REALM_VERSION_WOD = 5,
REALM_VERSION_LEGION = 6,
REALM_VERSION_BFA = 7,
REALM_VERSION_SHADOWLANDS = 8,
REALM_VERSION_COUNT = 9
};
/**
* This is used to make a link between build number and actual wow version that
* it belongs to. To get the connection between them, ie turn a build into a version
* one would use \ref RealmList::BelongsToVersion the other way around is not available
* as it does not make sense and isn't needed.
*/
RealmBuildInfo const* FindBuildInfo(uint16 _build);
/**
* @brief
*
*/
typedef std::set<uint32> RealmBuilds;
/// Storage object for a realm
/**
* @brief
*
*/
struct Realm
{
std::string name;
ACE_INET_Addr ExternalAddress;
ACE_INET_Addr LocalAddress;
ACE_INET_Addr LocalSubnetMask;
uint8 icon;
RealmFlags realmflags; // realmflags
uint8 timezone;
uint32 m_ID;
AccountTypes allowedSecurityLevel; // current allowed join security level (show as locked for not fit accounts)
float populationLevel;
RealmBuilds realmbuilds; // list of supported builds (updated in DB by mangosd)
RealmBuildInfo realmBuildInfo; // build info for show version in list
};
/**
* @brief Storage object for the list of realms on the server
*
*/
class RealmList
{
public:
/**
* @brief
*
*/
typedef std::map<std::string, Realm> RealmMap;
typedef std::list<const Realm*> RealmStlList;
typedef std::pair<RealmStlList::const_iterator, RealmStlList::const_iterator> RealmListIterators;
typedef std::map<uint32, RealmVersion> RealmBuildVersionMap;
static RealmList& Instance();
RealmList();
~RealmList() {};
void Initialize(uint32 updateInterval);
/**
* Initializes a map holding a link from build number to a version.
* \see RealmVersion
*/
void InitVersionToBuild();
void UpdateIfNeed();
/**
* Get's the iterators for all realms supporting the given version as a pair,
* the first member is a iterator to the begin() and the second is an iterator
* to the end().
* @param build the build number to fetch the iterators for
* @return iterators to the begin() and end() part of the realms supporting
* the given build, if there is no matching build iterators are given to end()
* and end() of a list.
*/
RealmListIterators GetIteratorsForBuild(uint32 build) const;
/**
* Returns how many realms we have available for the current build
* @param build the build we want to know number of available realms for
* @return the number of available realms
*/
uint32 NumRealmsForBuild(uint32 build) const;
/**
* @return the total number of realms available
* \see RealmList::NumRealmsForBuild
*/
uint32 size() const { return m_realms.size(); };
private:
/**
* Checks what version (ie, vanilla, tbc) a certain build number belongs to
* @param build the build you want to check the version for
* @return the corresponding version to the given build number
*/
RealmVersion BelongsToVersion(uint32 build) const;
/**
* Adds entries to a map containing a link from a build number to a certain
* wow version, ie: \ref RealmVersion::REALM_VERSION_VANILLA.
* \see RealmVersion
*/
void InitBuildToVersion();
/**
* Adds the given \ref Realm to a list sorted by version, ie: vanilla, tbc etc. This
* in turn is used to only present the compatible realms to the clients connecting,
* ie: vanilla clients will only see vanilla realms.
*
* This is controlled by what you set in the allowedbuilds field in the realm.realmlist
* database, if you set more than one build the first one found in there will be
* used, so if you tag a realm as this: "8606 6141" only TBC clients will be able to
* see the realm and connect to it.
* @param realm the realm you want to add to the sorted list, should be done for all realms
* \see RealmVersion
*/
void AddRealmToBuildList(const Realm& realm);
void UpdateRealms(bool init);
/**
* @brief
*
* @param ID
* @param name
* @param address
* @param port
* @param icon
* @param realmflags
* @param timezone
* @param allowedSecurityLevel
* @param popu
* @param builds
*/
void UpdateRealm(uint32 ID, const std::string& name, ACE_INET_Addr const& address, ACE_INET_Addr const& localAddress, ACE_INET_Addr const& localSubnetmask, uint32 port, uint8 icon, RealmFlags realmflags, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, const std::string& builds);
private:
RealmMap m_realms; ///< Internal map of realms
RealmStlList m_realmsByVersion[REALM_VERSION_COUNT]; ///< This sorts the realms by their supported build
RealmBuildVersionMap m_buildToVersion;
uint32 m_UpdateInterval;
time_t m_NextUpdateTime;
};
#define sRealmList RealmList::Instance()
#endif
/// @}

View file

@ -0,0 +1,298 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/** \file
\ingroup realmd
*/
#include "Common.h"
#include "BufferedSocket.h"
#include <ace/OS_NS_string.h>
#include <ace/INET_Addr.h>
#include <ace/SString.h>
#ifndef MSG_NOSIGNAL
#define MSG_NOSIGNAL 0
#endif
BufferedSocket::BufferedSocket(void):
input_buffer_(4096),
remote_address_("<unknown>")
{
}
/*virtual*/ BufferedSocket::~BufferedSocket(void)
{
}
/*virtual*/ int BufferedSocket::open(void* arg)
{
if (Base::open(arg) == -1)
{
return -1;
}
ACE_INET_Addr addr;
if (peer().get_remote_addr(addr) == -1)
{
return -1;
}
char address[1024];
addr.get_host_addr(address, 1024);
this->remote_address_ = address;
this->OnAccept();
return 0;
}
const std::string& BufferedSocket::get_remote_address(void) const
{
return this->remote_address_;
}
size_t BufferedSocket::recv_len(void) const
{
return this->input_buffer_.length();
}
bool BufferedSocket::recv_soft(char* buf, size_t len)
{
if (this->input_buffer_.length() < len)
{
return false;
}
ACE_OS::memcpy(buf, this->input_buffer_.rd_ptr(), len);
return true;
}
bool BufferedSocket::recv(char* buf, size_t len)
{
bool ret = this->recv_soft(buf, len);
if (ret)
{
this->recv_skip(len);
}
return ret;
}
void BufferedSocket::recv_skip(size_t len)
{
this->input_buffer_.rd_ptr(len);
}
ssize_t BufferedSocket::noblk_send(ACE_Message_Block& message_block)
{
const size_t len = message_block.length();
if (len == 0)
{
return -1;
}
// Try to send the message directly.
ssize_t n = this->peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);
if (n < 0)
{
if (errno == EWOULDBLOCK)
// Blocking signal
{
return 0;
}
else
// Error
{
return -1;
}
}
else if (n == 0)
{
// Can this happen ?
return -1;
}
// return bytes transmitted
return n;
}
bool BufferedSocket::send(const char* buf, size_t len)
{
if (buf == NULL || len == 0)
{
return true;
}
ACE_Data_Block db(
len,
ACE_Message_Block::MB_DATA,
(const char*)buf,
0,
0,
ACE_Message_Block::DONT_DELETE,
0);
ACE_Message_Block message_block(
&db,
ACE_Message_Block::DONT_DELETE,
0);
message_block.wr_ptr(len);
if (this->msg_queue()->is_empty())
{
// Try to send it directly.
ssize_t n = this->noblk_send(message_block);
if (n < 0)
{
return false;
}
else if (n == len)
{
return true;
}
// adjust how much bytes we sent
message_block.rd_ptr((size_t)n);
// fall down
}
// enqueue the message, note: clone is needed cause we cant enqueue stuff on the stack
ACE_Message_Block* mb = message_block.clone();
if (this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
mb->release();
return false;
}
// tell reactor to call handle_output() when we can send more data
if (this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
{
return false;
}
return true;
}
/*virtual*/ int BufferedSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
{
ACE_Message_Block* mb = 0;
if (this->msg_queue()->is_empty())
{
// if no more data to send, then cancel notification
this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
return 0;
}
if (this->msg_queue()->dequeue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
return -1;
}
ssize_t n = this->noblk_send(*mb);
if (n < 0)
{
mb->release();
return -1;
}
else if (n == mb->length())
{
mb->release();
return 1;
}
else
{
mb->rd_ptr(n);
if (this->msg_queue()->enqueue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
mb->release();
return -1;
}
return 0;
}
ACE_NOTREACHED(return -1);
}
/*virtual*/ int BufferedSocket::handle_input(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
{
const ssize_t space = this->input_buffer_.space();
ssize_t n = this->peer().recv(this->input_buffer_.wr_ptr(), space);
if (n < 0)
{
// blocking signal or error
return errno == EWOULDBLOCK ? 0 : -1;
}
else if (n == 0)
{
// EOF
return -1;
}
this->input_buffer_.wr_ptr((size_t)n);
this->OnRead();
// move data in the buffer to the beginning of the buffer
this->input_buffer_.crunch();
// return 1 in case there might be more data to read from OS
return n == space ? 1 : 0;
}
/*virtual*/ int BufferedSocket::handle_close(ACE_HANDLE /*h*/, ACE_Reactor_Mask /*m*/)
{
this->OnClose();
Base::handle_close();
return 0;
}
void BufferedSocket::close_connection(void)
{
this->peer().close_reader();
this->peer().close_writer();
reactor()->remove_handler(this, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::ALL_EVENTS_MASK);
}

View file

@ -0,0 +1,165 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/** \file
\ingroup realmd
*/
#ifndef MANGOS_H_BUFFEREDSOCKET
#define MANGOS_H_BUFFEREDSOCKET
#include <ace/Basic_Types.h>
#include <ace/Synch_Traits.h>
#include <ace/Svc_Handler.h>
#include <ace/SOCK_Stream.h>
#include <ace/Message_Block.h>
#include <ace/Basic_Types.h>
#include <string>
/**
* @brief
*
*/
class BufferedSocket: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
protected:
/**
* @brief
*
*/
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
/**
* @brief
*
*/
virtual void OnRead(void) { }
/**
* @brief
*
*/
virtual void OnAccept(void) { }
/**
* @brief
*
*/
virtual void OnClose(void) { }
public:
/**
* @brief
*
*/
BufferedSocket(void);
/**
* @brief
*
*/
virtual ~BufferedSocket(void);
/**
* @brief
*
* @return size_t
*/
size_t recv_len(void) const;
/**
* @brief
*
* @param buf
* @param len
* @return bool
*/
bool recv_soft(char* buf, size_t len);
/**
* @brief
*
* @param buf
* @param len
* @return bool
*/
bool recv(char* buf, size_t len);
/**
* @brief
*
* @param len
*/
void recv_skip(size_t len);
/**
* @brief
*
* @param buf
* @param len
* @return bool
*/
bool send(const char* buf, size_t len);
/**
* @brief
*
* @return const std::string
*/
const std::string& get_remote_address(void) const;
int open(void*) override;
/**
* @brief
*
*/
void close_connection(void);
int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE) override;
int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE) override;
/**
* @brief
*
* @param ACE_HANDLE
* @param ACE_Reactor_Mask
* @return int
*/
virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE,
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
private:
/**
* @brief
*
* @param message_block
* @return ssize_t
*/
ssize_t noblk_send(ACE_Message_Block& message_block);
private:
ACE_Message_Block input_buffer_; /**< TODO */
protected:
std::string remote_address_; /**< TODO */
};
#endif /* _BUFFEREDSOCKET_H_ */

View file

@ -0,0 +1,126 @@
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
/// \addtogroup realmd
/// @{
/// \file
#ifndef MANGOS_H_AUTHPACKETS
#define MANGOS_H_AUTHPACKETS
#include "Common.h"
#include <ace/Basic_Types.h>
#include <openssl/md5.h>
// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some paltform
#if defined( __GNUC__ )
#pragma pack(1)
#else
#pragma pack(push,1)
#endif
typedef struct AUTH_LOGON_CHALLENGE_C
{
uint8 cmd;
uint8 error;
uint16 size;
uint8 gamename[4];
uint8 version1;
uint8 version2;
uint8 version3;
uint16 build;
uint8 platform[4];
uint8 os[4];
uint8 country[4];
uint32 timezone_bias;
uint32 ip;
uint8 I_len;
uint8 I[1];
} sAuthLogonChallenge_C;
typedef struct AUTH_LOGON_PROOF_C
{
uint8 cmd;
uint8 A[32];
uint8 M1[20];
uint8 crc_hash[20];
uint8 number_of_keys;
uint8 securityFlags; // 0x00-0x04
} sAuthLogonProof_C;
typedef struct AUTH_LOGON_PROOF_S
{
uint8 cmd;
uint8 error;
uint8 M2[20];
uint32 accountFlags; // see enum AccountFlags
uint32 surveyId; // SurveyId
uint16 unkFlags; // some flags (AccountMsgAvailable = 0x01)
} sAuthLogonProof_S;
typedef struct AUTH_LOGON_PROOF_S_BUILD_6005
{
uint8 cmd;
uint8 error;
uint8 M2[20];
// uint32 unk1;
uint32 unk2;
// uint16 unk3;
} sAuthLogonProof_S_BUILD_6005;
typedef struct AUTH_RECONNECT_PROOF_C
{
uint8 cmd;
uint8 R1[16];
uint8 R2[20];
uint8 R3[20];
uint8 number_of_keys;
} sAuthReconnectProof_C;
typedef struct XFER_INIT
{
uint8 cmd; // XFER_INITIATE
uint8 fileNameLen; // strlen(fileName);
uint8 fileName[5]; // fileName[fileNameLen]
uint64 file_size; // file size (bytes)
uint8 md5[MD5_DIGEST_LENGTH]; // MD5
} XFER_INIT;
struct Chunk
{
ACE_UINT8 cmd;
ACE_UINT16 data_size;
ACE_UINT8 data[4096]; // 4096 - page size on most arch
};
// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some paltform
#if defined( __GNUC__ )
#pragma pack()
#else
#pragma pack(pop)
#endif
#endif /* MANGOS_H_AUTHPACKETS */
/// @}

View file

@ -0,0 +1,132 @@
################################################################################
# Realm list demon configuration #
################################################################################
[RealmdConf]
ConfVersion=@MANGOS_REALM_VER@
################################################################################
# REALMD SETTINGS
#
# LoginDatabaseInfo
# Connection settings for the realm/authentication database
# Default: hostname;port;username;password;database
# Use named pipes at Windows
# .;somenumber;username;password;database
#
# Use Unix sockets on Unix/Linux
# .;/path/to/unix_socket;username;password;database
#
# LogsDir
# Directory where log files should be written
# The given path has to exist, and be writable for the realm list demon
# Default: "" No log directory prefix, thus log files will be stored in
# the same path where the realm list demon is running
#
# PidFile
# Realm list demon PID file
# Default: "" Do not create a PID file.
#
# MaxPingTime
# Settings for maximum database-ping interval (minutes between pings)
# Default: 30
#
# RealmServerPort
# Port on which the server will listen
# Default: 3724
#
# BindIP
# Bind realm list demon to IP/hostname
# DO NOT CHANGE THIS UNLESS YOU _REALLY_ KNOW WHAT YOU'RE DOING
# Default: "0.0.0.0" Listen on all available addresses
#
# LogLevel
# Server console level of logging
# 0 = Minimum; 1 = Error; 2 = Detail; 3 = Full/Debug
# Default: 0
#
# LogTime
# Include time in server console output [hh:mm:ss]
# Default: 0 (no time)
# 1 (print time)
#
# LogFile
# Logfile name
# Default: "Realmd.log"
# "" - empty name disable creating log file
#
# LogTimestamp
# Logfile with timestamp of server start in name
# Default: 0 - no timestamp appended
# 1 - append timestamp in form of _YYYY-MM-DD_HH-MM-SS
#
# LogFileLevel
# Server file level of logging
# 0 = Minimum; 1 = Error; 2 = Detail; 3 = Full/Debug
# Default: 0
#
# LogColors
# Color for messages (format "normal_color details_color debug_color error_color)
# Colors: 0 - BLACK, 1 - RED, 2 - GREEN, 3 - BROWN, 4 - BLUE, 5 - MAGENTA, 6 - CYAN, 7 - GREY,
# 8 - YELLOW, 9 - LRED, 10 - LGREEN, 11 - LBLUE, 12 - LMAGENTA, 13 - LCYAN, 14 - WHITE
# Default: "" - none colors
# "13 7 11 9" - for example :)
#
# UseProcessors
# Used processors mask for multi-processors system (Used only at Windows)
# Default: 0 (selected by OS)
# number (bitmask value of selected processors)
#
# ProcessPriority
# Process proirity setting (Used only at Windows)
# Default: 1 (HIGH)
# 0 (Normal)
#
# WaitAtStartupError
# After startup error report wait <Enter> or some time before continue (and possible close console window)
# -1 (wait until <Enter> press)
# Default: 0 (not wait)
# N (>0, wait N secs)
#
# RealmsStateUpdateDelay
# Realm list Update up delay (updated at realm list request if delay expired).
# Default: 20
# 0 (Disabled)
#
# WrongPass.MaxCount
# Number of login attemps with wrong password before the account or IP is banned
# Default: 3 (Never ban)
#
# WrongPass.BanTime
# Duration of the ban in seconds (0 means permanent ban)
# Default: 300
#
# WrongPass.BanType
# Ban the IP or account on which login is attempted
# Default: 0 (Ban IP)
# 1 (Ban Account)
#
################################################################################
LoginDatabaseInfo = "127.0.0.1;3306;root;mangos;realmd"
LogsDir = ""
PidFile = ""
MaxPingTime = 30
RealmServerPort = 3724
BindIP = "0.0.0.0"
LogLevel = 0
LogTime = 0
LogFile = "realm-list.log"
LogTimestamp = 0
LogFileLevel = 0
LogColors = "13 7 11 9"
UseProcessors = 0
ProcessPriority = 1
WaitAtStartupError = 0
RealmsStateUpdateDelay = 20
WrongPass.MaxCount = 3
WrongPass.BanTime = 300
WrongPass.BanType = 0

BIN
src/realmd/realmd.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB