]>
jfr.im git - irc/quakenet/newserv.git/blob - noperserv/noperserv_commands.c
8 #include "../control/control.h"
9 #include "../nick/nick.h"
10 #include "../lib/irc_string.h"
11 #include "../lib/strlfunc.h"
12 #include "../localuser/localuserchannel.h"
13 #include "../geoip/geoip.h"
14 #include "../lib/version.h"
18 int controlkill ( void * sender
, int cargc
, char ** cargv
);
19 int controlopchan ( void * sender
, int cargc
, char ** cargv
);
20 int controlkick ( void * sender
, int cargc
, char ** cargv
);
21 int controlspewchan ( void * sender
, int cargc
, char ** cargv
);
22 int controlspew ( void * sender
, int cargc
, char ** cargv
);
23 int controlresync ( void * sender
, int cargc
, char ** cargv
);
24 int controlbroadcast ( void * sender
, int cargc
, char ** cargv
);
25 int controlobroadcast ( void * sender
, int cargc
, char ** cargv
);
26 int controlmbroadcast ( void * sender
, int cargc
, char ** cargv
);
27 int controlsbroadcast ( void * sender
, int cargc
, char ** cargv
);
28 int controlcbroadcast ( void * sender
, int cargc
, char ** cargv
);
31 /* registercontrolhelpcmd("kill", NO_OPER, 2, &controlkill, "Usage: kill <nick> ?reason?\nKill specified user with given reason (or 'Killed').");*/
32 registercontrolhelpcmd ( "kick" , NO_OPER
, 3 , & controlkick
, "Usage: kick <channel> <user> ?reason? \n Kick a user from the given channel, with given reason (or 'Kicked')." );
34 registercontrolhelpcmd ( "spewchan" , NO_OPER
, 1 , & controlspewchan
, "Usage: spewchan <pattern> \n Shows all channels which are matched by the given pattern" );
36 /* registercontrolhelpcmd("spew", NO_OPER, 1, &controlspew, "Usage: spewchan <pattern>\nShows all userss which are matched by the given pattern"); */
38 registercontrolhelpcmd ( "resync" , NO_OPER
, 1 , & controlresync
, "Usage: resync <channel> \n Resyncs a desynched channel" );
40 registercontrolhelpcmd ( "broadcast" , NO_OPER
, 1 , & controlbroadcast
, "Usage: broadcast <text> \n Sends a message to all users." );
41 registercontrolhelpcmd ( "obroadcast" , NO_OPER
, 1 , & controlobroadcast
, "Usage: obroadcast <text> \n Sends a message to all IRC operators." );
42 registercontrolhelpcmd ( "mbroadcast" , NO_OPER
, 2 , & controlmbroadcast
, "Usage: mbroadcast <mask> <text> \n Sends a message to all users matching the mask" );
43 registercontrolhelpcmd ( "sbroadcast" , NO_OPER
, 2 , & controlsbroadcast
, "Usage: sbroadcast <mask> <text> \n Sends a message to all users on specific server(s)." );
44 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)." );
48 deregistercontrolcmd ( "obroadcast" , controlobroadcast
);
49 deregistercontrolcmd ( "sbroadcast" , controlsbroadcast
);
50 deregistercontrolcmd ( "mbroadcast" , controlmbroadcast
);
51 deregistercontrolcmd ( "broadcast" , controlbroadcast
);
53 deregistercontrolcmd ( "resync" , controlresync
);
54 /* deregistercontrolcmd("spew", controlspew); */
55 deregistercontrolcmd ( "spewchan" , controlspewchan
);
57 /* deregistercontrolcmd("kill", controlkill); */
58 deregistercontrolcmd ( "kick" , controlkick
);
61 int controlkick ( void * sender
, int cargc
, char ** cargv
) {
62 nick
* np
=( nick
*) sender
;
69 if (( cp
= findchannel ( cargv
[ 0 ]))== NULL
) {
70 controlreply ( np
, "Couldn't find that channel." );
74 if (( target
= getnickbynick ( cargv
[ 1 ]))== NULL
) {
75 controlreply ( np
, "Sorry, couldn't find that user" );
79 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" );
80 localkickuser ( NULL
, cp
, target
, ( cargc
> 2 )? cargv
[ 2 ]: "Kicked" );
81 controlreply ( sender
, "KICK sent." );
86 /* NO checking to see if it's us or anyone important */
87 int controlkill ( void * sender
, int cargc
, char ** cargv
) {
89 nick
* np
= ( nick
*) sender
;
94 if (( target
= getnickbynick ( cargv
[ 0 ]))== NULL
) {
95 controlreply ( np
, "Sorry, couldn't find that user." );
99 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" );
100 killuser ( NULL
, target
, ( cargc
> 1 )? cargv
[ 1 ]: "Killed" );
101 controlreply ( np
, "KILL sent." );
106 int controlresync ( void * sender
, int cargc
, char ** cargv
) {
107 nick
* np
= ( nick
*) sender
;
115 cp
= findchannel ( cargv
[ 0 ]);
118 controlreply ( np
, "No such channel." );
123 controlwall ( NO_OPER
, NL_MISC
, " %s / %s RESYNC'ed %s " , np
-> nick
, np
-> authname
, cp
-> index
-> name
-> content
);
125 irc_send ( " %s CM %s o" , mynumeric
-> content
, cp
-> index
-> name
-> content
);
127 localsetmodeinit (& changes
, cp
, mynick
);
129 for ( a
= 0 ; a
< cp
-> users
-> hashsize
; a
++) {
130 if ( cp
-> users
-> content
[ a
] != nouser
) {
131 nick
* np2
= getnickbynumeric ( cp
-> users
-> content
[ a
]);
133 /* make newserv believe that this user is not opped */
134 if ( cp
-> users
-> content
[ a
] & CUMODE_OP
)
135 cp
-> users
-> content
[ a
] &= ~ CUMODE_OP
;
136 else if (! IsService ( np2
)) /* if the user wasn't opped before and is not a service we don't care about him */
140 localdosetmode_nick (& changes
, np2
, MC_OP
);
144 localsetmodeflush (& changes
, 1 );
146 controlreply ( np
, "Done." );
151 int controlspew ( void * sender
, int cargc
, char ** cargv
) {
152 /* nick *np = (nick *)sender; */
157 int controlspewchan ( void * sender
, int cargc
, char ** cargv
) {
158 nick
* np
= ( nick
*) sender
;
160 int i
, a
, ccount
= 0 , morecservices
, ucount
, cscount
;
169 for ( i
= 0 ; i
< CHANNELHASHSIZE
; i
++) {
170 for ( cip
= chantable
[ i
]; cip
; cip
= cip
-> next
) {
171 if (( cp
= cip
-> channel
) != NULL
&& match2strings ( cargv
[ 0 ], cip
-> name
-> content
)) {
172 /* find channel services */
174 cscount
= ucount
= morecservices
= 0 ;
176 for ( a
= 0 ; a
< cp
-> users
-> hashsize
; a
++) {
177 if ( cp
-> users
-> content
[ a
] != nouser
) {
178 np2
= getnickbynumeric ( cp
-> users
-> content
[ a
]);
180 if ( IsService ( np2
)) {
183 if ( strlen ( cservices
) < 100 ) {
185 strlcat ( cservices
, ", " , sizeof ( cservices
));
187 strlcat ( cservices
, np2
-> nick
, sizeof ( cservices
));
198 snprintf ( cservices
+ strlen ( cservices
), sizeof ( cservices
), " and %d more" , morecservices
);
200 snprintf ( strcscount
, sizeof ( strcscount
), " %d " , cscount
);
202 /* TODO: print this channel ;; @slug -- WTF? */
203 controlreply ( np
, "%-30s %5 ld %-8s %s%s %-11s %s%s%s " ,
206 ucount
!= 1 ? "users" : "user" ,
207 * cservices
? "- found " : "" ,
208 * cservices
? strcscount
: "" ,
209 * cservices
? ( strchr ( cservices
, ',' ) ? " chanservs" : " chanserv" ) : "" ,
210 * cservices
? "(" : "" ,
211 * cservices
? cservices
: "" ,
212 * cservices
? ")" : "" );
217 break ; /* Don't ever list more than 1000 channels */
223 controlreply ( np
, "More than 1000 matching channels were found. Please use a more specific pattern." );
225 controlreply ( np
, "Found %d channels matching specified pattern." , ccount
);
230 int controlbroadcast ( void * sender
, int cargc
, char ** cargv
) {
231 nick
* np
= ( nick
*) sender
;
236 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent a broadcast: %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ]);
238 irc_send ( " %s O $* :(Broadcast) %s " , longtonumeric ( mynick
-> numeric
, 5 ), cargv
[ 0 ]);
240 controlreply ( np
, "Message broadcasted." );
245 int controlmbroadcast ( void * sender
, int cargc
, char ** cargv
) {
246 nick
* np
= ( nick
*) sender
;
251 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent an mbroadcast to %s : %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ], cargv
[ 1 ]);
253 irc_send ( " %s O $@ %s :(mBroadcast) %s " , longtonumeric ( mynick
-> numeric
, 5 ), cargv
[ 0 ], cargv
[ 1 ]);
255 controlreply ( np
, "Message mbroadcasted." );
260 int controlsbroadcast ( void * sender
, int cargc
, char ** cargv
) {
261 nick
* np
= ( nick
*) sender
;
266 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent an sbroadcast to %s : %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ], cargv
[ 1 ]);
268 irc_send ( " %s O $ %s :(sBroadcast) %s " , longtonumeric ( mynick
-> numeric
, 5 ), cargv
[ 0 ], cargv
[ 1 ]);
270 controlreply ( np
, "Message sbroadcasted." );
275 int controlobroadcast ( void * sender
, int cargc
, char ** cargv
) {
276 nick
* np
= ( nick
*) sender
, * nip
;
282 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent an obroadcast: %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ]);
284 for ( i
= 0 ; i
< NICKHASHSIZE
; i
++)
285 for ( nip
= nicktable
[ i
]; nip
; nip
= nip
-> next
)
286 if ( nip
&& IsOper ( nip
))
287 controlnotice ( nip
, "(oBroadcast) %s " , cargv
[ 0 ]);
289 controlreply ( np
, "Message obroadcasted." );
294 const char GeoIP_country_code
[ 247 ][ 3 ] = { "--" , "AP" , "EU" , "AD" , "AE" , "AF" , "AG" , "AI" , "AL" , "AM" , "AN" , "AO" , "AQ" , "AR" , "AS" , "AT" , "AU" , "AW" , "AZ" , "BA" , "BB" , "BD" , "BE" , "BF" , "BG" , "BH" , "BI" , "BJ" , "BM" , "BN" , "BO" , "BR" , "BS" , "BT" , "BV" , "BW" , "BY" , "BZ" , "CA" , "CC" , "CD" , "CF" , "CG" , "CH" , "CI" , "CK" , "CL" , "CM" , "CN" , "CO" , "CR" , "CU" , "CV" , "CX" , "CY" , "CZ" , "DE" , "DJ" , "DK" , "DM" , "DO" , "DZ" , "EC" , "EE" , "EG" , "EH" , "ER" , "ES" , "ET" , "FI" , "FJ" , "FK" , "FM" , "FO" , "FR" , "FX" , "GA" , "GB" , "GD" , "GE" , "GF" , "GH" , "GI" , "GL" , "GM" , "GN" , "GP" , "GQ" , "GR" , "GS" , "GT" , "GU" , "GW" , "GY" , "HK" , "HM" , "HN" , "HR" , "HT" , "HU" , "ID" , "IE" , "IL" , "IN" , "IO" , "IQ" , "IR" , "IS" , "IT" , "JM" , "JO" , "JP" , "KE" , "KG" , "KH" , "KI" , "KM" , "KN" , "KP" , "KR" , "KW" , "KY" , "KZ" , "LA" , "LB" , "LC" , "LI" , "LK" , "LR" , "LS" , "LT" , "LU" , "LV" , "LY" , "MA" , "MC" , "MD" , "MG" , "MH" , "MK" , "ML" , "MM" , "MN" , "MO" , "MP" , "MQ" , "MR" , "MS" , "MT" , "MU" , "MV" , "MW" , "MX" , "MY" , "MZ" , "NA" , "NC" , "NE" , "NF" , "NG" , "NI" , "NL" , "NO" , "NP" , "NR" , "NU" , "NZ" , "OM" , "PA" , "PE" , "PF" , "PG" , "PH" , "PK" , "PL" , "PM" , "PN" , "PR" , "PS" , "PT" , "PW" , "PY" , "QA" , "RE" , "RO" , "RU" , "RW" , "SA" , "SB" , "SC" , "SD" , "SE" , "SG" , "SH" , "SI" , "SJ" , "SK" , "SL" , "SM" , "SN" , "SO" , "SR" , "ST" , "SV" , "SY" , "SZ" , "TC" , "TD" , "TF" , "TG" , "TH" , "TJ" , "TK" , "TM" , "TN" , "TO" , "TP" , "TR" , "TT" , "TV" , "TW" , "TZ" , "UA" , "UG" , "UM" , "US" , "UY" , "UZ" , "VA" , "VC" , "VE" , "VG" , "VI" , "VN" , "VU" , "WF" , "WS" , "YE" , "YT" , "YU" , "ZA" , "ZM" , "ZR" , "ZW" , "A1" , "A2" , "O1" };
296 int controlcbroadcast ( void * sender
, int cargc
, char ** cargv
) {
297 nick
* np
= ( nick
*) sender
, * nip
;
303 ext
= findnickext ( "geoip" );
305 controlreply ( np
, "Geoip module not loaded." );
309 target
= COUNTRY_MIN
- 1 ;
310 for ( i
= COUNTRY_MIN
; i
< COUNTRY_MAX
; i
++) {
311 if (! strcasecmp ( cargv
[ 0 ], GeoIP_country_code
[ i
])) {
318 controlreply ( np
, "Invalid country." );
322 controlwall ( NO_OPER
, NL_BROADCASTS
, " %s / %s sent a cbroadcast %s : %s " , np
-> nick
, np
-> authname
, cargv
[ 0 ], cargv
[ 1 ]);
324 for ( i
= 0 ; i
< NICKHASHSIZE
; i
++)
325 for ( nip
= nicktable
[ i
]; nip
; nip
= nip
-> next
)
326 if ( nip
&& (( int )(( long ) nip
-> exts
[ ext
]) == target
))
327 controlnotice ( nip
, "(cBroadcast) %s " , cargv
[ 1 ]);
329 controlreply ( np
, "Message cbroadcasted." );