diff --git a/src/ProxyServer.cc b/src/ProxyServer.cc index 9dc32950..ded088ff 100644 --- a/src/ProxyServer.cc +++ b/src/ProxyServer.cc @@ -23,6 +23,7 @@ #include "PSOProtocol.hh" #include "ReceiveCommands.hh" +#include "ReceiveSubcommands.hh" using namespace std; @@ -324,7 +325,30 @@ void ProxyServer::receive_and_process_commands(bool from_server) { log(INFO, "[ProxyServer] %s:", from_server ? "server" : "client"); print_data(stderr, command); - // preprocess the command if needed + // Preprocess the command if needed + + // Preprocessing for bidirectional commands... + switch (this->get_command_field(input_header)) { + case 0x60: + case 0x62: + case 0x6C: + case 0x6D: + case 0xC9: + case 0xCB: { // broadcast/target commands + if (command.size() <= this->header_size) { + log(WARNING, "[ProxyServer] Received broadcast/target command with no contents"); + } else { + uint8_t which = *reinterpret_cast(command.data() + this->header_size); + if (!subcommand_is_implemented(which)) { + log(WARNING, "[ProxyServer] Received broadcast/target subcommand %02hhX which is not implemented on the server", + which); + } + } + break; + } + } + + // Preprocessing for server->client commands... if (from_server) { switch (this->get_command_field(input_header)) { case 0x02: // init encryption diff --git a/src/ReceiveSubcommands.cc b/src/ReceiveSubcommands.cc index 083139ac..ed06a713 100644 --- a/src/ReceiveSubcommands.cc +++ b/src/ReceiveSubcommands.cc @@ -1011,7 +1011,7 @@ subcommand_handler_t subcommand_handlers[0x100] = { process_subcommand_forward_check_size_client, // Intra-map warp process_subcommand_forward_check_size_client, process_subcommand_forward_check_size_client, - process_subcommand_unimplemented, + process_subcommand_forward_check_size_game, process_subcommand_forward_check_size_game, process_subcommand_pick_up_item, process_subcommand_unimplemented, @@ -1196,3 +1196,7 @@ void process_subcommand(shared_ptr s, shared_ptr l, const PSOSubcommand* sub, size_t count) { subcommand_handlers[sub->byte[0]](s, l, c, command, flag, sub, count); } + +bool subcommand_is_implemented(uint8_t which) { + return subcommand_handlers[which] != process_subcommand_unimplemented; +} diff --git a/src/ReceiveSubcommands.hh b/src/ReceiveSubcommands.hh index d42ca758..070ad097 100644 --- a/src/ReceiveSubcommands.hh +++ b/src/ReceiveSubcommands.hh @@ -12,3 +12,5 @@ void check_size(uint16_t size, uint16_t min_size, uint16_t max_size = 0); void process_subcommand(std::shared_ptr s, std::shared_ptr l, std::shared_ptr c, uint8_t command, uint8_t flag, const PSOSubcommand* sub, size_t count); + +bool subcommand_is_implemented(uint8_t which);