/[cvs]/botnetop.mod/botcmds.c
ViewVC logotype

Contents of /botnetop.mod/botcmds.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (show annotations) (download) (as text)
Sun Jul 14 09:28:44 2002 UTC (16 years, 5 months ago) by sup
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +112 -115 lines
File MIME type: text/x-chdr
Updated to 1.1.0-gamma

1 /*
2 * botcmds.c -- part of botnetop.mod
3 *
4 * $Id$
5 */
6 /*
7 * Copyright (C) 2000, 2001, 2002 Teemu Hjelt <temex@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 static int bnop_reqop(char *chname, char *need)
25 {
26 int i, bufsize;
27 char *buf = NULL;
28 tand_t *bot = NULL;
29 struct chanset_t *chan = NULL;
30 struct userrec *u = NULL;
31
32 if (!(chan = findchan_by_dname(chname)))
33 return 0;
34 if (!strcmp(need, "op")) {
35 bufsize = strlen(chan->dname) + 7 + 1;
36 buf = (char *) nmalloc(bufsize);
37 if (buf == NULL)
38 return 0;
39 egg_snprintf(buf, bufsize, "reqops %s", chan->dname);
40 for (bot = tandbot; bot != NULL; bot = bot->next) {
41 if (!(u = get_user_by_handle(userlist, bot->bot)))
42 continue;
43 if (handisop(bot->bot, chan) && matchattr(u, "o|o", chan->dname) && ((i = nextbot(bot->bot)) >= 0))
44 botnet_send_zapf(i, botnetnick, bot->bot, buf);
45 }
46 nfree(buf);
47 } else
48 bnop_letmein(chan, need);
49
50 return 0;
51 }
52
53 static void bnop_askbot(char *hand, char *chname)
54 {
55 int i, bufsize;
56 char *buf = NULL;
57 struct chanset_t *chan = NULL;
58 struct userrec *u = NULL;
59 struct request_t *r = NULL;
60
61 if ((r = find_request(hand, chname)))
62 del_request(r);
63 if (!(chan = findchan_by_dname(chname)) || !(u = get_user_by_handle(userlist, hand)))
64 return;
65 if (!ismember(chan, botname) || !isop(botname, chan))
66 return;
67 if ((i = nextbot(hand)) >= 0) {
68 bufsize = strlen(chan->dname) + strlen(botname) + 13 + 1;
69 buf = (char *) nmalloc(bufsize);
70 if (buf == NULL)
71 return;
72 egg_snprintf(buf, bufsize, "doyawantops %s %s", chan->dname, botname);
73 botnet_send_zapf(i, botnetnick, hand, buf);
74 nfree(buf);
75 }
76 }
77
78 static void bnop_invite(struct chanset_t *chan, char *nick, char *hand, char *uhost)
79 {
80 if (bop_icheck && uhost[0]) {
81 if (!find_who(nick)) {
82 if (!add_who(nick, chan->dname, hand, uhost))
83 return;
84 }
85 dprintf(DP_MODE, "USERHOST %s\n", nick); /* Need to use DP_MODE queue here because
86 eggdrop can't stack USERHOST properly. */
87 } else {
88 dprintf(DP_SERVER, "INVITE %s %s\n", nick, chan->dname);
89 if (bop_log >= 1) {
90 if (egg_strcasecmp(nick, hand))
91 putlog(LOG_MISC, "*", "botnetop.mod " BOTNETOP_INVITED2, hand, nick, chan->dname);
92 else
93 putlog(LOG_MISC, "*", "botnetop.mod " BOTNETOP_INVITED, hand, chan->dname);
94 }
95 }
96 }
97
98 static void bnop_letmein(struct chanset_t *chan, char *need)
99 {
100 int i, bufsize, bots = 0;
101 char *buf = NULL, log[LOGSIZE];
102 tand_t *bot = NULL;
103 struct userrec *u = NULL;
104
105 if (ismember(chan, botname))
106 return;
107
108 bufsize = strlen(chan->dname) + strlen(botname) + strlen(botname) + strlen(botuserhost) + 13 + 1;
109 buf = (char *) nmalloc(bufsize);
110 if (buf == NULL)
111 return;
112
113 if (!strcmp(need, "key")) {
114 egg_snprintf(buf, bufsize, "wantkey %s %s %s", chan->dname, botname,
115 strchr("~+-^=", botuserhost[0]) ? botuserhost + 1 : botuserhost);
116 strncpyz(log, "botnetop.mod: " BOTNETOP_REQKEY, sizeof log);
117 } else if (!strcmp(need, "invite")) {
118 egg_snprintf(buf, bufsize, "wantinvite %s %s %s", chan->dname, botname,
119 strchr("~+-^=", botuserhost[0]) ? botuserhost + 1 : botuserhost);
120 strncpyz(log, "botnetop.mod: " BOTNETOP_REQINVITE, sizeof log);
121 } else if (!strcmp(need, "limit")) {
122 egg_snprintf(buf, bufsize, "wantlimit %s %s %s", chan->dname, botname,
123 strchr("~+-^=", botuserhost[0]) ? botuserhost + 1 : botuserhost);
124 strncpyz(log, "botnetop.mod: " BOTNETOP_REQLIMIT, sizeof log);
125 } else if (!strcmp(need, "unban")) {
126 egg_snprintf(buf, bufsize, "wantunban %s %s %s!%s", chan->dname,
127 botname, botname, botuserhost);
128 strncpyz(log, "botnetop.mod: " BOTNETOP_REQUNBAN, sizeof log);
129 }
130
131 if (buf[0]) {
132 for (bot = tandbot; bot != NULL; bot = bot->next) {
133 if (!(u = get_user_by_handle(userlist, bot->bot)))
134 continue;
135 if (!matchattr(u, "b|-", chan->dname) || !matchattr(u, "o|o", chan->dname))
136 continue;
137 if ((i = nextbot(bot->bot)) >= 0) {
138 botnet_send_zapf(i, botnetnick, bot->bot, buf);
139 bots++;
140 }
141 }
142 nfree(buf);
143 if ((bop_log >= 1) && (bots > 0))
144 putlog(LOG_MISC, "*", log, chan->dname, bots, bots == 1 ? "" : "s");
145 }
146 }
147
148 static cmd_t botnetop_need[] =
149 {
150 {"*", "", (Function) bnop_reqop, "bop_reqop"},
151 {0, 0, 0, 0}
152 };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23