I'm developing a multiplayer game where the server needs to relay incoming command messages to all other clients in the session. I'm separating commands (reliable messages for input, abilities, etc.) from updates (unreliable messages for game state).
My goal is to avoid deserializing the message on the server and then re-serializing it into a new message, as this adds significant boilerplate.
What I have tried
I attempted to use AddBytes and AddMessage to copy the original message's payload into a new one. The resulting message had the expected size, but the bits within the copy were corrupted and did not correspond to the original data.
var copy = Message.AddMessage(message, 8 * known_constant_for_this_message_type, 0) // returns corrupted data
// or AddMessage(message) when dealing with incoming message
.AddInt(senderId) // or other appendage
Workaround: Manual parsing and reconstruction
My current workaround is to manually deserialize the message on the server and then create new Message object, reserializing the data on the next line. This works correctly:
// receiving the data
var player = src.Players[sender];
player.Position = message.GetVector2();
player.Vector = message.GetVector2();
var timestamp = message.GetDouble(); // todo [inter,extra]polation, maybe some simulation and all of that
// reserialization
copy = Message.Create()
.AddVector2(player.Position)
.AddVector2(player.Vector)
.AddDouble(timestamp)
.AddInt(sender);
While this works, doing it for every command will be tedious, especially for commands that don't affect the game state.
I'm developing a multiplayer game where the server needs to relay incoming command messages to all other clients in the session. I'm separating commands (reliable messages for input, abilities, etc.) from updates (unreliable messages for game state).
My goal is to avoid deserializing the message on the server and then re-serializing it into a new message, as this adds significant boilerplate.
What I have tried
I attempted to use AddBytes and AddMessage to copy the original message's payload into a new one. The resulting message had the expected size, but the bits within the copy were corrupted and did not correspond to the original data.
Workaround: Manual parsing and reconstruction
My current workaround is to manually deserialize the message on the server and then create new
Messageobject, reserializing the data on the next line. This works correctly:While this works, doing it for every command will be tedious, especially for commands that don't affect the game state.