Browse Source

Add option to disable network support for builds

pull/304/head
Marlon Beijer 7 years ago committed by Anders Jenbo
parent
commit
3a267aa7f7
  1. 30
      CMakeLists.txt
  2. 2
      README.md
  3. 4
      SourceX/DiabloUI/selconn.cpp
  4. 6
      SourceX/dvlnet/abstract_net.cpp
  5. 11
      SourceX/dvlnet/packet.cpp
  6. 4
      SourceX/dvlnet/packet.h

30
CMakeLists.txt

@ -19,6 +19,7 @@ option(FASTER "Enable FASTER in engine" ON)
option(BINARY_RELEASE "Enable options for binary release" OFF)
option(NIGHTLY_BUILD "Enable options for nightly build" OFF)
option(USE_SDL1 "Use SDL1.2 instead of SDL2" OFF)
option(NONET "Disable network" OFF)
if(BINARY_RELEASE)
set(CMAKE_BUILD_TYPE "Release")
@ -62,7 +63,9 @@ set(CMAKE_THREAD_PREFER_PTHREAD ON)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(sodium REQUIRED)
if(NOT NONET)
find_package(sodium REQUIRED)
endif()
if(USE_SDL1)
find_package(SDL REQUIRED)
@ -176,7 +179,7 @@ add_library(devilution STATIC
Source/trigs.cpp
Source/wave.cpp)
add_executable(devilutionx MACOSX_BUNDLE
set(devilutionx_SRCS
SourceX/dx.cpp
SourceX/miniwin/misc.cpp
SourceX/miniwin/misc_io.cpp
@ -194,9 +197,6 @@ add_executable(devilutionx MACOSX_BUNDLE
SourceX/dvlnet/packet.cpp
SourceX/dvlnet/base.cpp
SourceX/dvlnet/frame_queue.cpp
SourceX/dvlnet/tcp_client.cpp
SourceX/dvlnet/tcp_server.cpp
SourceX/dvlnet/udp_p2p.cpp
SourceX/DiabloUI/art.cpp
SourceX/DiabloUI/credits.cpp
SourceX/DiabloUI/diabloui.cpp
@ -212,6 +212,15 @@ add_executable(devilutionx MACOSX_BUNDLE
./Packaging/macOS/AppIcon.icns
./Packaging/resources/CharisSILB.ttf)
if(NOT NONET)
list(APPEND devilutionx_SRCS
SourceX/dvlnet/tcp_client.cpp
SourceX/dvlnet/tcp_server.cpp
SourceX/dvlnet/udp_p2p.cpp)
endif()
add_executable(devilutionx MACOSX_BUNDLE ${devilutionx_SRCS})
configure_file(SourceS/config.h.in config.h @ONLY)
target_include_directories(devilution PUBLIC Source SourceS ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(devilutionx PRIVATE
@ -226,8 +235,11 @@ target_link_libraries(devilutionx PRIVATE
PKWare
StormLib
smacker
Radon
sodium)
Radon)
if(NOT NONET)
target_link_libraries(devilutionx PRIVATE sodium)
endif()
target_compile_definitions(devilution PRIVATE DEVILUTION_ENGINE)
target_compile_definitions(devilution PUBLIC
@ -249,6 +261,10 @@ foreach(target devilution devilutionx)
SDL2::SDL2_mixer)
endif()
if(NONET)
target_compile_definitions(${target} PRIVATE NONET)
endif()
if(ASAN)
target_compile_options(${target} PUBLIC -fsanitize=address -fsanitize-recover=address)
target_link_libraries(${target} PUBLIC -fsanitize=address -fsanitize-recover=address)

2
README.md

@ -150,6 +150,8 @@ make -j$(nproc)
### General
The default build type is `Debug`. This can be changed with `-DBINARY_RELEASE=ON`. Independently of this, the debug mode of the Diablo engine is always enabled by default. It can be disabled with `-DDEBUG=OFF`. Finally, in debug builds the address sanitizer is enabled by default. This can be disabled with `-DASAN=OFF`.
You can also generate 32bit builds on 64bit platforms by setting `-DCMAKE_TOOLCHAIN_FILE=../CMake/32bit.cmake` (remember to use the `linux32` command if on Linux).
Network support can be deiabled using `-DNONET`, this also removes the need for the ASIO and Sodium dependencies
### mingw32
Use `-DCROSS_PREFIX=/path/to/prefix` if the `i686-w64-mingw32` directory is not in `/usr`.
### Use SDL v1 instead of SDL v2.

4
SourceX/DiabloUI/selconn.cpp

@ -19,9 +19,13 @@ DWORD provider;
UiText SELCONNECT_DIALOG_DESCRIPTION(selconn_Description, { 35, 275, 205, 66 });
UiListItem SELCONN_DIALOG_ITEMS[] = {
#ifndef NONET
{ "Client-Server (TCP)", 0 },
{ "Peer-to-Peer (UDP)", 1 },
{ "Loopback", 2 },
#else
{ "Loopback", 0 },
#endif
};
UiItem SELCONNECT_DIALOG[] = {
UiImage(&ArtBackground, { 0, 0, 640, 480 }),

6
SourceX/dvlnet/abstract_net.cpp

@ -1,8 +1,10 @@
#include "dvlnet/abstract_net.h"
#include "stubs.h"
#ifndef NONET
#include "dvlnet/tcp_client.h"
#include "dvlnet/udp_p2p.h"
#endif
#include "dvlnet/loopback.h"
namespace dvl {
@ -14,6 +16,9 @@ abstract_net::~abstract_net()
std::unique_ptr<abstract_net> abstract_net::make_net(provider_t provider)
{
#ifdef NONET
return std::unique_ptr<abstract_net>(new loopback);
#else
if (provider == 'TCPN') {
return std::unique_ptr<abstract_net>(new tcp_client);
} else if (provider == 'UDPN') {
@ -23,6 +28,7 @@ std::unique_ptr<abstract_net> abstract_net::make_net(provider_t provider)
} else {
ABORT();
}
#endif
}
} // namespace net

11
SourceX/dvlnet/packet.cpp

@ -3,7 +3,9 @@
namespace dvl {
namespace net {
#ifndef NONET
static constexpr bool disable_encryption = false;
#endif
const buffer_t &packet::data()
{
@ -102,6 +104,7 @@ void packet_in::decrypt()
ABORT();
if (have_decrypted)
return;
#ifndef NONET
if (!disable_encryption) {
if (encrypted_buffer.size() < crypto_secretbox_NONCEBYTES
+ crypto_secretbox_MACBYTES
@ -119,7 +122,9 @@ void packet_in::decrypt()
encrypted_buffer.data(),
key.data()))
throw packet_exception();
} else {
} else
#endif
{
if (encrypted_buffer.size() < sizeof(packet_type) + 2 * sizeof(plr_t))
throw packet_exception();
decrypted_buffer = encrypted_buffer;
@ -139,6 +144,7 @@ void packet_out::encrypt()
process_data();
#ifndef NONET
if (!disable_encryption) {
auto len_cleartext = encrypted_buffer.size();
encrypted_buffer.insert(encrypted_buffer.begin(),
@ -155,11 +161,13 @@ void packet_out::encrypt()
key.data()))
ABORT();
}
#endif
have_encrypted = true;
}
packet_factory::packet_factory(std::string pw)
{
#ifndef NONET
if (sodium_init() < 0)
ABORT();
pw.resize(std::min<std::size_t>(pw.size(), crypto_pwhash_argon2id_PASSWD_MAX));
@ -173,6 +181,7 @@ packet_factory::packet_factory(std::string pw)
crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
crypto_pwhash_ALG_ARGON2ID13))
ABORT();
#endif
}
} // namespace net

4
SourceX/dvlnet/packet.h

@ -4,7 +4,9 @@
#include <memory>
#include <array>
#include <cstring>
#ifndef NONET
#include <sodium.h>
#endif
#include "dvlnet/abstract_net.h"
#include "stubs.h"
@ -25,7 +27,9 @@ typedef uint8_t plr_t;
typedef uint32_t cookie_t;
typedef int turn_t; // change int to something else in devilution code later
typedef int leaveinfo_t; // also change later
#ifndef NONET
typedef std::array<unsigned char, crypto_secretbox_KEYBYTES> key_t;
#endif
static constexpr plr_t PLR_MASTER = 0xFE;
static constexpr plr_t PLR_BROADCAST = 0xFF;

Loading…
Cancel
Save