diff --git a/sample/addons/epic-online-services-godot/eos.gd b/sample/addons/epic-online-services-godot/eos.gd index 1411d99..2fb1838 100644 --- a/sample/addons/epic-online-services-godot/eos.gd +++ b/sample/addons/epic-online-services-godot/eos.gd @@ -1873,6 +1873,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_interface_get_packet_queue_info() + + static func get_port_range() -> Dictionary: + return IEOS.p2p_interface_get_port_range() + + static func get_nat_type() -> NATType: + return IEOS.p2p_interface_get_nat_type() as NATType + + static func get_relay_control() -> RelayControl: + return IEOS.p2p_interface_get_relay_control() as RelayControl + + static func query_nat_type() -> void: + IEOS.p2p_interface_query_nat_type() + + static func set_packet_queue_size(options: SetPacketQueueSizeOptions) -> void: + IEOS.p2p_interface_set_packet_queue_size(options) + + static func set_port_range(options: SetPortRangeOptions) -> void: + IEOS.p2p_interface_set_port_range(options) + + static func set_relay_control(relay_control: RelayControl) -> void: + IEOS.p2p_interface_set_relay_control(relay_control) + diff --git a/src/eosg_multiplayer_peer.cpp b/src/eosg_multiplayer_peer.cpp index d5627d8..af97b22 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());