add $save command

This commit is contained in:
Martin Michelsen
2023-11-15 22:37:18 -08:00
parent 82c651a3ad
commit 722010c0f7
4 changed files with 34 additions and 4 deletions
+24
View File
@@ -1026,6 +1026,29 @@ static void server_command_convert_char_to_bb(shared_ptr<Client> c, const std::s
send_get_player_info(c);
}
static void server_command_save(shared_ptr<Client> c, const std::string&) {
check_version(c, GameVersion::BB);
try {
c->game_data.save_character_file();
send_text_message(c, "Character data saved");
} catch (const exception& e) {
send_text_message_printf(c, "Can\'t save character:\n%s", e.what());
}
try {
c->game_data.save_system_file();
send_text_message(c, "System data saved");
} catch (const exception& e) {
send_text_message_printf(c, "Can\'t save system data:\n%s", e.what());
}
try {
c->game_data.save_guild_card_file();
send_text_message(c, "Guild Card data saved");
} catch (const exception& e) {
send_text_message_printf(c, "Can\'t save Guild Cards:\n%s", e.what());
}
c->reschedule_save_game_data_event();
}
////////////////////////////////////////////////////////////////////////////////
// Administration commands
@@ -1695,6 +1718,7 @@ static const unordered_map<string, ChatCommandDefinition> chat_commands({
{"$qsync", {server_command_qsync, nullptr}},
{"$quest", {server_command_quest, nullptr}},
{"$rand", {server_command_rand, proxy_command_rand}},
{"$save", {server_command_save, nullptr}},
{"$saverec", {server_command_saverec, nullptr}},
{"$sc", {server_command_send_client, proxy_command_send_client}},
{"$secid", {server_command_secid, proxy_command_secid}},
+8 -4
View File
@@ -179,10 +179,7 @@ Client::Client(
this->last_switch_enabled_command.header.subcommand = 0;
memset(&this->next_connection_addr, 0, sizeof(this->next_connection_addr));
if (this->version() == GameVersion::BB) {
struct timeval tv = usecs_to_timeval(60000000); // 1 minute
event_add(this->save_game_data_event.get(), &tv);
}
this->reschedule_save_game_data_event();
this->reschedule_ping_and_timeout_events();
this->log.info("Created");
@@ -199,6 +196,13 @@ Client::~Client() {
this->log.info("Deleted");
}
void Client::reschedule_save_game_data_event() {
if (this->version() == GameVersion::BB) {
struct timeval tv = usecs_to_timeval(60000000); // 1 minute
event_add(this->save_game_data_event.get(), &tv);
}
}
void Client::reschedule_ping_and_timeout_events() {
struct timeval ping_tv = usecs_to_timeval(30000000); // 30 seconds
event_add(this->send_ping_event.get(), &ping_tv);
+1
View File
@@ -218,6 +218,7 @@ struct Client : public std::enable_shared_from_this<Client> {
ServerBehavior server_behavior);
~Client();
void reschedule_save_game_data_event();
void reschedule_ping_and_timeout_events();
inline GameVersion version() const {