From e16e5605ba7ae5fcf4839972bb681e6f008e5f8f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 10 Jan 2023 08:03:16 -0600 Subject: [PATCH] feat(net): add loop to grunt command processing --- lib/common | 2 +- src/net/grunt/Command.hpp | 43 +++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/common b/lib/common index 5dce613..9a5e71d 160000 --- a/lib/common +++ b/lib/common @@ -1 +1 @@ -Subproject commit 5dce613aeb790c30d02c222444d0379e4619c184 +Subproject commit 9a5e71de2207be9368428a3bff147b9bcd51d94a diff --git a/src/net/grunt/Command.hpp b/src/net/grunt/Command.hpp index e07ad0d..2fe2e86 100644 --- a/src/net/grunt/Command.hpp +++ b/src/net/grunt/Command.hpp @@ -18,23 +18,40 @@ class Grunt::Command { template int32_t Grunt::Command::Process(CDataStore& msg, Command* commands, uint32_t commandCount, T& a4, uint32_t& pos) { - uint8_t cmd; - msg.Get(cmd); + while (true) { + if (!msg.Sub8CBBF0(1)) { + return 1; + } - for (uint32_t i = 0; i < commandCount; i++) { - auto& command = commands[i]; + uint8_t cmd; + msg.Get(cmd); - if (command.cmd == cmd) { - auto callback = command.callback; - auto result = (a4.*callback)(msg); - - if (result == 0) { - return 1; - } else { - // TODO - return 0; + Command* command = nullptr; + for (uint32_t i = 0; i < commandCount; i++) { + if (commands[i].cmd == cmd) { + command = &commands[i]; } } + + if (!command) { + // Bad command received [0x%02X] (unrecognized command) + break; + } + + auto result = (a4.*command->callback)(msg); + + if (result == 0) { + return 1; + } + + if (result == 1) { + // Bad command received [0x%02X] (Corrupt) + break; + } + + if (result == 2) { + pos = msg.m_read; + } } // TODO