Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
3ddelano committed Dec 26, 2023
2 parents 8272248 + 8e2ad2f commit c4d5695
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
25 changes: 25 additions & 0 deletions sample/addons/epic-online-services-godot/eos.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)




Expand Down
20 changes: 9 additions & 11 deletions src/eosg_multiplayer_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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);
}
}

/****************************************
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/eosg_packet_peer_mediator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit c4d5695

Please sign in to comment.