Compare commits

..

4 Commits

Author SHA1 Message Date
David Markowitz
1bd04fe36f use a default for optimizations 2024-12-04 22:44:38 -08:00
David Markowitz
129d9fd0b9 update exception catching (#1661) 2024-12-04 03:30:14 -06:00
David Markowitz
ec4ec2133b fix: logging uninitialized memory (#1658)
fixes an issue where the console would halt because we printed a control code which did such
2024-12-03 15:01:43 -06:00
David Markowitz
218a3f2d0d Update BaseFootRaceManager.cpp (#1657) 2024-11-27 16:26:10 -06:00
36 changed files with 90 additions and 95 deletions

4
.gitignore vendored
View File

@@ -6,10 +6,6 @@ docker/configs
# Third party libraries
thirdparty/mysql/
thirdparty/mysql_linux/
thirdparty/backtrace/
thirdparty/magic_enum/
thirdparty/recastnavigation/
thirdparty/tinyxml2/
CMakeVariables.txt
# Build folders

12
.gitmodules vendored
View File

@@ -1,7 +1,19 @@
[submodule "thirdparty/cpp-httplib"]
path = thirdparty/cpp-httplib
url = https://github.com/yhirose/cpp-httplib
[submodule "thirdparty/tinyxml2"]
path = thirdparty/tinyxml2
url = https://github.com/leethomason/tinyxml2
[submodule "thirdparty/recastnavigation"]
path = thirdparty/recastnavigation
url = https://github.com/recastnavigation/recastnavigation
[submodule "thirdparty/libbcrypt"]
path = thirdparty/libbcrypt
url = https://github.com/trusch/libbcrypt.git
[submodule "thirdparty/mariadb-connector-cpp"]
path = thirdparty/mariadb-connector-cpp
url = https://github.com/mariadb-corporation/mariadb-connector-cpp.git
ignore = dirty
[submodule "thirdparty/magic_enum"]
path = thirdparty/magic_enum
url = https://github.com/Neargye/magic_enum.git

View File

@@ -9,6 +9,10 @@ if("${CMAKE_SOURCE_DIR}" MATCHES " ")
message(FATAL_ERROR "The server cannot build in the path (" ${CMAKE_SOURCE_DIR} ") because it contains a space. Please move the server to a path without spaces.")
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "The default build type" FORCE)
endif()
include(CTest)
set(CMAKE_C_STANDARD 99)
@@ -109,53 +113,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
find_package(MariaDB)
# Fetch third party dependencies
set(DLU_THIRDPARTY_SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty)
include(FetchContent)
FetchContent_Declare(
backtrace
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/backtrace
GIT_REPOSITORY https://github.com/ianlancetaylor/libbacktrace.git
)
FetchContent_Declare(
bcrypt
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/libbcrypt
GIT_REPOSITORY https://github.com/trusch/libbcrypt.git
GIT_TAG d6523c370de6e724ce4ec703e2449b5b028ea3b1
)
FetchContent_Declare(
magic_enum
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/magic_enum
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
GIT_TAG v0.9.7
)
FetchContent_Declare(
Recast
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/recastnavigation
GIT_REPOSITORY https://github.com/recastnavigation/recastnavigation.git
GIT_TAG v1.6.0
)
FetchContent_Declare(
tinyxml2
SYSTEM
SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/tinyxml2
GIT_REPOSITORY https://github.com/leethomason/tinyxml2.git
GIT_TAG 9.0.0
)
FetchContent_MakeAvailable(magic_enum Recast tinyxml2)
# Turn off tinyxml2 testing
set(tinyxml2_BUILD_TESTING OFF)
include(CMakePrintHelpers)
cmake_print_properties(TARGETS magic_enum Recast tinyxml2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES)
# Create a /resServer directory
make_directory(${CMAKE_BINARY_DIR}/resServer)
@@ -298,7 +255,10 @@ include_directories(
"tests/dGameTests/dComponentsTests"
SYSTEM
"thirdparty/magic_enum/include/magic_enum"
"thirdparty/raknet/Source"
"thirdparty/tinyxml2"
"thirdparty/recastnavigation"
"thirdparty/SQLite"
"thirdparty/cpplinq"
"thirdparty/cpp-httplib"
@@ -316,7 +276,7 @@ if(MSVC)
# add_compile_options("/W4")
# Want to enable warnings eventually, but WAY too much noise right now
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
add_compile_options("-Wuninitialized" "-Wold-style-cast" "-Wstrict-aliasing")
add_compile_options("-Wuninitialized" "-Wold-style-cast")
else()
message(WARNING "Unknown compiler: '${CMAKE_CXX_COMPILER_ID}' - No warning flags enabled.")
endif()
@@ -385,7 +345,7 @@ target_precompile_headers(
target_precompile_headers(
tinyxml2 PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${tinyxml2_SOURCE_DIR}/tinyxml2.h>"
"$<$<COMPILE_LANGUAGE:CXX>:${PROJECT_SOURCE_DIR}/thirdparty/tinyxml2/tinyxml2.h>"
)
if(${ENABLE_TESTING})

View File

@@ -60,7 +60,7 @@ int main(int argc, char** argv) {
try {
Database::Connect();
} catch (sql::SQLException& ex) {
} catch (std::exception& ex) {
LOG("Got an error while connecting to the database: %s", ex.what());
Database::Destroy("AuthServer");
delete Game::server;

View File

@@ -81,7 +81,7 @@ int main(int argc, char** argv) {
//Connect to the MySQL Database
try {
Database::Connect();
} catch (sql::SQLException& ex) {
} catch (std::exception& ex) {
LOG("Got an error while connecting to the database: %s", ex.what());
Database::Destroy("ChatServer");
delete Game::server;

View File

@@ -123,7 +123,7 @@ uint32_t BrickByBrickFix::UpdateBrickByBrickModelsToSd0() {
Database::Get()->UpdateUgcModelData(model.id, outputStringStream);
LOG("Updated model %i to sd0", model.id);
updatedModels++;
} catch (sql::SQLException exception) {
} catch (std::exception& exception) {
LOG("Failed to update model %i. This model should be inspected manually to see why."
"The database error is %s", model.id, exception.what());
}

View File

@@ -70,6 +70,5 @@ else ()
endif ()
target_link_libraries(dCommon
PUBLIC magic_enum
PRIVATE ZLIB::ZLIB bcrypt tinyxml2
INTERFACE dDatabase)

View File

@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <magic_enum/magic_enum.hpp>
#include "magic_enum.hpp"
namespace MessageType {
enum class Game : uint16_t {

View File

@@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <magic_enum/magic_enum.hpp>
#include "magic_enum.hpp"
namespace MessageType {
enum class World : uint32_t {

View File

@@ -2,7 +2,7 @@
#define __STRINGIFIEDENUM_H__
#include <string>
#include <magic_enum/magic_enum.hpp>
#include "magic_enum.hpp"
namespace StringifiedEnum {
template<typename T>

View File

@@ -4,7 +4,8 @@
#define __EINVENTORYTYPE__H__
#include <cstdint>
#include <magic_enum/magic_enum.hpp>
#include "magic_enum.hpp"
static const uint8_t NUMBER_OF_INVENTORIES = 17;
/**

View File

@@ -4,4 +4,4 @@ add_subdirectory(GameDatabase)
add_library(dDatabase STATIC "MigrationRunner.cpp")
target_include_directories(dDatabase PUBLIC ".")
target_link_libraries(dDatabase
PUBLIC magic_enum dDatabaseCDClient dDatabaseGame)
PUBLIC dDatabaseCDClient dDatabaseGame)

View File

@@ -34,7 +34,7 @@ Migration LoadMigration(std::string path) {
void MigrationRunner::RunMigrations() {
Database::Get()->CreateMigrationHistoryTable();
sql::SQLString finalSQL = "";
std::string finalSQL = "";
bool runSd0Migrations = false;
for (const auto& entry : GeneralUtils::GetSqlFileNamesFromFolder((BinaryPathFinder::GetBinaryDir() / "./migrations/dlu/").string())) {
auto migration = LoadMigration("dlu/" + entry);
@@ -61,12 +61,12 @@ void MigrationRunner::RunMigrations() {
}
if (!finalSQL.empty()) {
auto migration = GeneralUtils::SplitString(static_cast<std::string>(finalSQL), ';');
auto migration = GeneralUtils::SplitString(finalSQL, ';');
for (auto& query : migration) {
try {
if (query.empty()) continue;
Database::Get()->ExecuteCustomQuery(query.c_str());
} catch (sql::SQLException& e) {
Database::Get()->ExecuteCustomQuery(query);
} catch (std::exception& e) {
LOG("Encountered error running migration: %s", e.what());
}
}

View File

@@ -55,7 +55,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
"VerifyBehavior.cpp")
add_library(dBehaviors OBJECT ${DGAME_DBEHAVIORS_SOURCES})
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics magic_enum tinyxml2)
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics)
target_include_directories(dBehaviors PUBLIC "."
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # via BehaviorContext.h
PRIVATE

View File

@@ -79,4 +79,4 @@ target_include_directories(dComponents PUBLIC "."
)
target_precompile_headers(dComponents REUSE_FROM dGameBase)
target_link_libraries(dComponents PUBLIC magic_enum tinyxml2 INTERFACE dBehaviors)
target_link_libraries(dComponents INTERFACE dBehaviors)

View File

@@ -6,7 +6,7 @@ set(DGAME_DGAMEMESSAGES_SOURCES
add_library(dGameMessages OBJECT ${DGAME_DGAMEMESSAGES_SOURCES})
target_link_libraries(dGameMessages
PUBLIC magic_enum tinyxml2 dDatabase
PUBLIC dDatabase
INTERFACE dGameBase # TradingManager
)
target_include_directories(dGameMessages PUBLIC "."

View File

@@ -24,7 +24,6 @@ target_include_directories(dInventory PUBLIC "."
"${PROJECT_SOURCE_DIR}/dGame/dMission" # via MissionComponent.h
"${PROJECT_SOURCE_DIR}/dZoneManager" # via Item.cpp
)
target_link_libraries(dInventory PUBLIC magic_enum tinyxml2)
target_precompile_headers(dInventory REUSE_FROM dGameBase)
# Workaround for compiler bug where the optimized code could result in a memcpy of 0 bytes, even though that isnt possible.
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97185

View File

@@ -4,7 +4,7 @@ set(DGAME_DMISSION_SOURCES
"MissionTask.cpp")
add_library(dMission OBJECT ${DGAME_DMISSION_SOURCES})
target_link_libraries(dMission PUBLIC tinyxml2 dDatabase)
target_link_libraries(dMission PUBLIC dDatabase)
target_include_directories(dMission PUBLIC "."
PRIVATE
"${PROJECT_SOURCE_DIR}/dGame/dComponents"

View File

@@ -13,7 +13,7 @@ foreach(file ${DGAME_DPROPERTYBEHAVIORS_CONTROLBEHAVIORMESSAGES})
endforeach()
add_library(dPropertyBehaviors OBJECT ${DGAME_DPROPERTYBEHAVIORS_SOURCES})
target_link_libraries(dPropertyBehaviors PUBLIC tinyxml2 PRIVATE dDatabaseCDClient)
target_link_libraries(dPropertyBehaviors PRIVATE dDatabaseCDClient)
target_include_directories(dPropertyBehaviors PUBLIC "." "ControlBehaviorMessages"
PRIVATE
"${PROJECT_SOURCE_DIR}/dCommon/dClient" # ControlBehaviors.cpp uses AssetManager

View File

@@ -103,7 +103,7 @@ int main(int argc, char** argv) {
//Connect to the MySQL Database
try {
Database::Connect();
} catch (sql::SQLException& ex) {
} catch (std::exception& ex) {
LOG("Got an error while connecting to the database: %s", ex.what());
LOG("Migrations not run");
return EXIT_FAILURE;
@@ -264,7 +264,7 @@ int main(int argc, char** argv) {
//Create account
try {
Database::Get()->InsertNewAccount(username, std::string(hash, BCRYPT_HASHSIZE));
} catch (sql::SQLException& e) {
} catch (std::exception& e) {
LOG("A SQL error occurred!:\n %s", e.what());
return EXIT_FAILURE;
}

View File

@@ -24,9 +24,9 @@ void PersistentIDManager::Initialize() {
LOG("Invalid persistent object ID in database. Aborting to prevent bad id generation.");
throw std::runtime_error("Invalid persistent object ID in database. Aborting to prevent bad id generation.");
}
} catch (sql::SQLException& e) {
} catch (std::exception& e) {
LOG("Unable to fetch max persistent object ID in use. This will cause issues. Aborting to prevent collisions.");
LOG("SQL error: %s", e.what());
LOG("Error: %s", e.what());
throw e;
}
}

View File

@@ -14,4 +14,4 @@ target_include_directories(dNavigation PUBLIC "."
"${PROJECT_SOURCE_DIR}/dGame/dEntity"
"${PROJECT_SOURCE_DIR}/dNavigation/dTerrain" # via dNavMesh.cpp
)
target_link_libraries(dNavigation PUBLIC tinyxml2 PRIVATE Detour Recast dCommon)
target_link_libraries(dNavigation PRIVATE Detour Recast dCommon)

View File

@@ -87,6 +87,13 @@ void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, c
server->Send(bitStream, sysAddr, false);
}
std::string CleanReceivedString(const std::string& str) {
std::string toReturn = str;
const auto removed = std::ranges::find_if(toReturn, [](char c) { return isprint(c) == 0 && isblank(c) == 0; });
toReturn.erase(removed, toReturn.end());
return toReturn;
}
void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
CINSTREAM_SKIP_HEADER;
@@ -111,11 +118,11 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) {
LUWString memoryStats(256);
inStream.Read(memoryStats);
LOG_DEBUG("Memory Stats [%s]", memoryStats.GetAsString().c_str());
LOG_DEBUG("Memory Stats [%s]", CleanReceivedString(memoryStats.GetAsString()).c_str());
LUWString videoCard(128);
inStream.Read(videoCard);
LOG_DEBUG("VideoCard Info: [%s]", videoCard.GetAsString().c_str());
LOG_DEBUG("VideoCard Info: [%s]", CleanReceivedString(videoCard.GetAsString()).c_str());
// Processor/CPU info
uint32_t numOfProcessors;

View File

@@ -4,7 +4,7 @@
#define _VARIADIC_MAX 10
#include "dCommonVars.h"
#include "dNetCommon.h"
#include <magic_enum/magic_enum.hpp>
#include "magic_enum.hpp"
enum class ServerType : uint32_t;
enum class eLoginResponse : uint8_t;

View File

@@ -8,7 +8,7 @@ set(DNET_SOURCES "AuthPackets.cpp"
"ZoneInstanceManager.cpp")
add_library(dNet STATIC ${DNET_SOURCES})
target_link_libraries(dNet PUBLIC magic_enum PRIVATE bcrypt MD5)
target_link_libraries(dNet PRIVATE bcrypt MD5)
target_include_directories(dNet PRIVATE
"${PROJECT_SOURCE_DIR}/dCommon"
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"

View File

@@ -12,7 +12,10 @@ void BaseFootRaceManager::OnFireEventServerSide(Entity* self, Entity* sender, st
if (splitArguments.size() > 1) {
const auto eventName = splitArguments[0];
const auto player = Game::entityManager->GetEntity(std::stoull(splitArguments[1]));
auto playerId = GeneralUtils::TryParse<LWOOBJID>(splitArguments[1]);
if (!playerId) return;
const auto player = Game::entityManager->GetEntity(playerId.value());
if (player != nullptr) {
if (eventName == "updatePlayer") {

View File

@@ -13,7 +13,7 @@ target_include_directories(WorldServer PRIVATE
"${PROJECT_SOURCE_DIR}/dServer" # BinaryPathFinder.h
)
target_link_libraries(WorldServer PUBLIC ${COMMON_LIBRARIES}
target_link_libraries(WorldServer ${COMMON_LIBRARIES}
dScripts
dGameBase
dComponents

View File

@@ -194,7 +194,7 @@ int main(int argc, char** argv) {
//Connect to the MySQL Database:
try {
Database::Connect();
} catch (sql::SQLException& ex) {
} catch (std::exception& ex) {
LOG("Got an error while connecting to the database: %s", ex.what());
return EXIT_FAILURE;
}

View File

@@ -32,7 +32,7 @@ add_custom_command(TARGET dCommonTests POST_BUILD
endif()
# Link needed libraries
target_link_libraries(dCommonTests ${COMMON_LIBRARIES} GTest::gtest_main magic_enum)
target_link_libraries(dCommonTests ${COMMON_LIBRARIES} GTest::gtest_main)
# Copy test files to testing directory
add_subdirectory(TestBitStreams)

View File

@@ -8,7 +8,7 @@
#include "Game.h"
#include "MessageType/Game.h"
#include "MessageType/World.h"
#include <magic_enum/magic_enum.hpp>
#include "magic_enum.hpp"
#define ENUM_EQ(e, y, z)\
LOG("%s %s", StringifiedEnum::ToString(static_cast<e>(y)).data(), #z);\

View File

@@ -23,7 +23,7 @@ add_custom_command(TARGET dGameTests POST_BUILD
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()
target_link_libraries(dGameTests ${COMMON_LIBRARIES} magic_enum GTest::gtest_main
target_link_libraries(dGameTests ${COMMON_LIBRARIES} GTest::gtest_main
dGame dScripts dPhysics Detour Recast tinyxml2 dWorldServer dZoneManager dChatFilter dNavigation)
# Discover the tests

View File

@@ -1,12 +1,17 @@
# Source Code for recast
# add_subdirectory(recastnavigation)
add_subdirectory(recastnavigation)
# Turn off tinyxml2 testing
set(tinyxml2_BUILD_TESTING OFF)
# Source Code for tinyxml2
add_subdirectory(tinyxml2)
# Source Code for libbcrypt. Uses a file glob instead to get around Windows build issues.
file(
GLOB SOURCES_LIBBCRYPT
LIST_DIRECTORIES false
RELATIVE "${DLU_THIRDPARTY_SOURCE_DIR}"
${DLU_THIRDPARTY_SOURCE_DIR}/libbcrypt/src/*.c
file(
GLOB SOURCES_LIBBCRYPT
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${CMAKE_CURRENT_SOURCE_DIR}/libbcrypt/src/*.c
)
add_library(bcrypt ${SOURCES_LIBBCRYPT})
@@ -15,12 +20,12 @@ add_library(bcrypt ${SOURCES_LIBBCRYPT})
# fortunately they are only needed for building the libbcrypt directory and nothing else, so these are marked private.
if(NOT WIN32)
target_include_directories(bcrypt PRIVATE "libbcrypt/include/bcrypt")
target_include_directories(bcrypt PRIVATE "libbcrypt/include/bcrypt")
endif()
# Need to define this on Clang and GNU for 'strdup' support
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
target_compile_definitions(bcrypt PRIVATE "_POSIX_C_SOURCE=200809L")
target_compile_definitions(bcrypt PRIVATE "_POSIX_C_SOURCE=200809L")
endif()
target_include_directories(bcrypt INTERFACE "libbcrypt/include")
@@ -29,12 +34,21 @@ target_include_directories(bcrypt PRIVATE "libbcrypt/src")
# Source code for sqlite
add_subdirectory(SQLite)
# Source code for magic_enum
add_subdirectory(magic_enum)
# Create our third party library objects
add_subdirectory(raknet)
# Download Backtrace if configured
if(UNIX AND NOT APPLE)
include(FetchContent)
if (${INCLUDE_BACKTRACE} AND ${COMPILE_BACKTRACE})
FetchContent_Declare(
backtrace
GIT_REPOSITORY https://github.com/ianlancetaylor/libbacktrace.git
)
FetchContent_MakeAvailable(backtrace)
if (NOT EXISTS ${backtrace_SOURCE_DIR}/.libs)

1
thirdparty/libbcrypt vendored Submodule

Submodule thirdparty/libbcrypt added at d6523c370d

1
thirdparty/magic_enum vendored Submodule

Submodule thirdparty/magic_enum added at e55b9b54d5

1
thirdparty/recastnavigation vendored Submodule

1
thirdparty/tinyxml2 vendored Submodule

Submodule thirdparty/tinyxml2 added at a977397684