diff -r e534f2f78196 -r 21fba5183768 sources/interface.cpp --- a/sources/interface.cpp Mon Dec 15 02:03:08 2014 +0200 +++ b/sources/interface.cpp Mon Dec 15 02:15:09 2014 +0200 @@ -124,6 +124,7 @@ ::noecho(); ::refresh(); ::timeout (0); + ::use_default_colors(); g_title = format (APPNAME " %1 (%2)", full_version_string(), changeset_date_string()); for (int i = 0; i < NUM_COLORS; ++i) @@ -174,8 +175,9 @@ static FUNCTION safe_disconnect (Function afterwards) -> void { - if (RCONSession::get_session() != nullptr - and RCONSession::get_session()->state() != RCON_DISCONNECTED) + RCONSession* session = RCONSession::get_session(); + + if (session and session->state() != RCON_DISCONNECTED) { g_disconnectConfirmFunction = afterwards; set_input_state (INPUTSTATE_CONFIRM_DISCONNECTION); @@ -247,9 +249,18 @@ int end = min (g_input.length(), start + displaylength); assert (g_cursor >= start and g_cursor <= end); + String displayinput = g_input; + + // If we're inputting a password, replace it with asterisks + if (g_inputState == INPUTSTATE_PASSWORD) + { + for (char& ch : displayinput) + ch = '*'; + } + // Render the input string mvhline (LINES - 2, 0, ' ', COLS); - mvprintw (y, prompt.length() + 1, "%s", g_input.chars()); + mvprintw (y, prompt.length() + 1, "%s", displayinput.chars()); // Render the prompt attron (promptColor); @@ -258,7 +269,7 @@ // Store in memory where the cursor is now (so that we can re-draw it to position the terminal // cursor). - g_cursorChar.ch = g_cursor != 0 ? g_input[g_cursor - 1] : '\0'; + g_cursorChar.ch = g_cursor != 0 ? displayinput[g_cursor - 1] : '\0'; g_cursorChar.x = prompt.length() + (g_cursor - g_pan); g_needRefresh = true; g_needInputRender = false; @@ -366,9 +377,13 @@ if (g_inputState == INPUTSTATE_CONFIRM_DISCONNECTION) { if (ch == 'y' or ch == 'Y') + { + RCONSession::get_session()->disconnect(); g_disconnectConfirmFunction(); + } else if (ch == 'n' or ch == 'N') set_input_state (INPUTSTATE_NORMAL); + return; } @@ -553,3 +568,26 @@ g_needOutputRender = true; } + +// ------------------------------------------------------------------------------------------------- +// +FUNCTION +Interface::connect (String address, String password) -> void +{ + try + { + g_address = IPAddress::from_string (address); + } + catch (std::exception& e) + { + print (e.what()); + return; + } + + if (g_address.port == 0) + g_address.port = 10666; + + RCONSession* session = RCONSession::new_session(); + session->set_password (password); + session->connect (g_address); +}