mas-bandwidth / netcode

Secure client/server connections over UDP
BSD 3-Clause "New" or "Revised" License
2.43k stars 191 forks source link

Embed the `client index` to `connection payload packet` and `connection disconnect packet` #119

Closed kienhg96 closed 10 months ago

kienhg96 commented 10 months ago

Hi,

I think that it would be better if the client index is embedded in both connection payload packet and connection disconnect packet.

Currently, after receiving a packet, server will iterate overall the array of clients to find the associated client index by function netcode_server_find_client_index_by_address.

I suggest this way:

It could be like this:

connection payload packet:

[client index] (uint32)
[payload data] (1 to 1200 bytes)

connection disconnect packet:

[client index] (uint32)

Thanks for considering

gafferongames commented 10 months ago

I like this idea, would you be willing to make a PR that implements this, including an extension to the standard from 1.02 -> 1.03?

kienhg96 commented 10 months ago

OK, I'll try my best

gafferongames commented 10 months ago

I've thought about this more, the bandwidth cost and complexity of the change to add the client index to packets, is too high a price to pay, for something which could be implemented via a hash table look up on client id instead.

This also has the benefit that implementing it this way will also not require any changes in the protocol version.

So if you would like to add this feature, please implement a hash table lookup from client id -> client index, instead of including the client index in packets.

Thanks!

kienhg96 commented 10 months ago

Agree, and I relized that, the client index could not be placed inside the encrypted portion of packet. We need the private key to decrypt the packet. But we cannot get the private key until we get the client index.

gafferongames commented 10 months ago

Yes this is another good point.