Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions modules/enet/doc_classes/ENetConnection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
Sends any queued packets on the host specified to its designated peers.
</description>
</method>
<method name="get_local_address" qualifiers="const">
<return type="String" />
<description>
Returns the local address to which this peer is bound.
</description>
</method>
<method name="get_local_port" qualifiers="const">
<return type="int" />
<description>
Expand Down
21 changes: 20 additions & 1 deletion modules/enet/enet_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,29 @@ int ENetConnection::get_max_channels() const {
return host->channelLimit;
}

IPAddress ENetConnection::get_local_address() const {
ERR_FAIL_NULL_V_MSG(host, IPAddress(), "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V_MSG(!(host->socket), IPAddress(), "The ENetConnection instance isn't currently bound.");
ENetAddress address;
ERR_FAIL_COND_V_MSG(enet_socket_get_address(host->socket, &address), IPAddress(), "Unable to get socket address.");

IPAddress out;
#ifdef GODOT_ENET
out.set_ipv6((uint8_t *)&(address.host));
if (out == IPAddress("::")) {
return IPAddress("*");
}
#else
out.set_ipv4((uint8_t *)&(address.host));
#endif
return out;
}

int ENetConnection::get_local_port() const {
ERR_FAIL_NULL_V_MSG(host, 0, "The ENetConnection instance isn't currently active.");
ERR_FAIL_COND_V_MSG(!(host->socket), 0, "The ENetConnection instance isn't currently bound.");
ENetAddress address;
ERR_FAIL_COND_V_MSG(enet_socket_get_address(host->socket, &address), 0, "Unable to get socket address");
ERR_FAIL_COND_V_MSG(enet_socket_get_address(host->socket, &address), 0, "Unable to get socket address.");
return address.port;
}

Expand Down Expand Up @@ -387,6 +405,7 @@ void ENetConnection::_bind_methods() {
ClassDB::bind_method(D_METHOD("refuse_new_connections", "refuse"), &ENetConnection::refuse_new_connections);
ClassDB::bind_method(D_METHOD("pop_statistic", "statistic"), &ENetConnection::pop_statistic);
ClassDB::bind_method(D_METHOD("get_max_channels"), &ENetConnection::get_max_channels);
ClassDB::bind_method(D_METHOD("get_local_address"), &ENetConnection::get_local_address);
ClassDB::bind_method(D_METHOD("get_local_port"), &ENetConnection::get_local_port);
ClassDB::bind_method(D_METHOD("get_peers"), &ENetConnection::_get_peers);
ClassDB::bind_method(D_METHOD("socket_send", "destination_address", "destination_port", "packet"), &ENetConnection::socket_send);
Expand Down
1 change: 1 addition & 0 deletions modules/enet/enet_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class ENetConnection : public RefCounted {

// Extras
void get_peers(List<Ref<ENetPacketPeer>> &r_peers);
IPAddress get_local_address() const;
int get_local_port() const;

// Godot additions
Expand Down