diff options
Diffstat (limited to 'src/dedicated')
-rw-r--r-- | src/dedicated/console.cc | 107 | ||||
-rw-r--r-- | src/dedicated/console.h | 20 | ||||
-rw-r--r-- | src/dedicated/dedicated.cc | 25 | ||||
-rw-r--r-- | src/dedicated/dedicated.h | 12 |
4 files changed, 85 insertions, 79 deletions
diff --git a/src/dedicated/console.cc b/src/dedicated/console.cc index 5b7d92f..2c4c0da 100644 --- a/src/dedicated/console.cc +++ b/src/dedicated/console.cc @@ -22,7 +22,8 @@ #include <curses.h> #endif -namespace dedicated { +namespace dedicated +{ bool console_initialized = false; bool console_updated = false; @@ -43,19 +44,19 @@ Console *console() void Console::init() { #ifdef HAVE_CURSES - stdwin = initscr(); // initialize the ncurses window - cbreak(); // disable input line buffering - noecho(); // don't show typed characters - keypad(stdwin, TRUE); // enable special keys - nodelay(stdwin, TRUE); // non-blocking input - curs_set(1); // enable cursor + stdwin = initscr(); // initialize the ncurses window + cbreak(); // disable input line buffering + noecho(); // don't show typed characters + keypad(stdwin, TRUE); // enable special keys + nodelay(stdwin, TRUE); // non-blocking input + curs_set(1); // enable cursor if (has_colors() == TRUE) { start_color(); // this is ncurses-specific use_default_colors(); // COLOR_PAIR(0) is terminal default - init_pair(1, COLOR_RED, -1); + init_pair(1, COLOR_RED, -1); init_pair(2, COLOR_GREEN, -1); init_pair(3, COLOR_YELLOW, -1); init_pair(4, COLOR_BLUE, -1); @@ -69,10 +70,10 @@ void Console::init() con_print << "^BInitializing console..." << std::endl; #ifdef HAVE_CURSES - server_console.history.clear(); - server_console.history.push_back(""); - server_console.history_pos = server_console.history.rbegin(); - server_console.input_pos = 0; + server_console.history.clear(); + server_console.history.push_back(""); + server_console.history_pos = server_console.history.rbegin(); + server_console.input_pos = 0; server_console.console_scroll = 0; server_console.draw(); #endif // HAVE_CURSES @@ -105,7 +106,7 @@ Console::~Console() #ifdef HAVE_CURSES void Console::dump() { - // dump console content + // dump console content for (Queue::iterator it = log().begin(); it != log().end(); it++) { sys::ConsoleInterface::print((*it)); } @@ -115,11 +116,11 @@ void Console::resize() { if (!console_initialized) return; - + endwin(); refresh(); - draw(); + draw(); } void Console::print(const std::string & text) @@ -142,7 +143,7 @@ void Console::set_color(const char *color_code) // base colors // Default=0, Red=1, Green=2, Yellow=3, Blue=4, Cyan=5, Magenta=6, White=7 - color = *(color_code+1) - '0'; + color = *(color_code + 1) - '0'; if (color == 3 || color == 7) bold = true; else @@ -150,7 +151,7 @@ void Console::set_color(const char *color_code) } else if (aux::is_core_color_code(color_code)) { - switch (*(color_code+1)) { + switch (*(color_code + 1)) { case 'N': // normal color case 'D': // debug color color = 0; @@ -206,7 +207,7 @@ void Console::draw_status() attroff(A_BOLD); color_set(2, NULL); int minutes = (int) floorf(core::game()->time() / 60.0f); - int seconds = (int) floorf( core::game()->time() - (float) minutes* 60.0f); + int seconds = (int) floorf(core::game()->time() - (float) minutes * 60.0f); std::stringstream status; status << "time " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; mvaddnstr(0, 1, status.str().c_str(), status.str().size()); @@ -249,8 +250,8 @@ void Console::draw_text() } // new word, wrap if necessary - else if ((*c == '\n' ) || ( *c == ' ')) { - + else if ((*c == '\n') || (*c == ' ')) { + if (line_length + word_length > console_width) { if (line.size()) { lines.push_back(line); @@ -260,31 +261,31 @@ void Console::draw_text() line_length = 0; } } - + line.append(word); line_length += word_length; word.clear(); word_length = 0; wordpen = pen; - + // new line - if (*c == '\n' ) { + if (*c == '\n') { lines.push_back(line); line.clear(); line_length = 0; - // new word - } else if (*c == ' ' ) { + // new word + } else if (*c == ' ') { line += ' '; line_length++; } } // new character - else { + else { word += *c; word_length++; - + if (word_length == console_width) { if (line.size()) { lines.push_back(line); @@ -305,9 +306,9 @@ void Console::draw_text() c++; } - + } - current_line++; + current_line++; } int y = console_height - 1; @@ -339,20 +340,20 @@ void Console::draw_input() attron(A_BOLD); // draw input text mvaddstr(console_height, 0, ">"); - mvaddstr(console_height, 1, (*history_pos).c_str()); + mvaddstr(console_height, 1, (*history_pos).c_str()); // fill the remainder with spaces - for (int i=1 + (*history_pos).size(); i < console_width; i++) + for (int i = 1 + (*history_pos).size(); i < console_width; i++) addch(' '); } -void Console::draw() +void Console::draw() { - if (!console_initialized) + if (!console_initialized) return; #ifdef _WIN32 - console_width = stdwin->_maxx -1; - console_height = stdwin->_maxy -1; + console_width = stdwin->_maxx - 1; + console_height = stdwin->_maxy - 1; #else console_width = stdwin->_maxx; console_height = stdwin->_maxy; @@ -381,13 +382,13 @@ void Console::frame() while (key != ERR) { if (key == KEY_BACKSPACE || key == 8 || key == 127) { if ((*history_pos).size() && input_pos) { - (*history_pos).erase(input_pos-1, 1); + (*history_pos).erase(input_pos - 1, 1); input_pos--; input_updated = true; } break; - } else if (key == KEY_STAB || key ==9) { - core::CommandBuffer::complete( (*history_pos), input_pos); + } else if (key == KEY_STAB || key == 9) { + core::CommandBuffer::complete((*history_pos), input_pos); input_updated = true; break; } else if (key == KEY_LEFT) { @@ -396,7 +397,7 @@ void Console::frame() } input_updated = true; break; - } else if (key == KEY_RIGHT) { + } else if (key == KEY_RIGHT) { if (input_pos < (*history_pos).size()) { input_pos++; } @@ -425,38 +426,38 @@ void Console::frame() input_pos = (*history_pos).size(); input_updated = true; } - break; - } else if (key == KEY_ENTER || key == '\n') { + break; + } else if (key == KEY_ENTER || key == '\n') { if ((*history_pos).size()) { // store input into history while (history.size() >= MAXHISTOLINES) { history.pop_front(); } - + core::cmd() << (*history_pos) << std::endl; con_print << "^B>" << (*history_pos) << std::endl; (*history.rbegin()) = (*history_pos); - + history.push_back(""); history_pos = history.rbegin(); input_pos = 0; console_updated = true; } break; - } else if (key == KEY_PPAGE) { - console_scroll += scroll_offset; - if (console_scroll > log().size()) + } else if (key == KEY_PPAGE) { + console_scroll += scroll_offset; + if (console_scroll > log().size()) console_scroll = log().size(); console_updated = true; - break; - } else if (key == KEY_NPAGE) { - if (console_scroll > scroll_offset) + break; + } else if (key == KEY_NPAGE) { + if (console_scroll > scroll_offset) console_scroll -= scroll_offset; - else + else console_scroll = 0; console_updated = true; - break; - } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) { + break; + } else if ((key >= 32) && (key < 127) && ((*history_pos).size() < MAXCMDSIZE)) { if (input_pos == (*history_pos).size()) { (*history_pos) += (char)key; } else { @@ -464,7 +465,7 @@ void Console::frame() } input_pos++; input_updated = true; - } + } key = wgetch(stdwin); } diff --git a/src/dedicated/console.h b/src/dedicated/console.h index 19ea906..b0bafdb 100644 --- a/src/dedicated/console.h +++ b/src/dedicated/console.h @@ -1,7 +1,7 @@ /* dedicated/console.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_DEDICATED_CONSOLE_H__ @@ -9,9 +9,11 @@ #include "sys/consoleinterface.h" -namespace dedicated { +namespace dedicated +{ -class Console : public sys::ConsoleInterface { +class Console : public sys::ConsoleInterface +{ public: Console(); ~Console(); @@ -48,12 +50,12 @@ private: /// set ncurses drawing color void set_color(const char *color_code); - - // input history - History history; - History::reverse_iterator history_pos; - size_t input_pos; + // input history + History history; + History::reverse_iterator history_pos; + + size_t input_pos; size_t console_scroll; int console_width; diff --git a/src/dedicated/dedicated.cc b/src/dedicated/dedicated.cc index 43c636e..6812d63 100644 --- a/src/dedicated/dedicated.cc +++ b/src/dedicated/dedicated.cc @@ -1,7 +1,7 @@ /* dedicated/dedicated.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ #include <iostream> @@ -14,13 +14,14 @@ #include "dedicated/console.h" #include "dedicated/dedicated.h" -namespace dedicated { +namespace dedicated +{ void run(int count, char **arguments) { std::cout << core::name() << " " << core::version() << std::endl; - for (int i =0; i < count; i++) + for (int i = 0; i < count; i++) std::cout << arguments[i] << " "; std::cout << std::endl; @@ -38,7 +39,7 @@ void Dedicated::init(int count, char **arguments) core::Cvar::set("sv_dedicated", "1", core::Cvar::ReadOnly); - core::Application::init(count, arguments); + core::Application::init(count, arguments); Console::init(); @@ -59,7 +60,7 @@ void Dedicated::run() core::Timer timer; timer.mark(); - while(connected()) { + while (connected()) { frame(timer.timestamp()); #ifdef HAVE_CURSES console()->frame(); @@ -67,28 +68,28 @@ void Dedicated::run() } } -void Dedicated::shutdown() +void Dedicated::shutdown() { con_print << "^BShutting down dedicated server..." << std::endl; float ratio = 0; if (core::Stats::network_uncompressed_bytes_sent > 0) ratio = 100.0f - floorf((float)core::Stats::network_bytes_sent / - (float) core::Stats::network_uncompressed_bytes_sent * 100.0f); + (float) core::Stats::network_uncompressed_bytes_sent * 100.0f); int minutes = (int) floorf(time() / 60.0f); - int seconds = (int) floorf(time() - (float) minutes* 60.0f); - + int seconds = (int) floorf(time() - (float) minutes * 60.0f); + con_debug << "Statistics:" << std::endl; con_debug << " uptime " << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds << std::endl; con_debug << " bytes sent " << std::setfill(' ') << std::setw(6) << core::Stats::network_bytes_sent / 1024 << " Kb" << std::endl; con_debug << " bytes received " << std::setw(6) << core::Stats::network_bytes_received / 1024 << " Kb" << std::endl; con_debug << " compression " << std::setw(6) << ratio << " %" << std::endl; - + core::Application::shutdown(); Console::shutdown(); - + quit(0); } diff --git a/src/dedicated/dedicated.h b/src/dedicated/dedicated.h index f458895..d90b3b6 100644 --- a/src/dedicated/dedicated.h +++ b/src/dedicated/dedicated.h @@ -1,7 +1,7 @@ /* dedicated/dedicated.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ #ifndef __INCLUDED_DEDICATED_H__ @@ -10,13 +10,15 @@ #include "core/application.h" /// contains classes and functions to run the dedicated server -namespace dedicated { +namespace dedicated +{ /// run the dedicated server void run(int count, char **arguments); - + /// server application implementation -class Dedicated : public core::Application { +class Dedicated : public core::Application +{ public: /// initialize the server Application virtual void init(int count, char **arguments); |