Skip to content

Commit

Permalink
feat: implement maintain mode (opentibiabr#1791)
Browse files Browse the repository at this point in the history
Introduces functionality to enable maintenance mode, restricting user access and displaying a customizable message during server maintenance or update periods.
  • Loading branch information
dudantas authored Nov 8, 2023
1 parent 2137f6f commit 0249c80
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
9 changes: 9 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ coreDirectory = "data"
-- NOTE: Will only display logs with level higher or equal the one set.
logLevel = "info"

--- Toggles the server's maintenance mode.
-- When enabled, it restricts user access and indicates maintenance operations.
-- @field [parent=#global] #boolean toggleMaintainMode false by default, set to true to enable maintenance mode.
toggleMaintainMode = false
--- Message displayed during maintenance mode.
-- Should inform the expected downtime or resumption details succinctly.
-- @field [parent=#global] #string maintainModeMessage an empty string by default, set a custom message if needed.
maintainModeMessage = ""

-- Combat settings
-- NOTE: valid values for worldType are: "pvp", "no-pvp" and "pvp-enforced"
worldType = "pvp"
Expand Down
10 changes: 8 additions & 2 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ int CanaryServer::run() {

g_game().start(&serviceManager);
g_game().setGameState(GAME_STATE_NORMAL);

g_webhook().sendMessage("Server is now online", "Server has successfully started.", WEBHOOK_COLOR_ONLINE);
if (g_configManager().getBoolean(TOGGLE_MAINTAIN_MODE)) {
g_game().setGameState(GAME_STATE_CLOSED);
g_logger().warn("Initialized in maintain mode!");
g_webhook().sendMessage("Server is now online", "The server is now online. Access is currently restricted to administrators only.", WEBHOOK_COLOR_ONLINE);
} else {
g_game().setGameState(GAME_STATE_NORMAL);
g_webhook().sendMessage("Server is now online", "Server has successfully started.", WEBHOOK_COLOR_ONLINE);
}

loaderStatus = LoaderStatus::LOADED;
} catch (FailedToInitializeCanary &err) {
Expand Down
5 changes: 2 additions & 3 deletions src/config/config_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ enum booleanConfig_t {
RESET_SESSIONS_ON_STARTUP,
TOGGLE_WHEELSYSTEM,
TOGGLE_ATTACK_SPEED_ONFIST,

VIP_SYSTEM_ENABLED,
VIP_AUTOLOOT_VIP_ONLY,
VIP_STAY_ONLINE,

REWARD_CHEST_COLLECT_ENABLED,
TOGGLE_MOUNT_IN_PZ,
TOGGLE_HOUSE_TRANSFER_ON_SERVER_RESTART,

TOGGLE_RECEIVE_REWARD,
TOGGLE_MAINTAIN_MODE,

LAST_BOOLEAN_CONFIG
};
Expand Down Expand Up @@ -128,6 +126,7 @@ enum stringConfig_t {
FORGE_FIENDISH_INTERVAL_TIME,
TIBIADROME_CONCOCTION_TICK_TYPE,
M_CONST,
MAINTAIN_MODE_MESSAGE,

LAST_STRING_CONFIG
};
Expand Down
2 changes: 2 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ bool ConfigManager::load() {
boolean[BIND_ONLY_GLOBAL_ADDRESS] = getGlobalBoolean(L, "bindOnlyGlobalAddress", false);
boolean[OPTIMIZE_DATABASE] = getGlobalBoolean(L, "startupDatabaseOptimization", true);
boolean[TOGGLE_MAP_CUSTOM] = getGlobalBoolean(L, "toggleMapCustom", true);
boolean[TOGGLE_MAINTAIN_MODE] = getGlobalBoolean(L, "toggleMaintainMode", false);
string[MAINTAIN_MODE_MESSAGE] = getGlobalString(L, "maintainModeMessage", "");

string[IP] = getGlobalString(L, "ip", "127.0.0.1");
string[MAP_NAME] = getGlobalString(L, "mapName", "canary");
Expand Down
7 changes: 6 additions & 1 deletion src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,12 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS

if (g_game().getGameState() == GAME_STATE_CLOSED && !player->hasFlag(PlayerFlags_t::CanAlwaysLogin)) {
g_game().removePlayerUniqueLogin(player);
disconnectClient("Server is currently closed.\nPlease try again later.");
auto maintainMessage = g_configManager().getString(MAINTAIN_MODE_MESSAGE);
if (!maintainMessage.empty()) {
disconnectClient(maintainMessage);
} else {
disconnectClient("Server is currently closed.\nPlease try again later.");
}
return;
}

Expand Down

0 comments on commit 0249c80

Please sign in to comment.