Page 1 of 1

Stripcolor umode

Posted: Thu Nov 17, 2011 11:42 pm
by cedric
Hello,

I'm developing a module that allows a user to set usermode +c, after which he won't see colors in any channel or PM.
The clients that connect to our server don't have the capability to strip colors on their side. Channelmode +S is not an option either.

I was wondering if someone could review the code that I already have.
The code is at http://pastebin.com/5BsAW4jH

I've based myself on the nocolorumode module, which only strips colors from PMs.
I copy/pasted bits from the sendto_channel_butone function in src/send.c
I'm confused about the difference between vsendto_prefix_one, sendto_prefix_one, and sendto_one.
I also don't know if it's safe to get rid of the last if statement

Code: Select all

if (sentalongm[(i = acptr->from->slot)] != sentalong_marking)
Any help would be appreciated :)

Edit: I already discovered that there's a problem when someone does /notice #channel message instead of a normal PRIVMSG. But I yet have to find out how to fix it :)

Re: Stripcolor umode

Posted: Fri Nov 18, 2011 8:01 pm
by cedric
I've come to understand that my current aproach won't work when using prefixes in PRIVMSG's (like PRIVMSG %#chan :text). When hooking into HOOKTYPE_CHANMSG, it's not possible to know about the prefix it's being sent to (?). It's also not possible to modify the text on a per-user basis. Some users must receive the message with the colors stripped out, other users must receive the message in it's untouched form.

There should be a hook that gets executed for every message that is soon to be received by the client. I'm currently looking into HOOKTYPE_PACKET as a last resort, but I will have to use regex replaces to modify the outgoing message in this case.
There is currently no way (that I know of) to get around this without editing src/modules/m_message.c and/or src/send.c, which belongs to the official sourcecode.

Correct me if I'm wrong, I'm not getting a full grasp on the source code yet.

Re: Stripcolor umode

Posted: Fri Nov 18, 2011 8:38 pm
by katsklaw

Re: Stripcolor umode

Posted: Fri Nov 18, 2011 8:43 pm
by cedric
I've based myself on the nocolorumode module, which only strips colors from PMs.
Unfortunately it's not that easy :/

Re: Stripcolor umode

Posted: Fri Nov 18, 2011 9:36 pm
by katsklaw
Oh sorry, I missed part. You are correct about your targets (users vs channels) and are likely correct about your hooking theories. Unfortunately I am not so familiar with Unreal's module API or I would help further.

Re: Stripcolor umode

Posted: Fri Nov 18, 2011 10:16 pm
by Syzop
cedric wrote:I've come to understand that my current aproach won't work when using prefixes in PRIVMSG's (like PRIVMSG %#chan :text). When hooking into HOOKTYPE_CHANMSG, it's not possible to know about the prefix it's being sent to (?).
Correct, this information is not passed as an argument to the callback hook.
You could get it by overriding the command, but that's pretty ugly, and in this particular case would mean you end up rewriting the entire m_message function, which is just silly.
It's also not possible to modify the text on a per-user basis. Some users must receive the message with the colors stripped out, other users must receive the message in it's untouched form.
Correct.
There should be a hook that gets executed for every message that is soon to be received by the client. I'm currently looking into HOOKTYPE_PACKET as a last resort, but I will have to use regex replaces to modify the outgoing message in this case.
There is currently no way (that I know of) to get around this without editing src/modules/m_message.c and/or src/send.c, which belongs to the official sourcecode.
Correct.
Correct me if I'm wrong, I'm not getting a full grasp on the source code yet.
I think you understood it well ;). It's just unfortunate that while the module API is pretty powerful, in your case it doesn't really provide what you want (yeah, ok, except the packet hook).

Re: Stripcolor umode

Posted: Sat Nov 19, 2011 1:31 pm
by cedric
Thank you both for your replies, I will hook into HOOKTYPE_PACKET for now.
It's probably the easiest way to accomplish my goal.
I'll submit the module when it's done (and if I get it to work :P)

A new HOOKTYPE for this particular case might be a nice addition for a future release

Re: Stripcolor umode

Posted: Sat Nov 19, 2011 11:50 pm
by cedric
Ok, I came up with a VERY, VERY basic result :P
It doesn't check whether the packet contains a NOTICE, a PRIVMSG or a PING. It calls StripControlCodes on EVERY packet, regardless of the command.

Regardless of the fact that it may be bad practice to modify the actual packet, or the module being inefficient, I don't need anything more :)
The module won't work in combination with nocolorumode.c, since they both use usermode +c.

One more thing: I have no clue what this if-statement exactly does:

Code: Select all

if((from != &me && (!IsClient(from) && IsRegistered(from))) || (to != &me && !IsClient(to))) 
It was being used in k4be's m_npircs.c, and I simply copy/pasted that.

Source: http://pastebin.com/38Rm4iRX