# HG changeset patch # User Teemu Piippo # Date 1418608918 -7200 # Node ID ee770597a2813659d345f5e2e3d500256a5bcc4c # Parent b5b5a6a96d91d6abfc75160ae8fbb213237ab57b - added support for in-game colors diff -r b5b5a6a96d91 -r ee770597a281 sources/basics.h --- a/sources/basics.h Mon Dec 15 03:09:26 2014 +0200 +++ b/sources/basics.h Mon Dec 15 04:01:58 2014 +0200 @@ -62,7 +62,7 @@ template using Function = std::function; -FUNCTION print_to_console (const String& a) -> void; +FUNCTION print_to_console (String a) -> void; FUNCTION request_exit() -> void; template inline FUNCTION diff -r b5b5a6a96d91 -r ee770597a281 sources/interface.cpp --- a/sources/interface.cpp Mon Dec 15 03:09:26 2014 +0200 +++ b/sources/interface.cpp Mon Dec 15 04:01:58 2014 +0200 @@ -60,6 +60,32 @@ static IPAddress g_address; static String g_statusBarText; +static const struct { Color color; bool bold; } g_colorCodes['v' - 'a' + 1] = +{ + { RED, true }, // a - brick + { YELLOW, true }, // b - tan + { WHITE, false }, // c - gray + { GREEN, true }, // d - light green + { YELLOW, false }, // e - brown + { YELLOW, true }, // f - gold yellow + { RED, true }, // g - bright red + { BLUE, false }, // h - dark blue + { YELLOW, false }, // i - orange + { WHITE, true }, // j - white + { YELLOW, true }, // k - fire yellow + { DEFAULT, false }, // l - untranslated + { BLACK, false }, // m - black + { BLUE, true }, // n - light blue + { YELLOW, true }, // o - cream + { GREEN, true }, // p - olive green + { GREEN, false }, // q - dark green + { RED, false }, // r - dark red + { YELLOW, false }, // s - dark brown + { MAGENTA, false }, // t - purple + { BLACK, true }, // u - dark gray + { CYAN, true }, // v - cyan +}; + // ------------------------------------------------------------------------------------------------- // static FUNCTION @@ -262,7 +288,49 @@ for (int i = start; i < end; ++i) { mvhline (y, 0, ' ', COLS); - mvprintw (y++, 0, "%s", g_output[i].chars()); + int activeColor = -1; + bool boldActive = false; + int x = 0; + + for (int j = 0; j < g_output[i].length(); ++j) + { + char ch = g_output[i][j]; + + if (ch == '\x1C' and j + 1 < g_output[i].length()) + { + if (activeColor != -1) + attroff (activeColor); + + if (boldActive) + attroff (A_BOLD); + + char colorChar = g_output[i][j + 1]; + + if (colorChar >= 'a' and colorChar <= 'v' and colorChar != 'l') + { + auto colorInfo = g_colorCodes[colorChar - 'a']; + activeColor = interface_color_pair (colorInfo.color, DEFAULT); + boldActive = colorInfo.bold; + attron (activeColor); + + if (boldActive) + attron (A_BOLD); + } + + j++; + continue; + } + + mvaddch (y, x++, g_output[i][j]); + } + + if (activeColor != -1) + attroff (activeColor); + + if (boldActive) + attroff (A_BOLD); + + ++y; } g_needRefresh = true; @@ -614,8 +682,12 @@ // ------------------------------------------------------------------------------------------------- // -FUNCTION print_to_console (const String& a) -> void +FUNCTION print_to_console (String a) -> void { + // Zandronum is retarded and SOMETIMES sends color codes as "\\c" and sometimes as "\x1C". + // Let's correct that on our end and HOPE this won't cause conflicts. + a.replace ("\\c", "\x1C"); + for (char ch : a) { if (ch == '\n') diff -r b5b5a6a96d91 -r ee770597a281 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Mon Dec 15 03:09:26 2014 +0200 +++ b/sources/network/rconsession.cpp Mon Dec 15 04:01:58 2014 +0200 @@ -144,12 +144,9 @@ break; case SVRC_SALT: - { - String salt = packet.read_string(); - m_salt = salt; - m_state = RCON_AUTHENTICATING; - send_password(); - } + m_salt = packet.read_string(); + m_state = RCON_AUTHENTICATING; + send_password(); break; case SVRC_INVALIDPASSWORD: @@ -160,9 +157,7 @@ case SVRC_MESSAGE: { String message = packet.read_string(); - if (message.ends_with ("\n")) - message.remove_from_end (1); - + message.normalize(); print ("%1\n", message); } break;