Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: How to join a Service into a channel?  (Read 4955 times)

0 Members and 1 Guest are viewing this topic.

black-drag0n

  • Guest
How to join a Service into a channel?
« on: May 11, 2006, 03:52:31 PM »

hey whats up?
i've wrote a little module for the Anope1.7.13....
the functions i wrote runs... but i want the Service to join a the specified channel (supportchan) when the command "/msg Serv set support on" is used and part the channel on command "/msg Serv set support off".
thanks for ya help ;)

Code: [Select]

#include "module.h"
#define AUTHOR "black-drag0n"
#define VERSION "1.00"

  /* -----------------------------------------------------------
   * Name  : new_module
   * Author: black-drag0n <support@megafumi-source.de>
   * Date  : 11.05.2006
   * -----------------------------------------------------------
   * Functions: my_privmsgA, my_nickA, support_check,
   *            timeout_version_user, CheckOffDefList,
   *            CheckCustomDefList
   * Limitations: None Known.
   * Tested: Unreal(3.2)
   * -----------------------------------------------------------
   * This version has been tested on Unreal.
   *
   *  This modules has 18 configurable options, please read
   *  The comments
   *
   *  
   *  Please read the comments by each one.
   *
   * -----------------------------------------------------------
   */
 
/* ---------------------------------------------------------------------- */
/* START OF CONFIGURATION BLOCK - please read the comments :)             */
/* ---------------------------------------------------------------------- */
#define supportchan "#channel"

#define WOWServHELP1 "%s is a Service for me ;)", s_WowServ
#define WOWServHELP2 "help 2"
#define WOWServHELP3 "help 3"
#define WOWServHELP4 "help 4"
#define WOWServHELP5 "help 5"
#define WOWServHELP6 "Dir Stehen Folgende Befehle zur Auswahl:"
#define WOWServHELP7 "----------------------------------------"
#define WOWServHELP8 "2SYNTAX:2 /msg %s <your supporttext>"
#define WOWServHELP9 "Sendet eine Supportanfrage."
#define WOWServHELP10 "2SYNTAX:2 /msg %s BUG <Bugbeschreibung>"
#define WOWServHELP11 "Sendet einen Neuen Bug ein. Bitte Achtet darauf eine Genaue Beschreibung abzugeben."

#define SUPPORT_ACCEPTED "Deine Supportanfrage wurde Abgesandt."
#define SUPPORT_DISABLED "Die Befehele sind Vorübergehend nich verwendbar"
#define SUPPORT_REJECTED_TOOSMALL "Deine Nachricht ist zu kurz. Bitte vergewisser dich das du MINDESTENS 3 Wörter hast."

char *s_WowServ = "Serv";  /* Nickname - NICKLEN character MAXIMUM */
                                     /* (see your IRCd's protocall responce for this) */
char *s_WowServHOST = "Serv.Service";  /* HostMask: 64 character MAXIMUM */
char *s_WowServREALNAME = "Anope Service";         /* Realname 30 character MAXIMUM */

/* ---------------------------------------------------------------------- */
/* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING         */
/* ---------------------------------------------------------------------- */

int dontsaysupport=3;
int send_wowserv_help(User *u);
void send_wowserv_fhelp(User *u);
int my_privmsgC(char *source, int ac, char **av);
int my_supportserv_killrejoin(char *source, int ac, char **av);
int support_check(User * u, char *buf);
//char supportchan[50];

int AnopeInit(int argc, char **argv)
{
    Message *msg = NULL;
    int status;
    msg = createMessage("NOTICE", my_privmsgC);
    status = moduleAddMessage(msg, MOD_HEAD);
    msg = createMessage("PRIVMSG", my_privmsgC);
    status = moduleAddMessage(msg, MOD_HEAD);
    msg = createMessage("KILL", my_supportserv_killrejoin);
    status = moduleAddMessage(msg, MOD_HEAD);
    if (status == MOD_ERR_OK) {
        NEWNICK( s_WowServ,  s_WowServ,  s_WowServHOST,  s_WowServREALNAME, "+oS", 1);
    }
    moduleAddAuthor(AUTHOR);
    moduleAddVersion(VERSION);
    alog("[ircd_wowtserv] Modul wurde geladen und ist nun Aktiv.");
    alog("[ircd_wowserv] Für mehr Informationen nutze /msg %s HELP",  s_WowServ);
    #ifdef IRC_HYBRID
    send_cmd(NULL, "SJOIN %ld :@%s", time(NULL), s_WowServ);
    send_cmd(whosends(ci), "MODE +ovs %s %lu", s_WowServ, time(NULL));
    #endif
    return MOD_CONT;
}
void AnopeFini(void)
{
    send_cmd( s_WowServ, "QUIT :Module Unloaded!");
}
int my_privmsgC(char *source, int ac, char **msg)
{
    User *u;
    char *s;
    if (ac != 2) {
        return MOD_CONT;
    }
    if (!(u = finduser(source))) {
        return MOD_CONT;
    }
    if (*msg[0] == '#') {
        return MOD_CONT;
    }
    /* Channel message */
    s = strchr(msg[0], '@');
    if (s) {
        *s++ = 0;
        if (stricmp(s, ServerName) != 0) {
            return MOD_CONT;
        }
    }
    if ((stricmp(msg[0], s_WowServ)) == 0) {
        support_check(u, msg[1]);
        return  MOD_CONT;
    } else {        
    }
}

