Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: comparing channel name  (Read 7261 times)

0 Members and 1 Guest are viewing this topic.

Scott

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 6
comparing channel name
« on: December 14, 2010, 06:47:44 AM »

Hello i am trying to create a module which will trigger "on join"
of a certain channel.

I have hooked into the join event successfully, but now i need to check if it is the correct channel.

I have set the channel name in the services config, and am collecting that correctly within my event.

but now i am having trouble comparing av[2] to the channel name in the config.

here is my "if" statement, which is not working currently.
Code: [Select]
  if (av[2] == 'my_special_channel')

i have tried with quotes around my_special_channel
and i have tried with nothing around it.

i have also used

Code: [Select]
u = finduser(av[1]);
ci = cs_findchan(av[2]);

and tried replacing av[2] with ci
but nothing seems to be working correctly for me.

any tips would be greatly appreciated.
thank you.
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: comparing channel name
« Reply #1 on: December 14, 2010, 09:23:21 AM »

pasting the full code block would help...  ::)
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Scott

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 6
Re: comparing channel name
« Reply #2 on: December 14, 2010, 09:35:20 AM »

in services.conf
i have
SpecialChannel "#testchannel"

here is the module code
Code: [Select]
#include "module.h"
#define AUTHOR "PuNkTuReD"
#define VERSION "Special Channel v 0.1"

int handle_special_channel_join(int argc, char **argv);

int AnopeInit(int argc, char **argv)
{

EvtHook *hook;   
int status;         

hook = createEventHook(EVENT_JOIN_CHANNEL, handle_special_channel_join);
status = moduleAddEventHook(hook);
if (status != MOD_ERR_OK)
{
        alog("Error binding to event EVENT_JOIN_CHANNEL [%d]", status);
        return MOD_STOP;
}

moduleAddAuthor(AUTHOR);     
moduleAddVersion(VERSION);   
moduleSetType(THIRD);       

alog("Loaded Special Channel Module.");
return MOD_CONT;
}

int handle_special_channel_join(int argc, char **av)
{

  char *my_special_channel = NULL;
  Directive confvalues[] = {
      { "SpecialChannel", { { PARAM_STRING, PARAM_RELOAD, &my_special_channel } } }
  };

  moduleGetConfigDirective(confvalues);

User *u;
ChannelInfo *ci;

u = finduser(av[1]);
ci = cs_findchan(av[2]);

  if (av[2] == 'my_special_channel')
  {
    if (stricmp(av[0], EVENT_STOP) == 0)
    {
      alog("DEBUG: Correct event. Correct channel. %s", my_special_channel);
    }
  }

  return MOD_CONT;

}

void AnopeFini(void)
{
 alog("Unloaded Special Channel Module.");
}

any other tips, suggestions on the coding in general would also be appreciated.
Logged

Jobe

  • Contributor
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1023
    • Anope IRC Services
Re: comparing channel name
« Reply #3 on: December 14, 2010, 09:40:49 AM »

You need to use:
Code: [Select]
if (stricmp(av[2], 'my_special_channel') == 0)
Note: "stricmp()" is a case insensitive string comparison function, it will return <0 or >0 if there is a difference between the strings and 0 if they are the same (ignoring case).
« Last Edit: December 14, 2010, 09:43:19 AM by Jobe »
Logged
Your IP: ()
My IRC Status:

Come along and visit http://www.anopequotes.org/

Scott

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 6
Re: comparing channel name
« Reply #4 on: December 14, 2010, 09:49:27 AM »

after editing that one "if" statement, i crashed anope when joining said test channel.

PANIC! buffer = :irc.sassirc.com SJOIN !1D1ppZ #testchannel :@PuNkTuReD
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: comparing channel name
« Reply #5 on: December 15, 2010, 08:10:17 AM »

post your updated code...
and maybe get a backtrace, that will give you more info on where the crash is occuring...
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Scott

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 6
Re: comparing channel name
« Reply #6 on: December 15, 2010, 08:44:47 AM »

instead of using
if (stricmp(av[2], 'my_special_channel') == 0)
i have edited it to
if (stricmp(av[2], "#testchannel") == 0)
for the time being and it stopped the crash.

now ive run into problems with the anope umode command.

when compiling, i get this error.

os_specialchan.c: In function 'handle_special_channel_join':
os_specialchan.c:56: warning: passing argument 3 of 'anope_set_umode' from incompatible pointer type

i am 99% sure thats cos of my "my_special_modes" variable but am unsure how to fix it.
also, does that anope_set_umode work for adding and removing umodes?

