Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added color codes to /rules

  • Loading branch information...
commit f02c029012eabeacacd9b20edc5172d21ad7046a 1 parent 8fb1b91
Justin Crawford authored May 16, 2012
4  include/inspircd.h
@@ -455,6 +455,10 @@ class CoreExport InspIRCd
455 455
 	 */
456 456
 	bool ProcessedMotdEscapes;
457 457
 
  458
+	/** Holds whether the RULES has been parsed for color codes
  459
+	*/
  460
+	bool ProcessedRulesEscapes;
  461
+
458 462
 	/** Get the current time
459 463
 	 * Because this only calls time() once every time around the mainloop,
460 464
 	 * it is much faster than calling time() directly.
1  src/commands/cmd_rehash.cpp
@@ -95,6 +95,7 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
95 95
 
96 96
 		ServerInstance->DoGarbageCollect();
97 97
 		ServerInstance->ProcessedMotdEscapes = false; // Reprocess our motd file --Justasic
  98
+		ServerInstance->ProcessedRulesEscapes = false; // Reprocess our rules file --Justasic
98 99
 		ServerInstance->PendingRehash = new ConfigReaderThread(user->uuid);
99 100
 		ServerInstance->Threads->Submit(ServerInstance->PendingRehash);
100 101
 
62  src/commands/cmd_rules.cpp
@@ -46,6 +46,61 @@ class CommandRules : public Command
46 46
 	}
47 47
 };
48 48
 
  49
+/*
  50
+ * Replace all color codes from the special[] array to actual
  51
+ * color code chars using C++ style escape sequences. You
  52
+ * can append other chars to replace if you like (such as %U
  53
+ * being underline). -- Justasic
  54
+ */
  55
+void ProcessColors(ConfigFileCache::iterator &file)
  56
+{
  57
+  static struct special_chars
  58
+  {
  59
+    std::string character;
  60
+    std::string replace;
  61
+    special_chars(const std::string &c, const std::string &r) : character(c), replace(r) { }
  62
+  }
  63
+  
  64
+  special[] = {
  65
+    special_chars("\\002", "\002"),  // Bold
  66
+    special_chars("\\037", "\037"),  // underline
  67
+    special_chars("\\003", "\003"),  // Color
  68
+    special_chars("\\0017", "\017"), // Stop colors
  69
+    special_chars("\\u", "\037"),    // Alias for underline
  70
+    special_chars("\\b", "\002"),    // Alias for Bold
  71
+    special_chars("\\x", "\017"),    // Alias for stop
  72
+    special_chars("\\c", "\003"),    // Alias for color
  73
+    special_chars("", "")
  74
+  };
  75
+  
  76
+  for(file_cache::iterator it = file->second.begin(); it != file->second.end(); it++)
  77
+  {
  78
+    std::string ret = *it;
  79
+    for(int i = 0; special[i].character.empty() == false; ++i)
  80
+    {
  81
+      std::string::size_type pos = ret.find(special[i].character);
  82
+      if(pos != std::string::npos && ret[pos-1] == '\\' && ret[pos] == '\\')
  83
+	continue; // Skip double slashes.
  84
+	
  85
+	// Replace all our characters in the array
  86
+	while(pos != std::string::npos)
  87
+	{
  88
+	  ret = ret.substr(0, pos) + special[i].replace + ret.substr(pos + special[i].character.size());
  89
+	  pos = ret.find(special[i].character, pos + special[i].replace.size());
  90
+	}
  91
+    }
  92
+    
  93
+    // Replace double slashes with a single slash before we return
  94
+    std::string::size_type pos = ret.find("\\\\");
  95
+    while(pos != std::string::npos)
  96
+    {
  97
+      ret = ret.substr(0, pos) + "\\" + ret.substr(pos + 2);
  98
+      pos = ret.find("\\\\", pos + 1);
  99
+    }
  100
+    *it = ret;
  101
+  }
  102
+}
  103
+
49 104
 CmdResult CommandRules::Handle (const std::vector<std::string>& parameters, User *user)
50 105
 {
51 106
 	if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
@@ -66,6 +121,13 @@ CmdResult CommandRules::Handle (const std::vector<std::string>& parameters, User
66 121
 			ServerInstance->Config->ServerName.c_str(), ERR_NORULES, user->nick.c_str());
67 122
 		return CMD_SUCCESS;
68 123
 	}
  124
+
  125
+	if(!ServerInstance->ProcessedRulesEscapes)
  126
+	{
  127
+		ProcessColors(rules);
  128
+		ServerInstance->ProcessedRulesEscapes = true;
  129
+	}
  130
+
69 131
 	user->SendText(":%s %03d %s :%s server rules:", ServerInstance->Config->ServerName.c_str(),
70 132
 		RPL_RULESTART, user->nick.c_str(), ServerInstance->Config->ServerName.c_str());
71 133
 

0 notes on commit f02c029

Please sign in to comment.
Something went wrong with that request. Please try again.