# HG changeset patch # User Teemu Piippo # Date 1418602509 -7200 # Node ID 21fba5183768fec1926c19c4918fea0454236a8e # Parent e534f2f781967a90e8cc24ee164262010a7d48bf - added a simple command-line interface (you can now supply host and password on the command-line) - the password is now masked with asterisks when being input 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); +} diff -r e534f2f78196 -r 21fba5183768 sources/interface.h --- a/sources/interface.h Mon Dec 15 02:03:08 2014 +0200 +++ b/sources/interface.h Mon Dec 15 02:15:09 2014 +0200 @@ -39,4 +39,5 @@ FUNCTION render_full() -> void; FUNCTION set_title (const String& message) -> void; FUNCTION update_statusbar() -> void; + FUNCTION connect (String address, String password) -> void; }; diff -r e534f2f78196 -r 21fba5183768 sources/main.cpp --- a/sources/main.cpp Mon Dec 15 02:03:08 2014 +0200 +++ b/sources/main.cpp Mon Dec 15 02:15:09 2014 +0200 @@ -43,8 +43,18 @@ main (int argc, char* argv[]) -> int { HUFFMAN_Construct(); + + if (argc != 1 and argc != 3) + { + fprintf (stderr, "usage: %s\nusage: %s
\n", argv[0], argv[0]); + return EXIT_FAILURE; + } + Interface::initialize(); + if (argc == 3) + Interface::connect (argv[1], argv[2]); + try { for (;;)