MitchellMarinoDev / carrier-pigeon

A rusty networking library for games.
Other
12 stars 2 forks source link

Add Timestamp to UDP messages. #3

Closed MitchellMarinoDev closed 2 years ago

MitchellMarinoDev commented 2 years ago

This adds a timestamp to UDP messages, this way there is some way to order them. also adds a NetMsg<M> struct that wraps networking messages with their meta data (plain tuples were used before). The timestamping is done by sending the least significant 16 bits of the Unix millis. On the server, it uses the fact that messages aren't going to arrive more than 65 seconds later to reconstruct the rest of the unix millis. This uses the system clock, so if the system clock is not correct you may encounter issues. The timestamps are just added as meta in the NetMsg struct, and are not used directly by carrier-pigeon. If you cant verify the correctness of the system clock, or just dont want this feature, you can just no use the time field of the NetMsg.