use different colors for sent and received commands

This commit is contained in:
Martin Michelsen
2022-04-03 23:35:11 -07:00
parent be69f26af5
commit 028078925d
6 changed files with 30 additions and 6 deletions
+5
View File
@@ -26,6 +26,7 @@ using namespace std;
FileContentsCache file_cache;
bool use_terminal_colors = false;
@@ -279,6 +280,10 @@ void drop_privileges(const string& username) {
int main(int, char**) {
signal(SIGPIPE, SIG_IGN);
if (isatty(fileno(stderr))) {
use_terminal_colors = true;
}
shared_ptr<ServerState> state(new ServerState());
shared_ptr<struct event_base> base(event_base_new(), event_base_free);
+14 -1
View File
@@ -11,6 +11,10 @@ using namespace std;
extern bool use_terminal_colors;
PSOCommandHeader::PSOCommandHeader() {
this->bb.size = 0;
this->bb.command = 0;
@@ -185,7 +189,12 @@ void print_received_command(
const void* data,
size_t size,
GameVersion version,
const char* name) {
const char* name,
TerminalFormat color) {
if (use_terminal_colors) {
print_color_escape(stderr, color, TerminalFormat::BOLD, TerminalFormat::END);
}
string name_token;
if (name && name[0]) {
name_token = string(" from ") + name;
@@ -206,6 +215,10 @@ void print_received_command(
w.write(data, size);
print_data(stderr, w.str());
if (use_terminal_colors) {
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
}
}
void check_size_v(size_t size, size_t min_size, size_t max_size) {
+2 -1
View File
@@ -64,7 +64,8 @@ void print_received_command(
const void* data,
size_t size,
GameVersion version,
const char* name = nullptr);
const char* name = nullptr,
TerminalFormat color = TerminalFormat::FG_GREEN);
// This function is used in a lot of places to check received command sizes and
// cast them to the appropriate type
+1 -1
View File
@@ -587,7 +587,7 @@ void ProxyServer::LinkedSession::on_server_input() {
for_each_received_command(this->server_bev.get(), this->version, this->server_input_crypt.get(),
[&](uint16_t command, uint32_t flag, string& data) {
print_received_command(command, flag, data.data(), data.size(),
this->version, this->server_name.c_str());
this->version, this->server_name.c_str(), TerminalFormat::FG_RED);
process_proxy_command(
this->server->state,
*this,
-2
View File
@@ -1036,8 +1036,6 @@ void process_quest_ready(shared_ptr<ServerState> s, shared_ptr<Client> c,
void process_gba_file_request(shared_ptr<ServerState>, shared_ptr<Client> c,
uint16_t, uint32_t, const string& data) { // D7
static FileContentsCache file_cache;
string filename(data);
strip_trailing_zeroes(filename);
auto contents = file_cache.get(filename);
+8 -1
View File
@@ -19,7 +19,8 @@ using namespace std;
static FileContentsCache file_cache;
extern bool use_terminal_colors;
extern FileContentsCache file_cache;
@@ -88,9 +89,15 @@ void send_command(
if (name_str[0]) {
name_token = string(" to ") + name_str;
}
if (use_terminal_colors) {
print_color_escape(stderr, TerminalFormat::FG_YELLOW, TerminalFormat::BOLD, TerminalFormat::END);
}
log(INFO, "Sending%s (version=%d command=%04hX flag=%08X)",
name_token.c_str(), static_cast<int>(version), command, flag);
print_data(stderr, send_data.data(), send_data.size());
if (use_terminal_colors) {
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
}
}
if (crypt) {