Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Help SimpleServ  (Read 3979 times)

0 Members and 1 Guest are viewing this topic.

Dmitry

  • Guest
Help SimpleServ
« on: June 12, 2006, 06:22:11 PM »

Hello there!!!
I need help. I whant write service(SimpleServ) but i don't know how. May be somebody give me source code SimpleServ ;)
Example:
/msg SimpleServ hi
SimpeServ hello world!

[Edited on 12-6-2006 by Dmitry]
Logged

Trystan Scott Lee

  • Contributor
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 343
(No subject)
« Reply #1 on: June 12, 2006, 11:30:54 PM »

Anope includes catserv which will show you how to do a simple command
Logged
my God my tourniquet, return to me salvation

n00bie

  • Anope User
  • Offline Offline
  • Gender: Male
  • Posts: 411
(No subject)
« Reply #2 on: June 15, 2006, 01:51:36 PM »

filename: ircd_catserv.c
Code: [Select]

/**
 * Simple module to load up a client called CatServ and process commands for it
 * This module is an example, and has no useful purpose!
 *
 * Please visit http://modules.anope.org for useful modules!
 *
 **/
//More examples: anope-1.x.x/src/modules/demos

#include "module.h"
#define AUTHOR "Anope"
#define VERSION "$Id: ircd_catserv.c 953 2006-01-14 11:36:29Z certus $"

int my_privmsg(char *source, int ac, char **av);
int do_hi(User * u);
int do_meow(User * u);
int do_purr(User * u);
int do_help(User * u);

CommandHash *Catserv_cmdTable[MAX_CMD_HASH];
void addMessageList(void);
void addClient(char *nick, char *realname);
void delClient(void);
void catserv(User * u, char *buf);
char *s_CatServ = "CatServ";

int AnopeInit(int argc, char **argv)
{
    Message *msg = NULL;
    int status;
#ifdef IRC_UNREAL32
    if (UseTokens) {
     msg = createMessage("!", my_privmsg);
    } else {
     msg = createMessage("PRIVMSG", my_privmsg);
    }
#else
    msg = createMessage("PRIVMSG", my_privmsg);
#endif
    status = moduleAddMessage(msg, MOD_HEAD);
    if (status == MOD_ERR_OK) {
        addClient(s_CatServ, "meow!");
        addMessageList();
    }
    moduleAddAuthor(AUTHOR);
    moduleAddVersion(VERSION);
    if (logchan) {
send_cmd(s_CatServ, "JOIN %s", LogChannel);
    }
    alog("[%s] ircd_catserv.so: loaded, message status [%d]", s_CatServ, status);
    return MOD_CONT;
}

void addMessageList(void)
{
    Command *c;
    c = createCommand("hi", do_hi, NULL, -1, -1, -1, -1, -1);
    moduleAddCommand(Catserv_cmdTable, c, MOD_UNIQUE);
    c = createCommand("meow", do_meow, NULL, -1, -1, -1, -1, -1);
    moduleAddCommand(Catserv_cmdTable, c, MOD_UNIQUE);
    c = createCommand("purr", do_purr, NULL, -1, -1, -1, -1, -1);
    moduleAddCommand(Catserv_cmdTable, c, MOD_UNIQUE);
    c = createCommand("help", do_help, NULL, -1, -1, -1, -1, -1);
    moduleAddCommand(Catserv_cmdTable, c, MOD_UNIQUE);
}

void AnopeFini(void)
{
    delClient();
}

int my_privmsg(char *source, int ac, char **av)
{
    User *u;
    char *s;
    /* First, some basic checks */
    if (ac != 2)
        return MOD_CONT;        /* bleh */
    if (!(u = finduser(source))) {
        return MOD_CONT;
    }                           /* non-user source */
    if (*av[0] == '#') {
        return MOD_CONT;
    }
    /* Channel message */
    /* we should prolly honour the ignore list here, but i cba for this... */
    s = strchr(av[0], '@');
    if (s) {
        *s++ = 0;
        if (stricmp(s, ServerName) != 0)
            return MOD_CONT;
    }
    if ((stricmp(av[0], s_CatServ)) == 0) {     /* its for US! */
        catserv(u, av[1]);
        return MOD_STOP;
    } else {                    /* ok it isnt us, let the old code have it */
        return MOD_CONT;
    }
}
void addClient(char *nick, char *realname)
{
    anope_cmd_bot_nick(nick, "catserv", "meow.meow.land", realname, "+BS");
}

void delClient(void)
{
    anope_cmd_quit(s_CatServ, "QUIT :Module Unloaded!");
}
/* Main CatServ routine. */
void catserv(User * u, char *buf)
{
    char *cmd, *s;
    cmd = strtok(buf, " ");
    if (!cmd) {
        return;
    } else if (stricmp(cmd, "\1PING") == 0) {
        if (!(s = strtok(NULL, "")))
            s = "\1";
        notice(s_CatServ, u->nick, "\1PING %s", s);
    } else if (skeleton) {
        notice_lang(s_CatServ, u, SERVICE_OFFLINE, s_CatServ);
    } else {
        mod_run_cmd(s_CatServ, u, Catserv_cmdTable, cmd);
    }
}
int do_hi(User * u) {
notice(s_CatServ, u->nick, "Hello World!");
return MOD_STOP;
}
int do_meow(User * u) {
notice(s_CatServ, u->nick, "MEOW! MEOW! Gimme milk %s", u->nick);
return MOD_STOP;
}
int do_purr(User * u) {
    notice(s_CatServ, u->nick, "PURR! Dirty Rat");
    return MOD_STOP;
}
int do_help(User * u) {
notice(s_CatServ, u->nick, "Syntax: /msg %s hi|meow|purr", s_CatServ);
notice(s_CatServ, u->nick, "Help message goes here.");
return MOD_CONT;
}
/* EOF */

[Edited on 8-7-2006 by n00bie]
Logged
I am always doing things that which I cannot do, in order that I may learn how to do it.
Pages: [1]   Go Up