/*****************************************************************************/

int support_check(User * u, char *buf)
{
    char *FirstWord;
    char *SecondWord;
    char *buffer;  
    FirstWord = strtok(buf," ");
    SecondWord = strtok(NULL," ");
    buffer = strtok(NULL,"");
 
  if (!is_oper(u)) {
      if (dontsaysupport == 1) {
          return MOD_CONT;
      }
  }
 
  if (!FirstWord) {
     return  MOD_CONT;
  }
  if (stricmp(FirstWord, "1PING") == 0) {
     if (!SecondWord) {
         SecondWord = "1";
     }
     notice(s_WowServ, u->nick, "1PING %s", SecondWord);
     return   MOD_CONT;
  }
  if (skeleton) {
      notice_lang(s_WowServ, u, SERVICE_OFFLINE, s_WowServ);
      return  MOD_CONT;
  }
  if ((stricmp(FirstWord, "HELP") == 0) && (!SecondWord)) {
      if (dontsaysupport != 1) {
          send_wowserv_help(u);
      }
      return MOD_CONT;
  }
  if (!is_oper(u)) {
      if (dontsaysupport == 2) {
          notice(s_WowServ, u->nick, SUPPORT_DISABLED);
          return MOD_CONT;
      }
  }
  if (is_services_admin(u)) {
     if (stricmp(FirstWord, "SET") == 0) {
          if (!SecondWord) {
              notice(s_WowServ, u->nick, "Nutze 2/msg %s HELP2 für weitere Informationen.",  s_WowServ);
              return  MOD_CONT;
          }
          if (stricmp(SecondWord, "SUPPORT") == 0) {
     if (!buffer) {
                  notice(s_WowServ, u->nick, "Nutze 2/msg %s HELP2 für weitere Informationen.",  s_WowServ);
                  return  MOD_CONT;
              }

              if (stricmp(buffer, "ON") == 0) {
                  dontsaysupport = 3;
                  notice( s_WowServ, u->nick, "SupportService wurde Aktiviert");
                  wallops( s_WowServ, "%s set %s Support ON", u->nick, s_WowServ);
                  return  MOD_CONT;
              }
              if (stricmp(buffer, "OFF") == 0) {
                  dontsaysupport = 2;
                  notice( s_WowServ, u->nick, "SupportService wurde deaktiviert");
                   wallops( s_WowServ, "%s set %s Support OFF", u->nick,  s_WowServ);
                 return  MOD_CONT;
              }
              if (stricmp(buffer, "SILENT") == 0) {
                  dontsaysupport = 1;
                  notice( s_WowServ, u->nick, "Support wurde deaktiviert [SILENT]");
                  wallops( s_WowServ, "%s set %s Support OFF [SILENT]", u->nick, s_WowServ);
                  return  MOD_CONT;
              }
          return  MOD_CONT;
          }
     }
  }
  if (!SecondWord) {
          if (dontsaysupport == 2) {
            notice(s_WowServ, u->nick, SUPPORT_REJECTED_TOOSMALL);
            return  MOD_CONT;
        }

  }
  if (!buffer) {
       notice(s_WowServ, u->nick, SUPPORT_REJECTED_TOOSMALL);
       return  MOD_CONT;
  }  
  if (buffer) {
        if (dontsaysupport == 3) {
        if (stricmp(FirstWord, "BUG") == 0) {
          send_cmd(s_WowServ, "PRIVMSG %s New Bug from:[%s!%s@%s] Description: %s %s", supportchan, u->nick, u->username,
                                                                    u->host, SecondWord, buffer);
          notice(s_WowServ, u->nick, SUPPORT_ACCEPTED);
          return  MOD_CONT;
        }
        else {
        send_cmd(s_WowServ, "PRIVMSG %s Support from:[%s!%s@%s] Description: %s %s %s", supportchan, u->nick, u->username,
                                                                    u->host, FirstWord, SecondWord, buffer);
          notice(s_WowServ, u->nick, SUPPORT_ACCEPTED);
          return  MOD_CONT;
        }
      }
  }
  return  MOD_CONT;
}



