1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 03:23:15 +01:00

Refactor packet handling

This commit is contained in:
duncanspumpkin
2017-04-15 07:43:42 +01:00
committed by Michał Janiszewski
parent f8241b7bb0
commit feef3d98da
2 changed files with 13 additions and 10 deletions

View File

@@ -1363,7 +1363,6 @@ void Network::ProcessGameCommandQueue()
IGameAction * action = GameActions::Create(gc.actionType);
uint32 flags = gc.parameters->ReadValue<uint32>();
action->Deserialise(gc.parameters);
delete gc.parameters;
GameActionResult result = GameActions::Execute(action, flags | GAME_COMMAND_FLAG_NETWORKED);
if (result.Error != GA_ERROR::OK)
{
@@ -2066,9 +2065,8 @@ void Network::Client_Handle_GAME_ACTION(NetworkConnection& connection, NetworkPa
uint8 playerid;
packet >> tick >> type >> playerid;
MemoryStream stream;
for (size_t i = packet.BytesRead; i < packet.Size; ++i) {
stream.WriteValue(((uint8*)packet.GetData())[i]);
}
uint16 size = packet.Size - packet.BytesRead;
stream.WriteArray(packet.Read(size), size);
stream.SetPosition(0);
GameCommand gc = GameCommand(tick, type, stream, playerid);
game_command_queue.insert(gc);
@@ -2084,11 +2082,6 @@ void Network::Server_Handle_GAME_ACTION(NetworkConnection& connection, NetworkPa
}
packet >> tick >> commandType;
MemoryStream stream;
for (size_t i = packet.BytesRead; i < packet.Size; ++i) {
stream.WriteValue(((uint8*)packet.GetData())[i]);
}
stream.SetPosition(0);
//tick count is different by time last_action_time is set, keep same value
// Check if player's group permission allows command to run
@@ -2137,6 +2130,10 @@ void Network::Server_Handle_GAME_ACTION(NetworkConnection& connection, NetworkPa
game_command_playerid = connection.Player->Id;
// Run game command, and if it is successful send to clients
auto ga = GameActions::Create(commandType);
MemoryStream stream;
uint16 size = packet.Size - packet.BytesRead;
stream.WriteArray(packet.Read(size), size);
stream.SetPosition(0);
uint32 flags = stream.ReadValue<uint32>();
ga->Deserialise(&stream);
auto result = GameActions::Execute(ga, GAME_COMMAND_FLAG_NETWORKED | flags);

View File

@@ -204,10 +204,16 @@ private:
parameters = new MemoryStream(stream);
}
~GameCommand()
{
if (parameters != nullptr)
delete parameters;
}
uint32 tick;
uint32 eax, ebx, ecx, edx, esi, edi, ebp;
uint32 actionType = 0xFFFFFFFF;
MemoryStream *parameters;
MemoryStream *parameters = nullptr;
uint8 playerid;
uint8 callback;
bool operator<(const GameCommand& comp) const {