From a255dbc032d15a4f5024bc60baa19c45ebceecc6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 9 Feb 2011 16:01:17 +0000 Subject: added sv_collisionmargin Cvar and applied the value to mesh collisions, added seconds parameter to sys::get_datetime(), added con_timestamps Cvar, enabled console timestamps on the dedicated server by default. --- src/sys/consoleinterface.cc | 55 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'src/sys/consoleinterface.cc') diff --git a/src/sys/consoleinterface.cc b/src/sys/consoleinterface.cc index 45f678d..ce82047 100644 --- a/src/sys/consoleinterface.cc +++ b/src/sys/consoleinterface.cc @@ -4,6 +4,7 @@ the terms of the GNU General Public License version 2 */ +#include #include "sys/consoleinterface.h" namespace sys @@ -15,6 +16,20 @@ const size_t DEFAULT_LOGSIZE = 2048; bool con_ansicolor = false; +bool con_timestamps = false; + +bool beginofline = true; + +bool console_timestamps() +{ + return con_timestamps; +} + +void set_console_timestamps(const bool timestamps) +{ + con_timestamps = timestamps; +} + bool ansi() { return con_ansicolor; @@ -29,6 +44,13 @@ void set_ansi(const bool ansi) } } +void fallback_print_timestamp() +{ + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; + get_datetime(year, month, day, hour, min, sec); + std::cout << year << "-" << month << "-" << day << " " << hour << ":" << min << ":" << sec << " "; +} + void fallback_print(const std::string &text) { bool is_color_code = false; @@ -40,6 +62,7 @@ void fallback_print(const std::string &text) if ((*c) == '\n') { std::cout << std::endl; + beginofline = true; } else if ((*c) == '^') { @@ -109,11 +132,19 @@ void fallback_print(const std::string &text) std::cout << "\033[" << ansi_bold << ";" << ansi_color << "m"; c++; } else { + if (beginofline && con_timestamps) { + fallback_print_timestamp(); + } std::cout << *c; + beginofline = false; } } else { + if (beginofline && con_timestamps) { + fallback_print_timestamp(); + } std::cout << *c; + beginofline = false; } c++; @@ -127,9 +158,29 @@ int ConsoleBuffer::overflow(int c) if (c == Traits::eof()) return Traits::not_eof(c); - if (c == '\n') { + if (c == '\n') { if (ConsoleInterface::instance()) { - ConsoleInterface::instance()->event_text(con_buffer); + /* + * In the rcon case, the remote console will handle the timestamps + */ + if (con_timestamps && !ConsoleInterface::instance()->rcon()) { + std::ostringstream str; + int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; + get_datetime(year, month, day, hour, min, sec); + + str << "^B" + << std::setw(4) << std::setfill('0') << year << "-" + << std::setw(2) << std::setfill('0') << month << "-" + << std::setw(2) << std::setfill('0') << day << " " + << std::setw(2) << hour << ":" + << std::setw(2) << min << ":" + << std::setw(2) << sec << " " + << std::setw(2) << con_buffer; + + ConsoleInterface::instance()->event_text(str.str()); + } else { + ConsoleInterface::instance()->event_text(con_buffer); + } } else { fallback_print(con_buffer); std::cout << std::endl; -- cgit v1.2.3