diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 948f1c0aef..1a7e1d6908 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -105,11 +105,6 @@ static ConsoleFileList _console_file_list_savegame{FT_SAVEGAME, true}; ///< File static ConsoleFileList _console_file_list_scenario{FT_SCENARIO, false}; ///< File storage cache for scenarios. static ConsoleFileList _console_file_list_heightmap{FT_HEIGHTMAP, false}; ///< File storage cache for heightmaps. -/* console command defines */ -#define DEF_CONSOLE_CMD(function) static bool function([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) -#define DEF_CONSOLE_HOOK(function) static ConsoleHookResult function(bool echo) - - /**************** * command hooks ****************/ @@ -131,7 +126,7 @@ static inline bool NetworkAvailable(bool echo) * Check whether we are a server. * @return Are we a server? True when yes, false otherwise. */ -DEF_CONSOLE_HOOK(ConHookServerOnly) +static ConsoleHookResult ConHookServerOnly(bool echo) { if (!NetworkAvailable(echo)) return CHR_DISALLOW; @@ -146,7 +141,7 @@ DEF_CONSOLE_HOOK(ConHookServerOnly) * Check whether we are a client in a network game. * @return Are we a client in a network game? True when yes, false otherwise. */ -DEF_CONSOLE_HOOK(ConHookClientOnly) +static ConsoleHookResult ConHookClientOnly(bool echo) { if (!NetworkAvailable(echo)) return CHR_DISALLOW; @@ -161,7 +156,7 @@ DEF_CONSOLE_HOOK(ConHookClientOnly) * Check whether we are in a multiplayer game. * @return True when we are client or server in a network game. */ -DEF_CONSOLE_HOOK(ConHookNeedNetwork) +static ConsoleHookResult ConHookNeedNetwork(bool echo) { if (!NetworkAvailable(echo)) return CHR_DISALLOW; @@ -176,7 +171,7 @@ DEF_CONSOLE_HOOK(ConHookNeedNetwork) * Check whether we are in a multiplayer game and are playing, i.e. we are not the dedicated server. * @return Are we a client or non-dedicated server in a network game? True when yes, false otherwise. */ -DEF_CONSOLE_HOOK(ConHookNeedNonDedicatedNetwork) +static ConsoleHookResult ConHookNeedNonDedicatedNetwork(bool echo) { if (!NetworkAvailable(echo)) return CHR_DISALLOW; @@ -191,7 +186,7 @@ DEF_CONSOLE_HOOK(ConHookNeedNonDedicatedNetwork) * Check whether we are in singleplayer mode. * @return True when no network is active. */ -DEF_CONSOLE_HOOK(ConHookNoNetwork) +static ConsoleHookResult ConHookNoNetwork(bool echo) { if (_networking) { if (echo) IConsolePrint(CC_ERROR, "This command is forbidden in multiplayer."); @@ -204,7 +199,7 @@ DEF_CONSOLE_HOOK(ConHookNoNetwork) * Check if are either in singleplayer or a server. * @return True iff we are either in singleplayer or a server. */ -DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork) +static ConsoleHookResult ConHookServerOrNoNetwork(bool echo) { if (_networking && !_network_server) { if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server."); @@ -213,7 +208,7 @@ DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork) return CHR_ALLOW; } -DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool) +static ConsoleHookResult ConHookNewGRFDeveloperTool(bool echo) { if (_settings_client.gui.newgrf_developer_tools) { if (_game_mode == GM_MENU) { @@ -229,7 +224,7 @@ DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool) * Reset status of all engines. * @return Will always succeed. */ -DEF_CONSOLE_CMD(ConResetEngines) +static bool ConResetEngines([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Reset status data of all engines. This might solve some issues with 'lost' engines. Usage: 'resetengines'."); @@ -245,7 +240,7 @@ DEF_CONSOLE_CMD(ConResetEngines) * @return Will always return true. * @note Resetting the pool only succeeds when there are no vehicles ingame. */ -DEF_CONSOLE_CMD(ConResetEnginePool) +static bool ConResetEnginePool([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Reset NewGRF allocations of engine slots. This will remove invalid engine definitions, and might make default engines available again."); @@ -271,7 +266,7 @@ DEF_CONSOLE_CMD(ConResetEnginePool) * param tile number. * @return True when the tile is reset or the help on usage was printed (0 or two parameters). */ -DEF_CONSOLE_CMD(ConResetTile) +static bool ConResetTile([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Reset a tile to bare land. Usage: 'resettile '."); @@ -296,7 +291,7 @@ DEF_CONSOLE_CMD(ConResetTile) * param level As defined by ZoomLevel and as limited by zoom_min/zoom_max from GUISettings. * @return True when either console help was shown or a proper amount of parameters given. */ -DEF_CONSOLE_CMD(ConZoomToLevel) +static bool ConZoomToLevel([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { switch (argc) { case 0: @@ -355,7 +350,7 @@ DEF_CONSOLE_CMD(ConZoomToLevel) * and y coordinates. * @return True when either console help was shown or a proper amount of parameters given. */ -DEF_CONSOLE_CMD(ConScrollToTile) +static bool ConScrollToTile([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Center the screen on a given tile."); @@ -409,7 +404,7 @@ DEF_CONSOLE_CMD(ConScrollToTile) * param filename the filename to save the map to. * @return True when help was displayed or the file attempted to be saved. */ -DEF_CONSOLE_CMD(ConSave) +static bool ConSave([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Save the current game. Usage: 'save '."); @@ -436,7 +431,7 @@ DEF_CONSOLE_CMD(ConSave) * Explicitly save the configuration. * @return True. */ -DEF_CONSOLE_CMD(ConSaveConfig) +static bool ConSaveConfig([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Saves the configuration for new games to the configuration file, typically 'openttd.cfg'."); @@ -449,7 +444,7 @@ DEF_CONSOLE_CMD(ConSaveConfig) return true; } -DEF_CONSOLE_CMD(ConLoad) +static bool ConLoad([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Load a game by name or index. Usage: 'load '."); @@ -475,7 +470,7 @@ DEF_CONSOLE_CMD(ConLoad) return true; } -DEF_CONSOLE_CMD(ConLoadScenario) +static bool ConLoadScenario([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Load a scenario by name or index. Usage: 'load_scenario '."); @@ -501,7 +496,7 @@ DEF_CONSOLE_CMD(ConLoadScenario) return true; } -DEF_CONSOLE_CMD(ConLoadHeightmap) +static bool ConLoadHeightmap([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Load a heightmap by name or index. Usage: 'load_heightmap '."); @@ -527,7 +522,7 @@ DEF_CONSOLE_CMD(ConLoadHeightmap) return true; } -DEF_CONSOLE_CMD(ConRemove) +static bool ConRemove([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Remove a savegame by name or index. Usage: 'rm '."); @@ -553,7 +548,7 @@ DEF_CONSOLE_CMD(ConRemove) /* List all the files in the current dir via console */ -DEF_CONSOLE_CMD(ConListFiles) +static bool ConListFiles([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "List all loadable savegames and directories in the current dir via console. Usage: 'ls | dir'."); @@ -569,7 +564,7 @@ DEF_CONSOLE_CMD(ConListFiles) } /* List all the scenarios */ -DEF_CONSOLE_CMD(ConListScenarios) +static bool ConListScenarios([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "List all loadable scenarios. Usage: 'list_scenarios'."); @@ -585,7 +580,7 @@ DEF_CONSOLE_CMD(ConListScenarios) } /* List all the heightmaps */ -DEF_CONSOLE_CMD(ConListHeightmaps) +static bool ConListHeightmaps([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "List all loadable heightmaps. Usage: 'list_heightmaps'."); @@ -601,7 +596,7 @@ DEF_CONSOLE_CMD(ConListHeightmaps) } /* Change the dir via console */ -DEF_CONSOLE_CMD(ConChangeDirectory) +static bool ConChangeDirectory([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Change the dir via console. Usage: 'cd '."); @@ -630,7 +625,7 @@ DEF_CONSOLE_CMD(ConChangeDirectory) return true; } -DEF_CONSOLE_CMD(ConPrintWorkingDirectory) +static bool ConPrintWorkingDirectory([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Print out the current working directory. Usage: 'pwd'."); @@ -645,7 +640,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory) return true; } -DEF_CONSOLE_CMD(ConClearBuffer) +static bool ConClearBuffer([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Clear the console buffer. Usage: 'clear'."); @@ -705,7 +700,7 @@ static bool ConKickOrBan(const char *argv, bool ban, const std::string &reason) return true; } -DEF_CONSOLE_CMD(ConKick) +static bool ConKick([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Kick a client from a network game. Usage: 'kick []'."); @@ -728,7 +723,7 @@ DEF_CONSOLE_CMD(ConKick) } } -DEF_CONSOLE_CMD(ConBan) +static bool ConBan([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Ban a client from a network game. Usage: 'ban []'."); @@ -752,7 +747,7 @@ DEF_CONSOLE_CMD(ConBan) } } -DEF_CONSOLE_CMD(ConUnBan) +static bool ConUnBan([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Unban a client from a network game. Usage: 'unban '."); @@ -784,7 +779,7 @@ DEF_CONSOLE_CMD(ConUnBan) return true; } -DEF_CONSOLE_CMD(ConBanList) +static bool ConBanList([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "List the IP's of banned clients: Usage 'banlist'."); @@ -802,7 +797,7 @@ DEF_CONSOLE_CMD(ConBanList) return true; } -DEF_CONSOLE_CMD(ConPauseGame) +static bool ConPauseGame([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Pause a network game. Usage: 'pause'."); @@ -824,7 +819,7 @@ DEF_CONSOLE_CMD(ConPauseGame) return true; } -DEF_CONSOLE_CMD(ConUnpauseGame) +static bool ConUnpauseGame([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Unpause a network game. Usage: 'unpause'."); @@ -850,7 +845,7 @@ DEF_CONSOLE_CMD(ConUnpauseGame) return true; } -DEF_CONSOLE_CMD(ConRcon) +static bool ConRcon([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Remote control the server from another client. Usage: 'rcon '."); @@ -869,7 +864,7 @@ DEF_CONSOLE_CMD(ConRcon) return true; } -DEF_CONSOLE_CMD(ConStatus) +static bool ConStatus([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "List the status of all clients connected to the server. Usage 'status'."); @@ -880,7 +875,7 @@ DEF_CONSOLE_CMD(ConStatus) return true; } -DEF_CONSOLE_CMD(ConServerInfo) +static bool ConServerInfo([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "List current and maximum client/company limits. Usage 'server_info'."); @@ -896,7 +891,7 @@ DEF_CONSOLE_CMD(ConServerInfo) return true; } -DEF_CONSOLE_CMD(ConClientNickChange) +static bool ConClientNickChange([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc != 3) { IConsolePrint(CC_HELP, "Change the nickname of a connected client. Usage: 'client_name '."); @@ -930,7 +925,7 @@ DEF_CONSOLE_CMD(ConClientNickChange) return true; } -DEF_CONSOLE_CMD(ConJoinCompany) +static bool ConJoinCompany([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc < 2) { IConsolePrint(CC_HELP, "Request joining another company. Usage: 'join '."); @@ -977,7 +972,7 @@ DEF_CONSOLE_CMD(ConJoinCompany) return true; } -DEF_CONSOLE_CMD(ConMoveClient) +static bool ConMoveClient([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc < 3) { IConsolePrint(CC_HELP, "Move a client to another company. Usage: 'move '."); @@ -1020,7 +1015,7 @@ DEF_CONSOLE_CMD(ConMoveClient) return true; } -DEF_CONSOLE_CMD(ConResetCompany) +static bool ConResetCompany([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Remove an idle company from the game. Usage: 'reset_company '."); @@ -1061,7 +1056,7 @@ DEF_CONSOLE_CMD(ConResetCompany) return true; } -DEF_CONSOLE_CMD(ConNetworkClients) +static bool ConNetworkClients([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'."); @@ -1073,7 +1068,7 @@ DEF_CONSOLE_CMD(ConNetworkClients) return true; } -DEF_CONSOLE_CMD(ConNetworkReconnect) +static bool ConNetworkReconnect([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Reconnect to server to which you were connected last time. Usage: 'reconnect []'."); @@ -1104,7 +1099,7 @@ DEF_CONSOLE_CMD(ConNetworkReconnect) return NetworkClientConnectGame(_settings_client.network.last_joined, playas); } -DEF_CONSOLE_CMD(ConNetworkConnect) +static bool ConNetworkConnect([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Connect to a remote OTTD server and join the game. Usage: 'connect '."); @@ -1122,7 +1117,7 @@ DEF_CONSOLE_CMD(ConNetworkConnect) * script file console commands *********************************/ -DEF_CONSOLE_CMD(ConExec) +static bool ConExec([[maybe_unused]] uint8_t argc, [[maybe_unused]] char *argv[]) { if (argc == 0) { IConsolePrint(CC_HELP, "Execute a local script file. Usage: 'exec