23#include "3rdparty/fmt/chrono.h"
39int _debug_driver_level;
44int _debug_sprite_level;
45int _debug_oldloader_level;
47int _debug_fontcache_level;
48int _debug_script_level;
50int _debug_gamelog_level;
51int _debug_desync_level;
52int _debug_console_level;
54int _debug_random_level;
58 std::string_view name;
62#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
63static const std::initializer_list<DebugLevel> _debug_levels{
70 DEBUG_LEVEL(oldloader),
72 DEBUG_LEVEL(fontcache),
91 for (
const auto &debug_level : _debug_levels) {
93 fmt::format_to(output_iterator,
"List of debug facility names:\n");
95 fmt::format_to(output_iterator,
", ");
97 fmt::format_to(output_iterator,
"{}", debug_level.name);
101 fmt::format_to(output_iterator,
"\n\n");
111void DebugPrint(std::string_view category,
int level, std::string &&message)
113 if (category ==
"desync" && level != 0) {
115 if (!f.has_value())
return;
120 }
else if (category ==
"random") {
122 if (!f.has_value())
return;
124 fmt::print(*f,
"{}\n", message);
128 fmt::print(stderr,
"{}dbg: [{}:{}] {}\n",
GetLogPrefix(
true), category, level, message);
150 std::map<std::string_view, int> new_levels;
154 if (level.has_value()) {
155 for (
const auto &debug_level : _debug_levels) {
156 new_levels[debug_level.name] = *level;
160 static const std::string_view lowercase_letters{
"abcdefghijklmnopqrstuvwxyz"};
161 static const std::string_view lowercase_letters_and_digits{
"abcdefghijklmnopqrstuvwxyz0123456789"};
170 auto it = std::ranges::find(_debug_levels, key, &DebugLevel::name);
171 if (it == std::end(_debug_levels)) {
172 error_func(fmt::format(
"Unknown debug level '{}'", key));
180 if (!level.has_value()) {
181 error_func(fmt::format(
"Level for '{}' must be a valid integer.", key));
185 new_levels[it->name] = *level;
189 for (
const auto &debug_level : _debug_levels) {
190 const auto &nl = new_levels.find(debug_level.name);
191 if (nl != new_levels.end()) {
192 *debug_level.level = nl->second;
205 for (
const auto &debug_level : _debug_levels) {
206 if (!result.empty()) result +=
", ";
207 format_append(result,
"{}={}", debug_level.name, *debug_level.level);
222 std::string log_prefix;
224 log_prefix = fmt::format(
"[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(
nullptr)));
Class for handling the server side of the game connection.
static Pool::IterateWrapperFiltered< ServerNetworkAdminSocketHandler, ServerNetworkAdminSocketHandlerFilter > IterateActive(size_t from=0)
Returns an iterable ensemble of all active admin sockets.
Parse data from a string / buffer.
std::optional< T > TryReadIntegerBase(int base, bool clamp=false)
Try to read and parse an integer in number 'base', and then advance the reader.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
std::string_view ReadUntilCharNotIn(std::string_view chars)
Read 8-bit chars, while they are in 'chars', until they are not; and advance reader.
void SkipUntilCharIn(std::string_view chars)
Skip 8-bit chars, while they are not in 'chars', until they are.
void IConsolePrint(TextColour colour_code, const std::string &string)
Handle the printing of text entered into the console or redirected there by any other means.
Console functions used outside of the console code.
static const TextColour CC_DEBUG
Colour for debug output.
std::string GetLogPrefix(bool force)
Get the prefix for logs.
std::vector< QueuedDebugItem > _debug_remote_console_queue
Queue for debug messages to be passed to NetworkAdminConsole or IConsolePrint.
std::mutex _debug_remote_console_mutex
Mutex to guard the queue of debug messages for either NetworkAdminConsole or IConsolePrint.
void SetDebugString(std::string_view s, SetDebugStringErrorFunc error_func)
Set debugging levels by parsing the text in s.
void DebugReconsiderSendRemoteMessages()
Reconsider whether we need to send debug messages to either NetworkAdminConsole or IConsolePrint.
std::atomic< bool > _debug_remote_console
Whether we need to send data to either NetworkAdminConsole or IConsolePrint.
void DebugPrint(std::string_view category, int level, std::string &&message)
Internal function for outputting the debug line.
void DumpDebugFacilityNames(std::back_insert_iterator< std::string > &output_iterator)
Dump the available debug facility names in the help text.
std::vector< QueuedDebugItem > _debug_remote_console_queue_spare
Spare queue to swap with _debug_remote_console_queue.
std::string GetDebugString()
Print out the current debug-level.
void DebugSendRemoteMessages()
Send the queued Debug messages to either NetworkAdminConsole or IConsolePrint from the GameLoop threa...
Functions related to debugging.
std::optional< FileHandle > FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Functions for standard in/out file operations.
@ AUTOSAVE_DIR
Subdirectory of save for autosaves.
void NetworkAdminConsole(std::string_view origin, std::string_view string)
Send console to the admin network (if they did opt in for the respective update).
Server part of the admin network protocol.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
Functions related to low-level strings.
Element in the queue of debug messages that have to be passed to either NetworkAdminConsole or IConso...
std::string_view level
The used debug level.
std::string message
The actual formatted message.
@ ADMIN_UPDATE_CONSOLE
The admin would like to have console messages.
@ Automatic
The admin gets information about this when it changes.
Declarations of functions for MS windows systems.
std::mutex lock
synchronization for playback status fields