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
+1
View File
@@ -298,6 +298,7 @@ Some commands only work on the game server and not on the proxy server. The chat
* Blue Burst player commands (game server only)
* `$bbchar <username> <password> <1-4>`: Use this command when playing on a non-BB version of PSO. If the username and password are correct, this command converts your current character to BB format and saves it on the server in the given slot. Any character already in that slot is overwritten.
* `$edit <stat> <value>`: Modifies your character data. If the server does not allow cheat mode anywhere (that is, "CheatModeBehavior" is "Off" in config.json), this command does nothing.
* `$save`: Saves your character, system, and Guild Card data immediately. (By default, your character is saved every 60 seconds while online, and your account and Guild Card data are saved whenever they change.)
* Game state commands (game server only)
* `$maxlevel <level>`: Sets the maximum level for players to join the current game. (This only applies when joining; if a player joins and then levels up past this level during the game, they are not kicked out, but won't be able to rejoin if they leave.)
+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 {