From d9ab5df568c469fea45213cc7a2063c2a61a1ef5 Mon Sep 17 00:00:00 2001 From: LowFire Date: Sat, 23 Dec 2023 16:14:06 -0700 Subject: [PATCH 1/2] fix bug. Add P2PInterface class --- .../addons/epic-online-services-godot/eos.gd | 25 +++++++++++++++++++ src/eosg_multiplayer_peer.cpp | 20 +++++++-------- src/eosg_packet_peer_mediator.cpp | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/sample/addons/epic-online-services-godot/eos.gd b/sample/addons/epic-online-services-godot/eos.gd index 2b171c9..18ec315 100644 --- a/sample/addons/epic-online-services-godot/eos.gd +++ b/sample/addons/epic-online-services-godot/eos.gd @@ -1880,6 +1880,31 @@ class P2P: var incoming_packet_queue_max_size_bytes: int var outgoing_packet_queue_max_size_bytes: int + class P2PInterface: + static func get_packet_queue_info() -> Dictionary: + return IEOS.p2p_get_packet_queue_info() + + static func get_port_range() -> Dictionary: + return IEOS.p2p_get_port_range() + + static func get_nat_type() -> NATType: + return IEOS.p2p_get_nat_type() as NATType + + static func get_relay_control() -> RelayControl: + return IEOS.p2p_get_relay_control() as RelayControl + + static func query_nat_type() -> void: + IEOS.p2p_query_nat_type() + + static func set_packet_queue_size(options: SetPacketQueueSizeOptions) -> void: + IEOS.p2p_set_packet_queue_size(options) + + static func set_port_range(options: SetPortRangeOptions) -> void: + IEOS.p2p_set_port_range(options) + + static func set_relay_control(relay_control: RelayControl) -> void: + IEOS.p2p_set_relay_control(relay_control) + diff --git a/src/eosg_multiplayer_peer.cpp b/src/eosg_multiplayer_peer.cpp index 4350669..f421dde 100644 --- a/src/eosg_multiplayer_peer.cpp +++ b/src/eosg_multiplayer_peer.cpp @@ -76,10 +76,7 @@ Error EOSGMultiplayerPeer::create_server(const String &socket_id) { //Create a socket where we will be listening for connections socket = EOSGSocket(socket_id); if (socket.get_name().is_empty()) { - unique_id = 0; - active_mode = MODE_NONE; - connection_status = CONNECTION_DISCONNECTED; - polling = false; + _close(); ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Failed to create server."); } @@ -112,7 +109,7 @@ Error EOSGMultiplayerPeer::create_client(const String &socket_id, const String & //Create the socket we are trying to connect to socket = EOSGSocket(socket_id); if (socket.get_name().is_empty()) { - polling = false; + _close(); ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Failed to create client."); } @@ -164,10 +161,7 @@ Error EOSGMultiplayerPeer::create_mesh(const String &socket_id) { //Create a socket where we will be listening for connections socket = EOSGSocket(socket_id); if (socket.get_name().is_empty()) { - unique_id = 0; - active_mode = MODE_NONE; - connection_status = CONNECTION_DISCONNECTED; - polling = false; + _close(); ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Failed to create mesh."); } @@ -762,10 +756,13 @@ void EOSGMultiplayerPeer::_close() { socket.close(); active_mode = MODE_NONE; connection_status = CONNECTION_DISCONNECTED; - peers.clear(); pending_connection_requests.clear(); unique_id = 0; set_refuse_new_connections(false); + + if (peers.is_empty()) { //Go ahead and unregister if there were no peers connected + EOSGPacketPeerMediator::get_singleton()->unregister_peer(this); + } } /**************************************** @@ -1083,7 +1080,8 @@ void EOSGMultiplayerPeer::remote_connection_closed_callback(const EOS_P2P_OnRemo _close(); } - if (data->Reason == EOS_EConnectionClosedReason::EOS_CCR_ClosedByLocalUser) { + //The peer has closed their connection. Once all peers have been removed, unregister from the mediator + if (connection_status == CONNECTION_DISCONNECTED && peers.is_empty()) { EOSGPacketPeerMediator::get_singleton()->unregister_peer(this); } diff --git a/src/eosg_packet_peer_mediator.cpp b/src/eosg_packet_peer_mediator.cpp index b73b3bb..921d05a 100644 --- a/src/eosg_packet_peer_mediator.cpp +++ b/src/eosg_packet_peer_mediator.cpp @@ -168,7 +168,7 @@ bool EOSGPacketPeerMediator::register_peer(EOSGMultiplayerPeer *peer) { * unregistration usually happens when a peer closes. ****************************************/ void EOSGPacketPeerMediator::unregister_peer(EOSGMultiplayerPeer *peer) { - ERR_FAIL_COND_MSG(!active_peers.has(peer->get_socket()), "Failed to unregister peer. This peer has not been previously registered."); + if (!active_peers.has(peer->get_socket())) return; clear_packet_queue(peer->get_socket()); socket_packet_queues.erase(peer->get_socket()); From ebbb58dd2f4d63b6fe7e7b761be8d828d16988df Mon Sep 17 00:00:00 2001 From: LowFire Date: Sat, 23 Dec 2023 17:53:42 -0700 Subject: [PATCH 2/2] rename p2p interface methods --- sample/addons/epic-online-services-godot/eos.gd | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sample/addons/epic-online-services-godot/eos.gd b/sample/addons/epic-online-services-godot/eos.gd index 7e14d0c..2fb1838 100644 --- a/sample/addons/epic-online-services-godot/eos.gd +++ b/sample/addons/epic-online-services-godot/eos.gd @@ -1875,28 +1875,28 @@ class P2P: class P2PInterface: static func get_packet_queue_info() -> Dictionary: - return IEOS.p2p_get_packet_queue_info() + return IEOS.p2p_interface_get_packet_queue_info() static func get_port_range() -> Dictionary: - return IEOS.p2p_get_port_range() + return IEOS.p2p_interface_get_port_range() static func get_nat_type() -> NATType: - return IEOS.p2p_get_nat_type() as NATType + return IEOS.p2p_interface_get_nat_type() as NATType static func get_relay_control() -> RelayControl: - return IEOS.p2p_get_relay_control() as RelayControl + return IEOS.p2p_interface_get_relay_control() as RelayControl static func query_nat_type() -> void: - IEOS.p2p_query_nat_type() + IEOS.p2p_interface_query_nat_type() static func set_packet_queue_size(options: SetPacketQueueSizeOptions) -> void: - IEOS.p2p_set_packet_queue_size(options) + IEOS.p2p_interface_set_packet_queue_size(options) static func set_port_range(options: SetPortRangeOptions) -> void: - IEOS.p2p_set_port_range(options) + IEOS.p2p_interface_set_port_range(options) static func set_relay_control(relay_control: RelayControl) -> void: - IEOS.p2p_set_relay_control(relay_control) + IEOS.p2p_interface_set_relay_control(relay_control)