Browse Source

Only enable exceptions for builds with ZeroTier (#6824)

Co-authored-by: staphen <staphen@gmail.com>
pull/6837/head
Gleb Mazovetskiy 2 years ago committed by GitHub
parent
commit
e5c7f0f174
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CMakeLists.txt
  2. 7
      Source/dvlnet/abstract_net.cpp
  3. 41
      Source/dvlnet/base_protocol.h

2
CMakeLists.txt

@ -130,7 +130,7 @@ set_property(CACHE DEVILUTIONX_DEFAULT_RESAMPLER PROPERTY STRINGS ${_resamplers}
option(DISABLE_LTO "Disable link-time optimization (by default enabled in release mode)" OFF)
option(PIE "Generate position-independent code" OFF)
cmake_dependent_option(DEVILUTIONX_DISABLE_RTTI "Disable RTTI" ON "NONET" OFF)
cmake_dependent_option(DEVILUTIONX_DISABLE_EXCEPTIONS "Disable exceptions" ON "NONET" OFF)
cmake_dependent_option(DEVILUTIONX_DISABLE_EXCEPTIONS "Disable exceptions" ON "DISABLE_ZERO_TIER" OFF)
RELEASE_OPTION(DEVILUTIONX_STATIC_CXX_STDLIB "Link C++ standard library statically (if available)")
option(DEVILUTIONX_PROFILE_GENERATE "Build a binary that generates the profile for PGO" OFF)
option(DEVILUTIONX_PROFILE_USE "Build with PGO using the given profile file" OFF)

7
Source/dvlnet/abstract_net.cpp

@ -1,17 +1,20 @@
#include "dvlnet/abstract_net.h"
#include "dvlnet/loopback.h"
#include "utils/stubs.h"
#ifndef NONET
#include "dvlnet/base_protocol.h"
#include "dvlnet/cdwrap.h"
#ifndef DISABLE_ZERO_TIER
#include "dvlnet/base_protocol.h"
#include "dvlnet/protocol_zt.h"
#endif
#ifndef DISABLE_TCP
#include "dvlnet/tcp_client.h"
#endif
#endif
#include "dvlnet/loopback.h"
namespace devilution::net {

41
Source/dvlnet/base_protocol.h

@ -274,32 +274,27 @@ tl::expected<void, PacketError> base_protocol<P>::SendTo(plr_t player, packet &p
template <class P>
void base_protocol<P>::recv()
{
try {
buffer_t pkt_buf;
endpoint_t sender;
while (proto.recv(sender, pkt_buf)) { // read until kernel buffer is empty?
tl::expected<void, PacketError> result
= pktfty->make_packet(pkt_buf)
.and_then([&](std::unique_ptr<packet> &&pkt) {
return recv_decrypted(*pkt, sender);
});
if (!result.has_value()) {
// drop packet
proto.disconnect(sender);
Log("{}", result.error().what());
}
buffer_t pkt_buf;
endpoint_t sender;
while (proto.recv(sender, pkt_buf)) { // read until kernel buffer is empty?
tl::expected<void, PacketError> result
= pktfty->make_packet(pkt_buf)
.and_then([&](std::unique_ptr<packet> &&pkt) {
return recv_decrypted(*pkt, sender);
});
if (!result.has_value()) {
// drop packet
proto.disconnect(sender);
Log("{}", result.error().what());
}
while (proto.get_disconnected(sender)) {
for (plr_t i = 0; i < Players.size(); ++i) {
if (peers[i].endpoint == sender) {
DisconnectNet(i);
break;
}
}
while (proto.get_disconnected(sender)) {
for (plr_t i = 0; i < Players.size(); ++i) {
if (peers[i].endpoint == sender) {
DisconnectNet(i);
break;
}
}
} catch (std::exception &e) {
Log("{}", e.what());
return;
}
}

Loading…
Cancel
Save