int send_wowserv_help(User *u)
{
    if (is_oper(u)) {
              notice( s_WowServ, u->nick, "-----------------------------------------------------------------------");
              notice( s_WowServ, u->nick, "%s ist ein Service für den WoW Support.", s_WowServ);
              notice( s_WowServ, u->nick, "Services Admins haben zugriff auf folgenede einstellungen -");
              notice( s_WowServ, u->nick, "/msg %s SET SUPPORT [on|off|silent]", s_WowServ);
              notice( s_WowServ, u->nick, "Bei ON wird %s die Supportanfragen in %s posten.", s_WowServ, supportchan);
              notice( s_WowServ, u->nick, "OFF Schaltet den Dienst ab.");
              notice( s_WowServ, u->nick, "Bei SILENT wird jeder Nicht-Oper von %s ignoriert.", s_WowServ);
              notice( s_WowServ, u->nick, " ");
              notice( s_WowServ, u->nick, "Hilfebeschreibung für normale User:");
              notice( s_WowServ, u->nick, " ");
              send_wowserv_fhelp(u);
              return MOD_CONT;
    }
    send_wowserv_fhelp(u);
    return MOD_CONT;
 /*}*/
}

void send_wowserv_fhelp(User *u)
{
  if (!is_oper(u)) {
      notice(s_WowServ, u->nick, "-----------------------------------------------------------------------");
  }
  #ifdef WOWServHELP1
  notice(s_WowServ, u->nick, WOWServHELP1);
  #endif
  #ifdef WOWServHELP2
  notice(s_WowServ, u->nick, WOWServHELP2);
  #endif
  #ifdef WOWServHELP3
  notice(s_WowServ, u->nick, WOWServHELP3);
  #endif
  #ifdef WOWServHELP4
  notice(s_WowServ, u->nick, WOWServHELP4);
  #endif
  #ifdef WOWServHELP5
  notice(s_WowServ, u->nick, WOWServHELP5);
  #endif
  #ifdef WOWServHELP6
  notice(s_WowServ, u->nick, WOWServHELP6);
  #endif
  #ifdef WOWServHELP7
  notice(s_WowServ, u->nick, WOWServHELP7);
  #endif
  #ifdef WOWServHELP8
  notice(s_WowServ, u->nick, WOWServHELP8);
  #endif
  #ifdef WOWServHELP9
  notice(s_WowServ, u->nick, WOWServHELP9);
  #endif
  #ifdef WOWServHELP10
  notice(s_WowServ, u->nick, WOWServHELP10);
  #endif
  #ifdef WOWServHELP11
  notice(s_WowServ, u->nick, WOWServHELP11);
  #endif
  notice(s_WowServ, u->nick, "-----------------------------------------------------------------------");
  return;
}

int my_supportserv_killrejoin(char *source, int ac, char **av)
{

  if (ac != 2) {
      return MOD_STOP;
  }
  if (stricmp(av[0], s_WowServ) == 0) {
      alog("[ircd_wowserv] %s wurde GEKILLt, Reconnectning.", s_WowServ);
      NEWNICK( s_WowServ,  s_WowServ,  s_WowServHOST,  s_WowServREALNAME, "+oS", 1);
      return MOD_STOP;
  }
  return MOD_CONT;
}


The basic scructure is from the ircd_reportserv module...

i hope someone can help me ;)

[Bearbeitet am 11-5-2006 von black-drag0n]

[Bearbeitet am 11-5-2006 von black-drag0n]

[Bearbeitet am 11-5-2006 von black-drag0n]

[Bearbeitet am 11-5-2006 von black-drag0n]

[Bearbeitet am 11-5-2006 von black-drag0n]
Logged

Tom65789

  • Anope User
  • Offline Offline
  • Posts: 343
    • www.t65789.co.uk
(No subject)
« Reply #1 on: May 11, 2006, 04:23:19 PM »

the original code that SRG wrote uses strtok which shouldnt really NEVER be used in a module as it is used in the core and to make it join just add anope_cmd_join(s_WowServ, supportchan, time(NULL)); into the bit where you set ON and to part add anope_cmd_part(s_WowServ, supportchan,  "Parting %s", supportchan); to the OFF part. but the code you copied and pasted and adding the edits from an outdated code wasnt the best thing to do. It would be a better idea to re-write your own that is more upto date.

[Edited on 11-5-2006 by Tom65789]

