From 52db9008a83f6f5c423876da62b18ad580fea57f Mon Sep 17 00:00:00 2001 From: Martin Michelsen Date: Wed, 28 Dec 2022 00:29:55 -0800 Subject: [PATCH] implement ss shell command on game server --- src/ReceiveCommands.cc | 29 +++++++++++++++++++++++++++++ src/ReceiveCommands.hh | 2 ++ src/ServerShell.cc | 11 ++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index ced2f496..b8032060 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -4081,3 +4081,32 @@ void on_command(shared_ptr s, shared_ptr c, on_unimplemented_command(s, c, command, flag, data); } } + +void on_command_with_header(shared_ptr s, shared_ptr c, + string& data) { + switch (c->version()) { + case GameVersion::DC: + case GameVersion::GC: + case GameVersion::XB: { + auto& header = check_size_t(data, + sizeof(PSOCommandHeaderDCV3), 0xFFFF); + on_command(s, c, header.command, header.flag, data.substr(sizeof(header))); + break; + } + case GameVersion::PC: + case GameVersion::PATCH: { + auto& header = check_size_t(data, + sizeof(PSOCommandHeaderPC), 0xFFFF); + on_command(s, c, header.command, header.flag, data.substr(sizeof(header))); + break; + } + case GameVersion::BB: { + auto& header = check_size_t(data, + sizeof(PSOCommandHeaderBB), 0xFFFF); + on_command(s, c, header.command, header.flag, data.substr(sizeof(header))); + break; + } + default: + throw logic_error("unimplemented game version in on_command_with_header"); + } +} diff --git a/src/ReceiveCommands.hh b/src/ReceiveCommands.hh index 7f9890c5..e70ff77f 100644 --- a/src/ReceiveCommands.hh +++ b/src/ReceiveCommands.hh @@ -22,3 +22,5 @@ void on_disconnect(std::shared_ptr s, std::shared_ptr c); void on_command(std::shared_ptr s, std::shared_ptr c, uint16_t command, uint32_t flag, const std::string& data); +void on_command_with_header(std::shared_ptr s, + std::shared_ptr c, std::string& data); diff --git a/src/ServerShell.cc b/src/ServerShell.cc index b60d7ff2..704b2725 100644 --- a/src/ServerShell.cc +++ b/src/ServerShell.cc @@ -6,6 +6,7 @@ #include +#include "ReceiveCommands.hh" #include "ServerState.hh" #include "SendCommands.hh" #include "StaticGameData.hh" @@ -508,10 +509,6 @@ session with ID 17205AE4, run the command `on 17205AE4 sc 1D 00 04 00`.\n\ } } else { - if (command_name [1] == 's') { - throw runtime_error("cannot send to server in non-proxy session"); - } - shared_ptr c; if (session_name.empty()) { c = this->state->game_server->get_client(); @@ -528,7 +525,11 @@ session with ID 17205AE4, run the command `on 17205AE4 sc 1D 00 04 00`.\n\ } if (c) { - send_command_with_header(c->channel, data.data(), data.size()); + if (command_name[1] == 's') { + on_command_with_header(this->state, c, data); + } else { + send_command_with_header(c->channel, data.data(), data.size()); + } } else { throw runtime_error("no client available"); }