diff options
Diffstat (limited to 'modules/enet')
-rw-r--r-- | modules/enet/doc_classes/ENetMultiplayerPeer.xml | 2 | ||||
-rw-r--r-- | modules/enet/doc_classes/ENetPacketPeer.xml | 1 | ||||
-rw-r--r-- | modules/enet/enet_multiplayer_peer.cpp | 41 | ||||
-rw-r--r-- | modules/enet/enet_multiplayer_peer.h | 40 |
4 files changed, 26 insertions, 58 deletions
diff --git a/modules/enet/doc_classes/ENetMultiplayerPeer.xml b/modules/enet/doc_classes/ENetMultiplayerPeer.xml index 456b390dbb..f9659c092a 100644 --- a/modules/enet/doc_classes/ENetMultiplayerPeer.xml +++ b/modules/enet/doc_classes/ENetMultiplayerPeer.xml @@ -77,10 +77,8 @@ <member name="host" type="ENetConnection" setter="" getter="get_host"> The underlying [ENetConnection] created after [method create_client] and [method create_server]. </member> - <member name="refuse_new_connections" type="bool" setter="set_refuse_new_connections" getter="is_refusing_new_connections" override="true" default="false" /> <member name="server_relay" type="bool" setter="set_server_relay_enabled" getter="is_server_relay_enabled" default="true"> Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is [code]false[/code], clients won't be automatically notified of other peers and won't be able to send them packets through the server. </member> - <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="TransferMode" default="2" /> </members> </class> diff --git a/modules/enet/doc_classes/ENetPacketPeer.xml b/modules/enet/doc_classes/ENetPacketPeer.xml index 8f0693fb01..4116ba17f2 100644 --- a/modules/enet/doc_classes/ENetPacketPeer.xml +++ b/modules/enet/doc_classes/ENetPacketPeer.xml @@ -6,6 +6,7 @@ <description> A PacketPeer implementation representing a peer of an [ENetConnection]. This class cannot be instantiated directly but can be retrieved during [method ENetConnection.service] or via [method ENetConnection.get_peers]. + [b]Note:[/b] When exporting to Android, make sure to enable the [code]INTERNET[/code] permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android. </description> <tutorials> <link title="API documentation on the ENet website">http://enet.bespin.org/usergroup0.html</link> diff --git a/modules/enet/enet_multiplayer_peer.cpp b/modules/enet/enet_multiplayer_peer.cpp index afd31207f6..2cfae60ad2 100644 --- a/modules/enet/enet_multiplayer_peer.cpp +++ b/modules/enet/enet_multiplayer_peer.cpp @@ -33,22 +33,6 @@ #include "core/io/marshalls.h" #include "core/os/os.h" -void ENetMultiplayerPeer::set_transfer_channel(int p_channel) { - transfer_channel = p_channel; -} - -int ENetMultiplayerPeer::get_transfer_channel() const { - return transfer_channel; -} - -void ENetMultiplayerPeer::set_transfer_mode(Multiplayer::TransferMode p_mode) { - transfer_mode = p_mode; -} - -Multiplayer::TransferMode ENetMultiplayerPeer::get_transfer_mode() const { - return transfer_mode; -} - void ENetMultiplayerPeer::set_target_peer(int p_peer) { target_peer = p_peer; } @@ -62,6 +46,7 @@ int ENetMultiplayerPeer::get_packet_peer() const { Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_max_channels, int p_in_bandwidth, int p_out_bandwidth) { ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); + set_refuse_new_connections(false); Ref<ENetConnection> host; host.instantiate(); Error err = host->create_host_bound(bind_ip, p_port, p_max_clients, 0, p_max_channels > 0 ? p_max_channels + SYSCH_MAX : 0, p_out_bandwidth); @@ -70,7 +55,6 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma } active_mode = MODE_SERVER; - refuse_connections = false; unique_id = 1; connection_status = CONNECTION_CONNECTED; hosts[0] = host; @@ -79,6 +63,7 @@ Error ENetMultiplayerPeer::create_server(int p_port, int p_max_clients, int p_ma Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, int p_channel_count, int p_in_bandwidth, int p_out_bandwidth, int p_local_port) { ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); + set_refuse_new_connections(false); Ref<ENetConnection> host; host.instantiate(); Error err; @@ -102,7 +87,6 @@ Error ENetMultiplayerPeer::create_client(const String &p_address, int p_port, in // Need to wait for CONNECT event. connection_status = CONNECTION_CONNECTING; active_mode = MODE_CLIENT; - refuse_connections = false; peers[1] = peer; hosts[0] = host; @@ -113,7 +97,6 @@ Error ENetMultiplayerPeer::create_mesh(int p_id) { ERR_FAIL_COND_V_MSG(p_id <= 0, ERR_INVALID_PARAMETER, "The unique ID must be greater then 0"); ERR_FAIL_COND_V_MSG(_is_active(), ERR_ALREADY_IN_USE, "The multiplayer instance is already active."); active_mode = MODE_MESH; - refuse_connections = false; unique_id = p_id; connection_status = CONNECTION_CONNECTED; return OK; @@ -145,7 +128,7 @@ bool ENetMultiplayerPeer::_poll_server() { } switch (ret) { case ENetConnection::EVENT_CONNECT: { - if (refuse_connections) { + if (is_refusing_new_connections()) { event.peer->reset(); return false; } @@ -173,7 +156,7 @@ bool ENetMultiplayerPeer::_poll_server() { emit_signal(SNAME("peer_disconnected"), id); peers.erase(id); - if (!server_relay) { + if (server_relay) { _notify_peers(id, false); } return false; @@ -423,6 +406,7 @@ void ENetMultiplayerPeer::close_connection(uint32_t wait_usec) { hosts.clear(); unique_id = 0; connection_status = CONNECTION_DISCONNECTED; + set_refuse_new_connections(false); } int ENetMultiplayerPeer::get_available_packet_count() const { @@ -451,15 +435,16 @@ Error ENetMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size int packet_flags = 0; int channel = SYSCH_RELIABLE; + int transfer_channel = get_transfer_channel(); if (transfer_channel > 0) { channel = SYSCH_MAX + transfer_channel - 1; } else { - switch (transfer_mode) { + switch (get_transfer_mode()) { case Multiplayer::TRANSFER_MODE_UNRELIABLE: { packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; channel = SYSCH_UNRELIABLE; } break; - case Multiplayer::TRANSFER_MODE_ORDERED: { + case Multiplayer::TRANSFER_MODE_UNRELIABLE_ORDERED: { packet_flags = 0; channel = SYSCH_UNRELIABLE; } break; @@ -545,19 +530,15 @@ int ENetMultiplayerPeer::get_unique_id() const { return unique_id; } -void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - refuse_connections = p_enable; +void ENetMultiplayerPeer::set_refuse_new_connections(bool p_enabled) { #ifdef GODOT_ENET if (_is_active()) { for (KeyValue<int, Ref<ENetConnection>> &E : hosts) { - E.value->refuse_new_connections(p_enable); + E.value->refuse_new_connections(p_enabled); } } #endif -} - -bool ENetMultiplayerPeer::is_refusing_new_connections() const { - return refuse_connections; + MultiplayerPeer::set_refuse_new_connections(p_enabled); } void ENetMultiplayerPeer::set_server_relay_enabled(bool p_enabled) { diff --git a/modules/enet/enet_multiplayer_peer.h b/modules/enet/enet_multiplayer_peer.h index b5316b8292..7a60e2359c 100644 --- a/modules/enet/enet_multiplayer_peer.h +++ b/modules/enet/enet_multiplayer_peer.h @@ -65,10 +65,7 @@ private: uint32_t unique_id = 0; int target_peer = 0; - int transfer_channel = 0; - Multiplayer::TransferMode transfer_mode = Multiplayer::TRANSFER_MODE_RELIABLE; - bool refuse_connections = false; bool server_relay = true; ConnectionStatus connection_status = CONNECTION_DISCONNECTED; @@ -101,40 +98,31 @@ protected: static void _bind_methods(); public: - virtual void set_transfer_channel(int p_channel) override; - virtual int get_transfer_channel() const override; - - virtual void set_transfer_mode(Multiplayer::TransferMode p_mode) override; - virtual Multiplayer::TransferMode get_transfer_mode() const override; virtual void set_target_peer(int p_peer) override; - virtual int get_packet_peer() const override; - Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0); - Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0); - Error create_mesh(int p_id); - Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host); - - void close_connection(uint32_t wait_usec = 100); - - void disconnect_peer(int p_peer, bool now = false); - virtual void poll() override; - virtual bool is_server() const override; + // Overriden so we can instrument the DTLSServer when needed. + virtual void set_refuse_new_connections(bool p_enabled) override; - virtual int get_available_packet_count() const override; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + virtual ConnectionStatus get_connection_status() const override; + + virtual int get_unique_id() const override; virtual int get_max_packet_size() const override; + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual ConnectionStatus get_connection_status() const override; + Error create_server(int p_port, int p_max_clients = 32, int p_max_channels = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0); + Error create_client(const String &p_address, int p_port, int p_channel_count = 0, int p_in_bandwidth = 0, int p_out_bandwidth = 0, int p_local_port = 0); + Error create_mesh(int p_id); + Error add_mesh_peer(int p_id, Ref<ENetConnection> p_host); - virtual void set_refuse_new_connections(bool p_enable) override; - virtual bool is_refusing_new_connections() const override; + void close_connection(uint32_t wait_usec = 100); - virtual int get_unique_id() const override; + void disconnect_peer(int p_peer, bool now = false); void set_bind_ip(const IPAddress &p_ip); void set_server_relay_enabled(bool p_enabled); |