Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/consoleinterface.cc')
-rw-r--r--src/sys/consoleinterface.cc55
1 files changed, 53 insertions, 2 deletions
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 <iomanip>
#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;