show client player name in sent/received commands

This commit is contained in:
Martin Michelsen
2022-03-07 21:56:35 -08:00
parent 15f978820f
commit 627498dc8a
6 changed files with 20 additions and 9 deletions
+4 -2
View File
@@ -708,7 +708,8 @@ static void command_silence(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
}
target->can_chat = !target->can_chat;
send_text_message_printf(l, "$C6%s %ssilenced", target->player.disp.name,
string target_name_sjis = encode_sjis(target->player.disp.name);
send_text_message_printf(l, "$C6%s %ssilenced", target_name_sjis.c_str(),
target->can_chat ? "un" : "");
}
@@ -730,7 +731,8 @@ static void command_kick(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
send_message_box(target, u"$C6You were kicked off by a moderator.");
target->should_disconnect = true;
send_text_message_printf(l, "$C6%s kicked off", target->player.disp.name);
string target_name_sjis = encode_sjis(target->player.disp.name);
send_text_message_printf(l, "$C6%s kicked off", target_name_sjis.c_str());
}
static void command_ban(shared_ptr<ServerState> s, shared_ptr<Lobby> l,
-1
View File
@@ -45,7 +45,6 @@ Client::Client(
this->is_virtual_connection = false;
get_socket_addresses(fd, &this->local_addr, &this->remote_addr);
}
memset(this->name, 0, sizeof(this->name));
memset(&this->next_connection_addr, 0, sizeof(this->next_connection_addr));
}
-1
View File
@@ -35,7 +35,6 @@ struct ClientConfigBB {
struct Client {
// License & account
std::shared_ptr<const License> license;
char16_t name[0x20];
ClientConfigBB config;
GameVersion version;
uint16_t flags;
+8 -3
View File
@@ -1018,7 +1018,8 @@ void process_player_data(shared_ptr<ServerState> s, shared_ptr<Client> c,
if (!failure) {
send_text_message_printf(c,
"$C6PSOBB player data saved\nas player %hhu for user\n%s",
c->pending_bb_save_player_index + 1, c->pending_bb_save_username.c_str());
static_cast<uint8_t>(c->pending_bb_save_player_index + 1),
c->pending_bb_save_username.c_str());
}
c->pending_bb_save_username.clear();
@@ -2168,8 +2169,12 @@ void process_command(shared_ptr<ServerState> s, shared_ptr<Client> c,
uint16_t command, uint32_t flag, uint16_t size, const void* data) {
// TODO: this is slow; make it better somehow
{
log(INFO, "Received version=%d size=%04hX command=%04hX flag=%08X",
static_cast<int>(c->version), size, command, flag);
string name_token;
if (c->player.disp.name[0]) {
name_token = " from " + remove_language_marker(encode_sjis(c->player.disp.name));
}
log(INFO, "Received%s version=%d size=%04hX command=%04hX flag=%08X",
name_token.c_str(), static_cast<int>(c->version), size, command, flag);
string data_to_print;
if (c->version == GameVersion::BB) {
+6 -1
View File
@@ -74,7 +74,12 @@ void send_command(shared_ptr<Client> c, uint16_t command, uint32_t flag,
throw logic_error("unimplemented game version in send_command");
}
log(INFO, "Sending command");
string name_token;
if (c->player.disp.name[0]) {
name_token = " to " + remove_language_marker(encode_sjis(c->player.disp.name));
}
log(INFO, "Sending%s version=%d size=%04zX command=%04hX flag=%08X",
name_token.c_str(), static_cast<int>(c->version), size, command, flag);
print_data(stderr, send_data.data(), send_data.size());
c->send(move(send_data));
+2 -1
View File
@@ -109,7 +109,8 @@ void send_simple_mail(std::shared_ptr<Client> c, uint32_t from_serial_number,
const char16_t* from_name, const char16_t* text);
template <typename TARGET>
void send_text_message_printf(std::shared_ptr<TARGET> t, const char* format, ...) {
__attribute__((format(printf, 2, 3))) void send_text_message_printf(
std::shared_ptr<TARGET> t, const char* format, ...) {
va_list va;
va_start(va, format);
std::string buf = string_vprintf(format, va);