Sat, 09 Jan 2016 17:20:25 +0200
Added some basic IRC-like commands that can be used to do what keystrokes can do without actually using keystrokes
--- a/sources/interface.cpp Fri Jul 24 04:31:17 2015 +0300 +++ b/sources/interface.cpp Sat Jan 09 17:20:25 2016 +0200 @@ -827,7 +827,13 @@ break; case INPUTSTATE_NORMAL: - if (Session.send_command (current_input())) + if (current_input()[0] == '/') + { + handle_command(current_input()); + InputHistory.insert (0, ""); + NeedInputRender = true; + } + else if (Session.send_command (current_input())) { InputHistory.insert (0, ""); NeedInputRender = true; @@ -1027,4 +1033,51 @@ } } -END_ZFC_NAMESPACE \ No newline at end of file +// ------------------------------------------------------------------------------------------------- +// +void Interface::handle_command(const String& input) +{ + if (input[0] != '/') + return; + + StringList args = input.right(input.length() - 1).split(" "); + String command = args[0].to_lowercase(); + args.remove_at(0); + + if (command == "connect") + { + if (args.size() != 2) + print_error("Usage: /connect <address> <password>"); + else + { + IPAddress address; + + try + { + address = IPAddress::from_string(args[0]); + } + catch (std::exception& e) + { + print_error("%s\n", e.what()); + return; + } + + if (address.port == 0) + address.port = 10666; + + Session.set_password(args[1]); + Session.disconnect(); + Session.connect(CurrentAddress = address); + } + } + else if (command == "quit") + { + Session.disconnect(); + endwin(); + throw Exitception(); + } + else + print_error("Unknown command %s\n", command.chars()); +} + +END_ZFC_NAMESPACE
--- a/sources/interface.h Fri Jul 24 04:31:17 2015 +0300 +++ b/sources/interface.h Sat Jan 09 17:20:25 2016 +0200 @@ -59,6 +59,7 @@ void need_refresh(); void tab_complete (const String& part, String complete); RCONSession* get_session() { return &Session; } + void handle_command(const String& input); void vprint (const char* fmtstr, va_list args); void __cdecl print (const char* fmtstr, ...);
--- a/sources/mystring.cpp Fri Jul 24 04:31:17 2015 +0300 +++ b/sources/mystring.cpp Sat Jan 09 17:20:25 2016 +0200 @@ -166,12 +166,9 @@ if (b == -1 or b > length()) b = length(); - if (b == a) + if (b <= a) return ""; - if (b < a) - std::swap (a, b); - if (a == 0 and b == length()) return *this; @@ -185,6 +182,16 @@ // ------------------------------------------------------------------------------------------------- // +String String::right(int length) const +{ + if (length >= this->length()) + return *this; + else + return String(chars() + this->length() - length); +} + +// ------------------------------------------------------------------------------------------------- +// int String::word_position (int n) const { int count = 0; @@ -502,4 +509,4 @@ m_string = m_string.substr (a, b - a + 1); } -END_ZFC_NAMESPACE \ No newline at end of file +END_ZFC_NAMESPACE
--- a/sources/mystring.h Fri Jul 24 04:31:17 2015 +0300 +++ b/sources/mystring.h Sat Jan 09 17:20:25 2016 +0200 @@ -77,6 +77,7 @@ bool mask_against (const String &pattern) const; String md5() const; String mid (long a, long b) const; + String right (int length) const; StringList split (const String &del) const; StringList split (char del) const; const std::string& std_string() const { return m_string; }
--- a/sources/network/rconsession.cpp Fri Jul 24 04:31:17 2015 +0300 +++ b/sources/network/rconsession.cpp Sat Jan 09 17:20:25 2016 +0200 @@ -73,9 +73,7 @@ Bytestream packet; packet.write_byte (CLRC_DISCONNECT); this->send (packet); - - m_interface->print ("Disconnected from %s\n", - m_address.to_string (IPAddress::WITH_PORT).chars()); + m_interface->print ("Disconnected from %s\n", m_address.to_string (IPAddress::WITH_PORT).chars()); m_interface->update_statusbar(); } @@ -391,4 +389,4 @@ m_interface = iface; } -END_ZFC_NAMESPACE \ No newline at end of file +END_ZFC_NAMESPACE