godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

Expose ENetPacket.flags through ENetPacketPeer #10240

Open Chaosed0 opened 2 months ago

Chaosed0 commented 2 months ago

Describe the project you are working on

A client/server networked game.

Describe the problem or limitation you are having in your project

When a packet is sent from a client to a host, I would like to broadcast that packet from the host to all other clients. The game uses a mix of reliable and unreliable packets, so I would like to replicate the send mode of the original packet when broadcasting. However, Godot's implementation of ENetConnection and ENetPacketPeer does not allow accessing the send flags of the received packet.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

It looks like you are able to obtain the packet flags in bare ENet. However, in Godot's wrapper, it appears that everything about the packet is thrown away except for the data. The proposal is to expose the packet flags somewhere in the API.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

ENetPacketPeer should expose a new method, get_packet_flags, which returns the packet flags for the packet at the front of the queue.

There is already precedent for this - MultiplayerPeer has get_packet_mode.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Currently, ENetPacketPeer does not expose this data at all. I would have to duplicate the send flags in my own packet header, which is wasteful.

Is there a reason why this should be core and not an add-on in the asset library?

It is a built-in Godot class.

Theome commented 1 month ago

I would like to add to this proposal that the channel used to send the data should also be exposed. When using ENetPacketPeer's send method, the first parameter channel can not be read when receiving the message, rendering the channel parameter completely useless.

Chaosed0 commented 1 month ago

The channel is already exposed through the array returned from Service, as the fourth element in the array. Not an ideal place for it to be found, but it is documented in ENetConnection.

Theome commented 1 month ago

Thanks, you're right. I was looking at the wrong places and only found ENetPacketPeer's get_packet method, which appeared to be the counterpart to send, but only returns the raw packet bytes.