Yay colors

Mon, 04 May 2015 18:16:05 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 04 May 2015 18:16:05 +0300
changeset 70
0e947b487b18
parent 69
eb4c25284a19
child 71
4f7c2c944637

Yay colors

sources/basics.h file | annotate | diff | comparison | revisions
sources/colors.h file | annotate | diff | comparison | revisions
sources/format.h file | annotate | diff | comparison | revisions
sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
--- a/sources/basics.h	Mon May 04 15:51:03 2015 +0300
+++ b/sources/basics.h	Mon May 04 18:16:05 2015 +0300
@@ -64,6 +64,23 @@
 	NUM_COLORS
 };
 
+#define TEXTCOLOR_Escape "\x1C"
+#define TEXTCOLOR_Black			TEXTCOLOR_Escape "M"
+#define TEXTCOLOR_Gray			TEXTCOLOR_Escape "U"
+#define TEXTCOLOR_Silver		TEXTCOLOR_Escape "C"
+#define TEXTCOLOR_White			TEXTCOLOR_Escape "J"
+#define TEXTCOLOR_Red			TEXTCOLOR_Escape "R"
+#define TEXTCOLOR_BrightRed		TEXTCOLOR_Escape "G"
+#define TEXTCOLOR_Green			TEXTCOLOR_Escape "Q"
+#define TEXTCOLOR_BrightGreen	TEXTCOLOR_Escape "D"
+#define TEXTCOLOR_Yellow		TEXTCOLOR_Escape "K"
+#define TEXTCOLOR_BrightYellow	TEXTCOLOR_Escape "F"
+#define TEXTCOLOR_Blue			TEXTCOLOR_Escape "H"
+#define TEXTCOLOR_BrightBlue	TEXTCOLOR_Escape "N"
+#define TEXTCOLOR_Magenta		TEXTCOLOR_Escape "T"
+#define TEXTCOLOR_BrightCyan	TEXTCOLOR_Escape "V"
+#define TEXTCOLOR_Reset			TEXTCOLOR_Escape "-"
+
 // -------------------------------------------------------------------------------------------------
 //
 FUNCTION print_to_console (String a) -> void;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/colors.h	Mon May 04 18:16:05 2015 +0300
@@ -0,0 +1,1 @@
+#pragma once
\ No newline at end of file
--- a/sources/format.h	Mon May 04 15:51:03 2015 +0300
+++ b/sources/format.h	Mon May 04 18:16:05 2015 +0300
@@ -213,3 +213,23 @@
 {
 	print_to_console (format (fmtstr, args...));
 }
+
+// -------------------------------------------------------------------------------------------------
+//
+// Prints the formatting result as a warning to the console
+//
+template<typename... argtypes>
+void print_warning (const String& fmtstr, const argtypes&... args)
+{
+	print_to_console (TEXTCOLOR_BrightYellow "-!- " + format (fmtstr, args...) + TEXTCOLOR_Reset);
+}
+
+// -------------------------------------------------------------------------------------------------
+//
+// Prints the formatting result as a warning to the console
+//
+template<typename... argtypes>
+void print_error (const String& fmtstr, const argtypes&... args)
+{
+	print_to_console (TEXTCOLOR_BrightRed "!!! " + format (fmtstr, args...) + TEXTCOLOR_Reset);
+}
\ No newline at end of file
--- a/sources/network/rconsession.cpp	Mon May 04 15:51:03 2015 +0300
+++ b/sources/network/rconsession.cpp	Mon May 04 18:16:05 2015 +0300
@@ -108,12 +108,12 @@
 			switch (ServerResponse (header))
 			{
 			case SVRC_OLDPROTOCOL:
-				print ("Your RCON client is using outdated protocol.\n");
+				print_error ("Your RCON client is using outdated protocol.\n");
 				m_state = RCON_DISCONNECTED;
 				break;
 
 			case SVRC_BANNED:
-				print ("You have been banned from the server.\n");
+				print_error ("You have been banned from the server.\n");
 				m_state = RCON_DISCONNECTED;
 				break;
 
@@ -124,7 +124,7 @@
 				break;
 
 			case SVRC_INVALIDPASSWORD:
-				print ("Password incorrect.\n");
+				print_error ("Login failed.\n");
 				m_state = RCON_DISCONNECTED;
 				break;
 
@@ -166,21 +166,23 @@
 	}
 	catch (std::exception& e)
 	{
-		print ("error while reading packet: %1\n", e.what());
+		print_warning ("Couldn't process packet: %1\n", e.what());
 	}
 }
 
 METHOD
 RCONSession::process_server_updates (Bytestream& packet) -> void
 {
-	switch (RCONUpdateType (packet.read_byte()))
+	int header = packet.read_byte();
+
+	switch (RCONUpdateType (header))
 	{
 	case SVRCU_PLAYERDATA:
 		{
 			StringList players;
 
 			for (int i = packet.read_byte(); i > 0; --i)
-				players << packet.read_string();
+				players.append (packet.read_string());
 
 			Interface::set_player_names (players);
 		}
@@ -195,6 +197,10 @@
 		m_level = packet.read_string();
 		Interface::update_statusbar();
 		break;
+
+	default:
+		print_warning ("Unknown server update type: %d\n", header);
+		break;
 	}
 }
 

mercurial