]>
Commit | Line | Data |
---|---|---|
18f8bd28 CP |
1 | /* |
2 | nterfacer newserv control module | |
c2234094 | 3 | Copyright (C) 2004-2007 Chris Porter. |
18f8bd28 CP |
4 | */ |
5 | ||
b55cdc29 CP |
6 | #include <string.h> |
7 | ||
18f8bd28 CP |
8 | #include "../localuser/localuserchannel.h" |
9 | #include "../channel/channel.h" | |
a4560bdf | 10 | #include "../lib/strlfunc.h" |
18f8bd28 CP |
11 | #include "../control/control.h" |
12 | #include "../core/hooks.h" | |
8da2a7b1 CP |
13 | #include "../nick/nick.h" |
14 | #include "../lib/flags.h" | |
18f8bd28 | 15 | #include "../lib/irc_string.h" |
87698d77 | 16 | #include "../lib/version.h" |
c2234094 | 17 | #include "../authhash/authhash.h" |
18f8bd28 CP |
18 | |
19 | #include "library.h" | |
20 | #include "nterfacer_control.h" | |
21 | ||
70b0a4e5 | 22 | MODULE_VERSION(""); |
87698d77 | 23 | |
18f8bd28 | 24 | int handle_ison(struct rline *li, int argc, char **argv); |
c2234094 | 25 | int handle_isaccounton(struct rline *li, int argc, char **argv); |
18f8bd28 CP |
26 | int handle_whois(struct rline *li, int argc, char **argv); |
27 | int handle_message(struct rline *li, int argc, char **argv); | |
28 | int handle_notice(struct rline *li, int argc, char **argv); | |
29 | int handle_channel(struct rline *li, int argc, char **argv); | |
30 | int handle_onchan(struct rline *li, int argc, char **argv); | |
31 | int handle_status(struct rline *li, int argc, char **argv); | |
32 | int handle_servicesonchan(struct rline *li, int argc, char **argv); | |
b55cdc29 | 33 | int handle_counthost(struct rline *li, int argc, char **argv); |
18f8bd28 CP |
34 | |
35 | struct rline *grli; /* used inline for status */ | |
4e4920a4 | 36 | struct service_node *n_node; |
18f8bd28 CP |
37 | |
38 | void _init(void) { | |
504f62c7 CP |
39 | n_node = register_service("N"); |
40 | if(!n_node) | |
18f8bd28 CP |
41 | return; |
42 | ||
504f62c7 | 43 | register_handler(n_node, "ison", 1, handle_ison); |
3fed81d6 | 44 | /* register_handler(n_node, "isaccounton", 1, handle_isaccounton); */ |
504f62c7 CP |
45 | register_handler(n_node, "whois", 1, handle_whois); |
46 | register_handler(n_node, "msg", 2, handle_message); | |
47 | register_handler(n_node, "notice", 2, handle_notice); | |
48 | register_handler(n_node, "chanmsg", 2, handle_channel); | |
49 | register_handler(n_node, "onchan", 2, handle_onchan); | |
50 | register_handler(n_node, "status", 0, handle_status); | |
51 | register_handler(n_node, "servicesonchan", 1, handle_servicesonchan); | |
b55cdc29 | 52 | register_handler(n_node, "counthost", 1, handle_counthost); |
18f8bd28 CP |
53 | } |
54 | ||
55 | void _fini(void) { | |
504f62c7 CP |
56 | if(n_node) |
57 | deregister_service(n_node); | |
18f8bd28 CP |
58 | } |
59 | ||
60 | int handle_ison(struct rline *li, int argc, char **argv) { | |
61 | int i; | |
62 | for(i=0;i<argc;i++) | |
b55cdc29 CP |
63 | if(ri_append(li, "%d", getnickbynick(argv[i])?1:0) == BF_OVER) |
64 | return ri_error(li, BF_OVER, "Buffer overflow"); | |
18f8bd28 | 65 | |
18f8bd28 CP |
66 | return ri_final(li); |
67 | } | |
3fed81d6 | 68 | /* |
c2234094 CP |
69 | int handle_isaccounton(struct rline *li, int argc, char **argv) { |
70 | int i; | |
71 | for(i=0;i<argc;i++) | |
72 | if(ri_append(li, "%d", getnickbyauth(argv[i])?1:0) == BF_OVER) | |
73 | return ri_error(li, BF_OVER, "Buffer overflow"); | |
74 | ||
75 | return ri_final(li); | |
76 | } | |
3fed81d6 | 77 | */ |
18f8bd28 CP |
78 | int handle_whois(struct rline *li, int argc, char **argv) { |
79 | nick *np = getnickbynick(argv[0]); | |
80 | channel **channels; | |
81 | ||
82 | int i; | |
83 | ||
84 | if(!np) | |
85 | return ri_error(li, ERR_TARGET_NOT_FOUND, "User not online"); | |
86 | ||
87 | ri_append(li, "%s", np->nick); | |
88 | ri_append(li, "%s", np->ident); | |
89 | ri_append(li, "%s", np->host->name->content); | |
90 | ri_append(li, "%s", np->realname->name->content); | |
91 | ri_append(li, "%s", np->authname); | |
8da2a7b1 | 92 | ri_append(li, "%s", printflags(np->umodes, umodeflags)); |
18f8bd28 CP |
93 | |
94 | channels = np->channels->content; | |
95 | ||
96 | for(i=0;i<np->channels->cursi;i++) | |
97 | if(ri_append(li, "%s", channels[i]->index->name->content) == BF_OVER) | |
98 | return ri_error(li, BF_OVER, "Buffer overflow"); | |
99 | ||
100 | return ri_final(li); | |
101 | } | |
102 | ||
103 | int handle_message(struct rline *li, int argc, char **argv) { | |
104 | int realargc = abs(argc), i; | |
105 | nick *np = getnickbynick(argv[0]); | |
106 | if(!np) | |
107 | return ri_error(li, ERR_TARGET_NOT_FOUND, "User not online"); | |
108 | ||
109 | for(i=1;i<realargc;i++) { | |
110 | if(argc < 0) { | |
111 | controlnotice(np, "%s", argv[i]); | |
112 | } else { | |
113 | controlreply(np, "%s", argv[i]); | |
114 | } | |
115 | } | |
116 | ||
117 | ri_append(li, "Done."); | |
118 | return ri_final(li); | |
119 | } | |
120 | ||
121 | int handle_notice(struct rline *li, int argc, char **argv) { | |
122 | return handle_message(li, -argc, argv); | |
123 | } | |
124 | ||
125 | int handle_channel(struct rline *li, int argc, char **argv) { | |
126 | int i; | |
127 | channel *cp = findchannel(argv[0]); | |
128 | if(!cp) | |
129 | return ri_error(li, ERR_TARGET_NOT_FOUND, "Channel not found"); | |
130 | ||
131 | for(i=1;i<argc;i++) | |
132 | controlchanmsg(cp, "%s", argv[i]); | |
133 | ||
134 | ri_append(li, "Done."); | |
135 | return ri_final(li); | |
136 | } | |
137 | ||
138 | int handle_onchan(struct rline *li, int argc, char **argv) { | |
139 | int i; | |
140 | nick *np = getnickbynick(argv[0]); | |
141 | channel **channels; | |
142 | channel *cp; | |
143 | if(!np) | |
144 | return ri_error(li, ERR_TARGET_NOT_FOUND, "Nickname not found"); | |
145 | ||
146 | cp = findchannel(argv[1]); | |
147 | if(!cp) | |
148 | return ri_error(li, ERR_TARGET_NOT_FOUND, "Channel not found"); | |
149 | ||
150 | channels = (channel **)np->channels->content; | |
151 | for(i=0;i<np->channels->cursi;i++) { | |
152 | if(channels[i]->index->channel == cp) { | |
153 | ri_append(li, "1"); | |
154 | return ri_final(li); | |
155 | } | |
156 | } | |
157 | ||
158 | ri_append(li, "0"); | |
159 | return ri_final(li); | |
160 | } | |
161 | ||
162 | void handle_nterfacerstats(int hooknum, void *arg) { | |
b55cdc29 | 163 | /* hmm, not much we can do here, @ppa */ |
18f8bd28 CP |
164 | ri_append(grli, "%s", (char *)arg); |
165 | } | |
166 | ||
167 | int handle_status(struct rline *li, int argc, char **argv) { | |
168 | grli = li; | |
169 | ||
170 | registerhook(HOOK_CORE_STATSREPLY, &handle_nterfacerstats); | |
171 | triggerhook(HOOK_CORE_STATSREQUEST, (void *)5); | |
172 | deregisterhook(HOOK_CORE_STATSREPLY, &handle_nterfacerstats); | |
173 | return ri_final(li); | |
174 | } | |
175 | ||
176 | /* assumes services have a single char nickname and +k set */ | |
177 | int handle_servicesonchan(struct rline *li, int argc, char **argv) { | |
178 | int i; | |
179 | nick *np; | |
180 | channel *cp = findchannel(argv[0]); | |
181 | if(!cp) | |
182 | return ri_error(li, ERR_TARGET_NOT_FOUND, "Channel not found"); | |
183 | ||
184 | #if NICKLEN >= 1 /* if not we have a buffer overflow */ | |
185 | for(i=0;i<=cp->users->hashsize;i++) { | |
186 | if(cp->users->content[i] != nouser) { | |
187 | np = getnickbynumeric(cp->users->content[i]); | |
188 | if(np && IsService(np) && np->nick[0] && !np->nick[1]) | |
b55cdc29 CP |
189 | if(ri_append(li, "%s", np->nick) == BF_OVER) |
190 | return ri_error(li, BF_OVER, "Buffer overflow"); | |
18f8bd28 CP |
191 | } |
192 | } | |
193 | #endif | |
194 | ||
195 | return ri_final(li); | |
196 | } | |
b55cdc29 CP |
197 | |
198 | int handle_counthost(struct rline *li, int argc, char **argv) { | |
199 | int i, j; | |
200 | unsigned int results[100]; | |
201 | host *hp; | |
202 | if(argc > 100) | |
203 | return ri_error(li, ERR_TOO_MANY_ARGS, "Too many arguments"); | |
204 | ||
205 | memset(results, 0, sizeof(results)); | |
206 | ||
207 | for(j=0;j<argc;j++) | |
208 | collapse(argv[j]); | |
209 | ||
210 | for(i=0;i<HOSTHASHSIZE;i++) | |
211 | for(hp=hosttable[i];hp;hp=hp->next) | |
212 | for(j=0;j<argc;j++) | |
213 | if(!match(argv[j], hp->name->content)) | |
214 | results[j]+=hp->clonecount; | |
215 | ||
216 | for(j=0;j<argc;j++) | |
217 | if(ri_append(li, "%d", results[j]) == BF_OVER) | |
218 | return ri_error(li, BF_OVER, "Buffer overflow"); | |
219 | ||
220 | ||
221 | return ri_final(li); | |
222 | } | |
223 | ||
224 |