Page 1 of 1

Using addon UMODE constants in third party modules.

Posted: Tue Dec 06, 2016 6:41 pm
by KeMiJohN
Hi there :)

Back on the UnrealIRCd forums, after a decade in hiatus :P
(I made some posts in 2005)

I'm making a module, where I'm trying to parse the numeric UMODE values received by HOOKTYPE_UMODE_CHANGE to a string, like "+iw-s". (112 to 101)

I have no trouble using the built-in UMODE constants, like UMODE_INVISIBLE, UMODE_OPER, etc.

The problem occurs, when I want to use the UMODE constants added by modules in modules/usermodes/, like UMODE_PRIVACY, UMODE_SHOWWHOIS, etc.

I've siphoned the source for all the addon UMODE constants, and none of them, seem to be used anywhere outside the modules in which they are defined, so I'm thinking there may be a better way to do this, than having to hardcode all these constants and string values anyway.

Right now, I'm just trying to get a complete list of UMODE numeric values for debugging purposes.
These work fine:

Code: Select all

sendnotice(sptr, "i %d", UMODE_INVISIBLE);
sendnotice(sptr, "o %d", UMODE_OPER);
sendnotice(sptr, "w %d", UMODE_WALLOP);
sendnotice(sptr, "r %d", UMODE_REGNICK);
sendnotice(sptr, "s %d", UMODE_SERVNOTICE);
sendnotice(sptr, "x %d", UMODE_HIDE);
sendnotice(sptr, "z %d", UMODE_SECURE);
sendnotice(sptr, "d %d", UMODE_DEAF);
sendnotice(sptr, "H %d", UMODE_HIDEOPER);
sendnotice(sptr, "t %d", UMODE_SETHOST);
sendnotice(sptr, "I %d", UMODE_HIDLE);
Results:

Code: Select all

i 1
o 2
w 4
r 8
s 16
x 32
z 64
d 128
H 256
t 512
I 1024
These result in errors:

Code: Select all

sendnotice(sptr, "p %d", UMODE_PRIVACY);
sendnotice(sptr, "S %d", UMODE_SERVICEBOT);
sendnotice(sptr, "W %d", UMODE_SHOWWHOIS);
sendnotice(sptr, "T %d", UMODE_NOCTCP);
sendnotice(sptr, "G %d", UMODE_CENSOR);
sendnotice(sptr, "B %d", UMODE_BOT);
sendnotice(sptr, "R %d", UMODE_REGONLYMSG);
sendnotice(sptr, "q %d", UMODE_NOKICK);
Errors:

Code: Select all

testmodule.c: In function ‘user_mode’:
testmodule.c:351:28: error: ‘UMODE_PRIVACY’ undeclared (first use in this function)
   sendnotice(sptr, "p %d", UMODE_PRIVACY);
                            ^
testmodule.c:351:28: note: each undeclared identifier is reported only once for each function it appears in
testmodule.c:352:28: error: ‘UMODE_SERVICEBOT’ undeclared (first use in this function)
   sendnotice(sptr, "S %d", UMODE_SERVICEBOT);
                            ^
testmodule.c:353:28: error: ‘UMODE_SHOWWHOIS’ undeclared (first use in this function)
   sendnotice(sptr, "W %d", UMODE_SHOWWHOIS);
                            ^
testmodule.c:354:28: error: ‘UMODE_NOCTCP’ undeclared (first use in this function)
   sendnotice(sptr, "T %d", UMODE_NOCTCP);
                            ^
testmodule.c:355:28: error: ‘UMODE_CENSOR’ undeclared (first use in this function)
   sendnotice(sptr, "G %d", UMODE_CENSOR);
                            ^
testmodule.c:356:28: error: ‘UMODE_BOT’ undeclared (first use in this function)
   sendnotice(sptr, "B %d", UMODE_BOT);
                            ^
testmodule.c:357:28: error: ‘UMODE_REGONLYMSG’ undeclared (first use in this function)
   sendnotice(sptr, "R %d", UMODE_REGONLYMSG);
                            ^
testmodule.c:358:28: error: ‘UMODE_NOKICK’ undeclared (first use in this function)
   sendnotice(sptr, "q %d", UMODE_NOKICK);
                            ^
Any hints? :)

Best regards
-John

Re: Using addon UMODE constants in third party modules.

Posted: Wed Dec 07, 2016 8:18 pm
by Gottem
I went through the source and found this bit in src/s_user.c:

Code: Select all

char *get_modestr(long umodes)
I haven't screwed with UMODE hooks myself, but seems like this is what you need. =]

Re: Using addon UMODE constants in third party modules.

Posted: Thu Dec 08, 2016 6:17 pm
by KeMiJohN
Thank you very much! :)

The for loop iterating through Usermode_Table, was exactly what I was looking for.

Code: Select all

for (i = 0; i <= Usermode_highest; i++)
	Usermode_Table[i].flag
	Usermode_Table[i].mode

Re: Using addon UMODE constants in third party modules.

Posted: Fri Dec 09, 2016 3:35 pm
by Gottem
Cool, glad to be of help. =]