Compare commits

..

20 Commits

Author SHA1 Message Date
Dan ca704c7f88 feat(Scripting): Created two perl/lua scripting hooks for merchants (#5083)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-05-13 00:18:36 -07:00
Knightly ef6dfe0469 Load openssl libs from executable directory and update logging (#5078)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-05-07 20:25:01 -07:00
Dan d7e010a3ec strings: refactor Money and add MoneyShort (#5075) 2026-05-07 20:24:15 -07:00
nytmyr 85c3255568 [Bots] Command add fix for spelltypeids/spelltypenames (#5074)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-04-28 23:59:19 -07:00
KimLS c6ddf300a4 Add back msvc step with a maintained fork
Build / Linux (push) Waiting to run
Build / Windows (push) Waiting to run
2026-04-28 20:15:06 -07:00
KimLS 42d6004467 Remove step i think isn't required for windows, change linux path 2026-04-28 20:00:01 -07:00
KimLS cabe06ea92 Revert linux part for now 2026-04-28 19:42:26 -07:00
KimLS 4abd9c1b40 Some build changes, may or may not fix cache
Build / Linux (push) Waiting to run
Build / Windows (push) Waiting to run
2026-04-28 18:01:20 -07:00
KimLS f72bbab0e9 Change paths to try to get this working
Build / Linux (push) Waiting to run
Build / Windows (push) Waiting to run
2026-04-28 00:04:40 -07:00
KimLS 9647a5b82c Add develop branch 2026-04-27 23:20:29 -07:00
KimLS 84a90cef23 Linux build doesn't like the way we hash this 2026-04-27 22:22:54 -07:00
KimLS a8db057440 Add vcpkg cache, hopefully works. 2026-04-27 22:19:15 -07:00
Knightly 6d6cc8ca95 Update openssl calls to use EVP interface (#5072)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-04-25 16:49:03 -07:00
brainiac 6694281f22 Fix gcc warnings (#5071)
Build / Linux (push) Waiting to run
Build / Windows (push) Waiting to run
2026-04-24 23:05:32 -07:00
xJeris 5dc093fe5e Add Multiple Mercenary Hire Functionality (#5059)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-04-20 17:52:23 -07:00
ltroylove 758774b0bf fix: only dismiss pet summoned by the fading familiar buff (#5063) 2026-04-20 17:51:47 -07:00
ltroylove 1958a12bc7 fix: include base skill damage in FlyingKick, Kick, RoundKick, and Bash (#5061) 2026-04-20 17:51:17 -07:00
ltroylove 348094b881 fix: correct off-by-one in GetSpellLevel for Berserker class (#5060)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 17:50:36 -07:00
Knightly ba2ca5eada Lua: Header Matching and Cleanup (#5055)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-04-06 14:48:46 -07:00
brainiac 491b1edd12 Warning fixes, general cleanup (#5053)
Build / Linux (push) Has been cancelled
Build / Windows (push) Has been cancelled
2026-04-04 23:27:21 -07:00
174 changed files with 2185 additions and 4643 deletions
+1
View File
@@ -20,3 +20,4 @@
*.css text *.css text
*.js text *.js text
*.types text *.types text
*.pdf binary
+26 -2
View File
@@ -3,8 +3,8 @@ on:
push: push:
branches: branches:
- master - master
- develop
pull_request: pull_request:
jobs: jobs:
linux: linux:
name: Linux name: Linux
@@ -25,6 +25,17 @@ jobs:
sudo apt-get update sudo apt-get update
sudo apt-get install -y build-essential ninja-build ccache uuid-dev sudo apt-get install -y build-essential ninja-build ccache uuid-dev
- name: Restore vcpkg Cache
uses: actions/cache@v5
with:
path: |
build/vcpkg_installed
submodules/vcpkg/downloads
key: ${{ runner.os }}-vcpkg-${{ hashFiles('vcpkg.json') }}
restore-keys: |
${{ runner.os }}-vcpkg-${{ hashFiles('vcpkg.json') }}-
${{ runner.os }}-vcpkg-
- name: Configure - name: Configure
run: | run: |
cmake -S . -B build -G Ninja \ cmake -S . -B build -G Ninja \
@@ -47,6 +58,9 @@ jobs:
windows: windows:
name: Windows name: Windows
runs-on: windows-latest runs-on: windows-latest
env:
VCPKG_DOWNLOADS: ${{ github.workspace }}\submodules\vcpkg\downloads
VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}\vcpkg_archives,readwrite'
steps: steps:
- name: Checkout source - name: Checkout source
uses: actions/checkout@v5 uses: actions/checkout@v5
@@ -57,10 +71,20 @@ jobs:
run: git config --global core.longpaths true run: git config --global core.longpaths true
- name: Setup MSVC environment - name: Setup MSVC environment
uses: ilammy/msvc-dev-cmd@v1 uses: TheMrMilchmann/setup-msvc-dev@v4
with: with:
arch: x64 arch: x64
- name: Restore vcpkg Cache
uses: actions/cache@v5
with:
path: |
${{ env.VCPKG_DOWNLOADS }}
${{ github.workspace }}/vcpkg_archives
key: ${{ runner.os }}-vcpkg-${{ hashFiles('vcpkg.json') }}
restore-keys: |
${{ runner.os }}-vcpkg-
- name: Configure - name: Configure
shell: pwsh shell: pwsh
run: | run: |
+2 -2
View File
@@ -42,10 +42,10 @@ option(EQEMU_BUILD_PCH "Build with precompiled headers (Windows)" ON)
if(MSVC) if(MSVC)
add_compile_options(/bigobj) add_compile_options(/bigobj)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS NOMINMAX CRASH_LOGGING _HAS_AUTO_PTR_ETC) add_compile_definitions(_CRT_SECURE_NO_WARNINGS NOMINMAX WIN32_LEAN_AND_MEAN CRASH_LOGGING)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
option(EQEMU_DISABLE_MSVC_WARNINGS "Disable MSVC compile warnings." ON) option(EQEMU_DISABLE_MSVC_WARNINGS "Disable MSVC compile warnings." OFF)
if(EQEMU_DISABLE_MSVC_WARNINGS) if(EQEMU_DISABLE_MSVC_WARNINGS)
add_compile_options(/W0 /wd4005 /wd4996 /nologo /Os) add_compile_options(/W0 /wd4005 /wd4996 /nologo /Os)
endif() endif()
+66 -80
View File
@@ -6,21 +6,22 @@ set(common_sources
bodytypes.cpp bodytypes.cpp
classes.cpp classes.cpp
cli/eqemu_command_handler.cpp cli/eqemu_command_handler.cpp
compiler_macros.h
compression.cpp compression.cpp
condition.cpp
content/world_content_service.cpp content/world_content_service.cpp
crash.cpp crash.cpp
crc16.cpp crc16.cpp
crc32.cpp crc32.cpp
data_bucket.cpp data_bucket.cpp
data_bucket.cpp
database_instances.cpp
database.cpp database.cpp
database/database_dump_service.cpp database/database_dump_service.cpp
database/database_update.cpp database/database_update.cpp
database_instances.cpp
dbcore.cpp dbcore.cpp
deity.cpp deity.cpp
discord/discord.cpp
discord/discord_manager.cpp discord/discord_manager.cpp
discord/discord.cpp
dynamic_zone_base.cpp dynamic_zone_base.cpp
dynamic_zone_lockout.cpp dynamic_zone_lockout.cpp
emu_constants.cpp emu_constants.cpp
@@ -31,13 +32,16 @@ set(common_sources
eq_packet.cpp eq_packet.cpp
eq_stream_ident.cpp eq_stream_ident.cpp
eq_stream_proxy.cpp eq_stream_proxy.cpp
eqdb.cpp
eqdb_res.cpp eqdb_res.cpp
eqdb.cpp
eqemu_config.cpp eqemu_config.cpp
eqemu_exception.cpp eqemu_exception.cpp
eqemu_logsys.cpp eqemu_logsys.cpp
eqtime.cpp eqtime.cpp
event_sub.cpp event_sub.cpp
event/event_loop.cpp
event/task_scheduler.cpp
event/timer.cpp
events/player_event_discord_formatter.cpp events/player_event_discord_formatter.cpp
events/player_event_logs.cpp events/player_event_logs.cpp
evolving_items.cpp evolving_items.cpp
@@ -51,62 +55,56 @@ set(common_sources
ipc_mutex.cpp ipc_mutex.cpp
item_data.cpp item_data.cpp
item_instance.cpp item_instance.cpp
json/json.hpp
json/jsoncpp.cpp
json_config.cpp json_config.cpp
json/jsoncpp.cpp
light_source.cpp light_source.cpp
md5.cpp md5.cpp
memory/ksm.hpp
memory_buffer.cpp memory_buffer.cpp
memory_mapped_file.cpp memory_mapped_file.cpp
misc.cpp memory/ksm.cpp
misc_functions.cpp misc_functions.cpp
mutex.cpp misc.cpp
mysql_request_result.cpp mysql_request_result.cpp
mysql_request_row.cpp mysql_request_row.cpp
mysql_stmt.cpp mysql_stmt.cpp
net/console_server.cpp
net/console_server_connection.cpp net/console_server_connection.cpp
net/console_server.cpp
net/crc32.cpp net/crc32.cpp
net/dns.cpp
net/eqstream.cpp net/eqstream.cpp
net/packet.cpp net/packet.cpp
net/reliable_stream_connection.cpp net/reliable_stream_connection.cpp
net/servertalk_client_connection.cpp net/servertalk_client_connection.cpp
net/servertalk_legacy_client_connection.cpp net/servertalk_legacy_client_connection.cpp
net/servertalk_server.cpp
net/servertalk_server_connection.cpp net/servertalk_server_connection.cpp
net/servertalk_server.cpp
net/tcp_connection.cpp net/tcp_connection.cpp
net/tcp_server.cpp net/tcp_server.cpp
net/websocket_server.cpp
net/websocket_server_connection.cpp net/websocket_server_connection.cpp
net/websocket_server.cpp
opcode_map.cpp opcode_map.cpp
opcodemgr.cpp opcodemgr.cpp
packet_dump.cpp
packet_dump_file.cpp packet_dump_file.cpp
packet_dump.cpp
packet_functions.cpp packet_functions.cpp
patches/patches.cpp patches/patches.cpp
patches/rof.cpp
patches/rof2.cpp
patches/rof2_limits.cpp
patches/rof_limits.cpp patches/rof_limits.cpp
patches/sod.cpp patches/rof.cpp
patches/rof2_limits.cpp
patches/rof2.cpp
patches/sod_limits.cpp patches/sod_limits.cpp
patches/sof.cpp patches/sod.cpp
patches/sof_limits.cpp patches/sof_limits.cpp
patches/titanium.cpp patches/sof.cpp
patches/titanium_limits.cpp patches/titanium_limits.cpp
patches/uf.cpp patches/titanium.cpp
patches/uf_limits.cpp patches/uf_limits.cpp
patches/uf.cpp
path_manager.cpp
path_manager.cpp path_manager.cpp
perl_eqdb.cpp
perl_eqdb_res.cpp perl_eqdb_res.cpp
perl_eqdb.cpp
platform.cpp platform.cpp
platform/inet.h
platform/platform.h
platform/posix/include_inet.h
platform/posix/include_pthreads.h
platform/win/include_windows.h
platform/win/include_winsock2.h
proc_launcher.cpp proc_launcher.cpp
process.cpp process.cpp
process/process.cpp process/process.cpp
@@ -123,12 +121,12 @@ set(common_sources
shareddb.cpp shareddb.cpp
skill_caps.cpp skill_caps.cpp
skills.cpp skills.cpp
spdat.cpp
spdat_bot.cpp spdat_bot.cpp
spdat.cpp
StackWalker/StackWalker.cpp StackWalker/StackWalker.cpp
strings.cpp
strings_legacy.cpp strings_legacy.cpp
strings_misc.cpp strings_misc.cpp
strings.cpp
struct_strategy.cpp struct_strategy.cpp
textures.cpp textures.cpp
timer.cpp timer.cpp
@@ -538,35 +536,32 @@ set(repositories
) )
set(common_headers set(common_headers
StackWalker/StackWalker.h
additive_lagged_fibonacci_engine.h additive_lagged_fibonacci_engine.h
base_packet.h base_packet.h
bazaar.h bazaar.h
bodytypes.h bodytypes.h
classes.h
cli/argh.h cli/argh.h
cli/eqemu_command_handler.h cli/eqemu_command_handler.h
cli/terminal_color.hpp cli/terminal_color.hpp
classes.h
compression.h compression.h
condition.h
content/world_content_service.h content/world_content_service.h
crash.h crash.h
crc16.h crc16.h
crc32.h crc32.h
cron/croncpp.h cron/croncpp.h
data_bucket.cpp
data_verification.h data_verification.h
database_schema.h
database.h database.h
database/database_dump_service.h database/database_dump_service.h
database/database_update.h
database/database_update_manifest.h
database/database_update_manifest_bots.h database/database_update_manifest_bots.h
database/database_update_manifest_custom.h database/database_update_manifest_custom.h
database_schema.h database/database_update_manifest.h
database/database_update.h
dbcore.h dbcore.h
deity.h deity.h
discord/discord.h
discord/discord_manager.h discord/discord_manager.h
discord/discord.h
dynamic_zone_base.h dynamic_zone_base.h
dynamic_zone_lockout.h dynamic_zone_lockout.h
emu_constants.h emu_constants.h
@@ -576,24 +571,24 @@ set(common_headers
emu_versions.h emu_versions.h
eq_constants.h eq_constants.h
eq_limits.h eq_limits.h
eq_packet.h
eq_packet_structs.h eq_packet_structs.h
eq_packet.h
eq_stream_ident.h eq_stream_ident.h
eq_stream_intf.h eq_stream_intf.h
eq_stream_locator.h eq_stream_locator.h
eq_stream_proxy.h eq_stream_proxy.h
eqdb.h
eqdb_res.h eqdb_res.h
eqemu_config.h eqdb.h
eqemu_config_elements.h eqemu_config_elements.h
eqemu_config.h
eqemu_exception.h eqemu_exception.h
eqemu_logsys.h
eqemu_logsys_log_aliases.h eqemu_logsys_log_aliases.h
eqemu_logsys.h
eqtime.h eqtime.h
event_sub.h
event/event_loop.h event/event_loop.h
event/task.h event/task.h
event/timer.h event/timer.h
event_sub.h
events/player_event_discord_formatter.h events/player_event_discord_formatter.h
events/player_event_logs.h events/player_event_logs.h
events/player_events.h events/player_events.h
@@ -614,10 +609,11 @@ set(common_headers
ipc_mutex.h ipc_mutex.h
item_data.h item_data.h
item_instance.h item_instance.h
json_config.h
json/json_archive_single_line.h
json/json-forwards.h json/json-forwards.h
json/json.h json/json.h
json/json_archive_single_line.h json/json.hpp
json_config.h
light_source.h light_source.h
linked_list.h linked_list.h
loot.h loot.h
@@ -625,14 +621,14 @@ set(common_headers
md5.h md5.h
memory_buffer.h memory_buffer.h
memory_mapped_file.h memory_mapped_file.h
misc.h memory/ksm.h
misc_functions.h misc_functions.h
mutex.h misc.h
mysql_request_result.h mysql_request_result.h
mysql_request_row.h mysql_request_row.h
mysql_stmt.h mysql_stmt.h
net/console_server.h
net/console_server_connection.h net/console_server_connection.h
net/console_server.h
net/crc32.h net/crc32.h
net/dns.h net/dns.h
net/endian.h net/endian.h
@@ -644,49 +640,54 @@ set(common_headers
net/servertalk_client_connection.h net/servertalk_client_connection.h
net/servertalk_common.h net/servertalk_common.h
net/servertalk_legacy_client_connection.h net/servertalk_legacy_client_connection.h
net/servertalk_server.h
net/servertalk_server_connection.h net/servertalk_server_connection.h
net/tcp_connection.h net/servertalk_server.h
net/tcp_connection_pooling.h net/tcp_connection_pooling.h
net/tcp_connection.h
net/tcp_server.h net/tcp_server.h
net/websocket_server.h
net/websocket_server_connection.h net/websocket_server_connection.h
net/websocket_server.h
op_codes.h op_codes.h
opcode_dispatch.h opcode_dispatch.h
opcodemgr.h opcodemgr.h
packet_dump.h
packet_dump_file.h packet_dump_file.h
packet_dump.h
packet_functions.h packet_functions.h
patches/patches.h patches/patches.h
patches/rof.h
patches/rof2.h
patches/rof2_limits.h
patches/rof2_ops.h
patches/rof2_structs.h
patches/rof_limits.h patches/rof_limits.h
patches/rof_ops.h patches/rof_ops.h
patches/rof_structs.h patches/rof_structs.h
patches/sod.h patches/rof.h
patches/rof2_limits.h
patches/rof2_ops.h
patches/rof2_structs.h
patches/rof2.h
patches/sod_limits.h patches/sod_limits.h
patches/sod_ops.h patches/sod_ops.h
patches/sod_structs.h patches/sod_structs.h
patches/sof.h patches/sod.h
patches/sof_limits.h patches/sof_limits.h
patches/sof_ops.h patches/sof_ops.h
patches/sof_structs.h patches/sof_structs.h
patches/sof.h
patches/ss_declare.h patches/ss_declare.h
patches/ss_define.h patches/ss_define.h
patches/ss_register.h patches/ss_register.h
patches/titanium.h
patches/titanium_limits.h patches/titanium_limits.h
patches/titanium_ops.h patches/titanium_ops.h
patches/titanium_structs.h patches/titanium_structs.h
patches/uf.h patches/titanium.h
patches/uf_limits.h patches/uf_limits.h
patches/uf_ops.h patches/uf_ops.h
patches/uf_structs.h patches/uf_structs.h
path_manager.cpp patches/uf.h
platform.h platform.h
platform/inet.h
platform/platform.h
platform/posix/include_inet.h
platform/posix/include_pthreads.h
platform/win/include_windows.h
platform/win/include_winsock2.h
proc_launcher.h proc_launcher.h
process.h process.h
process/process.h process/process.h
@@ -713,6 +714,7 @@ set(common_headers
skills.h skills.h
spdat.h spdat.h
stacktrace/backward.hpp stacktrace/backward.hpp
StackWalker/StackWalker.h
strings.h strings.h
struct_strategy.h struct_strategy.h
tasks.h tasks.h
@@ -729,25 +731,9 @@ set(common_headers
zone_store.h zone_store.h
) )
# Source Groups (Regex based for automatic subdirectory handling) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${common_sources})
source_group("CLI" REGULAR_EXPRESSION "^cli/") source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Header Files" FILES ${common_headers})
source_group("Content" REGULAR_EXPRESSION "^content/") source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/repositories" PREFIX "Repositories" FILES ${repositories})
source_group("Cron" REGULAR_EXPRESSION "^cron/")
source_group("Database" REGULAR_EXPRESSION "^database/")
source_group("Discord" REGULAR_EXPRESSION "^discord/")
source_group("Event" REGULAR_EXPRESSION "^event/")
source_group("Events" REGULAR_EXPRESSION "^events/")
source_group("Http" REGULAR_EXPRESSION "^http/")
source_group("Json" REGULAR_EXPRESSION "^json/")
source_group("Memory" REGULAR_EXPRESSION "^memory/")
source_group("Net" REGULAR_EXPRESSION "^net/")
source_group("Patches" REGULAR_EXPRESSION "^patches/")
source_group("Process" REGULAR_EXPRESSION "^process/")
source_group("Repositories" REGULAR_EXPRESSION "^repositories/")
source_group("StackWalker" REGULAR_EXPRESSION "^StackWalker/")
source_group("Stacktrace" REGULAR_EXPRESSION "^stacktrace/")
source_group("Termcolor" REGULAR_EXPRESSION "^termcolor/")
source_group("Util" REGULAR_EXPRESSION "^util/")
option(EQEMU_ADD_PROFILER "Link with Google perftools profiler" OFF) option(EQEMU_ADD_PROFILER "Link with Google perftools profiler" OFF)
#PRNG options #PRNG options
+1 -1
View File
@@ -359,7 +359,7 @@ public:
BOOL Publics; // contains public symbols BOOL Publics; // contains public symbols
}; };
*/ */
typedef struct IMAGEHLP_MODULE64_V2 { struct IMAGEHLP_MODULE64_V2 {
DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64)
DWORD64 BaseOfImage; // base load address of module DWORD64 BaseOfImage; // base load address of module
DWORD ImageSize; // virtual size of the loaded module DWORD ImageSize; // virtual size of the loaded module
+1 -1
View File
@@ -134,7 +134,7 @@ protected:
CHAR loadedImageName[STACKWALK_MAX_NAMELEN]; CHAR loadedImageName[STACKWALK_MAX_NAMELEN];
} CallstackEntry; } CallstackEntry;
typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry}; enum CallstackEntryType {firstEntry, nextEntry, lastEntry};
virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName); virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName);
virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion); virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion);
+8 -18
View File
@@ -19,44 +19,34 @@
#include "common/misc.h" #include "common/misc.h"
#include "common/packet_dump.h" #include "common/packet_dump.h"
BasePacket::BasePacket(const unsigned char *buf, uint32 len) BasePacket::BasePacket(const unsigned char* buf, size_t len)
{ {
pBuffer=nullptr;
size=0;
_wpos = 0;
_rpos = 0;
timestamp.tv_sec = 0;
if (len > 0) { if (len > 0) {
size=len; size = static_cast<uint32>(len);
pBuffer = new unsigned char[len]; pBuffer = new unsigned char[len];
if (buf) { if (buf) {
memcpy(pBuffer, buf, len); memcpy(pBuffer, buf, len);
} else { }
else {
memset(pBuffer, 0, len); memset(pBuffer, 0, len);
} }
} }
} }
BasePacket::BasePacket(SerializeBuffer &buf) BasePacket::BasePacket(SerializeBuffer&& buf)
: pBuffer(std::exchange(buf.m_buffer, nullptr))
{ {
pBuffer = buf.m_buffer; // We are essentially taking ownership of this serialize buffer.
buf.m_buffer = nullptr; size = static_cast<uint32>(std::exchange(buf.m_pos, 0));
size = buf.m_pos;
buf.m_pos = 0;
buf.m_capacity = 0; buf.m_capacity = 0;
_wpos = 0;
_rpos = 0;
timestamp.tv_sec = 0;
} }
BasePacket::~BasePacket() BasePacket::~BasePacket()
{ {
if (pBuffer)
delete[] pBuffer; delete[] pBuffer;
pBuffer = nullptr; pBuffer = nullptr;
} }
void BasePacket::build_raw_header_dump(char *buffer, uint16 seq) const void BasePacket::build_raw_header_dump(char *buffer, uint16 seq) const
{ {
if (timestamp.tv_sec) { if (timestamp.tv_sec) {
+19 -13
View File
@@ -23,14 +23,26 @@
#include <cstdio> #include <cstdio>
class BasePacket { class BasePacket
{
protected:
BasePacket() = default;
BasePacket(const unsigned char* buf, size_t len);
BasePacket(SerializeBuffer&& buf);
virtual ~BasePacket();
public: public:
unsigned char *pBuffer; unsigned char* pBuffer = nullptr;
uint32 size, _wpos, _rpos; uint32 size = 0;
uint32 src_ip,dst_ip; uint32 _wpos = 0;
uint16 src_port,dst_port; uint32 _rpos = 0;
uint32 priority; uint32 src_ip = 0;
timeval timestamp; uint32 dst_ip = 0;
uint16 src_port = 0;
uint16 dst_port = 0;
uint32 priority = 0;
timeval timestamp{};
virtual void build_raw_header_dump(char *buffer, uint16 seq=0xffff) const; virtual void build_raw_header_dump(char *buffer, uint16 seq=0xffff) const;
virtual void build_header_dump(char *buffer) const; virtual void build_header_dump(char *buffer) const;
@@ -73,12 +85,6 @@ public:
uint32 GetReadPosition() { return _rpos; } uint32 GetReadPosition() { return _rpos; }
void SetWritePosition(uint32 Newwpos) { _wpos = Newwpos; } void SetWritePosition(uint32 Newwpos) { _wpos = Newwpos; }
void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; } void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; }
protected:
virtual ~BasePacket();
BasePacket() { pBuffer=nullptr; size=0; _wpos = 0; _rpos = 0; }
BasePacket(const unsigned char *buf, const uint32 len);
BasePacket(SerializeBuffer &buf);
}; };
extern void DumpPacketHex(const BasePacket* app); extern void DumpPacketHex(const BasePacket* app);
+3 -6
View File
@@ -23,12 +23,9 @@
namespace EQEmuCommand { namespace EQEmuCommand {
std::map<std::string, void (*)( using CommandFunction = void(*)(int argc, char** argv, argh::parser& cmd, std::string& description);
int argc,
char **argv, std::map<std::string, CommandFunction> function_map;
argh::parser &cmd,
std::string &description
)> function_map;
/** /**
* @param cmd * @param cmd
+1 -1
View File
@@ -51,7 +51,7 @@
# include <unistd.h> # include <unistd.h>
#elif defined(TERMCOLOR_OS_WINDOWS) #elif defined(TERMCOLOR_OS_WINDOWS)
# include <io.h> # include <io.h>
# include <windows.h> # include "common/platform/win/include_windows.h"
#endif #endif
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#if defined(_MSC_VER)
#define PUSH_DISABLE_DEPRECATED_WARNINGS() __pragma(warning(push)) \
__pragma(warning(disable:4996))
#define POP_DISABLE_DEPRECATED_WARNINGS() __pragma(warning(pop))
#elif defined(__GNUC__) || defined(__clang__)
#define PUSH_DISABLE_DEPRECATED_WARNINGS() _Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define POP_DISABLE_DEPRECATED_WARNINGS() _Pragma("GCC diagnostic pop")
#else
#define PUSH_DISABLE_DEPRECATED_WARNINGS()
#define POP_DISABLE_DEPRECATED_WARNINGS()
#endif
#if defined(_MSC_VER) && !defined(__clang__)
#define UNREACHABLE() __assume(0)
#else
#define UNREACHABLE() __builtin_unreachable()
#endif
-146
View File
@@ -1,146 +0,0 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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 "condition.h"
#ifdef _WINDOWS
Condition::Condition()
{
m_events[SignalEvent] = CreateEvent (nullptr, // security
FALSE, // is auto-reset event?
FALSE, // is signaled initially?
nullptr); // name
m_events[BroadcastEvent] = CreateEvent (nullptr, // security
TRUE, // is auto-reset event?
FALSE, // is signaled initially?
nullptr); // name
m_waiters = 0;
InitializeCriticalSection(&CSMutex);
}
Condition::~Condition()
{
DeleteCriticalSection(&CSMutex);
CloseHandle(m_events[SignalEvent]);
CloseHandle(m_events[BroadcastEvent]);
}
void Condition::Signal()
{
EnterCriticalSection(&CSMutex);
if(m_waiters > 0)
SetEvent(m_events[SignalEvent]);
LeaveCriticalSection(&CSMutex);
}
void Condition::SignalAll()
{
EnterCriticalSection(&CSMutex);
if(m_waiters > 0)
SetEvent(m_events[BroadcastEvent]);
LeaveCriticalSection(&CSMutex);
}
void Condition::Wait()
{
EnterCriticalSection(&CSMutex);
m_waiters++;
LeaveCriticalSection(&CSMutex);
int result = WaitForMultipleObjects (_eventCount, m_events, FALSE, INFINITE);
EnterCriticalSection(&CSMutex);
m_waiters--;
//see if we are the last person waiting on the condition, and there was a broadcast
//if so, we need to reset the broadcast event.
if(m_waiters == 0 && result == (WAIT_OBJECT_0+BroadcastEvent))
ResetEvent(m_events[BroadcastEvent]);
LeaveCriticalSection(&CSMutex);
}
#else
#include <pthread.h>
#include <sys/time.h>
#include <errno.h>
Condition::Condition()
{
pthread_cond_init(&cond,nullptr);
pthread_mutex_init(&mutex,nullptr);
}
void Condition::Signal()
{
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cond);
pthread_mutex_unlock(&mutex);
}
void Condition::SignalAll()
{
pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
}
void Condition::Wait()
{
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
pthread_mutex_unlock(&mutex);
}
/*
I commented this specifically because I think it might be very
difficult to write a windows counterpart to it, so I would like
to discourage its use until we can confirm that it can be reasonably
implemented on windows.
bool Condition::TimedWait(unsigned long usec)
{
struct timeval now;
struct timespec timeout;
int retcode=0;
pthread_mutex_lock(&mutex);
gettimeofday(&now,nullptr);
now.tv_usec+=usec;
timeout.tv_sec = now.tv_sec + (now.tv_usec/1000000);
timeout.tv_nsec = (now.tv_usec%1000000) *1000;
//cout << "now=" << now.tv_sec << "."<<now.tv_usec << endl;
//cout << "timeout=" << timeout.tv_sec << "."<<timeout.tv_nsec << endl;
retcode=pthread_cond_timedwait(&cond,&mutex,&timeout);
pthread_mutex_unlock(&mutex);
return retcode!=ETIMEDOUT;
}
*/
Condition::~Condition()
{
pthread_mutex_lock(&mutex);
pthread_cond_destroy(&cond);
pthread_mutex_unlock(&mutex);
pthread_mutex_destroy(&mutex);
}
#endif
-51
View File
@@ -1,51 +0,0 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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/>.
*/
#pragma once
#include "common/mutex.h"
#include "common/platform/posix/include_pthreads.h"
#include "common/platform/win/include_windows.h"
//Sombody, someday needs to figure out how to implement a condition
//system on windows...
class Condition {
private:
#ifdef WIN32
enum {
SignalEvent = 0,
BroadcastEvent,
_eventCount
};
HANDLE m_events[_eventCount];
uint32 m_waiters;
CRITICAL_SECTION CSMutex;
#else
pthread_cond_t cond;
pthread_mutex_t mutex;
#endif
public:
Condition();
void Signal();
void SignalAll();
void Wait();
// bool TimedWait(unsigned long usec);
~Condition();
};
+2 -2
View File
@@ -132,7 +132,7 @@ void WorldContentService::SetContentFlags(const std::vector<ContentFlagsReposito
bool WorldContentService::IsContentFlagEnabled(const std::string &content_flag) bool WorldContentService::IsContentFlagEnabled(const std::string &content_flag)
{ {
for (auto &f: GetContentFlags()) { for (auto &f: GetContentFlags()) {
if (f.flag_name == content_flag && f.enabled == true) { if (f.flag_name == content_flag && f.enabled == 1) {
return true; return true;
} }
} }
@@ -147,7 +147,7 @@ bool WorldContentService::IsContentFlagEnabled(const std::string &content_flag)
bool WorldContentService::IsContentFlagDisabled(const std::string &content_flag) bool WorldContentService::IsContentFlagDisabled(const std::string &content_flag)
{ {
for (auto &f: GetContentFlags()) { for (auto &f: GetContentFlags()) {
if (f.flag_name == content_flag && f.enabled == false) { if (f.flag_name == content_flag && f.enabled == 0) {
return true; return true;
} }
} }
+1 -1
View File
@@ -125,6 +125,6 @@ uint32 CRC32::Update(const uint8* buf, uint32 bufsize, uint32 crc32var) {
return crc32var; return crc32var;
} }
inline void CRC32::Calc(const uint8 byte, uint32& crc32var) { void CRC32::Calc(const uint8 byte, uint32& crc32var) {
crc32var = ((crc32var) >> 8) ^ CRC32Table[(byte) ^ ((crc32var) & 0x000000FF)]; crc32var = ((crc32var) >> 8) ^ CRC32Table[(byte) ^ ((crc32var) & 0x000000FF)];
} }
+2 -2
View File
@@ -728,7 +728,7 @@ bool Database::LoadVariables()
return true; return true;
} }
LockMutex lock(&Mvarcache); std::scoped_lock lock(Mvarcache);
for (const auto& e : l) { for (const auto& e : l) {
varcache.last_update = std::time(nullptr); varcache.last_update = std::time(nullptr);
@@ -747,7 +747,7 @@ bool Database::LoadVariables()
bool Database::GetVariable(const std::string& name, std::string& value) bool Database::GetVariable(const std::string& name, std::string& value)
{ {
LockMutex lock(&Mvarcache); std::scoped_lock lock(Mvarcache);
if (name.empty()) { if (name.empty()) {
return false; return false;
+3 -4
View File
@@ -20,13 +20,12 @@
#include "common/dbcore.h" #include "common/dbcore.h"
#include "common/eq_packet_structs.h" #include "common/eq_packet_structs.h"
#include "common/eqemu_logsys.h" #include "common/eqemu_logsys.h"
#include "common/linked_list.h"
#include "common/types.h" #include "common/types.h"
#include <cmath> #include <map>
#include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#define AUTHENTICATION_TIMEOUT 60 #define AUTHENTICATION_TIMEOUT 60
#define INVALID_ID 0xFFFFFFFF #define INVALID_ID 0xFFFFFFFF
@@ -265,7 +264,7 @@ public:
uint64_t GetNextTableId(const std::string& table_name); uint64_t GetNextTableId(const std::string& table_name);
private: private:
Mutex Mvarcache; std::mutex Mvarcache;
VarCache_Struct varcache; VarCache_Struct varcache;
/* Groups, utility methods. */ /* Groups, utility methods. */
+23 -40
View File
@@ -33,17 +33,9 @@
#endif #endif
DBcore::DBcore() DBcore::DBcore()
: mysql(mysql_init(nullptr))
, m_mutex(std::make_shared<Mutex>())
{ {
mysql = mysql_init(nullptr);
mysqlOwner = true;
pHost = nullptr;
pUser = nullptr;
pPassword = nullptr;
pDatabase = nullptr;
pCompress = false;
pSSL = false;
pStatus = Closed;
m_mutex = new Mutex;
} }
DBcore::~DBcore() DBcore::~DBcore()
@@ -56,20 +48,17 @@ DBcore::~DBcore()
if (mysqlOwner) { if (mysqlOwner) {
mysql_close(mysql); mysql_close(mysql);
} }
safe_delete_array(pHost);
safe_delete_array(pUser);
safe_delete_array(pPassword);
safe_delete_array(pDatabase);
} }
// Sends the MySQL server a keepalive // Sends the MySQL server a keepalive
void DBcore::ping() void DBcore::ping()
{ {
if (!m_mutex->trylock()) { if (!m_mutex->try_lock())
{
// well, if's it's locked, someone's using it. If someone's using it, it doesnt need a keepalive // well, if's it's locked, someone's using it. If someone's using it, it doesnt need a keepalive
return; return;
} }
mysql_ping(mysql); mysql_ping(mysql);
m_mutex->unlock(); m_mutex->unlock();
} }
@@ -92,7 +81,7 @@ MySQLRequestResult DBcore::QueryDatabase(const char *query, uint32 querylen, boo
BenchTimer timer; BenchTimer timer;
timer.reset(); timer.reset();
LockMutex lock(m_mutex); std::scoped_lock lock(*m_mutex);
// Reconnect if we are not connected before hand. // Reconnect if we are not connected before hand.
if (pStatus != Connected) { if (pStatus != Connected) {
@@ -217,15 +206,12 @@ bool DBcore::Open(
bool iSSL bool iSSL
) )
{ {
LockMutex lock(m_mutex); std::scoped_lock lock(*m_mutex);
safe_delete_array(pHost);
safe_delete_array(pUser); m_host = iHost;
safe_delete_array(pPassword); m_user = iUser;
safe_delete_array(pDatabase); m_password = iPassword;
pHost = strcpy(new char[strlen(iHost) + 1], iHost); m_database = iDatabase;
pUser = strcpy(new char[strlen(iUser) + 1], iUser);
pPassword = strcpy(new char[strlen(iPassword) + 1], iPassword);
pDatabase = strcpy(new char[strlen(iDatabase) + 1], iDatabase);
pCompress = iCompress; pCompress = iCompress;
pPort = iPort; pPort = iPort;
pSSL = iSSL; pSSL = iSSL;
@@ -234,10 +220,12 @@ bool DBcore::Open(
bool DBcore::Open(uint32 *errnum, char *errbuf) bool DBcore::Open(uint32 *errnum, char *errbuf)
{ {
// Expects m_mutex to already be locked.
if (errbuf) { if (errbuf) {
errbuf[0] = 0; errbuf[0] = 0;
} }
LockMutex lock(m_mutex);
if (GetStatus() == Connected) { if (GetStatus() == Connected) {
return true; return true;
} }
@@ -245,7 +233,7 @@ bool DBcore::Open(uint32 *errnum, char *errbuf)
mysql_close(mysql); mysql_close(mysql);
mysql_init(mysql); // Initialize structure again mysql_init(mysql); // Initialize structure again
} }
if (!pHost) { if (m_host.empty()) {
return false; return false;
} }
/* /*
@@ -268,11 +256,10 @@ bool DBcore::Open(uint32 *errnum, char *errbuf)
mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &off); mysql_options(mysql, MYSQL_OPT_SSL_ENFORCE, &off);
mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &off); mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &off);
} }
if (mysql_real_connect(mysql, pHost, pUser, pPassword, pDatabase, pPort, 0, flags)) { if (mysql_real_connect(mysql, m_host.c_str(), m_user.c_str(), m_password.c_str(), m_database.c_str(), pPort, nullptr, flags)) {
pStatus = Connected; pStatus = Connected;
std::string connected_origin_host = pHost; SetOriginHost(m_host);
SetOriginHost(connected_origin_host);
return true; return true;
} }
@@ -293,9 +280,9 @@ const std::string &DBcore::GetOriginHost() const
return origin_host; return origin_host;
} }
void DBcore::SetOriginHost(const std::string &origin_host) void DBcore::SetOriginHost(const std::string& originHost)
{ {
DBcore::origin_host = origin_host; DBcore::origin_host = originHost;
} }
std::string DBcore::Escape(const std::string& s) std::string DBcore::Escape(const std::string& s)
@@ -307,12 +294,8 @@ std::string DBcore::Escape(const std::string& s)
return temp.data(); return temp.data();
} }
void DBcore::SetMutex(Mutex *mutex) void DBcore::SetMutex(const std::shared_ptr<Mutex>& mutex)
{ {
if (m_mutex && m_mutex != mutex) {
safe_delete(m_mutex);
}
DBcore::m_mutex = mutex; DBcore::m_mutex = mutex;
} }
@@ -326,7 +309,7 @@ MySQLRequestResult DBcore::QueryDatabaseMulti(const std::string &query)
BenchTimer timer; BenchTimer timer;
timer.reset(); timer.reset();
LockMutex lock(m_mutex); std::scoped_lock lock(*m_mutex);
// Reconnect if we are not connected before hand. // Reconnect if we are not connected before hand.
if (pStatus != Connected) { if (pStatus != Connected) {
@@ -449,5 +432,5 @@ MySQLRequestResult DBcore::QueryDatabaseMulti(const std::string &query)
mysql::PreparedStmt DBcore::Prepare(std::string query) mysql::PreparedStmt DBcore::Prepare(std::string query)
{ {
return mysql::PreparedStmt(*mysql, std::move(query), m_mutex); return mysql::PreparedStmt(*mysql, std::move(query), *m_mutex);
} }
+17 -15
View File
@@ -17,11 +17,11 @@
*/ */
#pragma once #pragma once
#include "common/mutex.h"
#include "common/mysql_request_result.h" #include "common/mysql_request_result.h"
#include "common/types.h" #include "common/types.h"
#include "mysql.h" #include "mysql.h"
#include <memory>
#include <mutex> #include <mutex>
#define CR_SERVER_GONE_ERROR 2006 #define CR_SERVER_GONE_ERROR 2006
@@ -29,12 +29,15 @@
namespace mysql { class PreparedStmt; } namespace mysql { class PreparedStmt; }
class DBcore { class DBcore
{
public: public:
enum eStatus { enum eStatus {
Closed, Connected, Error Closed, Connected, Error
}; };
using Mutex = std::recursive_mutex;
DBcore(); DBcore();
~DBcore(); ~DBcore();
eStatus GetStatus() { return pStatus; } eStatus GetStatus() { return pStatus; }
@@ -58,7 +61,7 @@ public:
mysql = o.mysql; mysql = o.mysql;
mysqlOwner = false; mysqlOwner = false;
} }
void SetMutex(Mutex *mutex); void SetMutex(const std::shared_ptr<Mutex>& mutex);
// only safe on connections shared with other threads if results buffered // only safe on connections shared with other threads if results buffered
// unsafe to use off main thread due to internal server logging // unsafe to use off main thread due to internal server logging
@@ -81,22 +84,21 @@ protected:
private: private:
bool Open(uint32 *errnum = nullptr, char *errbuf = nullptr); bool Open(uint32 *errnum = nullptr, char *errbuf = nullptr);
MYSQL* mysql; MYSQL* mysql = nullptr;
bool mysqlOwner; bool mysqlOwner = true;
Mutex *m_mutex; eStatus pStatus = Closed;
eStatus pStatus;
std::mutex m_query_lock{}; std::shared_ptr<Mutex> m_mutex;
std::string origin_host; std::string origin_host;
char *pHost; std::string m_host;
char *pUser; std::string m_user;
char *pPassword; std::string m_password;
char *pDatabase; std::string m_database;
bool pCompress; bool pCompress = false;
uint32 pPort; uint32 pPort = 0;
bool pSSL; bool pSSL = false;
// allows multiple queries to be executed within the same query // allows multiple queries to be executed within the same query
// do not use this under normal operation // do not use this under normal operation
+1
View File
@@ -376,6 +376,7 @@ N(OP_MercenaryDismiss),
N(OP_MercenaryHire), N(OP_MercenaryHire),
N(OP_MercenarySuspendRequest), N(OP_MercenarySuspendRequest),
N(OP_MercenarySuspendResponse), N(OP_MercenarySuspendResponse),
N(OP_MercenarySwitch),
N(OP_MercenaryTimer), N(OP_MercenaryTimer),
N(OP_MercenaryTimerRequest), N(OP_MercenaryTimerRequest),
N(OP_MercenaryUnknown1), N(OP_MercenaryUnknown1),
+22 -13
View File
@@ -31,9 +31,19 @@
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, uint32 len) EQPacket::EQPacket()
: BasePacket(buf, len), {
emu_opcode(op) }
EQPacket::EQPacket(EmuOpcode op, const unsigned char *buf, size_t len)
: BasePacket(buf, len)
, emu_opcode(op)
{
}
EQPacket::EQPacket(EmuOpcode opcode, SerializeBuffer&& buf)
: BasePacket(std::move(buf))
, emu_opcode(opcode)
{ {
} }
@@ -360,17 +370,16 @@ EQRawApplicationPacket::EQRawApplicationPacket(const unsigned char *buf, const u
} }
} }
void DumpPacket(const EQApplicationPacket* app, bool iShowInfo) { void DumpPacket(const EQApplicationPacket* app, bool iShowInfo)
{
if (iShowInfo) { if (iShowInfo) {
std::cout << "Dumping Applayer: 0x" << std::hex << std::setfill('0') << std::setw(4) << app->GetOpcode() << std::dec; printf("Dumping Applayer: 0x%04x size: %u", app->GetOpcode(), app->size);
std::cout << " size:" << app->size << std::endl;
}
DumpPacketHex(app->pBuffer, app->size);
// DumpPacketAscii(app->pBuffer, app->size);
} }
std::string DumpPacketToString(const EQApplicationPacket* app){ DumpPacketHex(app->pBuffer, app->size);
std::ostringstream out; }
out << DumpPacketHexToString(app->pBuffer, app->size);
return out.str(); std::string DumpPacketToString(const EQApplicationPacket* app)
{
return DumpPacketHexToString(app->pBuffer, app->size);
} }
+49 -29
View File
@@ -28,8 +28,15 @@
#include "common/emu_opcodes.h" #include "common/emu_opcodes.h"
#endif #endif
class EQPacket : public BasePacket { class EQPacket : public BasePacket
{
friend class EQStream; friend class EQStream;
protected:
EQPacket();
EQPacket(EmuOpcode opcode, const unsigned char* buf, size_t len);
EQPacket(EmuOpcode opcode, SerializeBuffer&& buf);
public: public:
virtual ~EQPacket() {} virtual ~EQPacket() {}
@@ -41,19 +48,12 @@ public:
virtual void DumpRawHeaderNoTime(uint16 seq=0xffff, FILE *to = stdout) const; virtual void DumpRawHeaderNoTime(uint16 seq=0xffff, FILE *to = stdout) const;
void SetOpcode(EmuOpcode op) { emu_opcode = op; } void SetOpcode(EmuOpcode op) { emu_opcode = op; }
const EmuOpcode GetOpcode() const { return(emu_opcode); } EmuOpcode GetOpcode() const { return(emu_opcode); }
// const char *GetOpcodeName() const;
protected: protected:
//this is just a cache so we dont look it up several times on Get() //this is just a cache so we dont look it up several times on Get()
//and it is mutable so we can store the cached copy even on a const object //and it is mutable so we can store the cached copy even on a const object
EmuOpcode emu_opcode; EmuOpcode emu_opcode = OP_Unknown;
EQPacket(EmuOpcode opcode, const unsigned char *buf, const uint32 len);
EQPacket(EmuOpcode opcode, SerializeBuffer &buf) : BasePacket(buf), emu_opcode(opcode) { };
// EQPacket(const EQPacket &p) { }
EQPacket() { emu_opcode=OP_Unknown; pBuffer=nullptr; size=0; }
}; };
class EQRawApplicationPacket; class EQRawApplicationPacket;
@@ -90,19 +90,43 @@ protected:
uint16 opcode; uint16 opcode;
}; };
class EQApplicationPacket : public EQPacket { class EQApplicationPacket : public EQPacket
{
friend class EQStream; friend class EQStream;
public:
EQApplicationPacket()
{
}
EQApplicationPacket(EmuOpcode op)
: EQPacket(op, nullptr, 0)
{
}
EQApplicationPacket(EmuOpcode op, size_t len)
: EQPacket(op, nullptr, len)
{
}
EQApplicationPacket(EmuOpcode op, const unsigned char* buf, size_t len)
: EQPacket(op, buf, len)
{
}
EQApplicationPacket(EmuOpcode op, SerializeBuffer&& buf)
: EQPacket(op, std::move(buf))
{
}
private:
EQApplicationPacket(const EQApplicationPacket& p)
: EQPacket(p.emu_opcode, p.pBuffer, p.size)
, app_opcode_size(p.app_opcode_size)
, opcode_bypass(p.opcode_bypass)
{
}
public: public:
EQApplicationPacket() : EQPacket(OP_Unknown, nullptr, 0), opcode_bypass(0)
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
EQApplicationPacket(const EmuOpcode op) : EQPacket(op, nullptr, 0), opcode_bypass(0)
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
EQApplicationPacket(const EmuOpcode op, const uint32 len) : EQPacket(op, nullptr, len), opcode_bypass(0)
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
EQApplicationPacket(const EmuOpcode op, const unsigned char *buf, const uint32 len) : EQPacket(op, buf, len), opcode_bypass(0)
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
EQApplicationPacket(const EmuOpcode op, SerializeBuffer &buf) : EQPacket(op, buf), opcode_bypass(0)
{ app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2; }
bool combine(const EQApplicationPacket *rhs); bool combine(const EQApplicationPacket *rhs);
uint32 serialize (uint16 opcode, unsigned char *dest) const; uint32 serialize (uint16 opcode, unsigned char *dest) const;
uint32 Size() const { return size+app_opcode_size; } uint32 Size() const { return size+app_opcode_size; }
@@ -119,15 +143,11 @@ public:
uint16 GetProtocolOpcode() const { return protocol_opcode; } uint16 GetProtocolOpcode() const { return protocol_opcode; }
void SetProtocolOpcode(uint16 v) { protocol_opcode = v; } void SetProtocolOpcode(uint16 v) { protocol_opcode = v; }
protected: protected:
uint16 protocol_opcode = 0;
uint16 protocol_opcode; uint8 app_opcode_size = GetExecutablePlatform() == ExePlatformUCS ? 1 : 2;
uint8 app_opcode_size; uint16 opcode_bypass = 0;
uint16 opcode_bypass;
private:
EQApplicationPacket(const EQApplicationPacket &p) : EQPacket(p.emu_opcode, p.pBuffer, p.size), opcode_bypass(p.opcode_bypass) { app_opcode_size = p.app_opcode_size; }
}; };
class EQRawApplicationPacket : public EQApplicationPacket { class EQRawApplicationPacket : public EQApplicationPacket {
+6
View File
@@ -6236,6 +6236,12 @@ struct SuspendMercenary_Struct {
/*0001*/ /*0001*/
}; };
// [OPCode: 0x1b37 (RoF2)] [Client->Server] [Size: 4]
struct SwitchMercenary_Struct {
/*0000*/ uint32 MercIndex; // 0-based UI index into owned merc list
/*0004*/
};
// [OPCode: 0x2528] On Live as of April 2 2012 [Server->Client] [Size: 4] // [OPCode: 0x2528] On Live as of April 2 2012 [Server->Client] [Size: 4]
// Response to suspend merc with timestamp // Response to suspend merc with timestamp
struct SuspendMercenaryResponse_Struct { struct SuspendMercenaryResponse_Struct {
+2 -2
View File
@@ -26,13 +26,13 @@
//this is the only part of an EQStream that is seen by the application. //this is the only part of an EQStream that is seen by the application.
typedef enum { enum EQStreamState {
ESTABLISHED, ESTABLISHED,
CLOSING, //waiting for pending data to flush. CLOSING, //waiting for pending data to flush.
DISCONNECTING, //have sent disconnect, waiting for their disconnect reply. DISCONNECTING, //have sent disconnect, waiting for their disconnect reply.
CLOSED, //received a disconnect from remote side. CLOSED, //received a disconnect from remote side.
UNESTABLISHED UNESTABLISHED
} EQStreamState; };
class EQApplicationPacket; class EQApplicationPacket;
class OpcodeManager; class OpcodeManager;
+1 -3
View File
@@ -33,10 +33,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#ifdef _WINDOWS #ifdef _WINDOWS
#include <conio.h> #include "common/platform/platform.h"
#include <direct.h> #include <direct.h>
#include <process.h>
#include <windows.h>
#else #else
#include <sys/stat.h> #include <sys/stat.h>
#include <thread> #include <thread>
+36 -29
View File
@@ -15,36 +15,43 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once
#include "common/types.h" #include "common/event/event_loop.h"
#include "common/platform/posix/include_pthreads.h" #include "uv.h"
#include "common/platform/win/include_windows.h"
class Mutex { namespace EQ {
public:
Mutex();
~Mutex();
void lock(); EventLoop& EventLoop::Get()
void unlock(); {
bool trylock(); thread_local EventLoop inst;
protected: return inst;
private: }
#if defined _WINDOWS
CRITICAL_SECTION CSMutex;
#else
pthread_mutex_t CSMutex;
#endif
};
class LockMutex { EventLoop::EventLoop()
public: : m_loop(std::make_unique<uv_loop_t>())
LockMutex(Mutex* in_mut, bool iLock = true); {
~LockMutex(); memset(m_loop.get(), 0, sizeof(uv_loop_t));
void unlock(); uv_loop_init(m_loop.get());
void lock(); }
private:
bool locked; EventLoop::~EventLoop()
Mutex* mut; {
}; uv_loop_close(m_loop.get());
}
void EventLoop::Process()
{
uv_run(m_loop.get(), UV_RUN_NOWAIT);
}
void EventLoop::Run()
{
uv_run(m_loop.get(), UV_RUN_DEFAULT);
}
void EventLoop::Shutdown()
{
uv_stop(m_loop.get());
}
} // namespace EQ
+16 -33
View File
@@ -17,48 +17,31 @@
*/ */
#pragma once #pragma once
#include "common/platform/win/include_windows.h" // uv.h is going to include it so let's do it first. #include <memory>
#include "uv.h" // FIXME: hide this
#include <cstring> typedef struct uv_loop_s uv_loop_t;
namespace EQ {
namespace EQ
{
class EventLoop class EventLoop
{ {
public: public:
static EventLoop &Get() { static EventLoop& Get();
static thread_local EventLoop inst;
return inst;
}
~EventLoop() { ~EventLoop();
uv_loop_close(&m_loop); EventLoop(const EventLoop&) = delete;
} EventLoop& operator=(const EventLoop&) = delete;
void Process() { void Process();
uv_run(&m_loop, UV_RUN_NOWAIT); void Run();
} void Shutdown();
void Run() { uv_loop_t* Handle() { return m_loop.get(); }
uv_run(&m_loop, UV_RUN_DEFAULT);
}
void Shutdown() {
uv_stop(&m_loop);
}
uv_loop_t* Handle() { return &m_loop; }
private: private:
EventLoop() { EventLoop();
memset(&m_loop, 0, sizeof(uv_loop_t));
uv_loop_init(&m_loop);
}
EventLoop(const EventLoop&); std::unique_ptr<uv_loop_t> m_loop;
EventLoop& operator=(const EventLoop&);
uv_loop_t m_loop;
}; };
}
} // namespace EQ
+128
View File
@@ -0,0 +1,128 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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 "task_scheduler.h"
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
namespace EQ::Event {
static constexpr int DefaultThreadCount = 4;
struct TaskScheduler::SchedulerData
{
std::atomic_bool running{ false };
std::vector<std::thread> threads;
std::mutex lock;
std::condition_variable cv;
std::queue<std::function<void()>> tasks;
};
TaskScheduler::TaskScheduler()
: m_data(std::make_unique<SchedulerData>())
{
Start(DefaultThreadCount);
}
TaskScheduler::TaskScheduler(size_t threads)
{
Start(threads);
}
TaskScheduler::~TaskScheduler()
{
Stop();
}
void TaskScheduler::Start(size_t threads)
{
if (m_data->running.exchange(true))
return;
m_data->threads.reserve(threads);
for (size_t i = 0; i < threads; ++i)
{
m_data->threads.emplace_back(
[this]{ ProcessWork(); });
}
}
void TaskScheduler::Stop()
{
if (!m_data->running.exchange(false))
return;
m_data->cv.notify_all();
for (auto& t : m_data->threads)
{
t.join();
}
m_data->threads.clear();
}
void TaskScheduler::ProcessWork()
{
for (;;)
{
std::function<void()> work;
{
std::unique_lock lock(m_data->lock);
m_data->cv.wait(lock,
[this]
{
return !m_data->running || !m_data->tasks.empty();
});
if (!m_data->running)
{
return;
}
work = std::move(m_data->tasks.front());
m_data->tasks.pop();
}
work();
}
}
void TaskScheduler::AddTask(std::function<void()>&& task)
{
if (!m_data->running)
{
throw std::runtime_error("Enqueue on stopped scheduler.");
}
{
std::scoped_lock lock(m_data->lock);
m_data->tasks.push(std::move(task));
}
m_data->cv.notify_one();
}
} // namespace EQ::Event
+22 -93
View File
@@ -17,116 +17,45 @@
*/ */
#pragma once #pragma once
#include <condition_variable>
#include <functional> #include <functional>
#include <future> #include <future>
#include <mutex> #include <memory>
#include <queue>
#include <thread> namespace EQ::Event {
#include <vector>
namespace EQ
{
namespace Event
{
class TaskScheduler class TaskScheduler
{ {
public: public:
static const int DefaultThreadCount = 4; TaskScheduler();
TaskScheduler(size_t threads);
TaskScheduler() : _running(false) ~TaskScheduler();
{
Start(DefaultThreadCount);
}
TaskScheduler(size_t threads) : _running(false) void Start(size_t threads);
{ void Stop();
Start(threads);
}
~TaskScheduler() {
Stop();
}
void Start(size_t threads) {
if (true == _running) {
return;
}
_running = true;
for (size_t i = 0; i < threads; ++i) {
_threads.emplace_back(std::thread(std::bind(&TaskScheduler::ProcessWork, this)));
}
}
void Stop() {
if (false == _running) {
return;
}
{
std::unique_lock<std::mutex> lock(_lock);
_running = false;
}
_cv.notify_all();
for (auto &t : _threads) {
t.join();
}
}
template <typename Fn, typename... Args> template <typename Fn, typename... Args>
auto Enqueue(Fn&& fn, Args&&... args) -> std::future<typename std::invoke_result<Fn, Args...>::type> { auto Enqueue(Fn&& fn, Args&&... args) -> std::future<typename std::invoke_result<Fn, Args...>::type>
{
using return_type = typename std::invoke_result<Fn, Args...>::type; using return_type = typename std::invoke_result<Fn, Args...>::type;
auto task = std::make_shared<std::packaged_task<return_type()>>( auto task = std::make_shared<std::packaged_task<return_type()>>(
std::bind(std::forward<Fn>(fn), std::forward<Args>(args)...) [fn = std::forward<Fn>(fn), ...args = std::forward<Args>(args)]() mutable
{
return fn(std::forward<Args>(args)...);
}
); );
std::future<return_type> res = task->get_future(); AddTask([task] { (*task)(); });
{ return task->get_future();
std::unique_lock<std::mutex> lock(_lock);
if (false == _running) {
throw std::runtime_error("Enqueue on stopped scheduler.");
}
_tasks.emplace([task]() { (*task)(); });
}
_cv.notify_one();
return res;
} }
private: private:
void ProcessWork() { void AddTask(std::function<void()>&& task);
for (;;) { void ProcessWork();
std::function<void()> work;
{ struct SchedulerData;
std::unique_lock<std::mutex> lock(_lock); std::unique_ptr<SchedulerData> m_data;
_cv.wait(lock, [this] { return !_running || !_tasks.empty(); });
if (false == _running) {
return;
}
work = std::move(_tasks.front());
_tasks.pop();
}
work();
}
}
bool _running = true;
std::vector<std::thread> _threads;
std::mutex _lock;
std::condition_variable _cv;
std::queue<std::function<void()>> _tasks;
}; };
}
} } // namespace EQ::Event
+90
View File
@@ -0,0 +1,90 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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 "common/event/timer.h"
#include "uv.h"
namespace EQ {
Timer::Timer(callback_t cb)
: m_cb(std::move(cb))
{
}
Timer::Timer(uint64_t duration_ms, bool repeats, callback_t cb)
: m_cb(std::move(cb))
{
Start(duration_ms, repeats);
}
Timer::~Timer()
{
Stop();
}
void Timer::Start(uint64_t duration_ms, bool repeats)
{
if (!m_timer)
{
uv_loop_t* loop = EventLoop::Get().Handle();
m_timer = std::make_unique<uv_timer_t>();
memset(m_timer.get(), 0, sizeof(uv_timer_t));
uv_timer_init(loop, m_timer.get());
m_timer->data = this;
if (repeats)
{
uv_timer_start(m_timer.get(), [](uv_timer_t* handle)
{
Timer* t = static_cast<Timer*>(handle->data);
t->Execute();
}, duration_ms, duration_ms);
}
else
{
uv_timer_start(m_timer.get(),
[](uv_timer_t* handle)
{
Timer* t = static_cast<Timer*>(handle->data);
t->Stop();
t->Execute();
}, duration_ms, 0);
}
}
}
void Timer::Stop()
{
if (m_timer)
{
uv_close(reinterpret_cast<uv_handle_t*>(m_timer.release()),
[](uv_handle_t* handle)
{
delete reinterpret_cast<uv_timer_t*>(handle);
});
}
}
void Timer::Execute()
{
m_cb(this);
}
} // namespace EQ
+15 -53
View File
@@ -19,69 +19,31 @@
#include "event_loop.h" #include "event_loop.h"
#include <cstring>
#include <functional> #include <functional>
#include <memory>
typedef struct uv_timer_s uv_timer_t;
namespace EQ { namespace EQ {
class Timer class Timer
{ {
public: public:
Timer(std::function<void(Timer *)> cb) using callback_t = std::function<void(Timer*)>;
{
m_timer = nullptr;
m_cb = cb;
}
Timer(uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb) Timer(callback_t cb);
{ Timer(uint64_t duration_ms, bool repeats, callback_t cb);
m_timer = nullptr;
m_cb = cb;
Start(duration_ms, repeats);
}
~Timer() ~Timer();
{
Stop();
}
void Start(uint64_t duration_ms, bool repeats) { void Start(uint64_t duration_ms, bool repeats);
auto loop = EventLoop::Get().Handle(); void Stop();
if (!m_timer) {
m_timer = new uv_timer_t;
memset(m_timer, 0, sizeof(uv_timer_t));
uv_timer_init(loop, m_timer);
m_timer->data = this;
if (repeats) {
uv_timer_start(m_timer, [](uv_timer_t *handle) {
Timer *t = (Timer*)handle->data;
t->Execute();
}, duration_ms, duration_ms);
}
else {
uv_timer_start(m_timer, [](uv_timer_t *handle) {
Timer *t = (Timer*)handle->data;
t->Stop();
t->Execute();
}, duration_ms, 0);
}
}
}
void Stop() {
if (m_timer) {
uv_close((uv_handle_t*)m_timer, [](uv_handle_t* handle) {
delete (uv_timer_t *)handle;
});
m_timer = nullptr;
}
}
private: private:
void Execute() { void Execute();
m_cb(this);
}
uv_timer_t *m_timer; std::unique_ptr<uv_timer_t> m_timer;
std::function<void(Timer*)> m_cb; callback_t m_cb;
}; };
}
} // namespace EQ
+1 -1
View File
@@ -61,7 +61,7 @@ void PlayerEventLogs::Init()
continue; continue;
} }
m_settings[e.id] = e; m_settings[e.id] = e;
db.emplace_back(e.id); db.emplace_back(static_cast<int>(e.id));
} }
std::vector<PlayerEventLogSettingsRepository::PlayerEventLogSettings> settings_to_insert{}; std::vector<PlayerEventLogSettingsRepository::PlayerEventLogSettings> settings_to_insert{};
+2 -2
View File
@@ -46,7 +46,7 @@
#define GUILD_INITIATE 7 #define GUILD_INITIATE 7
#define GUILD_RECRUIT 8 #define GUILD_RECRUIT 8
typedef enum { enum GuildAction {
GUILD_ACTION_BANNER_CHANGE = 1, GUILD_ACTION_BANNER_CHANGE = 1,
GUILD_ACTION_BANNER_PLANT = 2, GUILD_ACTION_BANNER_PLANT = 2,
GUILD_ACTION_BANNER_REMOVE = 3, GUILD_ACTION_BANNER_REMOVE = 3,
@@ -77,6 +77,6 @@ typedef enum {
GUILD_ACTION_REAL_ESTATE_GUILD_PLOT_SELL = 28, GUILD_ACTION_REAL_ESTATE_GUILD_PLOT_SELL = 28,
GUILD_ACTION_REAL_ESTATE_MODIFY_TROPHIES = 29, GUILD_ACTION_REAL_ESTATE_MODIFY_TROPHIES = 29,
GUILD_ACTION_MEMBERS_DEMOTE_SELF = 30, GUILD_ACTION_MEMBERS_DEMOTE_SELF = 30,
} GuildAction; };
constexpr int format_as(GuildAction action) { return static_cast<int>(action); } constexpr int format_as(GuildAction action) { return static_cast<int>(action); }
+1 -1
View File
@@ -349,7 +349,7 @@ bool EQ::InventoryProfile::SwapItem(
fail_state = swapLevel; fail_state = swapLevel;
return false; return false;
} }
if (source_item_instance->IsEvolving() > 0) { if (source_item_instance->IsEvolving()) {
source_item_instance->SetEvolveEquipped(true); source_item_instance->SetEvolveEquipped(true);
} }
} }
+20 -111
View File
@@ -25,14 +25,24 @@
#include "common/net/dns.h" #include "common/net/dns.h"
#include "fmt/format.h" #include "fmt/format.h"
#include <cstring> #include <iostream>
#include <csignal> #include <string>
#include <vector> #include <vector>
/** #ifdef _WIN32
* @param ip #include <winsock2.h>
* @return #include <ws2tcpip.h>
*/ #pragma comment(lib, "Ws2_32.lib")
#else
#include <arpa/inet.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
uint32_t IpUtil::IPToUInt(const std::string &ip) uint32_t IpUtil::IPToUInt(const std::string &ip)
{ {
int a, b, c, d; int a, b, c, d;
@@ -49,12 +59,6 @@ uint32_t IpUtil::IPToUInt(const std::string &ip)
return addr; return addr;
} }
/**
* @param ip
* @param network
* @param mask
* @return
*/
bool IpUtil::IsIpInRange(const std::string &ip, const std::string &network, const std::string &mask) bool IpUtil::IsIpInRange(const std::string &ip, const std::string &network, const std::string &mask)
{ {
uint32_t ip_addr = IpUtil::IPToUInt(ip); uint32_t ip_addr = IpUtil::IPToUInt(ip);
@@ -67,10 +71,6 @@ bool IpUtil::IsIpInRange(const std::string &ip, const std::string &network, cons
return ip_addr >= net_lower && ip_addr <= net_upper; return ip_addr >= net_lower && ip_addr <= net_upper;
} }
/**
* @param ip
* @return
*/
bool IpUtil::IsIpInPrivateRfc1918(const std::string &ip) bool IpUtil::IsIpInPrivateRfc1918(const std::string &ip)
{ {
return ( return (
@@ -80,23 +80,6 @@ bool IpUtil::IsIpInPrivateRfc1918(const std::string &ip)
); );
} }
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Ws2_32.lib")
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include <fcntl.h>
#endif
#include <iostream>
#include <string>
#include <cstring>
std::string IpUtil::GetLocalIPAddress() std::string IpUtil::GetLocalIPAddress()
{ {
#ifdef _WIN32 #ifdef _WIN32
@@ -200,90 +183,16 @@ std::string IpUtil::GetPublicIPAddress()
return {}; return {};
} }
std::string IpUtil::DNSLookupSync(const std::string &addr, int port)
{
auto task_runner = new EQ::Event::TaskScheduler();
auto res = task_runner->Enqueue(
[&]() -> std::string {
bool running = true;
std::string ret;
EQ::Net::DNSLookup(
addr, port, false, [&](const std::string &addr) {
ret = addr;
if (addr.empty()) {
ret = "";
running = false;
}
return ret;
}
);
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
auto &loop = EQ::EventLoop::Get();
while (running) {
if (!ret.empty()) {
running = false;
}
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() > 1500) {
LogInfo(
"Deadline exceeded [{}]",
1500
);
running = false;
}
loop.Process();
}
return ret;
}
);
std::string result = res.get();
safe_delete(task_runner);
return result;
}
bool IpUtil::IsIPAddress(const std::string &ip_address) bool IpUtil::IsIPAddress(const std::string &ip_address)
{ {
struct sockaddr_in sa{}; sockaddr_in sa{};
int result = inet_pton(AF_INET, ip_address.c_str(), &(sa.sin_addr)); int result = inet_pton(AF_INET, ip_address.c_str(), &(sa.sin_addr));
return result != 0; return result != 0;
} }
#include <iostream> bool IpUtil::IsPortInUse(const std::string& ip, int port)
#ifdef _WIN32 {
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib") // Link against Winsock library
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
#include <iostream>
#include <string>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h> // For inet_pton
#pragma comment(lib, "ws2_32.lib") // Link against Winsock library
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> // For inet_pton
#include <unistd.h>
#endif
bool IpUtil::IsPortInUse(const std::string& ip, int port) {
bool in_use = false; bool in_use = false;
#ifdef _WIN32 #ifdef _WIN32
@@ -326,7 +235,7 @@ bool IpUtil::IsPortInUse(const std::string& ip, int port) {
return true; // Assume in use on failure return true; // Assume in use on failure
} }
if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) { if (bind(sock, (sockaddr*)&addr, sizeof(addr)) < 0) {
in_use = true; // Bind failed, port is in use in_use = true; // Bind failed, port is in use
} }
+1 -4
View File
@@ -29,10 +29,7 @@ public:
static bool IsIpInPrivateRfc1918(const std::string &ip); static bool IsIpInPrivateRfc1918(const std::string &ip);
static std::string GetLocalIPAddress(); static std::string GetLocalIPAddress();
static std::string GetPublicIPAddress(); static std::string GetPublicIPAddress();
static std::string DNSLookupSync(
const std::string &addr,
int port
);
static bool IsIPAddress(const std::string &ip_address); static bool IsIPAddress(const std::string &ip_address);
static bool IsPortInUse(const std::string& ip, int port); static bool IsPortInUse(const std::string& ip, int port);
+1
View File
@@ -320,6 +320,7 @@ bool EQ::ItemInstance::IsAugmentSlotAvailable(int32 augment_type, uint8 slot) co
} }
return ( return (
slot < invaug::SOCKET_COUNT &&
( (
augment_type == -1 || augment_type == -1 ||
( (
-8
View File
@@ -271,11 +271,7 @@ static size_t const stackLimit_g = JSONCPP_DEPRECATED_STACK_LIMIT; // see readVa
namespace Json { namespace Json {
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
typedef std::unique_ptr<CharReader> CharReaderPtr; typedef std::unique_ptr<CharReader> CharReaderPtr;
#else
typedef std::auto_ptr<CharReader> CharReaderPtr;
#endif
// Implementation of class Features // Implementation of class Features
// //////////////////////////////// // ////////////////////////////////
@@ -4153,11 +4149,7 @@ Value& Path::make(Value& root) const {
namespace Json { namespace Json {
#if __cplusplus >= 201103L || (defined(_CPPLIB_VER) && _CPPLIB_VER >= 520)
typedef std::unique_ptr<StreamWriter> StreamWriterPtr; typedef std::unique_ptr<StreamWriter> StreamWriterPtr;
#else
typedef std::auto_ptr<StreamWriter> StreamWriterPtr;
#endif
static bool containsControlCharacter(const char* str) { static bool containsControlCharacter(const char* str) {
while (*str) { while (*str) {
+1 -2
View File
@@ -45,5 +45,4 @@ struct LootItem {
uint32 lootdrop_id; // required for zone state referencing uint32 lootdrop_id; // required for zone state referencing
}; };
typedef std::list<LootItem*> LootItems; using LootItems = std::list<LootItem*>;
+192
View File
@@ -0,0 +1,192 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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 "ksm.h"
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/mman.h> // For madvise
#include <unistd.h> // For sysconf, sbrk
#endif
#ifdef _WIN32
// Windows-specific functionality
void* PageAlignedAllocatorBase::allocateInternal(size_t size, size_t alignment)
{
void* ptr = malloc(size);
if (!ptr)
{
throw std::bad_alloc();
}
return ptr;
}
size_t PageAlignedAllocatorBase::getPageSize() const
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
return sysInfo.dwPageSize; // Page size in bytes
}
namespace KSM {
// Windows-specific placeholder functions (no-op)
void CheckPageAlignment(void* ptr)
{
}
void* AllocatePageAligned(size_t size)
{
return memset(malloc(size), 0, size);
}
void MarkMemoryForKSM(void* start, size_t size)
{
}
void AlignHeapToPageBoundary()
{
}
void* MarkHeapStart()
{
return nullptr;
}
size_t MeasureHeapUsage(void* start)
{
return 0;
}
} // namespace KSM
#else
// Linux-specific functionality
void* PageAlignedAllocatorBase::allocateInternal(size_t size, size_t alignment)
{
void* ptr = nullptr;
if (posix_memalign(&ptr, alignment, size) != 0)
{
throw std::bad_alloc();
}
return ptr;
}
size_t PageAlignedAllocatorBase::getPageSize() const
{
return static_cast<size_t>(sysconf(_SC_PAGESIZE));
}
namespace KSM {
void CheckPageAlignment(void* ptr)
{
size_t page_size = sysconf(_SC_PAGESIZE);
if (reinterpret_cast<uintptr_t>(ptr) % page_size == 0)
{
LogKSMDetail("Memory is page-aligned [{}]", ptr);
}
else
{
LogKSMDetail("Memory is NOT page-aligned [{}]", ptr);
}
}
void* AllocatePageAligned(size_t size)
{
size_t page_size = sysconf(_SC_PAGESIZE);
void* aligned_ptr = nullptr;
if (posix_memalign(&aligned_ptr, page_size, size) != 0)
{
LogKSM("Failed to allocate page-aligned memory on Linux. page_size [{}] size [{}] bytes", page_size, size);
}
std::memset(aligned_ptr, 0, size);
return aligned_ptr;
}
void MarkMemoryForKSM(void* start, size_t size)
{
if (madvise(start, size, MADV_MERGEABLE) == 0)
{
LogKSM("Marked memory for KSM | start [{}] size [{}] bytes", start, size);
}
else
{
perror("madvise failed");
}
}
void AlignHeapToPageBoundary()
{
size_t page_size = sysconf(_SC_PAGESIZE);
if (page_size == 0)
{
LogKSM("Failed to retrieve page size SC_PAGESIZE [{}]", page_size);
return;
}
void* current_break = sbrk(0);
if (current_break == (void*)-1)
{
LogKSM("Failed to retrieve the current program break");
return;
}
uintptr_t current_address = reinterpret_cast<uintptr_t>(current_break);
size_t misalignment = current_address % page_size;
if (misalignment != 0)
{
size_t adjustment = page_size - misalignment;
if (sbrk(adjustment) == (void*)-1)
{
LogKSM("Failed to align heap to page boundary. adjustment [{}] bytes", adjustment);
return;
}
}
LogKSMDetail("Heap aligned to next page boundary. Current break [{}]", sbrk(0));
}
void* MarkHeapStart()
{
void* current_pos = sbrk(0);
AlignHeapToPageBoundary();
return current_pos;
}
size_t MeasureHeapUsage(void* start)
{
void* current_break = sbrk(0);
return static_cast<char*>(current_break) - static_cast<char*>(start);
}
} // namespace KSM
#endif
+74
View File
@@ -0,0 +1,74 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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/>.
*/
#pragma once
#include "common/eqemu_logsys.h"
class PageAlignedAllocatorBase
{
protected:
void* allocateInternal(size_t amount, size_t alignment);
size_t getPageSize() const;
};
// Page-aligned allocator for std::vector
template <typename T>
class PageAlignedAllocator : public PageAlignedAllocatorBase
{
public:
using value_type = T;
PageAlignedAllocator() noexcept = default;
template <typename U>
PageAlignedAllocator(const PageAlignedAllocator<U>&) noexcept {}
T* allocate(std::size_t n)
{
size_t size = n * sizeof(T);
return static_cast<T*>(allocateInternal(size, getPageSize()));
}
void deallocate(T* p, std::size_t) noexcept
{
free(p);
}
};
template <typename T, typename U>
bool operator==(const PageAlignedAllocator<T>&, const PageAlignedAllocator<U>&) noexcept {
return true;
}
template <typename T, typename U>
bool operator!=(const PageAlignedAllocator<T>&, const PageAlignedAllocator<U>&) noexcept {
return false;
}
// Kernel Samepage Merging (KSM) functionality
namespace KSM {
void CheckPageAlignment(void* ptr);
void* AllocatePageAligned(size_t size);
void MarkMemoryForKSM(void* start, size_t size);
void AlignHeapToPageBoundary();
void* MarkHeapStart();
size_t MeasureHeapUsage(void* start);
} // namespace KSM
-234
View File
@@ -1,234 +0,0 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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/>.
*/
#pragma once
#include "common/eqemu_logsys.h"
#include <iostream>
#include <vector>
#include <cstring>
#ifdef _WIN32
#include <malloc.h> // For _aligned_malloc, _aligned_free
#include <windows.h>
#else
#include <sys/mman.h> // For madvise
#include <unistd.h> // For sysconf, sbrk
#endif
// Page-aligned allocator for std::vector
template <typename T>
class PageAlignedAllocator {
public:
using value_type = T;
PageAlignedAllocator() noexcept = default;
template <typename U>
PageAlignedAllocator(const PageAlignedAllocator<U>&) noexcept {}
T* allocate(std::size_t n) {
void* ptr = nullptr;
size_t size = n * sizeof(T);
#ifdef _WIN32
// Simply allocate memory without alignment
ptr = malloc(size);
if (!ptr) throw std::bad_alloc();
#else
size_t alignment = getPageSize(); // Get the system's page size
if (posix_memalign(&ptr, alignment, size) != 0) {
throw std::bad_alloc();
}
#endif
return static_cast<T*>(ptr);
}
void deallocate(T* p, std::size_t) noexcept {
free(p);
}
private:
size_t getPageSize() const
{
#ifdef _WIN32
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
return sysInfo.dwPageSize; // Page size in bytes
#else
return static_cast<size_t>(sysconf(_SC_PAGESIZE));
#endif
};
};
template <typename T, typename U>
bool operator==(const PageAlignedAllocator<T>&, const PageAlignedAllocator<U>&) noexcept {
return true;
}
template <typename T, typename U>
bool operator!=(const PageAlignedAllocator<T>&, const PageAlignedAllocator<U>&) noexcept {
return false;
}
// Kernel Samepage Merging (KSM) functionality
namespace KSM {
#ifdef _WIN32
// Windows-specific placeholder functions (no-op)
inline void CheckPageAlignment(void* ptr) {
}
inline void* AllocatePageAligned(size_t size) {
return memset(malloc(size), 0, size);
}
inline void MarkMemoryForKSM(void* start, size_t size) {
}
inline void AlignHeapToPageBoundary() {
}
inline void* MarkHeapStart() {
return nullptr;
}
inline size_t MeasureHeapUsage(void* start) {
return 0;
}
#else
// Linux-specific functionality
inline void CheckPageAlignment(void* ptr) {
size_t page_size = sysconf(_SC_PAGESIZE);
if (reinterpret_cast<uintptr_t>(ptr) % page_size == 0) {
LogKSMDetail("Memory is page-aligned [{}]", ptr);
} else {
LogKSMDetail("Memory is NOT page-aligned [{}]", ptr);
}
}
inline void* AllocatePageAligned(size_t size) {
size_t page_size = sysconf(_SC_PAGESIZE);
void* aligned_ptr = nullptr;
if (posix_memalign(&aligned_ptr, page_size, size) != 0) {
LogKSM("Failed to allocate page-aligned memory on Linux. page_size [{}] size [{}] bytes", page_size, size);
}
std::memset(aligned_ptr, 0, size);
return aligned_ptr;
}
inline void MarkMemoryForKSM(void* start, size_t size) {
if (madvise(start, size, MADV_MERGEABLE) == 0) {
LogKSM("Marked memory for KSM | start [{}] size [{}] bytes", start, size);
} else {
perror("madvise failed");
}
}
inline void AlignHeapToPageBoundary() {
size_t page_size = sysconf(_SC_PAGESIZE);
if (page_size == 0) {
LogKSM("Failed to retrieve page size SC_PAGESIZE [{}]", page_size);
return;
}
void* current_break = sbrk(0);
if (current_break == (void*)-1) {
LogKSM("Failed to retrieve the current program break");
return;
}
uintptr_t current_address = reinterpret_cast<uintptr_t>(current_break);
size_t misalignment = current_address % page_size;
if (misalignment != 0) {
size_t adjustment = page_size - misalignment;
if (sbrk(adjustment) == (void*)-1) {
LogKSM("Failed to align heap to page boundary. adjustment [{}] bytes", adjustment);
return;
}
}
LogKSMDetail("Heap aligned to next page boundary. Current break [{}]", sbrk(0));
}
inline void* MarkHeapStart() {
void* current_pos = sbrk(0);
AlignHeapToPageBoundary();
return current_pos;
}
inline size_t MeasureHeapUsage(void* start) {
void* current_break = sbrk(0);
return static_cast<char*>(current_break) - static_cast<char*>(start);
}
#endif
inline size_t getPageSize()
{
#ifdef _WIN32
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
return sysInfo.dwPageSize; // Page size in bytes
#else
return static_cast<size_t>(sysconf(_SC_PAGESIZE)); // POSIX page size
#endif
};
template <typename T>
inline void PageAlignVectorAligned(std::vector<T, PageAlignedAllocator<T>>& vec) {
if (vec.empty()) {
return;
}
size_t page_size = getPageSize();
void* start = vec.data();
size_t size = vec.size() * sizeof(T);
// Check if the memory is page-aligned
if (reinterpret_cast<std::uintptr_t>(start) % page_size != 0) {
// Allocate a new aligned vector
std::vector<T, PageAlignedAllocator<T>> aligned_vec(vec.get_allocator());
aligned_vec.reserve(vec.capacity()); // Match capacity to avoid reallocation during copy
// Copy elements from the original vector
aligned_vec.insert(aligned_vec.end(), vec.begin(), vec.end());
// Swap the aligned vector with the original vector
vec.swap(aligned_vec);
// Clear the temporary aligned vector to free its memory
aligned_vec.clear();
// Verify the new alignment
start = vec.data();
if (reinterpret_cast<std::uintptr_t>(start) % page_size != 0) {
throw std::runtime_error("Failed to align vector memory to page boundaries.");
}
LogKSMDetail("Vector reallocated to ensure page alignment. start [{}] size [{}] bytes", start, size);
} else {
LogKSMDetail("Vector is already page-aligned. start [{}] size [{}] bytes", start, size);
}
#ifndef _WIN32
// Mark memory for KSM (only on non-Windows systems)
MarkMemoryForKSM(start, size);
#endif
}
}
-162
View File
@@ -1,162 +0,0 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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 "mutex.h"
#include <iostream>
#define DEBUG_MUTEX_CLASS 0
#if DEBUG_MUTEX_CLASS >= 1
#endif
#ifdef _WINDOWS
bool IsTryLockSupported();
bool TrylockSupported = IsTryLockSupported();
bool IsTryLockSupported() {
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
{
// If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO.
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) {
#if DEBUG_MUTEX_CLASS >= 1
std::cout << "Mutex::trylock() NOT supported" << std::endl;
#endif
return false;
}
}
// Tests for Windows NT product family.
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion >= 4) {
#if DEBUG_MUTEX_CLASS >= 1
std::cout << "Mutex::trylock() SUPPORTED" << std::endl;
#endif
return true;
}
else {
#if DEBUG_MUTEX_CLASS >= 1
std::cout << "Mutex::trylock() NOT supported" << std::endl;
#endif
return false;
}
}
#endif
Mutex::Mutex() {
#if DEBUG_MUTEX_CLASS >= 7
std::cout << "Constructing Mutex" << std::endl;
#endif
#ifdef _WINDOWS
InitializeCriticalSection(&CSMutex);
#else
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
#if defined(__CYGWIN__) || defined(__APPLE__) || defined(FREEBSD)
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#else
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
#endif
pthread_mutex_init(&CSMutex, &attr);
pthread_mutexattr_destroy(&attr);
#endif
}
Mutex::~Mutex() {
#ifdef _WINDOWS
DeleteCriticalSection(&CSMutex);
#else
#endif
}
void Mutex::lock() {
#if DEBUG_MUTEX_CLASS >= 5
if (!trylock()) {
std::cout << "Locking Mutex: Having to wait" << std::endl;
#ifdef _WINDOWS
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
#endif
}
#else
#ifdef _WINDOWS
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
#endif
#endif
}
bool Mutex::trylock() {
#ifdef _WINDOWS
#if(_WIN32_WINNT >= 0x0400)
if (TrylockSupported)
return TryEnterCriticalSection(&CSMutex);
else {
EnterCriticalSection(&CSMutex);
return true;
}
#else
EnterCriticalSection(&CSMutex);
return true;
#endif
#else
return (pthread_mutex_trylock(&CSMutex) == 0);
#endif
}
void Mutex::unlock() {
#ifdef _WINDOWS
LeaveCriticalSection(&CSMutex);
#else
pthread_mutex_unlock(&CSMutex);
#endif
}
LockMutex::LockMutex(Mutex* in_mut, bool iLock) {
mut = in_mut;
locked = iLock;
if (locked) {
mut->lock();
}
}
LockMutex::~LockMutex() {
if (locked) {
mut->unlock();
}
}
void LockMutex::unlock() {
if (locked)
mut->unlock();
locked = false;
}
void LockMutex::lock() {
if (!locked)
mut->lock();
locked = true;
}
+10 -6
View File
@@ -18,7 +18,6 @@
#include "mysql_stmt.h" #include "mysql_stmt.h"
#include "common/eqemu_logsys.h" #include "common/eqemu_logsys.h"
#include "common/mutex.h"
#include "common/timer.h" #include "common/timer.h"
#include <charconv> #include <charconv>
@@ -31,14 +30,19 @@ void PreparedStmt::StmtDeleter::operator()(MYSQL_STMT* stmt) noexcept
// The connection must be locked when closing the stmt to avoid mysql errors // The connection must be locked when closing the stmt to avoid mysql errors
// in case another thread tries to use it during the close. If the mutex is // in case another thread tries to use it during the close. If the mutex is
// changed to one that throws then exceptions need to be caught here. // changed to one that throws then exceptions need to be caught here.
LockMutex lock(mutex); std::scoped_lock lock(mutex);
mysql_stmt_close(stmt); mysql_stmt_close(stmt);
} }
PreparedStmt::PreparedStmt(MYSQL& mysql, std::string query, Mutex* mutex, StmtOptions opts) PreparedStmt::PreparedStmt(MYSQL& mysql, std::string query, DBcore::Mutex& mutex, StmtOptions opts)
: m_stmt(mysql_stmt_init(&mysql), { mutex }), m_query(std::move(query)), m_mutex(mutex), m_options(opts) : m_stmt(mysql_stmt_init(&mysql), { mutex })
, m_query(std::move(query))
, m_options(opts)
, m_mutex(mutex)
{ {
LockMutex lock(m_mutex); std::scoped_lock lock(m_mutex);
if (mysql_stmt_prepare(m_stmt.get(), m_query.c_str(), static_cast<unsigned long>(m_query.size())) != 0) if (mysql_stmt_prepare(m_stmt.get(), m_query.c_str(), static_cast<unsigned long>(m_query.size())) != 0)
{ {
ThrowError(fmt::format("Prepare error: {}", GetStmtError())); ThrowError(fmt::format("Prepare error: {}", GetStmtError()));
@@ -186,7 +190,7 @@ void PreparedStmt::CheckArgs(size_t argc)
StmtResult PreparedStmt::DoExecute() StmtResult PreparedStmt::DoExecute()
{ {
BenchTimer timer; BenchTimer timer;
LockMutex lock(m_mutex); std::scoped_lock lock(m_mutex);
if (m_need_bind && mysql_stmt_bind_param(m_stmt.get(), m_params.data()) != 0) if (m_need_bind && mysql_stmt_bind_param(m_stmt.get(), m_params.data()) != 0)
{ {
+7 -4
View File
@@ -17,10 +17,12 @@
*/ */
#pragma once #pragma once
#include "mysql.h" #include "common/dbcore.h"
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <mutex>
#include <optional> #include <optional>
#include <span> #include <span>
#include <string_view> #include <string_view>
@@ -183,7 +185,7 @@ public:
int64_t, uint64_t, float, double, bool, std::string_view, std::nullptr_t>; int64_t, uint64_t, float, double, bool, std::string_view, std::nullptr_t>;
PreparedStmt() = delete; PreparedStmt() = delete;
PreparedStmt(MYSQL& mysql, std::string query, Mutex* mutex, StmtOptions opts = {}); PreparedStmt(MYSQL& mysql, std::string query, DBcore::Mutex& mutex, StmtOptions opts = {});
const std::string& GetQuery() const { return m_query; } const std::string& GetQuery() const { return m_query; }
StmtOptions GetOptions() const { return m_options; } StmtOptions GetOptions() const { return m_options; }
@@ -219,7 +221,8 @@ private:
struct StmtDeleter struct StmtDeleter
{ {
Mutex* mutex = nullptr; DBcore::Mutex& mutex;
void operator()(MYSQL_STMT* stmt) noexcept; void operator()(MYSQL_STMT* stmt) noexcept;
}; };
@@ -232,7 +235,7 @@ private:
std::string m_query; std::string m_query;
StmtOptions m_options = {}; StmtOptions m_options = {};
bool m_need_bind = true; bool m_need_bind = true;
Mutex* m_mutex = nullptr; // connection mutex DBcore::Mutex& m_mutex; // connection mutex
}; };
} // namespace mysql } // namespace mysql
+131
View File
@@ -0,0 +1,131 @@
/* EQEmu: EQEmulator
Copyright (C) 2001-2026 EQEmu Development Team
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 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 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 "dns.h"
#include "common/eqemu_logsys.h"
#include "common/event/event_loop.h"
#include "common/event/task_scheduler.h"
#include "uv.h"
namespace EQ::Net {
struct DNSBaton
{
dns_callback_t cb;
bool ipv6;
};
void DNSLookup(const std::string& addr, int port, bool ipv6, dns_callback_t cb)
{
addrinfo hints = {};
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
uv_loop_t* loop = EQ::EventLoop::Get().Handle();
uv_getaddrinfo_t* resolver = new uv_getaddrinfo_t();
memset(resolver, 0, sizeof(uv_getaddrinfo_t));
std::string port_str = std::to_string(port);
DNSBaton* baton = new DNSBaton();
baton->cb = std::move(cb);
baton->ipv6 = ipv6;
resolver->data = baton;
uv_getaddrinfo(loop, resolver, [](uv_getaddrinfo_t* req, int status, addrinfo* result)
{
DNSBaton* baton = static_cast<DNSBaton*>(req->data);
dns_callback_t dns_callback = std::move(baton->cb);
bool ipv6 = baton->ipv6;
delete baton;
delete req;
if (status < 0)
{
dns_callback({});
return;
}
char addr[40] = {};
if (ipv6)
{
uv_ip6_name(reinterpret_cast<sockaddr_in6*>(result->ai_addr), addr, 40);
}
else
{
uv_ip4_name(reinterpret_cast<sockaddr_in*>(result->ai_addr), addr, 40);
}
uv_freeaddrinfo(result);
dns_callback(addr);
}, addr.c_str(), port_str.c_str(), &hints);
}
std::string DNSLookupSync(const std::string& addr, int port, bool ipv6 /* = false */)
{
EQ::Event::TaskScheduler task_runner;
auto res = task_runner.Enqueue(
[addr, port, ipv6]() -> std::string
{
bool running = true;
std::string ret;
EQ::Net::DNSLookup(
addr, port, ipv6, [&](const std::string& addr) {
ret = addr;
running = !addr.empty();
return ret;
}
);
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
auto& loop = EQ::EventLoop::Get();
while (running) {
if (!ret.empty()) {
running = false;
}
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count() > 1500) {
LogInfo(
"Deadline exceeded [{}]",
1500
);
running = false;
}
loop.Process();
}
return ret;
});
return res.get();
}
} // namespace EQ::Net
+5 -53
View File
@@ -17,63 +17,15 @@
*/ */
#pragma once #pragma once
#include "common/event/event_loop.h"
#include <functional> #include <functional>
#include <string> #include <string>
namespace EQ namespace EQ::Net {
{
namespace Net
{
static void DNSLookup(const std::string &addr, int port, bool ipv6, std::function<void(const std::string&)> cb) {
struct DNSBaton
{
std::function<void(const std::string&)> cb;
bool ipv6;
};
addrinfo hints; using dns_callback_t = std::function<void(const std::string&)>;
memset(&hints, 0, sizeof(addrinfo));
hints.ai_family = PF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
auto loop = EQ::EventLoop::Get().Handle(); void DNSLookup(const std::string& addr, int port, bool ipv6, dns_callback_t cb);
uv_getaddrinfo_t *resolver = new uv_getaddrinfo_t();
memset(resolver, 0, sizeof(uv_getaddrinfo_t));
auto port_str = std::to_string(port);
DNSBaton *baton = new DNSBaton();
baton->cb = cb;
baton->ipv6 = ipv6;
resolver->data = baton;
uv_getaddrinfo(loop, resolver, [](uv_getaddrinfo_t* req, int status, addrinfo* res) { std::string DNSLookupSync(const std::string& addr, int port, bool ipv6 = false);
DNSBaton *baton = (DNSBaton*)req->data;
if (status < 0) {
auto cb = baton->cb;
delete baton;
delete req;
cb("");
return;
}
char addr[40] = { 0 }; } // namespace EQ::Net
if (baton->ipv6) {
uv_ip6_name((struct sockaddr_in6*)res->ai_addr, addr, 40);
}
else {
uv_ip4_name((struct sockaddr_in*)res->ai_addr, addr, 40);
}
auto cb = baton->cb;
delete baton;
delete req;
uv_freeaddrinfo(res);
cb(addr);
}, addr.c_str(), port_str.c_str(), &hints);
}
}
}
+2
View File
@@ -19,7 +19,9 @@
#include "common/net/tcp_connection_pooling.h" #include "common/net/tcp_connection_pooling.h"
#include "common/platform/platform.h"
#include "uv.h" #include "uv.h"
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
+2 -2
View File
@@ -49,9 +49,9 @@ namespace EQ
WebsocketException(const std::string &msg) WebsocketException(const std::string &msg)
: _msg(msg.empty() ? "Unknown Error" : msg) { } : _msg(msg.empty() ? "Unknown Error" : msg) { }
~WebsocketException() throw() {} ~WebsocketException() noexcept {}
virtual char const *what() const throw() { virtual char const *what() const noexcept override {
return _msg.c_str(); return _msg.c_str();
} }
private: private:
+13 -14
View File
@@ -17,17 +17,16 @@
*/ */
#pragma once #pragma once
static constexpr char OP_SessionRequest = 0x01;
static const char OP_SessionRequest = 0x01; static constexpr char OP_SessionResponse = 0x02;
static const char OP_SessionResponse = 0x02; static constexpr char OP_Combined = 0x03;
static const char OP_Combined = 0x03; static constexpr char OP_SessionDisconnect = 0x05;
static const char OP_SessionDisconnect = 0x05; static constexpr char OP_KeepAlive = 0x06;
static const char OP_KeepAlive = 0x06; static constexpr char OP_SessionStatRequest = 0x07;
static const char OP_SessionStatRequest = 0x07; static constexpr char OP_SessionStatResponse = 0x08;
static const char OP_SessionStatResponse= 0x08; static constexpr char OP_Packet = 0x09;
static const char OP_Packet = 0x09; static constexpr char OP_Fragment = 0x0d;
static const char OP_Fragment = 0x0d; static constexpr char OP_OutOfOrderAck = 0x11;
static const char OP_OutOfOrderAck = 0x11; static constexpr char OP_Ack = 0x15;
static const char OP_Ack = 0x15; static constexpr char OP_AppCombined = 0x19;
static const char OP_AppCombined = 0x19; static constexpr char OP_OutOfSession = 0x1d;
static const char OP_OutOfSession = 0x1d;
+19 -16
View File
@@ -142,10 +142,12 @@ RegularOpcodeManager::~RegularOpcodeManager() {
safe_delete_array(eq_to_emu); safe_delete_array(eq_to_emu);
} }
bool RegularOpcodeManager::LoadOpcodes(const char *filename, bool report_errors) { bool RegularOpcodeManager::LoadOpcodes(const char *filename, bool report_errors)
{
std::scoped_lock lock(MOpcodes);
NormalMemStrategy s; NormalMemStrategy s;
s.it = this; s.it = this;
MOpcodes.lock();
loaded = true; loaded = true;
eq_to_emu = new EmuOpcode[MAX_EQ_OPCODE]; eq_to_emu = new EmuOpcode[MAX_EQ_OPCODE];
@@ -158,32 +160,30 @@ bool RegularOpcodeManager::LoadOpcodes(const char *filename, bool report_errors)
memset(emu_to_eq, 0, sizeof(uint16)*_maxEmuOpcode); memset(emu_to_eq, 0, sizeof(uint16)*_maxEmuOpcode);
bool ret = LoadOpcodesFile(filename, &s, report_errors); bool ret = LoadOpcodesFile(filename, &s, report_errors);
MOpcodes.unlock();
return ret; return ret;
} }
bool RegularOpcodeManager::ReloadOpcodes(const char *filename, bool report_errors) { bool RegularOpcodeManager::ReloadOpcodes(const char* filename, bool report_errors)
{
if (!loaded) if (!loaded)
return(LoadOpcodes(filename)); return LoadOpcodes(filename);
std::scoped_lock lock(MOpcodes);
NormalMemStrategy s; NormalMemStrategy s;
s.it = this; s.it = this;
MOpcodes.lock();
memset(eq_to_emu, 0, sizeof(uint16) * MAX_EQ_OPCODE); memset(eq_to_emu, 0, sizeof(uint16) * MAX_EQ_OPCODE);
return LoadOpcodesFile(filename, &s, report_errors);
bool ret = LoadOpcodesFile(filename, &s, report_errors);
MOpcodes.unlock();
return(ret);
} }
uint16 RegularOpcodeManager::EmuToEQ(const EmuOpcode emu_op) { uint16 RegularOpcodeManager::EmuToEQ(const EmuOpcode emu_op) {
//opcode is checked for validity in GetEQOpcode //opcode is checked for validity in GetEQOpcode
uint16 res; uint16 res;
MOpcodes.lock(); {
std::scoped_lock lock(MOpcodes);
res = emu_to_eq[emu_op]; res = emu_to_eq[emu_op];
MOpcodes.unlock(); }
LogNetcodeDetail("[Opcode Manager] Translate emu [{}] ({:#06x}) eq [{:#06x}]", OpcodeNames[emu_op], emu_op, res); LogNetcodeDetail("[Opcode Manager] Translate emu [{}] ({:#06x}) eq [{:#06x}]", OpcodeNames[emu_op], emu_op, res);
@@ -193,15 +193,18 @@ uint16 RegularOpcodeManager::EmuToEQ(const EmuOpcode emu_op) {
return(res); return(res);
} }
EmuOpcode RegularOpcodeManager::EQToEmu(const uint16 eq_op) { EmuOpcode RegularOpcodeManager::EQToEmu(const uint16 eq_op)
{
//opcode is checked for validity in GetEmuOpcode //opcode is checked for validity in GetEmuOpcode
//Disabled since current live EQ uses the entire uint16 bitspace for opcodes //Disabled since current live EQ uses the entire uint16 bitspace for opcodes
// if(eq_op > MAX_EQ_OPCODE) // if(eq_op > MAX_EQ_OPCODE)
// return(OP_Unknown); // return(OP_Unknown);
EmuOpcode res; EmuOpcode res;
MOpcodes.lock(); {
std::scoped_lock lock(MOpcodes);
res = eq_to_emu[eq_op]; res = eq_to_emu[eq_op];
MOpcodes.unlock(); }
#ifdef DEBUG_TRANSLATE #ifdef DEBUG_TRANSLATE
fprintf(stderr, "M Translate EQ 0x%.4x to Emu %s (%d)\n", eq_op, OpcodeNames[res], res); fprintf(stderr, "M Translate EQ 0x%.4x to Emu %s (%d)\n", eq_op, OpcodeNames[res], res);
#endif #endif
+16 -12
View File
@@ -18,10 +18,10 @@
#pragma once #pragma once
#include "common/emu_opcodes.h" #include "common/emu_opcodes.h"
#include "common/mutex.h"
#include "common/types.h" #include "common/types.h"
#include <map> #include <map>
#include <mutex>
//enable the use of shared mem opcodes for world and zone only //enable the use of shared mem opcodes for world and zone only
#ifdef ZONE #ifdef ZONE
@@ -31,7 +31,8 @@
#define SHARED_OPCODES #define SHARED_OPCODES
#endif #endif
class OpcodeManager { class OpcodeManager
{
public: public:
OpcodeManager(); OpcodeManager();
virtual ~OpcodeManager() {} virtual ~OpcodeManager() {}
@@ -48,24 +49,27 @@ public:
EmuOpcode NameSearch(const char *name); EmuOpcode NameSearch(const char *name);
//This has to be public for stupid visual studio //This has to be public for stupid visual studio
class OpcodeSetStrategy { class OpcodeSetStrategy
{
public: public:
virtual ~OpcodeSetStrategy() {} //shut up compiler! virtual ~OpcodeSetStrategy() = default;
virtual void Set(EmuOpcode emu_op, uint16 eq_op) = 0; virtual void Set(EmuOpcode emu_op, uint16 eq_op) = 0;
}; };
protected: protected:
bool loaded; //true if all opcodes loaded bool loaded; //true if all opcodes loaded
Mutex MOpcodes; //this only protects the local machine std::mutex MOpcodes; //this only protects the local machine
//in a shared manager, this dosent protect others //in a shared manager, this dosent protect others
static bool LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s, bool report_errors); static bool LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s, bool report_errors);
}; };
class MutableOpcodeManager : public OpcodeManager { class MutableOpcodeManager : public OpcodeManager
{
public: public:
MutableOpcodeManager() : OpcodeManager() {} MutableOpcodeManager() = default;
virtual bool Mutable() { return(true); }
virtual bool Mutable() override { return true; }
virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op) = 0; virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op) = 0;
}; };
@@ -108,13 +112,13 @@ public:
virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op); virtual void SetOpcode(EmuOpcode emu_op, uint16 eq_op);
protected: protected:
class NormalMemStrategy : public OpcodeManager::OpcodeSetStrategy { class NormalMemStrategy : public OpcodeManager::OpcodeSetStrategy
{
public: public:
virtual ~NormalMemStrategy() {} //shut up compiler!
RegularOpcodeManager* it; RegularOpcodeManager* it;
void Set(EmuOpcode emu_op, uint16 eq_op);
virtual void Set(EmuOpcode emu_op, uint16 eq_op) override;
}; };
friend class NormalMemStrategy;
uint16* emu_to_eq; uint16* emu_to_eq;
EmuOpcode* eq_to_emu; EmuOpcode* eq_to_emu;
+1 -1
View File
@@ -3221,7 +3221,7 @@ namespace RoF
buf.WriteString(new_message); buf.WriteString(new_message);
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf); auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
dest->FastQueuePacket(&outapp, ack_req); dest->FastQueuePacket(&outapp, ack_req);
delete in; delete in;
+15 -12
View File
@@ -689,7 +689,7 @@ namespace RoF2
EQApplicationPacket *outapp = nullptr; EQApplicationPacket *outapp = nullptr;
if (eq->bufffade == 1) if (eq->bufffade == 1)
{ {
outapp = new EQApplicationPacket(OP_BuffCreate, 29); outapp = new EQApplicationPacket(OP_BuffCreate, 29u);
outapp->WriteUInt32(emu->entityid); outapp->WriteUInt32(emu->entityid);
outapp->WriteUInt32(0); // tic timer outapp->WriteUInt32(0); // tic timer
outapp->WriteUInt8(0); // Type of OP_BuffCreate packet ? outapp->WriteUInt8(0); // Type of OP_BuffCreate packet ?
@@ -753,7 +753,7 @@ namespace RoF2
ar(bl); ar(bl);
//packet size //packet size
auto packet_size = bl.item_name.length() + 1 + 34; size_t packet_size = bl.item_name.length() + 1 + 34;
for (auto const &b: bl.trade_items) { for (auto const &b: bl.trade_items) {
packet_size += b.item_name.length() + 1; packet_size += b.item_name.length() + 1;
packet_size += 12; packet_size += 12;
@@ -1622,7 +1622,7 @@ namespace RoF2
//Log.LogDebugType(Logs::General, Logs::Netcode, "[ERROR] Yourname is %s", gu2->yourname); //Log.LogDebugType(Logs::General, Logs::Netcode, "[ERROR] Yourname is %s", gu2->yourname);
int MemberCount = 1; int MemberCount = 1;
int PacketLength = 8 + strlen(gu2->leadersname) + 1 + 22 + strlen(gu2->yourname) + 1; uint32 PacketLength = 8 + strlen(gu2->leadersname) + 1 + 22 + strlen(gu2->yourname) + 1;
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
{ {
@@ -2207,7 +2207,7 @@ namespace RoF2
char *Buffer = (char *)in->pBuffer; char *Buffer = (char *)in->pBuffer;
int PacketSize = sizeof(structs::MercenaryMerchantList_Struct) - 4 + emu->MercTypeCount * 4; uint32 PacketSize = sizeof(structs::MercenaryMerchantList_Struct) - 4 + emu->MercTypeCount * 4;
PacketSize += (sizeof(structs::MercenaryListEntry_Struct) - sizeof(structs::MercenaryStance_Struct)) * emu->MercCount; PacketSize += (sizeof(structs::MercenaryListEntry_Struct) - sizeof(structs::MercenaryStance_Struct)) * emu->MercCount;
uint32 r; uint32 r;
@@ -2278,15 +2278,19 @@ namespace RoF2
// There are 2 different sized versions of this packet depending if a merc is hired or not // There are 2 different sized versions of this packet depending if a merc is hired or not
if (emu->MercStatus >= 0) if (emu->MercStatus >= 0)
{ {
PacketSize += sizeof(structs::MercenaryDataUpdate_Struct) + (sizeof(structs::MercenaryData_Struct) - sizeof(structs::MercenaryStance_Struct)) * emu->MercCount; // Per-merc size: base struct minus Stances[1] and MercUnk05,
// then add back actual stances and name length per merc.
// MercUnk05 is a single trailing field after all mercs.
PacketSize += sizeof(structs::MercenaryDataUpdate_Struct);
uint32 r; uint32 r;
uint32 k; uint32 k;
for (r = 0; r < emu->MercCount; r++) for (r = 0; r < emu->MercCount; r++)
{ {
PacketSize += sizeof(structs::MercenaryData_Struct) - sizeof(structs::MercenaryStance_Struct) - sizeof(uint32); // subtract Stances[1] and MercUnk05
PacketSize += sizeof(structs::MercenaryStance_Struct) * emu->MercData[r].StanceCount; PacketSize += sizeof(structs::MercenaryStance_Struct) * emu->MercData[r].StanceCount;
PacketSize += strlen(emu->MercData[r].MercName); // Null Terminator size already accounted for in the struct PacketSize += strlen(emu->MercData[r].MercName); // Null Terminator size already accounted for in the struct
} }
PacketSize += sizeof(uint32); // MercUnk05 - trailing field after all mercs
outapp = new EQApplicationPacket(OP_MercenaryDataUpdate, PacketSize); outapp = new EQApplicationPacket(OP_MercenaryDataUpdate, PacketSize);
Buffer = (char *)outapp->pBuffer; Buffer = (char *)outapp->pBuffer;
@@ -2312,15 +2316,14 @@ namespace RoF2
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[r].StanceCount); VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[r].StanceCount);
VARSTRUCT_ENCODE_TYPE(int32, Buffer, emu->MercData[r].MercUnk03); VARSTRUCT_ENCODE_TYPE(int32, Buffer, emu->MercData[r].MercUnk03);
VARSTRUCT_ENCODE_TYPE(uint8, Buffer, emu->MercData[r].MercUnk04); VARSTRUCT_ENCODE_TYPE(uint8, Buffer, emu->MercData[r].MercUnk04);
//VARSTRUCT_ENCODE_TYPE(uint8, Buffer, 0); // MercName
VARSTRUCT_ENCODE_STRING(Buffer, emu->MercData[r].MercName); VARSTRUCT_ENCODE_STRING(Buffer, emu->MercData[r].MercName);
for (k = 0; k < emu->MercData[r].StanceCount; k++) for (k = 0; k < emu->MercData[r].StanceCount; k++)
{ {
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[r].Stances[k].StanceIndex); VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[r].Stances[k].StanceIndex);
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[r].Stances[k].Stance); VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[r].Stances[k].Stance);
} }
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, 1); // MercUnk05
} }
VARSTRUCT_ENCODE_TYPE(uint32, Buffer, emu->MercData[0].MercUnk05); // MercUnk05 - trailing field (unlocked slot count)
} }
else else
{ {
@@ -3820,7 +3823,7 @@ namespace RoF2
buf.WriteString(new_message); buf.WriteString(new_message);
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf); auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
dest->FastQueuePacket(&outapp, ack_req); dest->FastQueuePacket(&outapp, ack_req);
delete in; delete in;
@@ -4120,8 +4123,8 @@ namespace RoF2
std::begin(emu->items), std::begin(emu->items),
std::end(emu->items), std::end(emu->items),
std::begin(eq->items), std::begin(eq->items),
[&](const uint32 x) { [&](uint64 x) {
return x; return static_cast<uint32>(x);
} }
); );
std::copy_n( std::copy_n(
@@ -4599,7 +4602,7 @@ namespace RoF2
int k; int k;
for (r = 0; r < entrycount; r++, emu++) { for (r = 0; r < entrycount; r++, emu++) {
int PacketSize = 206; uint32 PacketSize = 206;
PacketSize += strlen(emu->name); PacketSize += strlen(emu->name);
PacketSize += strlen(emu->lastName); PacketSize += strlen(emu->lastName);
+1 -1
View File
@@ -2128,7 +2128,7 @@ namespace SoD
buf.WriteString(new_message); buf.WriteString(new_message);
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf); auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
dest->FastQueuePacket(&outapp, ack_req); dest->FastQueuePacket(&outapp, ack_req);
delete in; delete in;
+1 -1
View File
@@ -1785,7 +1785,7 @@ namespace SoF
buf.WriteString(new_message); buf.WriteString(new_message);
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf); auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
dest->FastQueuePacket(&outapp, ack_req); dest->FastQueuePacket(&outapp, ack_req);
delete in; delete in;
+1 -1
View File
@@ -1991,7 +1991,7 @@ namespace Titanium
buf.WriteString(new_message); buf.WriteString(new_message);
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf); auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
dest->FastQueuePacket(&outapp, ack_req); dest->FastQueuePacket(&outapp, ack_req);
delete in; delete in;
+1 -1
View File
@@ -2711,7 +2711,7 @@ namespace UF
buf.WriteString(new_message); buf.WriteString(new_message);
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf); auto outapp = new EQApplicationPacket(OP_SpecialMesg, std::move(buf));
dest->FastQueuePacket(&outapp, ack_req); dest->FastQueuePacket(&outapp, ack_req);
delete in; delete in;
+1
View File
@@ -19,6 +19,7 @@
#ifdef _WINDOWS #ifdef _WINDOWS
#include "common/platform/win/include_windows.h"
#include <WinSock2.h> #include <WinSock2.h>
#endif // _WINDOWS #endif // _WINDOWS
+3 -1
View File
@@ -23,11 +23,13 @@
inline std::string random_string(size_t length) inline std::string random_string(size_t length)
{ {
auto randchar = []() -> char { auto randchar = []() -> char
{
const char charset[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; const char charset[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz";
const size_t max_index = (sizeof(charset) - 1); const size_t max_index = (sizeof(charset) - 1);
return charset[static_cast<size_t>(std::rand()) % max_index]; return charset[static_cast<size_t>(std::rand()) % max_index];
}; };
std::string str(length, 0); std::string str(length, 0);
std::generate_n(str.begin(), length, randchar); std::generate_n(str.begin(), length, randchar);
return str; return str;
+1
View File
@@ -255,6 +255,7 @@ RULE_BOOL(Mercs, AllowMercSuspendInCombat, true, "Allow merc suspend in combat")
RULE_BOOL(Mercs, MercsIgnoreLevelBasedHasteCaps, false, "Ignores hard coded level based haste caps.") RULE_BOOL(Mercs, MercsIgnoreLevelBasedHasteCaps, false, "Ignores hard coded level based haste caps.")
RULE_INT(Mercs, MercsHasteCap, 100, "Haste cap for non-v3(over haste) haste") RULE_INT(Mercs, MercsHasteCap, 100, "Haste cap for non-v3(over haste) haste")
RULE_INT(Mercs, MercsHastev3Cap, 25, "Haste cap for v3(over haste) haste") RULE_INT(Mercs, MercsHastev3Cap, 25, "Haste cap for v3(over haste) haste")
RULE_INT(Mercs, MaxMercSlots, 6, "Maximum number of mercenary slots per character (max = MAXMERCS)")
RULE_CATEGORY_END() RULE_CATEGORY_END()
RULE_CATEGORY(Guild) RULE_CATEGORY(Guild)
+22 -18
View File
@@ -27,7 +27,7 @@
class SerializeBuffer class SerializeBuffer
{ {
public: public:
SerializeBuffer() : m_buffer(nullptr), m_capacity(0), m_pos(0) {} SerializeBuffer() = default;
explicit SerializeBuffer(size_t size) : m_capacity(size), m_pos(0) explicit SerializeBuffer(size_t size) : m_capacity(size), m_pos(0)
{ {
@@ -36,7 +36,9 @@ public:
} }
SerializeBuffer(const SerializeBuffer& rhs) SerializeBuffer(const SerializeBuffer& rhs)
: m_buffer(new unsigned char[rhs.m_capacity]), m_capacity(rhs.m_capacity), m_pos(rhs.m_pos) : m_buffer(new unsigned char[rhs.m_capacity])
, m_capacity(rhs.m_capacity)
, m_pos(rhs.m_pos)
{ {
memcpy(m_buffer, rhs.m_buffer, rhs.m_capacity); memcpy(m_buffer, rhs.m_buffer, rhs.m_capacity);
} }
@@ -53,30 +55,31 @@ public:
return *this; return *this;
} }
SerializeBuffer(SerializeBuffer &&rhs) : m_buffer(rhs.m_buffer), m_capacity(rhs.m_capacity), m_pos(rhs.m_pos) SerializeBuffer(SerializeBuffer&& rhs)
: m_buffer(std::exchange(rhs.m_buffer, nullptr))
, m_capacity(std::exchange(rhs.m_capacity, 0))
, m_pos(std::exchange(rhs.m_pos, 0))
{ {
rhs.m_buffer = nullptr;
rhs.m_capacity = 0;
rhs.m_pos = 0;
} }
SerializeBuffer& operator=(SerializeBuffer&& rhs) SerializeBuffer& operator=(SerializeBuffer&& rhs)
{ {
if (this != &rhs) { if (this != &rhs)
{
delete[] m_buffer; delete[] m_buffer;
m_buffer = rhs.m_buffer; m_buffer = std::exchange(rhs.m_buffer, nullptr);
m_capacity = rhs.m_capacity; m_capacity = std::exchange(rhs.m_capacity, 0);
m_pos = rhs.m_pos; m_pos = std::exchange(rhs.m_pos, 0);
rhs.m_buffer = nullptr;
rhs.m_capacity = 0;
rhs.m_pos = 0;
} }
return *this; return *this;
} }
~SerializeBuffer() { delete[] m_buffer; } ~SerializeBuffer()
{
delete[] m_buffer;
}
void WriteUInt8(uint8_t v) void WriteUInt8(uint8_t v)
{ {
@@ -209,7 +212,8 @@ public:
private: private:
void Grow(size_t new_size); void Grow(size_t new_size);
void Reset(); void Reset();
unsigned char *m_buffer;
size_t m_capacity; unsigned char* m_buffer = nullptr;
size_t m_pos; size_t m_capacity = 0;
size_t m_pos = 0;
}; };
+27 -30
View File
@@ -389,35 +389,31 @@ enum {
class ServerPacket class ServerPacket
{ {
public: public:
~ServerPacket() { safe_delete_array(pBuffer); } ~ServerPacket()
ServerPacket(uint16 in_opcode = 0, uint32 in_size = 0) { {
this->compressed = false; safe_delete_array(pBuffer);
size = in_size;
opcode = in_opcode;
if (size == 0) {
pBuffer = 0;
} }
else {
ServerPacket(uint16 in_opcode = 0, size_t in_size = 0)
: size(static_cast<uint32>(in_size))
, opcode(in_opcode)
{
if (size != 0)
{
pBuffer = new uchar[size]; pBuffer = new uchar[size];
memset(pBuffer, 0, size); memset(pBuffer, 0, size);
} }
_wpos = 0;
_rpos = 0;
} }
ServerPacket(uint16 in_opcode, const EQ::Net::Packet &p) { ServerPacket(uint16 in_opcode, const EQ::Net::Packet& p)
this->compressed = false; : size(static_cast<uint32>(p.Length()))
size = (uint32)p.Length(); , opcode(in_opcode)
opcode = in_opcode; {
if (size == 0) { if (size != 0)
pBuffer = 0; {
}
else {
pBuffer = new uchar[size]; pBuffer = new uchar[size];
memcpy(pBuffer, p.Data(), size); memcpy(pBuffer, p.Data(), size);
} }
_wpos = 0;
_rpos = 0;
} }
ServerPacket* Copy() { ServerPacket* Copy() {
@@ -447,14 +443,14 @@ public:
void ReadSkipBytes(uint32 count) { _rpos += count; } void ReadSkipBytes(uint32 count) { _rpos += count; }
void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; } void SetReadPosition(uint32 Newrpos) { _rpos = Newrpos; }
uint32 size; uint32 size = 0;
uint16 opcode; uint16 opcode = 0;
uchar* pBuffer; uchar* pBuffer = nullptr;
uint32 _wpos; uint32 _wpos = 0;
uint32 _rpos; uint32 _rpos = 0;
bool compressed; bool compressed = false;
uint32 InflatedSize; uint32 InflatedSize = 0;
uint32 destination; uint32 destination = 0;
}; };
#pragma pack(push) #pragma pack(push)
@@ -989,11 +985,12 @@ struct LauncherConnectInfo {
char name[64]; char name[64];
}; };
typedef enum { enum ZoneRequestCommands {
ZR_Start, ZR_Start,
ZR_Restart, ZR_Restart,
ZR_Stop ZR_Stop
} ZoneRequestCommands; };
struct LauncherZoneRequest { struct LauncherZoneRequest {
uint8 command; uint8 command;
char short_name[33]; char short_name[33];
+1 -1
View File
@@ -999,7 +999,7 @@ uint8 GetSpellLevel(uint16 spell_id, uint8 class_id)
return UINT8_MAX; return UINT8_MAX;
} }
if (class_id >= Class::PLAYER_CLASS_COUNT) { if (class_id < Class::Warrior || class_id > Class::PLAYER_CLASS_COUNT) {
return UINT8_MAX; return UINT8_MAX;
} }
+44 -103
View File
@@ -380,118 +380,59 @@ std::string Strings::NumberToWords(unsigned long long int n)
return res; return res;
} }
std::string Strings::Money(uint64 platinum, uint64 gold, uint64 silver, uint64 copper) std::string Strings::Money(uint64 platinum, uint64 gold, uint64 silver, uint64 copper, bool commify) {
{ uint64 values[] = { platinum, gold, silver, copper };
std::string money_string = "Unknown"; const char* names[] = { " platinum", " gold", " silver", " copper" };
if (copper && silver && gold && platinum) { // CSGP
money_string = fmt::format( std::vector<std::string> parts;
"{} platinum, {} gold, {} silver, and {} copper", for (int i = 0; i < 4; ++i) {
Strings::Commify(std::to_string(platinum)), if (values[i] > 0) {
Strings::Commify(std::to_string(gold)), std::string s = std::to_string(values[i]);
Strings::Commify(std::to_string(silver)), parts.push_back((commify ? Strings::Commify(s) : s) + names[i]);
Strings::Commify(std::to_string(copper))
);
} }
else if (copper && silver && !gold && platinum) { // CSP
money_string = fmt::format(
"{} platinum, {} silver, and {} copper",
Strings::Commify(std::to_string(platinum)),
Strings::Commify(std::to_string(silver)),
Strings::Commify(std::to_string(copper))
);
} }
else if (copper && silver && gold && !platinum) { // CSG
money_string = fmt::format( if (parts.empty()) return "0 copper";
"{} gold, {} silver, and {} copper", if (parts.size() == 1) return parts[0];
Strings::Commify(std::to_string(gold)),
Strings::Commify(std::to_string(silver)), std::string result;
Strings::Commify(std::to_string(copper)) for (size_t i = 0; i < parts.size(); ++i) {
); result += parts[i];
if (i < parts.size() - 2) {
result += ", ";
} }
else if (copper && !silver && !gold && platinum) { // CP else if (i == parts.size() - 2) {
money_string = fmt::format( // Oxford comma logic: ", and " for 3+ items, " and " for 2
"{} platinum and {} copper", result += (parts.size() > 2) ? ", and " : " and ";
Strings::Commify(std::to_string(platinum)),
Strings::Commify(std::to_string(copper))
);
} }
else if (copper && silver && !gold && !platinum) { // CS
money_string = fmt::format(
"{} silver and {} copper",
Strings::Commify(std::to_string(silver)),
Strings::Commify(std::to_string(copper))
);
} }
else if (!copper && silver && gold && platinum) { // SGP
money_string = fmt::format( return result;
"{} platinum, {} gold, and {} silver",
Strings::Commify(std::to_string(platinum)),
Strings::Commify(std::to_string(gold)),
Strings::Commify(std::to_string(silver))
);
} }
else if (!copper && silver && !gold && platinum) { // SP
money_string = fmt::format( std::string Strings::MoneyShort(uint64 copper, bool commify) {
"{} platinum and {} silver", // Matches merchant format
Strings::Commify(std::to_string(platinum)), uint64 values[] = {
Strings::Commify(std::to_string(silver)) copper / 1000,
); (copper / 100) % 10,
(copper / 10) % 10,
copper % 10
};
const char* names[] = { " platinum", " gold", " silver", " copper" };
std::string result;
for (int i = 0; i < 4; ++i) {
if (values[i] > 0) {
if (!result.empty()) result += " ";
std::string s = std::to_string(values[i]);
result += (commify ? Strings::Commify(s) : s) + names[i];
} }
else if (!copper && silver && gold && !platinum) { // SG
money_string = fmt::format(
"{} gold and {} silver",
Strings::Commify(std::to_string(gold)),
Strings::Commify(std::to_string(silver))
);
} }
else if (copper && !silver && gold && platinum) { // CGP
money_string = fmt::format( return result.empty() ? "0 copper" : result;
"{} platinum, {} gold, and {} copper",
Strings::Commify(std::to_string(platinum)),
Strings::Commify(std::to_string(gold)),
Strings::Commify(std::to_string(copper))
);
}
else if (copper && !silver && gold && !platinum) { // CG
money_string = fmt::format(
"{} gold and {} copper",
Strings::Commify(std::to_string(gold)),
Strings::Commify(std::to_string(copper))
);
}
else if (!copper && !silver && gold && platinum) { // GP
money_string = fmt::format(
"{} platinum and {} gold",
Strings::Commify(std::to_string(platinum)),
Strings::Commify(std::to_string(gold))
);
}
else if (!copper && !silver && !gold && platinum) { // P
money_string = fmt::format(
"{} platinum",
Strings::Commify(std::to_string(platinum))
);
}
else if (!copper && !silver && gold && !platinum) { // G
money_string = fmt::format(
"{} gold",
Strings::Commify(std::to_string(gold))
);
}
else if (!copper && silver && !gold && !platinum) { // S
money_string = fmt::format(
"{} silver",
Strings::Commify(std::to_string(silver))
);
}
else if (copper && !silver && !gold && !platinum) { // C
money_string = fmt::format(
"{} copper",
Strings::Commify(std::to_string(copper))
);
}
return money_string;
} }
std::string Strings::SecondsToTime(int duration, bool is_milliseconds) std::string Strings::SecondsToTime(int duration, bool is_milliseconds)
{ {
if (duration <= 0) { if (duration <= 0) {
+2 -1
View File
@@ -62,7 +62,8 @@ public:
static std::string Join(const std::vector<std::string> &ar, const std::string &delim); static std::string Join(const std::vector<std::string> &ar, const std::string &delim);
static std::string Join(const std::vector<uint32_t> &ar, const std::string &delim); static std::string Join(const std::vector<uint32_t> &ar, const std::string &delim);
static std::string MillisecondsToTime(int duration); static std::string MillisecondsToTime(int duration);
static std::string Money(uint64 platinum, uint64 gold = 0, uint64 silver = 0, uint64 copper = 0); static std::string Money(uint64 platinum, uint64 gold = 0, uint64 silver = 0, uint64 copper = 0, bool commify = true);
static std::string MoneyShort(uint64 copper = 0, bool commify = true); // Matches merchant format when commify is false
static std::string NumberToWords(unsigned long long int n); static std::string NumberToWords(unsigned long long int n);
static std::string Repeat(std::string s, int n); static std::string Repeat(std::string s, int n);
static std::string Replace(std::string subject, const std::string &search, const std::string &replace); static std::string Replace(std::string subject, const std::string &search, const std::string &replace);
+2 -2
View File
@@ -38,10 +38,10 @@
#define RELOADTASKS 0 #define RELOADTASKS 0
#define RELOADTASKSETS 2 #define RELOADTASKSETS 2
typedef enum { enum TaskMethodType {
METHODSINGLEID = 0, METHODSINGLEID = 0,
METHODQUEST = 2 METHODQUEST = 2
} TaskMethodType; };
enum class TaskActivityType : int32_t // task element/objective enum class TaskActivityType : int32_t // task element/objective
{ {
+1 -1
View File
@@ -103,7 +103,7 @@ namespace luabind { namespace detail
if (luabind::move_back_reference(L, ptr)) if (luabind::move_back_reference(L, ptr))
return; return;
make_instance(L, std::auto_ptr<T>(ptr)); make_instance(L, std::unique_ptr<T>(ptr));
} }
}; };
+1 -1
View File
@@ -335,7 +335,7 @@ namespace luabind
template <class T> template <class T>
struct default_pointer<null_type, T> struct default_pointer<null_type, T>
{ {
typedef std::auto_ptr<T> type; typedef std::unique_ptr<T> type;
}; };
template <class Class, class Pointer, class Signature, class Policies> template <class Class, class Pointer, class Signature, class Policies>
+4 -4
View File
@@ -46,7 +46,7 @@ struct construct_aux<0, T, Pointer, Signature>
object_rep* self = touserdata<object_rep>(self_); object_rep* self = touserdata<object_rep>(self_);
class_rep* cls = self->crep(); class_rep* cls = self->crep();
std::auto_ptr<T> instance(new T); std::unique_ptr<T> instance(new T);
inject_backref(self_.interpreter(), instance.get(), instance.get()); inject_backref(self_.interpreter(), instance.get(), instance.get());
void* naked_ptr = instance.get(); void* naked_ptr = instance.get();
@@ -55,7 +55,7 @@ struct construct_aux<0, T, Pointer, Signature>
void* storage = self->allocate(sizeof(holder_type)); void* storage = self->allocate(sizeof(holder_type));
self->set_instance(new (storage) holder_type( self->set_instance(new (storage) holder_type(
ptr, registered_class<T>::id, naked_ptr, cls)); std::move(ptr), registered_class<T>::id, naked_ptr, cls));
} }
}; };
@@ -92,7 +92,7 @@ struct construct_aux<N, T, Pointer, Signature>
object_rep* self = touserdata<object_rep>(self_); object_rep* self = touserdata<object_rep>(self_);
class_rep* cls = self->crep(); class_rep* cls = self->crep();
std::auto_ptr<T> instance(new T(BOOST_PP_ENUM_PARAMS(N,_))); std::unique_ptr<T> instance(new T(BOOST_PP_ENUM_PARAMS(N,_)));
inject_backref(self_.interpreter(), instance.get(), instance.get()); inject_backref(self_.interpreter(), instance.get(), instance.get());
void* naked_ptr = instance.get(); void* naked_ptr = instance.get();
@@ -101,7 +101,7 @@ struct construct_aux<N, T, Pointer, Signature>
void* storage = self->allocate(sizeof(holder_type)); void* storage = self->allocate(sizeof(holder_type));
self->set_instance(new (storage) holder_type( self->set_instance(new (storage) holder_type(
ptr, registered_class<T>::id, naked_ptr, cls)); std::move(ptr), registered_class<T>::id, naked_ptr, cls));
} }
}; };
@@ -58,7 +58,7 @@ namespace has_get_pointer_
T* get_pointer(T const volatile*); T* get_pointer(T const volatile*);
template<class T> template<class T>
T* get_pointer(std::auto_ptr<T> const&); T* get_pointer(std::unique_ptr<T> const&);
# endif # endif
@@ -57,7 +57,7 @@ inline mpl::true_ check_const_pointer(void const*)
} }
template <class T> template <class T>
void release_ownership(std::auto_ptr<T>& p) void release_ownership(std::unique_ptr<T>& p)
{ {
p.release(); p.release();
} }
@@ -83,7 +83,7 @@ public:
P p, class_id dynamic_id, void* dynamic_ptr, class_rep* cls P p, class_id dynamic_id, void* dynamic_ptr, class_rep* cls
) )
: instance_holder(cls, check_const_pointer(false ? get_pointer(p) : 0)) : instance_holder(cls, check_const_pointer(false ? get_pointer(p) : 0))
, p(p) , p(std::move(p))
, weak(0) , weak(0)
, dynamic_id(dynamic_id) , dynamic_id(dynamic_id)
, dynamic_ptr(dynamic_ptr) , dynamic_ptr(dynamic_ptr)
@@ -88,7 +88,7 @@ void make_instance(lua_State* L, P p)
try try
{ {
new (storage) holder_type(p, dynamic.first, dynamic.second, cls); new (storage) holder_type(std::move(p), dynamic.first, dynamic.second, cls);
} }
catch (...) catch (...)
{ {
+3 -3
View File
@@ -169,7 +169,7 @@ namespace luabind { namespace detail
{ {
if (get_pointer(x)) if (get_pointer(x))
{ {
make_instance(L, x); make_instance(L, std::move(x));
} }
else else
{ {
@@ -180,8 +180,8 @@ namespace luabind { namespace detail
template <class T> template <class T>
void make_pointee_instance(lua_State* L, T& x, mpl::false_, mpl::true_) void make_pointee_instance(lua_State* L, T& x, mpl::false_, mpl::true_)
{ {
std::auto_ptr<T> ptr(new T(x)); std::unique_ptr<T> ptr(new T(x));
make_instance(L, ptr); make_instance(L, std::move(ptr));
} }
template <class T> template <class T>
+1 -1
View File
@@ -46,7 +46,7 @@ namespace detail
template <class F, class Policies> template <class F, class Policies>
scope def(char const* name, F f, Policies const& policies) scope def(char const* name, F f, Policies const& policies)
{ {
return scope(std::auto_ptr<detail::registration>( return scope(std::unique_ptr<detail::registration>(
new detail::function_registration<F, Policies>(name, f, policies))); new detail::function_registration<F, Policies>(name, f, policies)));
} }
+1 -1
View File
@@ -56,7 +56,7 @@ namespace luabind {
struct LUABIND_API scope struct LUABIND_API scope
{ {
scope(); scope();
explicit scope(std::auto_ptr<detail::registration> reg); explicit scope(std::unique_ptr<detail::registration> reg);
scope(scope const& other_); scope(scope const& other_);
~scope(); ~scope();
+5 -5
View File
@@ -235,7 +235,7 @@ namespace luabind { namespace detail {
// -- interface --------------------------------------------------------- // -- interface ---------------------------------------------------------
class_base::class_base(char const* name) class_base::class_base(char const* name)
: scope(std::auto_ptr<registration>( : scope(std::unique_ptr<registration>(
m_registration = new class_registration(name)) m_registration = new class_registration(name))
) )
{ {
@@ -258,14 +258,14 @@ namespace luabind { namespace detail {
void class_base::add_member(registration* member) void class_base::add_member(registration* member)
{ {
std::auto_ptr<registration> ptr(member); std::unique_ptr<registration> ptr(member);
m_registration->m_members.operator,(scope(ptr)); m_registration->m_members.operator,(scope(std::move(ptr)));
} }
void class_base::add_default_member(registration* member) void class_base::add_default_member(registration* member)
{ {
std::auto_ptr<registration> ptr(member); std::unique_ptr<registration> ptr(member);
m_registration->m_default_members.operator,(scope(ptr)); m_registration->m_default_members.operator,(scope(std::move(ptr)));
} }
const char* class_base::name() const const char* class_base::name() const
+1 -1
View File
@@ -94,7 +94,7 @@ namespace
{ {
m_cache.insert(std::make_pair( m_cache.insert(std::make_pair(
key_type(src, target, dynamic_id, object_offset) key_type(src, target, dynamic_id, object_offset)
, cache_entry(offset, distance) , cache_entry(offset, static_cast<int>(distance))
)); ));
} }
+3 -2
View File
@@ -49,7 +49,8 @@ namespace luabind { namespace detail {
{ {
} }
scope::scope(std::auto_ptr<detail::registration> reg)
scope::scope(std::unique_ptr<detail::registration> reg)
: m_chain(reg.release()) : m_chain(reg.release())
{ {
} }
@@ -193,7 +194,7 @@ namespace luabind {
}; };
namespace_::namespace_(char const* name) namespace_::namespace_(char const* name)
: scope(std::auto_ptr<detail::registration>( : scope(std::unique_ptr<detail::registration>(
m_registration = new registration_(name))) m_registration = new registration_(name)))
{ {
} }
+10
View File
@@ -37,3 +37,13 @@ target_include_directories(loginserver PRIVATE ..)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set_property(TARGET loginserver PROPERTY FOLDER executables/servers) set_property(TARGET loginserver PROPERTY FOLDER executables/servers)
# vcpkg doesn't copy legacy.dll automatically because it is loaded at runtime, not via the import table.
if(WIN32 AND DEFINED VCPKG_INSTALLED_DIR AND DEFINED VCPKG_TARGET_TRIPLET)
add_custom_command(TARGET loginserver POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<IF:$<CONFIG:Debug>,${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/bin/legacy.dll,${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/legacy.dll>"
"$<TARGET_FILE_DIR:loginserver>/legacy.dll"
VERBATIM
)
endif()
+3 -76
View File
@@ -88,9 +88,6 @@ bool Client::Process()
SendPlayToWorld((const char *) app->pBuffer); SendPlayToWorld((const char *) app->pBuffer);
break; break;
} }
case OP_SystemFingerprint: {
break;
}
} }
delete app; delete app;
@@ -107,19 +104,16 @@ void Client::HandleSessionReady(const char *data, unsigned int size)
return; return;
} }
if (size < sizeof(int32)) { if (size < sizeof(unsigned int)) {
LogError("Session ready was too small"); LogError("Session ready was too small");
return; return;
} }
//existing sequence id
int32 sequence_in = *(int32*)data;
m_client_status = cs_waiting_for_login; m_client_status = cs_waiting_for_login;
auto *outapp = new EQApplicationPacket(OP_ChatMessage, sizeof(LoginHandShakeReply)); auto *outapp = new EQApplicationPacket(OP_ChatMessage, sizeof(LoginHandShakeReply));
auto buf = reinterpret_cast<LoginHandShakeReply *>(outapp->pBuffer); auto buf = reinterpret_cast<LoginHandShakeReply *>(outapp->pBuffer);
buf->base_header.sequence = sequence_in; buf->base_header.sequence = 0x02;
buf->base_reply.success = true; buf->base_reply.success = true;
buf->base_reply.error_str_id = 0x65; // 101 "No Error" buf->base_reply.error_str_id = 0x65; // 101 "No Error"
@@ -362,31 +356,6 @@ void Client::SendFailedLogin()
m_stored_username.clear(); m_stored_username.clear();
m_stored_password.clear(); m_stored_password.clear();
if (m_client_version == cv_steam_latest) {
// unencrypted
LoginBaseMessage h{};
h.sequence = m_login_base_message.sequence; // login (3)
h.encrypt_type = m_login_base_message.encrypt_type;
// encrypted
PlayerLoginReplySteamLatest r{};
r.base_reply.success = false;
r.base_reply.error_str_id = 105; // Error - The username and/or password were not valid
char encrypted_buffer[80] = { 0 };
auto rc = eqcrypt_block((const char*)&r, sizeof(r), encrypted_buffer, 1);
if (rc == nullptr) {
LogDebug("Failed to encrypt eqcrypt block for failed login");
}
constexpr int outsize = sizeof(LoginBaseMessage) + sizeof(encrypted_buffer);
EQApplicationPacket outapp(OP_LoginAccepted, outsize);
outapp.WriteData(&h, sizeof(h));
outapp.WriteData(&encrypted_buffer, sizeof(encrypted_buffer));
m_connection->QueuePacket(&outapp);
}
else {
// unencrypted // unencrypted
LoginBaseMessage h{}; LoginBaseMessage h{};
h.sequence = m_login_base_message.sequence; // login (3) h.sequence = m_login_base_message.sequence; // login (3)
@@ -409,8 +378,6 @@ void Client::SendFailedLogin()
outapp.WriteData(&encrypted_buffer, sizeof(encrypted_buffer)); outapp.WriteData(&encrypted_buffer, sizeof(encrypted_buffer));
m_connection->QueuePacket(&outapp); m_connection->QueuePacket(&outapp);
}
m_client_status = cs_failed_to_login; m_client_status = cs_failed_to_login;
} }
@@ -496,45 +463,6 @@ void Client::DoSuccessfulLogin(LoginAccountsRepository::LoginAccounts &a)
m_account_name = a.account_name; m_account_name = a.account_name;
m_loginserver_name = a.source_loginserver; m_loginserver_name = a.source_loginserver;
if (m_client_version == cv_steam_latest) {
// unencrypted
LoginBaseMessage h{};
h.sequence = m_login_base_message.sequence;
h.compressed = false;
h.encrypt_type = m_login_base_message.encrypt_type;
h.unk3 = m_login_base_message.unk3;
// not serializing any of the variable length strings so just use struct directly
PlayerLoginReplySteamLatest r{};
r.base_reply.success = true;
r.base_reply.error_str_id = 101; // No Error
r.unk1 = 0;
r.unk2 = 0;
r.lsid = a.id;
r.failed_attempts = 0;
r.show_player_count = server.options.IsShowPlayerCountEnabled();
r.unk3 = 0;
r.unk4 = 0;
memcpy(r.key, m_key.c_str(), m_key.size());
//todo: needs to be fixed
//SendExpansionPacketData(r);
char encrypted_buffer[80] = { 0 };
auto rc = eqcrypt_block((const char*)&r, sizeof(r), encrypted_buffer, 1);
if (rc == nullptr) {
LogDebug("Failed to encrypt eqcrypt block");
}
constexpr int outsize = sizeof(LoginBaseMessage) + sizeof(encrypted_buffer);
auto outapp = std::make_unique<EQApplicationPacket>(OP_LoginAccepted, outsize);
outapp->WriteData(&h, sizeof(h));
outapp->WriteData(&encrypted_buffer, sizeof(encrypted_buffer));
m_connection->QueuePacket(outapp.get());
}
else {
// unencrypted // unencrypted
LoginBaseMessage h{}; LoginBaseMessage h{};
h.sequence = m_login_base_message.sequence; h.sequence = m_login_base_message.sequence;
@@ -575,7 +503,6 @@ void Client::DoSuccessfulLogin(LoginAccountsRepository::LoginAccounts &a)
outapp->WriteData(&encrypted_buffer, sizeof(encrypted_buffer)); outapp->WriteData(&encrypted_buffer, sizeof(encrypted_buffer));
m_connection->QueuePacket(outapp.get()); m_connection->QueuePacket(outapp.get());
}
m_client_status = cs_logged_in; m_client_status = cs_logged_in;
} }
@@ -620,7 +547,7 @@ void Client::SendExpansionPacketData(PlayerLoginReply &plrs)
buf.WriteInt32(0xFFFFFFFF); buf.WriteInt32(0xFFFFFFFF);
} }
auto out = std::make_unique<EQApplicationPacket>(OP_LoginExpansionPacketData, buf); auto out = std::make_unique<EQApplicationPacket>(OP_LoginExpansionPacketData, std::move(buf));
m_connection->QueuePacket(out.get()); m_connection->QueuePacket(out.get());
} }
+20 -20
View File
@@ -74,7 +74,7 @@ void CheckSoDOpcodeFile(const std::string &path)
} }
} }
void CheckSteamLatestOpcodeFile(const std::string &path) void CheckLarionOpcodeFile(const std::string &path)
{ {
if (File::Exists(path)) { if (File::Exists(path)) {
return; return;
@@ -87,15 +87,15 @@ void CheckSteamLatestOpcodeFile(const std::string &path)
fprintf(f, "OP_Login=0x0002\n"); fprintf(f, "OP_Login=0x0002\n");
fprintf(f, "OP_ServerListRequest=0x0004\n"); fprintf(f, "OP_ServerListRequest=0x0004\n");
fprintf(f, "OP_PlayEverquestRequest=0x000d\n"); fprintf(f, "OP_PlayEverquestRequest=0x000d\n");
fprintf(f, "OP_PlayEverquestResponse=0x0023\n"); fprintf(f, "OP_PlayEverquestResponse=0x0022\n");
fprintf(f, "OP_ChatMessage=0x0018\n"); fprintf(f, "OP_ChatMessage=0x0017\n");
fprintf(f, "OP_LoginAccepted=0x0019\n"); fprintf(f, "OP_LoginAccepted=0x0018\n");
fprintf(f, "OP_ServerListResponse=0x001a\n"); fprintf(f, "OP_ServerListResponse=0x0019\n");
fprintf(f, "OP_Poll=0x002a\n"); fprintf(f, "OP_Poll=0x0029\n");
fprintf(f, "OP_EnterChat=0x000f\n"); fprintf(f, "OP_EnterChat=0x000f\n");
fprintf(f, "OP_PollResponse=0x0011\n"); fprintf(f, "OP_PollResponse=0x0011\n");
fprintf(f, "OP_SystemFingerprint=0x0016\n"); fprintf(f, "OP_SystemFingerprint=0x0016\n");
fprintf(f, "OP_ExpansionList=0x0031\n"); fprintf(f, "OP_ExpansionList=0x0030\n");
fclose(f); fclose(f);
} }
} }
@@ -177,40 +177,40 @@ ClientManager::ClientManager()
} }
); );
int steam_latest_port = server.config.GetVariableInt("client_configuration", "steam_latest_port", 15900); int larion_port = server.config.GetVariableInt("client_configuration", "larion_port", 15900);
EQStreamManagerInterfaceOptions steam_latest_opts(steam_latest_port, false, false); EQStreamManagerInterfaceOptions larion_opts(larion_port, false, false);
m_steam_latest_stream = new EQ::Net::EQStreamManager(steam_latest_opts); m_larion_stream = new EQ::Net::EQStreamManager(larion_opts);
m_steam_latest_ops = new RegularOpcodeManager; m_larion_ops = new RegularOpcodeManager;
opcodes_path = fmt::format( opcodes_path = fmt::format(
"{}/{}", "{}/{}",
PathManager::Instance()->GetOpcodePath(), PathManager::Instance()->GetOpcodePath(),
"login_opcodes_steam_latest.conf" "login_opcodes_larion.conf"
); );
CheckSteamLatestOpcodeFile(opcodes_path); CheckLarionOpcodeFile(opcodes_path);
if (!m_steam_latest_ops->LoadOpcodes(opcodes_path.c_str())) { if (!m_larion_ops->LoadOpcodes(opcodes_path.c_str())) {
LogError( LogError(
"ClientManager fatal error: couldn't load opcodes for Steam Latest file [{}]", "ClientManager fatal error: couldn't load opcodes for Larion file [{}]",
server.config.GetVariableString("client_configuration", "steam_latest_opcodes", "login_opcodes.conf") server.config.GetVariableString("client_configuration", "larion_opcodes", "login_opcodes.conf")
); );
run_server = false; run_server = false;
} }
m_steam_latest_stream->OnNewConnection( m_larion_stream->OnNewConnection(
[this](std::shared_ptr<EQ::Net::EQStream> stream) { [this](std::shared_ptr<EQ::Net::EQStream> stream) {
LogInfo( LogInfo(
"New Steam Latest client connection from [{}:{}]", "New Larion client connection from [{}:{}]",
long2ip(stream->GetRemoteIP()), long2ip(stream->GetRemoteIP()),
stream->GetRemotePort() stream->GetRemotePort()
); );
stream->SetOpcodeManager(&m_steam_latest_ops); stream->SetOpcodeManager(&m_larion_ops);
Client *c = new Client(stream, cv_steam_latest); Client *c = new Client(stream, cv_larion);
m_clients.push_back(c); m_clients.push_back(c);
} }
); );
+2 -2
View File
@@ -37,6 +37,6 @@ private:
EQ::Net::EQStreamManager *m_titanium_stream; EQ::Net::EQStreamManager *m_titanium_stream;
OpcodeManager *m_sod_ops; OpcodeManager *m_sod_ops;
EQ::Net::EQStreamManager *m_sod_stream; EQ::Net::EQStreamManager *m_sod_stream;
OpcodeManager *m_steam_latest_ops; OpcodeManager *m_larion_ops;
EQ::Net::EQStreamManager *m_steam_latest_stream; EQ::Net::EQStreamManager *m_larion_stream;
}; };
+102 -16
View File
@@ -16,11 +16,12 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "encryption.h" #include "encryption.h"
#include "common/compiler_macros.h"
#ifdef EQEMU_USE_OPENSSL #ifdef EQEMU_USE_OPENSSL
#include <openssl/des.h> #include <openssl/err.h>
#include <openssl/sha.h> #include <openssl/evp.h>
#include <openssl/md5.h> #include <openssl/provider.h>
#endif #endif
#ifdef EQEMU_USE_MBEDTLS #ifdef EQEMU_USE_MBEDTLS
#include <mbedtls/des.h> #include <mbedtls/des.h>
@@ -32,6 +33,8 @@
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <memory>
#ifdef ENABLE_SECURITY #ifdef ENABLE_SECURITY
#include <sodium.h> #include <sodium.h>
@@ -127,21 +130,104 @@ const char *eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char *buff
#endif #endif
#ifdef EQEMU_USE_OPENSSL #ifdef EQEMU_USE_OPENSSL
DES_key_schedule k; // Decrypt requires block-aligned input; encrypt zero-pads a trailing
DES_cblock v; // partial block to match the legacy DES_ncbc_encrypt semantics the
// game protocol expects.
memset(&k, 0, sizeof(DES_key_schedule));
memset(&v, 0, sizeof(DES_cblock));
if (!enc && buffer_in_sz && buffer_in_sz % 8 != 0) { if (!enc && buffer_in_sz && buffer_in_sz % 8 != 0) {
return nullptr; return nullptr;
} }
DES_ncbc_encrypt((const unsigned char*)buffer_in, (unsigned char*)buffer_out, (long)buffer_in_sz, &k, &v, enc); unsigned char key[8] = {0};
unsigned char iv[8] = {0};
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
if (!ctx) {
return nullptr;
}
bool result = EVP_CipherInit_ex2(ctx, EVP_des_cbc(), key, iv, enc, nullptr) == 1;
if (result) {
EVP_CIPHER_CTX_set_padding(ctx, 0);
const unsigned char* src = reinterpret_cast<const unsigned char*>(buffer_in);
size_t src_len = buffer_in_sz;
std::unique_ptr<unsigned char[]> padded;
if (enc && buffer_in_sz % 8 != 0) {
src_len = ((buffer_in_sz / 8) + 1) * 8;
padded.reset(new unsigned char[src_len]());
memcpy(padded.get(), buffer_in, buffer_in_sz);
src = padded.get();
}
int outl = 0;
int final_len = 0;
result = EVP_CipherUpdate(ctx, reinterpret_cast<unsigned char*>(buffer_out), &outl, src, static_cast<int>(src_len)) == 1
&& EVP_CipherFinal_ex(ctx, reinterpret_cast<unsigned char*>(buffer_out) + outl, &final_len) == 1;
}
EVP_CIPHER_CTX_free(ctx);
if (!result) {
return nullptr;
}
#endif #endif
return buffer_out; return buffer_out;
} }
#ifdef EQEMU_USE_OPENSSL
static OSSL_PROVIDER *s_legacy_provider = nullptr;
static OSSL_PROVIDER *s_default_provider = nullptr;
#endif
bool eqcrypt_init()
{
#ifdef EQEMU_USE_OPENSSL
#ifdef _WIN32
// Set OpenSSL default provider search path to the executable directory.
char* exe_path = nullptr;
if (_get_pgmptr(&exe_path) == 0 && exe_path != nullptr && *exe_path != '\0') {
std::string exe_dir{exe_path};
if (auto sep = exe_dir.find_last_of("\\/"); sep != std::string::npos) {
exe_dir.resize(sep);
OSSL_PROVIDER_set_default_search_path(nullptr, exe_dir.c_str());
}
}
#endif
if (!s_default_provider) {
s_default_provider = OSSL_PROVIDER_load(nullptr, "default");
}
if (!s_legacy_provider) {
s_legacy_provider = OSSL_PROVIDER_load(nullptr, "legacy");
}
if (!s_default_provider || !s_legacy_provider) {
char buf[256];
while (auto err = ERR_get_error()) {
ERR_error_string_n(err, buf, sizeof(buf));
LogError("OpenSSL provider load failure: {}", buf);
}
return false;
}
#endif
return true;
}
void eqcrypt_shutdown()
{
#ifdef EQEMU_USE_OPENSSL
if (s_legacy_provider) {
OSSL_PROVIDER_unload(s_legacy_provider);
s_legacy_provider = nullptr;
}
if (s_default_provider) {
OSSL_PROVIDER_unload(s_default_provider);
s_default_provider = nullptr;
}
#endif
}
std::string eqcrypt_md5(const std::string &msg) std::string eqcrypt_md5(const std::string &msg)
{ {
std::string ret; std::string ret;
@@ -164,13 +250,13 @@ std::string eqcrypt_md5(const std::string &msg)
unsigned char md5_digest[16]; unsigned char md5_digest[16];
char tmp[4]; char tmp[4];
MD5((const unsigned char*)msg.c_str(), msg.length(), md5_digest); if (EVP_Digest(msg.data(), msg.length(), md5_digest, nullptr, EVP_md5(), nullptr) == 1) {
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
sprintf(&tmp[0], "%02x", md5_digest[i]); sprintf(&tmp[0], "%02x", md5_digest[i]);
ret.push_back(tmp[0]); ret.push_back(tmp[0]);
ret.push_back(tmp[1]); ret.push_back(tmp[1]);
} }
}
#endif #endif
return ret; return ret;
@@ -198,13 +284,13 @@ std::string eqcrypt_sha1(const std::string &msg)
unsigned char sha_digest[20]; unsigned char sha_digest[20];
char tmp[4]; char tmp[4];
SHA1((const unsigned char*)msg.c_str(), msg.length(), sha_digest); if (EVP_Digest(msg.data(), msg.length(), sha_digest, nullptr, EVP_sha1(), nullptr) == 1) {
for (int i = 0; i < 20; ++i) { for (int i = 0; i < 20; ++i) {
sprintf(&tmp[0], "%02x", sha_digest[i]); sprintf(&tmp[0], "%02x", sha_digest[i]);
ret.push_back(tmp[0]); ret.push_back(tmp[0]);
ret.push_back(tmp[1]); ret.push_back(tmp[1]);
} }
}
#endif #endif
return ret; return ret;
@@ -232,13 +318,13 @@ std::string eqcrypt_sha512(const std::string &msg)
unsigned char sha_digest[64]; unsigned char sha_digest[64];
char tmp[4]; char tmp[4];
SHA512((const unsigned char*)msg.c_str(), msg.length(), sha_digest); if (EVP_Digest(msg.data(), msg.length(), sha_digest, nullptr, EVP_sha512(), nullptr) == 1) {
for (int i = 0; i < 64; ++i) { for (int i = 0; i < 64; ++i) {
sprintf(&tmp[0], "%02x", sha_digest[i]); sprintf(&tmp[0], "%02x", sha_digest[i]);
ret.push_back(tmp[0]); ret.push_back(tmp[0]);
ret.push_back(tmp[1]); ret.push_back(tmp[1]);
} }
}
#endif #endif
return ret; return ret;
+10
View File
@@ -48,10 +48,20 @@ namespace CryptoHash {
} }
std::string GetEncryptionByModeId(uint32 mode); std::string GetEncryptionByModeId(uint32 mode);
// DES-CBC with an all-zero key and IV (EQ login protocol obfuscation, not security).
// On encrypt, a trailing partial block is zero-padded to the next 8-byte boundary, so
// buffer_out must be at least ((buffer_in_sz + 7) / 8) * 8 bytes. On decrypt, buffer_in_sz
// must already be a multiple of 8 or the call returns nullptr.
const char *eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char *buffer_out, bool enc); const char *eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char *buffer_out, bool enc);
std::string eqcrypt_hash(const std::string &username, const std::string &password, int mode); std::string eqcrypt_hash(const std::string &username, const std::string &password, int mode);
bool eqcrypt_verify_hash(const std::string &username, const std::string &password, const std::string &pwhash, int mode); bool eqcrypt_verify_hash(const std::string &username, const std::string &password, const std::string &pwhash, int mode);
// OpenSSL 3.0 moved DES behind the "legacy" provider; these load/unload it
// for the lifetime of the process. No-op when built against mbedtls.
bool eqcrypt_init();
void eqcrypt_shutdown();
struct EncryptionResult { struct EncryptionResult {
std::string password; std::string password;
int mode = 0; int mode = 0;
+1 -22
View File
@@ -67,21 +67,6 @@ struct PlayerLoginReply {
char unknown[1]; // variable length, password unlikely? client doesn't send this on re-login from char select char unknown[1]; // variable length, password unlikely? client doesn't send this on re-login from char select
}; };
struct PlayerLoginReplySteamLatest
{
LoginBaseReplyMessage base_reply;
int8_t unk1; // (default: 0)
int8_t unk2; // (default: 0)
int32_t lsid; // (default: -1)
char key[11]; // client reads until null (variable length)
int32_t failed_attempts;
bool show_player_count; // admin flag, enables admin button and shows server player counts (default: false)
int32_t unk3; // guess, needs more investigation (default: 0)
int32_t unk4; // guess, needs more investigation (default: 0)
char username[1]; // variable length, if not empty client attempts to re-login to server select when quitting from char select and sends this in a struct
char unknown[1]; // variable length, password unlikely? client doesn't send this on re-login from char select
};
// variable length, for reference // variable length, for reference
struct LoginClientServerData { struct LoginClientServerData {
char ip[1]; char ip[1];
@@ -115,18 +100,12 @@ struct PlayEverquestResponse {
uint32 server_number; uint32 server_number;
}; };
//for reference
struct SystemFingerprint {
LoginBaseMessage base_header;
char fingerprint[1];
};
#pragma pack() #pragma pack()
enum LSClientVersion { enum LSClientVersion {
cv_titanium, cv_titanium,
cv_sod, cv_sod,
cv_steam_latest cv_larion
}; };
enum LSClientStatus { enum LSClientStatus {
@@ -3,12 +3,12 @@ OP_SessionReady=0x0001
OP_Login=0x0002 OP_Login=0x0002
OP_ServerListRequest=0x0004 OP_ServerListRequest=0x0004
OP_PlayEverquestRequest=0x000d OP_PlayEverquestRequest=0x000d
OP_PlayEverquestResponse=0x0023 OP_PlayEverquestResponse=0x0022
OP_ChatMessage=0x0018 OP_ChatMessage=0x0017
OP_LoginAccepted=0x0019 OP_LoginAccepted=0x0018
OP_ServerListResponse=0x001a OP_ServerListResponse=0x0019
OP_Poll=0x002a OP_Poll=0x0029
OP_EnterChat=0x000f OP_EnterChat=0x000f
OP_PollResponse=0x0011 OP_PollResponse=0x0011
OP_SystemFingerprint=0x0016 OP_SystemFingerprint=0x0016
OP_ExpansionList=0x0031 OP_ExpansionList=0x0030
+7 -4
View File
@@ -26,6 +26,7 @@
#include "common/platform.h" #include "common/platform.h"
#include "common/timer.h" #include "common/timer.h"
#include "common/types.h" #include "common/types.h"
#include "loginserver/encryption.h"
#include "loginserver/login_server.h" #include "loginserver/login_server.h"
#include "loginserver/loginserver_command_handler.h" #include "loginserver/loginserver_command_handler.h"
#include "loginserver/loginserver_webserver.h" #include "loginserver/loginserver_webserver.h"
@@ -158,12 +159,12 @@ void start_web_server()
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
RegisterExecutablePlatform(ExePlatformLogin); RegisterExecutablePlatform(ExePlatformLogin);
EQEmuLogSys::Instance()->LoadLogSettingsDefaults();
set_exception_handler(); set_exception_handler();
LogInfo("Logging System Init"); if (!eqcrypt_init()) {
LogError("Failed to initialize crypto providers");
if (argc == 1) { return 1;
EQEmuLogSys::Instance()->LoadLogSettingsDefaults();
} }
PathManager::Instance()->Init(); PathManager::Instance()->Init();
@@ -280,5 +281,7 @@ int main(int argc, char **argv)
LogInfo("Server Manager Shutdown"); LogInfo("Server Manager Shutdown");
delete server.server_manager; delete server.server_manager;
eqcrypt_shutdown();
return 0; return 0;
} }
+13 -50
View File
@@ -706,54 +706,6 @@ bool WorldServer::ValidateWorldServerAdminLogin(
void WorldServer::SerializeForClientServerList(SerializeBuffer &out, bool use_local_ip, LSClientVersion version) const void WorldServer::SerializeForClientServerList(SerializeBuffer &out, bool use_local_ip, LSClientVersion version) const
{ {
if (version == cv_steam_latest) {
if (use_local_ip) {
out.WriteString(GetLocalIP());
}
else {
out.WriteString(m_remote_ip_address);
}
out.WriteInt32(9000); // port, not currently settable in eqemu but needed for compat
switch (GetServerListID()) {
case LS::ServerType::Legends:
out.WriteInt32(LS::ServerTypeFlags::Legends);
break;
case LS::ServerType::Preferred:
out.WriteInt32(LS::ServerTypeFlags::Preferred);
break;
default:
out.WriteInt32(LS::ServerTypeFlags::Standard);
break;
}
out.WriteInt32(289); //unsure what this is yet
out.WriteUInt32(m_server_id);
out.WriteString(m_server_long_name);
out.WriteString("US"); // country code
out.WriteString("EN"); // language code
out.WriteString("Standard");
out.WriteString("This server has no description set currently.");
if (GetStatus() < 0) {
if (GetZonesBooted() == 0) {
out.WriteInt32(LS::ServerStatusFlags::Down);
}
else {
out.WriteInt32(LS::ServerStatusFlags::Locked);
}
}
else {
out.WriteInt32(LS::ServerStatusFlags::Up);
}
out.WriteUInt32(GetPlayersOnline());
out.WriteInt32(31); //expansions
out.WriteInt32(0); //truebox
}
else {
// see LoginClientServerData_Struct // see LoginClientServerData_Struct
if (use_local_ip) { if (use_local_ip) {
out.WriteString(GetLocalIP()); out.WriteString(GetLocalIP());
@@ -762,6 +714,10 @@ void WorldServer::SerializeForClientServerList(SerializeBuffer &out, bool use_lo
out.WriteString(m_remote_ip_address); out.WriteString(m_remote_ip_address);
} }
if (version == cv_larion) {
out.WriteUInt32(9000);
}
switch (GetServerListID()) { switch (GetServerListID()) {
case LS::ServerType::Legends: case LS::ServerType::Legends:
out.WriteInt32(LS::ServerTypeFlags::Legends); out.WriteInt32(LS::ServerTypeFlags::Legends);
@@ -773,8 +729,16 @@ void WorldServer::SerializeForClientServerList(SerializeBuffer &out, bool use_lo
out.WriteInt32(LS::ServerTypeFlags::Standard); out.WriteInt32(LS::ServerTypeFlags::Standard);
break; break;
} }
if (version == cv_larion) {
auto server_id = m_server_id;
//if this is 0, the client will not show the server in the list
out.WriteUInt32(1);
out.WriteUInt32(server_id);
}
else {
out.WriteUInt32(m_server_id); out.WriteUInt32(m_server_id);
}
out.WriteString(m_server_long_name); out.WriteString(m_server_long_name);
out.WriteString("us"); // country code out.WriteString("us"); // country code
out.WriteString("en"); // language code out.WriteString("en"); // language code
@@ -794,7 +758,6 @@ void WorldServer::SerializeForClientServerList(SerializeBuffer &out, bool use_lo
out.WriteUInt32(GetPlayersOnline()); out.WriteUInt32(GetPlayersOnline());
} }
}
void WorldServer::FormatWorldServerName(char *name, int8 server_list_type) void WorldServer::FormatWorldServerName(char *name, int8 server_list_type)
{ {
+1 -1
View File
@@ -153,7 +153,7 @@ std::unique_ptr<EQApplicationPacket> WorldServerManager::CreateServerListPacket(
s->SerializeForClientServerList(buf, use_local_ip, client->GetClientVersion()); s->SerializeForClientServerList(buf, use_local_ip, client->GetClientVersion());
} }
return std::make_unique<EQApplicationPacket>(OP_ServerListResponse, buf); return std::make_unique<EQApplicationPacket>(OP_ServerListResponse, std::move(buf));
} }
void WorldServerManager::SendUserLoginToWorldRequest( void WorldServerManager::SendUserLoginToWorldRequest(
-1
View File
@@ -1 +0,0 @@
This is a bunch of ImHex patterns for viewing various Outer Brood packets
@@ -1,23 +0,0 @@
struct BaseResponse
{
u8 success;
u32 error_str_id;
char error_str[];
};
struct Packet {
BaseResponse base;
s8 unk1; //I think this is just padding
s8 unk2; //I think this is just padding
u32 lsid;
char key[];
s32 failed_attempts;
u8 show_player_count;
s32 unk3; // 0
s32 unk4; // 0
char username[];
char password[]; //I'm not sure this is correct, it feels like this might be some internal refresh token
char paddingEnd[2];
};
Packet p @ 0x00;
-19
View File
@@ -1,19 +0,0 @@
// 0x01
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Packet {
LoginBase base;
u8 success;
s32 error_str_id;
char error_msg[];
char other_msg[];
};
Packet packet @0x00;
-22
View File
@@ -1,22 +0,0 @@
// 0x31
struct Expansion
{
u32 index;
u8 owned;
s32 expansion_name_string_id;
s32 order_string_id;
s32 unknown_string_id;
u32 unknown17;
};
struct Packet {
u32 unknown00;
u32 unknown04;
u16 unknown08;
u32 expansion_count;
Expansion expansions[expansion_count];
};
Packet packet @0x00;
-18
View File
@@ -1,18 +0,0 @@
// 0x02
#include <std/mem.pat>
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Packet {
LoginBase base;
u8 payload[std::mem::size() - $];
};
Packet packet @0x00;
-18
View File
@@ -1,18 +0,0 @@
// 0x19
#include <std/mem.pat>
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Packet {
LoginBase base;
u8 payload[std::mem::size() - $];
};
Packet packet @0x00;
@@ -1,20 +0,0 @@
// 0xd
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Packet {
LoginBase base;
u32 server_id;
char fingerprint[];
u32 unknown1;
u8 unknown2;
u32 unknown3;
};
Packet packet @0x00;
@@ -1,19 +0,0 @@
// 0x23
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Packet {
LoginBase base;
u8 success;
u32 login_server_string_id;
char login_server_string;
};
Packet packet @0x00;
@@ -1,15 +0,0 @@
// 0x04
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Packet {
LoginBase base;
};
Packet packet @0x00;
@@ -1,44 +0,0 @@
// 0x1a
// work in progress
struct LoginBase
{
u32 sequence_id;
u8 compressed;
u8 encrypt_type;
u32 unknown08;
};
struct Realm
{
char address[];
u32 port;
u32 server_category;
//not sure yet, seen 289 on a lot of classic servers
//41 fangbreaker, teek, oakwynd, tormax
//31 yelniak
//33 vaniki, mischief
u32 status_code;
u32 server_id;
char name[];
char language[];
char region[];
char server_type_desc[];
char server_desc[];
u32 server_flags;
u32 players_online;
u32 expansion; //I think
u32 truebox_max_clients;
};
struct Packet {
LoginBase base;
u8 success;
u32 login_server_string_id;
char login_server_string[];
u32 realm_count;
Realm realms[realm_count];
};
Packet packet @0x00;

Some files were not shown because too many files have changed in this diff Show More