feat(net): add loop to grunt command processing

This commit is contained in:
fallenoak 2023-01-10 08:03:16 -06:00
parent 27e0190fb9
commit e16e5605ba
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 31 additions and 14 deletions

@ -1 +1 @@
Subproject commit 5dce613aeb790c30d02c222444d0379e4619c184
Subproject commit 9a5e71de2207be9368428a3bff147b9bcd51d94a

View File

@ -18,23 +18,40 @@ class Grunt::Command {
template <class T>
int32_t Grunt::Command<T>::Process(CDataStore& msg, Command<T>* 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<T>* 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