Anope IRC Services  Version 1.8
ircd_catserv.c
Go to the documentation of this file.
1 
9 #include "module.h"
10 #include "catserv_messages.h"
11 
12 #define AUTHOR "Anope"
13 #define VERSION VERSION_STRING
14 
15 int my_privmsg(char *source, int ac, char **av);
16 
17 void addClient(char *nick, char *realname);
18 void delClient(void);
19 void catserv(User * u, char *buf);
20 
21 char *s_CatServ = "CatServ";
22 
23 int AnopeInit(int argc, char **argv)
24 {
25  Message *msg = NULL;
26  int status;
27  if (UseTokens) {
28  msg = createMessage("!", my_privmsg);
29  } else {
30  msg = createMessage("PRIVMSG", my_privmsg);
31  }
32  status = moduleAddMessage(msg, MOD_HEAD);
33  if (status == MOD_ERR_OK) {
34  addClient(s_CatServ, "meow!");
36  }
39  alog("ircd_catserv.so: loaded, message status [%d]", status);
40  return MOD_CONT;
41 }
42 
43 void AnopeFini(void)
44 {
45  delClient();
46 }
47 
48 int my_privmsg(char *source, int ac, char **av)
49 {
50  User *u;
51  Uid *ud = NULL;
52  char *s;
53 
54  /* First, some basic checks */
55  if (ac != 2)
56  return MOD_CONT; /* bleh */
57  if (ircd->ts6)
58  u = find_byuid(source); // If this is a ts6 ircd, find the user by uid
59  if (!u && !(u = finduser(source))) { // If user isn't found and we cant find them by nick, return
60  return MOD_CONT;
61  } /* non-user source */
62  if (*av[0] == '#') {
63  return MOD_CONT;
64  }
65  /* Channel message */
66  /* we should prolly honour the ignore list here, but i cba for this... */
67  s = strchr(av[0], '@');
68  if (s) {
69  *s++ = 0;
70  if (stricmp(s, ServerName) != 0)
71  return MOD_CONT;
72  }
73  if (ircd->ts6)
74  ud = find_uid(s_CatServ); // Find CatServs UID
75  if (stricmp(av[0], s_CatServ) == 0 || (ud && strcmp(av[0], ud->uid) == 0)) { /* If the nick or the uid matches its for us */
76  catserv(u, av[1]);
77  return MOD_STOP;
78  } else { /* ok it isnt us, let the old code have it */
79  return MOD_CONT;
80  }
81 }
82 
83 void addClient(char *nick, char *realname)
84 {
85  anope_cmd_bot_nick(nick, "catserv", "meow.meow.land", realname, "+");
86 }
87 
88 void delClient(void)
89 {
90  anope_cmd_quit(s_CatServ, "QUIT :Module Unloaded!");
91 }
92 
93 /*****************************************************************************/
94 /* Main CatServ routine. */
95 void catserv(User * u, char *buf)
96 {
97  char *cmd, *s;
98 
99  cmd = strtok(buf, " ");
100 
101  if (!cmd) {
102  return;
103  } else if (stricmp(cmd, "\1PING") == 0) {
104  if (!(s = strtok(NULL, "")))
105  s = "\1";
106  notice(s_CatServ, u->nick, "\1PING %s", s);
107  } else if (skeleton) {
108  notice_lang(s_CatServ, u, SERVICE_OFFLINE, s_CatServ);
109  } else {
111  }
112 }
113 
int my_privmsg(char *source, int ac, char **av)
Definition: ircd_catserv.c:48
E Uid * find_uid(const char *nick)
Definition: users.c:453
#define AUTHOR
Definition: ircd_catserv.c:12
void addMessageList(void)
void delClient(void)
Definition: ircd_catserv.c:88
char nick[NICKMAX]
Definition: services.h:875
int AnopeInit(int argc, char **argv)
Definition: ircd_catserv.c:23
E IRCDVar * ircd
Definition: extern.h:39
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
E void notice(char *source, char *dest, const char *fmt,...)
Definition: send.c:274
E User * find_byuid(const char *uid)
Definition: users.c:378
MDE Message * createMessage(const char *name, int(*func)(char *source, int ac, char **av))
Definition: modules.c:1470
char * uid
Definition: services.h:419
void catserv(User *u, char *buf)
Definition: ircd_catserv.c:95
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
void AnopeFini(void)
Definition: ircd_catserv.c:43
#define MOD_STOP
Definition: modules.h:53
void addClient(char *nick, char *realname)
Definition: ircd_catserv.c:83
E User * finduser(const char *nick)
Definition: users.c:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
CommandHash * Catserv_cmdTable[MAX_CMD_HASH]
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_ERR_OK
Definition: modules.h:71
#define MOD_CONT
Definition: modules.h:54
#define VERSION
Definition: ircd_catserv.c:13
MDE int moduleAddMessage(Message *m, int pos)
Definition: modules.c:1612
E int UseTokens
Definition: extern.h:360
char * s_CatServ
Definition: ircd_catserv.c:21
E int skeleton
Definition: extern.h:778
Definition: services.h:416
E char * ServerName
Definition: extern.h:274
int ts6
Definition: services.h:366
MDE void mod_run_cmd(char *service, User *u, CommandHash *cmdTable[], const char *cmd)
Definition: commands.c:67
#define MOD_HEAD
Definition: module.h:12
E void anope_cmd_bot_nick(char *nick, char *user, char *host, char *real, char *modes)
Definition: ircd.c:224
E void anope_cmd_quit(char *source, const char *fmt,...)
Definition: ircd.c:334