Strip colors only for non-op ?

These are old archives. They are kept for historic purposes only.
Post Reply
CrazyCat
Posts: 103
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Strip colors only for non-op ?

Post by CrazyCat » Mon Jun 04, 2012 10:54 am

Hello there,

Someone ask me for a particular thing: strip colors for "simple users" (and voiced ones) and allow halfops and ops to use colors in a channel.
I think it's possible to create a particular channel mode, based on the +S mode, checking the isop/ishalfop.

Do you think I'm true ?

Thanks

Edit : another small question, which channel mode can I use ? I want a specific one, not add the functionnality to +S. "w" as White ? Or is it possible to modify +S, adding it the authorized levels ? +S [o|h|v] (so default is +S, all colors are stripped) ?

katsklaw
Official supporter
Posts: 1114
Joined: Sun Apr 18, 2004 5:06 pm

Re: Strip colors only for non-op ?

Post by katsklaw » Tue Jun 05, 2012 12:05 am

#1: Yes it's possible to have such a module.

#2: You can use any letter not already taken by the core or any 3rd party mods you are using.

CrazyCat
Posts: 103
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Re: Strip colors only for non-op ?

Post by CrazyCat » Tue Jun 05, 2012 12:57 pm

Thanks for your reply.

I've a look on different modules on the way to add a cmode, each does differently. Is there a good way, or some good practrices ?

I've tried something like this:

Code: Select all

/*
 *   IRC - Internet Relay Chat, m_restrictcolors.c
 *   (C) 2012 CrazyCat
 *
 * This module allow the +W mode on a channel
 * When activated, only halfops and ops can use
 * colors on the chan.
 * Others are stripped.
 */
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#include "proto.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif

ModuleHeader MOD_HEADER(restrictcolors)
  = {
	"m_restrictcolors",
	"1.0",
	"color stripping for non-(half)op", 
	"3.2-b8-1",
	NULL 
    };

#define CFLAG_RESTRICTCOLORS  'W'
#define CmodeDel(w)     if (w) CmodeDel(w); w = NULL
#define HookDel(w)      if (w) HookDel(w); w = NULL

Cmode_t MODE_RESTRICTCOLORS = 0L;
Cmode *ModeRestrictColors = NULL;

static ModuleInfo RestrictColorsInfo;
static Hook *CheckMsg;
static Cmode  *AddCmode(Module *module, CmodeInfo *req, Cmode_t *mode);
static ModuleInfo	*thismodinfo = NULL;

DLLFUNC char *restrictcolors_checkmsg(aClient *, aClient *, aChannel *, char *, int);

DLLFUNC int MOD_TEST(restrictcolors)(ModuleInfo *modinfo)
{
	CmodeInfo req;
	memset(&req, 0, sizeof req);
	req.paracount	= 0;
	req.flag	= CFLAG_RESTRICTCOLORS;
	ModeRestrictColors	= AddCmode(modinfo->handle, &req, &MODE_RESTRICTCOLORS);
	
	if (!ModeRestrictColors)
	{
		MOD_UNLOAD(restrictcolors)(0);
		return MOD_FAILED;
	}
	return MOD_SUCCESS;
}