i have been looking at other modules to see how they go about it, but its eluding me at the moment.

just to clear things up, im trying to mark users as a bot when they join a specific channel.

Code: [Select]
#include "module.h"
#define AUTHOR "PuNkTuReD"
#define VERSION "Special Channel v 0.1"

void anope_set_umode(User * user, int argc, char **argv);

int handle_special_channel_join(int argc, char **argv);

int AnopeInit(int argc, char **argv)
{

EvtHook *hook;   
int status;         

hook = createEventHook(EVENT_JOIN_CHANNEL, handle_special_channel_join);
status = moduleAddEventHook(hook);
if (status != MOD_ERR_OK)
{
        alog("Error binding to event EVENT_JOIN_CHANNEL [%d]", status);
        return MOD_STOP;
}

moduleAddAuthor(AUTHOR);     
moduleAddVersion(VERSION);   
moduleSetType(THIRD);       

alog("Loaded Special Channel Module.");
return MOD_CONT;
}

int handle_special_channel_join(int argc, char **av)
{

  char *my_special_channel = NULL;
  char *my_special_modes = NULL;

  Directive confvalues1[] = {
      { "SpecialChannel", { { PARAM_STRING, PARAM_RELOAD, &my_special_channel } } }
  };
  Directive confvalues2[] = {
      { "SpecialModes", { { PARAM_STRING, PARAM_RELOAD, &my_special_modes } } }
  };

  moduleGetConfigDirective(confvalues1);
  moduleGetConfigDirective(confvalues2);

User *user;
user = finduser(av[1]);

  if (stricmp(av[2], "#testchannel") == 0)
  {
    if (stricmp(av[0], EVENT_STOP) == 0)
    {
      alog("\002JOIN:\002 %s joined %s", user, my_special_channel);
      alog("\002UMODE:\002 %s is now marked with the mode: %s", user, my_special_modes);
      anope_set_umode(user, 1, my_special_modes);
      return MOD_CONT;
    }
  }

  return MOD_CONT;

}

void AnopeFini(void)
{
 alog("Unloaded Special Channel Module.");
}

/* EOF */
« Last Edit: December 15, 2010, 08:49:22 AM by Scott »
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: comparing channel name
« Reply #7 on: December 15, 2010, 02:59:13 PM »

my_special_channel is a variable name so why on earth would you use 'my_special_channel'...  ???

anope_set_umode is not meant for setting modes on users.. it s meant for updating internal mode tracking, not sending any changes to the ircd. use common_svsmode() instead..
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Scott

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 6
Re: comparing channel name
« Reply #8 on: December 15, 2010, 03:16:50 PM »

I was using my_special_channel in the "if" statement because it was a suggestion by jobe.
thank you, i will look into the common_svsmode command.
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: comparing channel name
« Reply #9 on: December 15, 2010, 03:59:26 PM »

I was using my_special_channel in the "if" statement because it was a suggestion by jobe.
If jobe suggested you jump off a cliff, would you do it?  ::)

variables shouldn't be quoted.. my_special_channel is a variable so use
Code: [Select]
stricmp(av[2], my_special_channel)
btw, you might want to review getting variables from the conf.. for starters it s much more efficient to read it once on load and then hook to the reload command than reading it every time the function is called..  and secondly, both variables can be read in one go..
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

Scott

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 6
Re: comparing channel name
« Reply #10 on: December 15, 2010, 05:03:51 PM »

your right, i wouldn't jump off a cliff, because i know what the outcome would be.
I was stuck and tried his suggestion, simple as that.

And yes i can see how reading it once would be a better approach, thank you for the suggestion.
Logged

katsklaw

  • Supporter
  • Anope User
  • Offline Offline
  • Posts: 537
Re: comparing channel name
« Reply #11 on: December 15, 2010, 06:59:10 PM »

here is a sample load_config function reading multiple options:

Code: [Select]
void load_config(void)
{
int i;

    Directive confvalues[][1] = {
{{"AutoSync", {{PARAM_SET, PARAM_RELOAD, &AutoSync}}}},
{{"AutoSyncTime", {{PARAM_TIME, PARAM_RELOAD, &AutoSyncTime}}}}
    };

for (i = 0; i < 2; i++)
    moduleGetConfigDirective(confvalues[i]);

    if (AutoSync && !AutoSyncTime) {
        AutoSyncTime = dotime("24h");
    }

    if (debug)
        alog("debug: [os_tssync] Set config vars: AutoSync=%d AutoSyncTime=%d", AutoSync, AutoSyncTime);
}
Logged
Pages: [1]   Go Up