add some safety for accidental newserv chat commands on proxy server
This commit is contained in:
+30
-10
@@ -435,20 +435,40 @@ static void check_implemented_subcommand(
|
|||||||
void ProxyServer::LinkedSession::on_client_input() {
|
void ProxyServer::LinkedSession::on_client_input() {
|
||||||
string name = string_printf("ProxySession:%08" PRIX32 ":client", this->license->serial_number);
|
string name = string_printf("ProxySession:%08" PRIX32 ":client", this->license->serial_number);
|
||||||
for_each_received_command(this->client_bev.get(), this->version, this->client_input_crypt.get(),
|
for_each_received_command(this->client_bev.get(), this->version, this->client_input_crypt.get(),
|
||||||
[&](uint16_t command, uint32_t flag, const 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, name.c_str());
|
this->version, name.c_str());
|
||||||
check_implemented_subcommand(this->license->serial_number, command, data);
|
check_implemented_subcommand(this->license->serial_number, command, data);
|
||||||
|
|
||||||
if (!this->client_bev.get()) {
|
bool should_forward = true;
|
||||||
log(WARNING, "[ProxyServer/%08" PRIX32 "] No server is present; dropping command",
|
switch (command) {
|
||||||
this->license->serial_number);
|
case 0x06:
|
||||||
} else {
|
if (data.size() < 12) {
|
||||||
// Note: we intentionally don't pass a name string here because we already
|
break;
|
||||||
// printed the command above
|
}
|
||||||
send_command(this->server_bev.get(), this->version,
|
// If this chat message looks like a chat command, suppress it
|
||||||
this->server_output_crypt.get(), command, flag,
|
if (data[8] == '$' || (data[8] == '\t' && data[9] != 'C' && data[10] == '$')) {
|
||||||
data.data(), data.size());
|
log(WARNING, "[ProxyServer/%08" PRIX32 "] Chat message appears to be a server command; dropping it",
|
||||||
|
this->license->serial_number);
|
||||||
|
should_forward = false;
|
||||||
|
} else {
|
||||||
|
// Turn all $ into \t and all # into \n
|
||||||
|
add_color_inplace(data.data() + 8, data.size() - 8);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (should_forward) {
|
||||||
|
if (!this->client_bev.get()) {
|
||||||
|
log(WARNING, "[ProxyServer/%08" PRIX32 "] No server is present; dropping command",
|
||||||
|
this->license->serial_number);
|
||||||
|
} else {
|
||||||
|
// Note: we intentionally don't pass a name string here because we already
|
||||||
|
// printed the command above
|
||||||
|
send_command(this->server_bev.get(), this->version,
|
||||||
|
this->server_output_crypt.get(), command, flag,
|
||||||
|
data.data(), data.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user