DLLFUNC int MOD_INIT(restrictcolors)(ModuleInfo *modinfo)
{
	bcopy(modinfo,&RestrictColorsInfo,modinfo->size);
	CheckMsg = HookAddPCharEx(RestrictColorsInfo.handle, HOOKTYPE_CHANMSG, restrictcolors_checkmsg);
	return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(restrictcolors)(int module_load)
{
	return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(restrictcolors)(int module_unload)
{
	CmodeDel(ModeRestrictColors);
	HookDel(CheckMsg);
	return MOD_SUCCESS;
}

DLLFUNC char *restrictcolors_checkmsg(aClient *cptr, aClient *sptr, aChannel *chptr, char *text, int notice)
{
	if (IsULine(sptr) || IsServer(sptr))
		return text;

	if (chptr->mode.mode && MODE_RESTRICTCOLORS && !is_chan_op(sptr, chptr) && !is_halfop(sptr, chptr))
		return StripColors(text);

	return text;
	
}

static Cmode *AddCmode(Module *module, CmodeInfo *req, Cmode_t *mode)
{
	Cmode *cmode;

	*mode = 0;
	cmode = CmodeAdd(module, *req, mode);

#ifndef STATIC_LINKING
	if (ModuleGetError(module) != MODERR_NOERROR || !cmode)
	{
		config_error("Error adding channel mode +%c when loading module %s: %s", req->flag, MOD_HEADER(restrictcolors).name, ModuleGetErrorStr(module));
		return NULL;
	}
#else
	if (!cmode)
	{
		config_error("Error adding channel mode +%c when loading module %s", req->flag, MOD_HEADER(restrictcolors).name);
		return NULL;
	}
#endif

	return cmode;
}
I can compile and load the module, but the server crashes each time I try to set a +W mode on a chan.

katsklaw
Official supporter
Posts: 1114
Joined: Sun Apr 18, 2004 5:06 pm

Re: Strip colors only for non-op ?

Post by katsklaw » Tue Jun 05, 2012 7:08 pm

run Unreal in gdb and/or recompile with debugmode.

CrazyCat
Posts: 103
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Re: Strip colors only for non-op ?

Post by CrazyCat » Sat Jun 09, 2012 9:19 am

Finaly, I succeed !

Here's my small module.
It adds a +W channel mode. If setted, only halfops and ops can use colors.

CrazyCat
Posts: 103
Joined: Thu Apr 28, 2005 1:05 pm
Location: France
Contact:

Re: Strip colors only for non-op ?

Post by CrazyCat » Wed Jul 11, 2012 8:32 am

Hello again !

I've a small question, quite general but my need is for this module.

What's the way to add the description of the mode I created in the /quote chmodes ?

Thanks for your help !

Regards

katsklaw
Official supporter
Posts: 1114
Joined: Sun Apr 18, 2004 5:06 pm

Re: Strip colors only for non-op ?

Post by katsklaw » Tue Jul 17, 2012 1:57 pm

if you are referring to /helpops, then edit help.conf

cheiron
Posts: 74
Joined: Sun May 29, 2011 6:17 pm

Re: Strip colors only for non-op ?

Post by cheiron » Mon Jul 30, 2012 6:24 pm

I have run the new updated version of this module on deb 6 with unreal 3.2.8.1 and anope and it still triggers the unreal module m_adult and will not permit anyone to enter the room unless they have +X user mode set (which comes with m_adult)
something is triggering m_adult's module in this script..

could i have a fix asap please

Stealth
Head of Support
Posts: 2086
Joined: Tue Jun 15, 2004 8:50 pm
Location: Chino Hills, CA, US
Contact:

Re: Strip colors only for non-op ?

Post by Stealth » Sun Aug 05, 2012 10:43 pm

m_adult seems to be causing issues with many modules. I am beginning to think there is something wrong with m_adult that may be overriding or hooking an internal function in Unreal and causing conflicts with other modules. I have looked at the source code for m_adult in the past and found it is very poorly written, and poorly written modules do cause "random" conflicts.

Additionally, skimming the source for this module I do not see any common functions that could be triggering or causing a conflict with m_adult which further supports my theory about there being an issue in m_adult.

cheiron
Posts: 74
Joined: Sun May 29, 2011 6:17 pm

Re: Strip colors only for non-op ?

Post by cheiron » Mon Aug 06, 2012 3:55 pm

Captaine has not been seen since march of this year so it seems unlikey this will be resolved either.. shame as it is quite a useful module

Capitaine
Posts: 26
Joined: Mon Apr 26, 2004 6:09 pm

Re: Strip colors only for non-op ?

Post by Capitaine » Fri Aug 10, 2012 2:50 pm

Well I'm using it since years along with others modules, without problems.
And right now, I can't reproduce that behaviour.

There are no Unreal modules docs for developpers, so at times, I had just downloaded another available module, and made changes to meet my needs.

Anyway, I've made an update. See http://forums.unrealircd.com/viewtopic. ... 791#p35791
So you can check and give me your thoughts. :)

Post Reply