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

Contents of /botnetop.mod/tclcmds.c

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


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

1 /*
2 * tclcmds.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 #ifdef ENABLE_TCL_COMMANDS
25
26 static int onchan(struct userrec *u, struct chanset_t *chan)
27 {
28 char s[UHOSTLEN];
29 memberlist *m = NULL;
30
31 for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
32 egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
33 if ((u == get_user_by_host(s)))
34 return 1;
35 }
36
37 return 0;
38 }
39
40 static int tcl_bop_reqop STDVAR
41 {
42 struct chanset_t *chan = NULL;
43
44 BADARGS(3, 3, " channel need");
45 if (!(chan = findchan_by_dname(argv[1]))) {
46 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
47 return TCL_ERROR;
48 }
49 if (strcmp(argv[2], "op") && strcmp(argv[2], "key") && strcmp(argv[2], "invite") &&
50 strcmp(argv[2], "limit") && strcmp(argv[2], "unban")) {
51 Tcl_AppendResult(irp, "unknown need type: should be one of: ",
52 "op, key, invite, limit, unban", NULL);
53 return TCL_ERROR;
54 }
55 if (!strcmp(argv[2], "op")) {
56 if (isop(botname, chan)) {
57 Tcl_AppendResult(irp, "already opped on channel: ", argv[1], NULL);
58 return TCL_ERROR;
59 }
60 } else {
61 if (ismember(chan, botname)) {
62 Tcl_AppendResult(irp, "already on channel: ", argv[1], NULL);
63 return TCL_ERROR;
64 }
65 }
66 bnop_reqop(argv[1], argv[2]);
67
68 return TCL_OK;
69 }
70
71 static int tcl_bop_askbot STDVAR
72 {
73 struct chanset_t *chan = NULL;
74 struct userrec *u = NULL;
75
76 BADARGS(3, 3, " handle channel");
77 if (!(chan = findchan_by_dname(argv[2]))) {
78 Tcl_AppendResult(irp, "invalid channel: ", argv[2], NULL);
79 return TCL_ERROR;
80 }
81 if (!(u = get_user_by_handle(userlist, argv[1])) || !(u->flags & USER_BOT)) {
82 Tcl_AppendResult(irp, "invalid user: ", argv[1], NULL);
83 return TCL_ERROR;
84 }
85 if (!onchan(u, chan)) {
86 Tcl_AppendResult(irp, "user not on channel: ", argv[2], NULL);
87 return TCL_ERROR;
88 }
89 if (!ismember(chan, botname)) {
90 Tcl_AppendResult(irp, "not on channel: ", argv[2], NULL);
91 return TCL_ERROR;
92 }
93 if (!isop(botname, chan)) {
94 Tcl_AppendResult(irp, "not opped on channel: ", argv[2], NULL);
95 return TCL_ERROR;
96 }
97 if (nextbot(argv[1]) < 0) {
98 Tcl_AppendResult(irp, "not linked to: ", argv[1], NULL);
99 return TCL_ERROR;
100 }
101 bnop_askbot(argv[1], argv[2]);
102
103 return TCL_OK;
104 }
105
106 static int tcl_bop_letmein STDVAR
107 {
108 struct chanset_t *chan = NULL;
109
110 BADARGS(3, 3, " channel need");
111 if (!(chan = findchan_by_dname(argv[1]))) {
112 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
113 return TCL_ERROR;
114 }
115 if (strcmp(argv[2], "key") && strcmp(argv[2], "invite") && strcmp(argv[2], "limit")
116 && strcmp(argv[2], "unban")) {
117 Tcl_AppendResult(irp, "unknown need type: should be one of: ",
118 "key, invite, limit, unban", NULL);
119 return TCL_ERROR;
120 }
121 if (ismember(chan, botname)) {
122 Tcl_AppendResult(irp, "already on channel: ", argv[1], NULL);
123 return TCL_ERROR;
124 }
125 bnop_letmein(chan, argv[2]);
126
127 return TCL_OK;
128 }
129
130 static int tcl_bop_lowbots STDVAR
131 {
132 struct chanset_t *chan = NULL;
133
134 BADARGS(2, 2, " channel");
135 if (!(chan = findchan_by_dname(argv[1]))) {
136 Tcl_AppendResult(irp, "invalid channel: ", argv[1], NULL);
137 return TCL_ERROR;
138 }
139 if (lowbots(chan))
140 Tcl_AppendResult(irp, "1", NULL);
141 else
142 Tcl_AppendResult(irp, "0", NULL);
143
144 return TCL_OK;
145 }
146
147 static tcl_cmds botnetop_tcl_cmds[] =
148 {
149 {"bop_reqop", tcl_bop_reqop},
150 {"bop_askbot", tcl_bop_askbot},
151 {"bop_letmein", tcl_bop_letmein},
152 {"bop_lowbots", tcl_bop_lowbots},
153 {0, 0}
154 };
155
156 #endif

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23