Skip to content

Commit

Permalink
fix: exorcised the scary head. halloween is over (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 authored Oct 31, 2023
1 parent 3eaf668 commit 31976ec
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 42 deletions.
4 changes: 2 additions & 2 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ class DPP_EXPORT cluster {
/**
* @brief dpp::cluster is non-copyable
*/
cluster& operator=(const cluster&) = delete;
cluster& operator=(const cluster&) = delete;

/**
* @brief dpp::cluster is non-moveable
*/
cluster& operator=(const cluster&&) = delete;
cluster& operator=(const cluster&&) = delete;

/**
* @brief Destroy the cluster object
Expand Down
56 changes: 56 additions & 0 deletions include/dpp/export.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,62 @@
#define DPP_EXPORT
#endif

namespace dpp {

/**
* @brief Represents a build configuration. On some platforms (e.g. Windows) release isn't compatible with debug, so we use this enum to detect it.
*/
enum class build_type {
/**
* @brief Universal build, works with both debug and release
*/
universal,

/**
* @brief Debug build
*/
debug,

/**
* @brief Release build
*/
release
};

template <build_type>
extern bool DPP_EXPORT validate_configuration();

#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_GAME) || defined(UE_EDITOR) || defined(UE_BUILD_SHIPPING_WITH_EDITOR) || defined(UE_BUILD_DOCS)
/*
* We need to tell DPP to NOT do the version checker if something from Unreal Engine is defined.
* We have to do this because UE is causing some weirdness where the version checker is broken and always errors.
* This is really only for DPP-UE. There is no reason to not do the version checker unless you are in Unreal Engine.
*/
#define DPP_BYPASS_VERSION_CHECKING
#endif /* UE */

#ifndef DPP_BUILD /* when including dpp */
/**
* Version checking, making sure the program is in a configuration compatible with DPP's.
*
* Do NOT make these variables constexpr.
* We want them to initialize at runtime so the function can be pulled from the shared library object.
*/
#ifndef DPP_BYPASS_VERSION_CHECKING
#if defined(_WIN32)
#ifdef _DEBUG
inline const bool is_valid_config = validate_configuration<build_type::debug>();
#else
inline const bool is_valid_config = validate_configuration<build_type::release>();
#endif /* _DEBUG */
#else
inline const bool is_valid_config = validate_configuration<build_type::universal>();
#endif /* _WIN32 */
#endif /* !DPP_BYPASS_VERSION_CHECKING */
#endif /* !DPP_BUILD */

}

#ifndef _WIN32
#define SOCKET int
#else
Expand Down
30 changes: 0 additions & 30 deletions include/dpp/restresults.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,6 @@

namespace dpp {

#ifdef _WIN32
#ifdef _DEBUG
extern "C" DPP_EXPORT void you_are_using_a_debug_build_of_dpp_on_a_release_project();
#else
extern "C" DPP_EXPORT void you_are_using_a_release_build_of_dpp_on_a_debug_project();
#endif
#endif

struct DPP_EXPORT version_checker {
version_checker() {
#ifdef _WIN32
#ifdef _DEBUG
you_are_using_a_debug_build_of_dpp_on_a_release_project();
#else
you_are_using_a_release_build_of_dpp_on_a_debug_project();
#endif
#endif
}
};

/*
* We need to tell DPP to NOT do the version checker if something from Unreal Engine is defined.
* We have to do this because UE is causing some weirdness where the version checker is broken and always errors.
* This is really only for DPP-UE. There is no reason to not do the version checker unless you are in Unreal Engine.
*/
#if !defined(UE_BUILD_DEBUG) && !defined(UE_BUILD_DEVELOPMENT) && !defined(UE_BUILD_TEST) && !defined(UE_BUILD_SHIPPING) && !defined(UE_GAME) && !defined(UE_EDITOR) && !defined(UE_BUILD_SHIPPING_WITH_EDITOR) && !defined(UE_BUILD_DOCS)
static version_checker dpp_vc;
#endif


/**
* @brief A list of shards
*/
Expand Down
42 changes: 32 additions & 10 deletions src/dpp/cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@

namespace dpp {

#ifdef _WIN32
#ifdef _DEBUG
extern "C" void you_are_using_a_debug_build_of_dpp_on_a_release_project() {
}
#else
extern "C" void you_are_using_a_release_build_of_dpp_on_a_debug_project() {
}
#endif
#endif

/**
* @brief An audit reason for each thread. These are per-thread to make the cluster
* methods like cluster::get_audit_reason and cluster::set_audit_reason thread safe across
Expand All @@ -70,6 +60,38 @@ template<typename T> std::function<void(const T&)> make_intent_warning(cluster*
};
}

template <build_type BuildType>
bool validate_configuration() {
#ifdef _DEBUG
constexpr build_type expected = build_type::debug;
#else
constexpr build_type expected = build_type::release;
#endif
#ifdef _WIN32
if constexpr (BuildType != build_type::universal && BuildType != expected) {
MessageBox(
nullptr,
"Mismatched Debug/Release configurations between project and dpp.dll.\n"
"Please ensure both your program and the D++ DLL file are both using the same configuration.\n"
"The program will now terminate.",
"D++ Debug/Release mismatch",
MB_OK | MB_ICONERROR
);
/* Use std::runtime_rror here because dpp exceptions use std::string and that would crash when catching, because of ABI */
throw std::runtime_error("Mismatched Debug/Release configurations between project and dpp.dll");
}
return true;
#else
return true;
#endif
}

template bool DPP_EXPORT validate_configuration<build_type::debug>();

template bool DPP_EXPORT validate_configuration<build_type::release>();

template bool DPP_EXPORT validate_configuration<build_type::universal>();

cluster::cluster(const std::string &_token, uint32_t _intents, uint32_t _shards, uint32_t _cluster_id, uint32_t _maxclusters, bool comp, cache_policy_t policy, uint32_t request_threads, uint32_t request_threads_raw)
: default_gateway("gateway.discord.gg"), rest(nullptr), raw_rest(nullptr), compressed(comp), start_time(0), token(_token), last_identify(time(nullptr) - 5), intents(_intents),
numshards(_shards), cluster_id(_cluster_id), maxclusters(_maxclusters), rest_ping(0.0), cache_policy(policy), ws_mode(ws_json)
Expand Down

0 comments on commit 31976ec

Please sign in to comment.