Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-11-18 21:54:47 +0000
committerStijn Buys <ingar@osirion.org>2012-11-18 21:54:47 +0000
commit5d959c5ba476eb0b103fe5953cca69939a6d836a (patch)
tree81015c1b3b62c0de1dcdeb9c2eda2ac67b7a74ea /src/dedicated/console.cc
parent0b54403c6ac20f2cdd1454e90e9006379f374ec0 (diff)
Log dedicated server console messages to server.log,
print version number and command line to console on startup.
Diffstat (limited to 'src/dedicated/console.cc')
-rw-r--r--src/dedicated/console.cc72
1 files changed, 55 insertions, 17 deletions
diff --git a/src/dedicated/console.cc b/src/dedicated/console.cc
index 0c05d9c..5d16848 100644
--- a/src/dedicated/console.cc
+++ b/src/dedicated/console.cc
@@ -11,12 +11,14 @@
#include <iomanip>
#include <cmath>
+#include "sys/sys.h"
#include "auxiliary/functions.h"
#include "core/application.h"
#include "core/core.h"
#include "core/commandbuffer.h"
#include "dedicated/console.h"
#include "sys/consoleinterface.h"
+#include "filesystem/filesystem.h"
#ifdef HAVE_CURSES
@@ -71,7 +73,7 @@ void Console::init()
init_pair(7, COLOR_WHITE, -1);
init_pair(8, -1, -1);
}
-#endif // HAVE_CURSES
+#endif // HAVE_CURSES
con_print << "^BInitializing console..." << std::endl;
@@ -96,28 +98,72 @@ void Console::shutdown()
server_console.draw();
endwin();
console_initialized = false;
-
- server_console.dump();
-#endif
+#endif // HAVE_CURSES
}
Console::Console()
{
+
}
Console::~Console()
{
}
-#ifdef HAVE_CURSES
-void Console::dump()
+void Console::open_log()
{
- // dump console content
- for (Queue::iterator it = log().begin(); it != log().end(); it++) {
- sys::ConsoleInterface::print((*it));
+ console_logfilename.assign(filesystem::writedir());
+ console_logfilename.append("server.log");
+
+ std::ofstream logfile;
+ logfile.open(console_logfilename.c_str(), std::ios::app);
+ if (!logfile.is_open()) {
+ std::string errfilename(console_logfilename);
+ console_logfilename.clear();
+ con_warn << "Could not open logfile " << errfilename << std::endl;
+ } else {
+ logfile.close();
+
+ // dump console content
+ for (Queue::iterator it = log().begin(); it != log().end(); it++) {
+ print((*it));
+ }
}
}
+void Console::print(const std::string & text)
+{
+#ifdef HAVE_CURSES
+ // at this point the text is already saved in the console buffering
+ // Because w're using curses, the actual printing is handled async
+ if (console_initialized && !rcon()) {
+ console_updated = true;
+ draw();
+ }
+#else
+ // use fallback print
+ sys::ConsoleInterface::print(text);
+#endif // HAVE_CURSES
+ if (!rcon() && console_logfilename.size()) {
+ std::ofstream logfile;
+ logfile.open(console_logfilename.c_str(), std::ios::app);
+ if (logfile.is_open()) {
+ int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, milliseconds = 0;
+ sys::get_localtime(year, month, day, hour, min, sec, milliseconds);
+ logfile << std::setw(4) << std::setfill('0') << year << "-"
+ << std::setw(2) << std::setfill('0') << month << "-"
+ << std::setw(2) << std::setfill('0') << day << " "
+ << std::setw(2) << std::setfill('0') << hour << ":"
+ << std::setw(2) << std::setfill('0') << min << ":"
+ << std::setw(2) << std::setfill('0') << sec << " "
+ << std::setw(2) << " "
+ << aux::text_strip(text) << std::endl;
+ logfile.close();
+ }
+ }
+}
+
+#ifdef HAVE_CURSES
void Console::resize()
{
if (!console_initialized)
@@ -129,14 +175,6 @@ void Console::resize()
draw();
}
-void Console::print(const std::string & text)
-{
- if (console_initialized && !rcon()) {
- console_updated = true;
- draw();
- }
-}
-
void Console::set_color(const char *color_code)
{
if (!has_colors())