Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-02-09 16:01:17 +0000
committerStijn Buys <ingar@osirion.org>2011-02-09 16:01:17 +0000
commita255dbc032d15a4f5024bc60baa19c45ebceecc6 (patch)
treeca5517aae243957b824767169674248c70f7b1d3 /src/sys
parent38eb51c26ab0d9dbebc974c7a21f96a429ce3098 (diff)
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.
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/consoleinterface.cc55
-rw-r--r--src/sys/consoleinterface.h12
-rw-r--r--src/sys/sys.cc4
-rw-r--r--src/sys/sys.h2
4 files changed, 69 insertions, 4 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;
diff --git a/src/sys/consoleinterface.h b/src/sys/consoleinterface.h
index a7fde2e..b2dc5d6 100644
--- a/src/sys/consoleinterface.h
+++ b/src/sys/consoleinterface.h
@@ -20,12 +20,24 @@
namespace sys
{
+/// true if console timestamps are enabled
+bool console_timestamps();
+
+/// enable or disable consle timestamps
+void set_console_timestamps(const bool timestamps);
+
/// true if ANSI colors are enabled
bool ansi();
/// enable or disable ANSI colors
void set_ansi(bool enable = true);
+#ifdef HAVE_DEBUG_MESSAGES
+
+/// enable or disable debug messages
+
+#endif
+
/* -- ConsoleBuffer ------------------------------------------------ */
typedef std::char_traits<char> Traits;
diff --git a/src/sys/sys.cc b/src/sys/sys.cc
index f4e915d..39700b9 100644
--- a/src/sys/sys.cc
+++ b/src/sys/sys.cc
@@ -180,7 +180,7 @@ void sleep(float seconds)
#endif
}
-void get_datetime(int &year, int & month, int & day, int & hours, int & minutes)
+void get_datetime(int &year, int & month, int & day, int & hours, int & minutes, int &seconds)
{
#ifndef _WIN32
struct ::tm localtime;
@@ -193,6 +193,7 @@ void get_datetime(int &year, int & month, int & day, int & hours, int & minutes)
hours = localtime.tm_hour;
minutes = localtime.tm_min;
+ seconds = localtime.tm_sec;
#else
SYSTEMTIME localtime;
::GetLocalTime(&localtime);
@@ -203,6 +204,7 @@ void get_datetime(int &year, int & month, int & day, int & hours, int & minutes)
hours = localtime.wHour;
minutes = localtime.wMinute;
+ seconds = localtime.wSecond;
#endif
}
diff --git a/src/sys/sys.h b/src/sys/sys.h
index 3d94bcb..99c9291 100644
--- a/src/sys/sys.h
+++ b/src/sys/sys.h
@@ -46,7 +46,7 @@ void sleep(float seconds);
unsigned long time();
/// get the current system date and time
-void get_datetime(int &year, int & month, int & day, int & hours, int & minutes);
+void get_datetime(int &year, int & month, int & day, int & hours, int & minutes, int &seconds);
}
#include "sys/consoleinterface.h"