Merge pull request #95216 from Chaosed0/enet-get-packet-flags

Add method for getting packet flags from ENetPacketPeer
This commit is contained in:
Rémi Verschelde 2024-10-02 15:00:50 +02:00
commit cd7822051c
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 13 additions and 0 deletions

View file

@ -18,6 +18,12 @@
Returns the number of channels allocated for communication with peer.
</description>
</method>
<method name="get_packet_flags" qualifiers="const">
<return type="int" />
<description>
Returns the ENet flags of the next packet in the received queue. See [code]FLAG_*[/code] constants for available packet flags. Note that not all flags are replicated from the sending peer to the receiving peer.
</description>
</method>
<method name="get_remote_address" qualifiers="const">
<return type="String" />
<description>

View file

@ -175,6 +175,11 @@ int ENetPacketPeer::get_channels() const {
return peer->channelCount;
}
int ENetPacketPeer::get_packet_flags() const {
ERR_FAIL_COND_V(packet_queue.is_empty(), 0);
return packet_queue.front()->get()->flags;
}
void ENetPacketPeer::_on_disconnect() {
if (peer) {
peer->data = nullptr;
@ -206,6 +211,7 @@ void ENetPacketPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("send", "channel", "packet", "flags"), &ENetPacketPeer::_send);
ClassDB::bind_method(D_METHOD("throttle_configure", "interval", "acceleration", "deceleration"), &ENetPacketPeer::throttle_configure);
ClassDB::bind_method(D_METHOD("set_timeout", "timeout", "timeout_min", "timeout_max"), &ENetPacketPeer::set_timeout);
ClassDB::bind_method(D_METHOD("get_packet_flags"), &ENetPacketPeer::get_packet_flags);
ClassDB::bind_method(D_METHOD("get_remote_address"), &ENetPacketPeer::get_remote_address);
ClassDB::bind_method(D_METHOD("get_remote_port"), &ENetPacketPeer::get_remote_port);
ClassDB::bind_method(D_METHOD("get_statistic", "statistic"), &ENetPacketPeer::get_statistic);

View file

@ -113,6 +113,7 @@ public:
double get_statistic(PeerStatistic p_stat);
PeerState get_state() const;
int get_channels() const;
int get_packet_flags() const;
// Extras
IPAddress get_remote_address() const;