]>
jfr.im git - irc/quakenet/newserv.git/blob - nterfacer/nterfacer_control.c
2 nterfacer newserv control module
3 Copyright (C) 2004-2007 Chris Porter.
8 #include "../localuser/localuserchannel.h"
9 #include "../channel/channel.h"
10 #include "../lib/strlfunc.h"
11 #include "../control/control.h"
12 #include "../core/hooks.h"
13 #include "../nick/nick.h"
14 #include "../lib/flags.h"
15 #include "../lib/irc_string.h"
16 #include "../lib/version.h"
19 #include "nterfacer_control.h"
23 int handle_ison(struct rline
*li
, int argc
, char **argv
);
24 int handle_isaccounton(struct rline
*li
, int argc
, char **argv
);
25 int handle_whois(struct rline
*li
, int argc
, char **argv
);
26 int handle_message(struct rline
*li
, int argc
, char **argv
);
27 int handle_notice(struct rline
*li
, int argc
, char **argv
);
28 int handle_channel(struct rline
*li
, int argc
, char **argv
);
29 int handle_onchan(struct rline
*li
, int argc
, char **argv
);
30 int handle_status(struct rline
*li
, int argc
, char **argv
);
31 int handle_servicesonchan(struct rline
*li
, int argc
, char **argv
);
32 int handle_counthost(struct rline
*li
, int argc
, char **argv
);
34 struct rline
*grli
; /* used inline for status */
35 struct service_node
*n_node
;
38 n_node
= register_service("N");
42 register_handler(n_node
, "ison", 1, handle_ison
);
43 /* register_handler(n_node, "isaccounton", 1, handle_isaccounton); */
44 register_handler(n_node
, "whois", 1, handle_whois
);
45 register_handler(n_node
, "msg", 2, handle_message
);
46 register_handler(n_node
, "notice", 2, handle_notice
);
47 register_handler(n_node
, "chanmsg", 2, handle_channel
);
48 register_handler(n_node
, "onchan", 2, handle_onchan
);
49 register_handler(n_node
, "status", 0, handle_status
);
50 register_handler(n_node
, "servicesonchan", 1, handle_servicesonchan
);
51 register_handler(n_node
, "counthost", 1, handle_counthost
);
56 deregister_service(n_node
);
59 int handle_ison(struct rline
*li
, int argc
, char **argv
) {
62 if(ri_append(li
, "%d", getnickbynick(argv
[i
])?1:0) == BF_OVER
)
63 return ri_error(li
, BF_OVER
, "Buffer overflow");
68 int handle_isaccounton(struct rline *li, int argc, char **argv) {
71 if(ri_append(li, "%d", getnickbyauth(argv[i])?1:0) == BF_OVER)
72 return ri_error(li, BF_OVER, "Buffer overflow");
77 int handle_whois(struct rline
*li
, int argc
, char **argv
) {
78 nick
*np
= getnickbynick(argv
[0]);
84 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "User not online");
86 ri_append(li
, "%s", np
->nick
);
87 ri_append(li
, "%s", np
->ident
);
88 ri_append(li
, "%s", np
->host
->name
->content
);
89 ri_append(li
, "%s", np
->realname
->name
->content
);
90 ri_append(li
, "%s", np
->authname
);
91 ri_append(li
, "%s", printflags(np
->umodes
, umodeflags
));
93 channels
= np
->channels
->content
;
95 for(i
=0;i
<np
->channels
->cursi
;i
++)
96 if(ri_append(li
, "%s", channels
[i
]->index
->name
->content
) == BF_OVER
)
97 return ri_error(li
, BF_OVER
, "Buffer overflow");
102 int handle_message(struct rline
*li
, int argc
, char **argv
) {
103 int realargc
= abs(argc
), i
;
104 nick
*np
= getnickbynick(argv
[0]);
106 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "User not online");
108 for(i
=1;i
<realargc
;i
++) {
110 controlnotice(np
, "%s", argv
[i
]);
112 controlreply(np
, "%s", argv
[i
]);
116 ri_append(li
, "Done.");
120 int handle_notice(struct rline
*li
, int argc
, char **argv
) {
121 return handle_message(li
, -argc
, argv
);
124 int handle_channel(struct rline
*li
, int argc
, char **argv
) {
126 channel
*cp
= findchannel(argv
[0]);
128 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
131 controlchanmsg(cp
, "%s", argv
[i
]);
133 ri_append(li
, "Done.");
137 int handle_onchan(struct rline
*li
, int argc
, char **argv
) {
139 nick
*np
= getnickbynick(argv
[0]);
143 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Nickname not found");
145 cp
= findchannel(argv
[1]);
147 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
149 channels
= (channel
**)np
->channels
->content
;
150 for(i
=0;i
<np
->channels
->cursi
;i
++) {
151 if(channels
[i
]->index
->channel
== cp
) {
161 void handle_nterfacerstats(int hooknum
, void *arg
) {
162 /* hmm, not much we can do here, @ppa */
163 ri_append(grli
, "%s", (char *)arg
);
166 int handle_status(struct rline
*li
, int argc
, char **argv
) {
169 registerhook(HOOK_CORE_STATSREPLY
, &handle_nterfacerstats
);
170 triggerhook(HOOK_CORE_STATSREQUEST
, (void *)5);
171 deregisterhook(HOOK_CORE_STATSREPLY
, &handle_nterfacerstats
);
175 /* assumes services have a single char nickname and +k set */
176 int handle_servicesonchan(struct rline
*li
, int argc
, char **argv
) {
179 channel
*cp
= findchannel(argv
[0]);
181 return ri_error(li
, ERR_TARGET_NOT_FOUND
, "Channel not found");
183 #if NICKLEN >= 1 /* if not we have a buffer overflow */
184 for(i
=0;i
<=cp
->users
->hashsize
;i
++) {
185 if(cp
->users
->content
[i
] != nouser
) {
186 np
= getnickbynumeric(cp
->users
->content
[i
]);
187 if(np
&& IsService(np
) && np
->nick
[0] && !np
->nick
[1])
188 if(ri_append(li
, "%s", np
->nick
) == BF_OVER
)
189 return ri_error(li
, BF_OVER
, "Buffer overflow");
197 int handle_counthost(struct rline
*li
, int argc
, char **argv
) {
199 unsigned int results
[100];
202 return ri_error(li
, ERR_TOO_MANY_ARGS
, "Too many arguments");
204 memset(results
, 0, sizeof(results
));
209 for(i
=0;i
<HOSTHASHSIZE
;i
++)
210 for(hp
=hosttable
[i
];hp
;hp
=hp
->next
)
212 if(!match(argv
[j
], hp
->name
->content
))
213 results
[j
]+=hp
->clonecount
;
216 if(ri_append(li
, "%d", results
[j
]) == BF_OVER
)
217 return ri_error(li
, BF_OVER
, "Buffer overflow");