black-drag0n

  • Guest
(No subject)
« Reply #2 on: May 11, 2006, 04:57:27 PM »

thanks for ya help ;)

maybe it exists a better way... but i am only a newbe ;)
I still have to learn many thinks xD

thankz
Logged

black-drag0n

  • Guest
(No subject)
« Reply #3 on: May 11, 2006, 05:34:54 PM »

Now i found a "little" bug...

after a few minutes (about 10 minutes) every other service is lagging :(
i cannot use /msg operserv .... (no reply)
every service do not anwsering :((((

Somebody knows the problem?
What i've did wrong?
Logged

Tom65789

  • Anope User
  • Offline Offline
  • Posts: 343
    • www.t65789.co.uk
(No subject)
« Reply #4 on: May 11, 2006, 09:01:14 PM »

well with it using strtok is a very bad idea and i hope this isnt been used on a production network. i'll run it through a debugger and see what happens.

EDIT: well i only just compiled it and already got errors.

z:\anope1\src\modules\ircd_wowserv.c(118) : warning C4715: 'my_privmsgC' : not all control paths return a value

 and yep they locked up as i loaded it.

and this is what i got:

[May 11 21:08:01 2006] Trying to load module [ircd_wowserv]
[May 11 21:08:01 2006] Runtime module location: .\modules\runtime\ircd_wowserv.dll.a01788
[May 11 21:08:01 2006] debug: existing msg: (0x00344D40), new msg (0x0077E710)
[May 11 21:08:01 2006] Displaying message list for NOTICE
[May 11 21:08:01 2006] 1: 0x0077E710
[May 11 21:08:01 2006] 2: 0x00344D40
[May 11 21:08:01 2006] end
[May 11 21:08:01 2006] debug: existing msg: (0x00344E48), new msg (0x0077E748)
[May 11 21:08:01 2006] Displaying message list for PRIVMSG
[May 11 21:08:01 2006] 1: 0x0077E748
[May 11 21:08:01 2006] 2: 0x00344E48
[May 11 21:08:01 2006] end
[May 11 21:08:01 2006] debug: existing msg: (0x00344BE0), new msg (0x0077E780)
[May 11 21:08:01 2006] Displaying message list for KILL
[May 11 21:08:01 2006] 1: 0x0077E780
[May 11 21:08:01 2006] 2: 0x00344BE0
[May 11 21:08:01 2006] end

i would suggest using up to date code and re-writing this.

one error here:


Code: [Select]

if ((stricmp(msg[0], s_WowServ)) == 0) {
      support_check(u, msg[1]);
      return MOD_CONT;
      } else {
}


else? else what? thats why they are not responding and also a few other things.

[Edited on 11-5-2006 by Tom65789]

black-drag0n

  • Guest
(No subject)
« Reply #5 on: May 11, 2006, 10:52:53 PM »

when i want to compile in shell it shows me the following error:
 control reaches end of non-void function

but what does it mean?
or how can i make it better?

please help me xD

*edit:
I've found the error...

Code: [Select]

int my_privmsgC(char *source, int ac, char **msg)
{
    User *u;
    char *s;
    if (ac != 2) {
        return MOD_CONT;
    }
    if (!(u = finduser(source))) {
        return MOD_CONT;
    }
    if (*msg[0] == '#') {
        return MOD_CONT;
    }
    /* Channel message */
    s = strchr(msg[0], '@');
    if (s) {
        *s++ = 0;
        if (stricmp(s, ServerName) != 0) {
            return MOD_CONT;
        }
    }
    if ((stricmp(msg[0], s_WowServ)) == 0) {
        support_check(u, msg[1]);
        return  MOD_CONT;
    }
    return MOD_CONT;
}


i have forgot the last return... no errors on compile...
thanks ;)


[Bearbeitet am 11-5-2006 von black-drag0n]
Logged

Tom65789

  • Anope User
  • Offline Offline
  • Posts: 343
    • www.t65789.co.uk
(No subject)
« Reply #6 on: May 11, 2006, 10:53:56 PM »

firstly not using an out of date code would be helpful and its basically saying its doing a function that isnt returning anything. Thats one of the reasons why they are doing what they are now.

EDIT: if i get time i'll try and write one for you but no promises because i want to get my other 2 modules written and finished first.

[Edited on 11-5-2006 by Tom65789]

black-drag0n

  • Guest
(No subject)
« Reply #7 on: May 12, 2006, 06:18:32 AM »

it would help me more ir you explain some thing ;)

you don't must wrote this module for me...
I only want to understand anope ;) thats all xD
Logged
Pages: [1]   Go Up