Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔥 Remove networking #10

Merged
merged 3 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions 3rdParty/asio/CMakeLists.txt

This file was deleted.

19 changes: 0 additions & 19 deletions 3rdParty/libsodium/CMakeLists.txt

This file was deleted.

55 changes: 0 additions & 55 deletions 3rdParty/libzt/CMakeLists.txt

This file was deleted.

62 changes: 2 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ option(PIE "Generate position-independent code" OFF)
option(DIST "Dynamically link only glibc and SDL2" OFF)
option(BINARY_RELEASE "Enable options for binary release" OFF)
option(NIGHTLY_BUILD "Enable options for nightly build" OFF)
option(NONET "Disable network support" OFF)
option(NOSOUND "Disable sound support" OFF)

if(NOT NONET)
option(DISABLE_TCP "Disable TCP multiplayer option" OFF)
option(DISABLE_ZERO_TIER "Disable ZeroTier multiplayer option" OFF)
endif()

option(DISABLE_STREAMING_MUSIC "Disable streaming music (to work around broken platform implementations)" OFF)
mark_as_advanced(DISABLE_STREAMING_MUSIC)
option(DISABLE_STREAMING_SOUNDS "Disable streaming sounds (to work around broken platform implementations)" OFF)
Expand Down Expand Up @@ -63,12 +57,6 @@ if(NOT NOSOUND)
"DEVILUTIONX_SYSTEM_SDL_AUDIOLIB AND NOT DIST" ON)
endif()

if(NOT NONET)
option(DEVILUTIONX_SYSTEM_LIBSODIUM "Use system-provided libsodium" ON)
cmake_dependent_option(DEVILUTIONX_STATIC_LIBSODIUM "Link static libsodium" OFF
"DEVILUTIONX_SYSTEM_LIBSODIUM AND NOT DIST" ON)
endif()

option(DEVILUTIONX_SYSTEM_LIBFMT "Use system-provided libfmt" ON)
cmake_dependent_option(DEVILUTIONX_STATIC_LIBFMT "Link static libfmt" OFF
"DEVILUTIONX_SYSTEM_LIBFMT AND NOT DIST" ON)
Expand Down Expand Up @@ -163,15 +151,6 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)

find_package(Threads REQUIRED)

if(NOT NONET)
if(DEVILUTIONX_SYSTEM_LIBSODIUM)
set(sodium_USE_STATIC_LIBS ${DEVILUTIONX_STATIC_LIBSODIUM})
find_package(sodium REQUIRED)
else()
add_subdirectory(3rdParty/libsodium)
endif()
endif()

if(DEVILUTIONX_SYSTEM_LIBFMT)
find_package(fmt 7.0.0 QUIET)
if(fmt_FOUND)
Expand Down Expand Up @@ -219,10 +198,6 @@ else()
endif()
find_package(SDL2_ttf REQUIRED)

if(NOT NONET AND NOT DISABLE_TCP)
add_subdirectory(3rdParty/asio)
endif()

add_subdirectory(3rdParty/SDL_image)

if(NOT NOSOUND)
Expand Down Expand Up @@ -384,10 +359,10 @@ set(libdevilutionx_SRCS
Source/panels/mainpanel.cpp
Source/dvlnet/abstract_net.cpp
Source/dvlnet/base.cpp
Source/dvlnet/cdwrap.cpp
Source/dvlnet/cdwrap.cpp
Source/dvlnet/frame_queue.cpp
Source/dvlnet/loopback.cpp
Source/dvlnet/packet.cpp
Source/dvlnet/packet.cpp
Source/storm/storm.cpp

Source/storm/storm_net.cpp
Expand All @@ -407,20 +382,6 @@ else()
Source/utils/soundsample.cpp)
endif()

if(NOT NONET)
if(NOT DISABLE_TCP)
list(APPEND libdevilutionx_SRCS
Source/dvlnet/tcp_client.cpp
Source/dvlnet/tcp_server.cpp)
endif()
if(NOT DISABLE_ZERO_TIER)
list(APPEND libdevilutionx_SRCS
Source/dvlnet/protocol_zt.cpp
Source/dvlnet/zerotier_native.cpp
Source/dvlnet/zerotier_lwip.cpp)
endif()
endif()

set(BIN_TARGET devilutionx)

add_library(libdevilutionx OBJECT ${libdevilutionx_SRCS})
Expand Down Expand Up @@ -475,31 +436,17 @@ if(WIN32)
target_link_libraries(libdevilutionx PUBLIC find_steam_game)
endif()

if(NOT NONET)
if(NOT DISABLE_TCP)
target_link_libraries(libdevilutionx PUBLIC asio)
endif()
target_link_libraries(libdevilutionx PUBLIC sodium)
endif()

target_link_libraries(libdevilutionx PUBLIC fmt::fmt)
target_link_libraries(libdevilutionx PUBLIC PNG::PNG)

genex_for_option(DEBUG)
target_compile_definitions(libdevilutionx PUBLIC "$<${DEBUG_GENEX}:_DEBUG>")

if(NOT NONET AND NOT DISABLE_TCP)
target_compile_definitions(libdevilutionx PUBLIC ASIO_STANDALONE)
endif()

