Skip to content

Commit

Permalink
Add method for getting packet flags from ENetPacketPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosed0 authored and akien-mga committed Oct 2, 2024
1 parent f4af820 commit 21c5a73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/enet/doc_classes/ENetPacketPeer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions modules/enet/enet_packet_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions modules/enet/enet_packet_peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ENetPacketPeer : public PacketPeer {
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;
Expand Down

0 comments on commit 21c5a73

Please sign in to comment.