diff --git a/.gitignore b/.gitignore index a21ef251d..daba92762 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ install_manifest.txt log/ logs/ vcpkg/ +perl/ .idea/* *cbp diff --git a/BUILD.md b/BUILD.md new file mode 100644 index 000000000..1cc3cd99b --- /dev/null +++ b/BUILD.md @@ -0,0 +1,64 @@ +# Guide To Building From Source Without Installer + +This guide is far from exhaustive, you should expect to have some experience with building C++ code before considering compiling the code from scratch. You should instead consider using the installer scripts if you don't want to hack on the code directly. + +### CMake + +EQEmu uses CMake as the build system on all platforms. You will need CMake 3.2 or higher to build from source. + +### Dependencies + +The following libraries are required to build from source: +- [boost](https://www.boost.org/ "boost") +- [zlib](https://www.zlib.net/ "zlib") (If not included the source will build [zlib-ng](https://github.com/zlib-ng/zlib-ng "zlib-ng") instead) +- [libmysql](https://dev.mysql.com/downloads/connector/c/ "libmysql") or [libmariadb](https://github.com/MariaDB/mariadb-connector-c "libmariadb") + +The following libraries are not strictly required but in many cased recommended. +- [OpenSSL](https://www.openssl.org/ "OpenSSL") or [mbedTLS](https://tls.mbed.org/ "mbedTLS") (Required for the loginserver and headless client) +- [libsodium](https://github.com/jedisct1/libsodium "libsodium") (Required for strong password hashing on the loginserver) +- [Lua 5.1](https://www.lua.org/ "Lua 5.1") or [LuaJit](http://luajit.org/ "LuaJit") (Required for Lua Quest Scripting) +- [Perl](https://www.perl.org/ "Perl") (Required for Perl Quest Scripting) + +##### Windows +For windows it is suggested you make use of [vcpkg](https://github.com/microsoft/vcpkg "vcpkg") if you wish to build your own dependencies. + +If you wish to use Perl then you should use whichever version of Perl you have installed on the target system. + +You can also download a vcpkg export from our releases section for Visual Studio [x86](https://github.com/EQEmu/Server/releases/download/v1.2/vcpkg-export-x86.zip "x86") or [x64](https://github.com/EQEmu/Server/releases/download/v1.2/vcpkg-export-x64.zip "x64") that includes a toolchain file you can pass to CMake. + +##### Linux +For Linux you simply can install the dependencies from your package manager, below is an example of doing it on Ubuntu using apt-get. + + sudo apt-get install libmysqlclient-dev libperl-dev libboost-dev liblua5.1-0-dev zlib1g-dev uuid-dev libssl-dev + +### Running CMake + +##### Windows +The following is a modified command our automated build server uses to run CMake via the release vcpkg export and its toolchain file. + +Assuming it is starting in c:/projects/eqemu and the x64 dependencies were extracted to c:/projects/eqemu/vcpkg. + + mkdir build + cd build + cmake -G "Visual Studio 15 2017 Win64" -DEQEMU_BUILD_TESTS=ON -DEQEMU_BUILD_LOGIN=ON -DEQEMU_BUILD_ZLIB=ON -DEQEMU_ENABLE_BOTS=ON -DCMAKE_TOOLCHAIN_FILE="c:/projects/eqemu/vcpkg/vcpkg-export-20180828-145455/scripts/buildsystems/vcpkg.cmake" .. + +##### Linux +Similarly to Windows running CMake on Linux is simple it just omits the toolchain file and uses a different generator. + + mkdir build + cd build + cmake -G "Unix Makefiles" -DEQEMU_BUILD_TESTS=ON -DEQEMU_ENABLE_BOTS=ON -DEQEMU_BUILD_LOGIN=ON .. + +### Building + +##### Windows +Inside the build directory a file EQEmu.sln should be produced by a successful run of the CMake command. You can either open this with Visual Studio or build it directly with MSBuild via the command line. + + msbuild EQEmu.sln /p:Configuration=Release + +##### Linux +From the build directory you can simply call make to build. + +For example. + + make -j4 diff --git a/CMakeLists.txt b/CMakeLists.txt index dedce5c3f..0f738338f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,120 +1,28 @@ -#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_DEBUG -#EQEMU_ENABLE_BOTS -#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 -#EQEMU_ARCH -#EQEMU_ARCH_ALT +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) -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 +IF(POLICY CMP0074) + CMAKE_POLICY(SET CMP0074 NEW) +ENDIF() + 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_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) +SET(CMAKE_CXX_STANDARD 11) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) +SET(CMAKE_CXX_EXTENSIONS OFF) IF(MSVC) - IF(CMAKE_CL_64) - SET(EQEMU_ARCH "x64") - SET(EQEMU_ARCH_ALT "x64") - ELSE(CMAKE_CL_64) - SET(EQEMU_ARCH "x86") - SET(EQEMU_ARCH_ALT "Win32") - ENDIF(CMAKE_CL_64) - - SET(MYSQL_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/mysql_${EQEMU_ARCH}") - - IF(VCPKG_TOOLCHAIN) - IF(NOT MSVC_VERSION GREATER 1800) - SET(SODIUM_INCLUDE_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/include") - ENDIF() - ELSE(VCPKG_TOOLCHAIN) - SET(ZLIB_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/zlib_${EQEMU_ARCH}") - SET(LUA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/luaj_${EQEMU_ARCH}") - SET(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/openssl_${EQEMU_ARCH}") - - SET(SODIUM_INCLUDE_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/include") - ENDIF(VCPKG_TOOLCHAIN) - - IF(SODIUM_INCLUDE_HINTS) - IF(MSVC_VERSION GREATER 1800) - SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/${EQEMU_ARCH_ALT}/Release/v140/dynamic") - ELSEIF(MSVC_VERSION EQUAL 1800) - SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/${EQEMU_ARCH_ALT}/Release/v120/dynamic") - ELSE() - SET(SODIUM_LIBRARY_HINTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/libsodium/${EQEMU_ARCH_ALT}/Release/v110/dynamic") - ENDIF() - ENDIF(SODIUM_INCLUDE_HINTS) - - #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(-D_CRT_SECURE_NO_WARNINGS) 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) @@ -131,128 +39,279 @@ IF(UNIX) ENDIF(CMAKE_SYSTEM_NAME MATCHES "Darwin") ENDIF(UNIX) -#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" -) +ADD_DEFINITIONS(-DGLM_FORCE_RADIANS) +ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT) +ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL) -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" -) +#MSVC can fetch dependencies automatically. +IF(MSVC) + INCLUDE("${CMAKE_SOURCE_DIR}/cmake/DependencyHelperMSVC.cmake") +ENDIF() -OPTION(EQEMU_LSPX "" OFF) -MARK_AS_ADVANCED(EQEMU_LSPX) +#Find everything we need +FIND_PACKAGE(Boost REQUIRED) +FIND_PACKAGE(MySQL) +FIND_PACKAGE(MariaDB) +FIND_PACKAGE(ZLIB) +FIND_PACKAGE(OpenSSL) +FIND_PACKAGE(Lua51) +FIND_PACKAGE(PerlLibs) +FIND_PACKAGE(Sodium) +FIND_PACKAGE(mbedTLS) -MARK_AS_ADVANCED(EQEMU_LOG_LEVEL_DEBUG) +MESSAGE(STATUS "**************************************************") +MESSAGE(STATUS "* Library Detection *") +MESSAGE(STATUS "**************************************************") -#Bots are a compile time option so on/off +IF(MYSQL_FOUND) + MESSAGE(STATUS "* MySQL: FOUND *") +ELSE() + MESSAGE(STATUS "* MySQL: MISSING *") +ENDIF() + +IF(MARIADB_FOUND) + MESSAGE(STATUS "* MariaDB: FOUND *") +ELSE() + MESSAGE(STATUS "* MariaDB: MISSING *") +ENDIF() + +IF(ZLIB_FOUND) + MESSAGE(STATUS "* ZLIB: FOUND *") +ELSE() + MESSAGE(STATUS "* ZLIB: MISSING *") +ENDIF() + +IF(Lua51_FOUND) + MESSAGE(STATUS "* Lua: FOUND *") +ELSE() + MESSAGE(STATUS "* Lua: MISSING *") +ENDIF() + +IF(PerlLibs_FOUND) + MESSAGE(STATUS "* Perl: FOUND *") +ELSE() + MESSAGE(STATUS "* Perl: MISSING *") +ENDIF() + +IF(SODIUM_FOUND) + MESSAGE(STATUS "* libsodium: FOUND *") +ELSE() + MESSAGE(STATUS "* libsodium: MISSING *") +ENDIF() + +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 +OPTION(EQEMU_DEPOP_INVALIDATES_CACHE "#repop invalidates the npc_types cache (will cause a larger database hit on #repop but is more convienent)." ON) OPTION(EQEMU_ENABLE_BOTS "Enable Bots" OFF) - -#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_LOGIN "Build the login 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_LSPX) - ADD_DEFINITIONS(-DLSPX=ON) -ENDIF(EQEMU_LSPX) - IF(EQEMU_ENABLE_BOTS) ADD_DEFINITIONS(-DBOTS) ENDIF(EQEMU_ENABLE_BOTS) -#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) - -#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") +#database +IF(MySQL_FOUND AND MariaDB_FOUND) + SET(DATABASE_LIBRARY_SELECTION MySQL CACHE STRING "Database library to use: + MySQL + MariaDB" + ) + + IF(DATABASE_LIBRARY_SELECTION STREQUAL "MySQL") + SET(DATABASE_LIBRARY_TYPE " MySQL") + SET(DATABASE_LIBRARY_LIBS ${MySQL_LIBRARIES}) + SET(DATABASE_LIBRARY_INCLUDE ${MySQL_INCLUDE_DIR}) + ELSEIF(DATABASE_LIBRARY_SELECTION STREQUAL "MariaDB") + SET(DATABASE_LIBRARY_TYPE "MariaDB") + SET(DATABASE_LIBRARY_LIBS ${MariaDB_LIBRARIES}) + SET(DATABASE_LIBRARY_INCLUDE ${MariaDB_INCLUDE_DIR}) + ELSE() + MESSAGE(FATAL_ERROR "Unknown database library set, should be one of: MySQL, MariaDB") ENDIF() -ENDIF(NOT MSVC) +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() -#Various definitions -IF(EQEMU_BUILD_PERL) - ADD_DEFINITIONS(-DEMBPERL) - ADD_DEFINITIONS(-DEMBPERL_PLUGIN) -ENDIF(EQEMU_BUILD_PERL) -IF(EQEMU_BUILD_LUA) - ADD_DEFINITIONS(-DLUA_EQEMU) -ENDIF(EQEMU_BUILD_LUA) +#security +#prefer openssl to mbedtls (arbitrary) +IF(OpenSSL_FOUND AND MBEDTLS_FOUND) + SET(TLS_LIBRARY_SELECTION OpenSSL CACHE STRING "TLS library to use: + OpenSSL + mbedTLS" + ) + + IF(TLS_LIBRARY_SELECTION STREQUAL "OpenSSL") + SET(TLS_LIBRARY_TYPE " OpenSSL") + SET(TLS_LIBRARY_ENABLED ON) + SET(TLS_LIBRARY_LIBS ${OPENSSL_LIBRARIES}) + SET(TLS_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR}) + ADD_DEFINITIONS(-DEQEMU_USE_OPENSSL) + ELSEIF(TLS_LIBRARY_SELECTION STREQUAL "mbedTLS") + SET(TLS_LIBRARY_TYPE " mbedTLS") + SET(TLS_LIBRARY_ENABLED ON) + SET(TLS_LIBRARY_LIBS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) + SET(TLS_LIBRARY_INCLUDE ${MBEDTLS_INCLUDE_DIR}) + ADD_DEFINITIONS(-DEQEMU_USE_MBEDTLS) + ELSE() + MESSAGE(FATAL_ERROR "Unknown TLS library set, should be one of: OpenSSL, mbedTLS") + ENDIF() +ELSEIF(OpenSSL_FOUND) + SET(TLS_LIBRARY_TYPE " OpenSSL") + SET(TLS_LIBRARY_ENABLED ON) + SET(TLS_LIBRARY_LIBS ${OPENSSL_LIBRARIES}) + SET(TLS_LIBRARY_INCLUDE ${OPENSSL_INCLUDE_DIR}) + ADD_DEFINITIONS(-DEQEMU_USE_OPENSSL) +ELSEIF(MBEDTLS_FOUND) + SET(TLS_LIBRARY_TYPE " mbedTLS") + SET(TLS_LIBRARY_ENABLED ON) + SET(TLS_LIBRARY_LIBS ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY}) + SET(TLS_LIBRARY_INCLUDE ${MBEDTLS_INCLUDE_DIR}) + ADD_DEFINITIONS(-DEQEMU_USE_MBEDTLS) +ELSE() + SET(TLS_LIBRARY_TYPE "Disabled") + SET(TLS_LIBRARY_ENABLED OFF) +ENDIF() -#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_DEBUG=${EQEMU_LOG_LEVEL_DEBUG}) -ADD_DEFINITIONS(-DGLM_FORCE_RADIANS) -ADD_DEFINITIONS(-DGLM_FORCE_CTOR_INIT) -ADD_DEFINITIONS(-DGLM_ENABLE_EXPERIMENTAL) - -#Find everything we need -FIND_PACKAGE(ZLIB) -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} 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}) + 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_ENABLED ON) + SET(LUA_LIBRARY_LIBS ${LUA_LIBRARY} luabind) + SET(LUA_LIBRARY_INCLUDE ${LUA_INCLUDE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/libs/luabind") +ELSE() + SET(LUA_LIBRARY_TYPE "Disabled") + SET(LUA_LIBRARY_ENABLED OFF) +ENDIF() + +IF(PerlLibs_FOUND) + SET(PERL_LIBRARY_TYPE " Perl") + SET(PERL_LIBRARY_ENABLED ON) + SET(PERL_LIBRARY_LIBS ${PERL_LIBRARY}) + SET(PERL_LIBRARY_INCLUDE ${PERL_INCLUDE_PATH}) +ELSE() + SET(PERL_LIBRARY_TYPE "Disabled") + SET(PERL_LIBRARY_ENABLED OFF) +ENDIF() + +#use zlib if exists +IF(ZLIB_FOUND) + OPTION(EQEMU_BUILD_ZLIB "Build internal version of zlib." ON) + IF(EQEMU_BUILD_ZLIB) + SET(ZLIB_LIBRARY_TYPE "zlib-ng") + SET(ZLIB_LIBRARY_LIBS "zlibstatic") + SET(ZLIB_LIBRARY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/libs/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}/libs/zlibng") +ENDIF() + +MESSAGE(STATUS "") +MESSAGE(STATUS "**************************************************") +MESSAGE(STATUS "* Library Usage *") +MESSAGE(STATUS "**************************************************") +MESSAGE(STATUS "* Database: ${DATABASE_LIBRARY_TYPE} *") +MESSAGE(STATUS "* TLS: ${TLS_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(TLS_LIBRARY_ENABLED) + SET(SERVER_LIBS ${SERVER_LIBS} ${TLS_LIBRARY_LIBS}) + INCLUDE_DIRECTORIES(SYSTEM "${TLS_LIBRARY_INCLUDE}") +ENDIF() + +IF(SODIUM_LIBRARY_ENABLED) + SET(SERVER_LIBS ${SERVER_LIBS} ${SODIUM_LIBRARY_LIBS}) + INCLUDE_DIRECTORIES(SYSTEM "${SODIUM_LIBRARY_INCLUDE}") +ENDIF() + +IF(LUA_LIBRARY_ENABLED) + OPTION(EQEMU_BUILD_LUA "Build Lua parser." ON) + + IF(EQEMU_BUILD_LUA) + ADD_DEFINITIONS(-DLUA_EQEMU) + SET(SERVER_LIBS ${SERVER_LIBS} ${LUA_LIBRARY_LIBS}) + INCLUDE_DIRECTORIES(SYSTEM "${LUA_LIBRARY_INCLUDE}") + + 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() ENDIF() ENDIF() -IF(ZLIB_FOUND) - OPTION(EQEMU_BUILD_ZLIB "Build internal version of zlib." OFF) - - IF(EQEMU_BUILD_ZLIB) - INCLUDE_DIRECTORIES(BEFORE SYSTEM "${CMAKE_CURRENT_BINARY_DIR}/libs/zlibng" "${CMAKE_CURRENT_SOURCE_DIR}/libs/zlibng") - SET(SERVER_LIBS ${SERVER_LIBS} "zlibstatic") - ELSE() - INCLUDE_DIRECTORIES(SYSTEM "${ZLIB_INCLUDE_DIRS}") - SET(SERVER_LIBS ${SERVER_LIBS} ${ZLIB_LIBRARY}) +IF(PERL_LIBRARY_ENABLED) + OPTION(EQEMU_BUILD_PERL "Build Perl parser." ON) + 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() -ELSE() - MESSAGE(STATUS "Could NOT find ZLIB - using ZLIBSTATIC package.") - SET(EQEMU_BUILD_ZLIB ON) - INCLUDE_DIRECTORIES(BEFORE SYSTEM "${CMAKE_CURRENT_BINARY_DIR}/libs/zlibng" "${CMAKE_CURRENT_SOURCE_DIR}/libs/zlibng") - SET(SERVER_LIBS ${SERVER_LIBS} "zlibstatic") ENDIF() IF(WIN32) @@ -267,52 +326,32 @@ IF(UNIX) SET(SERVER_LIBS ${SERVER_LIBS} "uuid") 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") +IF(EQEMU_BUILD_LOGIN AND NOT TLS_LIBRARY_ENABLED) + MESSAGE(FATAL_ERROR "Login server requires a TLS Library to build.") +ENDIF() - 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 "${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/websocketpp") +IF(EQEMU_BUILD_HC AND NOT TLS_LIBRARY_ENABLED) + MESSAGE(FATAL_ERROR "Headless client requires a TLS Library to build.") +ENDIF() IF(EQEMU_BUILD_SERVER OR EQEMU_BUILD_LOGIN OR EQEMU_BUILD_TESTS OR EQEMU_BUILD_HC) ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(libs) ADD_SUBDIRECTORY(submodules/fmt) ADD_SUBDIRECTORY(submodules/libuv) - - 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) 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(libs/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) + IF(EQEMU_BUILD_SERVER) ADD_SUBDIRECTORY(shared_memory) ADD_SUBDIRECTORY(world) @@ -321,6 +360,7 @@ 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) diff --git a/client_files/CMakeLists.txt b/client_files/CMakeLists.txt index 93d748dc6..fe377ec9f 100644 --- a/client_files/CMakeLists.txt +++ b/client_files/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) add_subdirectory(import) add_subdirectory(export) diff --git a/client_files/export/CMakeLists.txt b/client_files/export/CMakeLists.txt index c24a01865..08cbbc822 100644 --- a/client_files/export/CMakeLists.txt +++ b/client_files/export/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(export_sources main.cpp diff --git a/client_files/import/CMakeLists.txt b/client_files/import/CMakeLists.txt index 0f779497c..a76bab416 100644 --- a/client_files/import/CMakeLists.txt +++ b/client_files/import/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(import_sources main.cpp diff --git a/cmake/DependencyHelperMSVC.cmake b/cmake/DependencyHelperMSVC.cmake new file mode 100644 index 000000000..48b99c9d9 --- /dev/null +++ b/cmake/DependencyHelperMSVC.cmake @@ -0,0 +1,94 @@ +OPTION(EQEMU_FETCH_MSVC_DEPENDENCIES_VCPKG "Automatically fetch vcpkg dependencies for MSCV" ON) +OPTION(EQEMU_FETCH_MSVC_DEPENDENCIES_PERL "Automatically fetch perl dependencies for MSCV" ON) + +MARK_AS_ADVANCED(EQEMU_FETCH_MSVC_DEPENDENCIES_VCPKG) +MARK_AS_ADVANCED(EQEMU_FETCH_MSVC_DEPENDENCIES_PERL) + +SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X86 "https://github.com/EQEmu/Server/releases/download/v1.2/vcpkg-export-x86.zip") +SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X64 "https://github.com/EQEmu/Server/releases/download/v1.2/vcpkg-export-x64.zip") +SET(EQEMU_MSVC_DEPENDENCIES_PERL_X86 "http://strawberryperl.com/download/5.24.4.1/strawberry-perl-5.24.4.1-32bit-portable.zip") +SET(EQEMU_MSVC_DEPENDENCIES_PERL_X64 "http://strawberryperl.com/download/5.24.4.1/strawberry-perl-5.24.4.1-64bit-portable.zip") +SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_ZIP "vcpkg-export-x86.zip") +SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_ZIP "vcpkg-export-x64.zip") +SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_DIR "vcpkg-export-20180828-145854") +SET(EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_DIR "vcpkg-export-20180828-145455") +SET(EQEMU_MSVC_DEPENDENCIES_PERL_X86_ZIP "strawberry-perl-5.24.4.1-32bit-portable.zip") +SET(EQEMU_MSVC_DEPENDENCIES_PERL_X64_ZIP "strawberry-perl-5.24.4.1-64bit-portable.zip") +SET(EQEMU_MSVC_DEPENDENCIES_PERL_X86_DIR "x86") +SET(EQEMU_MSVC_DEPENDENCIES_PERL_X64_DIR "x64") + +IF(CMAKE_SIZEOF_VOID_P EQUAL 8) + SET(EQEMU_VCPKG_URL ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X64}) + SET(EQEMU_PERL_URL ${EQEMU_MSVC_DEPENDENCIES_PERL_X64}) + SET(EQEMU_VCPKG_ZIP ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_ZIP}) + SET(EQEMU_VCPKG_DIR ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X64_DIR}) + SET(EQEMU_PERL_ZIP ${EQEMU_MSVC_DEPENDENCIES_PERL_X64_ZIP}) + SET(EQEMU_PERL_DIR ${EQEMU_MSVC_DEPENDENCIES_PERL_X64_DIR}) +ELSE() + SET(EQEMU_VCPKG_URL ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X86}) + SET(EQEMU_PERL_URL ${EQEMU_MSVC_DEPENDENCIES_PERL_X86}) + SET(EQEMU_VCPKG_ZIP ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_ZIP}) + SET(EQEMU_VCPKG_DIR ${EQEMU_MSVC_DEPENDENCIES_VCPKG_X86_DIR}) + SET(EQEMU_PERL_ZIP ${EQEMU_MSVC_DEPENDENCIES_PERL_X86_ZIP}) + SET(EQEMU_PERL_DIR ${EQEMU_MSVC_DEPENDENCIES_PERL_X86_DIR}) +ENDIF() + +IF(EQEMU_FETCH_MSVC_DEPENDENCIES_VCPKG) + MESSAGE(STATUS "Resolving vcpkg dependencies...") + + IF(NOT EXISTS ${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_ZIP}) + EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/vcpkg) + + MESSAGE(STATUS "Downloading existing vcpkg dependencies from releases...") + FILE(DOWNLOAD ${EQEMU_VCPKG_URL} ${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_ZIP} + SHOW_PROGRESS + STATUS DOWNLOAD_STATUS) + + LIST(GET DOWNLOAD_STATUS 0 STATUS_CODE) + IF(NOT STATUS_CODE EQUAL 0) + MESSAGE(FATAL_ERROR "Was unable to download dependencies from ${EQEMU_VCPKG_URL}") + ENDIF() + + MESSAGE(STATUS "Extracting files...") + EXECUTE_PROCESS( + COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_ZIP} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/vcpkg + ) + ENDIF() + + INCLUDE(${PROJECT_SOURCE_DIR}/vcpkg/${EQEMU_VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake) +ENDIF() + +IF(EQEMU_FETCH_MSVC_DEPENDENCIES_PERL) + #Try to find perl first, (so you can use your active install first) + FIND_PACKAGE(PerlLibs) + + IF(NOT PerlLibs_FOUND) + MESSAGE(STATUS "Resolving perl dependencies...") + + IF(NOT EXISTS ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_ZIP}) + EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/perl) + EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}) + + MESSAGE(STATUS "Downloading portable perl...") + FILE(DOWNLOAD ${EQEMU_PERL_URL} ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_ZIP} + SHOW_PROGRESS + STATUS DOWNLOAD_STATUS) + + LIST(GET DOWNLOAD_STATUS 0 STATUS_CODE) + IF(NOT STATUS_CODE EQUAL 0) + MESSAGE(FATAL_ERROR "Was unable to download dependencies from ${EQEMU_PERL_URL}") + ENDIF() + + MESSAGE(STATUS "Extracting files...") + EXECUTE_PROCESS( + COMMAND ${CMAKE_COMMAND} -E tar xzf ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_ZIP} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR} + ) + ENDIF() + + SET(PERL_EXECUTABLE ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}/perl/bin/perl.exe CACHE FILEPATH "Path to perl program" FORCE) + SET(PERL_INCLUDE_PATH ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}/perl/lib/CORE CACHE PATH "Path to perl include files" FORCE) + SET(PERL_LIBRARY ${PROJECT_SOURCE_DIR}/perl/${EQEMU_PERL_DIR}/perl/lib/CORE/libperl524.a CACHE FILEPATH "Path to perl library" FORCE) + ENDIF() +ENDIF() \ No newline at end of file diff --git a/cmake/FindEQLua51.cmake b/cmake/FindEQLua51.cmake deleted file mode 100644 index 9f6663d56..000000000 --- a/cmake/FindEQLua51.cmake +++ /dev/null @@ -1,124 +0,0 @@ -#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) - - diff --git a/cmake/FindLua51.cmake b/cmake/FindLua51.cmake new file mode 100644 index 000000000..47fa0aaae --- /dev/null +++ b/cmake/FindLua51.cmake @@ -0,0 +1,91 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. +# Modified from the FindLua51 that comes with CMake + +#[=======================================================================[.rst: +FindLua51 +--------- + + + +Locate Lua51 library 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) + + + +Note that the expected include convention is + +:: + + #include "lua.h" + +and not + +:: + + #include + +This is because, the lua location is not standardized and may exist in +locations other than lua/ +#]=======================================================================] + +find_path(LUA_INCLUDE_DIR lua.h + HINTS + ENV LUA_DIR + PATH_SUFFIXES include/lua51 include/lua5.1 include/lua-5.1 include/lua include/luajit include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +find_library(LUA_LIBRARY + NAMES lua51 lua5.1 lua-5.1 lua luajit + HINTS + ENV LUA_DIR + PATH_SUFFIXES lib + PATHS + ~/Library/Frameworks + /Library/Frameworks + /sw + /opt/local + /opt/csw + /opt +) + +if(LUA_LIBRARY) + # include the math library for Unix + if(UNIX AND NOT APPLE AND NOT BEOS AND NOT HAIKU) + 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(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +# handle the QUIETLY and REQUIRED arguments and set LUA51_FOUND to TRUE if +# all listed variables are TRUE +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) + diff --git a/cmake/FindMariaDB.cmake b/cmake/FindMariaDB.cmake new file mode 100644 index 000000000..14f54734d --- /dev/null +++ b/cmake/FindMariaDB.cmake @@ -0,0 +1,87 @@ +# - 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 + ) diff --git a/cmake/FindmbedTLS.cmake b/cmake/FindmbedTLS.cmake new file mode 100644 index 000000000..d2a3ce3b9 --- /dev/null +++ b/cmake/FindmbedTLS.cmake @@ -0,0 +1,93 @@ +# - 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 +) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 32c64e7ca..c4dec4074 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(common_sources base_packet.cpp diff --git a/common/useperl.h b/common/useperl.h index a6345df5d..fb638be57 100644 --- a/common/useperl.h +++ b/common/useperl.h @@ -13,6 +13,10 @@ #ifndef WIN32 extern "C" { //the perl headers dont do this for us... #endif +#if _MSC_VER +#define __inline__ __inline +#define __builtin_expect +#endif #include #include #ifndef WIN32 diff --git a/eqlaunch/CMakeLists.txt b/eqlaunch/CMakeLists.txt index 260a2b5bc..c5e7bbd03 100644 --- a/eqlaunch/CMakeLists.txt +++ b/eqlaunch/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(eqlaunch_sources eqlaunch.cpp diff --git a/hc/CMakeLists.txt b/hc/CMakeLists.txt index 1aa5805d5..9f2c78298 100644 --- a/hc/CMakeLists.txt +++ b/hc/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(hc_sources eq.cpp @@ -13,14 +13,10 @@ SET(hc_headers world.h ) -FIND_PACKAGE(OpenSSL REQUIRED) - -INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - ADD_EXECUTABLE(hc ${hc_sources} ${hc_headers}) INSTALL(TARGETS hc RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -TARGET_LINK_LIBRARIES(hc ${SERVER_LIBS} ${OPENSSL_LIBRARIES}) +TARGET_LINK_LIBRARIES(hc ${SERVER_LIBS}) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/libs/luabind/CMakeLists.txt b/libs/luabind/CMakeLists.txt index de3b60c61..d29bb4bb1 100644 --- a/libs/luabind/CMakeLists.txt +++ b/libs/luabind/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(lb_sources src/class.cpp diff --git a/loginserver/CMakeLists.txt b/loginserver/CMakeLists.txt index 43217a48d..7d60655fc 100644 --- a/loginserver/CMakeLists.txt +++ b/loginserver/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(eqlogin_sources account_management.cpp @@ -28,14 +28,10 @@ SET(eqlogin_headers world_server.h ) -FIND_PACKAGE(OpenSSL REQUIRED) - -INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) - ADD_EXECUTABLE(loginserver ${eqlogin_sources} ${eqlogin_headers}) INSTALL(TARGETS loginserver RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) -TARGET_LINK_LIBRARIES(loginserver ${SERVER_LIBS} ${OPENSSL_LIBRARIES}) +TARGET_LINK_LIBRARIES(loginserver ${SERVER_LIBS}) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/loginserver/encryption.cpp b/loginserver/encryption.cpp index 27d22cca8..6450f7493 100644 --- a/loginserver/encryption.cpp +++ b/loginserver/encryption.cpp @@ -1,268 +1,306 @@ -/** - * EQEmulator: Everquest Server Emulator - * Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY except by those people which sell it, which - * are required to give you total support for your newly bought product; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - +#include "encryption.h" +#ifdef EQEMU_USE_OPENSSL #include #include #include +#endif +#ifdef EQEMU_USE_MBEDTLS +#include +#include +#include +#include +#endif #include #include - #ifdef ENABLE_SECURITY - #include - #endif -#include "encryption.h" +std::string GetEncryptionByModeId(uint32 mode) { + switch (mode) { + case EncryptionModeMD5: + return "MD5"; + case EncryptionModeMD5PassUser: + return "MD5PassUser"; + case EncryptionModeMD5UserPass: + return "MD5UserPass"; + case EncryptionModeMD5Triple: + return "MD5Triple"; + case EncryptionModeSHA: + return "SHA"; + case EncryptionModeSHAPassUser: + return "SHAPassUser"; + case EncryptionModeSHAUserPass: + return "SHAUserPass"; + case EncryptionModeSHATriple: + return "SHATriple"; + case EncryptionModeSHA512: + return "SHA512"; + case EncryptionModeSHA512PassUser: + return "SHA512PassUser"; + case EncryptionModeSHA512UserPass: + return "SHA512UserPass"; + case EncryptionModeSHA512Triple: + return "SHA512Triple"; + case EncryptionModeArgon2: + return "Argon2"; + case EncryptionModeSCrypt: + return "SCrypt"; + default: + return ""; + } +} -/** - * @param buffer_in - * @param buffer_in_sz - * @param buffer_out - * @param enc - * @return - */ -const char *eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char *buffer_out, bool enc) -{ +const char* eqcrypt_block(const char *buffer_in, size_t buffer_in_sz, char* buffer_out, bool enc) { +#ifdef EQEMU_USE_MBEDTLS + if (enc) { + if (buffer_in_sz % 8 != 0) { + auto temp_buffer_sz = ((buffer_in_sz / 8) + 1) * 8; + unsigned char *temp_buffer = new unsigned char[temp_buffer_sz]; + unsigned char *temp_buffer_in = &temp_buffer[0]; + unsigned char *temp_buffer_out = &temp_buffer[temp_buffer_sz]; + + memset(temp_buffer, 0, temp_buffer_sz * 2); + memcpy(temp_buffer_in, buffer_in, buffer_in_sz); + + unsigned char key[MBEDTLS_DES_KEY_SIZE]; + unsigned char iv[8]; + memset(&key, 0, MBEDTLS_DES_KEY_SIZE); + memset(&iv, 0, 8); + + mbedtls_des_context context; + mbedtls_des_setkey_enc(&context, key); + mbedtls_des_crypt_cbc(&context, MBEDTLS_DES_ENCRYPT, temp_buffer_sz, iv, (const unsigned char*)temp_buffer_in, (unsigned char*)temp_buffer_out); + + memcpy(buffer_out, temp_buffer_out, temp_buffer_sz); + delete[] temp_buffer; + } + else { + unsigned char key[MBEDTLS_DES_KEY_SIZE]; + unsigned char iv[8]; + memset(&key, 0, MBEDTLS_DES_KEY_SIZE); + memset(&iv, 0, 8); + + mbedtls_des_context context; + mbedtls_des_setkey_enc(&context, key); + mbedtls_des_crypt_cbc(&context, MBEDTLS_DES_ENCRYPT, buffer_in_sz, iv, (const unsigned char*)buffer_in, (unsigned char*)buffer_out); + } + } + else { + if (buffer_in_sz && buffer_in_sz % 8 != 0) { + return nullptr; + } + + unsigned char key[MBEDTLS_DES_KEY_SIZE]; + unsigned char iv[8]; + memset(&key, 0, MBEDTLS_DES_KEY_SIZE); + memset(&iv, 0, 8); + + mbedtls_des_context context; + mbedtls_des_setkey_dec(&context, key); + mbedtls_des_crypt_cbc(&context, MBEDTLS_DES_DECRYPT, buffer_in_sz, iv, (const unsigned char*)buffer_in, (unsigned char*)buffer_out); + } +#endif + +#ifdef EQEMU_USE_OPENSSL DES_key_schedule k; - DES_cblock v; - + DES_cblock v; + memset(&k, 0, sizeof(DES_key_schedule)); memset(&v, 0, sizeof(DES_cblock)); - + if (!enc && buffer_in_sz && buffer_in_sz % 8 != 0) { return nullptr; } - - DES_ncbc_encrypt((const unsigned char *) buffer_in, (unsigned char *) buffer_out, (long) buffer_in_sz, &k, &v, enc); + + DES_ncbc_encrypt((const unsigned char*)buffer_in, (unsigned char*)buffer_out, (long)buffer_in_sz, &k, &v, enc); +#endif return buffer_out; } -/** - * @param msg - * @return - */ -std::string eqcrypt_md5(const std::string &msg) -{ - std::string ret; - unsigned char md5_digest[16]; - char tmp[4]; +std::string eqcrypt_md5(const std::string &msg) { + std::string ret; + ret.reserve(32); + +#ifdef EQEMU_USE_MBEDTLS + unsigned char digest[16]; + char temp[4]; - MD5((const unsigned char *) msg.c_str(), msg.length(), md5_digest); + if (0 == mbedtls_md5_ret((const unsigned char*)msg.c_str(), msg.length(), digest)) { + for (int i = 0; i < 16; ++i) { + sprintf(&temp[0], "%02x", digest[i]); + ret.push_back(temp[0]); + ret.push_back(temp[1]); + } + } +#endif + +#ifdef EQEMU_USE_OPENSSL + unsigned char md5_digest[16]; + char tmp[4]; + + MD5((const unsigned char*)msg.c_str(), msg.length(), md5_digest); for (int i = 0; i < 16; ++i) { sprintf(&tmp[0], "%02x", md5_digest[i]); ret.push_back(tmp[0]); ret.push_back(tmp[1]); } +#endif return ret; } -/** - * @param msg - * @return - */ -std::string eqcrypt_sha1(const std::string &msg) -{ - std::string ret; - unsigned char sha_digest[20]; - char tmp[4]; +std::string eqcrypt_sha1(const std::string &msg) { + std::string ret; + ret.reserve(40); - SHA1((const unsigned char *) msg.c_str(), msg.length(), sha_digest); +#ifdef EQEMU_USE_MBEDTLS + unsigned char digest[20]; + char temp[4]; + + if (0 == mbedtls_sha1_ret((const unsigned char*)msg.c_str(), msg.length(), digest)) { + for (int i = 0; i < 20; ++i) { + sprintf(&temp[0], "%02x", digest[i]); + ret.push_back(temp[0]); + ret.push_back(temp[1]); + } + } +#endif + +#ifdef EQEMU_USE_OPENSSL + unsigned char sha_digest[20]; + char tmp[4]; + + SHA1((const unsigned char*)msg.c_str(), msg.length(), sha_digest); for (int i = 0; i < 20; ++i) { sprintf(&tmp[0], "%02x", sha_digest[i]); ret.push_back(tmp[0]); ret.push_back(tmp[1]); } +#endif return ret; } -/** - * @param msg - * @return - */ -std::string eqcrypt_sha512(const std::string &msg) -{ - std::string ret; - unsigned char sha_digest[64]; - char tmp[4]; +std::string eqcrypt_sha512(const std::string &msg) { + std::string ret; + ret.reserve(128); - SHA512((const unsigned char *) msg.c_str(), msg.length(), sha_digest); +#ifdef EQEMU_USE_MBEDTLS + unsigned char digest[64]; + char temp[4]; + + if (0 == mbedtls_sha512_ret((const unsigned char*)msg.c_str(), msg.length(), digest, 0)) { + for (int i = 0; i < 64; ++i) { + sprintf(&temp[0], "%02x", digest[i]); + ret.push_back(temp[0]); + ret.push_back(temp[1]); + } + } +#endif + +#ifdef EQEMU_USE_OPENSSL + unsigned char sha_digest[64]; + char tmp[4]; + + SHA512((const unsigned char*)msg.c_str(), msg.length(), sha_digest); for (int i = 0; i < 64; ++i) { sprintf(&tmp[0], "%02x", sha_digest[i]); ret.push_back(tmp[0]); ret.push_back(tmp[1]); } +#endif return ret; } #ifdef ENABLE_SECURITY -/** - * @param msg - * @return - */ std::string eqcrypt_argon2(const std::string &msg) { - char buffer[crypto_pwhash_STRBYTES]; + std::string ret; + ret.resize(crypto_pwhash_STRBYTES); - if (crypto_pwhash_str( - &buffer[0], - &msg[0], - msg.length(), - crypto_pwhash_OPSLIMIT_INTERACTIVE, - crypto_pwhash_MEMLIMIT_INTERACTIVE - ) != 0) { + if (crypto_pwhash_str(&ret[0], &msg[0], msg.length(), crypto_pwhash_OPSLIMIT_SENSITIVE, crypto_pwhash_MEMLIMIT_SENSITIVE) != 0) { return ""; } - return buffer; + return ret; } -/** - * @param msg - * @return - */ std::string eqcrypt_scrypt(const std::string &msg) { - char buffer[crypto_pwhash_scryptsalsa208sha256_STRBYTES]; + std::string ret; + ret.resize(crypto_pwhash_scryptsalsa208sha256_STRBYTES); - if (crypto_pwhash_scryptsalsa208sha256_str( - &buffer[0], &msg[0], msg.length(), - crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE - ) != 0) { + if (crypto_pwhash_scryptsalsa208sha256_str(&ret[0], &msg[0], msg.length(), + crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE, crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE) != 0) { return ""; } - return buffer; + return ret; } #endif -/** - * @param username - * @param password - * @param mode - * @return - */ -std::string eqcrypt_hash(const std::string &username, const std::string &password, int mode) -{ - switch (mode) { - case EncryptionModeMD5: - return eqcrypt_md5(password); - case EncryptionModeMD5PassUser: - return eqcrypt_md5(password + ":" + username); - case EncryptionModeMD5UserPass: - return eqcrypt_md5(username + ":" + password); - case EncryptionModeMD5Triple: - return eqcrypt_md5(eqcrypt_md5(username) + eqcrypt_md5(password)); - case EncryptionModeSHA: - return eqcrypt_sha1(password); - case EncryptionModeSHAPassUser: - return eqcrypt_sha1(password + ":" + username); - case EncryptionModeSHAUserPass: - return eqcrypt_sha1(username + ":" + password); - case EncryptionModeSHATriple: - return eqcrypt_sha1(eqcrypt_sha1(username) + eqcrypt_sha1(password)); - case EncryptionModeSHA512: - return eqcrypt_sha512(password); - case EncryptionModeSHA512PassUser: - return eqcrypt_sha512(password + ":" + username); - case EncryptionModeSHA512UserPass: - return eqcrypt_sha512(username + ":" + password); - case EncryptionModeSHA512Triple: - return eqcrypt_sha512(eqcrypt_sha512(username) + eqcrypt_sha512(password)); +std::string eqcrypt_hash(const std::string &username, const std::string &password, int mode) { + switch (mode) + { + case 1: + return eqcrypt_md5(password); + case 2: + return eqcrypt_md5(password + ":" + username); + case 3: + return eqcrypt_md5(username + ":" + password); + case 4: + return eqcrypt_md5(eqcrypt_md5(username) + eqcrypt_md5(password)); + case 5: + return eqcrypt_sha1(password); + case 6: + return eqcrypt_sha1(password + ":" + username); + case 7: + return eqcrypt_sha1(username + ":" + password); + case 8: + return eqcrypt_sha1(eqcrypt_sha1(username) + eqcrypt_sha1(password)); + case 9: + return eqcrypt_sha512(password); + case 10: + return eqcrypt_sha512(password + ":" + username); + case 11: + return eqcrypt_sha512(username + ":" + password); + case 12: + return eqcrypt_sha512(eqcrypt_sha512(username) + eqcrypt_sha512(password)); #ifdef ENABLE_SECURITY - case EncryptionModeArgon2: - return eqcrypt_argon2(password); - case EncryptionModeSCrypt: - return eqcrypt_scrypt(password); + case 13: + return eqcrypt_argon2(password); + case 14: + return eqcrypt_scrypt(password); #endif - //todo bcrypt? pbkdf2? - default: - return ""; - break; + //todo bcrypt? pbkdf2? + default: + return ""; + break; } } -/** - * @param username - * @param password - * @param pwhash - * @param mode - * @return - */ -bool eqcrypt_verify_hash(const std::string &username, const std::string &password, const std::string &pwhash, int mode) -{ - switch (mode) { +bool eqcrypt_verify_hash(const std::string &username, const std::string &password, const std::string &pwhash, int mode) { + switch (mode) + { #ifdef ENABLE_SECURITY - case 13: - return crypto_pwhash_str_verify(&pwhash[0], &password[0], password.length()) == 0; - case 14: - return crypto_pwhash_scryptsalsa208sha256_str_verify(&pwhash[0], &password[0], password.length()) == 0; + case 13: + return crypto_pwhash_str_verify(&pwhash[0], &password[0], password.length()) == 0; + case 14: + return crypto_pwhash_scryptsalsa208sha256_str_verify(&pwhash[0], &password[0], password.length()) == 0; #endif - default: { - auto hash = eqcrypt_hash(username, password, mode); - return hash.compare(pwhash) == 0; - } + default: + { + auto hash = eqcrypt_hash(username, password, mode); + return hash.compare(pwhash) == 0; + } } return false; } - -std::string GetEncryptionByModeId(uint32 mode) { - switch (mode) { - case EncryptionModeMD5: - return "MD5"; - case EncryptionModeMD5PassUser: - return "MD5PassUser"; - case EncryptionModeMD5UserPass: - return "MD5UserPass"; - case EncryptionModeMD5Triple: - return "MD5Triple"; - case EncryptionModeSHA: - return "SHA"; - case EncryptionModeSHAPassUser: - return "SHAPassUser"; - case EncryptionModeSHAUserPass: - return "SHAUserPass"; - case EncryptionModeSHATriple: - return "SHATriple"; - case EncryptionModeSHA512: - return "SHA512"; - case EncryptionModeSHA512PassUser: - return "SHA512PassUser"; - case EncryptionModeSHA512UserPass: - return "SHA512UserPass"; - case EncryptionModeSHA512Triple: - return "SHA512Triple"; - case EncryptionModeArgon2: - return "Argon2"; - case EncryptionModeSCrypt: - return "SCrypt"; - default: - return ""; - } -} \ No newline at end of file diff --git a/queryserv/CMakeLists.txt b/queryserv/CMakeLists.txt index 393747a91..15c900e53 100644 --- a/queryserv/CMakeLists.txt +++ b/queryserv/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(qserv_sources database.cpp diff --git a/shared_memory/CMakeLists.txt b/shared_memory/CMakeLists.txt index 1844df758..6902a8b83 100644 --- a/shared_memory/CMakeLists.txt +++ b/shared_memory/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(shared_memory_sources base_data.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b404bab99..e7b97b57f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) ADD_SUBDIRECTORY(cppunit) diff --git a/tests/cppunit/CMakeLists.txt b/tests/cppunit/CMakeLists.txt index e60e2134f..16747f785 100644 --- a/tests/cppunit/CMakeLists.txt +++ b/tests/cppunit/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(cppunit_sources collectoroutput.cpp diff --git a/ucs/CMakeLists.txt b/ucs/CMakeLists.txt index e09e12781..a1c0b32b4 100644 --- a/ucs/CMakeLists.txt +++ b/ucs/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(ucs_sources chatchannel.cpp diff --git a/wi/.gitignore b/wi/.gitignore deleted file mode 100644 index b449f1759..000000000 --- a/wi/.gitignore +++ /dev/null @@ -1,47 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules -jspm_packages - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity diff --git a/wi/BUILD.md b/wi/BUILD.md deleted file mode 100644 index a3fa9a989..000000000 --- a/wi/BUILD.md +++ /dev/null @@ -1,17 +0,0 @@ -# Building EQEmu Web Interface Reference Implementation - -## Required Software -- [NodeJS](https://nodejs.org) - -## Install - -First: Make sure you have required software installed. - -Install 3rd Party Libraries first with the following command: - npm install - - -## Run - -Run with either your favorite NodeJS process manager or with the following command: - node . \ No newline at end of file diff --git a/wi/core/jwt_auth.js b/wi/core/jwt_auth.js deleted file mode 100644 index f63f22346..000000000 --- a/wi/core/jwt_auth.js +++ /dev/null @@ -1,27 +0,0 @@ -const jwt = require('jsonwebtoken'); - -var Auth = function (req, res, next) { - var token = ''; - try { - token = req.headers.authorization.substring(7); - } catch(ex) { - console.log(ex); - res.sendStatus(401); - return; - } - - jwt.verify(token, req.key, function(err, decoded) { - if(err) { - console.log(err); - res.sendStatus(401); - return; - } - - req.token = decoded; - next(); - }); -}; - -module.exports = { - 'auth': Auth -} diff --git a/wi/generate_pw_hash.js b/wi/generate_pw_hash.js deleted file mode 100644 index 6648e48c3..000000000 --- a/wi/generate_pw_hash.js +++ /dev/null @@ -1,4 +0,0 @@ -var sodium = require('libsodium-wrappers-sumo'); - -var hash = sodium.crypto_pwhash_str('password', 3, 32768); -console.log(hash); \ No newline at end of file diff --git a/wi/http/common.js b/wi/http/common.js deleted file mode 100644 index c049520e9..000000000 --- a/wi/http/common.js +++ /dev/null @@ -1,26 +0,0 @@ -var auth = require('../core/jwt_auth.js').auth; - -function RegisterFunction(path, fn, app, api) { - app.post(path, auth, function (req, res) { - var params = req.body.params || []; - - api.Call(fn, params) - .then(function(value) { - res.send({ response: value }); - }) - .catch(function(reason) { - if(reason.message) { - res.send({ status: reason.message }); - } - else if(reason === 'Not connected to world server.') { - res.send({ status: 'ENCONNECTED' }); - } else { - res.sendStatus(500); - } - }); - }); -} - -module.exports = { - 'Register': RegisterFunction -} \ No newline at end of file diff --git a/wi/http/data/account.js b/wi/http/data/account.js deleted file mode 100644 index 29cf1e2f8..000000000 --- a/wi/http/data/account.js +++ /dev/null @@ -1,16 +0,0 @@ -var endpoint = require('./endpoint.js'); -var auth = require('../../core/jwt_auth.js').auth; -var sql = require('./sql.js'); - -var RegisterAPI = function(app, api) { - endpoint.Register(app, api, 'account', 'account', 'id'); - - //Can register custom controller actions here. - app.post('/api/data/account/search', auth, function (req, res) { - sql.Search(req, res, 'account', 'id', ['id', 'name']); - }); -}; - -module.exports = { - 'Register': RegisterAPI -} \ No newline at end of file diff --git a/wi/http/data/endpoint.js b/wi/http/data/endpoint.js deleted file mode 100644 index 574ea56ec..000000000 --- a/wi/http/data/endpoint.js +++ /dev/null @@ -1,20 +0,0 @@ -var auth = require('../../core/jwt_auth.js').auth; -var sql = require('./sql.js'); - -var RegisterEndpoint = function(app, api, endpoint_verb, table_name, pkey) { - app.get('/api/data/' + endpoint_verb + '/:' + pkey, auth, function (req, res) { - sql.Retrieve(req, res, table_name, pkey); - }); - - app.put('/api/data/' + endpoint_verb + '/:' + pkey, auth, function (req, res) { - sql.CreateUpdate(req, res, table_name, pkey); - }); - - app.delete('/api/data/' + endpoint_verb + '/:' + pkey, auth, function (req, res) { - sql.Delete(req, res, table_name, pkey); - }); -}; - -module.exports = { - 'Register': RegisterEndpoint -} diff --git a/wi/http/data/index.js b/wi/http/data/index.js deleted file mode 100644 index b9bd6bc0e..000000000 --- a/wi/http/data/index.js +++ /dev/null @@ -1,8 +0,0 @@ -var RegisterAPI = function(app, api) { - require('./account.js').Register(app, api); - require('./item.js').Register(app, api); -}; - -module.exports = { - 'Register': RegisterAPI -} \ No newline at end of file diff --git a/wi/http/data/item.js b/wi/http/data/item.js deleted file mode 100644 index f88d80bfa..000000000 --- a/wi/http/data/item.js +++ /dev/null @@ -1,16 +0,0 @@ -var endpoint = require('./endpoint.js'); -var auth = require('../../core/jwt_auth.js').auth; -var sql = require('./sql.js'); - -var RegisterAPI = function(app, api) { - endpoint.Register(app, api, 'item', 'items', 'id'); - - //Can register custom controller actions here. - app.post('/api/data/item/search', auth, function (req, res) { - sql.Search(req, res, 'items', 'id', ['id', 'name', 'icon']); - }); -}; - -module.exports = { - 'Register': RegisterAPI -} \ No newline at end of file diff --git a/wi/http/data/sql.js b/wi/http/data/sql.js deleted file mode 100644 index 22416f3ba..000000000 --- a/wi/http/data/sql.js +++ /dev/null @@ -1,319 +0,0 @@ -var moment = require('moment'); - -function CreateReplace(table, body, fields) { - try { - var query = 'REPLACE INTO ' + table + ' VALUES('; - var first = true; - var args = []; - - for(var idx in fields) { - if(first) { - first = false; - } else { - query += ','; - } - - query += '?'; - - var entry = fields[idx]; - if(entry.type === 12) { - try { - var d = new moment(body[entry.name]); - - if(d.isValid()) { - args.push(d.format('YYYY-MM-DD HH:mm:ss')); - } else { - args.push(null); - } - } catch(ex) { - args.push(null); - } - } else { - args.push(body[entry.name]); - } - } - - query += ')'; - - return { 'query': query, 'args': args }; - } catch(ex) { - return { 'query': '', 'args': [] }; - } -} - -function CreateUpdate(req, res, table, pkey) { - req.mysql.getConnection(function(err, connection) { - try { - if(err) { - console.log(err); - connection.release(); - res.sendStatus(500); - return; - } - - if(req.body[pkey] !== parseInt(req.params[pkey], 10)) { - connection.release(); - res.sendStatus(400); - return; - } - - connection.query('SELECT * FROM ' + table + ' WHERE ' + pkey + '=? LIMIT 1', [req.params[pkey]], function (error, results, fields) { - try { - if(error) { - console.log(error); - connection.release(); - res.sendStatus(400); - return; - } - - var replace = CreateReplace(table, req.body, fields); - if(replace.query === '') { - connection.release(); - res.sendStatus(400); - return; - } - - connection.query(replace.query, replace.args, function(error, results, fields) { - try { - if(error) { - console.log(error); - connection.release(); - res.sendStatus(400); - return; - } - - connection.release(); - res.sendStatus(200); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); -} - -function Retrieve(req, res, table, pkey) { - req.mysql.getConnection(function(err, connection) { - try { - if(err) { - console.log(err); - connection.release(); - res.sendStatus(500); - return; - } - - connection.query('SELECT * FROM ' + table + ' WHERE ' + pkey + '=? LIMIT 1', [req.params[pkey]], function (error, results, fields) { - try { - if(results.length == 0) { - connection.release(); - res.sendStatus(404); - return; - } - - var result = results[0]; - var ret = { }; - - for(var idx in result) { - var value = result[idx]; - ret[idx] = value; - } - - connection.release(); - res.json(ret); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); -} - -function Delete(req, res, table, pkey) { - req.mysql.getConnection(function(err, connection) { - try { - if(err) { - console.log(err); - connection.release(); - res.sendStatus(500); - return; - } - - connection.query('DELETE FROM ' + table + ' WHERE ' + pkey + '=? LIMIT 1', [req.params[pkey]], function (error, results, fields) { - try { - if(error) { - console.log(error); - connection.release(); - res.sendStatus(400); - return; - } - - connection.release(); - res.sendStatus(200); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); -} - -function getLimit(req, columns) { - var limit = ''; - - var len = parseInt(req.body['length']); - if(len > 100) { - len = 100; - } - - if(req.body.hasOwnProperty('start') && len != -1) { - limit = 'LIMIT ' + req.body['start'] + ', ' + req.body['length']; - } - - return limit; -} - -function getOrder(req, columns) { - var order = ''; - - if (req.body.hasOwnProperty('order') && req.body['order'].length) { - var orderBy = []; - for(var i = 0; i < req.body['order'].length; ++i) { - var columnIdx = parseInt(req.body['order'][i].column); - var column = req.body['columns'][columnIdx]; - var columnId = column.data; - var dir = req.body['order'][i].dir === 'asc' ? 'ASC' : 'DESC'; - orderBy.push(req.mysql.escapeId(columnId) + ' ' + dir); - } - - order = 'ORDER BY ' + orderBy.join(','); - } - - return order; -} - -function filter(req, columns, args) { - var where = ''; - var globalSearch = []; - var columnSearch = []; - - if (req.body.hasOwnProperty('search') && req.body['search'].value.length) { - var searchTerm = req.body['search'].value; - for(var i = 0; i < req.body['columns'].length; ++i) { - var column = req.body['columns'][i]; - - if(column.searchable) { - globalSearch.push(req.mysql.escapeId(column.data) + ' LIKE ?'); - args.push('%' + searchTerm + '%'); - } - } - } - - for(var i = 0; i < req.body['columns'].length; ++i) { - var column = req.body['columns'][i]; - var searchTerm = column.search.value; - - if(searchTerm !== '' && column.searchable) { - columnSearch.push(req.mysql.escapeId(column.data) + ' LIKE ?'); - args.push('%' + searchTerm + '%'); - } - } - - if(globalSearch.length) { - where = globalSearch.join(' OR '); - } - - if(columnSearch.length) { - if(where === '') { - where = columnSearch.join(' AND '); - } else { - where += ' AND '; - where += columnSearch.join(' AND '); - } - } - - if(where !== '') { - where = 'WHERE ' + where; - } - - return where; -} - -function Search(req, res, table, pkey, columns) { - var args = []; - var limit = getLimit(req, columns); - var order = getOrder(req, columns); - var where = filter(req, columns, args); - - var query = 'SELECT ' + columns.join(', ') + ' FROM ' + table + ' ' + where + ' ' + order + ' ' + limit; - - req.mysql.getConnection(function(err, connection) { - try { - if(err) { - console.log(err); - connection.release(); - res.sendStatus(500); - return; - } - - connection.query(query, args, function (error, results, fields) { - try { - var ret = []; - - for(var i in results) { - var result = results[i]; - - var obj = { }; - for(var idx in result) { - var value = result[idx]; - obj[idx] = value; - } - - ret.push(obj); - } - - connection.release(); - res.json(ret); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); - } catch(ex) { - console.log(ex); - connection.release(); - res.sendStatus(500); - } - }); -}; - -module.exports = { - 'CreateUpdate': CreateUpdate, - 'Retrieve': Retrieve, - 'Delete': Delete, - 'Search': Search, -} \ No newline at end of file diff --git a/wi/http/eqw.js b/wi/http/eqw.js deleted file mode 100644 index 9a72e6114..000000000 --- a/wi/http/eqw.js +++ /dev/null @@ -1,16 +0,0 @@ -const common = require('./common.js'); - -var RegisterEQW = function(app, api) { - common.Register('/api/eqw/getconfig', 'EQW::GetConfig', app, api); - common.Register('/api/eqw/islocked', 'EQW::IsLocked', app, api); - common.Register('/api/eqw/lock', 'EQW::Lock', app, api); - common.Register('/api/eqw/unlock', 'EQW::Unlock', app, api); - common.Register('/api/eqw/getplayercount', 'EQW::GetPlayerCount', app, api); - common.Register('/api/eqw/getzonecount', 'EQW::GetZoneCount', app, api); - common.Register('/api/eqw/getlaunchercount', 'EQW::GetLauncherCount', app, api); - common.Register('/api/eqw/getloginservercount', 'EQW::GetLoginServerCount', app, api); -}; - -module.exports = { - 'Register': RegisterEQW -} diff --git a/wi/http/index.js b/wi/http/index.js deleted file mode 100644 index 46e2f6d71..000000000 --- a/wi/http/index.js +++ /dev/null @@ -1,9 +0,0 @@ -var RegisterAPI = function(app, api) { - require('./eqw.js').Register(app, api); - require('./token.js').Register(app); - require('./data').Register(app, api); -}; - -module.exports = { - 'Register': RegisterAPI -} \ No newline at end of file diff --git a/wi/http/token.js b/wi/http/token.js deleted file mode 100644 index a3815121f..000000000 --- a/wi/http/token.js +++ /dev/null @@ -1,43 +0,0 @@ -const sodium = require('libsodium-wrappers-sumo'); -const jwt = require('jsonwebtoken'); - -var RegisterToken = function(app) { - app.post('/api/token', function (req, res) { - try { - req.mysql.getConnection(function(err, connection) { - if(err) { - console.log(err); - res.sendStatus(500); - connection.release(); - return; - } - - connection.query('SELECT password FROM account WHERE name = ? LIMIT 1', [req.body.username], function (error, results, fields) { - if(results.length == 0) { - res.sendStatus(401); - connection.release(); - return; - } - - - if(sodium.crypto_pwhash_str_verify(results[0].password, req.body.password)) { - var expires = Math.floor(Date.now() / 1000) + (60 * 60 * 24 * 7); - var token = jwt.sign({ username: req.body.username, exp: expires }, req.key); - res.send({token: token, expires: expires}); - connection.release(); - } else { - res.sendStatus(401); - connection.release(); - } - }); - }); - } catch(ex) { - res.sendStatus(500); - console.log(ex); - } - }); -}; - -module.exports = { - 'Register': RegisterToken -} \ No newline at end of file diff --git a/wi/index.js b/wi/index.js deleted file mode 100644 index 822592b8d..000000000 --- a/wi/index.js +++ /dev/null @@ -1,56 +0,0 @@ -const fs = require('fs'); -const settings = JSON.parse(fs.readFileSync('settings.json', 'utf8')); -const key = fs.readFileSync(settings.key, 'utf8'); - -var server; -if(settings.https.enabled) { - const options = { - key: fs.readFileSync(settings.https.key), - cert: fs.readFileSync(settings.https.cert) - }; - - server = require('https').createServer(); -} else { - server = require('http').createServer(); -} - -const servertalk = require('./network/servertalk_api.js'); -const websocket_iterface = require('./ws/ws_interface.js'); -const express = require('express'); -const app = express(); -const bodyParser = require('body-parser'); -const uuid = require('node-uuid'); -const jwt = require('jsonwebtoken'); -var mysql = require('mysql').createPool(settings.db); - -var api = new servertalk.api(); -var wsi = new websocket_iterface.wsi(server, key, api); -api.Init(settings.servertalk.addr, settings.servertalk.port, false, settings.servertalk.key); - -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: true })); - -app.use(function(req, res, next) { - res.header("Access-Control-Allow-Origin", "*"); - res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT"); - res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); - next(); -}); - -//make sure all routes can see our injected dependencies -app.use(function (req, res, next) { - req.servertalk = api; - req.mysql = mysql; - req.key = key; - next(); -}); - -app.get('/', function (req, res) { - res.send({ status: "online" }); -}); - -require('./http').Register(app, api); -require('./ws').Register(wsi, api); - -server.on('request', app); -server.listen(settings.port, function () { console.log('Listening on ' + server.address().port) }); diff --git a/wi/key.pem b/wi/key.pem deleted file mode 100644 index 1f0cbdc91..000000000 --- a/wi/key.pem +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEowIBAAKCAQEAoijNhaW4sH2yLEQOUCNLSU0qIGnr9mxewEPXSNURKFExC1WE -ah983xy+WTbKjakH6Rp2OwCvLxNIu6QBKRgcJ963ICWY7ysn4bU2Q2KoSJgAEel8 -UMDHWYfyyAPdr4DUwUw7YMf4LBThCGBC5DTPilZiVqQNyOf8KL5w/oKcavVMddod -eBNE1ewoxVveHN6WUDkYQKZK2AsrpNG6TjfJc3wI3Z722tRHui4E772l/sD0SuEj -41pBzOG0VM7DHwUpHQosnvnwx9kjefPNE/uvo14PuzP5yYG2h2PFkQ7uuXjK2/le -iVcyap/zgheOHjlYmOJGT1cnVSodv+rY56eilwIDAQABAoIBAQAM/sAZqcI3Qpt4 -uKt8+Jcb9Lcfid2DDgQ53DXwfEK3vGn1wpCuAH/9UUxf0ehBmf4sTBaVe+SOHTmC -8A23wVrgRxTd2qV65TZ4/BCxLcLWrney98cioZBYOHDYXpbxbZ2fMADCLMRSpAm0 -piI2L5VCPNH8p4EDTLQEf96GRulKGOWETeVNai3C7Ept6Fxv0YIiiER8j2oPsb1O -LVCBKBPsNs0IlabJAzfDnaqdfWzuLWIT0L4w/qvzfwkdM8tVxch2zjEVosbz4ser -rPO3tle3mobgDvXrW9jEYkIpOtEqCS7l4ybidVuEfY55KlkZ7rGBQ2N1jbLvKjb5 -AUyHUBchAoGBAOKjzzBPB/mofycF8iF1QJwripGTDUGM7aXBS0Clp4mh0ksvBsUf -Zg+Qnzr2xZaN53lU65xQlMrebMJow4iJj71VesF9FWPPNbIhh7eMTX4pABcKZNvc -Y0iFf5XZAl3LFdDocQSuB3j5WLNrjSFMBZuYUiZhgiRadtcdpQr+O4lbAoGBALcq -ltbFogxXoo7/CIajbYdNUGbba96jQMOzC1D7yeim1MTtDNGs56ZhDjFZepMRMyfX -/Z7iqxjZQQ1m1THtuiM4g+ug08EYI8G/7DYO5DqMABGFb3vKU9ilhYASqfznpKMJ -2sl/d5j8ocS7crkKwR8Tbo3ZG8NgObQNTL+mIFR1AoGAJS66zzIoHM2IDt7q2pJi -Bz0dfsShaB+23XrY3cJPukTSO4N7mNuN4v/XH9VclVayozVLclnGD4JuVXbanYv0 -CRv9B8F9wOI97PuTSIm8LPaNDTqnUWrW3w8H34261ah768o2wI3MrAw8gTMj9FKE -mQJkd+eHcm9lD+XNLgCHxAECgYBiMQ2t00L89NnraKLscp4b44GPsl9QehoVD12o -q2JhO1Ziv2WY3eVNV0hhgkNopdbTrEGFNKRebNEn2xG9c2DO0tQ9s/jw0f0RN87s -Z+1HyZebzPmn1h4+zPUVZGwGbTPgRz8nuBKoS/541bg5pJ9FBojEuDfe9C3a7SpQ -r0EzpQKBgBmYrKi07wTUSZ3TjHWvOK75XhJ5pOdfbuDZk+N02jzhmihzI2M/Sh7s -l1gavtY9o9JGUAW35L/Ju4X1Xgm3t5Cg9+4n6ecOfSKP9nJpgj1EvHyWvw9t8ZSg -V9M0Hf5EoSPWuEj+mlWrIuvV/HgkouUVqDzUm6wUuyTqdTCgUQrA ------END RSA PRIVATE KEY----- diff --git a/wi/network/servertalk_api.js b/wi/network/servertalk_api.js deleted file mode 100644 index be4220edf..000000000 --- a/wi/network/servertalk_api.js +++ /dev/null @@ -1,148 +0,0 @@ -const servertalk = require('./servertalk_client.js'); -const uuid = require('node-uuid'); - -class ServertalkAPI -{ - Init(addr, port, ipv6, credentials) { - this.client = new servertalk.client(); - this.client.Init(addr, port, ipv6, 'WebInterface', credentials); - this.pending_calls = {}; - this.subscriptions = {}; - var self = this; - - this.client.on('connecting', function() { - //console.log('Connecting...'); - }); - - this.client.on('connect', function(){ - //console.log('Connected'); - }); - - this.client.on('close', function(){ - //console.log('Closed'); - }); - - this.client.on('error', function(err){ - }); - - this.client.on('message', function(opcode, packet) { - if(opcode == 47) { - var response = Buffer.from(packet).toString('utf8'); - try { - var res = JSON.parse(response); - - if(res.id) { - if(self.pending_calls.hasOwnProperty(res.id)) { - var entry = self.pending_calls[res.id]; - - if(res.error) { - var reject = entry[1]; - reject(res.error); - } else { - var resolve = entry[0]; - resolve(res.response); - } - - delete self.pending_calls[res.id]; - } - } - } catch(ex) { - console.log('Error processing response from server:\n', ex); - } - } else if(opcode == 104) { - var message = Buffer.from(packet).toString('utf8'); - try { - var msg = JSON.parse(message); - - if(msg.event) { - if(self.subscriptions.hasOwnProperty(msg.event)) { - var subs = self.subscriptions[msg.event]; - - for(var idx in subs) { - try { - var sub = subs[idx]; - sub.emit('subscriptionMessage', msg); - } catch(ex) { - console.log('Error dispatching subscription message', ex); - } - } - } - } - } catch(ex) { - console.log('Error processing response from server:\n', ex); - } - } - }); - } - - Call(method, args, timeout) { - if(!timeout) { - timeout = 15000 - } - - var self = this; - return new Promise( - function(resolve, reject) { - if(!self.client.Connected()) { - reject('Not connected to world server.'); - return; - } - - var id = uuid.v4(); - - self.pending_calls[id] = [resolve, reject]; - - var c = { id: id, method: method, params: args }; - self.client.Send(47, Buffer.from(JSON.stringify(c))); - - setTimeout(function() { - delete self.pending_calls[id]; - reject('Request timed out after ' + timeout + 'ms'); - }, timeout); - } - ); - } - - Notify(method, args) { - var c = { method: method, params: args }; - client.Send(47, Buffer.from(JSON.stringify(c))); - } - - Subscribe(event_id, who) { - this.Unsubscribe(event_id, who); - - var subs = this.subscriptions[event_id]; - if(subs) { - //console.log('Subscribe', who.uuid, 'to', event_id); - subs[who.uuid] = who; - } else { - //console.log('Subscribe', who.uuid, 'to', event_id); - this.subscriptions[event_id] = { }; - this.subscriptions[event_id][who.uuid] = who; - //Tell our server we have a subscription for event_id - } - } - - Unsubscribe(event_id, who) { - var subs = this.subscriptions[event_id]; - if(subs) { - //console.log('Unsubscribe', who.uuid, 'from', event_id); - delete subs[who.uuid]; - - if(Object.keys(subs).length === 0) { - delete this.subscriptions[event_id]; - //Tell our server we no longer have a subscription for event_id - } - } - } - - UnsubscribeAll(who) { - for(var sub_idx in this.subscriptions) { - this.Unsubscribe(sub_idx, who); - } - } -} - -module.exports = { - 'api': ServertalkAPI -} \ No newline at end of file diff --git a/wi/network/servertalk_client.js b/wi/network/servertalk_client.js deleted file mode 100644 index 4197a1aa4..000000000 --- a/wi/network/servertalk_client.js +++ /dev/null @@ -1,299 +0,0 @@ -var net = require('net'); -var sodium = require('libsodium-wrappers'); -const EventEmitter = require('events'); - -var ServertalkPacketType = -{ - ServertalkClientHello: 1, - ServertalkServerHello: 2, - ServertalkClientHandshake: 3, - ServertalkClientDowngradeSecurityHandshake: 4, - ServertalkMessage: 5, -}; - -class ServertalkClient extends EventEmitter -{ - Init(addr, port, ipv6, identifier, credentials) { - this.m_addr = addr; - this.m_identifier = identifier; - this.m_credentials = credentials; - this.m_connecting = false; - this.m_port = port; - this.m_ipv6 = ipv6; - this.m_encrypted = false; - this.m_connection = null; - this.m_buffer = Buffer.alloc(0); - this.m_public_key_ours = null; - this.m_private_key_ours = null; - this.m_nonce_ours = null; - this.m_public_key_theirs = null; - this.m_nonce_theirs = null; - this.m_shared_key = null; - - var self = this; - setInterval(function() { self.Connect(); }, 100); - } - - Send(opcode, p) { - try { - var out; - if(this.m_encrypted) { - if(p.length == 0) { - p = Buffer.alloc(1); - } - - out = Buffer.alloc(6); - out.writeUInt32LE(p.length + sodium.crypto_secretbox_MACBYTES, 0); - out.writeUInt16LE(opcode, 4); - - var cipher = sodium.crypto_box_easy_afternm(p, this.m_nonce_ours, this.m_shared_key); - this.IncrementUint64(this.m_nonce_ours); - - out = Buffer.concat([out, Buffer.from(cipher)], out.length + cipher.length); - } else { - out = Buffer.alloc(6); - out.writeUInt32LE(p.length, 0); - out.writeUInt16LE(opcode, 4); - out = Buffer.concat([out, p], out.length + p.length); - } - - this.InternalSend(ServertalkPacketType.ServertalkMessage, out); - } catch(ex) { - this.emit('error', new Error(ex)); - } - } - - Connected() { - return this.m_connection && !this.m_connecting; - } - - Connect() { - if (this.m_port == 0 || this.m_connection || this.m_connecting) { - return; - } - - this.m_connecting = true; - - this.emit('connecting'); - - var self = this; - this.m_connection = net.connect({port: this.m_port, host: this.m_addr}, function() { - self.m_connection.on('close', function(had_error) { - self.emit('close'); - self.m_connection = null; - self.m_encrypted = false; - }); - - self.m_connection.on('data', function(buffer) { - self.ProcessData(buffer); - }); - - self.SendHello(); - self.m_connecting = false; - }); - - this.m_connection.on('error', function() { - self.emit('close'); - self.m_connection = null; - self.m_connecting = false; - }); - } - - ProcessData(buffer) { - this.m_buffer = Buffer.concat([this.m_buffer, buffer], this.m_buffer.length + buffer.length); - this.ProcessReadBuffer(); - } - - SendHello() { - var p = Buffer.alloc(0); - this.InternalSend(ServertalkPacketType.ServertalkClientHello, p); - } - - InternalSend(type, p) { - if(!this.m_connection) { - return; - } - - var out = Buffer.alloc(5); - out.writeUInt32LE(p.length, 0); - out.writeUInt8(type, 4); - - if (p.length > 0) { - out = Buffer.concat([out, p], out.length + p.length); - } - - this.m_connection.write(out); - } - - ProcessReadBuffer() { - var current = 0; - var total = this.m_buffer.length; - - while (current < total) { - var left = total - current; - - var length = 0; - var type = 0; - if (left < 5) { - break; - } - - length = this.m_buffer.readUInt32LE(current); - type = this.m_buffer.readUInt8(current + 4); - - if (current + 5 + length > total) { - break; - } - - if (length == 0) { - var p = Buffer.alloc(0); - switch (type) { - case ServertalkPacketType.ServertalkServerHello: - this.ProcessHello(p); - break; - case ServertalkPacketType.ServertalkMessage: - this.ProcessMessage(p); - break; - } - } - else { - var p = this.m_buffer.slice(current + 5, current + 5 + length); - switch (type) { - case ServertalkPacketType.ServertalkServerHello: - this.ProcessHello(p); - break; - case ServertalkPacketType.ServertalkMessage: - this.ProcessMessage(p); - break; - } - } - - current += length + 5; - } - - if (current == total) { - this.m_buffer = Buffer.alloc(0); - } - else { - this.m_buffer = this.m_buffer.slice(current); - } - } - - ProcessHello(p) { - this.m_encrypted = false; - this.m_public_key_ours = null; - this.m_public_key_theirs = null; - this.m_private_key_ours = null; - this.m_nonce_ours = null; - this.m_nonce_theirs = null; - this.m_shared_key = null; - - try { - var enc = p.readUInt8(0) == 1 ? true : false; - if (enc) { - if (p.length == (1 + sodium.crypto_box_PUBLICKEYBYTES + sodium.crypto_box_NONCEBYTES)) { - this.m_public_key_theirs = p.slice(1, 1 + sodium.crypto_box_PUBLICKEYBYTES); - this.m_nonce_theirs = p.slice(1 + sodium.crypto_box_PUBLICKEYBYTES, 1 + sodium.crypto_box_PUBLICKEYBYTES + sodium.crypto_box_NONCEBYTES); - this.m_encrypted = true; - this.SendHandshake(false); - - this.emit('connect'); - } - else { - this.emit('error', new Error('Could not process hello, size !=', 1 + sodium.crypto_box_PUBLICKEYBYTES + sodium.crypto_box_NONCEBYTES)); - } - } else { - this.SendHandshake(false); - - this.emit('connect'); - } - } catch(ex) { - this.emit('error', new Error(ex)); - } - } - - ProcessMessage(p) { - try { - var length = p.readUInt32LE(0); - var opcode = p.readUInt16LE(4); - if(length > 0) { - var data = p.slice(6); - - if(this.m_encrypted) { - var message_len = length - sodium.crypto_secretbox_MACBYTES; - - var decrypted = sodium.crypto_box_open_easy_afternm(data, this.m_nonce_theirs, this.m_shared_key); - - this.IncrementUint64(this.m_nonce_theirs); - - this.emit('message', opcode, decrypted); - } else { - this.emit('message', opcode, data); - } - } else { - this.emit('message', opcode, Buffer.alloc(0)); - } - } catch(ex) { - this.emit('error', new Error(ex)); - } - } - - SendHandshake() { - var handshake; - - if(this.m_encrypted) { - var keypair = sodium.crypto_box_keypair(); - this.m_public_key_ours = keypair.publicKey; - this.m_private_key_ours = keypair.privateKey; - this.m_nonce_ours = Buffer.from(sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES)); - this.m_shared_key = sodium.crypto_box_beforenm(this.m_public_key_theirs, this.m_private_key_ours); - - this.m_public_key_theirs = null; - this.m_private_key_ours = null; - - var message = Buffer.alloc(this.m_identifier.length + this.m_credentials.length + 2); - message.write(this.m_identifier, 0); - message.write(this.m_credentials, this.m_identifier.length + 1); - - var ciphertext = sodium.crypto_box_easy_afternm(message, this.m_nonce_ours, this.m_shared_key); - - handshake = Buffer.concat([Buffer.from(this.m_public_key_ours), Buffer.from(this.m_nonce_ours), Buffer.from(ciphertext)], sodium.crypto_box_PUBLICKEYBYTES + sodium.crypto_box_NONCEBYTES + ciphertext.length); - this.IncrementUint64(this.m_nonce_ours); - - this.m_public_key_ours = null; - } else { - handshake = Buffer.alloc(this.m_identifier.length + this.m_credentials.length + 2); - handshake.write(this.m_identifier, 0); - handshake.write(this.m_credentials, this.m_identifier.length() + 1); - } - - this.InternalSend(ServertalkPacketType.ServertalkClientHandshake, handshake); - } - - IncrementUint64(value) { - var bytes = []; - for(var i = 0; i < 8; ++i) { - bytes[i] = value[i]; - } - - bytes[0] += 1; - for(i = 0; i < 7; ++i) { - if(bytes[i] >= 0x100) { - bytes[0] = 0; - bytes[i + 1] += 1; - } - } - - if(bytes[7] >= 0x100) { - bytes[7] = 0; - } - - for(var i = 0; i < 8; ++i) { - value[i] = bytes[i]; - } - } -} - -module.exports = { - 'client': ServertalkClient -} \ No newline at end of file diff --git a/wi/package.json b/wi/package.json deleted file mode 100644 index 43b9e9f98..000000000 --- a/wi/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "wi", - "version": "1.0.0", - "description": "Web interface connection for EQEmu", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "KimLS", - "license": "GPL-3.0", - "dependencies": { - "body-parser": "^1.15.2", - "express": "^4.14.0", - "hammerjs": "^2.0.8", - "jsonwebtoken": "^7.2.1", - "libsodium": "^0.4.8", - "libsodium-wrappers": "^0.4.8", - "libsodium-wrappers-sumo": "^0.4.8", - "moment": "^2.17.1", - "mysql": "^2.12.0", - "node-uuid": "^1.4.7", - "ws": "^1.1.1" - } -} diff --git a/wi/settings.json b/wi/settings.json deleted file mode 100644 index de325ddde..000000000 --- a/wi/settings.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "db": { - "connectionLimit": 10, - "host": "localhost", - "user": "root", - "password": "blink", - "database": "eqdb" - }, - "servertalk": { - "addr": "localhost", - "port": "9101", - "key": "ujwn2isnal1987scanb" - }, - "https": { - "enabled": false, - "key": "key.pem", - "cert": "cert.pem" - }, - "port": 9080, - "key": "key.pem" -} \ No newline at end of file diff --git a/wi/test.js b/wi/test.js deleted file mode 100644 index 0ede3b12c..000000000 --- a/wi/test.js +++ /dev/null @@ -1,11 +0,0 @@ -const WebSocket = require('ws'); -const ws = new WebSocket('ws://localhost:9080'); - -ws.on('open', function open() { - ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg2MzI4MDI3LCJpYXQiOjE0ODU3MjMyMjd9.fJUeSQsxb5C13ICANox81YdE5yImkrVw-lRCP3O40-E', method: 'EQW::ZoneUpdate::Subscribe'})); - ws.send(JSON.stringify({authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IktTcHJpdGUxIiwiZXhwIjoxNDg2MzI4MDI3LCJpYXQiOjE0ODU3MjMyMjd9.fJUeSQsxb5C13ICANox81YdE5yImkrVw-lRCP3O40-E', method: 'EQW::ClientUpdate::Subscribe'})); -}); - -ws.on('message', function(data, flags) { - console.log(data); -}); \ No newline at end of file diff --git a/wi/ws/eqw.js b/wi/ws/eqw.js deleted file mode 100644 index 81d5c22f4..000000000 --- a/wi/ws/eqw.js +++ /dev/null @@ -1,18 +0,0 @@ -const common = require('./wi_common.js'); - -var RegisterEQW = function(wsi, api) { - common.Register('EQW::GetConfig', wsi, api); - common.Register('EQW::IsLocked', wsi, api); - common.Register('EQW::Lock', wsi, api); - common.Register('EQW::Unlock', wsi, api); - common.Register('EQW::GetPlayerCount', wsi, api); - common.Register('EQW::GetZoneCount', wsi, api); - common.Register('EQW::GetLauncherCount', wsi, api); - common.Register('EQW::GetLoginServerCount', wsi, api); - common.RegisterSubscription('EQW::ZoneUpdate', wsi, api); - common.RegisterSubscription('EQW::ClientUpdate', wsi, api); -}; - -module.exports = { - 'Register': RegisterEQW -} \ No newline at end of file diff --git a/wi/ws/index.js b/wi/ws/index.js deleted file mode 100644 index 1d4f92a56..000000000 --- a/wi/ws/index.js +++ /dev/null @@ -1,7 +0,0 @@ -var RegisterAPI = function(wsi, api) { - require('./eqw.js').Register(wsi, api); -}; - -module.exports = { - 'Register': RegisterAPI -} \ No newline at end of file diff --git a/wi/ws/wi_common.js b/wi/ws/wi_common.js deleted file mode 100644 index a2712783a..000000000 --- a/wi/ws/wi_common.js +++ /dev/null @@ -1,27 +0,0 @@ -function Register(name, wsi, api) { - wsi.Register(name, - function(request) { - api.Call(name, request.params) - .then(function(value) { - wsi.Send(request, value); - }) - .catch(function(reason) { - wsi.SendError(request, reason); - }); - }, true); -} - -function RegisterSubscription(event, wsi, api) { - wsi.Register(event + '::Subscribe', function(request) { - api.Subscribe(event, request.ws); - }); - - wsi.Register(event + '::Unsubscribe', function(request) { - api.Unsubscribe(event, request.ws); - }); -} - -module.exports = { - 'Register': Register, - 'RegisterSubscription': RegisterSubscription -} diff --git a/wi/ws/ws_interface.js b/wi/ws/ws_interface.js deleted file mode 100644 index ea60ca2fd..000000000 --- a/wi/ws/ws_interface.js +++ /dev/null @@ -1,118 +0,0 @@ -const WebSocketServer = require('ws').Server; -const jwt = require('jsonwebtoken'); -const uuid = require('node-uuid'); - -class WebSocketInterface -{ - constructor(server, key, api) { - this.wss = new WebSocketServer({ server: server }); - this.methods = {}; - var self = this; - - this.wss.on('connection', function connection(ws) { - self.ws = ws; - ws.uuid = uuid.v4(); - ws.on('message', function incoming(message) { - try { - var request = JSON.parse(message); - request.ws = ws; - - if(request.method) { - var method = self.methods[request.method]; - if(!method) { - self.SendError(request, 'Method not found: ' + request.method); - return; - } - - if(method.requires_auth) { - if(!request.authorization) { - self.SendError(request, 'Authorization Required'); - return; - } - - jwt.verify(request.authorization, key, function(err, decoded) { - if(err) { - self.SendError(request, 'Authorization Required'); - return; - } - - request.token = decoded; - method.fn(request); - }); - - return; - } - - method.fn(request); - - } else { - self.SendError(request, 'No method supplied'); - } - - } catch(ex) { - console.log('Error parsing message:', ex); - self.SendError(null, 'No method supplied'); - } - }); - - ws.on('close', function() { - api.UnsubscribeAll(ws); - }); - - ws.on('subscriptionMessage', function(msg) { - self.SendRaw(msg); - }); - }); - } - - Register(method, fn, requires_auth) { - var entry = { fn: fn, requires_auth: requires_auth }; - this.methods[method] = entry; - } - - SendError(request, msg) { - try { - if(this.ws) { - var error = {}; - - if(request && request.id) { - error.id = request.id; - } - - error.error = msg; - this.ws.send(JSON.stringify(error)); - } - } catch(ex) { - console.log(ex); - } - } - - Send(request, value) { - try { - if(this.ws) { - var response = {}; - - if(request && request.id) { - response.id = response.id; - } - - response.response = value; - this.ws.send(JSON.stringify(response)); - } - } catch(ex) { - console.log(ex); - } - } - - SendRaw(obj) { - try { - this.ws.send(JSON.stringify(obj)); - } catch(ex) { - console.log(ex); - } - } -} - -module.exports = { - 'wsi': WebSocketInterface -} \ No newline at end of file diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index fa4b6ecc6..c042a7364 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(world_sources adventure.cpp @@ -42,7 +42,6 @@ SET(world_headers lfplist.h login_server.h login_server_list.h - net.h queryserv.h sof_char_create_data.h ucs.h @@ -65,8 +64,4 @@ ADD_DEFINITIONS(-DWORLD) TARGET_LINK_LIBRARIES(world ${SERVER_LIBS}) -IF(EQEMU_BUILD_PERL) - TARGET_LINK_LIBRARIES(world ${PERL_LIBRARY}) -ENDIF() - SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/zone/CMakeLists.txt b/zone/CMakeLists.txt index 2de1ac1f6..f75e963f9 100644 --- a/zone/CMakeLists.txt +++ b/zone/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.2) SET(zone_sources aa.cpp @@ -79,6 +79,7 @@ SET(zone_sources horse.cpp inventory.cpp loottables.cpp + main.cpp map.cpp merc.cpp mob.cpp @@ -87,7 +88,6 @@ SET(zone_sources mob_movement_manager.cpp mob_info.cpp mod_functions.cpp - net.cpp npc.cpp npc_ai.cpp npc_scale_manager.cpp @@ -210,7 +210,6 @@ SET(zone_headers merc.h mob.h mob_movement_manager.h - net.h npc.h npc_ai.h npc_scale_manager.h @@ -258,12 +257,4 @@ ADD_DEFINITIONS(-DZONE) TARGET_LINK_LIBRARIES(zone ${SERVER_LIBS}) -IF(EQEMU_BUILD_PERL) - TARGET_LINK_LIBRARIES(zone ${PERL_LIBRARY}) -ENDIF() - -IF(EQEMU_BUILD_LUA) - TARGET_LINK_LIBRARIES(zone luabind ${LUA_LIBRARY}) -ENDIF(EQEMU_BUILD_LUA) - SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) diff --git a/zone/client.cpp b/zone/client.cpp index 2e128d66c..759a9e921 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -41,7 +41,6 @@ extern volatile bool RunLoops; #include "../common/profanity_manager.h" #include "data_bucket.h" #include "position.h" -#include "net.h" #include "worldserver.h" #include "zonedb.h" #include "petitions.h" @@ -67,6 +66,8 @@ extern PetitionList petition_list; bool commandlogged; char entirecommand[255]; +void UpdateWindowTitle(char* iNewTitle); + Client::Client(EQStreamInterface* ieqs) : Mob("No name", // name "", // lastname @@ -244,7 +245,7 @@ Client::Client(EQStreamInterface* ieqs) PendingRezzSpellID = 0; numclients++; // emuerror; - UpdateWindowTitle(); + UpdateWindowTitle(nullptr); horseId = 0; tgb = false; tribute_master_id = 0xFFFFFFFF; @@ -454,7 +455,7 @@ Client::~Client() { ClearRespawnOptions(); numclients--; - UpdateWindowTitle(); + UpdateWindowTitle(nullptr); if(zone) zone->RemoveAuth(GetName(), lskey); diff --git a/zone/embperl.h b/zone/embperl.h index ebd76fa0e..816e9b84a 100644 --- a/zone/embperl.h +++ b/zone/embperl.h @@ -25,6 +25,10 @@ Eglin #ifndef WIN32 extern "C" { //the perl headers dont do this for us... #endif +#if _MSC_VER +#define __inline__ __inline +#define __builtin_expect +#endif #include #include #ifndef WIN32 diff --git a/zone/embxs.h b/zone/embxs.h index 67a37a6da..97e3bb573 100644 --- a/zone/embxs.h +++ b/zone/embxs.h @@ -8,6 +8,10 @@ #ifndef WIN32 extern "C" { //the perl headers dont do this for us... #endif +#if _MSC_VER +#define __inline__ __inline +#define __builtin_expect +#endif #include #include #ifndef WIN32 diff --git a/zone/entity.cpp b/zone/entity.cpp index 084e0fc93..7f016f197 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -33,7 +33,6 @@ #include "../common/guilds.h" #include "guild_mgr.h" -#include "net.h" #include "petitions.h" #include "quest_parser_collection.h" #include "raids.h" @@ -56,7 +55,6 @@ extern Zone *zone; extern volatile bool is_zone_loaded; extern WorldServer worldserver; -extern NetConnection net; extern uint32 numclients; extern PetitionList petition_list; @@ -300,6 +298,13 @@ const Bot *Entity::CastToBot() const #endif EntityList::EntityList() + : + object_timer(5000), + door_timer(5000), + corpse_timer(2000), + group_timer(1000), + raid_timer(1000), + trap_timer(1000) { // set up ids between 1 and 1500 // neither client or server performs well if you have @@ -349,7 +354,7 @@ void EntityList::TrapProcess() return; if (trap_list.empty()) { - net.trap_timer.Disable(); + trap_timer.Disable(); return; } @@ -388,7 +393,7 @@ void EntityList::GroupProcess() return; if (group_list.empty()) { - net.group_timer.Disable(); + group_timer.Disable(); return; } @@ -412,7 +417,7 @@ void EntityList::RaidProcess() return; if (raid_list.empty()) { - net.raid_timer.Disable(); + raid_timer.Disable(); return; } @@ -427,7 +432,7 @@ void EntityList::DoorProcess() return; #endif if (door_list.empty()) { - net.door_timer.Disable(); + door_timer.Disable(); return; } @@ -445,7 +450,7 @@ void EntityList::DoorProcess() void EntityList::ObjectProcess() { if (object_list.empty()) { - net.object_timer.Disable(); + object_timer.Disable(); return; } @@ -464,7 +469,7 @@ void EntityList::ObjectProcess() void EntityList::CorpseProcess() { if (corpse_list.empty()) { - net.corpse_timer.Disable(); // No corpses in list + corpse_timer.Disable(); // No corpses in list return; } @@ -606,8 +611,8 @@ void EntityList::AddGroup(Group *group, uint32 gid) { group->SetID(gid); group_list.push_back(group); - if (!net.group_timer.Enabled()) - net.group_timer.Start(); + if (!group_timer.Enabled()) + group_timer.Start(); #if EQDEBUG >= 5 CheckGroupList(__FILE__, __LINE__); #endif @@ -631,8 +636,8 @@ void EntityList::AddRaid(Raid *raid, uint32 gid) { raid->SetID(gid); raid_list.push_back(raid); - if (!net.raid_timer.Enabled()) - net.raid_timer.Start(); + if (!raid_timer.Enabled()) + raid_timer.Start(); } @@ -649,8 +654,8 @@ void EntityList::AddCorpse(Corpse *corpse, uint32 in_id) corpse->CalcCorpseName(); corpse_list.insert(std::pair(corpse->GetID(), corpse)); - if (!net.corpse_timer.Enabled()) - net.corpse_timer.Start(); + if (!corpse_timer.Enabled()) + corpse_timer.Start(); } void EntityList::AddNPC(NPC *npc, bool SendSpawnPacket, bool dontqueue) @@ -752,8 +757,8 @@ void EntityList::AddObject(Object *obj, bool SendSpawnPacket) object_list.insert(std::pair(obj->GetID(), obj)); - if (!net.object_timer.Enabled()) - net.object_timer.Start(); + if (!object_timer.Enabled()) + object_timer.Start(); } void EntityList::AddDoor(Doors *door) @@ -761,16 +766,16 @@ void EntityList::AddDoor(Doors *door) door->SetEntityID(GetFreeID()); door_list.insert(std::pair(door->GetEntityID(), door)); - if (!net.door_timer.Enabled()) - net.door_timer.Start(); + if (!door_timer.Enabled()) + door_timer.Start(); } void EntityList::AddTrap(Trap *trap) { trap->SetID(GetFreeID()); trap_list.insert(std::pair(trap->GetID(), trap)); - if (!net.trap_timer.Enabled()) - net.trap_timer.Start(); + if (!trap_timer.Enabled()) + trap_timer.Start(); } void EntityList::AddBeacon(Beacon *beacon) diff --git a/zone/entity.h b/zone/entity.h index 339bbfd8a..6b22f1a4c 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -538,6 +538,13 @@ private: std::list area_list; std::queue free_ids; + Timer object_timer; + Timer door_timer; + Timer corpse_timer; + Timer group_timer; + Timer raid_timer; + Timer trap_timer; + // Please Do Not Declare Any EntityList Class Members After This Comment #ifdef BOTS public: diff --git a/zone/lua_mod.cpp b/zone/lua_mod.cpp index a891fb064..8dc77f4f7 100644 --- a/zone/lua_mod.cpp +++ b/zone/lua_mod.cpp @@ -1,3 +1,5 @@ +#ifdef LUA_EQEMU + #include "lua.hpp" #include #include @@ -629,3 +631,5 @@ void LuaMod::GetExperienceForKill(Client *self, Mob *against, uint32 &returnValu lua_pop(L, n); } } + +#endif diff --git a/zone/lua_parser.cpp b/zone/lua_parser.cpp index 2c7cfe53e..7c7242e4c 100644 --- a/zone/lua_parser.cpp +++ b/zone/lua_parser.cpp @@ -1300,8 +1300,6 @@ QuestEventID LuaParser::ConvertLuaEvent(QuestEventID evt) { } } -#endif - void LuaParser::MeleeMitigation(Mob *self, Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts, bool &ignoreDefault) { for (auto &mod : mods_) { @@ -1374,3 +1372,5 @@ uint32 LuaParser::GetExperienceForKill(Client *self, Mob *against, bool &ignoreD } return retval; } + +#endif diff --git a/zone/lua_stat_bonuses.cpp b/zone/lua_stat_bonuses.cpp index 282aaad38..d311cf123 100644 --- a/zone/lua_stat_bonuses.cpp +++ b/zone/lua_stat_bonuses.cpp @@ -1,3 +1,5 @@ +#ifdef LUA_EQEMU + #include "lua.hpp" #include @@ -1542,4 +1544,6 @@ luabind::scope lua_register_stat_bonuses() { .def("Assassinate", &Lua_StatBonuses::GetAssassinate) .def("AssassinateLevel", &Lua_StatBonuses::GetAssassinateLevel) .def("ReduceTradeskillFail", &Lua_StatBonuses::GetReduceTradeskillFail); -} \ No newline at end of file +} + +#endif diff --git a/zone/net.cpp b/zone/main.cpp similarity index 92% rename from zone/net.cpp rename to zone/main.cpp index 0ce901359..9ee3eda25 100644 --- a/zone/net.cpp +++ b/zone/main.cpp @@ -47,7 +47,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "zone_config.h" #include "masterentity.h" #include "worldserver.h" -#include "net.h" #include "zone.h" #include "queryserv.h" #include "command.h" @@ -96,7 +95,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA volatile bool RunLoops = true; extern volatile bool is_zone_loaded; -NetConnection net; EntityList entity_list; WorldServer worldserver; uint32 numclients = 0; @@ -115,6 +113,9 @@ const ZoneConfig *Config; double frame_time = 0.0; void Shutdown(); +void UpdateWindowTitle(char* iNewTitle); +void CatchSignal(int sig_num); + extern void MapOpcodes(); int main(int argc, char** argv) { @@ -440,7 +441,7 @@ int main(int argc, char** argv) { bool websocker_server_opened = false; Timer quest_timers(100); - UpdateWindowTitle(); + UpdateWindowTitle(nullptr); std::shared_ptr eqss; EQStreamInterface *eqsi; std::unique_ptr eqsm; @@ -514,23 +515,12 @@ int main(int argc, char** argv) { if (is_zone_loaded) { { - if (net.group_timer.Enabled() && net.group_timer.Check()) - entity_list.GroupProcess(); - - if (net.door_timer.Enabled() && net.door_timer.Check()) - entity_list.DoorProcess(); - - if (net.object_timer.Enabled() && net.object_timer.Check()) - entity_list.ObjectProcess(); - - if (net.corpse_timer.Enabled() && net.corpse_timer.Check()) - entity_list.CorpseProcess(); - - if (net.trap_timer.Enabled() && net.trap_timer.Check()) - entity_list.TrapProcess(); - - if (net.raid_timer.Enabled() && net.raid_timer.Check()) - entity_list.RaidProcess(); + entity_list.GroupProcess(); + entity_list.DoorProcess(); + entity_list.ObjectProcess(); + entity_list.CorpseProcess(); + entity_list.TrapProcess(); + entity_list.RaidProcess(); entity_list.Process(); entity_list.MobProcess(); @@ -622,60 +612,6 @@ void Shutdown() LogSys.CloseFileLogs(); } -uint32 NetConnection::GetIP() -{ - char name[255 + 1]; - size_t len = 0; - hostent* host = 0; - - if (gethostname(name, len) < 0 || len <= 0) - { - return 0; - } - - host = (hostent*)gethostbyname(name); - if (host == 0) - { - return 0; - } - - return inet_addr(host->h_addr); -} - -uint32 NetConnection::GetIP(char* name) -{ - hostent* host = 0; - - host = (hostent*)gethostbyname(name); - if (host == 0) - { - return 0; - } - - return inet_addr(host->h_addr); - -} - -NetConnection::NetConnection() - : - object_timer(5000), - door_timer(5000), - corpse_timer(2000), - group_timer(1000), - raid_timer(1000), - trap_timer(1000) -{ - group_timer.Disable(); - raid_timer.Disable(); - corpse_timer.Disable(); - door_timer.Disable(); - object_timer.Disable(); - trap_timer.Disable(); -} - -NetConnection::~NetConnection() { -} - /* Update Window Title with relevant information */ void UpdateWindowTitle(char* iNewTitle) { #ifdef _WINDOWS diff --git a/zone/net.h b/zone/net.h deleted file mode 100644 index 4d44b6058..000000000 --- a/zone/net.h +++ /dev/null @@ -1,48 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#ifdef _WINDOWS - #include - #include -#else - #include - #include - #include - #include - #include -#endif - -#include "../common/types.h" -#include "../common/timer.h" -void CatchSignal(int); -void UpdateWindowTitle(char* iNewTitle = 0); - -class NetConnection -{ -public: - ~NetConnection(); - NetConnection(); - - uint32 GetIP(); - uint32 GetIP(char* name); - Timer object_timer; - Timer door_timer; - Timer corpse_timer; - Timer group_timer; - Timer raid_timer; - Timer trap_timer; -}; diff --git a/zone/oldcode.cpp b/zone/oldcode.cpp deleted file mode 100644 index 7329c73f3..000000000 --- a/zone/oldcode.cpp +++ /dev/null @@ -1,1851 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2004 EQEMu Development Team (http://eqemu.org) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#include "../common/debug.h" -#include -using namespace std; -#include -#include -#include -#include -#include - #ifdef _CRTDBG_MAP_ALLOC - #undef new - #endif -#include - #ifdef _CRTDBG_MAP_ALLOC - #define new new(_NORMAL_BLOCK, __FILE__, __LINE__) - #endif -using namespace std; -#ifdef WIN32 -#include -#define snprintf _snprintf -#define vsnprintf _vsnprintf -#define strncasecmp _strnicmp -#define strcasecmp _stricmp -#endif - -bool spells_loaded = false; -volatile bool RunLoops = true; -extern volatile bool ZoneLoaded; -#ifdef SHAREMEM - #include "../common/EMuShareMem.h" - extern LoadEMuShareMemDLL EMuShareMemDLL; - #ifndef WIN32 - #include - #include - #include - #include -#ifndef FREEBSD - union semun { - int val; - struct semid_ds *buf; - ushort *array; - struct seminfo *__buf; - void *__pad; - }; -#endif - #endif -#endif - - - - -#include "../common/queue.h" -#include "../common/timer.h" -#include "../common/eq_stream.h" -#include "../common/eq_packet_structs.h" -#include "../common/mutex.h" -#include "../common/version.h" -#include "../common/files.h" -#include "../common/eqemu_error.h" -#include "../common/packet_dump_file.h" - -#include "masterentity.h" -#include "worldserver.h" -#include "net.h" -#include "spdat.h" -#include "zone.h" -#include "command.h" -#include "parser.h" -#include "embparser.h" - - -#ifndef NEW_LoadSPDat -void LoadSPDat(SPDat_Spell_Struct** SpellsPointer) { - //FILE *fp; - //cout << "Beginning Spells memset." << endl; - int u; - //for (u = 0; u < SPDAT_RECORDS; u++) - //{ //cout << u << ' '; - memset((char*) &spells,0,sizeof(SPDat_Spell_Struct)*SPDAT_RECORDS); - //} - //cout << "Memset finished\n"; - char temp=' '; - int tempid=0; - char token[64]=""; - int a = 0; - char sep='^'; - LogFile->write(EQEMuLog::Normal, "If this is the last message you see, you forgot to move spells_en.txt from your EQ dir to this dir."); - -#ifdef FREEBSD -#error ifstreams seem to break BSD... -#endif - ifstream in;in.open(SPELLS_FILE); - - if(!in.is_open()){ - LogFile->write(EQEMuLog::Error, "File '%s' not found in same directory as zone.exe, spell loading FAILED!", SPELLS_FILE); - return; - } - //while(!in.eof()) - //{in >> temp;} - //for(int x =0; x< spellsen_size; x++) - // memset((char*) &spells[x],0,sizeof(SPDat_Spell_Struct)); - while(tempid <= SPDAT_RECORDS-1) - { - //if(tempid>3490) - //{ - // cout << "BLEH"; - // getch(); - //} - - //in.getline(&temp, 624); - in.get(temp); - while(chrcmpI(&temp, &sep)) - { - strncat(token,&temp,1); - a++;//cout << temp<< ' '; - in.get(temp); - } - tempid=atoi(token); - if(tempid>=SPDAT_RECORDS) - break; - //cout << "TempID: " << tempid << endl; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].name,token,a); - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - //cout << spells[tempid].name << '^'; - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].player_1,token,a); - //cout << spells[tempid].player_1 << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].teleport_zone,token,a); - //cout << spells[tempid].teleport_zone << '^'; - a=0; - - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].you_cast,token,a); - //cout << spells[tempid].you_cast << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].other_casts,token,a); - //cout << spells[tempid].other_casts << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].cast_on_you,token,a); - //cout << spells[tempid].cast_on_you << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].cast_on_other,token,a); - //cout << spells[tempid].cast_on_other << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - strncpy(spells[tempid].spell_fades,token,a); - //cout << spells[tempid].spell_fades << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - in.get(temp); - } - spells[tempid].range=atof(token); - //cout << spells[tempid].range << '^'; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].aoerange=atof(token); - //cout << spells[tempid].aoerange << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].pushback=atof(token); - //cout << spells[tempid].pushback << '^'; - a=0; - - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].pushup=atof(token); - //cout << spells[tempid].pushup << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].cast_time=atoi(token); - - //cout << spells[tempid].cast_time << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].recovery_time=atoi(token); - //cout << spells[tempid].recovery_time << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].recast_time=atoi(token); - //cout << spells[tempid].recast_time << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].buffdurationformula=atoi(token); - //cout << spells[tempid].buffdurationformula << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].buffduration=atoi(token); - //cout << spells[tempid].buffduration << '^'; - - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].ImpactDuration=atoi(token); - //cout << spells[tempid].ImpactDuration<< '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].mana=atoi(token); - //cout << spells[tempid].mana << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - int y; - for(y=0; y< 12;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].base[y]=atoi(token); - //cout << spells[tempid].base[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - - } - for(y=0; y< 12;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].max[y]=atoi(token); - //cout << spells[tempid].max[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].icon=atoi(token); - //cout << spells[tempid].icon << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].memicon=atoi(token); - //cout << spells[tempid].memicon << '^'; - - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - for(y=0; y< 4;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].components[y]=atoi(token); - //cout << spells[tempid].components[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } - for(y=0; y< 4;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].component_counts[y]=atoi(token);//atoi(token); - //cout << spells[tempid].component_counts[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - } - for(y=0; y< 4;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].NoexpendReagent[y]=atoi(token); //NoExpend Reagent - //cout << spells[tempid].NoexpendReagent[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } - for(y=0; y< 12;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].formula[y]=atoi(token); - //cout << spells[tempid].formula[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - - spells[tempid].LightType=atoi(token); - //cout << spells[tempid].LightType << '^'; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].goodEffect=atoi(token); - //cout << spells[tempid].goodEffect << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].Activated=atoi(token); - //cout << spells[tempid].Activated << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].resisttype=atoi(token); - //cout << spells[tempid].resisttype << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - for(y=0; y< 12;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].effectid[y]=atoi(token); - //cout << spells[tempid].effectid[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].targettype=atoi(token); - //cout << spells[tempid].targettype << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].basediff=atoi(token); - //cout << spells[tempid].basediff<< '^'; - a=0; - for(u=0;u<64;u++) - - token[u]=(char)0; - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].skill=atoi(token); - //cout << spells[tempid].skill << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].zonetype=atoi(token); - //cout << spells[tempid].zonetype << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].EnvironmentType=atoi(token); - //cout << spells[tempid].EnvironmentType << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - - in.get(temp); - } - spells[tempid].TimeOfDay=atoi(token); - //cout << spells[tempid].TimeOfDay << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - for(y=0; y< 15;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].classes[y]= atoi(token); - //cout << spells[tempid].classes[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } //cout << "end class"; - /*for(y=0; y< 3;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].unknown1[y]=atoi(token); - cout << spells[tempid].unknown1[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - } - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].unknown2=atoi(token); - cout << spells[tempid].unknown2 << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - */ - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].CastingAnim=atoi(token); - //cout << spells[tempid].CastingAnim << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].TargetAnim=atoi(token); - //cout << spells[tempid].TargetAnim << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].TravelType=atoi(token); - //cout << spells[tempid].TravelType << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].SpellAffectIndex=atoi(token); - //cout << spells[tempid].SpellAffectIndex << '^'; - - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - for(y=0; y< 23;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].Spacing2[y]=atoi(token); - //cout << spells[tempid].base[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - } - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].ResistDiff=atoi(token); - //cout << spells[tempid].ResistDiff << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - in.get(temp); - for(y=0; y< 2;y++) - { - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].Spacing3[y]=atoi(token); - //cout << spells[tempid].base[y] << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - } - - in.get(temp); - while(chrcmpI(&temp,&sep)) - { - strncat(token,&temp,1); - a++; - in.get(temp); - } - spells[tempid].RecourseLink = atoi(token); - //cout << spells[tempid].RecourseLink << '^'; - a=0; - for(u=0;u<64;u++) - token[u]=(char)0; - - while(temp!='\n') - in.get(temp); - - //cout << endl; - if(tempid==SPDAT_RECORDS-1) break; - } - //for(u=0;u< SPDAT_RECORDS;u++) - // cout << u << ' ' << spells[u].name << '^'; - - spells_loaded = true; - cout << "Spells loaded.\n"; - in.close(); - -} -#endif - - -/*void EntityList::SendAATimer(uint32 charid,UseAA_Struct* uaa){ - Client* client2=this->GetClientByCharID(charid); - if(!client2){ - LogFile->write(EQEMuLog::Error, "Error in SendAATimer: Couldnt find character!"); - return; - } - client2->SendAATimer(uaa); -} - -void ZoneDatabase::UpdateAndDeleteAATimers(uint32 charid){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - char *query2 = 0; - - if (!RunQuery(query, MakeAnyLenString(&query, "delete from aa_timers where charid=%i and UNIX_TIMESTAMP(now())>=end",charid), errbuf)) { - LogFile->write(EQEMuLog::Error, "UpdateAATimers query '%s' %s", query, errbuf); - } - if (!RunQuery(query2, MakeAnyLenString(&query2, "update aa_timers set end=end-(UNIX_TIMESTAMP(now())-begin),begin=UNIX_TIMESTAMP(now()) where charid=%i",charid), errbuf)) { - LogFile->write(EQEMuLog::Error, "UpdateAATimers query '%s' %s", query2, errbuf); - } - safe_delete_array(query); - safe_delete_array(query2); -} - -void ZoneDatabase::UpdateTimersClientConnected(uint32 charid){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - if (!RunQuery(query, MakeAnyLenString(&query, "update aa_timers set end=(UNIX_TIMESTAMP(now())+(end-begin)),begin=UNIX_TIMESTAMP(now()) where charid=%i",charid), errbuf)) { - LogFile->write(EQEMuLog::Error, "UpdateAATimers query '%s' %s", query, errbuf); - } - safe_delete_array(query); -} - -void ZoneDatabase::GetAATimers(uint32 charid){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - - if (RunQuery(query, MakeAnyLenString(&query, "SELECT ability,begin,end from aa_timers WHERE charid=%i", charid), errbuf, &result)) { - while( ( row = mysql_fetch_row(result) ) ){ - UseAA_Struct* uaa=new UseAA_Struct(); - uaa->ability=atoi(row[0]); - uaa->begin=atoi(row[1]); - uaa->end=atoi(row[2]); - entity_list.SendAATimer(charid,uaa); - safe_delete(uaa); - } - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "Database::GetAATimers query '%s' %s", query, errbuf); - } - safe_delete_array(query); -} - -uint32 ZoneDatabase::GetTimerRemaining(uint32 charid,uint32 ability){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - uint32 remain=0; - if (RunQuery(query, MakeAnyLenString(&query, "SELECT end-begin from aa_timers WHERE charid=%i and ability=%i", charid,ability), errbuf, &result)) { - if((row=mysql_fetch_row(result))){ - remain=atoi(row[0]); - } - mysql_free_result(result); - } - else { - LogFile->write(EQEMuLog::Error, "Database::GetTimerRemaining query '%s' %s", query, errbuf); - } - safe_delete_array(query); - return remain; -} - -void ZoneDatabase::UpdateAATimers(uint32 charid,uint32 endtime,uint32 begintime,uint32 ability){ - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - if(begintime==0){ - if (!RunQuery(query, MakeAnyLenString(&query, "replace into aa_timers (charid,end,begin,ability) values(%i,UNIX_TIMESTAMP(now())+%i,UNIX_TIMESTAMP(now()),%i)",charid,endtime,ability), errbuf)) { - LogFile->write(EQEMuLog::Error, "UpdateAATimers query '%s' %s", query, errbuf); - } - } - else{ - if (!RunQuery(query, MakeAnyLenString(&query, "replace into aa_timers (charid,end,begin,ability) values(%i,%i,%i,%i)",charid,endtime,begintime,ability), errbuf)) { - LogFile->write(EQEMuLog::Error, "UpdateAATimers query '%s' %s", query, errbuf); - } - } - safe_delete_array(query); -}*/ - -/* -uint16 Client::GetCombinedAC_TEST() { - int ac1; - - ac1 = GetRawItemAC(); - if (m_pp.class_ != WIZARD && m_pp.class_ != MAGICIAN && m_pp.class_ != NECROMANCER && m_pp.class_ != ENCHANTER) { - ac1 = ac1*4/3; - } - ac1 += GetSkill(DEFENSE)/3; - if (GetAGI() > 70) { - ac1 += GetAGI()/20; - } - - int ac2; - - ac2 = GetRawItemAC(); - if (m_pp.class_ != WIZARD && m_pp.class_ != MAGICIAN && m_pp.class_ != NECROMANCER && m_pp.class_ != ENCHANTER) { - ac2 = ac2*4/3; - } - ac2 += GetSkill(DEFENSE)*400/255; - - int combined_ac = (ac1+ac2)*1000/847; - return combined_ac; - float combined_ac = ((float)ac1+(float)ac2)*1000.0f/847.0f; - return (uint16) combined_ac;//*10.0f)-10; -} -*/ - - -/*bool Client::GetIncreaseSpellDurationItem(uint16 &spell_id, char *itemname) -{ - for (int i=0; i<22; i++) { - const ItemInst* inst = m_inv[i]; - if (!inst || !inst->IsType(ItemTypeCommon)) - continue; - - const Item_Struct* item = inst->GetItem(); - if (item->FocusId && (item->FocusId != 0xFFFF)) { - if (IsIncreaseDurationSpell(item->FocusId)) { - spell_id = item->FocusId; - if (itemname) - strcpy(itemname, item->Name); - return true; - } - } - } - return false; -} - -bool Client::GetReduceManaCostItem(uint16 &spell_id, char *itemname) -{ - for (int i=0; i<22; i++) { - const ItemInst* inst = m_inv[i]; - if (!inst || !inst->IsType(ItemTypeCommon)) - continue; - - const Item_Struct* item = inst->GetItem(); - if (item->FocusId && (item->FocusId != 0xFFFF)) { - if (IsReduceManaSpell(item->FocusId)) { - spell_id = item->FocusId; - if (itemname) - strcpy(itemname, item->Name); - return true; - } - } - } - return false; -} - -bool Client::GetReduceCastTimeItem(uint16 &spell_id, char *itemname) -{ - for (int i=0; i<22; i++) { - const ItemInst* inst = m_inv[i]; - if (!inst || !inst->IsType(ItemTypeCommon)) - continue; - - const Item_Struct* item = inst->GetItem(); - if (item->FocusId && (item->FocusId != 0xFFFF)) { - if (IsReduceCastTimeSpell(item->FocusId)) { - spell_id = item->FocusId; - if (itemname) - strcpy(itemname, item->Name); - return true; - } - } - } - return false; -} - -bool Client::GetExtendedRangeItem(uint16 &spell_id, char *itemname) -{ - for (int i=0; i<22; i++) { - const ItemInst* inst = m_inv[i]; - if (!inst || !inst->IsType(ItemTypeCommon)) - continue; - - const Item_Struct* item = inst->GetItem(); - if (item->FocusId && (item->FocusId != 0xFFFF)) { - if (IsExtRangeSpell(item->FocusId)) { - spell_id = item->FocusId; - if (itemname) - strcpy(itemname, item->Name); - return true; - } - } - } - return false; -} - -bool Client::GetImprovedHealingItem(uint16 &spell_id, char *itemname) -{ - for (int i=0; i<22; i++) { - const ItemInst* inst = m_inv[i]; - if (!inst || !inst->IsType(ItemTypeCommon)) - continue; - - const Item_Struct* item = inst->GetItem(); - if (item->FocusId && (item->FocusId != 0xFFFF)) { - if (IsImprovedHealingSpell(item->FocusId)) { - spell_id = item->FocusId; - if (itemname) - strcpy(itemname, item->Name); - return true; - } - } - } - return false; -} - -bool Client::GetImprovedDamageItem(uint16 &spell_id, char *itemname) -{ - for (int i=0; i<22; i++) { - const ItemInst* inst = m_inv[i]; - if (!inst || !inst->IsType(ItemTypeCommon)) - continue; - - const Item_Struct* item = inst->GetItem(); - if (item->FocusId && (item->FocusId != 0xFFFF)) { - if (IsImprovedDamageSpell(item->FocusId)) { - spell_id = item->FocusId; - if (itemname) - strcpy(itemname, item->Name); - return true; - } - } - } - return false; -} - -int32 Client::GenericFocus(uint16 spell_id, uint16 modspellid) -{ - int modifier = 100, i; - const SPDat_Spell_Struct &spell = spells[spell_id]; - const SPDat_Spell_Struct &modspell = spells[modspellid]; - - for (i = 0; i < EFFECT_COUNT; i++) - { - if(IsBlankSpellEffect(modspellid, i)) - continue; - switch( spells[modspellid].effectid[i] ) - { - case SE_LimitMaxLevel: - if (spell.classes[(GetClass()%17) - 1] > modspell.base[i]) - return 100; - break; - case SE_LimitMinLevel: - if (spell.classes[(GetClass()%17) - 1] < modspell.base[i]) - return 100; - break; - case SE_IncreaseRange: - modifier += modspell.base[i]; - break; - case SE_IncreaseSpellHaste: - modifier -= modspell.base[i]; - break; - case SE_IncreaseSpellDuration: - modifier += modspell.base[i]; - break; - case SE_LimitSpell: - // negative sign means exclude - // positive sign means include - if (modspell.base[i] < 0) - { - if (modspell.base[i] * (-1) == spell_id) - return 100; - } - else - { - if (spells[modspellid].base[i] != spell_id) - return 100; - } - break; - case SE_LimitEffect: - switch( spells[modspellid].base[i] ) - { - case -147: - if (IsPercentalHealSpell(spell_id)) - return 100; - break; - case -101: - if (IsCHDurationSpell(spell_id)) - return 100; - break; - case -40: - if (IsInvulnerabilitySpell(spell_id)) - return 100; - break; - case -32: - if (IsSummonItemSpell(spell_id)) - return 100; - break; - case 0: - if (!IsEffectHitpointsSpell(spell_id)) - return 100; - break; - case 33: - if (!IsSummonPetSpell(spell_id)) - return 100; - break; - case 36: - if (!IsPoisonCounterSpell(spell_id)) - return 100; - break; - case 71: - if (!IsSummonSkeletonSpell(spell_id)) - return 100; - break; - default: - LogFile->write(EQEMuLog::Normal, "GenericFocus: unknown limit effect %d", spells[modspellid].base[i]); - } - break; - case SE_LimitCastTime: - if (modspell.base[i] > (int16)spell.cast_time) - return 100; - break; - case SE_LimitSpellType: - switch( spells[modspellid].base[i] ) - { - case 0: - if (!IsDetrimentalSpell(spell_id)) - return 100; - break; - case 1: - if (!IsBeneficialSpell(spell_id)) - return 100; - break; - default: - LogFile->write(EQEMuLog::Normal, "GenericFocus: unknown limit spelltype %d", spells[modspellid].base[i]); - } - break; - case SE_LimitMinDur: - if (modspell.base[i] > CalcBuffDuration_formula(GetLevel(), spell.buffdurationformula, spell.buffduration)) - return 100; - break; - case SE_ImprovedDamage: - case SE_ImprovedHeal: - modifier += modspell.base[i]; - break; - case SE_ReduceManaCost: - modifier -= modspell.base[i]; - break; - default: - LogFile->write(EQEMuLog::Normal, "GenericFocus: unknown effectid %d", modspell.effectid[i]); - } - } - - return modifier; -} -*/ - - - -/*void Client::Discipline(ClientDiscipline_Struct* disc_in, Mob* tar) { -Message(0, "Disc packet id=%d, %x,%x,%x", disc_in->disc_id, disc_in->unknown3[0], disc_in->unknown3[1], disc_in->unknown3[2]); - if (!p_timers.Expired(&database, pTimerDisciplineReuse)) { - char val1[20]={0}; - char val2[20]={0}; - uint32 remain = p_timers.GetRemainingTime(pTimerDisciplineReuse); - MessageString(Chat::White,DISCIPLINE_CANUSEIN,ConvertArray((remain)/60,val1),ConvertArray(remain%60,val2)); - //Message(0,"You can use a new discipline in %i minutes %i seconds.", (disc_timer.GetRemainingTime()/1000)/60, disc_timer.GetRemainingTime()/1000%60); - return; - } - - //reuse times are a little messes up, they should scale down somehow - //as you gain in levels, but im not sure how, so its just a lvl 60 bonus right now - - //should change this to check classes better. - - //both in seconds, converted at the end. - uint32 duration = 0; - uint32 reuse = 0; - - switch(disc_in->disc_id){ - // Shared? - case discResistant: { // Resistant - // 1 minute duration - // 1 hour reuse - // +3 to +10 to resists - if (GetLevel()<=29) - return; - duration = 60; - reuse = 60*60; - entity_list.MessageClose(this, false, 100, 0, "%s has become more resistant!", GetName()); - break; - } - case discFearless: { // Fearless - // 11 second duration - // 1 hour reuse - // 100% fear immunity - if (GetLevel()<=39) - return; - duration = 11; - reuse = 60*60; - entity_list.MessageCloseString(this, false, 100, 0, DISCIPLINE_FEARLESS, GetName()); - //entity_list.MessageClose(this, false, 100, 0, "%s becomes fearless!", GetName()); - break; - } - case discWhirlwind: { // Counterattack/Whirlwind/Furious - // warrior level 56 - // rogue/monk level 53 - // 9 second duration - // 1 hour reuse - if ((GetClass() == WARRIOR && GetLevel() <= 56) - ||(GetLevel() <= 53) - ) return; - duration = 9; - reuse = 60*60; - entity_list.MessageClose(this, false, 100, 0, "%s\'s face becomes twisted with fury!", GetName()); - break; - } - case discFellstrike: { // Duelist/Innerflame/Fellstrike - // monk level 56 - // rogue level 59 - // warrior level 58 - // 12 second duration - // 30 minute reuse - // min 4*base hand/weapon damage - if ((GetClass() == MONK && GetLevel() <= 55) - ||(GetClass() == WARRIOR && GetLevel() <= 58) - ||(GetClass() == ROGUE && GetLevel() <= 59) - ) return; - duration = 12; - reuse = 60*30; - entity_list.MessageClose(this, false, 100, 0, "%s\'s muscles bulge with force of will!", GetName()); - break; - } - case discBlindingSpeed: { // Blindingspeed/Hundredfist - // rogue level 58 - // monk level 57 - // 15 second duration - // 30 minute reuse - if ((GetClass() == MONK && GetLevel() <= 58) - ||(GetClass() == ROGUE && GetLevel() <= 57) - ) return; - //disc_timer.Start(1000*60*30); - //disc_elapse.Start(1000*15); - duration = 15; - reuse = 60*30; - Message(0, "This discipline not implemented.."); - break; - } - case discDeadeye: { // Deadeye/Charge - // warrior level 53 - // rogue level 54 - // 14 second duration - // 30 minute reuse - if ((GetClass() == WARRIOR && GetLevel() <= 53) - ||(GetClass() == ROGUE && GetLevel() <= 54) - ) return; - duration = 14; - reuse = 60*30; - entity_list.MessageClose(this, false, 100, 0, "%s feels unstopable!", GetName()); - break; - } - // Warrior - case discEvasive: { // Evasive - // level 52 - // 3 minute duration - // 15 minute reuse - // +35% avoidance - // -15% out - duration = 3*60; - reuse = 15*60; - break; - } - case discMightystrike: { // Mightystrike - // level 54 - // 10 second duration - // 1 hour reuse - // Auto crit - duration = 10; - reuse = 60*60; - break; - } - case discDefensive: { // Defensive - // level 55 - // 3 minute duration - // 15 minute reuse, 10 after 60 - // +35% mitigation - // -15% out - duration = 3*60; - if(level > 59) - reuse = 10*60; - else - reuse = 15*60; - break; - } - case discPrecise: { // Precise - // level 57 - // 3 minute duration - // 30 minute reuse - // -15% avoidance - // +35% out - duration = 3*60; - reuse = 30*60; - break; - } - case discAggressive: { // Aggressive - // level 60 - // 3 minute duration - // 27 minute reuse - // -15% mitigation - // +35% out - duration = 3*60; - reuse = 27*60; - break; - } - // Monk - case discStonestance: { // Stonestance - // level 51 - duration = 12; - if(level > 59) - reuse = 3*60; - else - reuse = 12*60; - break; - } - case discThunderkick: { // Thunderkick - // level 52 - if(level > 59) - reuse = 1*60; - else - reuse = 7*60; - duration = 5*60; //hack for now, checked in combat and expired once used. - break; - } - case discVoidance: { // Voidance - // level 54 - if(level > 59) - reuse = 54*60; - else - reuse = 60*60; - duration = 8; - break; - } - case discSilentfist: { // Silentfist - // level 59 - // 6-7 minute reuse - // Dragon punch damage bonus - // Chance to stun - if(level > 59) - reuse = 6*60; - else - reuse = 7*60; - duration = 5*60; //hack for now, checked in combat and expired once used. - break; - } - case discAshenhand: { // Ashenhand - // level 60 - // 72 minute reuse - // Eagle Strike damage bonus - // Chance to slay - reuse = 72*60; - duration = 5*60; //hack for now, checked in combat and expired once used. - break; - } - // Rogue - case discNimble: { // Nimble - // level 55 - // 12 second duration - // 30 minute reuse - // Auto dodge - if(level > 59) - reuse = 25*60; - else - reuse = 30*60; - duration = 12; - break; - } - case discKinesthetics: { // Kinesthetics - // level 57 - // 18 second duration - // 30,27 minute reuse - // Auto dualwield - // Auto double attack - if(level > 59) - reuse = 27*60; - else - reuse = 30*60; - duration = 18; - break; - } - // Paladin - case discHolyforge: { // Holyforge - // level 55 - // 2 minute duration - // 72 minute reuse - // Crit/Crip undead - // +15% to crit chance - if(level > 59) - reuse = 65*60; - else - reuse = 72*60; - duration = 5*60; - break; - } - case discSanctification: { // Sanctification - // level 60 - // 10 second duration - // 72 minute reuse - // Spell immunity - reuse = 72*60; - duration = 15; - break; - } - // Ranger - case discTrueshot: { // Trueshot - // level 55 - // 2 minute duration - // 72 minute reuse - // Max to two times max bow damage - // +15% to hit - if(level > 59) - reuse = 67*60; - else - reuse = 72*60; - duration = 2*60; - break; - } - case discWeaponshield: { // Weaponshield - // level 60 - // 15 second duration - // 72 minute reuse - // auto parry - reuse = 72*60; - duration = 20; - break; - } - // Bard - case discDeftdance: { // Deftdance - // level 55 - // 10 second duration - // 72 minute reuse - // auto dodge - // auto dualwield - if(level > 59) - reuse = 67*60; - else - reuse = 72*60; - duration = 10; - break; - } - case discPuretone: { // Puretone - // level 60 - // 2 minute duration - // 72 minute reuse - // Auto instrument - reuse = 72*60; - duration = 4*60; - break; - } - // Shadow knight - case discUnholyAura: { // Unholy - // level 55 - // 72 minute reuse - // +25% to harmtouch - // -300 to resist - if(level > 59) - reuse = 67*60; - else - reuse = 72*60; - duration = 5*60; //hack for now, checked in combat and expired once used. - break; - } - case discLeechCurse: { // Leech curse - // level 60 - // 15 second duration - // 72 minute reuse - // Heal self for each point of melee damage done - reuse = 72*60; - duration = 15; - break; - } - // Default - case 0:{ // Timer request - break; - } - default: - LogFile->write(EQEMuLog::Error, "Unknown Discipline requested by client: %s class: %i Disciline:%i", GetName(), class_,disc_in->disc_id); - return; - } - - if(reuse != 0) { - p_timers.Start(pTimerDisciplineReuse, reuse); - //nonpersistent timer for the 'discipline ready' message - disc_timer.Start(1000*reuse); - } - if(duration != 0) - disc_elapse.Start(1000*duration); - - disc_inuse = disc_in->disc_id; -}*/ - -#if 0 // solar: this is old code -/*void EntityList::AESpell(Mob* caster, Mob* center, float dist, uint16 spell_id, bool group) -{ - LinkedListIterator iterator(mob_list); - iterator.Reset(); - while(iterator.MoreElements()) { - Mob* mob = iterator.GetData(); - if (group){ - // Client casting group spell with out target group buffs enabled - // Skip non group members - if (caster->IsClient() - && !caster->CastToClient()->TGB() - && GetGroupByMob(mob) != 0 - && !GetGroupByMob(mob)->IsGroupMember(caster) - ) { - LogFile->write(EQEMuLog::Debug, "Group spell skipping %s", mob->GetName()); - iterator.Advance(); - continue; - } - // Client casting group spell with target group buffs enabled - else if (caster->IsClient() - && caster->CastToClient()->TGB() - && GetGroupByMob(mob) != 0 - && GetGroupByMob(mob)->IsGroupMember(caster) - ){ - LogFile->write(EQEMuLog::Debug, "Group spell TGB on %s's Group", mob->GetName()); - GetGroupByMob(mob)->CastGroupSpell(caster, spell_id); - iterator.Advance(); - continue; - } - else if (caster->IsClient() - && caster->CastToClient()->TGB() - && GetGroupByMob(mob) == 0 - && mob == center - ){ - LogFile->write(EQEMuLog::Debug, "Group spell TGB on %s", mob->GetName()); - caster->SpellOnTarget(spell_id, mob); - return; - } - } - if ( - mob->DistNoZ(*center) <= dist - && !(mob->IsClient() && mob->CastToClient()->GMHideMe()) - && !mob->IsCorpse() - ) { - //cout << "AE Spell Hit: t=" << iterator.GetData()->GetName() << ", d=" << iterator.GetData()->CastToMob()->DistNoRoot(center) << ", x=" << iterator.GetData()->CastToMob()->GetX() << ", y=" << iterator.GetData()->CastToMob()->GetY() << endl; - if (caster == mob) { - // Caster gets the first hit, already handled in spells.cpp - } - #ifdef IPC - else if(caster->IsNPC() && !caster->CastToNPC()->IsInteractive()) { - #else - else if(caster->IsNPC()) { - #endif - // Npc - if (caster->IsAttackAllowed(mob) && spells[spell_id].targettype != ST_AEBard) { - caster->SpellOnTarget(spell_id, mob); - } - else if (mob->IsAIControlled() && spells[spell_id].targettype == ST_AEBard) { - caster->SpellOnTarget(spell_id, mob); - } - else { - } - } - #ifdef IPC - else if(caster->IsNPC() && caster->CastToNPC()->IsInteractive()) { - // Interactive npc - if (caster->IsAttackAllowed(mob) && spells[spell_id].targettype != ST_AEBard && spells[spell_id].targettype != ST_GroupTeleport) { - caster->SpellOnTarget(spell_id, mob); - } - else if (!mob->IsAIControlled() && (spells[spell_id].targettype == ST_AEBard||group) && mob->CastToClient()->GetPVP() == caster->CastToClient()->GetPVP()) { - if (group && GetGroupByMob(mob) != GetGroupByMob(caster)) { - iterator.Advance(); - continue; - } - caster->SpellOnTarget(spell_id, mob); - } - else { - } - } - #endif - else if (caster->IsClient() && !(caster->CastToClient()->IsBecomeNPC())) { - // Client - if (caster->IsAttackAllowed(mob) && spells[spell_id].targettype != ST_AEBard){ - caster->SpellOnTarget(spell_id, mob); - } - else if(spells[spell_id].targettype == ST_GroupTeleport && mob->IsClient() && mob->isgrouped && caster->isgrouped && entity_list.GetGroupByMob(caster)) - { - Group* caster_group = entity_list.GetGroupByMob(caster); - if(caster_group != 0 && caster_group->IsGroupMember(mob)) - caster->SpellOnTarget(spell_id,mob); - } - else if (mob->IsClient() && (spells[spell_id].targettype == ST_AEBard||group) && mob->CastToClient()->GetPVP() == caster->CastToClient()->GetPVP()) { - if (group && GetGroupByMob(mob) != GetGroupByMob(caster)) { - iterator.Advance(); - continue; - } - else if (mob->IsClient() && spells[spell_id].targettype == ST_AEBard && mob->CastToClient()->GetPVP() == caster->CastToClient()->GetPVP()) - caster->SpellOnTarget(spell_id, mob); - #ifdef IPC - else if (mob->IsNPC() && mob->CastToNPC()->IsInteractive()) { - if (group && GetGroupByMob(mob) != GetGroupByMob(caster)) - continue; - caster->SpellOnTarget(spell_id, mob); - } - #endif - } - } - else if (caster->IsClient()) { - // Client BecomeNPC - caster->SpellOnTarget(spell_id, mob); - } - } - iterator.Advance(); - } -}*/ -#endif // solar: old code - -/*#if 0 -// Queries the loottable: adds item & coin to the npc -void ZoneDatabase::AddLootTableToNPC(uint32 loottable_id, ItemList* itemlist, uint32* copper, uint32* silver, uint32* gold, uint32* plat) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - *copper = 0; - *silver = 0; - *gold = 0; - *plat = 0; - - if (RunQuery(query, MakeAnyLenString(&query, "SELECT id, mincash, maxcash, avgcoin FROM loottable WHERE id=%i", loottable_id), errbuf, &result)) { - safe_delete_array(query); - if (mysql_num_rows(result) == 1) { - row = mysql_fetch_row(result); - uint32 mincash = atoi(row[1]); - uint32 maxcash = atoi(row[2]); - if (mincash > maxcash) { - cerr << "Error in loottable #" << row[0] << ": mincash > maxcash" << endl; - } - else if (maxcash != 0) { - uint32 cash = 0; - if (mincash == maxcash) - cash = mincash; - else - cash = (rand() % (maxcash - mincash)) + mincash; - if (cash != 0) { - uint32 coinavg = atoi(row[3]); - if (coinavg != 0) { - uint32 mincoin = (uint32) (coinavg * 0.75 + 1); - uint32 maxcoin = (uint32) (coinavg * 1.25 + 1); - *copper = (rand() % (maxcoin - mincoin)) + mincoin - 1; - *silver = (rand() % (maxcoin - mincoin)) + mincoin - 1; - *gold = (rand() % (maxcoin - mincoin)) + mincoin - 1; - cash -= *copper; - cash -= *silver * 10; - cash -= *gold * 10; - } - *plat = cash / 1000; - cash -= *plat * 1000; - uint32 gold2 = cash / 100; - cash -= gold2 * 100; - uint32 silver2 = cash / 10; - cash -= silver2 * 10; - *gold += gold2; - *silver += silver2; - *copper += cash; - } - } - } - else { - mysql_free_result(result); - return; - } - mysql_free_result(result); - } - else - { - cerr << "Error in AddLootTableToNPC get coin query '" << query << "' " << errbuf << endl; - safe_delete_array(query); - return; - } - - if (RunQuery(query, MakeAnyLenString(&query, "SELECT loottable_id, lootdrop_id, multiplier, probability FROM loottable_entries WHERE loottable_id=%i", loottable_id), errbuf, &result)) { - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) { - int multiplier = atoi(row[2]); - for (int i = 1; i <= multiplier; i++) { - if ( ((rand()%1)*100) < atoi(row[3])) { - AddLootDropToNPC(atoi(row[1]), itemlist); - } - } - } - mysql_free_result(result); - } - else { - cerr << "Error in AddLootTableToNPC get items query '" << query << "' " << errbuf << endl; - safe_delete_array(query); - return; - } - - return; -} - -// Called by AddLootTableToNPC -// maxdrops = size of the array npcd -void ZoneDatabase::AddLootDropToNPC(uint32 lootdrop_id, ItemList* itemlist) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char *query = 0; - MYSQL_RES *result; - MYSQL_ROW row; - -// This is Wiz's updated Pool Looting functionality. Eventually, the database format should be moved over to use this -// or implemented to support both methods. (A unique identifier in lootable_entries indicates to roll for a pool item -// in another table. -#ifdef POOLLOOTING - uint32 chancepool = 0; - uint32 items[50]; - uint32 itemchance[50]; - uint16 itemcharges[50]; - uint8 i = 0; - - for (int m=0;m < 50;m++) - { - items[m]=0; - itemchance[m]=0; - itemcharges[m]=0; - } - - if (RunQuery(query, MakeAnyLenString(&query, "SELECT lootdrop_id, item_id, item_charges, equip_item, chance FROM lootdrop_entries WHERE lootdrop_id=%i order by chance desc", lootdrop_id), errbuf, &result)) - { - safe_delete_array(query); - while (row = mysql_fetch_row(result)) - { - items[i] = atoi(row[1]); - itemchance[i] = atoi(row[4]) + chancepool; - itemcharges[i] = atoi(row[2]); - chancepool += atoi(row[4]); - i++; - } - uint32 res; - i = 0; - - if (chancepool!=0) //avoid divide by zero if some mobs have 0 for chancepool - { - res = rand()%chancepool; - } - else - { - res = 0; - } - - while (items[i] != 0) - { - if (res <= itemchance[i]) - break; - else - i++; - } - const Item_Struct* dbitem = database.GetItem(items[i]); - if (dbitem == 0) - { - LogFile->write(EQEMuLog::Error, "AddLootDropToNPC: dbitem=0, item#=%i, lootdrop_id=%i", items[i], lootdrop_id); - } - else - { - //cout << "Adding item to Mob" << endl; - ServerLootItem_Struct* item = new ServerLootItem_Struct; - item->item_id = dbitem->ItemNumber; - item->charges = itemcharges[i]; - item->equipSlot = 0; - (*itemlist).Append(item); - } - mysql_free_result(result); - } -#else - if (RunQuery(query, MakeAnyLenString(&query, "SELECT lootdrop_id, item_id, item_charges, equip_item, chance FROM lootdrop_entries WHERE lootdrop_id=%i order by chance desc", lootdrop_id), errbuf, &result)) - { - safe_delete_array(query); - while ((row = mysql_fetch_row(result))) - { - uint8 LootDropMod=1; // place holder till I put it in a database variable to make it configurable. - if( (rand()%100) < ((atoi(row[4]) * LootDropMod)) ) - { - uint32 itemid = atoi(row[1]); - const Item_Struct* dbitem = database.GetItem(itemid); - if (dbitem == 0) - { - LogFile->write(EQEMuLog::Error, "AddLootDropToNPC: dbitem=0, item#=%i, lootdrop_id=%i", itemid, lootdrop_id); - } - else - { - printf("Adding item: %i",item->ItemNumber); - ServerLootItem_Struct* item = new ServerLootItem_Struct; - item->item_id = dbitem->item_id; - item->charges = atoi(row[2]); - item->equipSlot = 0; - (*itemlist).Append(item); - } - - //mysql_free_result(result); - //return; - } - } - mysql_free_result(result); - } -#endif - else - { - LogFile->write(EQEMuLog::Error, "Error in AddLootDropToNPC query '%s' %s", query, errbuf); - safe_delete_array(query); - return; - } - - return; -} -#endif*/ diff --git a/zone/oldcode.h b/zone/oldcode.h deleted file mode 100644 index 6decf7f76..000000000 --- a/zone/oldcode.h +++ /dev/null @@ -1,22 +0,0 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2004 EQEMu Development Team (http://eqemu.org) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ -#ifndef OLDCODE_H -#define OLDCODE_H - -#endif - diff --git a/zone/queryserv.cpp b/zone/queryserv.cpp index 691943a7c..6e8b57423 100644 --- a/zone/queryserv.cpp +++ b/zone/queryserv.cpp @@ -21,7 +21,6 @@ Copyright (C) 2001-2014 EQEMu Development Team (http://eqemulator.net) #include "../common/string_util.h" #include "queryserv.h" #include "worldserver.h" -#include "net.h" extern WorldServer worldserver; diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index 1ed7d4998..4f7e35ace 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -44,7 +44,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "quest_parser_collection.h" #include "guild_mgr.h" #include "mob.h" -#include "net.h" #include "petitions.h" #include "raids.h" #include "string_ids.h" @@ -59,7 +58,6 @@ extern Zone* zone; extern volatile bool is_zone_loaded; extern void CatchSignal(int); extern WorldServer worldserver; -extern NetConnection net; extern PetitionList petition_list; extern uint32 numclients; extern volatile bool RunLoops; diff --git a/zone/zone.cpp b/zone/zone.cpp index 1bb8b8c36..99c120cab 100755 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -39,7 +39,6 @@ #include "guild_mgr.h" #include "map.h" -#include "net.h" #include "npc.h" #include "object.h" #include "pathfinder_null.h" @@ -68,7 +67,6 @@ #endif extern bool staticzone; -extern NetConnection net; extern PetitionList petition_list; extern QuestParserCollection* parse; extern uint32 numclients; @@ -81,6 +79,8 @@ Mutex MZoneShutdown; volatile bool is_zone_loaded = false; Zone* zone = 0; +void UpdateWindowTitle(char* iNewTitle); + bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) { const char* zonename = database.GetZoneName(iZoneID); @@ -147,7 +147,7 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) { LogInfo("---- Zone server [{}], listening on port:[{}] ----", zonename, ZoneConfig::get()->ZonePort); LogInfo("Zone Bootup: [{}] ([{}]: [{}])", zonename, iZoneID, iInstanceID); parse->Init(); - UpdateWindowTitle(); + UpdateWindowTitle(nullptr); zone->GetTimeSync(); zone->RequestUCSServerStatus(); @@ -727,7 +727,7 @@ void Zone::Shutdown(bool quiet) safe_delete(zone); entity_list.ClearAreas(); parse->ReloadQuests(true); - UpdateWindowTitle(); + UpdateWindowTitle(nullptr); LogSys.CloseFileLogs(); @@ -2422,4 +2422,4 @@ void Zone::CalculateNpcUpdateDistanceSpread() update_distance, combined_spread ); -} \ No newline at end of file +}