]>
jfr.im git - irc/quakenet/newserv.git/blob - noperserv/noperserv_commands.c
8 #include "../control/control.h"
9 #include "../nick/nick.h"
10 #include "../newsearch/newsearch.h"
11 #include "../lib/irc_string.h"
12 #include "../lib/strlfunc.h"
13 #include "../localuser/localuserchannel.h"
14 #include "../geoip/geoip.h"
15 #include "../lib/version.h"
16 #include "../core/modules.h"
20 int controlkill ( void * sender
, int cargc
, char ** cargv
);
21 int controlopchan ( void * sender
, int cargc
, char ** cargv
);
22 int controlkick ( void * sender
, int cargc
, char ** cargv
);
23 int controlspewchan ( void * sender
, int cargc
, char ** cargv
);
24 int controlspew ( void * sender
, int cargc
, char ** cargv
);
25 int controlresync ( void * sender
, int cargc
, char ** cargv
);
26 int controlbroadcast ( void * sender
, int cargc
, char ** cargv
);
27 int controlobroadcast ( void * sender
, int cargc
, char ** cargv
);
28 int controlmbroadcast ( void * sender
, int cargc
, char ** cargv
);
29 int controlsbroadcast ( void * sender
, int cargc
, char ** cargv
);
30 int controlcbroadcast ( void * sender
, int cargc
, char ** cargv
);
33 /* registercontrolhelpcmd("kill", NO_OPER, 2, &controlkill, "Usage: kill <nick> ?reason?\nKill specified user with given reason (or 'Killed').");*/
34 registercontrolhelpcmd ( "kick" , NO_OPER
, 3 , & controlkick
, "Usage: kick <channel> <user> ?reason? \n Kick a user from the given channel, with given reason (or 'Kicked')." );
36 registercontrolhelpcmd ( "spewchan" , NO_OPER
, 1 , & controlspewchan
, "Usage: spewchan <pattern> \n Shows all channels which are matched by the given pattern" );
38 registercontrolhelpcmd ( "spew" , NO_OPER
, 1 , & controlspew
, "Usage: spewchan <pattern> \n Shows all userss which are matched by the given pattern" );
40 registercontrolhelpcmd ( "resync" , NO_OPER
, 1 , & controlresync
, "Usage: resync <channel> \n Resyncs a desynched channel" );
42 registercontrolhelpcmd ( "broadcast" , NO_OPER
, 1 , & controlbroadcast
, "Usage: broadcast <text> \n Sends a message to all users." );
43 registercontrolhelpcmd ( "obroadcast" , NO_OPER
, 1 , & controlobroadcast
, "Usage: obroadcast <text> \n Sends a message to all IRC operators." );
44 registercontrolhelpcmd ( "mbroadcast" , NO_OPER
, 2 , & controlmbroadcast
, "Usage: mbroadcast <mask> <text> \n Sends a message to all users matching the mask" );
45 registercontrolhelpcmd ( "sbroadcast" , NO_OPER
, 2 , & controlsbroadcast
, "Usage: sbroadcast <mask> <text> \n Sends a message to all users on specific server(s)." );
46 registercontrolhelpcmd ( "cbroadcast" , NO_OPER
, 2 , & controlcbroadcast
, "Usage: cbroadcast <2 letter country> <text> \n Sends a message to all users in the specified country (GeoIP must be loaded)." );
50 deregistercontrolcmd ( "obroadcast" , controlobroadcast
);
51 deregistercontrolcmd ( "sbroadcast" , controlsbroadcast
);
52 deregistercontrolcmd ( "mbroadcast" , controlmbroadcast
);
53 deregistercontrolcmd ( "broadcast" , controlbroadcast
);
55 deregistercontrolcmd ( "resync" , controlresync
);
56 deregistercontrolcmd ( "spew" , controlspew
);
57 deregistercontrolcmd ( "spewchan" , controlspewchan
);
59 /* deregistercontrolcmd("kill", controlkill); */
60 deregistercontrolcmd ( "kick" , controlkick
);
63 int controlkick ( void * sender
, int cargc
, char ** cargv
) {
64 nick
* np
=( nick
*) sender
;
71 if (( cp
= findchannel ( cargv
[ 0 ]))== NULL
) {
72 controlreply ( np
, "Couldn't find that channel." );
76 if (( target
= getnickbynick ( cargv
[ 1 ]))== NULL
) {
77 controlreply ( np
, "Sorry, couldn't find that user" );
81 controlwall ( NO_OPER
, NL_KICKKILLS
, " %s / %s sent KICK for %s ! %s @ %s on %s ( %s )" , np
-> nick
, np
-> authname
, target
-> nick
, target
-> ident
, target
-> host
-> name
-> content
, cp
-> index
-> name
-> content
, ( cargc
> 2 )? cargv
[ 2 ]: "Kicked" );
82 localkickuser ( NULL
, cp
, target
, ( cargc
> 2 )? cargv
[ 2 ]: "Kicked" );
83 controlreply ( sender
, "KICK sent." );
88 /* NO checking to see if it's us or anyone important */
89 int controlkill ( void * sender
, int cargc
, char ** cargv
) {
91 nick
* np
= ( nick
*) sender
;
96 if (( target
= getnickbynick ( cargv
[ 0 ]))== NULL
) {
97 controlreply ( np
, "Sorry, couldn't find that user." );
101 controlwall ( NO_OPER
, NL_KICKKILLS
, " %s / %s sent KILL for %s ! %s @ %s ( %s )" , np
-> nick
, np
-> authname
, target
-> nick
, target
-> ident
, target
-> host
-> name
-> content
, ( cargc
> 1 )? cargv
[ 1 ]: "Killed" );
102 killuser ( NULL
, target
, ( cargc
> 1 )? cargv
[ 1 ]: "Killed" );
103 controlreply ( np
, "KILL sent." );
108 int controlresync ( void * sender
, int cargc
, char ** cargv
) {
109 nick
* np
= ( nick
*) sender
;
117 cp
= findchannel ( cargv
[ 0 ]);
120 controlreply ( np
, "No such channel." );
125 controlwall ( NO_OPER
, NL_MISC
, " %s / %s RESYNC'ed %s " , np
-> nick
, np
-> authname
, cp
-> index
-> name
-> content
);
127 irc_send ( " %s CM %s o" , mynumeric
-> content
, cp
-> index
-> name
-> content
);
129 localsetmodeinit (& changes
, cp
, mynick
);
131 for ( a
= 0 ; a
< cp
-> users
-> hashsize
; a
++) {
132 if ( cp
-> users
-> content
[ a
] != nouser
) {
133 nick
* np2
= getnickbynumeric ( cp
-> users
-> content
[ a
]);
135 /* make newserv believe that this user is not opped */
136 if ( cp
-> users
-> content
[ a
] & CUMODE_OP
)
137 cp
-> users
-> content
[ a
] &= ~ CUMODE_OP
;
138 else if (! IsService ( np2
)) /* if the user wasn't opped before and is not a service we don't care about him */
142 localdosetmode_nick (& changes
, np2
, MC_OP
);
146 localsetmodeflush (& changes
, 1 );
148 controlreply ( np
, "Done." );
153 int controlspew ( void * sender
, int cargc
, char ** cargv
) {
159 tree
= NSASTNode ( match_parse
, NSASTNode ( hostmask_parse
), NSASTLiteral ( cargv
[ 0 ]));
160 return ast_nicksearch ( tree
, controlreply
, sender
, controlnswall
, printnick
, NULL
, NULL
, 500 );
163 /* this function is the definition of horrible */
164 int controlspewchan ( void * sender
, int cargc
, char ** cargv
) {
165 nick
* np
= ( nick
*) sender
;
167 int i
, a
, ccount
= 0 , morecservices
, ucount
, cscount
;
176 for ( i
= 0 ; i
< CHANNELHASHSIZE
; i
++) {
177 for ( cip
= chantable
[ i
]; cip
; cip
= cip
-> next
) {
178 if (( cp
= cip
-> channel
) != NULL
&& match2strings ( cargv
[ 0 ], cip
-> name
-> content
)) {
179 /* find channel services */
181 cscount
= ucount
= morecservices
= 0 ;
183 for ( a
= 0 ; a
< cp
-> users
-> hashsize
; a
++) {
184 if ( cp
-> users
-> content
[ a
] != nouser
) {
185 np2
= getnickbynumeric ( cp
-> users
-> content
[ a
]);
187 if ( IsService ( np2
)) {
190 if ( strlen ( cservices
) < 100 ) {
192 strlcat ( cservices
, ", " , sizeof ( cservices
));
194 strlcat ( cservices
, np2
-> nick
, sizeof ( cservices
));
205 snprintf ( cservices
+ strlen ( cservices
), sizeof ( cservices
), " and %d more" , morecservices
);
207 snprintf ( strcscount
, sizeof ( strcscount
), " %d " , cscount
);
209 /* TODO: print this channel ;; @slug -- WTF? */
210 controlreply ( np
, "%-30s %5 ld %-8s %s%s %-11s %s%s%s " ,
213 ucount
!= 1 ? "users" : "user" ,
214 * cservices
? "- found " : "" ,
215 * cservices
? strcscount
: "" ,
216 * cservices
? ( strchr ( cservices
, ',' ) ? " chanservs" : " chanserv" ) : "" ,
217 * cservices
? "(" : "" ,
218 * cservices
? cservices
: "" ,
219 * cservices
? ")" : "" );
224 break ; /* Don't ever list more than 1000 channels */
230 controlreply ( np
, "More than 1000 matching channels were found. Please use a more specific pattern." );
232 controlreply ( np
, "Found %d channels matching specified pattern." , ccount
);
237 int controlbroadcast ( void * sender
, int cargc
, char ** cargv
) {
238 nick
* np
= ( nick
*) sender
;
243 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent a broadcast: %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ]);
245 irc_send ( " %s O $* :(Broadcast) %s " , longtonumeric ( mynick
-> numeric
, 5 ), cargv
[ 0 ]);
247 controlreply ( np
, "Message broadcasted." );
252 int controlmbroadcast ( void * sender
, int cargc
, char ** cargv
) {
253 nick
* np
= ( nick
*) sender
;
258 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent an mbroadcast to %s : %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ], cargv
[ 1 ]);
260 irc_send ( " %s O $@ %s :(mBroadcast) %s " , longtonumeric ( mynick
-> numeric
, 5 ), cargv
[ 0 ], cargv
[ 1 ]);
262 controlreply ( np
, "Message mbroadcasted." );
267 int controlsbroadcast ( void * sender
, int cargc
, char ** cargv
) {
268 nick
* np
= ( nick
*) sender
;
273 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent an sbroadcast to %s : %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ], cargv
[ 1 ]);
275 irc_send ( " %s O $ %s :(sBroadcast) %s " , longtonumeric ( mynick
-> numeric
, 5 ), cargv
[ 0 ], cargv
[ 1 ]);
277 controlreply ( np
, "Message sbroadcasted." );
282 int controlobroadcast ( void * sender
, int cargc
, char ** cargv
) {
283 nick
* np
= ( nick
*) sender
, * nip
;
289 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent an obroadcast: %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ]);
291 for ( i
= 0 ; i
< NICKHASHSIZE
; i
++)
292 for ( nip
= nicktable
[ i
]; nip
; nip
= nip
-> next
)
293 if ( nip
&& IsOper ( nip
))
294 controlnotice ( nip
, "(oBroadcast) %s " , cargv
[ 0 ]);
296 controlreply ( np
, "Message obroadcasted." );
301 int controlcbroadcast ( void * sender
, int cargc
, char ** cargv
) {
302 nick
* np
= ( nick
*) sender
, * nip
;
309 ext
= findnickext ( "geoip" );
311 controlreply ( np
, "Geoip module not loaded." );
315 l
= ndlsym ( "geoip" , "geoip_lookupcode" );
316 target
= l ( cargv
[ 0 ]);
319 controlreply ( np
, "Invalid country." );
323 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent a cbroadcast %s : %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ], cargv
[ 1 ]);
325 for ( i
= 0 ; i
< NICKHASHSIZE
; i
++)
326 for ( nip
= nicktable
[ i
]; nip
; nip
= nip
-> next
)
327 if ( nip
&& (( int )(( long ) nip
-> exts
[ ext
]) == target
))
328 controlnotice ( nip
, "(cBroadcast) %s " , cargv
[ 1 ]);
330 controlreply ( np
, "Message cbroadcasted." );