# Defines without value
foreach(
def_name
NOSOUND
NONET
PREFILL_PLAYER_NAME
DISABLE_TCP
DISABLE_ZERO_TIER
DISABLE_STREAMING_MUSIC
DISABLE_STREAMING_SOUNDS
GPERF
Expand Down Expand Up @@ -760,8 +707,3 @@ if(CPACK)
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
include(CPack)
endif()

if(NOT NONET AND NOT DISABLE_ZERO_TIER)
add_subdirectory(3rdParty/libzt)
target_link_libraries(libdevilutionx PUBLIC zt-static)
endif()
8 changes: 0 additions & 8 deletions Source/DiabloUI/selconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ void SelconnLoad()
{
LoadBackgroundArt("ui_art\\selconn.pcx");

#ifndef NONET
#ifndef DISABLE_ZERO_TIER
vecConnItems.push_back(std::make_unique<UiListItem>("Zerotier", SELCONN_ZT));
#endif
#ifndef DISABLE_TCP
vecConnItems.push_back(std::make_unique<UiListItem>("Client-Server (TCP)", SELCONN_TCP));
#endif
#endif
vecConnItems.push_back(std::make_unique<UiListItem>("Loopback", SELCONN_LOOPBACK));

UiAddBackground(&vecSelConnDlg);
Expand Down
27 changes: 0 additions & 27 deletions Source/dvlnet/abstract_net.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#include "dvlnet/abstract_net.h"

#include "utils/stubs.h"
#ifndef NONET
#include "dvlnet/base_protocol.h"
#include "dvlnet/cdwrap.h"
#ifndef DISABLE_ZERO_TIER
#include "dvlnet/protocol_zt.h"
#endif
#ifndef DISABLE_TCP
#include "dvlnet/tcp_client.h"
#endif
#endif
#include "dvlnet/loopback.h"
#include "storm/storm.h"

Expand All @@ -19,24 +9,7 @@ namespace net {

std::unique_ptr<abstract_net> abstract_net::MakeNet(provider_t provider)
{
#ifdef NONET
return std::make_unique<loopback>();
#else
switch (provider) {
#ifndef DISABLE_TCP
case SELCONN_TCP:
return std::make_unique<cdwrap<tcp_client>>();
#endif
#ifndef DISABLE_ZERO_TIER
case SELCONN_ZT:
return std::make_unique<cdwrap<base_protocol<protocol_zt>>>();
#endif
case SELCONN_LOOPBACK:
return std::make_unique<loopback>();
default:
ABORT();
}
#endif
}

} // namespace net
Expand Down
71 changes: 5 additions & 66 deletions Source/dvlnet/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
namespace devilution {
namespace net {

#ifndef NONET
static constexpr bool DisableEncryption = false;
#endif

const char *packet_type_to_string(uint8_t packetType)
{
switch (packetType) {
Expand Down Expand Up @@ -154,31 +150,10 @@ void packet_in::Decrypt()
ABORT();
if (have_decrypted)
return;
#ifndef NONET
if (!DisableEncryption) {
if (encrypted_buffer.size() < crypto_secretbox_NONCEBYTES
+ crypto_secretbox_MACBYTES
+ sizeof(packet_type) + 2 * sizeof(plr_t))
throw packet_exception();
auto pktlen = (encrypted_buffer.size()
- crypto_secretbox_NONCEBYTES
- crypto_secretbox_MACBYTES);
decrypted_buffer.resize(pktlen);
int status = crypto_secretbox_open_easy(
decrypted_buffer.data(),
encrypted_buffer.data() + crypto_secretbox_NONCEBYTES,
encrypted_buffer.size() - crypto_secretbox_NONCEBYTES,
encrypted_buffer.data(),
key.data());
if (status != 0)
throw packet_exception();
} else
#endif
{
if (encrypted_buffer.size() < sizeof(packet_type) + 2 * sizeof(plr_t))
throw packet_exception();
decrypted_buffer = encrypted_buffer;
}

if (encrypted_buffer.size() < sizeof(packet_type) + 2 * sizeof(plr_t))
throw packet_exception();
decrypted_buffer = encrypted_buffer;

process_data();

Expand All @@ -194,48 +169,12 @@ void packet_out::Encrypt()

process_data();

#ifndef NONET
if (!DisableEncryption) {
auto lenCleartext = encrypted_buffer.size();
encrypted_buffer.insert(encrypted_buffer.begin(),
crypto_secretbox_NONCEBYTES, 0);
encrypted_buffer.insert(encrypted_buffer.end(),
crypto_secretbox_MACBYTES, 0);
randombytes_buf(encrypted_buffer.data(), crypto_secretbox_NONCEBYTES);
int status = crypto_secretbox_easy(
encrypted_buffer.data() + crypto_secretbox_NONCEBYTES,
encrypted_buffer.data() + crypto_secretbox_NONCEBYTES,
lenCleartext,
encrypted_buffer.data(),
key.data());
if (status != 0)
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));
pw.resize(std::max<std::size_t>(pw.size(), crypto_pwhash_argon2id_PASSWD_MIN), 0);
std::string salt("W9bE9dQgVaeybwr2");
salt.resize(crypto_pwhash_argon2id_SALTBYTES, 0);
int status = crypto_pwhash(
key.data(),
crypto_secretbox_KEYBYTES,
pw.data(),
pw.size(),
reinterpret_cast<const unsigned char *>(salt.data()),
3 * crypto_pwhash_argon2id_OPSLIMIT_MIN,
2 * crypto_pwhash_argon2id_MEMLIMIT_MIN,
crypto_pwhash_ALG_ARGON2ID13);
if (status != 0)
ABORT();
#endif

}

} // namespace net
Expand Down
8 changes: 1 addition & 7 deletions Source/dvlnet/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <memory>
#include <array>
#include <cstring>
#ifndef NONET
#include <sodium.h>
#endif

#include "dvlnet/abstract_net.h"
#include "utils/stubs.h"
Expand Down Expand Up @@ -35,12 +32,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;
#else

// Stub out the key_t defintion as we're not doing any encryption.
using key_t = uint8_t;
#endif

static constexpr plr_t PLR_MASTER = 0xFE;
static constexpr plr_t PLR_BROADCAST = 0xFF;
Expand Down
Loading