# HG changeset patch # User Teemu Piippo # Date 1452354525 -7200 # Node ID 5900be70c619644adb212de263a318ce1230bdd7 # Parent 7b156b764d1189629f002029f636e21cac10b685# Parent ca10837a2a9ee3cba6a9ccbaba421bfa4af3a9e6 Merged with default diff -r ca10837a2a9e -r 5900be70c619 sources/coloredline.cpp --- a/sources/coloredline.cpp Sat Jan 09 17:48:28 2016 +0200 +++ b/sources/coloredline.cpp Sat Jan 09 17:48:45 2016 +0200 @@ -135,6 +135,14 @@ // ------------------------------------------------------------------------------------------------- // +void ColoredLine::add_string (const String& text) +{ + for (char a : text) + add_char (a); +} + +// ------------------------------------------------------------------------------------------------- +// void ColoredLine::set_color (Color a, bool on) { assert (a < 8); diff -r ca10837a2a9e -r 5900be70c619 sources/coloredline.h --- a/sources/coloredline.h Sat Jan 09 17:48:28 2016 +0200 +++ b/sources/coloredline.h Sat Jan 09 17:48:45 2016 +0200 @@ -69,6 +69,7 @@ const Vector& data() const { return m_data; } int length() const { return m_length; } void add_char (char ch); + void add_string (const String& msg); void finalize(); int rows (int cols) const; diff -r ca10837a2a9e -r 5900be70c619 sources/interface.cpp --- a/sources/interface.cpp Sat Jan 09 17:48:28 2016 +0200 +++ b/sources/interface.cpp Sat Jan 09 17:48:45 2016 +0200 @@ -635,10 +635,7 @@ if (CurrentInputState == INPUTSTATE_CONFIRM_DISCONNECTION) { if (ch == 'y' or ch == 'Y') - { - Session.disconnect(); - DisconnectConfirmFunction(); - } + disconnected(); else if (ch == 'n' or ch == 'N') set_input_state (INPUTSTATE_NORMAL); @@ -1035,6 +1032,14 @@ // ------------------------------------------------------------------------------------------------- // +void Interface::disconnected() +{ + Session.disconnect(); + set_input_state (INPUTSTATE_NORMAL); +} + +// ------------------------------------------------------------------------------------------------- +// void Interface::handle_command(const String& input) { if (input[0] != '/') @@ -1076,6 +1081,13 @@ endwin(); throw Exitception(); } + else if (command == "watch") + { + if (not args.is_empty()) + Session.request_watch(args); + else + print_error("No CVars to watch.\n"); + } else print_error("Unknown command %s\n", command.chars()); } diff -r ca10837a2a9e -r 5900be70c619 sources/interface.h --- a/sources/interface.h Sat Jan 09 17:48:28 2016 +0200 +++ b/sources/interface.h Sat Jan 09 17:48:45 2016 +0200 @@ -59,6 +59,7 @@ void need_refresh(); void tab_complete (const String& part, String complete); RCONSession* get_session() { return &Session; } + void disconnected(); void handle_command(const String& input); void vprint (const char* fmtstr, va_list args); @@ -110,4 +111,4 @@ int find_next_word(); }; -END_ZFC_NAMESPACE \ No newline at end of file +END_ZFC_NAMESPACE diff -r ca10837a2a9e -r 5900be70c619 sources/mystring.cpp diff -r ca10837a2a9e -r 5900be70c619 sources/mystring.h diff -r ca10837a2a9e -r 5900be70c619 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Sat Jan 09 17:48:28 2016 +0200 +++ b/sources/network/rconsession.cpp Sat Jan 09 17:48:45 2016 +0200 @@ -184,6 +184,9 @@ } m_interface->print ("End of previous messages.\n"); + + // Watch sv_hostname so that we can update the titlebar when it changes. + request_watch("sv_hostname"); break; case SVRC_UPDATE: @@ -222,6 +225,40 @@ } } break; + + case SVRC_WATCHINGCVAR: + m_interface->print ("You are now watching %s\n", packet.read_string().chars()); + m_interface->print ("Its value is: %s\n", packet.read_string().chars()); + break; + + case SVRC_ALREADYWATCHINGCVAR: + m_interface->print ("You are already watching %s\n", packet.read_string().chars()); + break; + + case SVRC_WATCHCVARNOTFOUND: + m_interface->print ("CVar %s not found\n", packet.read_string().chars()); + break; + + case SVRC_CVARCHANGED: + { + String name = packet.read_string(); + String value = packet.read_string(); + m_interface->print ("The value of CVar %s", name.chars()); + m_interface->print (" is now %s\n", value.chars()); + + // If sv_hostname changes, update the titlebar + if (name == "sv_hostname") + { + m_hostname = value; + m_interface->set_title(m_hostname); + } + } + break; + + case SVRC_YOUREDISCONNECTED: + m_interface->print ("You have been disconnected: %s", packet.read_string().chars()); + m_interface->disconnected(); + break; } } } @@ -328,8 +365,18 @@ return false; Bytestream packet; - packet.write_byte (CLRC_COMMAND); - packet.write_string (message); + + // Let's hardcode a /watch for CVar watching testing purposes + if (message.starts_with ("/watch ")) + { + request_watch(message.mid(String("/watch ").length(), -1).split(',')); + } + else + { + packet.write_byte (CLRC_COMMAND); + packet.write_string (message); + } + send (packet); bump_last_ping(); return true; @@ -389,4 +436,27 @@ m_interface = iface; } +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::request_watch (const String& cvar) +{ + StringList cvars; + cvars.append(cvar); + request_watch(cvars); +} + +// ------------------------------------------------------------------------------------------------- +// +void RCONSession::request_watch (const StringList& cvars) +{ + Bytestream packet; + packet.write_byte(CLRC_WATCHCVAR); + + for (int i = 0; i < cvars.size(); ++i) + packet.write_string(cvars[i].normalized()); + + packet.write_string(""); + send(packet); +} + END_ZFC_NAMESPACE diff -r ca10837a2a9e -r 5900be70c619 sources/network/rconsession.h --- a/sources/network/rconsession.h Sat Jan 09 17:48:28 2016 +0200 +++ b/sources/network/rconsession.h Sat Jan 09 17:48:45 2016 +0200 @@ -38,7 +38,7 @@ // enum { - RCON_PROTOCOL_VERSION = 4 + RCON_PROTOCOL_VERSION = 5 }; // ------------------------------------------------------------------------------------------------- @@ -54,6 +54,11 @@ SVRC_UPDATE, SVRC_TABCOMPLETE, SVRC_TOOMANYTABCOMPLETES, + SVRC_WATCHINGCVAR, + SVRC_ALREADYWATCHINGCVAR, + SVRC_WATCHCVARNOTFOUND, + SVRC_CVARCHANGED, + SVRC_YOUREDISCONNECTED, }; // ------------------------------------------------------------------------------------------------- @@ -66,6 +71,7 @@ CLRC_PONG, CLRC_DISCONNECT, CLRC_TABCOMPLETE, + CLRC_WATCHCVAR, }; // ------------------------------------------------------------------------------------------------- @@ -114,6 +120,8 @@ bool is_active() const; void request_tab_complete (const String& part); void set_interface (class Interface* iface); + void request_watch (const String& cvar); + void request_watch (const StringList& cvars); private: RCONSessionState m_state; @@ -130,4 +138,4 @@ class Interface* m_interface; }; -END_ZFC_NAMESPACE \ No newline at end of file +END_ZFC_NAMESPACE