From 18eddfc98d2d8a5f6c850bebdb08a983f3936a9a Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Mon, 13 Jul 2020 19:14:27 +0200 Subject: [PATCH] Funnel refuse_new_connections to Godot ENet. (cherry picked from commit 7ec5c917d143783c04a2816d3da7ebc48d47816b) --- modules/enet/networked_multiplayer_enet.cpp | 3 +++ thirdparty/enet/enet/enet.h | 1 + thirdparty/enet/godot.cpp | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 406eb467f03..59b4c0b99fb 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -668,6 +668,9 @@ int NetworkedMultiplayerENet::get_unique_id() const { void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { refuse_connections = p_enable; +#ifdef GODOT_ENET + enet_host_refuse_new_connections(host, p_enable); +#endif } bool NetworkedMultiplayerENet::is_refusing_new_connections() const { diff --git a/thirdparty/enet/enet/enet.h b/thirdparty/enet/enet/enet.h index 3900353c345..d3b3b54b9d1 100644 --- a/thirdparty/enet/enet/enet.h +++ b/thirdparty/enet/enet/enet.h @@ -587,6 +587,7 @@ extern void enet_host_bandwidth_throttle (ENetHost *); extern enet_uint32 enet_host_random_seed (void); ENET_API void enet_host_dtls_server_setup (ENetHost *, void *, void *); ENET_API void enet_host_dtls_client_setup (ENetHost *, void *, uint8_t, const char *); +ENET_API void enet_host_refuse_new_connections (ENetHost *, int); ENET_API int enet_peer_send (ENetPeer *, enet_uint8, ENetPacket *); ENET_API ENetPacket * enet_peer_receive (ENetPeer *, enet_uint8 * channelID); diff --git a/thirdparty/enet/godot.cpp b/thirdparty/enet/godot.cpp index da3a86277b3..3975c1d86e9 100644 --- a/thirdparty/enet/godot.cpp +++ b/thirdparty/enet/godot.cpp @@ -51,6 +51,7 @@ public: virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port) = 0; virtual int set_option(ENetSocketOption p_option, int p_value) = 0; virtual void close() = 0; + virtual void set_refuse_new_connections(bool p_refuse) { /* Only used by dtls server */ } virtual ~ENetGodotSocket(){}; }; @@ -250,6 +251,10 @@ public: close(); } + void set_refuse_new_connections(bool p_refuse) { + udp_server->set_max_pending_connections(p_refuse ? 0 : 16); + } + Error bind(IP_Address p_ip, uint16_t p_port) { return udp_server->listen(p_port, p_ip); } @@ -269,6 +274,7 @@ public: } Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port) { + udp_server->poll(); // TODO limits? Maybe we can better enforce allowed connections! if (udp_server->is_connection_available()) { Ref udp = udp_server->take_connection(); @@ -409,6 +415,11 @@ void enet_host_dtls_client_setup(ENetHost *host, void *p_cert, uint8_t p_verify, memdelete(sock); } +void enet_host_refuse_new_connections(ENetHost *host, int p_refuse) { + ERR_FAIL_COND(!host->socket); + ((ENetGodotSocket *)host->socket)->set_refuse_new_connections(p_refuse); +} + int enet_socket_bind(ENetSocket socket, const ENetAddress *address) { IP_Address ip;