Compare commits

..

10 Commits

491 changed files with 23585 additions and 24827 deletions
+23
View File
@@ -0,0 +1,23 @@
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
[*.cpp]
indent_style = tab
[*.h]
indent_style = tab
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
+13 -3
View File
@@ -23,11 +23,21 @@ CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
[Bb]uild*/
Build/
build/
Build32/
build32/
Build64/
build64/
Build_32/
build_32/
Build_64/
build_64/
x64/
x86/
log/
logs/
vcpkg/
.idea/*
*cbp
.editorconfig
*cbp
+7 -7
View File
@@ -1,3 +1,6 @@
[submodule "submodules/websocketpp"]
path = submodules/websocketpp
url = https://github.com/zaphoyd/websocketpp.git
[submodule "submodules/glm"]
path = submodules/glm
url = https://github.com/g-truc/glm.git
@@ -10,12 +13,9 @@
[submodule "submodules/cereal"]
path = submodules/cereal
url = https://github.com/USCiLab/cereal.git
[submodule "submodules/websocketpp"]
path = submodules/websocketpp
url = https://github.com/zaphoyd/websocketpp.git
[submodule "submodules/recastnavigation"]
path = submodules/recastnavigation
url = https://github.com/EQEmu/recastnavigation.git
[submodule "submodules/zlibng"]
path = submodules/zlibng
url = https://github.com/zlib-ng/zlib-ng.git
url = https://github.com/recastnavigation/recastnavigation.git
[submodule "submodules/concurrentqueue"]
path = submodules/concurrentqueue
url = https://github.com/cameron314/concurrentqueue.git
+284 -229
View File
@@ -1,24 +1,122 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
#EQEmu CMake
#Variables used:
#EQEMU_DISABLE_CRT_SECURE_WARNINGS
#EQEMU_FAST_FLOATINGPOINT
#EQEMU_ENABLE_CRASH_LOGGING
#EQEMU_DISABLE_SAFESEH
#EQEMU_BUILD_MSVC_MP
#EQEMU_DEBUG_LEVEL
#EQEMU_LOG_LEVEL_STATUS
#EQEMU_LOG_LEVEL_NORMAL
#EQEMU_LOG_LEVEL_ERROR
#EQEMU_LOG_LEVEL_DEBUG
#EQEMU_LOG_LEVEL_QUEST
#EQEMU_LOG_LEVEL_COMMANDS
#EQEMU_LOG_LEVEL_CRASH
#EQEMU_DEPOP_INVALIDATES_CACHE
#EQEMU_ENABLE_BOTS
#EQEMU_DISABLE_LOGSYS
#EQEMU_COMMANDS_LOGGING
#EQEMU_BUILD_SERVER
#EQEMU_BUILD_LOGIN
#EQEMU_BUILD_TESTS
#EQEMU_BUILD_PERL
#EQEMU_BUILD_LUA
#EQEMU_SANITIZE_LUA_LIBS
#EQEMU_BUILD_CLIENT_FILES
#EQEMU_USE_MAP_MMFS
#EQEMU_MAP_DIR
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
IF(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
ENDIF()
#FindMySQL is located here so lets make it so CMake can find it
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH})
#Our project name is EQEmu
PROJECT(EQEmu)
#Default build type is set to RelWithDebInfo for generators that honor that like makefiles
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dependencies" "${CMAKE_PREFIX_PATH}")
#Add our various windows definitions
IF(MSVC OR MINGW)
ADD_DEFINITIONS(-D_WINDOWS)
IF(CMAKE_CL_64)
ADD_DEFINITIONS(-DWIN64)
ELSE(CMAKE_CL_64)
ADD_DEFINITIONS(-DWIN32)
ENDIF(CMAKE_CL_64)
ENDIF(MSVC OR MINGW)
IF(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
IF(CMAKE_CL_64)
SET(ZLIB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zlib_x64")
SET(MYSQL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/mysql_x64")
SET(LUA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/luaj_x64")
SET(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/openssl_x64")
SET(SODIUM_INCLUDE_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/include")
IF(MSVC_VERSION GREATER 1800)
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/x64/Release/v140/dynamic")
ELSEIF(MSVC_VERSION EQUAL 1800)
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/x64/Release/v120/dynamic")
ELSE()
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/x64/Release/v110/dynamic")
ENDIF()
ELSE(CMAKE_CL_64)
SET(ZLIB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zlib_x86")
SET(MYSQL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/mysql_x86")
SET(LUA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/luaj_x86")
SET(SODIUM_INCLUDE_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/include")
SET(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/openssl_x86")
IF(MSVC_VERSION GREATER 1800)
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/Win32/Release/v140/dynamic")
ELSEIF(MSVC_VERSION EQUAL 1800)
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/Win32/Release/v120/dynamic")
ELSE()
SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/Win32/Release/v110/dynamic")
ENDIF()
ENDIF(CMAKE_CL_64)
#disable CRT warnings on windows cause they're annoying as shit and we use C functions everywhere
OPTION(EQEMU_DISABLE_CRT_SECURE_WARNINGS "Disable Secure CRT Warnings" ON)
IF(EQEMU_DISABLE_CRT_SECURE_WARNINGS)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
ENDIF(EQEMU_DISABLE_CRT_SECURE_WARNINGS)
#fast FP if you'd like it
OPTION(EQEMU_FAST_FLOATINGPOINT "Use MSVC /fp:fast option" ON)
IF(EQEMU_FAST_FLOATINGPOINT)
ADD_DEFINITIONS(/fp:fast)
ENDIF(EQEMU_FAST_FLOATINGPOINT)
#crash logging currently only works on windows x86/x64
OPTION(EQEMU_ENABLE_CRASH_LOGGING "Enable crash logging" ON)
IF(EQEMU_ENABLE_CRASH_LOGGING)
ADD_DEFINITIONS(-DCRASH_LOGGING)
ENDIF(EQEMU_ENABLE_CRASH_LOGGING)
OPTION(EQEMU_BUILD_MSVC_MP "Enable build with multiple processes." ON)
IF(EQEMU_BUILD_MSVC_MP)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ENDIF(EQEMU_BUILD_MSVC_MP)
#We want to compile /MT not /MD so we change that
FOREACH(flag_var CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
IF(${flag_var} MATCHES "/MD")
STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
ENDIF(${flag_var} MATCHES "/MD")
ENDFOREACH(flag_var)
ADD_DEFINITIONS(-DNOMINMAX)
ADD_DEFINITIONS(-DCRASH_LOGGING)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
ELSE(MSVC)
#Normally set by perl but we don't use the perl flags anymore so we set it.
ADD_DEFINITIONS(-DHAS_UNION_SEMUN)
ENDIF(MSVC)
@@ -35,239 +133,180 @@ IF(UNIX)
ENDIF(CMAKE_SYSTEM_NAME MATCHES "Darwin")
ENDIF(UNIX)
ADD_DEFINITIONS(-DGLM_FORCE_RADIANS)
ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT)
ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL)
#debug level, 5 is default. Most people wont ever change this but it's there if you want to
SET(EQEMU_DEBUG_LEVEL 5 CACHE STRING "EQEmu debug level:
0 - Quiet mode Errors to file Status and Normal ignored
1 - Status and Normal to console, Errors to logfile
2 - Status, Normal, and Error to console and logfile
3 - Light debug release errors and status
4 - Moderate debug release errors and status
5 - Maximum debug release errors and status
10 - More errors than you ever wanted to see"
)
#Find everything we need
FIND_PACKAGE(MySQL)
FIND_PACKAGE(MariaDB)
FIND_PACKAGE(Boost REQUIRED)
FIND_PACKAGE(ZLIB)
FIND_PACKAGE(OpenSSL)
FIND_PACKAGE(Lua51)
FIND_PACKAGE(PerlLibs)
FIND_PACKAGE(Sodium)
FIND_PACKAGE(mbedTLS)
SET(EQEMU_LOG_LEVEL_STATUS 2 CACHE STRING "EQEmu logging level for [Status]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Library Detection *")
MESSAGE(STATUS "**************************************************")
SET(EQEMU_LOG_LEVEL_NORMAL 3 CACHE STRING "EQEmu logging level for [Normal]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(MYSQL_FOUND)
MESSAGE(STATUS "* MySQL: FOUND *")
ELSE()
MESSAGE(STATUS "* MySQL: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_ERROR 2 CACHE STRING "EQEmu logging level for [Error]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(MARIADB_FOUND)
MESSAGE(STATUS "* MariaDB: FOUND *")
ELSE()
MESSAGE(STATUS "* MariaDB: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_DEBUG 3 CACHE STRING "EQEmu logging level for [Debug]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(ZLIB_FOUND)
MESSAGE(STATUS "* ZLIB: FOUND *")
ELSE()
MESSAGE(STATUS "* ZLIB: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_QUEST 2 CACHE STRING "EQEmu logging level for [Quest]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(Lua51_FOUND)
MESSAGE(STATUS "* Lua: FOUND *")
ELSE()
MESSAGE(STATUS "* Lua: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_COMMANDS 1 CACHE STRING "EQEmu logging level for [Commands]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(PerlLibs_FOUND)
MESSAGE(STATUS "* Perl: FOUND *")
ELSE()
MESSAGE(STATUS "* Perl: MISSING *")
ENDIF()
SET(EQEMU_LOG_LEVEL_CRASH 3 CACHE STRING "EQEmu logging level for [Crash]:
0 - Disabled
1 - Ouput to File Enabled
2 - Output to stdout Enabled
3 - Output to File and stdout Enabled
8 - Output to stderr Enabled
9 - Output to File and stderr Enabled
11 - Output to File, stdout and stderr Enabled"
)
IF(SODIUM_FOUND)
MESSAGE(STATUS "* libsodium: FOUND *")
ELSE()
MESSAGE(STATUS "* libsodium: MISSING *")
ENDIF()
MARK_AS_ADVANCED(EQEMU_LOG_LEVEL_STATUS EQEMU_LOG_LEVEL_NORMAL EQEMU_LOG_LEVEL_ERROR EQEMU_LOG_LEVEL_DEBUG EQEMU_LOG_LEVEL_QUEST EQEMU_LOG_LEVEL_COMMANDS EQEMU_LOG_LEVEL_CRASH)
IF(OpenSSL_FOUND)
MESSAGE(STATUS "* OpenSSL: FOUND *")
ELSE()
MESSAGE(STATUS "* OpenSSL: MISSING *")
ENDIF()
IF(MBEDTLS_FOUND)
MESSAGE(STATUS "* mbedTLS: FOUND *")
ELSE()
MESSAGE(STATUS "* mbedTLS: MISSING *")
ENDIF()
MESSAGE(STATUS "**************************************************")
#options
#NPC Types Cache Behavior
OPTION(EQEMU_DEPOP_INVALIDATES_CACHE "#repop invalidates the npc_types cache (will cause a larger database hit on #repop but is more convienent)." ON)
#Bots are a compile time option so on/off
OPTION(EQEMU_ENABLE_BOTS "Enable Bots" OFF)
#Disable entire _mlog system (excludes trade/command logs)
OPTION(EQEMU_DISABLE_LOGSYS "Disable Logging INI System" ON)
#Enable GM Command log system
OPTION(EQEMU_COMMANDS_LOGGING "Enable GM Command logs" ON)
OPTION(EQEMU_BUILD_SERVER "Build the game server." ON)
OPTION(EQEMU_BUILD_HC "Build the headless client." OFF)
OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
IF(EQEMU_COMMANDS_LOGGING)
ADD_DEFINITIONS(-DCOMMANDS_LOGGING)
ENDIF(EQEMU_COMMANDS_LOGGING)
IF(EQEMU_DISABLE_LOGSYS)
ADD_DEFINITIONS(-DDISABLE_LOGSYS)
ENDIF(EQEMU_DISABLE_LOGSYS)
IF(EQEMU_ENABLE_BOTS)
ADD_DEFINITIONS(-DBOTS)
ENDIF(EQEMU_ENABLE_BOTS)
#database
#prefer mariadb to mysql (arbitrary)
IF(MySQL_FOUND AND MariaDB_FOUND)
SET(DATABASE_LIBRARY_TYPE "MariaDB")
SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR})
ELSEIF(MariaDB_FOUND)
SET(DATABASE_LIBRARY_TYPE "MariaDB")
SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR})
ELSEIF(MySQL_FOUND)
SET(DATABASE_LIBRARY_TYPE " MySQL")
SET(DATABASE_LIBRARY_LIBS ${MySQL_LIBRARIES})
SET(DATABASE_LIBRARY_INCLUDE ${MySQL_INCLUDE_DIR})
ELSE()
MESSAGE(FATAL_ERROR "One of MySQL or MariaDB is a required dependency.")
ENDIF()
#What to build
OPTION(EQEMU_BUILD_SERVER "Build the game server." ON)
OPTION(EQEMU_BUILD_LOGIN "Build the login server." OFF)
OPTION(EQEMU_BUILD_HC "Build the headless client." OFF)
OPTION(EQEMU_BUILD_TESTS "Build utility tests." OFF)
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON)
OPTION(EQEMU_BUILD_CLIENT_FILES "Build Client Import/Export Data Programs." ON)
#security
#prefer openssl to mbedtls (arbitrary)
IF(OpenSSL_FOUND AND MBEDTLS_FOUND)
SET(SSL_LIBRARY_TYPE " OpenSSL")
SET(SSL_LIBRARY_ENABLED ON)
SET(SSL_LIBRARY_LIBS ${OPENSSL_LIBRARIES})
SET(SSL_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR})
ELSEIF(OpenSSL_FOUND)
SET(SSL_LIBRARY_TYPE " OpenSSL")
SET(SSL_LIBRARY_ENABLED ON)
SET(SSL_LIBRARY_LIBS ${OPENSSL_LIBRARIES})
SET(SSL_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR})
ELSEIF(MBEDTLS_FOUND)
SET(SSL_LIBRARY_TYPE " mbedTLS")
SET(SSL_LIBRARY_ENABLED ON)
SET(SSL_LIBRARY_LIBS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
SET(SSL_LIBRARY_INCLUDE ${MBEDTLS_INCLUDE_DIR})
ELSE()
SET(SSL_LIBRARY_TYPE "Disabled")
SET(SSL_LIBRARY_ENABLED OFF)
ENDIF()
IF(SODIUM_FOUND)
SET(SODIUM_LIBRARY_TYPE "Libsodium")
SET(SODIUM_LIBRARY_ENABLED ON)
SET(SODIUM_LIBRARY_LIBS ${SODIUM_LIBRARIES})
SET(SODIUM_LIBRARY_INCLUDE ${SODIUM_INCLUDE_DIRS})
ADD_DEFINITIONS(-DENABLE_SECURITY)
ELSE()
SET(SODIUM_LIBRARY_TYPE " Disabled")
SET(SODIUM_LIBRARY_ENABLED OFF)
ENDIF()
IF(Lua51_FOUND)
SET(LUA_LIBRARY_TYPE " Lua 5.1")
SET(LUA_LIBRARY_LIBS ${LUA_LIBRARY} luabind)
SET(LUA_LIBRARY_INCLUDE ${LUA_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind")
OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON)
IF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DLUA_EQEMU)
OPTION(EQEMU_SANITIZE_LUA_LIBS "Sanitize Lua Libraries (Remove OS and IO standard libraries from being able to run)." ON)
IF(EQEMU_SANITIZE_LUA_LIBS)
ADD_DEFINITIONS(-DSANITIZE_LUA_LIBS)
ENDIF()
#C++11 stuff
IF(NOT MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reserved-user-defined-literal")
ENDIF()
ELSE()
SET(LUA_LIBRARY_TYPE "Disabled")
ENDIF()
IF(PerlLibs_FOUND)
SET(PERL_LIBRARY_TYPE " Perl")
SET(PERL_LIBRARY_LIBS ${PERL_LIBRARY})
SET(PERL_LIBRARY_INCLUDE ${PERL_INCLUDE_PATH})
OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON)
IF(EQEMU_BUILD_PERL)
ADD_DEFINITIONS(-DEMBPERL)
ADD_DEFINITIONS(-DEMBPERL_PLUGIN)
ENDIF()
ELSE()
SET(PERL_LIBRARY_TYPE "Disabled")
ENDIF()
#use zlib if exists
IF(ZLIB_FOUND)
OPTION(EQEMU_BUILD_ZLIB "Build internal version of zlib." OFF)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_LIBRARY_TYPE "zlib-ng")
SET(ZLIB_LIBRARY_LIBS "zlibstatic")
SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/zlibng")
ELSE()
SET(ZLIB_LIBRARY_TYPE " zlib")
SET(ZLIB_LIBRARY_LIBS ${ZLIB_LIBRARY})
SET(ZLIB_LIBRARY_INCLUDE ${ZLIB_INCLUDE_DIRS})
ENDIF()
ELSE()
SET(ZLIB_LIBRARY_TYPE "zlib-ng")
SET(ZLIB_LIBRARY_LIBS "zlibstatic")
SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/submodules/zlibng")
ENDIF()
MESSAGE(STATUS "")
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Library Usage *")
MESSAGE(STATUS "**************************************************")
MESSAGE(STATUS "* Database: ${DATABASE_LIBRARY_TYPE} *")
MESSAGE(STATUS "* TLS: ${SSL_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Sodium: ${SODIUM_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Lua: ${LUA_LIBRARY_TYPE} *")
MESSAGE(STATUS "* Perl: ${PERL_LIBRARY_TYPE} *")
MESSAGE(STATUS "* zlib: ${ZLIB_LIBRARY_TYPE} *")
MESSAGE(STATUS "**************************************************")
#setup server libs and headers
SET(SERVER_LIBS common ${DATABASE_LIBRARY_LIBS} ${ZLIB_LIBRARY_LIBS} ${Boost_LIBRARIES} uv_a fmt RecastNavigation::Detour)
INCLUDE_DIRECTORIES(SYSTEM "${DATABASE_LIBRARY_INCLUDE}")
INCLUDE_DIRECTORIES(SYSTEM "${ZLIB_LIBRARY_INCLUDE}")
INCLUDE_DIRECTORIES(SYSTEM "${Boost_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/glm")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/cereal/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/fmt/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/libuv/include" )
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DebugUtils/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Detour/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourCrowd/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourTileCache/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Recast/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/websocketpp")
IF(SSL_LIBRARY_ENABLED)
SET(SERVER_LIBS ${SERVER_LIBS} ${SSL_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${SSL_LIBRARY_INCLUDE}")
ENDIF()
IF(SODIUM_LIBRARY_ENABLED)
SET(SERVER_LIBS ${SERVER_LIBS} ${SODIUM_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${SODIUM_LIBRARY_INCLUDE}")
ENDIF()
IF(EQEMU_BUILD_LUA)
SET(SERVER_LIBS ${SERVER_LIBS} ${LUA_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${LUA_LIBRARY_INCLUDE}")
ENDIF()
ENDIF(NOT MSVC)
#Various definitions
IF(EQEMU_BUILD_PERL)
SET(SERVER_LIBS ${SERVER_LIBS} ${PERL_LIBRARY_LIBS})
INCLUDE_DIRECTORIES(SYSTEM "${PERL_LIBRARY_INCLUDE}")
ADD_DEFINITIONS(-DEMBPERL)
ADD_DEFINITIONS(-DEMBPERL_PLUGIN)
ENDIF(EQEMU_BUILD_PERL)
IF(EQEMU_BUILD_LUA)
ADD_DEFINITIONS(-DLUA_EQEMU)
ENDIF(EQEMU_BUILD_LUA)
#Disabled until reevaluation performed
#OPTION(EQEMU_USE_MAP_MMFS "Create and use Zone Map MMF files." OFF)
#IF(EQEMU_USE_MAP_MMFS)
# ADD_DEFINITIONS(-DUSE_MAP_MMFS)
#ENDIF(EQEMU_USE_MAP_MMFS)
SET(EQEMU_MAP_DIR "./Maps" CACHE STRING "The dir that maps, water maps, and paths are located in.")
ADD_DEFINITIONS(-DEQDEBUG=${EQEMU_DEBUG_LEVEL})
ADD_DEFINITIONS(-DINVERSEXY)
ADD_DEFINITIONS(-DFIELD_ITEMS)
ADD_DEFINITIONS(-DMAP_DIR="${EQEMU_MAP_DIR}")
ADD_DEFINITIONS(-DLOG_LEVEL_STATUS=${EQEMU_LOG_LEVEL_STATUS})
ADD_DEFINITIONS(-DLOG_LEVEL_NORMAL=${EQEMU_LOG_LEVEL_NORMAL})
ADD_DEFINITIONS(-DLOG_LEVEL_ERROR=${EQEMU_LOG_LEVEL_ERROR})
ADD_DEFINITIONS(-DLOG_LEVEL_DEBUG=${EQEMU_LOG_LEVEL_DEBUG})
ADD_DEFINITIONS(-DLOG_LEVEL_QUEST=${EQEMU_LOG_LEVEL_QUEST})
ADD_DEFINITIONS(-DLOG_LEVEL_COMMANDS=${EQEMU_LOG_LEVEL_COMMANDS})
ADD_DEFINITIONS(-DLOG_LEVEL_CRASH=${EQEMU_LOG_LEVEL_CRASH})
ADD_DEFINITIONS(-DGLM_FORCE_RADIANS)
ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT)
ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL)
#Find everything we need
FIND_PACKAGE(ZLIB REQUIRED)
FIND_PACKAGE(MySQL REQUIRED)
IF(EQEMU_BUILD_PERL)
FIND_PACKAGE(PerlLibs REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM "${PERL_INCLUDE_PATH}")
ENDIF(EQEMU_BUILD_PERL)
SET(SERVER_LIBS common debug ${MySQL_LIBRARY_DEBUG} optimized ${MySQL_LIBRARY_RELEASE} ${ZLIB_LIBRARY} uv_a fmt RecastNavigation::Detour)
FIND_PACKAGE(Sodium REQUIRED)
IF(SODIUM_FOUND)
OPTION(EQEMU_ENABLE_SECURITY "Use Encryption For TCP Connections" ON)
IF(EQEMU_ENABLE_SECURITY)
INCLUDE_DIRECTORIES(SYSTEM "${SODIUM_INCLUDE_DIRS}")
ADD_DEFINITIONS(-DENABLE_SECURITY)
SET(SERVER_LIBS ${SERVER_LIBS} ${SODIUM_LIBRARIES})
ENDIF()
ENDIF()
IF(WIN32)
@@ -282,9 +321,35 @@ IF(UNIX)
SET(SERVER_LIBS ${SERVER_LIBS} "uuid")
ENDIF()
IF(EQEMU_BUILD_LOGIN AND NOT SSL_LIBRARY_ENABLED)
MESSAGE(FATAL_ERROR "Login server requires a SSL Library to build.")
ENDIF()
IF(EQEMU_BUILD_LUA)
FIND_PACKAGE(EQLua51 REQUIRED)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
SET(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/boost")
FIND_PACKAGE(Boost REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM "${LUA_INCLUDE_DIR}" "${Boost_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind")
OPTION(EQEMU_SANITIZE_LUA_LIBS "Sanitize Lua Libraries (Remove OS and IO standard libraries from being able to run)." ON)
IF(EQEMU_SANITIZE_LUA_LIBS)
ADD_DEFINITIONS(-DSANITIZE_LUA_LIBS)
ENDIF(EQEMU_SANITIZE_LUA_LIBS)
ENDIF(EQEMU_BUILD_LUA)
INCLUDE_DIRECTORIES(SYSTEM "${ZLIB_INCLUDE_DIRS}")
INCLUDE_DIRECTORIES(SYSTEM "${MySQL_INCLUDE_DIR}")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/glm")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/cereal/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/fmt/include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/libuv/include" )
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DebugUtils/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Detour/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourCrowd/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/DetourTileCache/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/recastnavigation/Recast/Include")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/submodules/concurrentqueue")
IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC)
ADD_SUBDIRECTORY(common)
@@ -292,20 +357,11 @@ IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_H
ADD_SUBDIRECTORY(submodules/fmt)
ADD_SUBDIRECTORY(submodules/libuv)
IF(EQEMU_BUILD_ZLIB)
SET(ZLIB_COMPAT ON CACHE BOOL "Compile with zlib compatible API")
SET(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Build test binaries")
ADD_SUBDIRECTORY(submodules/zlibng)
ENDIF()
SET(RECASTNAVIGATION_DEMO OFF CACHE BOOL "Build demo")
SET(RECASTNAVIGATION_TESTS OFF CACHE BOOL "Build tests")
SET(RECASTNAVIGATION_EXAMPLES OFF CACHE BOOL "Build examples")
ADD_SUBDIRECTORY(submodules/recastnavigation)
ENDIF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC)
MESSAGE(STATUS "Libs: ${SERVER_LIBS}")
IF(EQEMU_BUILD_SERVER)
ADD_SUBDIRECTORY(shared_memory)
ADD_SUBDIRECTORY(world)
@@ -314,7 +370,6 @@ IF(EQEMU_BUILD_SERVER)
ADD_SUBDIRECTORY(queryserv)
ADD_SUBDIRECTORY(eqlaunch)
ENDIF(EQEMU_BUILD_SERVER)
IF(EQEMU_BUILD_LOGIN)
ADD_SUBDIRECTORY(loginserver)
ENDIF(EQEMU_BUILD_LOGIN)
-6
View File
@@ -70,9 +70,3 @@ forum, although pull requests will be much quicker and easier on all parties.
* GPL Perl - GPL / ActiveState (under the assumption that this is a free project)
* CPPUnit - GLP StringUtilities - Apache
* LUA - MIT
## Contributors
<a href="https://github.com/EQEmu/server/graphs/contributors">
<img src="https://contributors-img.firebaseapp.com/image?repo=EQEmu/server" />
</a>
-3
View File
@@ -1,3 +0,0 @@
# Security Policy - Reporting Vulnerabilities
When reporting active hacks, exploits and other vulnerabilities, please describe how to reproduce said report and if you can provide context into a possible solution
-69
View File
@@ -1,74 +1,5 @@
EQEMu Changelog (Started on Sept 24, 2003 15:50)
-------------------------------------------------------
== 8/16/2019 ==
Akkadius: Simplified the use of roamboxes and improved the AI for roambox pathing https://i.imgur.com/z33u7y9.gif
Akkadius: Implemented command #roambox set <box_size> [move_delay]
Akkadius: Implemented command #roambox remove
Akkadius: Implemented LUA NPC:SetSimpleRoamBox(box_size, [move_distance], [move_delay]);
Akkadius: Implemented Perl $npc->SetSimpleRoamBox(box_size, [move_distance], [move_delay]);
Akkadius: Spawngroup data now hot reloads on #repop
Akkadius: Command #npceditmass now lists column options when one isn't properly specified
Akkadius: Implemented command #spawneditmass <search> <option> <value> with options [respawn_time] currently implemented
== 8/11/2019 ==
Akkadius: Added bulk edit command #npceditmass <column-to-search> <column-search-value> <change-column> <change-value>
Akkadius: Modified #findzone to include clickable saylinks to both regular zone (if able) and private gmzone instances
Akkadius: Added #findzone expansion <expansion-number> to show zones via expansion
== 8/6/2019 ==
Akkadius: Optimizations to movement updates to eliminate ghosting possibilities in larger zones
== 7/22/2019 ==
Uleat: Added script 'vcxproj_dependencies.py' - a script to help determine conflicting project dependencies (alpha-stage)
== 7/10/2019 ==
Akkadius: Add #npcedit flymode [0 = ground, 1 = flying, 2 = levitate, 3 = water, 4 = floating]
Akkadius: Added "flymode" to npc_types database table
== 7/3/2019 ==
Akkadius/KLS:
- Optimizations to packet updates introduced back into the source post network code overhaul
- Optimizations made to position update packets by sending updates far less frequently when not in line with zone:max_movement_update_range
- Optimizations made to position updates in respect to the much higher resolution of navmesh path-finding that we were using. We have cut down
on the resolution of path finding / updating so that we reduce the CPU overhead of path-finding and subsequent client update packets that
get generated this action
- Optimization made by adjusting ZLIB compression rate that was accidentally set to a compression level of 4 a long time ago
- Added #netstats admin command to troubleshoot connection issues in detail
- Websocket server is now available in zone and is bound to the same UDP port that the zoneserver listens on
- Currently implemented websocket API calls at the zone level
get_packet_statistics
get_opcode_list
get_npc_list_detail
get_door_list_detail
get_corpse_list_detail
get_object_list_detail
get_mob_list_detail
get_client_list_detail
get_zone_attributes
get_logsys_categories
set_logging_level
- Example of a Typescript client: https://gist.github.com/Akkadius/52d12d0379f36cf81c51b3b7da13db37
- Library Changes
- We now use git submodules for libraries / dependencies versus manually downloading to the dependencies folder and/or storing
said dependencies within our codebase itself
- To update dependencies (Required for compiling)
- git submodule init
- git submodule update
- Libraries now in submodules
- [glm] https://github.com/g-truc/glm.git
- [flm] https://github.com/fmtlib/fmt.git
- [libuv] https://github.com/libuv/libuv.git
- [cereal] https://github.com/USCiLab/cereal.git
- [websocketpp] https://github.com/zaphoyd/websocketpp.git
- [recastnavigation] https://github.com/EQEmu/recastnavigation.git
== 6/24/2019 ==
Uleat: Reworked BotDatabase into a functional add-on for ZoneDatabase
- Eliminated the database connection associated with class BotDatabase
- All behaviors remain the same with the exception of the calling object
-- To invoke a BotDatabase function, use database.botdb.<f> rather than botdb.<f>
== 3/1/2019 ==
Noudess: Major faction conversion to use client data.
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
add_subdirectory(import)
add_subdirectory(export)
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(export_sources
main.cpp
+1 -1
View File
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(import_sources
main.cpp
+124
View File
@@ -0,0 +1,124 @@
#CMake - Cross Platform Makefile Generator
#Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
#All rights reserved.
#
#Redistribution and use in source and binary forms, with or without
#modification, are permitted provided that the following conditions
#are met:
#
#* Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
#* Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
#* Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# This module defines
# LUA51_FOUND, if false, do not try to link to Lua
# LUA_LIBRARIES
# LUA_INCLUDE_DIR, where to find lua.h
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
IF(LUA_ROOT)
FIND_PATH(LUA_INCLUDE_DIR
NAMES lua.h
HINTS
ENV LUA_DIR
PATHS
${LUA_ROOT}
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include src
)
FIND_LIBRARY(LUA_LIBRARY
NAMES lua51 lua5.1 lua-5.1 lua
HINTS
ENV LUA_DIR
PATHS
${LUA_ROOT}
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES lib bin
)
ELSE(LUA_ROOT)
FIND_PATH(LUA_INCLUDE_DIR
NAMES lua.h
HINTS
ENV LUA_DIR
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES include/lua51 include/lua5.1 include/lua include
)
FIND_LIBRARY(LUA_LIBRARY
NAMES lua51 lua5.1 lua-5.1 lua
HINTS
ENV LUA_DIR
PATHS
~/Library/Frameworks
/Library/Frameworks
/sw
/opt/local
/opt/csw
/opt
PATH_SUFFIXES lib bin
)
ENDIF(LUA_ROOT)
IF(LUA_LIBRARY)
# include the math library for Unix
IF(UNIX AND NOT APPLE)
FIND_LIBRARY(LUA_MATH_LIBRARY m)
SET(LUA_LIBRARIES "${LUA_LIBRARY};${LUA_MATH_LIBRARY}" CACHE STRING "Lua Libraries")
# For Windows and Mac, don't need to explicitly include the math library
ELSE()
SET( LUA_LIBRARIES "${LUA_LIBRARY}" CACHE STRING "Lua Libraries")
ENDIF()
ENDIF()
IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/lua.h")
FILE(STRINGS "${LUA_INCLUDE_DIR}/lua.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua .+\"")
STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"Lua ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
UNSET(lua_version_str)
ENDIF()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lua51
REQUIRED_VARS LUA_LIBRARIES LUA_INCLUDE_DIR
VERSION_VAR LUA_VERSION_STRING)
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARIES LUA_LIBRARY LUA_MATH_LIBRARY)
-87
View File
@@ -1,87 +0,0 @@
# - Find mariadbclient
#
# -*- cmake -*-
#
# Find the native MariaDB includes and library
#
# MariaDB_INCLUDE_DIR - where to find mysql.h, etc.
# MariaDB_LIBRARIES - List of libraries when using MariaDB.
# MariaDB_FOUND - True if MariaDB found.
# The following can be used as a hint as to where to search:
# MARIADB_ROOT
IF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARIES)
# Already in cache, be silent
SET(MariaDB_FIND_QUIETLY TRUE)
ENDIF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARIES)
# Include dir
IF(MARIADB_ROOT)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATHS ${MARIADB_ROOT}/include
PATH_SUFFIXES mysql mariadb
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATH_SUFFIXES mysql mariadb
)
ELSE(MARIADB_ROOT)
FIND_PATH(MariaDB_INCLUDE_DIR
NAMES mariadb_version.h
PATH_SUFFIXES mysql mariadb
)
ENDIF(MARIADB_ROOT)
# Library
SET(MariaDB_NAMES libmariadb)
IF(MARIADB_ROOT)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES}
PATHS ${MARIADB_ROOT}/lib
PATH_SUFFIXES mysql mariadb
NO_DEFAULT_PATH
NO_SYSTEM_ENVIRONMENT_PATH
)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES}
PATH_SUFFIXES mysql mariadb
)
ELSE(MARIADB_ROOT)
FIND_LIBRARY(MariaDB_LIBRARY
NAMES ${MariaDB_NAMES} mariadbclient_r mariadbclient
PATHS /usr/lib /usr/local/lib /usr/lib64 /usr/local/lib64
PATH_SUFFIXES mysql mariadb
)
ENDIF(MARIADB_ROOT)
IF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
SET(MariaDB_FOUND TRUE)
SET(MariaDB_LIBRARIES ${MariaDB_LIBRARY})
ELSE (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
SET(MariaDB_FOUND FALSE)
SET(MariaDB_LIBRARIES)
ENDIF (MariaDB_INCLUDE_DIR AND MariaDB_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set MariaDB_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MariaDB DEFAULT_MSG MariaDB_LIBRARY MariaDB_INCLUDE_DIR)
IF(MariaDB_FOUND)
SET( MariaDB_LIBRARY_RELEASE ${MariaDB_LIBRARY} )
SET( MariaDB_LIBRARY_DEBUG ${MariaDB_LIBRARY} )
SET( MariaDB_LIBRARIES ${MariaDB_LIBRARY_RELEASE} ${MariaDB_LIBRARY_DEBUG} )
ELSE(MariaDB_FOUND)
SET( MariaDB_LIBRARIES )
ENDIF(MariaDB_FOUND)
MARK_AS_ADVANCED(
MariaDB_LIBRARY_DEBUG
MariaDB_LIBRARY_RELEASE
MariaDB_INCLUDE_DIR
)
-93
View File
@@ -1,93 +0,0 @@
# - Try to find mbedTLS
# Once done this will define
#
# Read-Only variables
# MBEDTLS_FOUND - system has mbedTLS
# MBEDTLS_INCLUDE_DIR - the mbedTLS include directory
# MBEDTLS_LIBRARY_DIR - the mbedTLS library directory
# MBEDTLS_LIBRARIES - Link these to use mbedTLS
# MBEDTLS_LIBRARY - path to mbedTLS library
# MBEDX509_LIBRARY - path to mbedTLS X.509 library
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
#
# Hint
# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation.
SET(_MBEDTLS_ROOT_HINTS
${MBEDTLS_ROOT_DIR}
ENV MBEDTLS_ROOT_DIR
)
SET(_MBEDTLS_ROOT_HINTS_AND_PATHS
HINTS ${_MBEDTLS_ROOT_HINTS}
PATHS ${_MBEDTLS_ROOT_PATHS}
)
FIND_PATH(MBEDTLS_INCLUDE_DIR
NAMES mbedtls/version.h
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES include
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
# Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF()
FIND_LIBRARY(MBEDTLS_LIBRARY
NAMES mbedtls libmbedtls
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
FIND_LIBRARY(MBEDX509_LIBRARY
NAMES mbedx509 libmbedx509
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
FIND_LIBRARY(MBEDCRYPTO_LIBRARY
NAMES mbedcrypto libmbedcrypto
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE)
ENDIF()
IF(MBEDTLS_FOUND)
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
IF(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH)
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY)
ELSE(MBEDTLS_FOUND)
IF(MBEDTLS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find mbedTLS")
ENDIF(MBEDTLS_FIND_REQUIRED)
ENDIF(MBEDTLS_FOUND)
MARK_AS_ADVANCED(
MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY
MBEDX509_LIBRARY
MBEDCRYPTO_LIBRARY
)
+8 -11
View File
@@ -1,4 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(common_sources
base_packet.cpp
classes.cpp
@@ -78,6 +79,7 @@ SET(common_sources
net/crc32.cpp
net/daybreak_connection.cpp
net/eqstream.cpp
net/eqstream_concurrent.cpp
net/packet.cpp
net/servertalk_client_connection.cpp
net/servertalk_legacy_client_connection.cpp
@@ -85,8 +87,6 @@ SET(common_sources
net/servertalk_server_connection.cpp
net/tcp_connection.cpp
net/tcp_server.cpp
net/websocket_server.cpp
net/websocket_server_connection.cpp
patches/patches.cpp
patches/sod.cpp
patches/sod_limits.cpp
@@ -211,7 +211,6 @@ SET(common_headers
xml_parser.h
zone_numbers.h
event/event_loop.h
event/idle.h
event/task.h
event/timer.h
json/json.h
@@ -224,6 +223,8 @@ SET(common_headers
net/dns.h
net/endian.h
net/eqstream.h
net/eqstream_concurrent.h
net/eqstream_concurrent_message.h
net/packet.h
net/servertalk_client_connection.h
net/servertalk_legacy_client_connection.h
@@ -232,8 +233,6 @@ SET(common_headers
net/servertalk_server_connection.h
net/tcp_connection.h
net/tcp_server.h
net/websocket_server.h
net/websocket_server_connection.h
patches/patches.h
patches/sod.h
patches/sod_limits.h
@@ -272,7 +271,6 @@ SET(common_headers
SOURCE_GROUP(Event FILES
event/event_loop.h
event/idle.h
event/timer.h
event/task.h
)
@@ -299,6 +297,9 @@ SOURCE_GROUP(Net FILES
net/eqmq.h
net/eqstream.cpp
net/eqstream.h
net/eqstream_concurrent.cpp
net/eqstream_concurrent.h
net/eqstream_concurrent_message.h
net/packet.cpp
net/packet.h
net/servertalk_client_connection.cpp
@@ -314,10 +315,6 @@ SOURCE_GROUP(Net FILES
net/tcp_connection.h
net/tcp_server.cpp
net/tcp_server.h
net/websocket_server.cpp
net/websocket_server.h
net/websocket_server_connection.cpp
net/websocket_server_connection.h
)
SOURCE_GROUP(Patches FILES
+1 -1
View File
@@ -23,7 +23,7 @@
* 2005-08-05 v5 - Removed most Lint (http://www.gimpel.com/) errors... thanks to Okko Willeboordse!
*
**********************************************************************/
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
+1 -1
View File
@@ -9,7 +9,7 @@
* 2013-01-26 - Modified by KimLS(KLS) for EQEmu's purposes
*
**********************************************************************/
#ifdef _WIN32
#ifdef _WINDOWS
// #pragma once is supported starting with _MCS_VER 1000,
// so we need not to check the version (because we only support _MSC_VER >= 1100)!
#pragma once
+1 -2
View File
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#ifdef _WINDOWS
#include <time.h>
#include <winsock2.h>
#include <windows.h>
@@ -75,7 +75,6 @@ public:
uint32 ReadUInt32() { uint32 value = *(uint32 *)(pBuffer + _rpos); _rpos += sizeof(uint32); return value; }
uint32 ReadUInt32(uint32 Offset) const { uint32 value = *(uint32 *)(pBuffer + Offset); return value; }
void ReadString(char *str) { uint32 len = static_cast<uint32>(strlen((char *)(pBuffer + _rpos))) + 1; memcpy(str, pBuffer + _rpos, len); _rpos += len; }
void ReadString(std::string &str) { str = reinterpret_cast<char *>(pBuffer + _rpos); _rpos += str.length() + 1; }
void ReadString(char *str, uint32 Offset, uint32 MaxLength) const;
uint32 GetWritePosition() { return _wpos; }
+1 -1
View File
@@ -18,7 +18,7 @@
#include "condition.h"
#ifdef _WIN32
#ifdef _WINDOWS
Condition::Condition()
{
+2 -2
View File
@@ -20,7 +20,7 @@
#include "global_define.h"
#include "mutex.h"
#ifndef _WIN32
#ifndef WIN32
#include <pthread.h>
#endif
@@ -30,7 +30,7 @@
class Condition {
private:
#ifdef _WIN32
#ifdef WIN32
enum {
SignalEvent = 0,
BroadcastEvent,
+1 -1
View File
@@ -2,7 +2,7 @@
#include "eqemu_logsys.h"
#include "crash.h"
#if defined(_WIN32) && defined(CRASH_LOGGING)
#if defined(_WINDOWS) && defined(CRASH_LOGGING)
#include "StackWalker.h"
class EQEmuStackWalker : public StackWalker
+17 -14
View File
@@ -30,7 +30,7 @@
#include <string.h>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
@@ -171,27 +171,30 @@ void Database::LoginIP(uint32 AccountID, const char* LoginIP) {
QueryDatabase(query);
}
int16 Database::CheckStatus(uint32 account_id)
{
std::string query = StringFormat(
"SELECT `status`, TIMESTAMPDIFF(SECOND, NOW(), `suspendeduntil`) FROM `account` WHERE `id` = %i",
account_id);
int16 Database::CheckStatus(uint32 account_id) {
std::string query = StringFormat("SELECT `status`, UNIX_TIMESTAMP(`suspendeduntil`) as `suspendeduntil`, UNIX_TIMESTAMP() as `current`"
" FROM `account` WHERE `id` = %i", account_id);
auto results = QueryDatabase(query);
if (!results.Success())
auto results = QueryDatabase(query);
if (!results.Success()) {
return 0;
}
if (results.RowCount() != 1)
return 0;
auto row = results.begin();
int16 status = atoi(row[0]);
int32 suspendeduntil = 0;
auto row = results.begin();
int16 status = atoi(row[0]);
int32 date_diff = 0;
// MariaDB initalizes with NULL if unix_timestamp() is out of range
if (row[1] != nullptr) {
suspendeduntil = atoi(row[1]);
}
if (row[1] != nullptr)
date_diff = atoi(row[1]);
int32 current = atoi(row[2]);
if (date_diff > 0)
if(suspendeduntil > current)
return -1;
return status;
+10 -2
View File
@@ -82,9 +82,17 @@ struct VarCache_Struct {
};
class PTimerList;
# define _ISNAN_(a) std::isnan(a)
#define SQL(...) #__VA_ARGS__
#ifdef _WINDOWS
#if _MSC_VER > 1700 // greater than 2012 (2013+)
# define _ISNAN_(a) std::isnan(a)
#else
# include <float.h>
# define _ISNAN_(a) _isnan(a)
#endif
#else
# define _ISNAN_(a) std::isnan(a)
#endif
class Database : public DBcore {
public:
+2 -2
View File
@@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <iostream>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
@@ -476,7 +476,7 @@ bool Database::CheckDatabaseConversions() {
CheckDatabaseConvertCorpseDeblob();
/* Run EQEmu Server script (Checks for database updates) */
if(system("perl eqemu_server.pl ran_from_world"));
system("perl eqemu_server.pl ran_from_world");
return true;
}
+1 -1
View File
@@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <iostream>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
#define strncasecmp _strnicmp
+2 -2
View File
@@ -1,4 +1,4 @@
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#endif
@@ -13,7 +13,7 @@
#include <mysqld_error.h>
#include <string.h>
#ifdef _WIN32
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef DBCORE_H
#define DBCORE_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
-10
View File
@@ -77,10 +77,6 @@ namespace EQEmu
} // namespace invtype
namespace DevTools {
const int32 GM_ACCOUNT_STATUS_LEVEL = 150;
}
namespace popupresponse {
const int32 SERVER_INTERNAL_USE_BASE = 2000000000;
const int32 MOB_INFO_DISMISS = 2000000001;
@@ -311,12 +307,6 @@ namespace EQEmu
} // namespace bug
enum WaypointStatus : int {
RoamBoxPauseInProgress = -3,
QuestControlNoGrid = -2,
QuestControlGrid = -1
};
} /*EQEmu*/
#endif /*COMMON_EMU_CONSTANTS_H*/
+193 -129
View File
@@ -71,7 +71,7 @@
//#define AT_Trader 300 // Bazaar Trader Mode (not present in SoF or RoF2)
// animations for AT_Anim
#define ANIM_FREEZE 102
#define ANIM_FREEZE 102
#define ANIM_STAND 0x64
#define ANIM_SIT 0x6e
#define ANIM_CROUCH 0x6f
@@ -87,114 +87,199 @@ typedef enum {
_eaMaxAppearance
} EmuAppearance;
namespace Chat {
const uint16 White = 0;
const uint16 DimGray = 1;
const uint16 Default = 1;
const uint16 Green = 2;
const uint16 BrightBlue = 3;
const uint16 LightBlue = 4;
const uint16 Magenta = 5;
const uint16 Gray = 6;
const uint16 LightGray = 7;
const uint16 NPCQuestSay = 10;
const uint16 DarkGray = 12;
const uint16 Red = 13;
const uint16 Lime = 14;
const uint16 Yellow = 15;
const uint16 Blue = 16;
const uint16 LightNavy = 17;
const uint16 Cyan = 18;
const uint16 Black = 20;
// msg_type's for custom usercolors
#define MT_Say 256
#define MT_Tell 257
#define MT_Group 258
#define MT_Guild 259
#define MT_OOC 260
#define MT_Auction 261
#define MT_Shout 262
#define MT_Emote 263
#define MT_Spells 264
#define MT_YouHitOther 265
#define MT_OtherHitsYou 266
#define MT_YouMissOther 267
#define MT_OtherMissesYou 268
#define MT_Broadcasts 269
#define MT_Skills 270
#define MT_Disciplines 271
#define MT_Unused1 272
#define MT_DefaultText 273
#define MT_Unused2 274
#define MT_MerchantOffer 275
#define MT_MerchantBuySell 276
#define MT_YourDeath 277
#define MT_OtherDeath 278
#define MT_OtherHits 279
#define MT_OtherMisses 280
#define MT_Who 281
#define MT_YellForHelp 282
#define MT_NonMelee 283
#define MT_WornOff 284
#define MT_MoneySplit 285
#define MT_LootMessages 286
#define MT_DiceRoll 287
#define MT_OtherSpells 288
#define MT_SpellFailure 289
#define MT_Chat 290
#define MT_Channel1 291
#define MT_Channel2 292
#define MT_Channel3 293
#define MT_Channel4 294
#define MT_Channel5 295
#define MT_Channel6 296
#define MT_Channel7 297
#define MT_Channel8 298
#define MT_Channel9 299
#define MT_Channel10 300
#define MT_CritMelee 301
#define MT_SpellCrits 302
#define MT_TooFarAway 303
#define MT_NPCRampage 304
#define MT_NPCFlurry 305
#define MT_NPCEnrage 306
#define MT_SayEcho 307
#define MT_TellEcho 308
#define MT_GroupEcho 309
#define MT_GuildEcho 310
#define MT_OOCEcho 311
#define MT_AuctionEcho 312
#define MT_ShoutECho 313
#define MT_EmoteEcho 314
#define MT_Chat1Echo 315
#define MT_Chat2Echo 316
#define MT_Chat3Echo 317
#define MT_Chat4Echo 318
#define MT_Chat5Echo 319
#define MT_Chat6Echo 320
#define MT_Chat7Echo 321
#define MT_Chat8Echo 322
#define MT_Chat9Echo 323
#define MT_Chat10Echo 324
#define MT_DoTDamage 325
#define MT_ItemLink 326
#define MT_RaidSay 327
#define MT_MyPet 328
#define MT_DS 329
#define MT_Leadership 330
#define MT_PetFlurry 331
#define MT_PetCrit 332
#define MT_FocusEffect 333
#define MT_Experience 334
#define MT_System 335
#define MT_PetSpell 336
#define MT_PetResponse 337
#define MT_ItemSpeech 338
#define MT_StrikeThrough 339
#define MT_Stun 340
/**
* User colors
*/
const uint16 Say = 256;
const uint16 Tell = 257;
const uint16 Group = 258;
const uint16 Guild = 259;
const uint16 OOC = 260;
const uint16 Auction = 261;
const uint16 Shout = 262;
const uint16 Emote = 263;
const uint16 Spells = 264;
const uint16 YouHitOther = 265;
const uint16 OtherHitYou = 266;
const uint16 YouMissOther = 267;
const uint16 OtherMissYou = 268;
const uint16 Broadcasts = 269;
const uint16 Skills = 270;
const uint16 Disciplines = 271;
const uint16 Unused1 = 272;
const uint16 DefaultText = 273;
const uint16 Unused2 = 274;
const uint16 MerchantOffer = 275;
const uint16 MerchantExchange = 276;
const uint16 YourDeath = 277;
const uint16 OtherDeath = 278;
const uint16 OtherHitOther = 279;
const uint16 OtherMissOther = 280;
const uint16 Who = 281;
const uint16 YellForHelp = 282;
const uint16 NonMelee = 283;
const uint16 SpellWornOff = 284;
const uint16 MoneySplit = 285;
const uint16 Loot = 286;
const uint16 DiceRoll = 287;
const uint16 OtherSpells = 288;
const uint16 SpellFailure = 289;
const uint16 ChatChannel = 290;
const uint16 Chat1 = 291;
const uint16 Chat2 = 292;
const uint16 Chat3 = 293;
const uint16 Chat4 = 294;
const uint16 Chat5 = 295;
const uint16 Chat6 = 296;
const uint16 Chat7 = 297;
const uint16 Chat8 = 298;
const uint16 Chat9 = 299;
const uint16 Chat10 = 300;
const uint16 MeleeCrit = 301;
const uint16 SpellCrit = 302;
const uint16 TooFarAway = 303;
const uint16 NPCRampage = 304;
const uint16 NPCFlurry = 305;
const uint16 NPCEnrage = 306;
const uint16 EchoSay = 307;
const uint16 EchoTell = 308;
const uint16 EchoGroup = 309;
const uint16 EchoGuild = 310;
const uint16 EchoOOC = 311;
const uint16 EchoAuction = 312;
const uint16 EchoShout = 313;
const uint16 EchoEmote = 314;
const uint16 EchoChat1 = 315;
const uint16 EchoChat2 = 316;
const uint16 EchoChat3 = 317;
const uint16 EchoChat4 = 318;
const uint16 EchoChat5 = 319;
const uint16 EchoChat6 = 320;
const uint16 EchoChat7 = 321;
const uint16 EchoChat8 = 322;
const uint16 EchoChat9 = 323;
const uint16 EchoChat10 = 324;
const uint16 DotDamage = 325;
const uint16 ItemLink = 326;
const uint16 RaidSay = 327;
const uint16 MyPet = 328;
const uint16 DamageShield = 329;
const uint16 LeaderShip = 330;
const uint16 PetFlurry = 331;
const uint16 PetCritical = 332;
const uint16 FocusEffect = 333;
const uint16 Experience = 334;
const uint16 System = 335;
const uint16 PetSpell = 336;
const uint16 PetResponse = 337;
const uint16 ItemSpeech = 338;
const uint16 StrikeThrough = 339;
const uint16 Stun = 340;
// TODO: Really should combine above and below into one
//from showeq
enum ChatColor
{
/*
CC_Default = 0,
CC_DarkGrey = 1,
CC_DarkGreen = 2,
CC_DarkBlue = 3,
CC_Purple = 5,
CC_LightGrey = 6,
*/
CC_WhiteSmoke = 0, // FF|F0F0F0
CC_Green = 2, // FF|008000
CC_BrightBlue = 3, // FF|0040FF
CC_Magenta = 5, // FF|F000F0
CC_Gray = 6, // FF|808080
CC_LightGray = 7, // FF|E0E0E0
//CC_WhiteSmoke2 = 10, // FF|F0F0F0
CC_DarkGray = 12, // FF|A0A0A0
CC_Red = 13, // FF|F00000
CC_Lime = 14, // FF|00F000
CC_Yellow = 15, // FF|F0F000
CC_Blue = 16, // FF|0000F0
CC_LightNavy = 17, // FF|0000AF
CC_Cyan = 18, // FF|00F0F0
CC_Black = 20, // FF|000000
// any index <= 255 that is not defined above
CC_DimGray = 1, // FF|606060
CC_Default = 1,
CC_User_Say = 256,
CC_User_Tell = 257,
CC_User_Group = 258,
CC_User_Guild = 259,
CC_User_OOC = 260,
CC_User_Auction = 261,
CC_User_Shout = 262,
CC_User_Emote = 263,
CC_User_Spells = 264,
CC_User_YouHitOther = 265,
CC_User_OtherHitYou = 266,
CC_User_YouMissOther = 267,
CC_User_OtherMissYou = 268,
CC_User_Duels = 269,
CC_User_Skills = 270,
CC_User_Disciplines = 271,
CC_User_Default = 273,
CC_User_MerchantOffer = 275,
CC_User_MerchantExchange = 276,
CC_User_YourDeath = 277,
CC_User_OtherDeath = 278,
CC_User_OtherHitOther = 279,
CC_User_OtherMissOther = 280,
CC_User_Who = 281,
CC_User_Yell = 282,
CC_User_NonMelee = 283,
CC_User_SpellWornOff = 284,
CC_User_MoneySplit = 285,
CC_User_Loot = 286,
CC_User_Random = 287,
CC_User_OtherSpells = 288,
CC_User_SpellFailure = 289,
CC_User_ChatChannel = 290,
CC_User_Chat1 = 291,
CC_User_Chat2 = 292,
CC_User_Chat3 = 293,
CC_User_Chat4 = 294,
CC_User_Chat5 = 295,
CC_User_Chat6 = 296,
CC_User_Chat7 = 297,
CC_User_Chat8 = 298,
CC_User_Chat9 = 299,
CC_User_Chat10 = 300,
CC_User_MeleeCrit = 301,
CC_User_SpellCrit = 302,
CC_User_TooFarAway = 303,
CC_User_NPCRampage = 304,
CC_User_NPCFurry = 305,
CC_User_NPCEnrage = 306,
CC_User_EchoSay = 307,
CC_User_EchoTell = 308,
CC_User_EchoGroup = 309,
CC_User_EchoGuild = 310,
CC_User_EchoOOC = 311,
CC_User_EchoAuction = 312,
CC_User_EchoShout = 313,
CC_User_EchoEmote = 314,
CC_User_EchoChat1 = 315,
CC_User_EchoChat2 = 316,
CC_User_EchoChat3 = 317,
CC_User_EchoChat4 = 318,
CC_User_EchoChat5 = 319,
CC_User_EchoChat6 = 320,
CC_User_EchoChat7 = 321,
CC_User_EchoChat8 = 322,
CC_User_EchoChat9 = 323,
CC_User_EchoChat10 = 324,
CC_User_UnusedAtThisTime = 325,
CC_User_ItemTags = 326,
CC_User_RaidSay = 327,
CC_User_MyPet = 328,
CC_User_DamageShield = 329,
};
//ZoneChange_Struct->success values
@@ -438,25 +523,4 @@ static const uint8 SkillDamageTypes[EQEmu::skills::HIGHEST_SKILL + 1] = // chang
static const uint32 MAX_SPELL_DB_ID_VAL = 65535;
enum ChatChannelNames : uint16
{
ChatChannel_Guild = 0,
ChatChannel_Group = 2,
ChatChannel_Shout = 3,
ChatChannel_Auction = 4,
ChatChannel_OOC = 5,
ChatChannel_Broadcast = 6,
ChatChannel_Tell = 7,
ChatChannel_Say = 8,
ChatChannel_Petition = 10,
ChatChannel_GMSAY = 11,
ChatChannel_TellEcho = 14,
ChatChannel_Raid = 15,
ChatChannel_UNKNOWN_Guild = 17,
ChatChannel_UNKNOWN_GMSAY = 18,
ChatChannel_UCSRelay = 20,
ChatChannel_Emotes = 22
};
#endif /*COMMON_EQ_CONSTANTS_H*/
-14
View File
@@ -1188,20 +1188,6 @@ struct SpecialMesg_Struct
/*24*/ char message[1]; // What is being said?
};
struct SpecialMesgHeader_Struct
{
/*00*/ char SpeakMode; // 2 shouts, 4 %1 %2, 3 %2, 5 tells group, 0 copy, default says
/*01*/ char JournalMode; // 1 and 2 go to journal
/*02*/ char language;
/*03*/ uint32 msg_type; // Color of text (see MT_*** below)
/*07*/ uint32 target_spawn_id; // Who is it being said to?
/*11*/ // speaker's name
/*xx*/ // unknown, location, client doesn't care
/*xx*/ // unknown
/*xx*/ // unknown
/*xx*/ // message
};
/*
** When somebody changes what they're wearing or give a pet a weapon (model changes)
** Length: 19 Bytes
+16 -3
View File
@@ -7,6 +7,7 @@
#include "emu_versions.h"
#include "eq_packet.h"
#include "net/daybreak_connection.h"
#include "event/event_loop.h"
typedef enum {
ESTABLISHED,
@@ -23,6 +24,7 @@ struct EQStreamManagerInterfaceOptions
{
EQStreamManagerInterfaceOptions() {
opcode_size = 2;
loop = &EQ::EventLoop::GetDefault();
}
EQStreamManagerInterfaceOptions(int port, bool encoded, bool compressed) {
@@ -40,22 +42,33 @@ struct EQStreamManagerInterfaceOptions
}
daybreak_options.port = port;
loop = &EQ::EventLoop::GetDefault();
}
int opcode_size;
bool track_opcode_stats;
EQ::Net::DaybreakConnectionManagerOptions daybreak_options;
EQ::EventLoop *loop;
};
enum EQStreamPriority : int32_t {
High,
Normal,
Low
};
class EQStreamInterface;
class EQStreamManagerInterface
{
public:
EQStreamManagerInterface(const EQStreamManagerInterfaceOptions &options) { m_options = options; }
virtual ~EQStreamManagerInterface() { };
EQStreamManagerInterfaceOptions GetOptions() { return m_options; }
const EQStreamManagerInterfaceOptions& GetOptions() const { return m_options; }
virtual void SetOptions(const EQStreamManagerInterfaceOptions& options) = 0;
EQStreamManagerInterfaceOptions& MutateOptions() { return m_options; }
virtual void OnNewConnection(std::function<void(std::shared_ptr<EQStreamInterface>)> func) = 0;
virtual void OnConnectionStateChange(std::function<void(std::shared_ptr<EQStreamInterface>, EQ::Net::DbProtocolStatus, EQ::Net::DbProtocolStatus)> func) = 0;
virtual void SetPriority(EQStreamPriority priority) = 0;
protected:
EQStreamManagerInterfaceOptions m_options;
};
+48 -82
View File
@@ -26,26 +26,24 @@
std::string EQEmuConfig::ConfigFile = "eqemu_config.json";
EQEmuConfig *EQEmuConfig::_config = nullptr;
void EQEmuConfig::parse_config()
{
ShortName = _root["server"]["world"].get("shortname", "").asString();
LongName = _root["server"]["world"].get("longname", "").asString();
void EQEmuConfig::parse_config() {
ShortName = _root["server"]["world"].get("shortname", "").asString();
LongName = _root["server"]["world"].get("longname", "").asString();
WorldAddress = _root["server"]["world"].get("address", "").asString();
LocalAddress = _root["server"]["world"].get("localaddress", "").asString();
MaxClients = atoi(_root["server"]["world"].get("maxclients", "-1").asString().c_str());
SharedKey = _root["server"]["world"].get("key", "").asString();
LoginCount = 0;
MaxClients = atoi(_root["server"]["world"].get("maxclients", "-1").asString().c_str());
SharedKey = _root["server"]["world"].get("key", "").asString();
LoginCount = 0;
if (_root["server"]["world"]["loginserver"].isObject()) {
LoginHost = _root["server"]["world"]["loginserver"].get("host", "login.eqemulator.net").asString();
LoginPort = atoi(_root["server"]["world"]["loginserver"].get("port", "5998").asString().c_str());
LoginHost = _root["server"]["world"]["loginserver"].get("host", "login.eqemulator.net").asString();
LoginPort = atoi(_root["server"]["world"]["loginserver"].get("port", "5998").asString().c_str());
LoginLegacy = false;
if (_root["server"]["world"]["loginserver"].get("legacy", "0").asString() == "1") { LoginLegacy = true; }
LoginAccount = _root["server"]["world"]["loginserver"].get("account", "").asString();
if (_root["server"]["world"]["loginserver"].get("legacy", "0").asString() == "1") LoginLegacy = true;
LoginAccount = _root["server"]["world"]["loginserver"].get("account", "").asString();
LoginPassword = _root["server"]["world"]["loginserver"].get("password", "").asString();
}
else {
} else {
char str[32];
loginlist.Clear();
do {
@@ -55,104 +53,76 @@ void EQEmuConfig::parse_config()
}
auto loginconfig = new LoginConfig;
loginconfig->LoginHost = _root["server"]["world"][str].get("host", "login.eqemulator.net").asString();
loginconfig->LoginPort = atoi(_root["server"]["world"][str].get("port", "5998").asString().c_str());
loginconfig->LoginAccount = _root["server"]["world"][str].get("account", "").asString();
loginconfig->LoginHost = _root["server"]["world"][str].get("host", "login.eqemulator.net").asString();
loginconfig->LoginPort = atoi(_root["server"]["world"][str].get("port", "5998").asString().c_str());
loginconfig->LoginAccount = _root["server"]["world"][str].get("account", "").asString();
loginconfig->LoginPassword = _root["server"]["world"][str].get("password", "").asString();
loginconfig->LoginLegacy = false;
if (_root["server"]["world"][str].get("legacy", "0").asString() == "1") { loginconfig->LoginLegacy = true; }
if (_root["server"]["world"][str].get("legacy", "0").asString() == "1") loginconfig->LoginLegacy = true;
loginlist.Insert(loginconfig);
} while (LoginCount < 100);
}
//<locked> from xml converts to json as locked: "", so i default to "false".
//The only way to enable locked is by switching to true, meaning this value is always false until manually set true
Locked = false;
if (_root["server"]["world"].get("locked", "false").asString() == "true") { Locked = true; }
WorldIP = _root["server"]["world"]["tcp"].get("host", "127.0.0.1").asString();
if (_root["server"]["world"].get("locked", "false").asString() == "true") Locked = true;
WorldIP = _root["server"]["world"]["tcp"].get("host", "127.0.0.1").asString();
WorldTCPPort = atoi(_root["server"]["world"]["tcp"].get("port", "9000").asString().c_str());
TelnetIP = _root["server"]["world"]["telnet"].get("ip", "127.0.0.1").asString();
TelnetIP = _root["server"]["world"]["telnet"].get("ip", "127.0.0.1").asString();
TelnetTCPPort = atoi(_root["server"]["world"]["telnet"].get("port", "9001").asString().c_str());
TelnetEnabled = false;
if (_root["server"]["world"]["telnet"].get("enabled", "false").asString() == "true") { TelnetEnabled = true; }
if (_root["server"]["world"]["telnet"].get("enabled", "false").asString() == "true") TelnetEnabled = true;
WorldHTTPMimeFile = _root["server"]["world"]["http"].get("mimefile", "mime.types").asString();
WorldHTTPPort = atoi(_root["server"]["world"]["http"].get("port", "9080").asString().c_str());
WorldHTTPEnabled = false;
WorldHTTPPort = atoi(_root["server"]["world"]["http"].get("port", "9080").asString().c_str());
WorldHTTPEnabled = false;
if (_root["server"]["world"]["http"].get("enabled", "false").asString() == "true") WorldHTTPEnabled = true;
if (_root["server"]["world"]["http"].get("enabled", "false").asString() == "true") {
WorldHTTPEnabled = true;
}
/**
* UCS
*/
ChatHost = _root["server"]["chatserver"].get("host", "eqchat.eqemulator.net").asString();
ChatPort = atoi(_root["server"]["chatserver"].get("port", "7778").asString().c_str());
MailHost = _root["server"]["mailserver"].get("host", "eqmail.eqemulator.net").asString();
MailPort = atoi(_root["server"]["mailserver"].get("port", "7778").asString().c_str());
/**
* Database
*/
DatabaseUsername = _root["server"]["database"].get("username", "eq").asString();
DatabasePassword = _root["server"]["database"].get("password", "eq").asString();
DatabaseHost = _root["server"]["database"].get("host", "localhost").asString();
DatabasePort = atoi(_root["server"]["database"].get("port", "3306").asString().c_str());
DatabaseDB = _root["server"]["database"].get("db", "eq").asString();
DatabaseHost = _root["server"]["database"].get("host", "localhost").asString();
DatabasePort = atoi(_root["server"]["database"].get("port", "3306").asString().c_str());
DatabaseDB = _root["server"]["database"].get("db", "eq").asString();
/**
* QS
*/
QSDatabaseHost = _root["server"]["qsdatabase"].get("host", "localhost").asString();
QSDatabasePort = atoi(_root["server"]["qsdatabase"].get("port", "3306").asString().c_str());
QSDatabaseHost = _root["server"]["qsdatabase"].get("host", "localhost").asString();
QSDatabasePort = atoi(_root["server"]["qsdatabase"].get("port", "3306").asString().c_str());
QSDatabaseUsername = _root["server"]["qsdatabase"].get("username", "eq").asString();
QSDatabasePassword = _root["server"]["qsdatabase"].get("password", "eq").asString();
QSDatabaseDB = _root["server"]["qsdatabase"].get("db", "eq").asString();
QSDatabaseDB = _root["server"]["qsdatabase"].get("db", "eq").asString();
/**
* Zones
*/
DefaultStatus = atoi(_root["server"]["zones"].get("defaultstatus", 0).asString().c_str());
ZonePortLow = atoi(_root["server"]["zones"]["ports"].get("low", "7000").asString().c_str());
ZonePortHigh = atoi(_root["server"]["zones"]["ports"].get("high", "7999").asString().c_str());
ZonePortLow = atoi(_root["server"]["zones"]["ports"].get("low", "7000").asString().c_str());
ZonePortHigh = atoi(_root["server"]["zones"]["ports"].get("high", "7999").asString().c_str());
/**
* Files
*/
SpellsFile = _root["server"]["files"].get("spells", "spells_us.txt").asString();
OpCodesFile = _root["server"]["files"].get("opcodes", "opcodes.conf").asString();
MailOpCodesFile = _root["server"]["files"].get("mail_opcodes", "mail_opcodes.conf").asString();
PluginPlFile = _root["server"]["files"].get("plugin.pl", "plugin.pl").asString();
SpellsFile = _root["server"]["files"].get("spells", "spells_us.txt").asString();
OpCodesFile = _root["server"]["files"].get("opcodes", "opcodes.conf").asString();
PluginPlFile = _root["server"]["files"].get("plugin.pl", "plugin.pl").asString();
/**
* Directories
*/
MapDir = _root["server"]["directories"].get("maps", "Maps/").asString();
QuestDir = _root["server"]["directories"].get("quests", "quests/").asString();
PluginDir = _root["server"]["directories"].get("plugins", "plugins/").asString();
MapDir = _root["server"]["directories"].get("maps", "Maps/").asString();
QuestDir = _root["server"]["directories"].get("quests", "quests/").asString();
PluginDir = _root["server"]["directories"].get("plugins", "plugins/").asString();
LuaModuleDir = _root["server"]["directories"].get("lua_modules", "lua_modules/").asString();
PatchDir = _root["server"]["directories"].get("patches", "./").asString();
PatchDir = _root["server"]["directories"].get("patches", "./").asString();
SharedMemDir = _root["server"]["directories"].get("shared_memory", "shared/").asString();
LogDir = _root["server"]["directories"].get("logs", "logs/").asString();
LogDir = _root["server"]["directories"].get("logs", "logs/").asString();
/**
* Logs
*/
LogPrefix = _root["server"]["launcher"].get("logprefix", "logs/zone-").asString();
LogSuffix = _root["server"]["launcher"].get("logsuffix", ".log").asString();
/**
* Launcher
*/
RestartWait = atoi(_root["server"]["launcher"]["timers"].get("restart", "10000").asString().c_str());
TerminateWait = atoi(_root["server"]["launcher"]["timers"].get("reterminate", "10000").asString().c_str());
InitialBootWait = atoi(_root["server"]["launcher"]["timers"].get("initial", "20000").asString().c_str());
RestartWait = atoi(_root["server"]["launcher"]["timers"].get("restart", "10000").asString().c_str());
TerminateWait = atoi(_root["server"]["launcher"]["timers"].get("reterminate", "10000").asString().c_str());
InitialBootWait = atoi(_root["server"]["launcher"]["timers"].get("initial", "20000").asString().c_str());
ZoneBootInterval = atoi(_root["server"]["launcher"]["timers"].get("interval", "2000").asString().c_str());
#ifdef _WIN32
#ifdef WIN32
ZoneExe = _root["server"]["launcher"].get("exe", "zone.exe").asString();
#else
ZoneExe = _root["server"]["launcher"].get("exe", "./zone").asString();
@@ -260,9 +230,6 @@ std::string EQEmuConfig::GetByName(const std::string &var_name) const
if (var_name == "OpCodesFile") {
return (OpCodesFile);
}
if (var_name == "MailOpCodesFile") {
return (MailOpCodesFile);
}
if (var_name == "PluginPlFile") {
return (PluginPlFile);
}
@@ -345,7 +312,6 @@ void EQEmuConfig::Dump() const
std::cout << "QSDatabasePort = " << QSDatabasePort << std::endl;
std::cout << "SpellsFile = " << SpellsFile << std::endl;
std::cout << "OpCodesFile = " << OpCodesFile << std::endl;
std::cout << "MailOpcodesFile = " << MailOpCodesFile << std::endl;
std::cout << "PluginPlFile = " << PluginPlFile << std::endl;
std::cout << "MapDir = " << MapDir << std::endl;
std::cout << "QuestDir = " << QuestDir << std::endl;
@@ -356,6 +322,6 @@ void EQEmuConfig::Dump() const
std::cout << "LogDir = " << LogDir << std::endl;
std::cout << "ZonePortLow = " << ZonePortLow << std::endl;
std::cout << "ZonePortHigh = " << ZonePortHigh << std::endl;
std::cout << "DefaultStatus = " << (int) DefaultStatus << std::endl;
std::cout << "DefaultStatus = " << (int)DefaultStatus << std::endl;
// std::cout << "DynamicCount = " << DynamicCount << std::endl;
}
-1
View File
@@ -84,7 +84,6 @@ class EQEmuConfig
// From <files/>
std::string SpellsFile;
std::string OpCodesFile;
std::string MailOpCodesFile;
std::string PluginPlFile;
// From <directories/>
+19 -14
View File
@@ -33,7 +33,7 @@
std::ofstream process_log;
#ifdef _WIN32
#ifdef _WINDOWS
#include <direct.h>
#include <conio.h>
#include <iostream>
@@ -81,13 +81,20 @@ namespace Console {
};
}
enum GameChatColor {
yellow = 15,
red = 13,
light_green = 14,
light_cyan = 258,
light_purple = 5
};
/**
* EQEmuLogSys Constructor
*/
EQEmuLogSys::EQEmuLogSys()
{
on_log_gmsay_hook = [](uint16 log_type, const std::string &) {};
on_log_console_hook = [](uint16 debug_level, uint16 log_type, const std::string &) {};
bool file_logs_enabled = false;
int log_platform = 0;
}
@@ -298,22 +305,22 @@ uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category)
switch (log_category) {
case Logs::Status:
case Logs::Normal:
return Chat::Yellow;
return GameChatColor::yellow;
case Logs::MySQLError:
case Logs::Error:
return Chat::Red;
return GameChatColor::red;
case Logs::MySQLQuery:
case Logs::Debug:
return Chat::Lime;
return GameChatColor::light_green;
case Logs::Quests:
return Chat::Group;
return GameChatColor::light_cyan;
case Logs::Commands:
case Logs::Mercenaries:
return Chat::Magenta;
return GameChatColor::light_purple;
case Logs::Crash:
return Chat::Red;
return GameChatColor::red;
default:
return Chat::Yellow;
return GameChatColor::yellow;
}
}
@@ -324,7 +331,7 @@ uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category)
*/
void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, const std::string &message)
{
#ifdef _WIN32
#ifdef _WINDOWS
HANDLE console_handle;
console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX info = { 0 };
@@ -339,8 +346,6 @@ void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category,
#else
std::cout << EQEmuLogSys::GetLinuxConsoleColorFromCategory(log_category) << message << LC_RESET << std::endl;
#endif
on_log_console_hook(debug_level, log_category, message);
}
/**
@@ -408,7 +413,7 @@ void EQEmuLogSys::SetCurrentTimeStamp(char *time_stamp)
*/
void EQEmuLogSys::MakeDirectory(const std::string &directory_name)
{
#ifdef _WIN32
#ifdef _WINDOWS
struct _stat st;
if (_stat(directory_name.c_str(), &st) == 0) // exists
return;
@@ -500,4 +505,4 @@ void EQEmuLogSys::StartFileLogs(const std::string &log_name)
std::ios_base::app | std::ios_base::out
);
}
}
}
+1 -3
View File
@@ -240,8 +240,7 @@ public:
*/
uint16 GetGMSayColorFromCategory(uint16 log_category);
void SetGMSayHandler(std::function<void(uint16 log_type, const std::string&)> f) { on_log_gmsay_hook = f; }
void SetConsoleHandler(std::function<void(uint16 debug_level, uint16 log_type, const std::string&)> f) { on_log_console_hook = f; }
void OnLogHookCallBackZone(std::function<void(uint16 log_type, const std::string&)> f) { on_log_gmsay_hook = f; }
private:
@@ -249,7 +248,6 @@ private:
* Callback pointer to zone process for hooking logs to zone using GMSay
*/
std::function<void(uint16 log_category, const std::string&)> on_log_gmsay_hook;
std::function<void(uint16 debug_level, uint16 log_category, const std::string&)> on_log_console_hook;
/**
* Formats log messages like '[Category] This is a log message'
+6 -6
View File
@@ -7,7 +7,7 @@ namespace EQ
{
class EventLoop
{
public:
public:
EventLoop() {
memset(&m_loop, 0, sizeof(uv_loop_t));
uv_loop_init(&m_loop);
@@ -16,12 +16,9 @@ namespace EQ
~EventLoop() {
uv_loop_close(&m_loop);
}
EventLoop(const EventLoop&) = delete;
EventLoop& operator=(const EventLoop&) = delete;
static EventLoop &GetDefault() {
static thread_local EventLoop inst;
static EventLoop inst;
return inst;
}
@@ -31,7 +28,10 @@ namespace EQ
uv_loop_t* Handle() { return &m_loop; }
private:
private:
EventLoop(const EventLoop&);
EventLoop& operator=(const EventLoop&);
uv_loop_t m_loop;
};
}
+22 -20
View File
@@ -24,12 +24,14 @@ namespace EQ {
std::exception error;
};
Task(EventLoop &loop, TaskFn fn) : _loop(loop) {
_fn = fn;
Task(EQ::EventLoop *loop, TaskFn fn) {
m_loop = loop;
m_fn = fn;
}
Task(TaskFn fn) : _loop(EventLoop::GetDefault()) {
_fn = fn;
Task(TaskFn fn) {
m_loop = &EQ::EventLoop::GetDefault();
m_fn = fn;
}
~Task() {
@@ -37,34 +39,34 @@ namespace EQ {
}
Task& Then(ResolveFn fn) {
_then = fn;
m_then = fn;
return *this;
}
Task& Catch(RejectFn fn) {
_catch = fn;
m_catch = fn;
return *this;
}
Task& Finally(FinallyFn fn) {
_fin = fn;
m_finally = fn;
return *this;
}
void Run() {
uv_work_t *work = new uv_work_t;
memset(work, 0, sizeof(uv_work_t));
uv_work_t *m_work = new uv_work_t;
memset(m_work, 0, sizeof(uv_work_t));
TaskBaton *baton = new TaskBaton();
baton->fn = _fn;
baton->on_then = _then;
baton->on_catch = _catch;
baton->on_finally = _fin;
baton->fn = m_fn;
baton->on_then = m_then;
baton->on_catch = m_catch;
baton->on_finally = m_finally;
baton->has_result = false;
baton->has_error = false;
work->data = baton;
m_work->data = baton;
uv_queue_work(_loop.Handle(), work, [](uv_work_t* req) {
uv_queue_work(m_loop->Handle(), m_work, [](uv_work_t* req) {
TaskBaton *baton = (TaskBaton*)req->data;
baton->fn([baton](const EQEmu::Any& result) {
@@ -96,10 +98,10 @@ namespace EQ {
}
private:
TaskFn _fn;
ResolveFn _then;
RejectFn _catch;
FinallyFn _fin;
EventLoop &_loop;
EQ::EventLoop *m_loop;
TaskFn m_fn;
ResolveFn m_then;
RejectFn m_catch;
FinallyFn m_finally;
};
}
+34 -30
View File
@@ -6,29 +6,33 @@ namespace EQ {
class Timer
{
public:
Timer(EventLoop &loop, std::function<void(Timer *)> cb) : _loop(loop)
Timer(EQ::EventLoop *loop, std::function<void(Timer *)> cb)
{
_timer = nullptr;
_cb = cb;
m_loop = loop;
m_timer = nullptr;
m_cb = cb;
}
Timer(EventLoop &loop, uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb) : _loop(loop)
Timer(std::function<void(Timer *)> cb)
{
_timer = nullptr;
_cb = cb;
m_loop = &EQ::EventLoop::GetDefault();
m_timer = nullptr;
m_cb = cb;
}
Timer(EQ::EventLoop *loop, uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb)
{
m_loop = loop;
m_timer = nullptr;
m_cb = cb;
Start(duration_ms, repeats);
}
Timer(std::function<void(Timer *)> cb) : _loop(EventLoop::GetDefault())
Timer(uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb)
{
_timer = nullptr;
_cb = cb;
}
Timer(uint64_t duration_ms, bool repeats, std::function<void(Timer *)> cb) : _loop(EventLoop::GetDefault())
{
_timer = nullptr;
_cb = cb;
m_loop = &EQ::EventLoop::GetDefault();
m_timer = nullptr;
m_cb = cb;
Start(duration_ms, repeats);
}
@@ -38,21 +42,21 @@ namespace EQ {
}
void Start(uint64_t duration_ms, bool repeats) {
auto loop = EventLoop::GetDefault().Handle();
if (!_timer) {
_timer = new uv_timer_t;
memset(_timer, 0, sizeof(uv_timer_t));
uv_timer_init(loop, _timer);
_timer->data = this;
auto loop = m_loop->Handle();
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(_timer, [](uv_timer_t *handle) {
uv_timer_start(m_timer, [](uv_timer_t *handle) {
Timer *t = (Timer*)handle->data;
t->Execute();
}, duration_ms, duration_ms);
}
else {
uv_timer_start(_timer, [](uv_timer_t *handle) {
uv_timer_start(m_timer, [](uv_timer_t *handle) {
Timer *t = (Timer*)handle->data;
t->Stop();
t->Execute();
@@ -62,20 +66,20 @@ namespace EQ {
}
void Stop() {
if (_timer) {
uv_close((uv_handle_t*)_timer, [](uv_handle_t* handle) {
if (m_timer) {
uv_close((uv_handle_t*)m_timer, [](uv_handle_t* handle) {
delete handle;
});
_timer = nullptr;
m_timer = nullptr;
}
}
private:
void Execute() {
_cb(this);
m_cb(this);
}
EventLoop &_loop;
uv_timer_t *_timer;
std::function<void(Timer*)> _cb;
EQ::EventLoop *m_loop;
uv_timer_t *m_timer;
std::function<void(Timer*)> m_cb;
};
}
+12 -10
View File
@@ -18,7 +18,6 @@
#include "faction.h"
#include "races.h"
#include "rulesys.h"
const char *FactionValueToString(FACTION_VALUE fv)
{
@@ -60,31 +59,34 @@ FACTION_VALUE CalculateFaction(FactionMods* fm, int32 tmpCharacter_value)
if (fm) {
character_value += fm->base + fm->class_mod + fm->race_mod + fm->deity_mod;
}
if (character_value >= RuleI(Faction, AllyFactionMinimum)) {
if (character_value >= 1100) {
return FACTION_ALLY;
}
if (character_value >= RuleI(Faction, WarmlyFactionMinimum)) {
if (character_value >= 750 && character_value <= 1099) {
return FACTION_WARMLY;
}
if (character_value >= RuleI(Faction, KindlyFactionMinimum)) {
if (character_value >= 500 && character_value <= 749) {
return FACTION_KINDLY;
}
if (character_value >= RuleI(Faction, AmiablyFactionMinimum)) {
if (character_value >= 100 && character_value <= 499) {
return FACTION_AMIABLE;
}
if (character_value >= RuleI(Faction, IndifferentlyFactionMinimum)) {
if (character_value >= 0 && character_value <= 99) {
return FACTION_INDIFFERENT;
}
if (character_value >= RuleI(Faction, ApprehensivelyFactionMinimum)) {
if (character_value >= -100 && character_value <= -1) {
return FACTION_APPREHENSIVE;
}
if (character_value >= RuleI(Faction, DubiouslyFactionMinimum)) {
if (character_value >= -500 && character_value <= -101) {
return FACTION_DUBIOUS;
}
if (character_value >= RuleI(Faction, ThreateninglyFactionMinimum)) {
if (character_value >= -750 && character_value <= -501) {
return FACTION_THREATENLY;
}
return FACTION_SCOWLS;
if (character_value <= -751) {
return FACTION_SCOWLS;
}
return FACTION_INDIFFERENT;
}
// this function should check if some races have more than one race define
+2 -2
View File
@@ -17,7 +17,7 @@
*/
// WHY IS THIS UP HERE
#if defined(_DEBUG) && defined(_WIN32)
#if defined(_DEBUG) && defined(WIN32)
#ifndef _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
@@ -27,7 +27,7 @@
#ifndef EQDEBUG_H
#define EQDEBUG_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
+2 -2
View File
@@ -23,6 +23,6 @@
#include "eq_packet_structs.h"
#ifndef _WIN32
#ifndef WIN32
#include <netinet/in.h> //for htonl
#endif
#endif
+6 -6
View File
@@ -17,7 +17,7 @@
*/
#include "ipc_mutex.h"
#ifdef _WIN32
#ifdef _WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#undef WIN32_LEAN_AND_MEAN
@@ -33,7 +33,7 @@
namespace EQEmu {
struct IPCMutex::Implementation {
#ifdef _WIN32
#ifdef _WINDOWS
HANDLE mut_;
#else
int fd_;
@@ -42,7 +42,7 @@ namespace EQEmu {
IPCMutex::IPCMutex(std::string name) : locked_(false) {
imp_ = new Implementation;
#ifdef _WIN32
#ifdef _WINDOWS
auto Config = EQEmuConfig::get();
std::string final_name = Config->SharedMemDir + "EQEmuMutex_";
final_name += name;
@@ -82,7 +82,7 @@ namespace EQEmu {
}
IPCMutex::~IPCMutex() {
#ifdef _WIN32
#ifdef _WINDOWS
if(locked_) {
ReleaseMutex(imp_->mut_);
}
@@ -103,7 +103,7 @@ namespace EQEmu {
return false;
}
#ifdef _WIN32
#ifdef _WINDOWS
DWORD wait_result = WaitForSingleObject(imp_->mut_, INFINITE);
if(wait_result != WAIT_OBJECT_0) {
return false;
@@ -121,7 +121,7 @@ namespace EQEmu {
if(!locked_) {
return false;
}
#ifdef _WIN32
#ifdef _WINDOWS
if(!ReleaseMutex(imp_->mut_)) {
return false;
}
+5 -5
View File
@@ -17,7 +17,7 @@
*/
#include "memory_mapped_file.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#else
#include <sys/types.h>
@@ -36,7 +36,7 @@
namespace EQEmu {
struct MemoryMappedFile::Implementation {
#ifdef _WIN32
#ifdef _WINDOWS
HANDLE mapped_object_;
#else
int fd_;
@@ -47,7 +47,7 @@ namespace EQEmu {
: filename_(filename), size_(size) {
imp_ = new Implementation;
#ifdef _WIN32
#ifdef _WINDOWS
DWORD total_size = size + sizeof(shared_memory_struct);
HANDLE file = CreateFile(filename.c_str(),
GENERIC_READ | GENERIC_WRITE,
@@ -116,7 +116,7 @@ namespace EQEmu {
size_ = size;
fclose(f);
#ifdef _WIN32
#ifdef _WINDOWS
DWORD total_size = size + sizeof(shared_memory_struct);
HANDLE file = CreateFile(filename.c_str(),
GENERIC_READ | GENERIC_WRITE,
@@ -172,7 +172,7 @@ namespace EQEmu {
}
MemoryMappedFile::~MemoryMappedFile() {
#ifdef _WIN32
#ifdef _WINDOWS
if(imp_->mapped_object_) {
CloseHandle(imp_->mapped_object_);
}
+4 -4
View File
@@ -1,4 +1,4 @@
#ifdef _WIN32
#ifdef _WINDOWS
// VS6 doesn't like the length of STL generated names: disabling
#pragma warning(disable:4786)
#endif
@@ -10,7 +10,7 @@
#include <iostream>
#include <zlib.h>
#ifndef _WIN32
#ifndef WIN32
#include <sys/time.h>
#endif
@@ -24,7 +24,7 @@
std::map<int,std::string> DBFieldNames;
#ifndef _WIN32
#ifndef WIN32
#if defined(FREEBSD) || defined(__CYGWIN__)
int print_stacktrace()
{
@@ -526,7 +526,7 @@ std::string generate_key(int length)
{
std::string key;
//TODO: write this for win32...
#ifndef _WIN32
#ifndef WIN32
int i;
timeval now;
static const char *chars="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+1 -1
View File
@@ -24,7 +24,7 @@ void decode(char *in, char *out);
void encode_chunk(char *in, int len, char *out);
void decode_chunk(char *in, char *out);
#ifndef _WIN32
#ifndef WIN32
int print_stacktrace();
#endif
+10 -10
View File
@@ -22,19 +22,19 @@
#include <string.h>
#include <time.h>
#ifndef _WIN32
#ifndef WIN32
#include <netinet/in.h>
#include <sys/socket.h>
#endif
#include <iostream>
#include <iomanip>
#ifdef _WIN32
#ifdef _WINDOWS
#include <io.h>
#endif
#include "../common/timer.h"
#include "../common/seperator.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
@@ -73,7 +73,7 @@ void CoutTimestamp(bool ms) {
int32 filesize(FILE* fp) {
#ifdef _WIN32
#ifdef _WINDOWS
return _filelength(_fileno(fp));
#else
struct stat file_stat;
@@ -88,7 +88,7 @@ int32 filesize(FILE* fp) {
}
uint32 ResolveIP(const char* hostname, char* errbuf) {
#ifdef _WIN32
#ifdef _WINDOWS
static InitWinsock ws;
#endif
if (errbuf)
@@ -99,14 +99,14 @@ uint32 ResolveIP(const char* hostname, char* errbuf) {
return 0;
}
struct sockaddr_in server_sin;
#ifdef _WIN32
#ifdef _WINDOWS
PHOSTENT phostent = nullptr;
#else
struct hostent *phostent = nullptr;
#endif
server_sin.sin_family = AF_INET;
if ((phostent = gethostbyname(hostname)) == nullptr) {
#ifdef _WIN32
#ifdef _WINDOWS
if (errbuf)
snprintf(errbuf, ERRBUF_SIZE, "Unable to get the host name. Error: %i", WSAGetLastError());
#else
@@ -115,7 +115,7 @@ uint32 ResolveIP(const char* hostname, char* errbuf) {
#endif
return 0;
}
#ifdef _WIN32
#ifdef _WINDOWS
memcpy ((char FAR *)&(server_sin.sin_addr), phostent->h_addr, phostent->h_length);
#else
memcpy ((char*)&(server_sin.sin_addr), phostent->h_addr, phostent->h_length);
@@ -136,7 +136,7 @@ bool ParseAddress(const char* iAddress, uint32* oIP, uint16* oPort, char* errbuf
return false;
}
#ifdef _WIN32
#ifdef _WINDOWS
InitWinsock::InitWinsock() {
WORD version = MAKEWORD (1,1);
WSADATA wsadata;
@@ -157,7 +157,7 @@ const char * itoa(int num) {
return temp;
}
#ifndef _WIN32
#ifndef WIN32
const char * itoa(int num, char* a,int b) {
static char temp[_ITOA_BUFLEN];
memset(temp,0,_ITOA_BUFLEN);
+3 -3
View File
@@ -32,8 +32,8 @@
//
#define VARSTRUCT_DECODE_TYPE(Type, Buffer) *(Type *)Buffer; Buffer += sizeof(Type);
#define VARSTRUCT_DECODE_STRING(String, Buffer) strcpy(String, Buffer); Buffer += strlen(String)+1;
#define VARSTRUCT_ENCODE_STRING(Buffer, String) { int length = sprintf(Buffer, "%s", String); Buffer += length + 1; }
#define VARSTRUCT_ENCODE_INTSTRING(Buffer, Number) { int length = sprintf(Buffer, "%i", Number); Buffer += length + 1; }
#define VARSTRUCT_ENCODE_STRING(Buffer, String) { sprintf(Buffer, "%s", String); Buffer += strlen(String) + 1; }
#define VARSTRUCT_ENCODE_INTSTRING(Buffer, Number) { sprintf(Buffer, "%i", Number); Buffer += strlen(Buffer) + 1; }
#define VARSTRUCT_ENCODE_TYPE(Type, Buffer, Value) { *(Type *)Buffer = Value; Buffer += sizeof(Type); }
#define VARSTRUCT_SKIP_TYPE(Type, Buffer) Buffer += sizeof(Type);
@@ -77,7 +77,7 @@ uint32 Catch22(uint32 mask);
#define _ITOA_BUFLEN 25
const char *itoa(int num); //not thread safe
#ifndef _WIN32
#ifndef _WINDOWS
const char *itoa(int num, char* a,int b);
#endif
+7 -7
View File
@@ -25,7 +25,7 @@
#endif
#ifdef _WIN32
#ifdef _WINDOWS
bool IsTryLockSupported();
bool TrylockSupported = IsTryLockSupported();
@@ -69,7 +69,7 @@ Mutex::Mutex() {
#if DEBUG_MUTEX_CLASS >= 7
std::cout << "Constructing Mutex" << std::endl;
#endif
#ifdef _WIN32
#ifdef _WINDOWS
InitializeCriticalSection(&CSMutex);
#else
pthread_mutexattr_t attr;
@@ -85,7 +85,7 @@ Mutex::Mutex() {
}
Mutex::~Mutex() {
#ifdef _WIN32
#ifdef _WINDOWS
DeleteCriticalSection(&CSMutex);
#else
#endif
@@ -95,14 +95,14 @@ void Mutex::lock() {
#if DEBUG_MUTEX_CLASS >= 5
if (!trylock()) {
std::cout << "Locking Mutex: Having to wait" << std::endl;
#ifdef _WIN32
#ifdef _WINDOWS
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
#endif
}
#else
#ifdef _WIN32
#ifdef _WINDOWS
EnterCriticalSection(&CSMutex);
#else
pthread_mutex_lock(&CSMutex);
@@ -111,7 +111,7 @@ void Mutex::lock() {
}
bool Mutex::trylock() {
#ifdef _WIN32
#ifdef _WINDOWS
#if(_WIN32_WINNT >= 0x0400)
if (TrylockSupported)
return TryEnterCriticalSection(&CSMutex);
@@ -129,7 +129,7 @@ bool Mutex::trylock() {
}
void Mutex::unlock() {
#ifdef _WIN32
#ifdef _WINDOWS
LeaveCriticalSection(&CSMutex);
#else
pthread_mutex_unlock(&CSMutex);
+2 -2
View File
@@ -17,7 +17,7 @@
*/
#ifndef MYMUTEX_H
#define MYMUTEX_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#else
@@ -36,7 +36,7 @@ public:
bool trylock();
protected:
private:
#if defined _WIN32
#if defined WIN32 || defined WIN64
CRITICAL_SECTION CSMutex;
#else
pthread_mutex_t CSMutex;
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef MYSQL_REQUEST_RESULT_H
#define MYSQL_REQUEST_RESULT_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
+1 -1
View File
@@ -1,7 +1,7 @@
#ifndef MYSQL_REQUEST_ROW_H
#define MYSQL_REQUEST_ROW_H
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
#endif
+32 -20
View File
@@ -10,20 +10,27 @@
EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager()
{
m_attached = nullptr;
m_next_id = 1;
memset(&m_timer, 0, sizeof(uv_timer_t));
memset(&m_socket, 0, sizeof(uv_udp_t));
Attach(EQ::EventLoop::GetDefault().Handle());
Attach(EventLoop::GetDefault().Handle());
}
EQ::Net::DaybreakConnectionManager::DaybreakConnectionManager(const DaybreakConnectionManagerOptions &opts)
{
m_attached = nullptr;
m_options = opts;
m_next_id = 1;
memset(&m_timer, 0, sizeof(uv_timer_t));
memset(&m_socket, 0, sizeof(uv_udp_t));
Attach(EQ::EventLoop::GetDefault().Handle());
if (opts.loop == nullptr) {
Attach(EventLoop::GetDefault().Handle());
}
else {
Attach(opts.loop->Handle());
}
}
EQ::Net::DaybreakConnectionManager::~DaybreakConnectionManager()
@@ -89,7 +96,7 @@ void EQ::Net::DaybreakConnectionManager::Connect(const std::string &addr, int po
{
//todo dns resolution
auto connection = std::shared_ptr<DaybreakConnection>(new DaybreakConnection(this, addr, port));
auto connection = std::shared_ptr<DaybreakConnection>(new DaybreakConnection(this, GetNextId(), addr, port));
connection->m_self = connection;
if (m_on_new_connection) {
@@ -227,7 +234,7 @@ void EQ::Net::DaybreakConnectionManager::ProcessPacket(const std::string &endpoi
StaticPacket p((void*)data, size);
auto request = p.GetSerialize<DaybreakConnect>(0);
connection = std::shared_ptr<DaybreakConnection>(new DaybreakConnection(this, request, endpoint, port));
connection = std::shared_ptr<DaybreakConnection>(new DaybreakConnection(this, GetNextId(), request, endpoint, port));
connection->m_self = connection;
if (m_on_new_connection) {
@@ -285,10 +292,18 @@ void EQ::Net::DaybreakConnectionManager::SendDisconnect(const std::string &addr,
});
}
uint64_t EQ::Net::DaybreakConnectionManager::GetNextId()
{
auto id = m_next_id;
m_next_id++;
return id;
}
//new connection made as server
EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner, const DaybreakConnect &connect, const std::string &endpoint, int port)
EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner, uint64_t id, const DaybreakConnect &connect, const std::string &endpoint, int port)
{
m_owner = owner;
m_id = id;
m_last_send = Clock::now();
m_last_recv = Clock::now();
m_status = StatusConnected;
@@ -311,9 +326,10 @@ EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner
}
//new connection made as client
EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner, const std::string &endpoint, int port)
EQ::Net::DaybreakConnection::DaybreakConnection(DaybreakConnectionManager *owner, uint64_t id, const std::string &endpoint, int port)
{
m_owner = owner;
m_id = id;
m_last_send = Clock::now();
m_last_recv = Clock::now();
m_status = StatusConnecting;
@@ -368,7 +384,6 @@ void EQ::Net::DaybreakConnection::QueuePacket(Packet &p, int stream, bool reliab
packet.PutUInt8(0, 0);
packet.PutPacket(1, p);
InternalQueuePacket(packet, stream, reliable);
return;
}
InternalQueuePacket(p, stream, reliable);
@@ -385,7 +400,7 @@ EQ::Net::DaybreakConnectionStats EQ::Net::DaybreakConnection::GetStats()
void EQ::Net::DaybreakConnection::ResetStats()
{
m_stats.Reset();
m_stats = DaybreakConnectionStats();
}
void EQ::Net::DaybreakConnection::Process()
@@ -418,7 +433,6 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
auto opcode = p.GetInt8(1);
if (p.GetInt8(0) == 0 && (opcode == OP_KeepAlive || opcode == OP_OutboundPing)) {
m_stats.bytes_after_decode += p.Length();
return;
}
@@ -427,8 +441,6 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
if (m_owner->m_on_error_message) {
m_owner->m_on_error_message(fmt::format("Tossed packet that failed CRC of type {0:#x}", p.Length() >= 2 ? p.GetInt8(1) : 0));
}
m_stats.bytes_after_decode += p.Length();
return;
}
@@ -457,7 +469,6 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
}
}
m_stats.bytes_after_decode += temp.Length();
ProcessDecodedPacket(StaticPacket(temp.Data(), temp.Length()));
}
else {
@@ -476,12 +487,10 @@ void EQ::Net::DaybreakConnection::ProcessPacket(Packet &p)
}
}
m_stats.bytes_after_decode += temp.Length();
ProcessDecodedPacket(StaticPacket(temp.Data(), temp.Length()));
}
}
else {
m_stats.bytes_after_decode += p.Length();
ProcessDecodedPacket(p);
}
}
@@ -1000,7 +1009,7 @@ uint32_t Deflate(const uint8_t* in, uint32_t in_len, uint8_t* out, uint32_t out_
zstream.avail_in = in_len;
zstream.opaque = Z_NULL;
deflateInit(&zstream, Z_BEST_SPEED);
deflateInit(&zstream, Z_FINISH);
zstream.next_out = out;
zstream.avail_out = out_len;
@@ -1096,6 +1105,10 @@ void EQ::Net::DaybreakConnection::ProcessResend(int stream)
}
m_stats.resent_packets++;
m_stats.resent_time_min = std::min(m_stats.resent_time_min, (uint64_t)time_since_last_send.count());
m_stats.resent_time_max = std::max(m_stats.resent_time_max, (uint64_t)time_since_last_send.count());
m_stats.resent_time_average = (m_stats.resent_time_average / 2) + (time_since_last_send.count() / 2);
InternalBufferedSend(p);
entry.second.last_sent = now;
entry.second.times_resent++;
@@ -1125,6 +1138,10 @@ void EQ::Net::DaybreakConnection::ProcessResend(int stream)
}
m_stats.resent_packets++;
m_stats.resent_time_min = std::min(m_stats.resent_time_min, (uint64_t)time_since_last_send.count());
m_stats.resent_time_max = std::max(m_stats.resent_time_max, (uint64_t)time_since_last_send.count());
m_stats.resent_time_average = (m_stats.resent_time_average / 2) + (time_since_last_send.count() / 2);
InternalBufferedSend(p);
entry.second.last_sent = now;
entry.second.times_resent++;
@@ -1292,9 +1309,6 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
};
if (PacketCanBeEncoded(p)) {
m_stats.bytes_before_encode += p.Length();
DynamicPacket out;
out.PutPacket(0, p);
@@ -1342,8 +1356,6 @@ void EQ::Net::DaybreakConnection::InternalSend(Packet &p)
return;
}
m_stats.bytes_before_encode += p.Length();
uv_udp_send_t *send_req = new uv_udp_send_t;
sockaddr_in send_addr;
uv_ip4_addr(m_endpoint.c_str(), m_port, &send_addr);
+17 -24
View File
@@ -13,6 +13,7 @@
namespace EQ
{
class EventLoop;
namespace Net
{
enum DaybreakProtocolOpcode
@@ -90,25 +91,10 @@ namespace EQ
resent_packets = 0;
resent_fragments = 0;
resent_full = 0;
resent_time_min = 0;
resent_time_max = 0;
resent_time_average = 0;
datarate_remaining = 0.0;
bytes_after_decode = 0;
bytes_before_encode = 0;
}
void Reset() {
recv_bytes = 0;
sent_bytes = 0;
min_ping = 0xFFFFFFFFFFFFFFFFUL;
max_ping = 0;
avg_ping = 0;
created = Clock::now();
dropped_datarate_packets = 0;
resent_packets = 0;
resent_fragments = 0;
resent_full = 0;
datarate_remaining = 0.0;
bytes_after_decode = 0;
bytes_before_encode = 0;
}
uint64_t recv_bytes;
@@ -128,9 +114,10 @@ namespace EQ
uint64_t resent_packets;
uint64_t resent_fragments;
uint64_t resent_full;
uint64_t resent_time_min;
uint64_t resent_time_max;
uint64_t resent_time_average;
double datarate_remaining;
uint64_t bytes_after_decode;
uint64_t bytes_before_encode;
};
class DaybreakConnectionManager;
@@ -138,8 +125,8 @@ namespace EQ
class DaybreakConnection
{
public:
DaybreakConnection(DaybreakConnectionManager *owner, const DaybreakConnect &connect, const std::string &endpoint, int port);
DaybreakConnection(DaybreakConnectionManager *owner, const std::string &endpoint, int port);
DaybreakConnection(DaybreakConnectionManager *owner, uint64_t id, const DaybreakConnect &connect, const std::string &endpoint, int port);
DaybreakConnection(DaybreakConnectionManager *owner, uint64_t id, const std::string &endpoint, int port);
~DaybreakConnection();
const std::string& RemoteEndpoint() const { return m_endpoint; }
@@ -158,6 +145,7 @@ namespace EQ
const DaybreakEncodeType* GetEncodePasses() const { return m_encode_passes; }
const DaybreakConnectionManager* GetManager() const { return m_owner; }
DaybreakConnectionManager* GetManager() { return m_owner; }
uint64_t GetId() const { return m_id; }
private:
DaybreakConnectionManager *m_owner;
std::string m_endpoint;
@@ -180,6 +168,7 @@ namespace EQ
size_t m_rolling_ping;
Timestamp m_close_time;
double m_outgoing_budget;
uint64_t m_id;
struct DaybreakSentPacket
{
@@ -257,7 +246,7 @@ namespace EQ
resend_delay_min = 150;
resend_delay_max = 5000;
connect_delay_ms = 500;
stale_connection_ms = 60000;
stale_connection_ms = 90000;
connect_stale_ms = 5000;
crc_length = 2;
max_packet_size = 512;
@@ -269,9 +258,10 @@ namespace EQ
simulated_in_packet_loss = 0;
simulated_out_packet_loss = 0;
tic_rate_hertz = 60.0;
resend_timeout = 30000;
resend_timeout = 90000;
connection_close_time = 2000;
outgoing_data_rate = 0.0;
loop = nullptr;
}
size_t max_packet_size;
@@ -295,6 +285,7 @@ namespace EQ
DaybreakEncodeType encode_passes[2];
int port;
double outgoing_data_rate;
EQ::EventLoop *loop;
};
class DaybreakConnectionManager
@@ -323,6 +314,7 @@ namespace EQ
uv_udp_t m_socket;
uv_loop_t *m_attached;
DaybreakConnectionManagerOptions m_options;
uint64_t m_next_id;
std::function<void(std::shared_ptr<DaybreakConnection>)> m_on_new_connection;
std::function<void(std::shared_ptr<DaybreakConnection>, DbProtocolStatus, DbProtocolStatus)> m_on_connection_state_change;
std::function<void(std::shared_ptr<DaybreakConnection>, const Packet&)> m_on_packet_recv;
@@ -332,6 +324,7 @@ namespace EQ
void ProcessPacket(const std::string &endpoint, int port, const char *data, size_t size);
std::shared_ptr<DaybreakConnection> FindConnectionByEndpoint(std::string addr, int port);
void SendDisconnect(const std::string &addr, int port);
uint64_t GetNextId();
friend class DaybreakConnection;
};
+6 -2
View File
@@ -8,7 +8,7 @@ namespace EQ
{
namespace Net
{
static void DNSLookup(const std::string &addr, int port, bool ipv6, std::function<void(const std::string&)> cb) {
static void DNSLookup(EQ::EventLoop *eloop, const std::string &addr, int port, bool ipv6, std::function<void(const std::string&)> cb) {
struct DNSBaton
{
std::function<void(const std::string&)> cb;
@@ -21,7 +21,7 @@ namespace EQ
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = eloop->Handle();
uv_getaddrinfo_t *resolver = new uv_getaddrinfo_t();
memset(resolver, 0, sizeof(uv_getaddrinfo_t));
auto port_str = std::to_string(port);
@@ -57,5 +57,9 @@ namespace EQ
cb(addr);
}, addr.c_str(), port_str.c_str(), &hints);
}
static void DNSLookup(const std::string &addr, int port, bool ipv6, std::function<void(const std::string&)> cb) {
DNSLookup(&EQ::EventLoop::GetDefault(), addr, port, ipv6, cb);
}
}
}
+2 -9
View File
@@ -13,13 +13,6 @@ EQ::Net::EQStreamManager::~EQStreamManager()
{
}
void EQ::Net::EQStreamManager::SetOptions(const EQStreamManagerInterfaceOptions &options)
{
m_options = options;
auto &opts = m_daybreak.GetOptions();
opts = options.daybreak_options;
}
void EQ::Net::EQStreamManager::DaybreakNewConnection(std::shared_ptr<DaybreakConnection> connection)
{
std::shared_ptr<EQStream> stream(new EQStream(this, connection));
@@ -72,7 +65,7 @@ void EQ::Net::EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
opcode = p->GetOpcodeBypass();
}
else {
m_packet_sent_count[static_cast<int>(p->GetOpcode())]++; //Wont bother with bypass tracking of these since those are rare for testing anyway
m_packet_sent_count[p->GetOpcode()]++; //Wont bother with bypass tracking of these since those are rare for testing anyway
opcode = (*m_opcode_manager)->EmuToEQ(p->GetOpcode());
}
@@ -122,7 +115,7 @@ EQApplicationPacket *EQ::Net::EQStream::PopPacket() {
}
EmuOpcode emu_op = (*m_opcode_manager)->EQToEmu(opcode);
m_packet_recv_count[static_cast<int>(emu_op)]++;
m_packet_recv_count[emu_op]++;
EQApplicationPacket *ret = new EQApplicationPacket(emu_op, (unsigned char*)p->Data() + m_owner->GetOptions().opcode_size, p->Length() - m_owner->GetOptions().opcode_size);
ret->SetProtocolOpcode(opcode);
+7 -7
View File
@@ -19,13 +19,13 @@ namespace EQ
EQStreamManager(const EQStreamManagerInterfaceOptions &options);
~EQStreamManager();
virtual void SetOptions(const EQStreamManagerInterfaceOptions& options);
void OnNewConnection(std::function<void(std::shared_ptr<EQStream>)> func) { m_on_new_connection = func; }
void OnConnectionStateChange(std::function<void(std::shared_ptr<EQStream>, DbProtocolStatus, DbProtocolStatus)> func) { m_on_connection_state_change = func; }
virtual void OnNewConnection(std::function<void(std::shared_ptr<EQStreamInterface>)> func) { m_on_new_connection = func; }
virtual void OnConnectionStateChange(std::function<void(std::shared_ptr<EQStreamInterface>, EQ::Net::DbProtocolStatus, EQ::Net::DbProtocolStatus)> func) { m_on_connection_state_change = func; }
virtual void SetPriority(EQStreamPriority priority) { }
private:
DaybreakConnectionManager m_daybreak;
std::function<void(std::shared_ptr<EQStream>)> m_on_new_connection;
std::function<void(std::shared_ptr<EQStream>, DbProtocolStatus, DbProtocolStatus)> m_on_connection_state_change;
std::function<void(std::shared_ptr<EQStreamInterface>)> m_on_new_connection;
std::function<void(std::shared_ptr<EQStreamInterface>, DbProtocolStatus, DbProtocolStatus)> m_on_connection_state_change;
std::map<std::shared_ptr<DaybreakConnection>, std::shared_ptr<EQStream>> m_streams;
void DaybreakNewConnection(std::shared_ptr<DaybreakConnection> connection);
@@ -66,8 +66,8 @@ namespace EQ
std::shared_ptr<DaybreakConnection> m_connection;
OpcodeManager **m_opcode_manager;
std::deque<std::unique_ptr<EQ::Net::Packet>> m_packet_queue;
std::unordered_map<int, int> m_packet_recv_count;
std::unordered_map<int, int> m_packet_sent_count;
std::unordered_map<EmuOpcode, int> m_packet_recv_count;
std::unordered_map<EmuOpcode, int> m_packet_sent_count;
friend class EQStreamManager;
};
}
+685
View File
@@ -0,0 +1,685 @@
#include "eqstream_concurrent.h"
#include "eqstream_concurrent_message.h"
#include "../event/event_loop.h"
#include "../event/timer.h"
#include "../string_util.h"
#include "../opcodemgr.h"
#include "../eqemu_logsys.h"
#include "../eqemu_logsys_fmt.h"
#include "daybreak_connection.h"
#include <thread>
#include <concurrentqueue.h>
#include <unordered_map>
#include <queue>
#include <deque>
#include <list>
struct EQ::Net::ConcurrentEQStreamManager::Impl
{
std::thread background;
bool background_running;
moodycamel::ConcurrentQueue<ceqs_msg_t> foreground_queue;
moodycamel::ConcurrentQueue<ceqs_msg_t> background_queue;
std::unordered_map<uint64_t, std::shared_ptr<DaybreakConnection>> connections;
std::unique_ptr<EQ::Timer> foreground_loop_timer;
std::unique_ptr<EQ::Timer> background_loop_timer;
std::unique_ptr<EQ::Timer> background_update_stats_timer;
std::unordered_map<uint64_t, std::shared_ptr<ConcurrentEQStream>> streams;
std::function<void(std::shared_ptr<EQStreamInterface>)> on_new_connection;
std::function<void(std::shared_ptr<EQStreamInterface>, EQ::Net::DbProtocolStatus, EQ::Net::DbProtocolStatus)> on_connection_state_change;
EQStreamPriority priority;
};
EQ::Net::ConcurrentEQStreamManager::ConcurrentEQStreamManager(const EQStreamManagerInterfaceOptions &options)
: EQStreamManagerInterface(options)
{
_impl.reset(new Impl());
_impl->background = std::thread(std::bind(&ConcurrentEQStreamManager::_BackgroundThread, this));
_impl->foreground_loop_timer.reset(new EQ::Timer(options.loop, 16, true,
std::bind(&ConcurrentEQStreamManager::_ForegroundTimer, this, std::placeholders::_1)));
_impl->priority = EQStreamPriority::High;
}
EQ::Net::ConcurrentEQStreamManager::~ConcurrentEQStreamManager()
{
for (auto &s : _impl->streams) {
s.second->_Invalidate();
}
_impl->foreground_loop_timer.release();
//Tell the background to shutdown and wait for it to actually do so
ceqs_terminate_msg_t msg;
msg.type = ceqs_msg_type::TerminateBackground;
_PushToBackgroundQueue((ceqs_msg_t*)&msg);
_impl->background.join();
//Go through our incoming messages to make sure we clean up any packets in that need to be freed
ceqs_msg_t eqs_msg;
while (_impl->foreground_queue.try_dequeue(eqs_msg)) {
if (eqs_msg.type == ceqs_msg_type::PacketRecv) {
ceqs_packet_recv_msg_t *eqs_msg_in = (ceqs_packet_recv_msg_t*)&eqs_msg;
delete eqs_msg_in->packet;
}
}
}
void EQ::Net::ConcurrentEQStreamManager::_BackgroundThread() {
_impl->background_running = true;
EQ::EventLoop loop;
auto &eqs_opts = GetOptions();
auto opts = eqs_opts.daybreak_options;
opts.loop = &loop;
std::unique_ptr<DaybreakConnectionManager> dbcm(new DaybreakConnectionManager(opts));
dbcm->OnNewConnection(std::bind(&ConcurrentEQStreamManager::DaybreakNewConnection, this, std::placeholders::_1));
dbcm->OnConnectionStateChange(std::bind(&ConcurrentEQStreamManager::DaybreakConnectionStateChange, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
dbcm->OnPacketRecv(std::bind(&ConcurrentEQStreamManager::DaybreakPacketRecv, this, std::placeholders::_1, std::placeholders::_2));
_impl->background_loop_timer.reset(new EQ::Timer(&loop, 16, true,
std::bind(&ConcurrentEQStreamManager::_BackgroundTimer, this, std::placeholders::_1)));
_impl->background_update_stats_timer.reset(new EQ::Timer(&loop, 500, true,
std::bind(&ConcurrentEQStreamManager::_BackgroundUpdateStatsTimer, this, std::placeholders::_1)));
while (true == _impl->background_running) {
loop.Process();
switch (_impl->priority) {
case EQStreamPriority::Low:
Sleep(10);
break;
case EQStreamPriority::Normal:
Sleep(5);
break;
case EQStreamPriority::High:
Sleep(1);
break;
}
}
_impl->background_loop_timer.release();
_impl->background_update_stats_timer.release();
dbcm.release();
ceqs_msg_t eqs_msg;
while (_impl->background_queue.try_dequeue(eqs_msg)) {
if (eqs_msg.type == ceqs_msg_type::QueuePacket) {
ceqs_queue_packet_msg_t *eqs_msg_in = (ceqs_queue_packet_msg_t*)&eqs_msg;
delete eqs_msg_in->packet;
}
}
}
//Called by background
void EQ::Net::ConcurrentEQStreamManager::_BackgroundTimer(EQ::Timer * t)
{
ceqs_msg_t msg_queue[16];
size_t count = 0;
while ((count = _impl->background_queue.try_dequeue_bulk(msg_queue, 16)) != 0) {
for (size_t i = 0; i < count; ++i) {
_ProcessBackgroundMessage(msg_queue[i]);
}
}
}
void EQ::Net::ConcurrentEQStreamManager::_BackgroundUpdateStatsTimer(EQ::Timer *t)
{
ceqs_msg_t msgs[16];
int i = 0;
for (auto &c : _impl->connections) {
auto &connection = c.second;
auto msg = (ceqs_update_stats_msg_t*)&msgs[i];
msg->type = ceqs_msg_type::UpdateStats;
msg->stream_id = connection->GetId();
msg->stats = connection->GetStats();
i++;
if (i >= 16) {
_impl->foreground_queue.enqueue_bulk(msgs, 16);
i = 0;
}
}
if (i > 0) {
_impl->foreground_queue.enqueue_bulk(msgs, i);
}
}
//Called by background
void EQ::Net::ConcurrentEQStreamManager::_ProcessBackgroundMessage(const ceqs_msg_t &msg)
{
switch (msg.type) {
case ceqs_msg_type::QueuePacket:
{
ceqs_queue_packet_msg_t *msg_in = (ceqs_queue_packet_msg_t*)&msg;
auto iter = _impl->connections.find(msg_in->stream_id);
if (iter != _impl->connections.end()) {
iter->second->QueuePacket(*msg_in->packet, 0, msg_in->ack_req);
}
delete msg_in->packet;
break;
}
case ceqs_msg_type::TerminateBackground:
{
_impl->background_running = false;
break;
}
case ceqs_msg_type::CloseConnection:
{
ceqs_close_connection_msg_t *msg_in = (ceqs_close_connection_msg_t*)&msg;
auto iter = _impl->connections.find(msg_in->stream_id);
if (iter != _impl->connections.end()) {
iter->second->Close();
}
break;
}
case ceqs_msg_type::ResetStats:
{
ceqs_reset_stats_msg_t *msg_in = (ceqs_reset_stats_msg_t*)&msg;
auto iter = _impl->connections.find(msg_in->stream_id);
if (iter != _impl->connections.end()) {
iter->second->ResetStats();
}
break;
}
case ceqs_msg_type::SetPriority:
{
ceqs_set_priority_msg_t *msg_in = (ceqs_set_priority_msg_t*)&msg;
_impl->priority = msg_in->priority;
break;
}
default:
break;
}
}
//Called by foreground
void EQ::Net::ConcurrentEQStreamManager::_ForegroundTimer(EQ::Timer *t)
{
ceqs_msg_t msg_queue[16];
size_t count = 0;
while ((count = _impl->foreground_queue.try_dequeue_bulk(msg_queue, 16)) != 0) {
for (size_t i = 0; i < count; ++i) {
_ProcessForegroundMessage(msg_queue[i]);
}
}
}
//Called by foreground
void EQ::Net::ConcurrentEQStreamManager::_ProcessForegroundMessage(const ceqs_msg_t &msg)
{
switch (msg.type) {
case ceqs_msg_type::NewConnection:
{
ceqs_new_connection_msg_t *msg_in = (ceqs_new_connection_msg_t*)&msg;
std::shared_ptr<ConcurrentEQStream> stream(new ConcurrentEQStream(this,
msg_in->stream_id,
msg_in->endpoint,
msg_in->remote_port,
(DbProtocolStatus)msg_in->state));
_impl->streams.insert(std::make_pair(msg_in->stream_id, stream));
if (_impl->on_new_connection) {
_impl->on_new_connection(stream);
}
break;
}
case ceqs_msg_type::ConnectionStateChange:
{
ceqs_connection_state_change_msg_t *msg_in = (ceqs_connection_state_change_msg_t*)&msg;
auto iter = _impl->streams.find(msg_in->stream_id);
if (iter != _impl->streams.end()) {
iter->second->_SetState((DbProtocolStatus)msg_in->to);
if ((DbProtocolStatus)msg_in->to == DbProtocolStatus::StatusDisconnected || (DbProtocolStatus)msg_in->to == DbProtocolStatus::StatusDisconnecting) {
_impl->streams.erase(iter);
}
}
break;
}
case ceqs_msg_type::PacketRecv:
{
ceqs_packet_recv_msg_t *msg_in = (ceqs_packet_recv_msg_t*)&msg;
std::unique_ptr<EQ::Net::Packet> p(msg_in->packet);
auto iter = _impl->streams.find(msg_in->stream_id);
if (iter != _impl->streams.end()) {
iter->second->_RecvPacket(std::move(p));
}
break;
}
case ceqs_msg_type::UpdateStats:
{
ceqs_update_stats_msg_t *msg_in = (ceqs_update_stats_msg_t*)&msg;
auto iter = _impl->streams.find(msg_in->stream_id);
if (iter != _impl->streams.end()) {
iter->second->_UpdateStats(msg_in->stats);
}
break;
}
default:
break;
}
}
void EQ::Net::ConcurrentEQStreamManager::_PushToBackgroundQueue(ceqs_msg_t *msg)
{
_impl->background_queue.enqueue(*msg);
}
void EQ::Net::ConcurrentEQStreamManager::_PushToForegroundQueue(ceqs_msg_t *msg)
{
_impl->foreground_queue.enqueue(*msg);
}
//Called by foreground
void EQ::Net::ConcurrentEQStreamManager::OnNewConnection(std::function<void(std::shared_ptr<EQStreamInterface>)> func)
{
_impl->on_new_connection = func;
}
//Called by foreground
void EQ::Net::ConcurrentEQStreamManager::OnConnectionStateChange(std::function<void(std::shared_ptr<EQStreamInterface>, DbProtocolStatus, DbProtocolStatus)> func)
{
_impl->on_connection_state_change = func;
}
//Called by foreground
void EQ::Net::ConcurrentEQStreamManager::SetPriority(EQStreamPriority priority)
{
ceqs_set_priority_msg_t msg;
msg.type = ceqs_msg_type::SetPriority;
msg.priority = priority;
_PushToBackgroundQueue((ceqs_msg_t*)&msg);
}
//Called by background
void EQ::Net::ConcurrentEQStreamManager::DaybreakNewConnection(std::shared_ptr<DaybreakConnection> connection)
{
_impl->connections.insert(std::make_pair(connection->GetId(), connection));
ceqs_new_connection_msg_t msg;
msg.type = ceqs_msg_type::NewConnection;
msg.stream_id = connection->GetId();
msg.remote_port = connection->RemotePort();
msg.state = connection->GetStatus();
strcpy(msg.endpoint, connection->RemoteEndpoint().c_str());
msg.endpoint[connection->RemoteEndpoint().length()] = 0;
//Make sure the foreground gets this message
_PushToForegroundQueue((ceqs_msg_t*)&msg);
}
//Called by background
void EQ::Net::ConcurrentEQStreamManager::DaybreakConnectionStateChange(std::shared_ptr<DaybreakConnection> connection, DbProtocolStatus from, DbProtocolStatus to)
{
if (to == DbProtocolStatus::StatusDisconnecting || to == DbProtocolStatus::StatusDisconnected) {
auto iter = _impl->connections.find(connection->GetId());
if (iter != _impl->connections.end()) {
_impl->connections.erase(iter);
}
}
ceqs_connection_state_change_msg_t msg;
msg.type = ceqs_msg_type::ConnectionStateChange;
msg.stream_id = connection->GetId();
msg.from = (int)from;
msg.to = (int)to;
//Make sure the foreground gets this message
_PushToForegroundQueue((ceqs_msg_t*)&msg);
}
//Called by background
void EQ::Net::ConcurrentEQStreamManager::DaybreakPacketRecv(std::shared_ptr<DaybreakConnection> connection, const Packet &p)
{
ceqs_packet_recv_msg_t msg;
msg.type = ceqs_msg_type::PacketRecv;
msg.stream_id = connection->GetId();
msg.packet = new DynamicPacket();
msg.packet->PutPacket(0, p);
//Make sure the foreground gets this message
_PushToForegroundQueue((ceqs_msg_t*)&msg);
}
struct EQ::Net::ConcurrentEQStream::Impl
{
ConcurrentEQStreamManager *parent;
uint64_t id;
std::string remote_endpoint;
int remote_port;
uint32_t remote_ip;
DbProtocolStatus state;
std::deque<std::unique_ptr<EQ::Net::Packet>> packet_queue;
OpcodeManager **opcode_manager;
DaybreakConnectionStats stats;
std::unordered_map<EmuOpcode, int> packet_recv_count;
std::unordered_map<EmuOpcode, int> packet_sent_count;
};
//Called by foreground
EQ::Net::ConcurrentEQStream::ConcurrentEQStream(ConcurrentEQStreamManager *parent, uint64_t id, const std::string &remote_endpoint, int remote_port, DbProtocolStatus state)
{
_impl.reset(new Impl());
_impl->parent = parent;
_impl->id = id;
_impl->remote_endpoint = remote_endpoint;
_impl->remote_port = remote_port;
_impl->remote_ip = inet_addr(remote_endpoint.c_str());
_impl->state = state;
_impl->opcode_manager = nullptr;
}
//Called by foreground
EQ::Net::ConcurrentEQStream::~ConcurrentEQStream()
{
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
{
if (!_impl->parent) {
return;
}
if (_impl->opcode_manager && *_impl->opcode_manager) {
auto &options = _impl->parent->GetOptions();
uint16 opcode = 0;
if (p->GetOpcodeBypass() != 0) {
opcode = p->GetOpcodeBypass();
}
else {
_impl->packet_sent_count[p->GetOpcode()]++;
opcode = (*_impl->opcode_manager)->EmuToEQ(p->GetOpcode());
}
EQ::Net::DynamicPacket *out = new EQ::Net::DynamicPacket();
switch (options.opcode_size) {
case 1:
out->PutUInt8(0, opcode);
out->PutData(1, p->pBuffer, p->size);
break;
case 2:
out->PutUInt16(0, opcode);
out->PutData(2, p->pBuffer, p->size);
break;
}
ceqs_queue_packet_msg_t msg;
msg.type = ceqs_msg_type::QueuePacket;
msg.stream_id = _impl->id;
msg.packet = out;
msg.ack_req = ack_req;
//Make sure the background gets this message
_impl->parent->_PushToBackgroundQueue((ceqs_msg_t*)&msg);
}
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::FastQueuePacket(EQApplicationPacket **p, bool ack_req)
{
QueuePacket(*p, ack_req);
delete *p;
*p = nullptr;
}
//Called by foreground
EQApplicationPacket *EQ::Net::ConcurrentEQStream::PopPacket()
{
if (!_impl->parent) {
return nullptr;
}
if (_impl->packet_queue.empty()) {
return nullptr;
}
if (_impl->opcode_manager != nullptr && *_impl->opcode_manager != nullptr) {
auto &options = _impl->parent->GetOptions();
auto &p = _impl->packet_queue.front();
uint16 opcode = 0;
switch (options.opcode_size) {
case 1:
opcode = p->GetUInt8(0);
break;
case 2:
opcode = p->GetUInt16(0);
break;
}
EmuOpcode emu_op = (*_impl->opcode_manager)->EQToEmu(opcode);
_impl->packet_recv_count[emu_op]++;
EQApplicationPacket *ret = new EQApplicationPacket(emu_op, (unsigned char*)p->Data() + options.opcode_size, p->Length() - options.opcode_size);
ret->SetProtocolOpcode(opcode);
_impl->packet_queue.pop_front();
return ret;
}
return nullptr;
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::Close()
{
if (!_impl->parent) {
return;
}
ceqs_close_connection_msg_t msg;
msg.type = ceqs_msg_type::CloseConnection;
msg.stream_id = _impl->id;
_impl->parent->_PushToBackgroundQueue((ceqs_msg_t*)&msg);
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::ReleaseFromUse()
{
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::RemoveData()
{
}
//Called by foreground
std::string EQ::Net::ConcurrentEQStream::GetRemoteAddr() const
{
return _impl->remote_endpoint;
}
//Called by foreground
uint32 EQ::Net::ConcurrentEQStream::GetRemoteIP() const
{
return _impl->remote_ip;
}
//Called by foreground
uint16 EQ::Net::ConcurrentEQStream::GetRemotePort() const
{
return _impl->remote_port;
}
//Called by foreground
bool EQ::Net::ConcurrentEQStream::CheckState(EQStreamState state)
{
return GetState() == state;
}
//Called by foreground
std::string EQ::Net::ConcurrentEQStream::Describe() const
{
return "Concurrent EQStream";
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::SetActive(bool val)
{
}
//Called by foreground
EQStreamInterface::MatchState EQ::Net::ConcurrentEQStream::CheckSignature(const Signature *sig)
{
if (!_impl->parent) {
return MatchFailed;
}
if (!_impl->packet_queue.empty()) {
auto& options = _impl->parent->GetOptions();
auto p = _impl->packet_queue.front().get();
uint16 opcode = 0;
size_t length = p->Length() - options.opcode_size;
switch (options.opcode_size) {
case 1:
opcode = p->GetUInt8(0);
break;
case 2:
opcode = p->GetUInt16(0);
break;
}
if (sig->ignore_eq_opcode != 0 && opcode == sig->ignore_eq_opcode) {
if (_impl->packet_queue.size() > 1) {
p = _impl->packet_queue[1].get();
opcode = 0;
length = p->Length() - options.opcode_size;
switch (options.opcode_size) {
case 1:
opcode = p->GetUInt8(0);
break;
case 2:
opcode = p->GetUInt16(0);
break;
}
}
else {
return MatchNotReady;
}
}
if (opcode == sig->first_eq_opcode) {
if (length == sig->first_length) {
LogF(Logs::General, Logs::Netcode, "[IDENT_TRACE] {0}:{1}: First opcode matched {2:#x} and length matched {3}",
GetRemoteAddr(), GetRemotePort(), sig->first_eq_opcode, length);
return MatchSuccessful;
}
else if (length == 0) {
LogF(Logs::General, Logs::Netcode, "[IDENT_TRACE] {0}:{1}: First opcode matched {2:#x} and length is ignored.",
GetRemoteAddr(), GetRemotePort(), sig->first_eq_opcode);
return MatchSuccessful;
}
else {
LogF(Logs::General, Logs::Netcode, "[IDENT_TRACE] {0}:{1}: First opcode matched {2:#x} but length {3} did not match expected {4}",
GetRemoteAddr(), GetRemotePort(), sig->first_eq_opcode, length, sig->first_length);
return MatchFailed;
}
}
else {
LogF(Logs::General, Logs::Netcode, "[IDENT_TRACE] {0}:{1}: First opcode {1:#x} did not match expected {2:#x}",
GetRemoteAddr(), GetRemotePort(), opcode, sig->first_eq_opcode);
return MatchFailed;
}
}
return MatchNotReady;
}
//Called by foreground
EQStreamState EQ::Net::ConcurrentEQStream::GetState()
{
switch (_impl->state) {
case StatusConnecting:
return UNESTABLISHED;
case StatusConnected:
return ESTABLISHED;
case StatusDisconnecting:
return DISCONNECTING;
default:
return CLOSED;
}
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::SetOpcodeManager(OpcodeManager **opm)
{
_impl->opcode_manager = opm;
}
//Called by foreground
EQStreamInterface::Stats EQ::Net::ConcurrentEQStream::GetStats() const
{
EQStreamInterface::Stats ret;
ret.DaybreakStats = _impl->stats;
for (int i = 0; i < _maxEmuOpcode; ++i) {
ret.RecvCount[i] = 0;
ret.SentCount[i] = 0;
}
for (auto &s : _impl->packet_sent_count) {
ret.SentCount[s.first] = s.second;
}
for (auto &r : _impl->packet_recv_count) {
ret.RecvCount[r.first] = r.second;
}
return ret;
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::ResetStats()
{
if (!_impl->parent) {
return;
}
ceqs_reset_stats_msg_t msg;
msg.type = ceqs_msg_type::ResetStats;
msg.stream_id = _impl->id;
_impl->parent->_PushToBackgroundQueue((ceqs_msg_t*)&msg);
}
//Called by foreground
EQStreamManagerInterface *EQ::Net::ConcurrentEQStream::GetManager() const
{
return _impl->parent;
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::_SetState(DbProtocolStatus state)
{
_impl->state = state;
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::_RecvPacket(std::unique_ptr<EQ::Net::Packet> p)
{
_impl->packet_queue.push_back(std::move(p));
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::_UpdateStats(const DaybreakConnectionStats &stats)
{
_impl->stats = stats;
}
//Called by foreground
void EQ::Net::ConcurrentEQStream::_Invalidate()
{
_impl->parent = nullptr;
}
+75
View File
@@ -0,0 +1,75 @@
#pragma once
#include "../eq_stream_intf.h"
#include "eqstream_concurrent_message.h"
#include <memory>
namespace EQ
{
class Timer;
namespace Net
{
class ConcurrentEQStream;
class ConcurrentEQStreamManager : public EQStreamManagerInterface
{
public:
ConcurrentEQStreamManager(const EQStreamManagerInterfaceOptions &options);
~ConcurrentEQStreamManager();
virtual void OnNewConnection(std::function<void(std::shared_ptr<EQStreamInterface>)> func);
virtual void OnConnectionStateChange(std::function<void(std::shared_ptr<EQStreamInterface>, EQ::Net::DbProtocolStatus, EQ::Net::DbProtocolStatus)> func);
virtual void SetPriority(EQStreamPriority priority);
void _PushToBackgroundQueue(ceqs_msg_t* msg);
void _PushToForegroundQueue(ceqs_msg_t* msg);
private:
struct Impl;
std::unique_ptr<Impl> _impl;
void _BackgroundThread();
void _BackgroundTimer(EQ::Timer *t);
void _BackgroundUpdateStatsTimer(EQ::Timer *t);
void _ProcessBackgroundMessage(const ceqs_msg_t &msg);
void _ForegroundTimer(EQ::Timer *t);
void _ProcessForegroundMessage(const ceqs_msg_t &msg);
void DaybreakNewConnection(std::shared_ptr<DaybreakConnection> connection);
void DaybreakConnectionStateChange(std::shared_ptr<DaybreakConnection> connection, DbProtocolStatus from, DbProtocolStatus to);
void DaybreakPacketRecv(std::shared_ptr<DaybreakConnection> connection, const Packet &p);
};
class ConcurrentEQStream : public EQStreamInterface
{
public:
ConcurrentEQStream(ConcurrentEQStreamManager *parent, uint64_t id, const std::string &remote_endpoint, int remote_port, DbProtocolStatus state);
~ConcurrentEQStream();
virtual void QueuePacket(const EQApplicationPacket *p, bool ack_req = true);
virtual void FastQueuePacket(EQApplicationPacket **p, bool ack_req = true);
virtual EQApplicationPacket *PopPacket();
virtual void Close();
virtual void ReleaseFromUse();
virtual void RemoveData();
virtual std::string GetRemoteAddr() const;
virtual uint32 GetRemoteIP() const;
virtual uint16 GetRemotePort() const;
virtual bool CheckState(EQStreamState state);
virtual std::string Describe() const;
virtual void SetActive(bool val);
virtual MatchState CheckSignature(const Signature *sig);
virtual EQStreamState GetState();
virtual void SetOpcodeManager(OpcodeManager **opm);
virtual Stats GetStats() const;
virtual void ResetStats();
virtual EQStreamManagerInterface* GetManager() const;
void _SetState(DbProtocolStatus state);
void _RecvPacket(std::unique_ptr<EQ::Net::Packet> p);
void _UpdateStats(const DaybreakConnectionStats &stats);
void _Invalidate();
private:
struct Impl;
std::unique_ptr<Impl> _impl;
};
}
}
+95
View File
@@ -0,0 +1,95 @@
#pragma once
#define EQSM_PAD_LEN 252
namespace EQ
{
namespace Net
{
class DynamicPacket;
enum ceqs_msg_type : uint32_t
{
//Sent by background
NewConnection,
ConnectionStateChange,
PacketRecv,
UpdateStats,
//Sent by foreground
QueuePacket,
TerminateBackground,
CloseConnection,
ResetStats,
SetPriority
};
typedef struct
{
ceqs_msg_type type;
char padding[EQSM_PAD_LEN];
} ceqs_msg_t;
//Sent by background
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
int remote_port;
int state;
char endpoint[64];
} ceqs_new_connection_msg_t;
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
int from;
int to;
} ceqs_connection_state_change_msg_t;
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
EQ::Net::DynamicPacket *packet;
} ceqs_packet_recv_msg_t;
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
DaybreakConnectionStats stats;
} ceqs_update_stats_msg_t;
//Sent by foreground
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
EQ::Net::DynamicPacket *packet;
bool ack_req;
} ceqs_queue_packet_msg_t;
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
} ceqs_close_connection_msg_t;
typedef struct
{
ceqs_msg_type type;
uint64_t stream_id;
} ceqs_reset_stats_msg_t;
typedef struct
{
ceqs_msg_type type;
} ceqs_terminate_msg_t;
typedef struct
{
ceqs_msg_type type;
EQStreamPriority priority;
} ceqs_set_priority_msg_t;
}
}
+279 -6
View File
@@ -1,16 +1,279 @@
#include "packet.h"
#include <fmt/format.h>
#include "endian.h"
#include <cctype>
#include <fmt/format.h>
bool EQ::Net::StaticPacket::Resize(size_t new_size)
void EQ::Net::Packet::PutInt8(size_t offset, int8_t value)
{
if (new_size > _max_len) {
return false;
if (Length() < offset + 1) {
if (!Resize(offset + 1)) {
throw std::out_of_range("Packet::PutInt8(), could not resize packet and would of written past the end.");
}
}
_len = new_size;
return true;
*(int8_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutInt16(size_t offset, int16_t value)
{
if (Length() < offset + 2) {
if (!Resize(offset + 2)) {
throw std::out_of_range("Packet::PutInt16(), could not resize packet and would of written past the end.");
}
}
*(int16_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutInt32(size_t offset, int32_t value)
{
if (Length() < offset + 4) {
if (!Resize(offset + 4)) {
throw std::out_of_range("Packet::PutInt32(), could not resize packet and would of written past the end.");
}
}
*(int32_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutInt64(size_t offset, int64_t value)
{
if (Length() < offset + 8) {
if (!Resize(offset + 8)) {
throw std::out_of_range("Packet::PutInt64(), could not resize packet and would of written past the end.");
}
}
*(int64_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt8(size_t offset, uint8_t value)
{
if (Length() < offset + 1) {
if (!Resize(offset + 1)) {
throw std::out_of_range("Packet::PutUInt8(), could not resize packet and would of written past the end.");
}
}
*(uint8_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt16(size_t offset, uint16_t value)
{
if (Length() < offset + 2) {
if (!Resize(offset + 2)) {
throw std::out_of_range("Packet::PutUInt16(), could not resize packet and would of written past the end.");
}
}
*(uint16_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt32(size_t offset, uint32_t value)
{
if (Length() < offset + 4) {
if (!Resize(offset + 4)) {
throw std::out_of_range("Packet::PutUInt32(), could not resize packet and would of written past the end.");
}
}
*(uint32_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutUInt64(size_t offset, uint64_t value)
{
if (Length() < offset + 8) {
if (!Resize(offset + 8)) {
throw std::out_of_range("Packet::PutUInt64(), could not resize packet and would of written past the end.");
}
}
*(uint64_t*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutFloat(size_t offset, float value)
{
if (Length() < offset + 4) {
if (!Resize(offset + 4)) {
throw std::out_of_range("Packet::PutFloat(), could not resize packet and would of written past the end.");
}
}
*(float*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutDouble(size_t offset, double value)
{
if (Length() < offset + 8) {
if (!Resize(offset + 8)) {
throw std::out_of_range("Packet::PutDouble(), could not resize packet and would of written past the end.");
}
}
*(double*)((char*)Data() + offset) = value;
}
void EQ::Net::Packet::PutString(size_t offset, const std::string &str)
{
if (Length() < offset + str.length()) {
if (!Resize(offset + str.length())) {
throw std::out_of_range("Packet::PutString(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), str.c_str(), str.length());
}
void EQ::Net::Packet::PutCString(size_t offset, const char *str)
{
size_t sz = strlen(str);
if (Length() < offset + sz + 1) {
if (!Resize(offset + sz + 1)) {
throw std::out_of_range("Packet::PutCString(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), str, sz);
*((char*)Data() + offset + sz) = 0;
}
void EQ::Net::Packet::PutPacket(size_t offset, const Packet &p)
{
if (p.Length() == 0) {
return;
}
if (Length() < offset + p.Length()) {
if (!Resize(offset + p.Length())) {
throw std::out_of_range("Packet::PutPacket(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), p.Data(), p.Length());
}
void EQ::Net::Packet::PutData(size_t offset, void *data, size_t length)
{
if (length == 0) {
return;
}
if (Length() < offset + length) {
if (!Resize(offset + length)) {
throw std::out_of_range("Packet::PutData(), could not resize packet and would of written past the end.");
}
}
memcpy(((char*)Data() + offset), data, length);
}
int8_t EQ::Net::Packet::GetInt8(size_t offset) const
{
if (Length() < offset + 1) {
throw std::out_of_range("Packet read out of range.");
}
return *(int8_t*)((char*)Data() + offset);
}
int16_t EQ::Net::Packet::GetInt16(size_t offset) const
{
if (Length() < offset + 2) {
throw std::out_of_range("Packet read out of range.");
}
return *(int16_t*)((char*)Data() + offset);
}
int32_t EQ::Net::Packet::GetInt32(size_t offset) const
{
if (Length() < offset + 4) {
throw std::out_of_range("Packet read out of range.");
}
return *(int32_t*)((char*)Data() + offset);
}
int64_t EQ::Net::Packet::GetInt64(size_t offset) const
{
if (Length() < offset + 8) {
throw std::out_of_range("Packet read out of range.");
}
return *(int64_t*)((char*)Data() + offset);
}
uint8_t EQ::Net::Packet::GetUInt8(size_t offset) const
{
if (Length() < offset + 1) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint8_t*)((char*)Data() + offset);
}
uint16_t EQ::Net::Packet::GetUInt16(size_t offset) const
{
if (Length() < offset + 2) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint16_t*)((char*)Data() + offset);
}
uint32_t EQ::Net::Packet::GetUInt32(size_t offset) const
{
if (Length() < offset + 4) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint32_t*)((char*)Data() + offset);
}
uint64_t EQ::Net::Packet::GetUInt64(size_t offset) const
{
if (Length() < offset + 8) {
throw std::out_of_range("Packet read out of range.");
}
return *(uint64_t*)((char*)Data() + offset);
}
float EQ::Net::Packet::GetFloat(size_t offset) const
{
if (Length() < offset + 4) {
throw std::out_of_range("Packet read out of range.");
}
return *(float*)((char*)Data() + offset);
}
double EQ::Net::Packet::GetDouble(size_t offset) const
{
if (Length() < offset + 8) {
throw std::out_of_range("Packet read out of range.");
}
return *(double*)((char*)Data() + offset);
}
std::string EQ::Net::Packet::GetString(size_t offset, size_t length) const
{
if (Length() < offset + length) {
throw std::out_of_range("Packet read out of range.");
}
return std::string((char*)Data() + offset, (char*)Data() + offset + length);
}
std::string EQ::Net::Packet::GetCString(size_t offset) const
{
if (Length() < offset + 1) {
throw std::out_of_range("Packet read out of range.");
}
char *str = ((char*)Data() + offset);
return std::string(str);
}
char ToSafePrint(unsigned char in) {
@@ -79,3 +342,13 @@ std::string EQ::Net::Packet::ToString(size_t line_length) const
return ret;
}
bool EQ::Net::StaticPacket::Resize(size_t new_size)
{
if (new_size > m_max_data_length) {
return false;
}
m_data_length = new_size;
return true;
}
+67 -691
View File
@@ -13,7 +13,8 @@ namespace EQ {
class Packet
{
public:
Packet() = default;
Packet() : m_stream(std::ios::out | std::ios::binary) { }
virtual ~Packet() { }
virtual const void *Data() const = 0;
virtual void *Data() = 0;
@@ -23,617 +24,6 @@ namespace EQ {
virtual bool Resize(size_t new_size) = 0;
virtual void Reserve(size_t new_size) = 0;
std::string ToString() const;
std::string ToString(size_t line_length) const;
void SetWritePos(size_t offset) { _wpos = offset; }
void SetReadPos(size_t offset) { _rpos = offset; }
//Position Independent Output Interface
void PutInt8(size_t offset, int8_t value) {
if (Length() < offset + sizeof(int8_t)) {
if (!Resize(offset + sizeof(int8_t))) {
throw std::out_of_range("Packet::PutInt8(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int8_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int8_t);
}
void PutInt16(size_t offset, int16_t value) {
if (Length() < offset + sizeof(int16_t)) {
if (!Resize(offset + sizeof(int16_t))) {
throw std::out_of_range("Packet::PutInt16(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int16_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int16_t);
}
void PutInt32(size_t offset, int32_t value) {
if (Length() < offset + sizeof(int32_t)) {
if (!Resize(offset + sizeof(int32_t))) {
throw std::out_of_range("Packet::PutInt32(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int32_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int32_t);
}
void PutInt64(size_t offset, int64_t value) {
if (Length() < offset + sizeof(int64_t)) {
if (!Resize(offset + sizeof(int64_t))) {
throw std::out_of_range("Packet::PutInt64(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<int64_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(int64_t);
}
void PutUInt8(size_t offset, uint8_t value) {
if (Length() < offset + sizeof(uint8_t)) {
if (!Resize(offset + sizeof(uint8_t))) {
throw std::out_of_range("Packet::PutUInt8(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint8_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint8_t);
}
void PutUInt16(size_t offset, uint16_t value) {
if (Length() < offset + sizeof(uint16_t)) {
if (!Resize(offset + sizeof(uint16_t))) {
throw std::out_of_range("Packet::PutUInt16(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint16_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint16_t);
}
void PutUInt32(size_t offset, uint32_t value) {
if (Length() < offset + sizeof(uint32_t)) {
if (!Resize(offset + sizeof(uint32_t))) {
throw std::out_of_range("Packet::PutUInt32(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint32_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint32_t);
}
void PutUInt64(size_t offset, uint64_t value) {
if (Length() < offset + sizeof(uint64_t)) {
if (!Resize(offset + sizeof(uint64_t))) {
throw std::out_of_range("Packet::PutUInt64(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<uint64_t*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(uint64_t);
}
void PutFloat(size_t offset, float value) {
if (Length() < offset + sizeof(float)) {
if (!Resize(offset + sizeof(float))) {
throw std::out_of_range("Packet::PutFloat(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<float*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(float);
}
void PutDouble(size_t offset, double value) {
if (Length() < offset + sizeof(double)) {
if (!Resize(offset + sizeof(double))) {
throw std::out_of_range("Packet::PutDouble(), could not resize packet and would of written past the end.");
}
}
*reinterpret_cast<double*>(static_cast<char*>(Data()) + offset) = value;
_wpos = offset + sizeof(double);
}
void PutString(size_t offset, const std::string &str) {
if (Length() < offset + str.length()) {
if (!Resize(offset + str.length())) {
throw std::out_of_range("Packet::PutString(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), str.c_str(), str.length());
_wpos = offset + str.length();
}
void PutCString(size_t offset, const char *str) {
size_t sz = strlen(str);
if (Length() < offset + sz + sizeof(int8_t)) {
if (!Resize(offset + sz + sizeof(int8_t))) {
throw std::out_of_range("Packet::PutCString(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), str, sz);
*(static_cast<char*>(Data()) + offset + sz) = 0;
_wpos = offset + sz + sizeof(int8_t);
}
void PutPacket(size_t offset, const Packet &p) {
if (p.Length() == 0) {
return;
}
if (Length() < offset + p.Length()) {
if (!Resize(offset + p.Length())) {
throw std::out_of_range("Packet::PutPacket(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), p.Data(), p.Length());
_wpos = offset + p.Length();
}
void PutData(size_t offset, void *data, size_t length) {
if (length == 0) {
return;
}
if (Length() < offset + length) {
if (!Resize(offset + length)) {
throw std::out_of_range("Packet::PutData(), could not resize packet and would of written past the end.");
}
}
std::memcpy((static_cast<char*>(Data()) + offset), data, length);
_wpos = offset + length;
}
//Position Dependent Output Interface
void PutInt8(int8_t value) {
PutInt8(_wpos, value);
}
void PutInt16(int16_t value) {
PutInt16(_wpos, value);
}
void PutInt32(int32_t value) {
PutInt32(_wpos, value);
}
void PutInt64(int64_t value) {
PutInt64(_wpos, value);
}
void PutUInt8(uint8_t value) {
PutUInt8(_wpos, value);
}
void PutUInt16(uint16_t value) {
PutUInt16(_wpos, value);
}
void PutUInt32(uint32_t value) {
PutUInt32(_wpos, value);
}
void PutUInt64(uint64_t value) {
PutUInt64(_wpos, value);
}
void PutFloat(float value) {
PutFloat(_wpos, value);
}
void PutDouble(double value) {
PutDouble(_wpos, value);
}
void PutString(const std::string &str) {
PutString(_wpos, str);
}
void PutCString(const char *str) {
PutCString(_wpos, str);
}
void PutPacket(const Packet &p) {
PutPacket(_wpos, p);
}
void PutData(void *data, size_t length) {
PutData(_wpos, data, length);
}
//Position Independent Input Interface
int8_t GetInt8(size_t offset) const {
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int8_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
int16_t GetInt16(size_t offset) const {
if (Length() < offset + sizeof(int16_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int16_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
int32_t GetInt32(size_t offset) const {
if (Length() < offset + sizeof(int32_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int32_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
int64_t GetInt64(size_t offset) const {
if (Length() < offset + sizeof(int64_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int64_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint8_t GetUInt8(size_t offset) const {
if (Length() < offset + sizeof(uint8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint8_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint16_t GetUInt16(size_t offset) const {
if (Length() < offset + sizeof(uint16_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint16_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint32_t GetUInt32(size_t offset) const {
if (Length() < offset + sizeof(uint32_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint32_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
uint64_t GetUInt64(size_t offset) const {
if (Length() < offset + sizeof(uint64_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const uint64_t*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
float GetFloat(size_t offset) const {
if (Length() < offset + sizeof(float)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const float*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
double GetDouble(size_t offset) const {
if (Length() < offset + sizeof(double)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const double*>(reinterpret_cast<const int8_t*>(Data()) + offset);
}
std::string GetString(size_t offset, size_t length) const {
if (Length() < offset + length) {
throw std::out_of_range("Packet read out of range.");
}
return std::string(reinterpret_cast<const int8_t*>(Data()) + offset, reinterpret_cast<const int8_t*>(Data()) + offset + length);
}
std::string GetCString(size_t offset) const {
if (Length() < offset) {
throw std::out_of_range("Packet read out of range.");
}
auto sz = strlen(static_cast<const char*>(Data()));
if (Length() < offset + sz + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
const char *str = reinterpret_cast<const char*>(reinterpret_cast<const int8_t*>(Data()) + offset);
return std::string(str);
}
//Position Dependent Input Interface
int8_t GetInt8() {
auto offset = _rpos;
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int8_t);
return *reinterpret_cast<int8_t*>(static_cast<char*>(Data()) + offset);
}
int16_t GetInt16() {
auto offset = _rpos;
if (Length() < offset + sizeof(int16_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int16_t);
return *reinterpret_cast<int16_t*>(static_cast<char*>(Data()) + offset);
}
int32_t GetInt32() {
auto offset = _rpos;
if (Length() < offset + sizeof(int32_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int32_t);
return *reinterpret_cast<int32_t*>(static_cast<char*>(Data()) + offset);
}
int64_t GetInt64() {
auto offset = _rpos;
if (Length() < offset + sizeof(int64_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(int64_t);
return *reinterpret_cast<int64_t*>(static_cast<char*>(Data()) + offset);
}
uint8_t GetUInt8() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint8_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint8_t);
return *reinterpret_cast<uint8_t*>(static_cast<char*>(Data()) + offset);
}
uint16_t GetUInt16() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint16_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint16_t);
return *reinterpret_cast<uint16_t*>(static_cast<char*>(Data()) + offset);
}
uint32_t GetUInt32() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint32_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint32_t);
return *reinterpret_cast<uint32_t*>(static_cast<char*>(Data()) + offset);
}
uint64_t GetUInt64() {
auto offset = _rpos;
if (Length() < offset + sizeof(uint64_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(uint64_t);
return *reinterpret_cast<uint64_t*>(static_cast<char*>(Data()) + offset);
}
float GetFloat() {
auto offset = _rpos;
if (Length() < offset + sizeof(float)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(float);
return *reinterpret_cast<float*>(static_cast<char*>(Data()) + offset);
}
double GetDouble() {
auto offset = _rpos;
if (Length() < offset + sizeof(double)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sizeof(double);
return *reinterpret_cast<double*>(static_cast<char*>(Data()) + offset);
}
std::string GetString(size_t length) {
auto offset = _rpos;
if (Length() < offset + length) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + length;
return std::string(static_cast<char*>(Data()) + offset, static_cast<char*>(Data()) + offset + length);
}
std::string GetCString() {
auto offset = _rpos;
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
auto sz = strlen(static_cast<const char*>(Data()));
if (Length() < offset + sz + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
_rpos = offset + sz + sizeof(int8_t);
char *str = (static_cast<char*>(Data()) + offset);
return std::string(str);
}
int8_t& operator[](size_t offset) {
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<int8_t*>(static_cast<char*>(Data()) + offset);
}
const int8_t& operator[](size_t offset) const {
if (Length() < offset + sizeof(int8_t)) {
throw std::out_of_range("Packet read out of range.");
}
return *reinterpret_cast<const int8_t*>(static_cast<const char*>(Data()) + offset);
}
//Stream Output Interface
Packet &operator<<(int8_t v) {
PutInt8(v);
return *this;
}
Packet &operator<<(int16_t v) {
PutInt16(v);
return *this;
}
Packet &operator<<(int32_t v) {
PutInt32(v);
return *this;
}
Packet &operator<<(int64_t v) {
PutInt64(v);
return *this;
}
Packet &operator<<(uint8_t v) {
PutUInt8(v);
return *this;
}
Packet &operator<<(uint16_t v) {
PutUInt16(v);
return *this;
}
Packet &operator<<(uint32_t v) {
PutUInt32(v);
return *this;
}
Packet &operator<<(uint64_t v) {
PutUInt64(v);
return *this;
}
Packet &operator<<(float v) {
PutFloat(v);
return *this;
}
Packet &operator<<(double v) {
PutDouble(v);
return *this;
}
Packet &operator<<(const std::string &v) {
PutString(v.data());
return *this;
}
Packet &operator<<(const char *v) {
PutCString(v);
return *this;
}
Packet &operator<<(const Packet &v) {
PutPacket(v);
return *this;
}
//Stream Input Interface
Packet &operator>>(int8_t &v) {
v = GetInt8();
return *this;
}
Packet &operator>>(int16_t &v) {
v = GetInt16();
return *this;
}
Packet &operator>>(int32_t &v) {
v = GetInt32();
return *this;
}
Packet &operator>>(int64_t &v) {
v = GetInt64();
return *this;
}
Packet &operator>>(uint8_t &v) {
v = GetUInt8();
return *this;
}
Packet &operator>>(uint16_t &v) {
v = GetUInt16();
return *this;
}
Packet &operator>>(uint32_t &v) {
v = GetUInt32();
return *this;
}
Packet &operator>>(uint64_t &v) {
v = GetUInt64();
return *this;
}
Packet &operator>>(float &v) {
v = GetFloat();
return *this;
}
Packet &operator>>(double &v) {
v = GetDouble();
return *this;
}
Packet &operator>>(std::string &v) {
v = GetCString();
return *this;
}
// Seriliazation
template<typename T>
T GetSerialize(size_t offset) const
{
@@ -646,12 +36,11 @@ namespace EQ {
template<typename T>
void PutSerialize(size_t offset, const T &value) {
std::stringstream stream;
cereal::BinaryOutputArchive output(stream);
m_stream.clear();
cereal::BinaryOutputArchive output(m_stream);
output(value);
auto str = stream.str();
auto str = m_stream.str();
if (Length() < offset + str.length()) {
if (!Resize(offset + str.length())) {
throw std::out_of_range("Packet::PutSerialize(), could not resize packet and would of written past the end.");
@@ -660,95 +49,82 @@ namespace EQ {
memcpy((char*)Data() + offset, &str[0], str.length());
}
void PutInt8(size_t offset, int8_t value);
void PutInt16(size_t offset, int16_t value);
void PutInt32(size_t offset, int32_t value);
void PutInt64(size_t offset, int64_t value);
void PutUInt8(size_t offset, uint8_t value);
void PutUInt16(size_t offset, uint16_t value);
void PutUInt32(size_t offset, uint32_t value);
void PutUInt64(size_t offset, uint64_t value);
void PutFloat(size_t offset, float value);
void PutDouble(size_t offset, double value);
void PutString(size_t offset, const std::string &str);
void PutCString(size_t offset, const char *str);
void PutPacket(size_t offset, const Packet &p);
void PutData(size_t offset, void *data, size_t length);
int8_t GetInt8(size_t offset) const;
int16_t GetInt16(size_t offset) const;
int32_t GetInt32(size_t offset) const;
int64_t GetInt64(size_t offset) const;
uint8_t GetUInt8(size_t offset) const;
uint16_t GetUInt16(size_t offset) const;
uint32_t GetUInt32(size_t offset) const;
uint64_t GetUInt64(size_t offset) const;
float GetFloat(size_t offset) const;
double GetDouble(size_t offset) const;
std::string GetString(size_t offset, size_t length) const;
std::string GetCString(size_t offset) const;
std::string ToString() const;
std::string ToString(size_t line_length) const;
protected:
size_t _rpos{ 0 };
size_t _wpos{ 0 };
std::stringstream m_stream;
};
class StaticPacket : public Packet
{
public:
StaticPacket(void *data, size_t len) : _data(data), _len(len), _max_len(len) {
}
StaticPacket(void *data, size_t size) { m_data = data; m_data_length = size; m_max_data_length = size; }
virtual ~StaticPacket() { }
StaticPacket(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; }
StaticPacket& operator=(const StaticPacket &o) { m_data = o.m_data; m_data_length = o.m_data_length; return *this; }
StaticPacket(StaticPacket &&o) { m_data = o.m_data; m_data_length = o.m_data_length; }
StaticPacket(const StaticPacket &o) : _data(o._data), _len(o._len), _max_len(o._max_len) {
_rpos = o._rpos;
_wpos = o._wpos;
}
StaticPacket& operator=(const StaticPacket& o) {
_data = o._data;
_len = o._len;
_max_len = o._max_len;
_rpos = o._rpos;
_wpos = o._wpos;
return *this;
}
StaticPacket(StaticPacket &&o) noexcept : _data(o._data), _len(o._len), _max_len(o._max_len) {
_rpos = o._rpos;
_wpos = o._wpos;
}
const void *Data() const override { return _data; }
void *Data() override { return _data; }
size_t Length() const override { return _len; }
size_t Length() override { return _len; }
bool Clear() override { return false; }
bool Resize(size_t new_size) override;
void Reserve(size_t new_size) override { }
virtual const void *Data() const { return m_data; }
virtual void *Data() { return m_data; }
virtual size_t Length() const { return m_data_length; }
virtual size_t Length() { return m_data_length; }
virtual bool Clear() { return false; }
virtual bool Resize(size_t new_size);
virtual void Reserve(size_t new_size) { }
protected:
void *_data;
size_t _len;
size_t _max_len;
void *m_data;
size_t m_data_length;
size_t m_max_data_length;
};
class DynamicPacket : public Packet
{
public:
const static size_t DefaultSize = 4096;
DynamicPacket() {
_data.reserve(DefaultSize);
}
DynamicPacket(size_t size) {
_data.reserve(size);
}
DynamicPacket(const DynamicPacket& o) : _data(o._data) {
_rpos = o._rpos;
_wpos = o._wpos;
}
DynamicPacket& operator=(const DynamicPacket& o) {
_data = o._data;
_rpos = o._rpos;
_wpos = o._wpos;
}
DynamicPacket(DynamicPacket &&o) noexcept : _data(o.MoveData()) {
_rpos = o._rpos;
_wpos = o._wpos;
}
std::vector<int8_t>&& MoveData() {
_rpos = 0;
_wpos = 0;
return std::move(_data);
}
const void *Data() const override { return _data.data(); }
void *Data() override { return _data.data(); }
size_t Length() const override { return _data.size(); }
size_t Length() override { return _data.size(); }
bool Clear() override { _data.clear(); return true; }
bool Resize(size_t new_size) override { _data.resize(new_size); return true; }
void Reserve(size_t new_size) override { _data.reserve(new_size); }
DynamicPacket() { }
virtual ~DynamicPacket() { }
DynamicPacket(DynamicPacket &&o) { m_data = std::move(o.m_data); }
DynamicPacket(const DynamicPacket &o) { m_data = o.m_data; }
DynamicPacket& operator=(const DynamicPacket &o) { m_data = o.m_data; return *this; }
virtual const void *Data() const { return &m_data[0]; }
virtual void *Data() { return &m_data[0]; }
virtual size_t Length() const { return m_data.size(); }
virtual size_t Length() { return m_data.size(); }
virtual bool Clear() { m_data.clear(); return true; }
virtual bool Resize(size_t new_size) { m_data.resize(new_size, 0); return true; }
virtual void Reserve(size_t new_size) { m_data.reserve(new_size); }
protected:
std::vector<int8_t> _data;
std::vector<char> m_data;
};
} // namespace Net
} // namespace EQ
}
}
+8 -4
View File
@@ -15,7 +15,7 @@ EQ::Net::TCPConnection::~TCPConnection() {
Disconnect();
}
void EQ::Net::TCPConnection::Connect(const std::string &addr, int port, bool ipv6, std::function<void(std::shared_ptr<TCPConnection>)> cb)
void EQ::Net::TCPConnection::Connect(EQ::EventLoop *loop, const std::string & addr, int port, bool ipv6, std::function<void(std::shared_ptr<TCPConnection>)> cb)
{
struct EQTCPConnectBaton
{
@@ -23,10 +23,9 @@ void EQ::Net::TCPConnection::Connect(const std::string &addr, int port, bool ipv
std::function<void(std::shared_ptr<EQ::Net::TCPConnection>)> cb;
};
auto loop = EQ::EventLoop::GetDefault().Handle();
uv_tcp_t *socket = new uv_tcp_t;
memset(socket, 0, sizeof(uv_tcp_t));
uv_tcp_init(loop, socket);
uv_tcp_init(loop->Handle(), socket);
sockaddr_storage iaddr;
if (ipv6) {
@@ -64,6 +63,11 @@ void EQ::Net::TCPConnection::Connect(const std::string &addr, int port, bool ipv
});
}
void EQ::Net::TCPConnection::Connect(const std::string &addr, int port, bool ipv6, std::function<void(std::shared_ptr<TCPConnection>)> cb)
{
Connect(&EventLoop::GetDefault(), addr, port, ipv6, cb);
}
void EQ::Net::TCPConnection::Start() {
uv_read_start((uv_stream_t*)m_socket, [](uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
buf->base = new char[suggested_size];
@@ -142,7 +146,7 @@ void EQ::Net::TCPConnection::Write(const char *data, size_t count)
WriteBaton *baton = new WriteBaton;
baton->connection = this;
baton->buffer = new char[count];
baton->buffer = new char[count];;
uv_write_t *write_req = new uv_write_t;
memset(write_req, 0, sizeof(uv_write_t));
+2
View File
@@ -7,6 +7,7 @@
namespace EQ
{
class EventLoop;
namespace Net
{
class TCPConnection
@@ -15,6 +16,7 @@ namespace EQ
TCPConnection(uv_tcp_t *socket);
~TCPConnection();
static void Connect(EQ::EventLoop *loop, const std::string &addr, int port, bool ipv6, std::function<void(std::shared_ptr<TCPConnection>)> cb);
static void Connect(const std::string &addr, int port, bool ipv6, std::function<void(std::shared_ptr<TCPConnection>)> cb);
void Start();
+9 -2
View File
@@ -7,6 +7,13 @@ void on_close_tcp_server_handle(uv_handle_t* handle) {
EQ::Net::TCPServer::TCPServer()
{
m_loop = &EventLoop::GetDefault();
m_socket = nullptr;
}
EQ::Net::TCPServer::TCPServer(EQ::EventLoop *loop)
{
m_loop = loop;
m_socket = nullptr;
}
@@ -32,7 +39,7 @@ void EQ::Net::TCPServer::Listen(const std::string &addr, int port, bool ipv6, st
m_on_new_connection = cb;
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = m_loop->Handle();
m_socket = new uv_tcp_t;
memset(m_socket, 0, sizeof(uv_tcp_t));
uv_tcp_init(loop, m_socket);
@@ -53,7 +60,7 @@ void EQ::Net::TCPServer::Listen(const std::string &addr, int port, bool ipv6, st
return;
}
auto loop = EQ::EventLoop::GetDefault().Handle();
auto loop = server->loop;
uv_tcp_t *client = new uv_tcp_t;
memset(client, 0, sizeof(uv_tcp_t));
uv_tcp_init(loop, client);
+4 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "tcp_connection.h"
#include "../event/event_loop.h"
namespace EQ
{
@@ -10,6 +11,7 @@ namespace EQ
{
public:
TCPServer();
TCPServer(EQ::EventLoop *loop);
~TCPServer();
void Listen(int port, bool ipv6, std::function<void(std::shared_ptr<TCPConnection>)> cb);
@@ -19,7 +21,8 @@ namespace EQ
private:
std::function<void(std::shared_ptr<TCPConnection>)> m_on_new_connection;
EQ::EventLoop *m_loop;
uv_tcp_t *m_socket;
};
}
}
}
-265
View File
@@ -1,265 +0,0 @@
#include "websocket_server.h"
#include "../event/event_loop.h"
#include "../event/timer.h"
#include <fmt/format.h>
#include <map>
#include <unordered_set>
#include <array>
struct MethodHandlerEntry
{
MethodHandlerEntry() {
status = 0;
}
MethodHandlerEntry(EQ::Net::WebsocketServer::MethodHandler h, int s) {
handler = h;
status = s;
}
EQ::Net::WebsocketServer::MethodHandler handler;
int status;
};
struct EQ::Net::WebsocketServer::Impl
{
std::unique_ptr<TCPServer> server;
std::unique_ptr<EQ::Timer> ping_timer;
std::map<std::shared_ptr<websocket_connection>, std::unique_ptr<WebsocketServerConnection>> connections;
std::map<std::string, MethodHandlerEntry> methods;
websocket_server ws_server;
LoginHandler login_handler;
std::array<std::unordered_set<WebsocketServerConnection*>, SubscriptionEventMax> subscriptions;
};
EQ::Net::WebsocketServer::WebsocketServer(const std::string &addr, int port)
{
_impl.reset(new Impl());
_impl->server.reset(new EQ::Net::TCPServer());
_impl->server->Listen(addr, port, false, [this](std::shared_ptr<EQ::Net::TCPConnection> connection) {
auto wsc = _impl->ws_server.get_connection();
WebsocketServerConnection *c = new WebsocketServerConnection(this, connection, wsc);
_impl->connections.insert(std::make_pair(wsc, std::unique_ptr<WebsocketServerConnection>(c)));
});
_impl->ws_server.set_write_handler(
[this](websocketpp::connection_hdl hdl, char const *data, size_t size) -> websocketpp::lib::error_code {
auto c = _impl->ws_server.get_con_from_hdl(hdl);
auto iter = _impl->connections.find(c);
if (iter != _impl->connections.end()) {
iter->second->GetTCPConnection()->Write(data, size);
}
return websocketpp::lib::error_code();
});
_impl->ping_timer.reset(new EQ::Timer(5000, true, [this](EQ::Timer *t) {
auto iter = _impl->connections.begin();
while (iter != _impl->connections.end()) {
try {
auto &connection = iter->second;
connection->GetWebsocketConnection()->ping("keepalive");
}
catch (std::exception) {
iter->second->GetTCPConnection()->Disconnect();
}
iter++;
}
}));
_impl->methods.insert(std::make_pair("login", MethodHandlerEntry(std::bind(&WebsocketServer::Login, this, std::placeholders::_1, std::placeholders::_2), 0)));
_impl->methods.insert(std::make_pair("subscribe", MethodHandlerEntry(std::bind(&WebsocketServer::Subscribe, this, std::placeholders::_1, std::placeholders::_2), 0)));
_impl->methods.insert(std::make_pair("unsubscribe", MethodHandlerEntry(std::bind(&WebsocketServer::Unsubscribe, this, std::placeholders::_1, std::placeholders::_2), 0)));
_impl->login_handler = [](const WebsocketServerConnection* connection, const std::string& user, const std::string& pass) {
WebsocketLoginStatus ret;
ret.account_name = "admin";
if (connection->RemoteIP() == "127.0.0.1" || connection->RemoteIP() == "::") {
ret.logged_in = true;
return ret;
}
ret.logged_in = false;
return ret;
};
_impl->ws_server.clear_access_channels(websocketpp::log::alevel::all);
}
EQ::Net::WebsocketServer::~WebsocketServer()
{
}
void EQ::Net::WebsocketServer::ReleaseConnection(WebsocketServerConnection *connection)
{
UnsubscribeAll(connection);
_impl->connections.erase(connection->GetWebsocketConnection());
}
Json::Value EQ::Net::WebsocketServer::HandleRequest(WebsocketServerConnection *connection, const std::string &method, const Json::Value &params)
{
Json::Value err;
if (method != "login") {
if (!connection->IsAuthorized()) {
throw WebsocketException("Not logged in");
}
}
auto iter = _impl->methods.find(method);
if (iter != _impl->methods.end()) {
auto &s = iter->second;
if (s.status > connection->GetStatus()) {
throw WebsocketException("Status too low");
}
return s.handler(connection, params);
}
throw WebsocketException("Unknown Method");
}
void EQ::Net::WebsocketServer::SetMethodHandler(const std::string &method, MethodHandler handler, int required_status)
{
//Reserved method names
if (method == "subscribe" ||
method == "unsubscribe" ||
method == "login") {
return;
}
_impl->methods[method] = MethodHandlerEntry(handler, required_status);
}
void EQ::Net::WebsocketServer::SetLoginHandler(LoginHandler handler)
{
_impl->login_handler = handler;
}
void EQ::Net::WebsocketServer::DispatchEvent(WebsocketSubscriptionEvent evt, Json::Value data, int required_status)
{
try {
Json::Value event_obj;
event_obj["type"] = "event";
event_obj["event"] = (int)evt;
event_obj["data"] = data;
std::stringstream payload;
payload << event_obj;
for (auto &iter : _impl->connections) {
auto &c = iter.second;
if (c->GetStatus() >= required_status && IsSubscribed(c.get(), evt)) {
c->GetWebsocketConnection()->send(payload.str());
}
}
}
catch (std::exception) {
}
}
Json::Value EQ::Net::WebsocketServer::Login(WebsocketServerConnection *connection, const Json::Value &params)
{
Json::Value ret;
try {
Json::Value ret;
auto user = params[0].asString();
auto pass = params[1].asString();
auto r = _impl->login_handler(connection, user, pass);
if (r.logged_in) {
connection->SetAuthorized(true, r.account_name, r.account_id, 255);
ret["status"] = "Ok";
}
else if (user == "admin" && (connection->RemoteIP() == "127.0.0.1" || connection->RemoteIP() == "::")) {
r.logged_in = true;
r.account_id = 0;
connection->SetAuthorized(true, r.account_name, r.account_id, 255);
ret["status"] = "Ok";
}
else {
connection->SetAuthorized(false, "", 0, 0);
ret["status"] = "Not Authorized";
}
return ret;
}
catch (std::exception) {
throw WebsocketException("Unable to process login request");
}
}
Json::Value EQ::Net::WebsocketServer::Subscribe(WebsocketServerConnection *connection, const Json::Value &params)
{
Json::Value ret;
try {
auto evt = params[0].asInt();
if (evt < 0 || evt >= SubscriptionEventMax) {
throw WebsocketException("Not a valid subscription");
}
DoSubscribe(connection, (WebsocketSubscriptionEvent)evt);
ret["status"] = "Ok";
return ret;
}
catch (WebsocketException &ex) {
throw ex;
}
catch (std::exception) {
throw WebsocketException("Unable to process unsubscribe request");
}
}
Json::Value EQ::Net::WebsocketServer::Unsubscribe(WebsocketServerConnection *connection, const Json::Value &params)
{
Json::Value ret;
try {
auto evt = params[0].asInt();
if (evt < 0 || evt >= SubscriptionEventMax) {
throw WebsocketException("Not a valid subscription");
}
DoUnsubscribe(connection, (WebsocketSubscriptionEvent)evt);
ret["status"] = "Ok";
return ret;
}
catch (WebsocketException &ex) {
throw ex;
}
catch (std::exception) {
throw WebsocketException("Unable to process unsubscribe request");
}
}
void EQ::Net::WebsocketServer::DoSubscribe(WebsocketServerConnection *connection, WebsocketSubscriptionEvent sub) {
auto &s = _impl->subscriptions[sub];
auto iter = s.find(connection);
if (iter == s.end()) {
s.insert(connection);
}
}
void EQ::Net::WebsocketServer::DoUnsubscribe(WebsocketServerConnection *connection, WebsocketSubscriptionEvent sub) {
auto &s = _impl->subscriptions[sub];
s.erase(connection);
}
bool EQ::Net::WebsocketServer::IsSubscribed(WebsocketServerConnection *connection, WebsocketSubscriptionEvent sub) {
auto &s = _impl->subscriptions[sub];
return s.count(connection) == 1;
}
void EQ::Net::WebsocketServer::UnsubscribeAll(WebsocketServerConnection *connection) {
for (auto i = 0; i < SubscriptionEventMax; ++i) {
DoUnsubscribe(connection, (WebsocketSubscriptionEvent)i);
}
}
-74
View File
@@ -1,74 +0,0 @@
#pragma once
#include "websocket_server_connection.h"
#include "../json/json.h"
#include <memory>
#include <functional>
#include <exception>
namespace EQ
{
namespace Net
{
enum WebsocketSubscriptionEvent : int
{
SubscriptionEventNone,
SubscriptionEventLog,
SubscriptionEventMax
};
struct WebsocketLoginStatus
{
bool logged_in;
std::string account_name;
uint32 account_id;
int status;
};
class WebsocketException : public std::exception
{
public:
WebsocketException(const std::string &msg)
: _msg(msg.empty() ? "Unknown Error" : msg) { }
~WebsocketException() throw() {}
virtual char const *what() const throw() {
return _msg.c_str();
}
private:
const std::string _msg;
};
class WebsocketServer
{
public:
typedef std::function<Json::Value(WebsocketServerConnection*, const Json::Value&)> MethodHandler;
typedef std::function<WebsocketLoginStatus(WebsocketServerConnection*, const std::string&, const std::string&)> LoginHandler;
WebsocketServer(const std::string &addr, int port);
~WebsocketServer();
void SetMethodHandler(const std::string& method, MethodHandler handler, int required_status);
void SetLoginHandler(LoginHandler handler);
void DispatchEvent(WebsocketSubscriptionEvent evt, Json::Value data = Json::Value(), int required_status = 0);
private:
void ReleaseConnection(WebsocketServerConnection *connection);
Json::Value HandleRequest(WebsocketServerConnection *connection, const std::string& method, const Json::Value &params);
Json::Value Login(WebsocketServerConnection *connection, const Json::Value &params);
Json::Value Subscribe(WebsocketServerConnection *connection, const Json::Value &params);
Json::Value Unsubscribe(WebsocketServerConnection *connection, const Json::Value &params);
void DoSubscribe(WebsocketServerConnection *connection, WebsocketSubscriptionEvent sub);
void DoUnsubscribe(WebsocketServerConnection *connection, WebsocketSubscriptionEvent sub);
bool IsSubscribed(WebsocketServerConnection *connection, WebsocketSubscriptionEvent sub);
void UnsubscribeAll(WebsocketServerConnection *connection);
struct Impl;
std::unique_ptr<Impl> _impl;
friend class WebsocketServerConnection;
};
}
}
-153
View File
@@ -1,153 +0,0 @@
#include "websocket_server_connection.h"
#include "websocket_server.h"
#include "../timer.h"
#include "../util/uuid.h"
#include <sstream>
#include <fmt/format.h>
struct EQ::Net::WebsocketServerConnection::Impl {
WebsocketServer *parent;
std::shared_ptr<TCPConnection> connection;
std::shared_ptr<websocket_connection> ws_connection;
std::string id;
bool authorized;
std::string account_name;
uint32 account_id;
int status;
};
EQ::Net::WebsocketServerConnection::WebsocketServerConnection(WebsocketServer *parent,
std::shared_ptr<TCPConnection> connection,
std::shared_ptr<websocket_connection> ws_connection)
{
_impl.reset(new Impl());
_impl->parent = parent;
_impl->connection = connection;
_impl->id = EQ::Util::UUID::Generate().ToString();
_impl->authorized = false;
_impl->account_id = 0;
_impl->status = 0;
_impl->ws_connection = ws_connection;
_impl->ws_connection->set_message_handler(std::bind(&WebsocketServerConnection::OnMessage, this, std::placeholders::_1, std::placeholders::_2));
_impl->ws_connection->start();
connection->OnDisconnect([this](EQ::Net::TCPConnection *connection) {
_impl->parent->ReleaseConnection(this);
});
connection->OnRead([this](EQ::Net::TCPConnection *c, const unsigned char *buffer, size_t buffer_size) {
_impl->ws_connection->read_all((const char*)buffer, buffer_size);
});
connection->Start();
}
EQ::Net::WebsocketServerConnection::~WebsocketServerConnection()
{
}
std::string EQ::Net::WebsocketServerConnection::GetID() const
{
return _impl->id;
}
bool EQ::Net::WebsocketServerConnection::IsAuthorized() const
{
return _impl->authorized;
}
std::string EQ::Net::WebsocketServerConnection::GetAccountName() const
{
return _impl->account_name;
}
uint32 EQ::Net::WebsocketServerConnection::GetAccountID() const
{
return _impl->account_id;
}
int EQ::Net::WebsocketServerConnection::GetStatus() const
{
return _impl->status;
}
std::string EQ::Net::WebsocketServerConnection::RemoteIP() const
{
return _impl->connection->RemoteIP();
}
int EQ::Net::WebsocketServerConnection::RemotePort() const
{
return _impl->connection->RemotePort();
}
std::shared_ptr<EQ::Net::websocket_connection> EQ::Net::WebsocketServerConnection::GetWebsocketConnection()
{
return _impl->ws_connection;
}
std::shared_ptr<EQ::Net::TCPConnection> EQ::Net::WebsocketServerConnection::GetTCPConnection()
{
return _impl->connection;
}
void EQ::Net::WebsocketServerConnection::OnMessage(websocketpp::connection_hdl hdl, websocket_message_ptr msg)
{
BenchTimer timer;
timer.reset();
if (msg->get_opcode() == websocketpp::frame::opcode::text) {
try {
auto &payload = msg->get_payload();
std::stringstream ss(payload);
Json::Value root;
ss >> root;
auto method = root["method"].asString();
auto params = root["params"];
std::string id = "";
auto idNode = root["id"];
if (!idNode.isNull() && idNode.isString()) {
id = idNode.asString();
}
Json::Value response;
response["type"] = "method";
response["data"] = _impl->parent->HandleRequest(this, method, params);
response["method"] = method;
if(id != "") {
response["id"] = id;
}
SendResponse(response, timer.elapsed());
}
catch (std::exception &ex) {
Json::Value error;
error["type"] = "method";
error["error"] = fmt::format("{0}", ex.what());
SendResponse(error, timer.elapsed());
}
}
}
void EQ::Net::WebsocketServerConnection::SendResponse(const Json::Value &response, double time_elapsed)
{
Json::Value root = response;
root["execution_time"] = std::to_string(time_elapsed);
std::stringstream payload;
payload << root;
_impl->ws_connection->send(payload.str());
}
void EQ::Net::WebsocketServerConnection::SetAuthorized(bool v, const std::string account_name, uint32 account_id, int status)
{
_impl->authorized = v;
_impl->account_name = account_name;
_impl->account_id = account_id;
_impl->status = status;
}
-46
View File
@@ -1,46 +0,0 @@
#pragma once
#include "tcp_server.h"
#include "../types.h"
#include "../json/json-forwards.h"
#include <websocketpp/config/core.hpp>
#include <websocketpp/server.hpp>
namespace EQ
{
namespace Net
{
typedef websocketpp::server<websocketpp::config::core> websocket_server;
typedef websocketpp::connection<websocketpp::config::core> websocket_connection;
typedef websocket_server::message_ptr websocket_message_ptr;
class WebsocketServer;
class WebsocketServerConnection
{
public:
WebsocketServerConnection(WebsocketServer *parent,
std::shared_ptr<TCPConnection> connection,
std::shared_ptr<websocket_connection> ws_connection);
~WebsocketServerConnection();
std::string GetID() const;
bool IsAuthorized() const;
std::string GetAccountName() const;
uint32 GetAccountID() const;
int GetStatus() const;
std::string RemoteIP() const;
int RemotePort() const;
private:
std::shared_ptr<websocket_connection> GetWebsocketConnection();
std::shared_ptr<TCPConnection> GetTCPConnection();
void OnMessage(websocketpp::connection_hdl hdl, websocket_message_ptr msg);
void SendResponse(const Json::Value &response, double time_elapsed);
void SetAuthorized(bool v, const std::string account_name, uint32 account_id, int status);
struct Impl;
std::unique_ptr<Impl> _impl;
friend class WebsocketServer;
};
}
}
+1 -2
View File
@@ -16,7 +16,6 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "eqemu_logsys.h"
#include "emu_opcodes.h"
#include "opcodemgr.h"
@@ -32,7 +31,7 @@ OpcodeManager::OpcodeManager() {
bool OpcodeManager::LoadOpcodesFile(const char *filename, OpcodeSetStrategy *s, bool report_errors) {
FILE *opf = fopen(filename, "r");
if(opf == nullptr) {
Log(Logs::General, Logs::Error, "Unable to open opcodes file '%s'", filename);
fprintf(stderr, "Unable to open opcodes file '%s'. Thats bad.\n", filename);
return(false);
}
+1 -1
View File
@@ -29,7 +29,7 @@
//#endif
#include <string.h>
#ifdef _WIN32
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
+1 -1
View File
@@ -23,7 +23,7 @@
#include "packet_dump.h"
#include "packet_functions.h"
#ifndef _WIN32
#ifndef WIN32
#include <netinet/in.h>
#endif
+33 -21
View File
@@ -3199,35 +3199,47 @@ namespace RoF
EQApplicationPacket *in = *p;
*p = nullptr;
SerializeBuffer buf(in->size);
buf.WriteInt8(in->ReadUInt8()); // speak mode
buf.WriteInt8(in->ReadUInt8()); // journal mode
buf.WriteInt8(in->ReadUInt8()); // language
buf.WriteInt32(in->ReadUInt32()); // message type
buf.WriteInt32(in->ReadUInt32()); // target spawn id
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
std::string name;
in->ReadString(name); // NPC names max out at 63 chars
unsigned char *__emu_buffer = in->pBuffer;
buf.WriteString(name);
buf.WriteInt32(in->ReadUInt32()); // loc
buf.WriteInt32(in->ReadUInt32());
buf.WriteInt32(in->ReadUInt32());
std::string old_message;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
in->ReadString(old_message);
ServerToRoFSayLink(new_message, old_message);
buf.WriteString(new_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = strlen(emu->sayer) + new_message.length() + 25;
in->pBuffer = new unsigned char[in->size];
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
char *OutBuffer = (char *)in->pBuffer;
dest->FastQueuePacket(&outapp, ack_req);
delete in;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[2]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[3]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[4]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[5]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[6]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[7]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[8]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[9]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[10]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[11]);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_Stun)
+33 -21
View File
@@ -3266,35 +3266,47 @@ namespace RoF2
EQApplicationPacket *in = *p;
*p = nullptr;
SerializeBuffer buf(in->size);
buf.WriteInt8(in->ReadUInt8()); // speak mode
buf.WriteInt8(in->ReadUInt8()); // journal mode
buf.WriteInt8(in->ReadUInt8()); // language
buf.WriteInt32(in->ReadUInt32()); // message type
buf.WriteInt32(in->ReadUInt32()); // target spawn id
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
std::string name;
in->ReadString(name); // NPC names max out at 63 chars
unsigned char *__emu_buffer = in->pBuffer;
buf.WriteString(name);
buf.WriteInt32(in->ReadUInt32()); // loc
buf.WriteInt32(in->ReadUInt32());
buf.WriteInt32(in->ReadUInt32());
std::string old_message;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
in->ReadString(old_message);
ServerToRoF2SayLink(new_message, old_message);
buf.WriteString(new_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = strlen(emu->sayer) + new_message.length() + 25;
in->pBuffer = new unsigned char[in->size];
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
char *OutBuffer = (char *)in->pBuffer;
dest->FastQueuePacket(&outapp, ack_req);
delete in;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[2]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[3]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[4]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[5]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[6]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[7]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[8]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[9]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[10]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[11]);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_Stun)
+33 -21
View File
@@ -2069,35 +2069,47 @@ namespace SoD
EQApplicationPacket *in = *p;
*p = nullptr;
SerializeBuffer buf(in->size);
buf.WriteInt8(in->ReadUInt8()); // speak mode
buf.WriteInt8(in->ReadUInt8()); // journal mode
buf.WriteInt8(in->ReadUInt8()); // language
buf.WriteInt32(in->ReadUInt32()); // message type
buf.WriteInt32(in->ReadUInt32()); // target spawn id
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
std::string name;
in->ReadString(name); // NPC names max out at 63 chars
unsigned char *__emu_buffer = in->pBuffer;
buf.WriteString(name);
buf.WriteInt32(in->ReadUInt32()); // loc
buf.WriteInt32(in->ReadUInt32());
buf.WriteInt32(in->ReadUInt32());
std::string old_message;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
in->ReadString(old_message);
ServerToSoDSayLink(new_message, old_message);
buf.WriteString(new_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = strlen(emu->sayer) + new_message.length() + 25;
in->pBuffer = new unsigned char[in->size];
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
char *OutBuffer = (char *)in->pBuffer;
dest->FastQueuePacket(&outapp, ack_req);
delete in;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[2]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[3]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[4]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[5]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[6]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[7]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[8]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[9]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[10]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[11]);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_Stun)
+33 -27
View File
@@ -1116,10 +1116,7 @@ namespace SoF
}
OUT(deity);
OUT(intoxication);
OUT_array(spellSlotRefresh, spells::SPELL_GEM_COUNT);
eq->spellSlotRefresh[9] = 0; // 10th slot is not valid in this release
OUT(abilitySlotRefresh);
OUT(points); // Relocation Test
// OUT(unknown0166[4]);
@@ -1180,10 +1177,7 @@ namespace SoF
}
// OUT(unknown4184[128]);
OUT_array(mem_spells, spells::SPELL_GEM_COUNT);
eq->mem_spells[9] = 0xFFFFFFFFU; // 10th slot is not valid in this release
// OUT(unknown04396[32]);
OUT(platinum);
OUT(gold);
@@ -1726,35 +1720,47 @@ namespace SoF
EQApplicationPacket *in = *p;
*p = nullptr;
SerializeBuffer buf(in->size);
buf.WriteInt8(in->ReadUInt8()); // speak mode
buf.WriteInt8(in->ReadUInt8()); // journal mode
buf.WriteInt8(in->ReadUInt8()); // language
buf.WriteInt32(in->ReadUInt32()); // message type
buf.WriteInt32(in->ReadUInt32()); // target spawn id
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
std::string name;
in->ReadString(name);
unsigned char *__emu_buffer = in->pBuffer;
buf.WriteString(name);
buf.WriteInt32(in->ReadUInt32()); // loc
buf.WriteInt32(in->ReadUInt32());
buf.WriteInt32(in->ReadUInt32());
std::string old_message;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
in->ReadString(old_message);
ServerToSoFSayLink(new_message, old_message);
buf.WriteString(new_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = strlen(emu->sayer) + new_message.length() + 25;
in->pBuffer = new unsigned char[in->size];
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
char *OutBuffer = (char *)in->pBuffer;
dest->FastQueuePacket(&outapp, ack_req);
delete in;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[2]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[3]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[4]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[5]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[6]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[7]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[8]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[9]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[10]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[11]);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_Stun)
-4
View File
@@ -328,11 +328,7 @@ namespace SoF
const int SPELL_ID_MAX = 15999;
const int SPELLBOOK_SIZE = 480;
// Be careful not to confuse these two..SoF disc release has a special requirement...
// - The number of available spell gems HAS NOT increased from 9 at this point
// - The profile allocation HAS increased to 10 at this point
const int SPELL_GEM_COUNT = static_cast<uint32>(CastingSlot::MaxGems);
const int SPELL_GEM_PROFILE_SIZE = 10; // special case declaration
const int LONG_BUFFS = 25;
const int SHORT_BUFFS = 15;
+3 -3
View File
@@ -885,7 +885,7 @@ struct PlayerProfile_Struct //23576 Octets
/*00060*/ BindStruct binds[5]; // Bind points (primary is first)
/*00160*/ uint32 deity; // deity
/*00164*/ uint32 intoxication; // Alcohol level (in ticks till sober?)
/*00168*/ uint32 spellSlotRefresh[spells::SPELL_GEM_PROFILE_SIZE]; // Refresh time (millis) - 4 Octets Each
/*00168*/ uint32 spellSlotRefresh[spells::SPELL_GEM_COUNT]; // Refresh time (millis) - 4 Octets Each
/*00208*/ uint32 abilitySlotRefresh;
/*00212*/ uint8 haircolor; // Player hair color
/*00213*/ uint8 beardcolor; // Player beard color
@@ -912,7 +912,7 @@ struct PlayerProfile_Struct //23576 Octets
/*04173*/ uint8 unknown02264[147]; // was [139]
/*04312*/ uint32 spell_book[spells::SPELLBOOK_SIZE]; // List of the Spells in spellbook 480 = 60 pages
/*06232*/ uint8 unknown4184[128]; // was [136]
/*06396*/ uint32 mem_spells[spells::SPELL_GEM_PROFILE_SIZE]; // List of spells memorized
/*06396*/ uint32 mem_spells[spells::SPELL_GEM_COUNT]; // List of spells memorized
/*06436*/ uint8 unknown04396[28]; //#### uint8 unknown04396[32]; in Titanium ####[28]
/*06464*/ uint32 platinum; // Platinum Pieces on player
/*06468*/ uint32 gold; // Gold Pieces on player
@@ -3768,7 +3768,7 @@ struct AnnoyingZoneUnknown_Struct {
};
struct LoadSpellSet_Struct {
uint32 spell[spells::SPELL_GEM_PROFILE_SIZE];
uint32 spell[spells::SPELL_GEM_COUNT];
uint32 unknown;
};
+33 -21
View File
@@ -1420,35 +1420,47 @@ namespace Titanium
EQApplicationPacket *in = *p;
*p = nullptr;
SerializeBuffer buf(in->size);
buf.WriteInt8(in->ReadUInt8()); // speak mode
buf.WriteInt8(in->ReadUInt8()); // journal mode
buf.WriteInt8(in->ReadUInt8()); // language
buf.WriteInt32(in->ReadUInt32()); // message type
buf.WriteInt32(in->ReadUInt32()); // target spawn id
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
std::string name;
in->ReadString(name); // NPC names max out at 63 chars
unsigned char *__emu_buffer = in->pBuffer;
buf.WriteString(name);
buf.WriteInt32(in->ReadUInt32()); // loc
buf.WriteInt32(in->ReadUInt32());
buf.WriteInt32(in->ReadUInt32());
std::string old_message;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
in->ReadString(old_message);
ServerToTitaniumSayLink(new_message, old_message);
buf.WriteString(new_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = strlen(emu->sayer) + new_message.length() + 25;
in->pBuffer = new unsigned char[in->size];
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
char *OutBuffer = (char *)in->pBuffer;
dest->FastQueuePacket(&outapp, ack_req);
delete in;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[2]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[3]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[4]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[5]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[6]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[7]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[8]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[9]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[10]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[11]);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_TaskDescription)
+33 -21
View File
@@ -2369,35 +2369,47 @@ namespace UF
EQApplicationPacket *in = *p;
*p = nullptr;
SerializeBuffer buf(in->size);
buf.WriteInt8(in->ReadUInt8()); // speak mode
buf.WriteInt8(in->ReadUInt8()); // journal mode
buf.WriteInt8(in->ReadUInt8()); // language
buf.WriteInt32(in->ReadUInt32()); // message type
buf.WriteInt32(in->ReadUInt32()); // target spawn id
SpecialMesg_Struct *emu = (SpecialMesg_Struct *)in->pBuffer;
std::string name;
in->ReadString(name); // NPC names max out at 63 chars
unsigned char *__emu_buffer = in->pBuffer;
buf.WriteString(name);
buf.WriteInt32(in->ReadUInt32()); // loc
buf.WriteInt32(in->ReadUInt32());
buf.WriteInt32(in->ReadUInt32());
std::string old_message;
std::string old_message = &emu->message[strlen(emu->sayer)];
std::string new_message;
in->ReadString(old_message);
ServerToUFSayLink(new_message, old_message);
buf.WriteString(new_message);
//in->size = 3 + 4 + 4 + strlen(emu->sayer) + 1 + 12 + new_message.length() + 1;
in->size = strlen(emu->sayer) + new_message.length() + 25;
in->pBuffer = new unsigned char[in->size];
auto outapp = new EQApplicationPacket(OP_SpecialMesg, buf);
char *OutBuffer = (char *)in->pBuffer;
dest->FastQueuePacket(&outapp, ack_req);
delete in;
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->header[2]);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->msg_type);
VARSTRUCT_ENCODE_TYPE(uint32, OutBuffer, emu->target_spawn_id);
VARSTRUCT_ENCODE_STRING(OutBuffer, emu->sayer);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[0]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[1]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[2]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[3]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[4]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[5]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[6]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[7]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[8]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[9]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[10]);
VARSTRUCT_ENCODE_TYPE(uint8, OutBuffer, emu->unknown12[11]);
VARSTRUCT_ENCODE_STRING(OutBuffer, new_message.c_str());
delete[] __emu_buffer;
dest->FastQueuePacket(&in, ack_req);
}
ENCODE(OP_Stun)
+8 -8
View File
@@ -22,7 +22,7 @@
#include "global_define.h"
#include "types.h"
#include "proc_launcher.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#else
#include <sys/types.h>
@@ -39,7 +39,7 @@
ProcLauncher ProcLauncher::s_launcher;
#ifdef _WIN32
#ifdef _WINDOWS
const ProcLauncher::ProcRef ProcLauncher::ProcError = 0xFFFFFFFF;
#else
const ProcLauncher::ProcRef ProcLauncher::ProcError = -1;
@@ -47,7 +47,7 @@ const ProcLauncher::ProcRef ProcLauncher::ProcError = -1;
ProcLauncher::ProcLauncher()
{
#ifndef _WIN32
#ifndef WIN32
if(signal(SIGCHLD, ProcLauncher::HandleSigChild) == SIG_ERR)
fprintf(stderr, "Unable to register child signal handler. Thats bad.");
m_signalCount = 0;
@@ -55,7 +55,7 @@ ProcLauncher::ProcLauncher()
}
void ProcLauncher::Process() {
#ifdef _WIN32
#ifdef _WINDOWS
std::map<ProcRef, Spec *>::iterator cur, end, tmp;
cur = m_running.begin();
end = m_running.end();
@@ -112,7 +112,7 @@ void ProcLauncher::ProcessTerminated(std::map<ProcRef, Spec *>::iterator &it) {
if(it->second->handler != nullptr)
it->second->handler->OnTerminate(it->first, it->second);
#ifdef _WIN32
#ifdef _WINDOWS
CloseHandle(it->second->proc_info.hProcess);
#else //!WIN32
#endif //!WIN32
@@ -125,7 +125,7 @@ ProcLauncher::ProcRef ProcLauncher::Launch(Spec *&to_launch) {
Spec *it = to_launch;
to_launch = nullptr;
#ifdef _WIN32
#ifdef _WINDOWS
STARTUPINFO siStartInfo;
BOOL bFuncRetn = FALSE;
@@ -283,7 +283,7 @@ bool ProcLauncher::Terminate(const ProcRef &proc, bool graceful) {
//we do not remove it from the list until we have been notified
//that they have been terminated.
#ifdef _WIN32
#ifdef _WINDOWS
if(!TerminateProcess(res->second->proc_info.hProcess, 0)) {
return(false);
}
@@ -325,7 +325,7 @@ void ProcLauncher::TerminateAll(bool final) {
}
#ifndef _WIN32
#ifndef WIN32
void ProcLauncher::HandleSigChild(int signum) {
if(signum == SIGCHLD) {
ProcLauncher::get()->m_signalCount++;
+3 -3
View File
@@ -33,7 +33,7 @@ public:
static ProcLauncher *get() { return(&s_launcher); }
static void ProcessInThisThread();
#ifdef _WIN32
#ifdef WIN32
typedef DWORD ProcRef;
static const ProcRef ProcError;
#else
@@ -55,7 +55,7 @@ public:
std::string logFile; //empty = do not redirect output.
protected:
//None of these fields get copied around
#ifdef _WIN32
#ifdef WIN32
PROCESS_INFORMATION proc_info;
#endif
};
@@ -83,7 +83,7 @@ protected:
private:
static ProcLauncher s_launcher;
#ifndef _WIN32
#ifndef WIN32
uint32 m_signalCount;
static void HandleSigChild(int signum);
#endif
+1 -1
View File
@@ -23,7 +23,7 @@
#include "database.h"
#include "string_util.h"
#ifdef _WIN32
#ifdef _WINDOWS
#include <winsock2.h>
#include <windows.h>
int gettimeofday (timeval *tp, ...);
+5 -2
View File
@@ -121,8 +121,11 @@ private:
int m_activeRuleset;
std::string m_activeName;
int32 m_RuleIntValues [_IntRuleCount ];
#ifdef WIN64
uint32 m_RuleIntValues [_IntRuleCount ];
#else
int m_RuleIntValues [_IntRuleCount ];
#endif
float m_RuleRealValues[_RealRuleCount];
uint32 m_RuleBoolValues[_BoolRuleCount];
+5 -16
View File
@@ -205,7 +205,6 @@ RULE_CATEGORY_END()
RULE_CATEGORY(GM)
RULE_INT(GM, MinStatusToSummonItem, 250)
RULE_INT(GM, MinStatusToZoneAnywhere, 250)
RULE_INT(GM, MinStatusToLevelTarget, 100)
RULE_CATEGORY_END()
RULE_CATEGORY(World)
@@ -226,6 +225,8 @@ RULE_BOOL(World, MaxClientsSetByStatus, false) // If True, IP Limiting will be s
RULE_BOOL(World, EnableIPExemptions, false) // If True, ip_exemptions table is used, if there is no entry for the IP it will default to RuleI(World, MaxClientsPerIP)
RULE_BOOL(World, ClearTempMerchantlist, true) // Clears temp merchant items when world boots.
RULE_BOOL(World, DeleteStaleCorpeBackups, true) // Deletes stale corpse backups older than 2 weeks.
RULE_INT(World, AccountSessionLimit, -1) //Max number of characters allowed on at once from a single account (-1 is disabled)
RULE_INT(World, ExemptAccountLimitStatus, -1) //Min status required to be exempt from multi-session per account limiting (-1 is disabled)
RULE_BOOL(World, GMAccountIPList, false) // Check ip list against GM Accounts, AntiHack GM Accounts.
RULE_INT(World, MinGMAntiHackStatus, 1) //Minimum GM status to check against AntiHack list
RULE_INT(World, SoFStartZoneID, -1) //Sets the Starting Zone for SoF Clients separate from Titanium Clients (-1 is disabled)
@@ -240,11 +241,10 @@ RULE_BOOL (World, IPLimitDisconnectAll, false)
RULE_BOOL(World, MaxClientsSimplifiedLogic, false) // New logic that only uses ExemptMaxClientsStatus and MaxClientsPerIP. Done on the loginserver. This mimics the P99-style special IP rules.
RULE_INT (World, TellQueueSize, 20)
RULE_BOOL(World, StartZoneSameAsBindOnCreation, true) //Should the start zone ALWAYS be the same location as your bind?
RULE_BOOL(World, EnforceCharacterLimitAtLogin, false)
RULE_CATEGORY_END()
RULE_CATEGORY(Zone)
RULE_INT(Zone, ClientLinkdeadMS, 90000) //the time a client remains link dead on the server after a sudden disconnection
RULE_INT(Zone, ClientLinkdeadMS, 180000) //the time a client remains link dead on the server after a sudden disconnection
RULE_INT(Zone, GraveyardTimeMS, 1200000) //ms time until a player corpse is moved to a zone's graveyard, if one is specified for the zone
RULE_BOOL(Zone, EnableShadowrest, 1) // enables or disables the shadowrest zone feature for player corpses. Default is turned on.
RULE_BOOL(Zone, UsePlayerCorpseBackups, true) // Keeps backups of player corpses.
@@ -683,10 +683,10 @@ RULE_CATEGORY_END()
RULE_CATEGORY(Network)
RULE_INT(Network, ResendDelayBaseMS, 100)
RULE_REAL(Network, ResendDelayFactor, 1.5)
RULE_INT(Network, ResendDelayMinMS, 300)
RULE_INT(Network, ResendDelayMinMS, 100)
RULE_INT(Network, ResendDelayMaxMS, 5000)
RULE_REAL(Network, ClientDataRate, 0.0) // KB / sec, 0.0 disabled
RULE_BOOL(Network, CompressZoneStream, true)
RULE_BOOL(Network, TrackOpcodeStats, false)
RULE_CATEGORY_END()
RULE_CATEGORY(QueryServ)
@@ -735,17 +735,6 @@ RULE_BOOL(Bugs, UseOldReportingMethod, true) // Forces the use of the old bug re
RULE_BOOL(Bugs, DumpTargetEntity, false) // Dumps the target entity, if one is provided
RULE_CATEGORY_END()
RULE_CATEGORY(Faction)
RULE_INT(Faction, AllyFactionMinimum, 1100)
RULE_INT(Faction, WarmlyFactionMinimum, 750)
RULE_INT(Faction, KindlyFactionMinimum, 500)
RULE_INT(Faction, AmiablyFactionMinimum, 100)
RULE_INT(Faction, IndifferentlyFactionMinimum, 0)
RULE_INT(Faction, ApprehensivelyFactionMinimum, -100)
RULE_INT(Faction, DubiouslyFactionMinimum, -500)
RULE_INT(Faction, ThreateninglyFactionMinimum, -750)
RULE_CATEGORY_END()
#undef RULE_CATEGORY
#undef RULE_INT
#undef RULE_REAL
+1 -1
View File
@@ -143,7 +143,7 @@ public:
void WriteString(const char *str)
{
assert(str != nullptr);
auto len = std::char_traits<char>::length(str) + 1;
auto len = strlen(str) + 1;
if (m_pos + len > m_capacity)
Grow(m_capacity + len);
memcpy(m_buffer + m_pos, str, len);
+94 -65
View File
@@ -15,80 +15,109 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Serverinfo.cpp - Server information gathering functions, used in #serverinfo - Windows specific
// I'm not sure quite how to get this exact information in *nix, hopefully someone can fill that in
// -T7g
// Implement preliminary support for *nix variants
// misanthropicfiend
#include "serverinfo.h"
#include <uv.h>
#ifdef _WINDOWS
#include <windows.h>
size_t EQ::GetRSS()
{
size_t rss = 0;
char Ver_name[100];
DWORD Ver_build, Ver_min, Ver_maj, Ver_pid;
if (0 != uv_resident_set_memory(&rss)) {
return 0;
int GetOS() {
strcpy(Ver_name, "Unknown operating system");
OSVERSIONINFO Ver_os;
Ver_os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(!(GetVersionEx(&Ver_os))) return 1;
Ver_build = Ver_os.dwBuildNumber & 0xFFFF;
Ver_min = Ver_os.dwMinorVersion;
Ver_maj = Ver_os.dwMajorVersion;
Ver_pid = Ver_os.dwPlatformId;
if ((Ver_pid == 1) && (Ver_maj == 4))
{
if ((Ver_min < 10) && (Ver_build == 950))
{
strcpy(Ver_name, "Microsoft Windows 95");
}
else if ((Ver_min < 10) &&
((Ver_build > 950) && (Ver_build <= 1080)))
{
strcpy(Ver_name, "Microsoft Windows 95 SP1");
}
else if ((Ver_min < 10) && (Ver_build > 1080))
{
strcpy(Ver_name, "Microsoft Windows 95 OSR2");
}
else if ((Ver_min == 10) && (Ver_build == 1998))
{
strcpy(Ver_name, "Microsoft Windows 98");
}
else if ((Ver_min == 10) &&
((Ver_build > 1998) && (Ver_build < 2183)))
{
strcpy(Ver_name, "Microsoft Windows 98, Service Pack 1");
}
else if ((Ver_min == 10) && (Ver_build >= 2183))
{
strcpy(Ver_name, "Microsoft Windows 98 Second Edition");
}
else if (Ver_min == 90)
{
strcpy(Ver_name, "Microsoft Windows ME");
}
}
else if (Ver_pid == 2)
{
if ((Ver_maj == 3) && (Ver_min == 51))
{
strcpy(Ver_name, "Microsoft Windows NT 3.51");
}
else if ((Ver_maj == 4) && (Ver_min == 0))
{
strcpy(Ver_name, "Microsoft Windows NT 4");
}
else if ((Ver_maj == 5) && (Ver_min == 0))
{
strcpy(Ver_name, "Microsoft Windows 2000");
}
else if ((Ver_maj == 5) && (Ver_min == 1))
{
strcpy(Ver_name, "Microsoft Windows XP");
}
else if ((Ver_maj == 5) && (Ver_min == 2))
{
strcpy(Ver_name, "Microsoft Windows 2003");
}
}
return rss;
return 0;
}
double EQ::GetUptime()
{
double uptime = 0.0;
#else
if (0 != uv_uptime(&uptime)) {
return 0.0;
#include <sys/utsname.h>
#include <stdio.h>
#include <string.h>
char* GetOS(char* os_string) {
utsname info;
if(uname(&info)==0) {
snprintf(os_string, 99, "%s %s %s %s %s", info.sysname, info.nodename, info.release, info.version, info.machine);
} else {
strncpy(os_string, "Error determining OS & version!", 25);
}
return uptime;
return os_string;
}
size_t EQ::GetPID()
{
return uv_os_getpid();
}
std::vector<eq_cpu_info_t> EQ::GetCPUs()
{
std::vector<eq_cpu_info_t> ret;
uv_cpu_info_t *cpu_info = nullptr;
int count = 0;
if (0 != uv_cpu_info(&cpu_info, &count)) {
return ret;
}
ret.reserve(count);
for (int i = 0; i < count; ++i) {
eq_cpu_info_t r;
auto &entry = cpu_info[i];
r.model = entry.model;
r.speed = entry.speed / 1000.0;
r.time_user = entry.cpu_times.user;
r.time_sys = entry.cpu_times.sys;
r.time_idle = entry.cpu_times.idle;
r.time_nice = entry.cpu_times.nice;
r.time_irq = entry.cpu_times.irq;
ret.push_back(r);
}
uv_free_cpu_info(cpu_info, count);
return ret;
}
eq_utsname_t EQ::GetOS()
{
eq_utsname_t ret;
uv_utsname_t name;
if (0 != uv_os_uname(&name)) {
return ret;
}
ret.machine = name.machine;
ret.release = name.release;
ret.sysname = name.sysname;
ret.version = name.version;
return ret;
}
#endif
+10 -28
View File
@@ -15,33 +15,15 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#pragma once
#ifndef SERVERINFO_H
#define SERVERINFO_H
#include <string>
#include <vector>
#ifdef _WINDOWS
extern char Ver_name[36];
extern DWORD Ver_build, Ver_min, Ver_maj, Ver_pid;
int GetOS();
#else
char* GetOS(char* os_string);
#endif
typedef struct eq_cpu_info_s {
std::string model;
double speed;
uint64_t time_user;
uint64_t time_nice;
uint64_t time_sys;
uint64_t time_idle;
uint64_t time_irq;
} eq_cpu_info_t;
typedef struct eq_utsname_s {
std::string sysname;
std::string release;
std::string version;
std::string machine;
} eq_utsname_t;
namespace EQ
{
size_t GetRSS();
double GetUptime();
size_t GetPID();
std::vector<eq_cpu_info_t> GetCPUs();
eq_utsname_t GetOS();
}
#endif
+1 -20
View File
@@ -80,7 +80,6 @@
#define ServerOP_GroupJoin 0x003e //for joining ooz folks
#define ServerOP_UpdateSpawn 0x003f
#define ServerOP_SpawnStatusChange 0x0040
#define ServerOP_DropClient 0x0041 // DropClient
#define ServerOP_ReloadTasks 0x0060
#define ServerOP_DepopAllPlayersCorpses 0x0061
#define ServerOP_ReloadTitles 0x0062
@@ -214,15 +213,6 @@ enum { QSG_LFGuild_PlayerMatches = 0, QSG_LFGuild_UpdatePlayerInfo, QSG_LFGuild_
#define ServerOP_Speech 0x4513
enum {
UserToWorldStatusWorldUnavail = 0,
UserToWorldStatusSuccess = 1,
UserToWorldStatusSuspended = -1,
UserToWorldStatusBanned = -2,
UserToWorldStatusWorldAtCapacity = -3,
UserToWorldStatusAlreadyOnline = -4
};
/************ PACKET RELATED STRUCT ************/
class ServerPacket
{
@@ -318,17 +308,11 @@ struct ServerZoneIncomingClient_Struct {
uint32 accid;
int16 admin;
uint32 charid;
uint32 lsid;
bool tellsoff;
char charname[64];
char lskey[30];
};
struct ServerZoneDropClient_Struct
{
uint32 lsid;
};
struct ServerChangeWID_Struct {
uint32 charid;
uint32 newwid;
@@ -359,8 +343,7 @@ struct ServerChannelMessage_Struct {
bool noreply;
uint16 chan_num;
uint32 guilddbid;
uint8 language;
uint8 lang_skill;
uint16 language;
uint8 queued; // 0 = not queued, 1 = queued, 2 = queue full, 3 = offline
char message[0];
};
@@ -873,8 +856,6 @@ struct ServerRaidGroupAction_Struct { //add / remove depends on opcode.
struct ServerRaidMessage_Struct {
uint32 rid;
uint32 gid;
uint8 language;
uint8 lang_skill;
char from[64];
char message[0];
};
+1 -1
View File
@@ -77,7 +77,7 @@
#include "classes.h"
#include "spdat.h"
#ifndef _WIN32
#ifndef WIN32
#include <stdlib.h>
#include "unix.h"
#endif
+1 -1
View File
@@ -590,7 +590,7 @@ typedef enum {
#define SE_CorruptionCounter 369 // implemented
#define SE_ResistCorruption 370 // implemented
#define SE_AttackSpeed4 371 // implemented - stackable slow effect 'Inhibit Melee'
#define SE_ForageSkill 372 // implemented[AA] Will increase the skill cap for those that have the Forage skill and grant the skill and raise the cap to those that do not.
#define SE_ForageSkill 372 // *not implemented[AA] Will increase the skill cap for those that have the Forage skill and grant the skill and raise the cap to those that do not.
#define SE_CastOnFadeEffectAlways 373 // implemented - Triggers if fades after natural duration OR from rune/numhits fades.
#define SE_ApplyEffect 374 // implemented
#define SE_DotCritDmgIncrease 375 // implemented - Increase damage of DoT critical amount
+2 -23
View File
@@ -17,7 +17,7 @@
#include "string_util.h"
#include <algorithm>
#ifdef _WIN32
#ifdef _WINDOWS
#include <windows.h>
#define snprintf _snprintf
@@ -27,8 +27,6 @@
#else
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#endif
#ifndef va_copy
@@ -121,29 +119,10 @@ std::vector<std::string> SplitString(const std::string &str, char delim) {
while(std::getline(ss, item, delim)) {
ret.push_back(item);
}
return ret;
}
std::string implode(std::string glue, std::vector<std::string> src)
{
if (src.empty()) {
return {};
}
std::ostringstream output;
std::vector<std::string>::iterator src_iter;
for (src_iter = src.begin(); src_iter != src.end(); src_iter++) {
output << *src_iter << glue;
}
std::string final_output = output.str();
final_output.resize (output.str().size () - glue.size());
return final_output;
}
std::string EscapeString(const std::string &s) {
std::string ret;
-1
View File
@@ -30,7 +30,6 @@ const std::string ucfirst(std::string s);
std::vector<std::string> split(std::string str_to_split, char delimiter);
const std::string StringFormat(const char* format, ...);
const std::string vStringFormat(const char* format, va_list args);
std::string implode(std::string glue, std::vector<std::string> src);
std::vector<std::string> SplitString(const std::string &s, char delim);
std::string EscapeString(const char *src, size_t sz);
std::string EscapeString(const std::string &s);
+2 -2
View File
@@ -18,7 +18,7 @@
// Disgrace: for windows compile
#ifndef _WIN32
#ifndef WIN32
#include <sys/time.h>
#else
#include <sys/timeb.h>
@@ -64,7 +64,7 @@ Timer::Timer(uint32 start, uint32 timer, bool iUseAcurateTiming = false) {
}
/* Reimplemented for MSVC - Bounce */
#ifdef _WIN32
#ifdef _WINDOWS
int gettimeofday (timeval *tp, ...)
{
timeb tb;
+1 -1
View File
@@ -22,7 +22,7 @@
#include <chrono>
// Disgrace: for windows compile
#ifdef _WIN32
#ifdef _WINDOWS
#include "global_define.h"
int gettimeofday (timeval *tp, ...);
#endif
+5 -5
View File
@@ -29,7 +29,7 @@ typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
#ifdef _WIN32
#ifdef _WINDOWS
#pragma warning( disable : 4200 )
#endif
@@ -42,7 +42,7 @@ typedef unsigned short ushort;
typedef unsigned char uchar;
typedef const char Const_char; //for perl XS
#ifdef _WIN32
#ifdef _WINDOWS
#if (!defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1900))
#define snprintf _snprintf
#endif
@@ -61,7 +61,7 @@ typedef const char Const_char; //for perl XS
#define H32(i) ((uint32) (i >> 32))
#define L16(i) ((uint16) i)
#ifndef _WIN32
#ifndef WIN32
// More WIN32 compatability
typedef unsigned long DWORD;
typedef unsigned char BYTE;
@@ -79,14 +79,14 @@ typedef const char Const_char; //for perl XS
#endif
#ifdef _WIN32
#ifdef _WINDOWS
#define DLLFUNC extern "C" __declspec(dllexport)
#else
#define DLLFUNC extern "C"
#endif
// htonll and ntohll already defined on windows
#ifndef _WIN32
#ifndef WIN32
# if defined(__linux__)
# include <endian.h>
# elif defined(__FreeBSD__) || defined(__NetBSD__)
+1 -1
View File
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _WIN32
#ifndef _WINDOWS
#include "unix.h"
#include <string.h>
+1 -1
View File
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _WIN32
#ifndef _WINDOWS
#ifndef __UNIX_H__
#define __UNIX_H__
#include <unistd.h>
+3 -3
View File
@@ -10,16 +10,16 @@
// this doesn't do shit for C++ but libc++ and GCC 6.1+ use it to define some macros
#include <ciso646>
#ifndef _WIN32
#ifndef WIN32
extern "C" { //the perl headers dont do this for us...
#endif
#include <perl.h>
#include <XSUB.h>
#ifndef _WIN32
#ifndef WIN32
};
#endif
#ifdef _WIN32
#ifdef WIN32
#ifndef snprintf
#define snprintf _snprintf
#endif
+3 -3
View File
@@ -31,16 +31,16 @@
*/
#define CURRENT_BINARY_DATABASE_VERSION 9141
#define CURRENT_BINARY_DATABASE_VERSION 9138
#ifdef BOTS
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9024
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9022
#else
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 0 // must be 0
#endif
#define COMPILE_DATE __DATE__
#define COMPILE_TIME __TIME__
#ifndef _WIN32
#ifndef WIN32
#define LAST_MODIFIED __TIME__
#else
#define LAST_MODIFIED __TIMESTAMP__
+2
View File
@@ -0,0 +1,2 @@
*.*
*

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