mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: compile-time validate the string format of IConsolePrint (#11804)
This means we can no longer use runtime picking what string to use.
This commit is contained in:
parent
8b4c5a6269
commit
0b7410d979
|
@ -267,20 +267,18 @@ DEF_CONSOLE_CMD(ConZoomToLevel)
|
||||||
case 0:
|
case 0:
|
||||||
IConsolePrint(CC_HELP, "Set the current zoom level of the main viewport.");
|
IConsolePrint(CC_HELP, "Set the current zoom level of the main viewport.");
|
||||||
IConsolePrint(CC_HELP, "Usage: 'zoomto <level>'.");
|
IConsolePrint(CC_HELP, "Usage: 'zoomto <level>'.");
|
||||||
IConsolePrint(
|
|
||||||
CC_HELP,
|
if (ZOOM_LVL_MIN < _settings_client.gui.zoom_min) {
|
||||||
ZOOM_LVL_MIN < _settings_client.gui.zoom_min ?
|
IConsolePrint(CC_HELP, "The lowest zoom-in level allowed by current client settings is {}.", std::max(ZOOM_LVL_MIN, _settings_client.gui.zoom_min));
|
||||||
"The lowest zoom-in level allowed by current client settings is {}." :
|
} else {
|
||||||
"The lowest supported zoom-in level is {}.",
|
IConsolePrint(CC_HELP, "The lowest supported zoom-in level is {}.", std::max(ZOOM_LVL_MIN, _settings_client.gui.zoom_min));
|
||||||
std::max(ZOOM_LVL_MIN, _settings_client.gui.zoom_min)
|
}
|
||||||
);
|
|
||||||
IConsolePrint(
|
if (_settings_client.gui.zoom_max < ZOOM_LVL_MAX) {
|
||||||
CC_HELP,
|
IConsolePrint(CC_HELP, "The highest zoom-out level allowed by current client settings is {}.", std::min(_settings_client.gui.zoom_max, ZOOM_LVL_MAX));
|
||||||
_settings_client.gui.zoom_max < ZOOM_LVL_MAX ?
|
} else {
|
||||||
"The highest zoom-out level allowed by current client settings is {}." :
|
IConsolePrint(CC_HELP, "The highest supported zoom-out level is {}.", std::min(_settings_client.gui.zoom_max, ZOOM_LVL_MAX));
|
||||||
"The highest supported zoom-out level is {}.",
|
}
|
||||||
std::min(_settings_client.gui.zoom_max, ZOOM_LVL_MAX)
|
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 2: {
|
case 2: {
|
||||||
|
|
|
@ -34,16 +34,15 @@ void IConsolePrint(TextColour colour_code, const std::string &string);
|
||||||
* @param format_string The formatting string to tell what to do with the remaining arguments.
|
* @param format_string The formatting string to tell what to do with the remaining arguments.
|
||||||
* @param first_arg The first argument to the format.
|
* @param first_arg The first argument to the format.
|
||||||
* @param other_args The other arguments to the format.
|
* @param other_args The other arguments to the format.
|
||||||
* @tparam T The type of formatting parameter.
|
|
||||||
* @tparam A The type of the first argument.
|
* @tparam A The type of the first argument.
|
||||||
* @tparam Args The types of the other arguments.
|
* @tparam Args The types of the other arguments.
|
||||||
*/
|
*/
|
||||||
template <typename T, typename A, typename ... Args>
|
template <typename A, typename ... Args>
|
||||||
inline void IConsolePrint(TextColour colour_code, const T &format, A first_arg, Args&&... other_args)
|
inline void IConsolePrint(TextColour colour_code, fmt::format_string<A, Args...> format, A first_arg, Args&&... other_args)
|
||||||
{
|
{
|
||||||
/* The separate first_arg argument is added to aid overloading.
|
/* The separate first_arg argument is added to aid overloading.
|
||||||
* Otherwise the calls that do no need formatting will still use this function. */
|
* Otherwise the calls that do no need formatting will still use this function. */
|
||||||
IConsolePrint(colour_code, fmt::format(format, first_arg, other_args...));
|
IConsolePrint(colour_code, fmt::format(format, std::forward<A>(first_arg), std::forward<Args>(other_args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parser */
|
/* Parser */
|
||||||
|
|
|
@ -1704,12 +1704,14 @@ void NetworkServer_Tick(bool send_frame)
|
||||||
case NetworkClientSocket::STATUS_ACTIVE:
|
case NetworkClientSocket::STATUS_ACTIVE:
|
||||||
if (lag > _settings_client.network.max_lag_time) {
|
if (lag > _settings_client.network.max_lag_time) {
|
||||||
/* Client did still not report in within the specified limit. */
|
/* Client did still not report in within the specified limit. */
|
||||||
IConsolePrint(CC_WARNING, cs->last_packet + std::chrono::milliseconds(lag * MILLISECONDS_PER_TICK) > std::chrono::steady_clock::now() ?
|
|
||||||
/* A packet was received in the last three game days, so the client is likely lagging behind. */
|
if (cs->last_packet + std::chrono::milliseconds(lag * MILLISECONDS_PER_TICK) > std::chrono::steady_clock::now()) {
|
||||||
"Client #{} (IP: {}) is dropped because the client's game state is more than {} ticks behind." :
|
/* A packet was received in the last three game days, so the client is likely lagging behind. */
|
||||||
/* No packet was received in the last three game days; sounds like a lost connection. */
|
IConsolePrint(CC_WARNING, "Client #{} (IP: {}) is dropped because the client's game state is more than {} ticks behind.", cs->client_id, cs->GetClientIP(), lag);
|
||||||
"Client #{} (IP: {}) is dropped because the client did not respond for more than {} ticks.",
|
} else {
|
||||||
cs->client_id, cs->GetClientIP(), lag);
|
/* No packet was received in the last three game days; sounds like a lost connection. */
|
||||||
|
IConsolePrint(CC_WARNING, "Client #{} (IP: {}) is dropped because the client did not respond for more than {} ticks.", cs->client_id, cs->GetClientIP(), lag);
|
||||||
|
}
|
||||||
cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
|
cs->SendError(NETWORK_ERROR_TIMEOUT_COMPUTER);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue