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
parent0b54403c6ac20f2cdd1454e90e9006379f374ec0 (diff)
Log dedicated server console messages to server.log,
print version number and command line to console on startup.
-rw-r--r--src/client/client.cc10
-rw-r--r--src/dedicated/console.cc72
-rw-r--r--src/dedicated/console.h23
-rw-r--r--src/dedicated/dedicated.cc14
-rw-r--r--src/game/game.cc4
5 files changed, 85 insertions, 38 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index fd6a597..4d40e78 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -43,11 +43,11 @@ Client *client()
void run(int count, char **arguments)
{
- std::cout << core::name() << " " << core::version() << std::endl;
-
- for (int i = 0; i < count; i++)
- std::cout << arguments[i] << " ";
- std::cout << std::endl;
+ con_print << " command line ";
+ for (int i = 0; i < count; i++) {
+ con_print << arguments[i] << " ";
+ }
+ con_print << std::endl;
app.init(count, arguments);
app.run();
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())
diff --git a/src/dedicated/console.h b/src/dedicated/console.h
index b0bafdb..2b00c05 100644
--- a/src/dedicated/console.h
+++ b/src/dedicated/console.h
@@ -18,6 +18,9 @@ public:
Console();
~Console();
+ /// dump console content to cout
+ void open_log();
+
/// initialize the server console
static void init();
/// shutdown the server console
@@ -40,11 +43,10 @@ protected:
void draw_text();
/// draw the console input (ncurses)
void draw_input();
- /// dump console content to cout
- void dump();
- /// print one line of text (do nothing)
+#endif
+ /// print one line of text
virtual void print(const std::string & text);
-
+#ifdef HAVE_CURSES
private:
typedef std::deque<std::string> History;
@@ -52,15 +54,16 @@ private:
void set_color(const char *color_code);
// input history
- History history;
- History::reverse_iterator history_pos;
+ History history;
+ History::reverse_iterator history_pos;
- size_t input_pos;
- size_t console_scroll;
+ size_t input_pos;
+ size_t console_scroll;
- int console_width;
- int console_height;
+ int console_width;
+ int console_height;
#endif
+ std::string console_logfilename;
};
Console *console();
diff --git a/src/dedicated/dedicated.cc b/src/dedicated/dedicated.cc
index 63a1f43..adaba15 100644
--- a/src/dedicated/dedicated.cc
+++ b/src/dedicated/dedicated.cc
@@ -18,11 +18,12 @@ namespace dedicated
void run(int count, char **arguments)
{
- std::cout << core::name() << " " << core::version() << std::endl;
-
- for (int i = 0; i < count; i++)
- std::cout << arguments[i] << " ";
- std::cout << std::endl;
+
+ con_print << " command line ";
+ for (int i = 0; i < count; i++) {
+ con_print << arguments[i] << " ";
+ }
+ con_print << std::endl;
Dedicated app;
app.init(count, arguments);
@@ -41,6 +42,9 @@ void Dedicated::init(int count, char **arguments)
core::Cvar::set("sv_dedicated", "1", core::Cvar::ReadOnly);
core::Application::init(count, arguments);
+
+ // start logging
+ console()->open_log();
// the command line is in the buffer, execute it
core::CommandBuffer::exec();
diff --git a/src/game/game.cc b/src/game/game.cc
index b7c15db..c863582 100644
--- a/src/game/game.cc
+++ b/src/game/game.cc
@@ -4,7 +4,7 @@
the terms of the GNU General Public License version 2
*/
-
+#include "core/core.h"
#include "core/loader.h"
#include "game/game.h"
#include "game/base/game.h"
@@ -15,6 +15,8 @@
/// register game modules
void register_modules(bool register_noninteractive_modules)
{
+ con_print << "^F" << core::name() << " " << core::version() << std::endl;
+
con_print << "^BRegistering game modules..." << std::endl;
// interactive modules