* See: http://www.inspircd.org/wiki/index.php/Credits
*
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ * the file COPYING for details.
*
* ---------------------------------------------------
*/
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
#include "inspircd.h"
/* $ModDesc: Provides channel +S mode (strip ansi colour) */
UserStripColor *usc;
public:
- ModuleStripColor(InspIRCd* Me) : Module::Module(Me)
+ ModuleStripColor(InspIRCd* Me) : Module(Me)
{
usc = new UserStripColor(ServerInstance);
csc = new ChannelStripColor(ServerInstance);
DELETE(csc);
}
- // ANSI colour stripping based on C example by Doc (Peter Wood)
virtual void ReplaceLine(std::string &sentence)
{
- int i, a, len, remove;
- len = sentence.length();
-
- for (i = 0; i < len; i++)
- {
- remove = 0;
-
- switch (sentence[i])
+ /* refactor this completely due to SQUIT bug since the old code would strip last char and replace with \0 --peavey */
+ int seq = 0;
+ std::string::iterator i,safei;
+ for (i = sentence.begin(); i != sentence.end(); ++i)
+ {
+ if ((*i == 3))
+ seq = 1;
+ else if (seq && ( (*i >= '0') && (*i <= '9') || (*i == ',') ) )
{
- case 2:
- case 15:
- case 22:
- case 21:
- case 31:
- remove++;
- break;
-
- case 3:
- remove = 1;
-
- if (isdigit(sentence[i + remove]))
- remove++;
-
- if (isdigit(sentence[i + remove]))
- remove++;
-
- if (sentence[i + remove] == ',')
- {
- remove += 2;
-
- if (isdigit(sentence[i + remove]))
- remove++;
- }
- break;
+ seq++;
+ if ( (seq <= 4) && (*i == ',') )
+ seq = 1;
+ else if (seq > 3)
+ seq = 0;
}
-
- if (remove != 0)
+ else
+ seq = 0;
+
+ if (seq || ((*i == 2) || (*i == 15) || (*i == 22) || (*i == 21) || (*i == 31)))
{
- len -= remove;
-
- for (a = i; a <= len; a++)
- sentence[a] = sentence[a + remove];
- i--;
+ safei = i;
+ --i;
+ sentence.erase(safei);
}
}
}
};
-// stuff down here is the module-factory stuff. For basic modules you can ignore this.
-
-class ModuleStripColorFactory : public ModuleFactory
-{
- public:
- ModuleStripColorFactory()
- {
- }
-
- ~ModuleStripColorFactory()
- {
- }
-
- virtual Module * CreateModule(InspIRCd* Me)
- {
- return new ModuleStripColor(Me);
- }
-
-};
-
-
-extern "C" void * init_module( void )
-{
- return new ModuleStripColorFactory;
-}
-
+MODULE_INIT(ModuleStripColor)