add $qfread command

This commit is contained in:
Martin Michelsen
2024-05-22 21:19:53 -07:00
parent 836704e987
commit 340a36878b
6 changed files with 151 additions and 58 deletions
+35 -4
View File
@@ -538,8 +538,38 @@ static void server_command_qgread(shared_ptr<Client> c, const std::string& args)
if (flag_num >= flags.size()) {
send_text_message_printf(c, "$C7Flag number must be\nless than %zu", flags.size());
} else {
send_text_message_printf(c, "$C7Quest counter %hhu\nhas value %" PRIu32,
flag_num, flags[flag_num].load());
send_text_message_printf(c, "$C7Quest counter %hhu\nhas value %" PRIu32, flag_num, flags[flag_num].load());
}
}
static void server_command_qfread(shared_ptr<Client> c, const std::string& args) {
auto s = c->require_server_state();
uint8_t counter_index;
uint32_t mask;
try {
const auto& def = s->quest_counter_fields.at(args);
counter_index = def.first;
mask = def.second;
} catch (const out_of_range&) {
send_text_message(c, "$C4Invalid field name");
return;
}
if (mask == 0) {
throw runtime_error("invalid quest counter definition");
}
uint32_t counter_value = c->character()->quest_counters.at(counter_index) & mask;
while (!(mask & 1)) {
mask >>= 1;
counter_value >>= 1;
}
if (mask == 1) {
send_text_message_printf(c, "$C7Field %s\nhas value %s", args.c_str(), counter_value ? "TRUE" : "FALSE");
} else {
send_text_message_printf(c, "$C7Field %s\nhas value %" PRIu32, args.c_str(), counter_value);
}
}
@@ -1634,7 +1664,7 @@ static void server_command_kick(shared_ptr<Client> c, const std::string& args) {
return;
}
send_message_box(target, "$C6You were kicked off by a moderator.");
send_message_box(target, "$C6You have been kicked off the server.");
target->should_disconnect = true;
string target_name = name_for_client(target);
send_text_message_printf(l, "$C6%s kicked off", target_name.c_str());
@@ -1685,7 +1715,7 @@ static void server_command_ban(shared_ptr<Client> c, const std::string& args) {
target->login->account->ban_end_time = now() + usecs;
target->login->account->save();
send_message_box(target, "$C6You were banned by a moderator.");
send_message_box(target, "$C6You have been banned.");
target->should_disconnect = true;
string target_name = name_for_client(target);
send_text_message_printf(l, "$C6%s banned", target_name.c_str());
@@ -2455,6 +2485,7 @@ static const unordered_map<string, ChatCommandDefinition> chat_commands({
{"$qcall", {server_command_qcall, proxy_command_qcall}},
{"$qcheck", {server_command_qcheck, nullptr}},
{"$qclear", {server_command_qclear, proxy_command_qclear}},
{"$qfread", {server_command_qfread, nullptr}},
{"$qgread", {server_command_qgread, nullptr}},
{"$qgwrite", {server_command_qgwrite, nullptr}},
{"$qset", {server_command_qset, proxy_command_qset}},
+9
View File
@@ -769,6 +769,15 @@ void ServerState::load_config_early() {
this->quest_flag_rewrites_v3 = parse_quest_flag_rewrites("QuestFlagRewritesV3");
this->quest_flag_rewrites_v4 = parse_quest_flag_rewrites("QuestFlagRewritesV4");
this->quest_counter_fields.clear();
try {
for (const auto& it : this->config_json->get_dict("QuestCounterFields")) {
const auto& def = it.second->as_list();
this->quest_counter_fields.emplace(it.first, make_pair(def.at(0)->as_int(), def.at(1)->as_int()));
}
} catch (const out_of_range&) {
}
this->persistent_game_idle_timeout_usecs = this->config_json->get_int("PersistentGameIdleTimeout", 0);
this->cheat_mode_behavior = parse_behavior_switch("CheatModeBehavior", BehaviorSwitch::OFF_BY_DEFAULT);
this->use_game_creator_section_id = this->config_json->get_bool("UseGameCreatorSectionID", false);
+1
View File
@@ -116,6 +116,7 @@ struct ServerState : public std::enable_shared_from_this<ServerState> {
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v1_v2;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v3;
std::unordered_map<uint16_t, IntegralExpression> quest_flag_rewrites_v4;
std::unordered_map<std::string, std::pair<uint8_t, uint32_t>> quest_counter_fields; // For $qfread command
uint64_t persistent_game_idle_timeout_usecs = 0;
bool ep3_send_function_call_enabled = false;
bool enable_v3_v4_protected_subcommands = false;