use different colors for sent and received commands
This commit is contained in:
@@ -26,6 +26,7 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
FileContentsCache file_cache;
|
FileContentsCache file_cache;
|
||||||
|
bool use_terminal_colors = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -279,6 +280,10 @@ void drop_privileges(const string& username) {
|
|||||||
int main(int, char**) {
|
int main(int, char**) {
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
|
||||||
|
if (isatty(fileno(stderr))) {
|
||||||
|
use_terminal_colors = true;
|
||||||
|
}
|
||||||
|
|
||||||
shared_ptr<ServerState> state(new ServerState());
|
shared_ptr<ServerState> state(new ServerState());
|
||||||
|
|
||||||
shared_ptr<struct event_base> base(event_base_new(), event_base_free);
|
shared_ptr<struct event_base> base(event_base_new(), event_base_free);
|
||||||
|
|||||||
+14
-1
@@ -11,6 +11,10 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern bool use_terminal_colors;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PSOCommandHeader::PSOCommandHeader() {
|
PSOCommandHeader::PSOCommandHeader() {
|
||||||
this->bb.size = 0;
|
this->bb.size = 0;
|
||||||
this->bb.command = 0;
|
this->bb.command = 0;
|
||||||
@@ -185,7 +189,12 @@ void print_received_command(
|
|||||||
const void* data,
|
const void* data,
|
||||||
size_t size,
|
size_t size,
|
||||||
GameVersion version,
|
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;
|
string name_token;
|
||||||
if (name && name[0]) {
|
if (name && name[0]) {
|
||||||
name_token = string(" from ") + name;
|
name_token = string(" from ") + name;
|
||||||
@@ -206,6 +215,10 @@ void print_received_command(
|
|||||||
w.write(data, size);
|
w.write(data, size);
|
||||||
|
|
||||||
print_data(stderr, w.str());
|
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) {
|
void check_size_v(size_t size, size_t min_size, size_t max_size) {
|
||||||
|
|||||||
+2
-1
@@ -64,7 +64,8 @@ void print_received_command(
|
|||||||
const void* data,
|
const void* data,
|
||||||
size_t size,
|
size_t size,
|
||||||
GameVersion version,
|
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
|
// This function is used in a lot of places to check received command sizes and
|
||||||
// cast them to the appropriate type
|
// cast them to the appropriate type
|
||||||
|
|||||||
+1
-1
@@ -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(),
|
for_each_received_command(this->server_bev.get(), this->version, this->server_input_crypt.get(),
|
||||||
[&](uint16_t command, uint32_t flag, string& data) {
|
[&](uint16_t command, uint32_t flag, string& data) {
|
||||||
print_received_command(command, flag, data.data(), data.size(),
|
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(
|
process_proxy_command(
|
||||||
this->server->state,
|
this->server->state,
|
||||||
*this,
|
*this,
|
||||||
|
|||||||
@@ -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,
|
void process_gba_file_request(shared_ptr<ServerState>, shared_ptr<Client> c,
|
||||||
uint16_t, uint32_t, const string& data) { // D7
|
uint16_t, uint32_t, const string& data) { // D7
|
||||||
static FileContentsCache file_cache;
|
|
||||||
|
|
||||||
string filename(data);
|
string filename(data);
|
||||||
strip_trailing_zeroes(filename);
|
strip_trailing_zeroes(filename);
|
||||||
auto contents = file_cache.get(filename);
|
auto contents = file_cache.get(filename);
|
||||||
|
|||||||
+8
-1
@@ -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]) {
|
if (name_str[0]) {
|
||||||
name_token = string(" to ") + name_str;
|
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)",
|
log(INFO, "Sending%s (version=%d command=%04hX flag=%08X)",
|
||||||
name_token.c_str(), static_cast<int>(version), command, flag);
|
name_token.c_str(), static_cast<int>(version), command, flag);
|
||||||
print_data(stderr, send_data.data(), send_data.size());
|
print_data(stderr, send_data.data(), send_data.size());
|
||||||
|
if (use_terminal_colors) {
|
||||||
|
print_color_escape(stderr, TerminalFormat::NORMAL, TerminalFormat::END);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crypt) {
|
if (crypt) {
|
||||||
|
|||||||
Reference in New Issue
Block a user