use disconnect_client for the kick and ban commands

This commit is contained in:
Martin Michelsen
2025-01-17 21:05:40 -08:00
parent e2caf81e4b
commit 6e9d86a6ca
2 changed files with 15 additions and 3 deletions
+14 -2
View File
@@ -307,6 +307,12 @@ ChatCommandDefinition cc_ban(
if (target->login->account->check_flag(Account::Flag::BAN_USER)) {
throw precondition_failed("$C6You do not have\nsufficient privileges.");
}
if (a.c == target) {
// This shouldn't be possible because you need BAN_USER to get here,
// but the target can't have BAN_USER if we get here, so if a.c and
// target are the same, one of the preceding conditions must be false.
throw logic_error("client attempts to ban themself");
}
uint64_t usecs = stoull(a.text, nullptr, 0) * 1000000;
@@ -330,8 +336,8 @@ ChatCommandDefinition cc_ban(
target->login->account->ban_end_time = phosg::now() + usecs;
target->login->account->save();
send_message_box(target, "$C6You have been banned.");
target->should_disconnect = true;
string target_name = name_for_client(target);
s->game_server->disconnect_client(target);
send_text_message_printf(a.c, "$C6%s banned", target_name.c_str());
},
unavailable_on_proxy_server);
@@ -1134,10 +1140,16 @@ ChatCommandDefinition cc_kick(
if (target->login->account->check_flag(Account::Flag::KICK_USER)) {
throw precondition_failed("$C6You do not have\nsufficient privileges.");
}
if (a.c == target) {
// This shouldn't be possible because you need KICK_USER to get here,
// but the target can't have KICK_USER if we get here, so if a.c and
// target are the same, one of the preceding conditions must be false.
throw logic_error("client attempts to kick themself off");
}
send_message_box(target, "$C6You have been kicked off the server.");
target->should_disconnect = true;
string target_name = name_for_client(target);
s->game_server->disconnect_client(target);
send_text_message_printf(a.c, "$C6%s kicked off", target_name.c_str());
},
unavailable_on_proxy_server);
+1 -1
View File
@@ -655,7 +655,7 @@ ShellCommand c_kick(
+[](ShellCommand::Args& args) -> std::deque<std::string> {
auto target = args.s->find_client(&args.args);
send_message_box(target, "$C6You have been kicked off the server.");
target->should_disconnect = true;
args.s->game_server->disconnect_client(target);
return {phosg::string_printf("Client C-%" PRIX64 " disconnected from server", target->id)};
});