| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722 |
- /*
- * chancmds.c -- part of irc.mod
- * handles commands directly relating to channel interaction
- *
- */
- /* Do we have any flags that will allow us ops on a channel?
- */
- static struct chanset_t *get_channel(int idx, char *chname)
- {
- struct chanset_t *chan = NULL;
- if (chname && chname[0]) {
- chan = findchan_by_dname(chname);
- if (chan)
- return chan;
- else
- dprintf(idx, "No such channel.\n");
- } else {
- chname = dcc[idx].u.chat->con_chan;
- chan = findchan_by_dname(chname);
- if (chan)
- return chan;
- else
- dprintf(idx, "Invalid console channel.\n");
- }
- return 0;
- }
- /* Do we have any flags that will allow us ops on a channel?
- */
- static int has_op(int idx, struct chanset_t *chan)
- {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_OP)) {
- dprintf(idx, "No such channel.\n");
- return 0;
- }
- if (chk_op(user, chan))
- return 1;
- dprintf(idx, "You are not a channel op on %s.\n", chan->dname);
- return 0;
- }
- /* Finds a nick of the handle. Returns m->nick if
- * the nick was found, otherwise NULL (Sup 1Nov2000)
- */
- static char *getnick(char *handle, struct chanset_t *chan)
- {
- char s[UHOSTLEN] = "";
- struct userrec *u = NULL;
- for (register memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- if ((u = get_user_by_host(s)) && !egg_strcasecmp(u->handle, handle))
- return m->nick;
- }
- return NULL;
- }
- static void cmd_act(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: act [channel] <action>\n");
- return;
- }
- char *chname = NULL;
- struct chanset_t *chan = NULL;
- if (strchr(CHANMETA, par[0]) != NULL)
- chname = newsplit(&par);
- else
- chname = 0;
- chan = get_channel(idx, chname);
- if (!chan || !has_op(idx, chan))
- return;
- memberlist *m = ismember(chan, botname);
- if (!m) {
- dprintf(idx, "Cannot say to %s: I'm not on that channel.\n", chan->dname);
- return;
- }
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if ((chan->channel.mode & CHANMODER) && !me_op(chan) && !me_voice(chan)) {
- dprintf(idx, "Cannot say to %s: It is moderated.\n", chan->dname);
- return;
- }
- putlog(LOG_CMDS, "*", "#%s# (%s) act %s", dcc[idx].nick,
- chan->dname, par);
- dprintf(DP_HELP, "PRIVMSG %s :\001ACTION %s\001\n",
- chan->name, par);
- dprintf(idx, "Action to %s: %s\n", chan->dname, par);
- }
- static void cmd_msg(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: msg <nick> <message>\n");
- return;
- }
- char *nick = newsplit(&par);
- putlog(LOG_CMDS, "*", "#%s# msg %s %s", dcc[idx].nick, nick, par);
- dprintf(DP_HELP, "PRIVMSG %s :%s\n", nick, par);
- dprintf(idx, "Msg to %s: %s\n", nick, par);
- }
- static void cmd_say(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: say [channel] <message>\n");
- return;
- }
- char *chname = NULL;
- struct chanset_t *chan = NULL;
- if (strchr(CHANMETA, par[0]) != NULL)
- chname = newsplit(&par);
- else
- chname = 0;
- chan = get_channel(idx, chname);
- if (!chan || !has_op(idx, chan))
- return;
- memberlist *m = ismember(chan, botname);
- if (!m) {
- dprintf(idx, "Cannot say to %s: I'm not on that channel.\n", chan->dname);
- return;
- }
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if ((chan->channel.mode & CHANMODER) && !me_op(chan) && !me_voice(chan)) {
- dprintf(idx, "Cannot say to %s: It is moderated.\n", chan->dname);
- return;
- }
- putlog(LOG_CMDS, "*", "#%s# (%s) say %s", dcc[idx].nick, chan->dname, par);
- dprintf(DP_HELP, "PRIVMSG %s :%s\n", chan->name, par);
- dprintf(idx, "Said to %s: %s\n", chan->dname, par);
- }
- static void cmd_swhois(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: swhois [server/nick] nick\n");
- return;
- }
- putlog(LOG_CMDS, "*", "#%s# swhois %s", dcc[idx].nick, par);
- if (!server_online) {
- dprintf(idx, "I am currently not connected!\n");
- return;
- }
- char *server = newsplit(&par), *nick = NULL;
- if (par[0])
- nick = newsplit(&par);
- strlcpy(dcc[idx].whois, nick ? nick : server, UHOSTLEN);
- dprintf(DP_SERVER, "WHOIS %s %s\n", server, nick ? nick : "");
- }
- static void cmd_kickban(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: kickban [channel|*] [-|@]<nick> [reason]\n");
- return;
- }
- struct chanset_t *chan = NULL;
- char *chname = NULL;
- bool all = 0;
- if (par[0] == '*' && par[1] == ' ') {
- all = 1;
- newsplit(&par);
- } else {
- if (strchr(CHANMETA, par[0]) != NULL)
- chname = newsplit(&par);
- else
- chname = 0;
- chan = get_channel(idx, chname);
- if (!chan || !has_op(idx, chan))
- return;
- }
- putlog(LOG_CMDS, "*", "#%s# (%s) kickban %s", dcc[idx].nick, all ? "*" : chan->dname, par);
- char *nick = newsplit(&par), bantype = 0;
- if ((nick[0] == '@') || (nick[0] == '-')) {
- bantype = nick[0];
- nick++;
- }
- if (match_my_nick(nick)) {
- dprintf(idx, "I'm not going to kickban myself.\n");
- return;
- }
- memberlist *m = NULL;
- char *s1 = NULL, s[UHOSTLEN] = "";
- struct userrec *u = NULL;
- if (all)
- chan = chanset;
- while (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_OP)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- return;
- }
- else if (!chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to %s\n", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- if (all) goto next;
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I can't help you now because I'm not a channel op"
- " on %s.\n", chan->dname);
- return;
- }
- m = ismember(chan, nick);
- if (!m) {
- if (all) goto next;
- dprintf(idx, "%s is not on %s\n", nick, chan->dname);
- return;
- }
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- u = get_user_by_host(s);
- get_user_flagrec(u, &victim, chan->dname);
-
- if ((chan_master(victim) || glob_master(victim)) &&
- !(glob_owner(user) || chan_owner(user))) {
- if (all) goto next;
- dprintf(idx, "%s is a %s master.\n", nick, chan->dname);
- return;
- }
- if (glob_bot(victim) && !(glob_owner(user) || chan_owner(user))) {
- if (all) goto next;
- dprintf(idx, "%s is another channel bot!\n", nick);
- return;
- }
- if (use_exempts && (u_match_mask(global_exempts,s) ||
- u_match_mask(chan->exempts, s))) {
- dprintf(idx, "%s is permanently exempted!\n", nick);
- return;
- }
- if (m->flags & CHANOP)
- add_mode(chan, '-', 'o', m->nick);
- check_exemptlist(chan, s);
- switch (bantype) {
- case '@':
- s1 = strchr(s, '@');
- s1 -= 3;
- s1[0] = '*';
- s1[1] = '!';
- s1[2] = '*';
- break;
- case '-':
- s1 = strchr(s, '!');
- s1[1] = '*';
- s1--;
- s1[0] = '*';
- break;
- default:
- s1 = quickban(chan, m->userhost);
- break;
- }
- if (bantype == '@' || bantype == '-')
- do_mask(chan, chan->channel.ban, s1, 'b');
- if (!par[0])
- par = "requested";
- dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, m->nick, bankickprefix, par);
- m->flags |= SENTKICK;
- u_addmask('b', chan, s1, dcc[idx].nick, par, now + (60 * chan->ban_time), 0);
- dprintf(idx, "Kick-banned %s on %s.\n", nick, chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_voice(int idx, char *par)
- {
- char *nick = newsplit(&par);
- struct chanset_t *chan = NULL;
- bool all = 0;
- if (par[0] == '*' && !par[1]) {
- all = 1;
- newsplit(&par);
- } else {
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- }
- char s[UHOSTLEN] = "";
- memberlist *m = NULL;
- if (all)
- chan = chanset;
- putlog(LOG_CMDS, "*", "#%s# (%s) voice %s", dcc[idx].nick, all ? "*" : chan->dname , nick);
- while (chan) {
- if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
- if (all) goto next;
- dprintf(idx, "Usage: voice <nick> [channel|*]\n");
- return;
- }
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_VOICE)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- return;
- }
- else if (!chk_voice(user, chan) && !chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to voice on %s\n", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- if (all) goto next;
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I can't help you now because I'm not a chan op on %s.\n",
- chan->dname);
- return;
- }
- m = ismember(chan, nick);
- if (!m) {
- if (all) goto next;
- dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
- return;
- }
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- add_mode(chan, '+', 'v', nick);
- dprintf(idx, "Gave voice to %s on %s\n", nick, chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_devoice(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- char *nick = newsplit(&par);
- bool all = 0;
- if (par[0] == '*' && !par[1]) {
- all = 1;
- newsplit(&par);
- } else {
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- }
- memberlist *m = NULL;
- if (all)
- chan = chanset;
- putlog(LOG_CMDS, "*", "#%s# (%s) devoice %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
- while (chan) {
- if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
- if (all) goto next;
- dprintf(idx, "Usage: devoice <nick> [channel|*]\n");
- return;
- }
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_VOICE)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- return;
- }
- else if (!chk_voice(user, chan) && !chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to devoice on %s\n", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- if (all) goto next;
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I can't do that right now I'm not a chan op on %s",
- chan->dname);
- return;
- }
- m = ismember(chan, nick);
- if (!m) {
- if (all) goto next;
- dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
- return;
- }
- add_mode(chan, '-', 'v', nick);
- dprintf(idx, "Devoiced %s on %s\n", nick, chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_op(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- char *nick = newsplit(&par);
- bool all = 0;
- if (par[0] == '*' && !par[1]) {
- all = 1;
- newsplit(&par);
- } else {
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- }
- char s[UHOSTLEN] = "";
- memberlist *m = NULL;
- struct userrec *u = NULL;
- if (all)
- chan = chanset;
- putlog(LOG_CMDS, "*", "#%s# (%s) op %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
- while (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
- if (all) goto next;
- dprintf(idx, "Usage: op <nick> [channel|*]\n");
- return;
- }
- if (privchan(user, chan, PRIV_OP)) {
- if (!all)
- dprintf(idx, "No such channel.\n");
- goto next;
- }
- else if (!chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to op on %s\n", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- if (all) goto next;
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I can't help you now because I'm not a chan op on %s.\n",
- chan->dname);
- return;
- }
- m = ismember(chan, nick);
- if (!m) {
- if (all) goto next;
- dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
- return;
- }
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- u = get_user_by_host(s);
- get_user_flagrec(u, &victim, chan->dname);
- if (chk_deop(victim)) {
- dprintf(idx, "%s is currently being auto-deopped on %s.\n", m->nick, chan->dname);
- if (all) goto next;
- return;
- }
- if (channel_bitch(chan) && !chk_op(victim, chan)) {
- dprintf(idx, "%s is not a registered op on %s.\n", m->nick, chan->dname);
- if (all) goto next;
- return;
- }
- if (do_op(nick, chan, 0, 1)) {
- dprintf(idx, "Gave op to %s on %s.\n", nick, chan->dname);
- stats_add(u, 0, 1);
- }
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_mdop(int idx, char *par)
- {
- char *p = NULL, *chname = NULL;
- int force_bots = 0,
- force_alines = 0,
- force_slines = 0,
- force_overlap = 0;
- int overlap = 0,
- bitch = 0,
- simul = 0;
- int needed_deops,
- max_deops,
- bots,
- deops,
- sdeops;
- memberlist **chanbots = NULL,
- **targets = NULL,
- *m = NULL;
- int chanbotcount = 0,
- targetcount = 0,
- tpos = 0,
- bpos = 0,
- i;
- struct chanset_t *chan = NULL;
- char work[1024] = "";
-
- putlog(LOG_CMDS, "*", "#%s# mdop %s", dcc[idx].nick, par);
- if (strchr(CHANMETA, par[0]) != NULL)
- chname = newsplit(&par);
- else
- chname = 0;
- chan = get_channel(idx, chname);
-
- if (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (!shouldjoin(chan) || !channel_active(chan)) {
- dprintf(idx, "I'm not on %s\n", chan->dname);
- return;
- }
- if (channel_pending(chan)) {
- dprintf(idx, "Channel pending.\n");
- return;
- }
- if (!glob_owner(user) && !chan_owner(user)) {
- dprintf(idx, "You do not have mdop access for %s\n", chan->dname);
- return;
- }
- }
- if (!chan || !chname[0]) {
- dprintf(idx, "Usage: mdop <#channel> [bots=n] [alines=n] [slines=n] [overlap=n] [bitch] [simul]\n");
- return;
- }
- targets = (memberlist **) my_calloc(1, chan->channel.members * sizeof(memberlist *));
- chanbots = (memberlist **) my_calloc(1, chan->channel.members * sizeof(memberlist *));
- ContextNote("!mdop!");
- for (m = chan->channel.member; m; m = m->next)
- if (m->flags & CHANOP) {
- ContextNote(m->nick);
- if (!m->user)
- targets[targetcount++] = m;
- else if (m->user->bot && (m->user->flags & USER_OP)
- && (strcmp(conf.bot->nick, m->user->handle))
- && (nextbot(m->user->handle) >= 0))
- chanbots[chanbotcount++] = m;
- else if (!(m->user->flags & USER_OP))
- targets[targetcount++] = m;
- }
- if (!chanbotcount) {
- dprintf(idx, "No bots opped on %s\n", chan->name);
- free(targets);
- free(chanbots);
- return;
- }
- if (!targetcount) {
- dprintf(idx, "Noone to deop on %s\n", chan->name);
- free(targets);
- free(chanbots);
- return;
- }
- while (par && par[0]) {
- p = newsplit(&par);
- if (!strncmp(p, "bots=", 5)) {
- p += 5;
- force_bots = atoi(p);
- if ((force_bots < 1) || (force_bots > chanbotcount)) {
- dprintf(idx, "bots must be within 1-%i\n", chanbotcount);
- free(targets);
- free(chanbots);
- return;
- }
- } else if (!strncmp(p, "alines=", 7)) {
- p += 7;
- force_alines = atoi(p);
- if ((force_alines < 1) || (force_alines > 5)) {
- dprintf(idx, "alines must be within 1-5\n");
- free(targets);
- free(chanbots);
- return;
- }
- } else if (!strncmp(p, "slines=", 7)) {
- p += 7;
- force_slines = atoi(p);
- if ((force_slines < 1) || (force_slines > 6)) {
- dprintf(idx, "slines must be within 1-6\n");
- free(targets);
- free(chanbots);
- return;
- }
- } else if (!strncmp(p, "overlap=", 8)) {
- p += 8;
- force_overlap = atoi(p);
- if ((force_overlap < 1) || (force_overlap > 8)) {
- dprintf(idx, "overlap must be within 1-8\n");
- free(targets);
- free(chanbots);
- return;
- }
- } else if (!strcmp(p, "bitch")) {
- bitch = 1;
- } else if (!strcmp(p, "simul")) {
- simul = 1;
- } else {
- dprintf(idx, "Unrecognized mdop option %s\n", p);
- free(targets);
- free(chanbots);
- return;
- }
- }
- overlap = (force_overlap ? force_overlap : 2);
- needed_deops = (overlap * targetcount);
- max_deops = ((force_bots ? force_bots : chanbotcount) * (force_alines ? force_alines : 5) * 4);
- if (needed_deops > max_deops) {
- if (overlap == 1)
- dprintf(idx, "Not enough bots.\n");
- else
- dprintf(idx, "Not enough bots. Try with overlap=1\n");
- free(targets);
- free(chanbots);
- return;
- }
- /* ok it's possible... now let's figure out how */
- if (force_bots && force_alines) {
- /* not much choice... overlap should not autochange */
- bots = force_bots;
- deops = force_alines * 4;
- } else {
- if (force_bots) {
- /* calc needed deops per bot */
- bots = force_bots;
- deops = (needed_deops + (bots - 1)) / bots;
- } else if (force_alines) {
- deops = force_alines * 4;
- bots = (needed_deops + (deops - 1)) / deops;
- } else {
- deops = 12;
- bots = (needed_deops + (deops - 1)) / deops;
- if (bots > chanbotcount) {
- deops = 16;
- bots = (needed_deops + (deops - 1)) / deops;
- }
- if (bots > chanbotcount) {
- deops = 20;
- bots = (needed_deops + (deops - 1)) / deops;
- }
- if (bots > chanbotcount) {
- putlog(LOG_MISC, "*", "Totally fucked calculations in cmd_mdop. this CAN'T happen.");
- dprintf(idx, "Something's wrong... bug the coder\n");
- free(targets);
- free(chanbots);
- return;
- }
- }
- }
- if (force_slines)
- sdeops = force_slines * 4;
- else
- sdeops = 20;
- if (sdeops < deops)
- sdeops = deops;
- dprintf(idx, "Mass deop of %s\n", chan->name);
- dprintf(idx, " %d bots used for deop\n", bots);
- dprintf(idx, " %d assumed deops per participating bot\n", deops);
- dprintf(idx, " %d max deops per participating bot\n", sdeops);
- dprintf(idx, " %d assumed deops per target nick\n", overlap);
- /* now use bots/deops to distribute nicks to deop */
- while (bots) {
- if (!simul)
- sprintf(work, "dp %s", chan->name);
- else
- work[0] = 0;
- for (i = 0; i < deops; i++) {
- strcat(work, " ");
- strcat(work, targets[tpos]->nick);
- tpos++;
- if (tpos >= targetcount)
- tpos = 0;
- }
- if (sdeops > deops) {
- int atpos;
- atpos = tpos;
- for (i = 0; i < (sdeops - deops); i++) {
- strcat(work, " ");
- strcat(work, targets[atpos]->nick);
- atpos++;
- if (atpos >= targetcount)
- atpos = 0;
- }
- }
- if (simul)
- dprintf(idx, "%s deops%s\n", chanbots[bpos]->nick, work);
- else
- botnet_send_zapf(nextbot(chanbots[bpos]->user->handle), conf.bot->nick, chanbots[bpos]->user->handle, work);
- bots--;
- bpos++;
- }
- if (bitch && !simul && chan) {
- chan->status |= CHAN_BITCH;
- do_chanset(NULL, chan, "+bitch", DO_LOCAL | DO_NET);
- }
- free(targets);
- free(chanbots);
- return;
- }
- void mdop_request(char *botnick, char *code, char *par)
- {
- char *chname = NULL, *p = NULL;
- char work[2048] = "";
- chname = newsplit(&par);
- work[0] = 0;
- while (par[0]) {
- int cnt = 0;
- strcat(work, "MODE ");
- strcat(work, chname);
- strcat(work, " -oooo");
- while ((cnt < 4) && par[0]) {
- p = newsplit(&par);
- strcat(work, " ");
- strcat(work, p);
- cnt++;
- }
- strcat(work, "\r");
- strcat(work, "\n");
- }
- tputs(serv, work, strlen(work));
- }
- static void cmd_deop(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- char *nick = newsplit(&par);
- bool all = 0;
- if (par[0] == '*' && !par[1]) {
- all = 1;
- newsplit(&par);
- } else {
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- }
- char s[UHOSTLEN] = "";
- memberlist *m = NULL;
- struct userrec *u = NULL;
- if (all)
- chan = chanset;
- putlog(LOG_CMDS, "*", "#%s# (%s) deop %s", dcc[idx].nick, all ? "*" : chan->dname, nick);
- while (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (!nick[0] && !(nick = getnick(dcc[idx].nick, chan))) {
- if (all) goto next;
- dprintf(idx, "Usage: deop <nick> [channel|*]\n");
- return;
- }
- if (privchan(user, chan, PRIV_OP)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- }
- else if (!chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to deop on %s\n", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- if (all) goto next;
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I can't help you now because I'm not a chan op on %s.\n",
- chan->dname);
- return;
- }
- m = ismember(chan, nick);
- if (!m) {
- if (all) goto next;
- dprintf(idx, "%s is not on %s.\n", nick, chan->dname);
- return;
- }
- if (match_my_nick(nick)) {
- if (all) goto next;
- dprintf(idx, "I'm not going to deop myself.\n");
- return;
- }
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- u = get_user_by_host(s);
- get_user_flagrec(u, &victim, chan->dname);
- if ((chan_master(victim) || glob_master(victim)) &&
- !(chan_owner(user) || glob_owner(user))) {
- dprintf(idx, "%s is a master for %s.\n", m->nick, chan->dname);
- if (all) goto next;
- return;
- }
- if ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) &&
- !(chan_master(user) || glob_master(user))) {
- dprintf(idx, "%s has the op flag for %s.\n", m->nick, chan->dname);
- if (all) goto next;
- return;
- }
- add_mode(chan, '-', 'o', nick);
- dprintf(idx, "Deopped %s on %s.\n", nick, chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_kick(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: kick [channel|*] <nick> [reason]\n");
- return;
- }
- struct chanset_t *chan = NULL;
- char *chname = NULL;
- bool all = 0;
- if (par[0] == '*' && par[1] == ' ') {
- all = 1;
- newsplit(&par);
- } else {
- if (strchr(CHANMETA, par[0]) != NULL)
- chname = newsplit(&par);
- else
- chname = 0;
- chan = get_channel(idx, chname);
- if (!chan || !has_op(idx, chan))
- return;
- }
- putlog(LOG_CMDS, "*", "#%s# (%s) kick %s", dcc[idx].nick, all ? "*" : chan->dname, par);
- char *nick = newsplit(&par);
- if (!par[0])
- par = "request";
- if (match_my_nick(nick)) {
- dprintf(idx, "I'm not going to kick myself.\n");
- return;
- }
- char s[UHOSTLEN] = "";
- memberlist *m = NULL;
- struct userrec *u = NULL;
- if (all)
- chan = chanset;
- while (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_OP)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- return;
- }
- else if (!chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to kick on %s\n", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- if (all) goto next;
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I can't help you now because I'm not a channel op on %s.\n", chan->dname);
- return;
- }
- m = ismember(chan, nick);
- if (!m) {
- if (all) goto next;
- dprintf(idx, "%s is not on %s\n", nick, chan->dname);
- return;
- }
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- u = get_user_by_host(s);
- get_user_flagrec(u, &victim, chan->dname);
- if ((chan_op(victim) || (glob_op(victim) && !chan_deop(victim))) &&
- !(chan_master(user) || glob_master(user))) {
- if (all) goto next;
- dprintf(idx, "%s is a legal op.\n", nick);
- return;
- }
- if ((chan_master(victim) || glob_master(victim)) &&
- !(glob_owner(user) || chan_owner(user))) {
- if (all) goto next;
- dprintf(idx, "%s is a %s master.\n", nick, chan->dname);
- return;
- }
- if (glob_bot(victim) && !(glob_owner(user) || chan_owner(user))) {
- dprintf(idx, "%s is another channel bot!\n", nick);
- return;
- }
- dprintf(DP_SERVER, "KICK %s %s :%s%s\n", chan->name, m->nick, kickprefix, par);
- m->flags |= SENTKICK;
- dprintf(idx, "Kicked %s on %s.\n", nick, chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_getkey(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- putlog(LOG_CMDS, "*", "#%s getkey %s", dcc[idx].nick, par);
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_OP)) {
- dprintf(idx, "No such channel.\n");
- return;
- }
- else if (!chk_op(user, chan)) {
- dprintf(idx, "You don't have access for %s\n", chan->dname);
- return;
- }
- if (!(channel_pending(chan) || channel_active(chan))) {
- dprintf(idx, "I'm not on %s right now.\n", chan->dname);
- return;
- }
- if (!chan->channel.key[0])
- dprintf(idx, "%s has no key set.", chan->dname);
- else
- dprintf(idx, "Key for %s is: %s", chan->dname, chan->channel.key);
- if (chan->key_prot[0])
- dprintf(idx, " (Enforcing +k %s)", chan->key_prot);
- dprintf(idx, "\n");
- }
- static void cmd_mop(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- bool found = 0, all = 0;
- if (par[0] == '*' && !par[1]) {
- get_user_flagrec(dcc[idx].user, &user, NULL);
- if (!glob_owner(user)) {
- dprintf(idx, "You do not have access to mop '*'\n");
- return;
- }
- all = 1;
- chan = chanset;
- newsplit(&par);
- } else {
- if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
- chan = get_channel(idx, newsplit(&par));
- } else
- chan = get_channel(idx, "");
- }
- if (!chan && !all)
- return;
- putlog(LOG_CMDS, "*", "#%s# (%s) mop %s", dcc[idx].nick, all ? "*" : chan->dname, par);
- memberlist *m = NULL;
- char s[256] = "";
- while (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_OP)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- return;
- }
- if (!chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You are not a channel op on %s.\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- dprintf(idx, "I am not opped on %s.\n", chan->dname);
- return;
- }
- if (channel_active(chan) && !channel_pending(chan)) {
- for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
- if (!m->user) {
- sprintf(s, "%s!%s", m->nick, m->userhost);
- m->user = get_user_by_host(s);
- }
- if (m->user && u_pass_match(m->user, "-"))
- continue; /* dont op users without a pass */
- get_user_flagrec(m->user, &victim, chan->dname);
- if (!chan_hasop(m) && !glob_bot(victim) && chk_op(victim, chan)) {
- found++;
- dprintf(idx, "Gave op to '%s' as '%s' on %s\n", m->user->handle, m->nick, chan->dname);
- do_op(m->nick, chan, 0, 0);
- }
- }
- } else {
- if (!all)
- dprintf(idx, "Channel %s is not active or is pending.\n", chan->dname);
- return;
- }
- if (!found && !all)
- dprintf(idx, "No one to op on %s\n", chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_find(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: find <nick!ident@host.com> (wildcard * allowed)\n");
- return;
- }
- putlog(LOG_CMDS, "*", "#%s# find %s", dcc[idx].nick, par);
- struct chanset_t *chan = NULL, **cfound = NULL;
- memberlist *m = NULL, **found = NULL;
- struct userrec *u2 = NULL;
- int fcount = 0;
- bool tr = 0;
- /* make a list of members in found[] */
- for (chan = chanset; chan; chan = chan->next) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (!privchan(user, chan, PRIV_OP)) {
- for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
- char tmp[256] = "";
- sprintf(tmp, "%s!%s", m->nick, m->userhost ? m->userhost : "(null)");
- if (wild_match(par, tmp)) {
- fcount++;
- if (!found) {
- found = (memberlist **) my_calloc(1, sizeof(memberlist *) * 100);
- cfound = (struct chanset_t **) my_calloc(1, sizeof(struct chanset_t *) * 100);
- }
- found[fcount - 1] = m;
- cfound[fcount - 1] = chan;
- if (fcount == 100) {
- tr = 1;
- break;
- }
- }
- }
- }
- if (fcount == 100) {
- tr = 1;
- break;
- }
- }
- if (fcount) {
- char tmp[1024] = "";
- int findex, i;
- for (findex = 0; findex < fcount; findex++) {
- char check[500] = "";
- if (found[findex]) {
- sprintf(check, "%s!%s", found[findex]->nick, found[findex]->userhost);
- u2 = get_user_by_host(check);
- sprintf(tmp, "%s!%s %s%s%s on %s", found[findex]->nick, found[findex]->userhost,
- u2 ? "(user:" : "", u2 ? u2->handle : "", u2 ? ")" : "",
- cfound[findex]->name);
- for (i = findex + 1; i < fcount; i++) {
- if (found[i] && (!strcmp(found[i]->nick, found[findex]->nick))) {
- sprintf(tmp + strlen(tmp), ", %s", cfound[i]->name);
- found[i] = NULL;
- }
- }
- dprintf(idx, "%s\n", tmp);
- }
- }
- free(found);
- free(cfound);
- } else {
- dprintf(idx, "No matches for %s on any channels.\n", par);
- }
- if (tr)
- dprintf(idx, "(more than 100 matches; list truncated)\n");
- dprintf(idx, "--- Found %d matches.\n", fcount);
- }
- static void do_invite(int idx, char *par, bool op)
- {
- struct chanset_t *chan = NULL;
- memberlist *m = NULL;
- bool all = 0;
- char *nick = NULL;
- if (!par[0])
- par = dcc[idx].nick;
- nick = newsplit(&par);
- if (par[0] == '*' && !par[1]) {
- all = 1;
- newsplit(&par);
- } else {
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- }
- if (all)
- chan = chanset;
- putlog(LOG_CMDS, "*", "#%s# (%s) %s %s", dcc[idx].nick, all ? "*" : chan->dname, op ? "iop" : "invite", nick);
- while (chan) {
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (privchan(user, chan, PRIV_OP)) {
- if (all) goto next;
- dprintf(idx, "No such channel.\n");
- }
- else if (!chk_op(user, chan)) {
- if (all) goto next;
- dprintf(idx, "You don't have access to invite to %s\n", chan->dname);
- return;
- }
- if (!me_op(chan)) {
- if (all) goto next;
- if (chan->channel.mode & CHANINV) {
- dprintf(idx, "I can't help you now because I'm not a channel op on %s", chan->dname);
- return;
- }
- if (!channel_active(chan)) {
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- }
- m = ismember(chan, nick);
- if (m && !chan_issplit(m)) {
- if (all) goto next;
- dprintf(idx, "%s is already on %s!\n", nick, chan->dname);
- return;
- }
- cache_invite(chan, nick, NULL, NULL, op, 0);
- dprintf(idx, "Inviting %s to %s.\n", nick, chan->dname);
- next:;
- if (!all)
- chan = NULL;
- else
- chan = chan->next;
- }
- }
- static void cmd_invite(int idx, char *par)
- {
- do_invite(idx, par, 0);
- }
- #ifdef CACHE
- static void cmd_iop(int idx, char *par)
- {
- do_invite(idx, par, 1);
- }
- #endif /* CACHE */
- static void cmd_authed(int idx, char *par)
- {
- putlog(LOG_CMDS, "*", "#%s# authed", dcc[idx].nick);
- dprintf(idx, "Authed:\n");
- for (int i = 0; i < auth_total; i++) {
- if (auth[i].authed)
- dprintf(idx, " %d%s. %s!%s at %li\n", i, auth[i].bd ? "x" : "", auth[i].nick, auth[i].host, auth[i].authtime);
- }
- }
- static void cmd_channel(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- chan = get_channel(idx, par);
- if (!chan || !has_op(idx, chan))
- return;
- char handle[HANDLEN + 1] = "", s[UHOSTLEN] = "", s1[UHOSTLEN] = "", atrflag = 0, chanflag[2] = "";
- memberlist *m = NULL;
- size_t maxnicklen, maxhandlen;
- char format[81] = "";
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- putlog(LOG_CMDS, "*", "#%s# (%s) channel", dcc[idx].nick, chan->dname);
- strlcpy(s, getchanmode(chan), sizeof s);
- if (channel_pending(chan)) {
- egg_snprintf(s1, sizeof s1, "%s %s", IRC_PROCESSINGCHAN, chan->dname);
- } else if (channel_active(chan)) {
- egg_snprintf(s1, sizeof s1, "%s %s", IRC_CHANNEL, chan->dname);
- } else {
- egg_snprintf(s1, sizeof s1, "%s %s", IRC_DESIRINGCHAN, chan->dname);
- }
- dprintf(idx, "%s, %d member%s, mode %s:\n", s1, chan->channel.members,
- chan->channel.members == 1 ? "" : "s", s);
- if (chan->channel.topic)
- dprintf(idx, "%s: %s\n", IRC_CHANNELTOPIC, chan->channel.topic);
- if (channel_active(chan)) {
- /* find max nicklen and handlen */
- maxnicklen = maxhandlen = 0;
- for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
- if (strlen(m->nick) > maxnicklen)
- maxnicklen = strlen(m->nick);
- if (m->user)
- if (strlen(m->user->handle) > maxhandlen)
- maxhandlen = strlen(m->user->handle);
- }
- if (maxnicklen < 9) maxnicklen = 9;
- if (maxhandlen < 9) maxhandlen = 9;
-
- dprintf(idx, "(n = owner, m = master, o = op, d = deop, b = bot) CAP:global\n");
- egg_snprintf(format, sizeof format, " %%-%us %%-%us %%-6s %%-4s %%-5s %%s\n",
- maxnicklen, maxhandlen);
- dprintf(idx, format, "NICKNAME", "HANDLE", " JOIN", " HOPS", "IDLE", "USER@HOST");
- for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
- if (m->joined > 0) {
- if ((now - (m->joined)) > 86400)
- egg_strftime(s, 6, "%d%b", gmtime(&(m->joined)));
- else
- egg_strftime(s, 6, "%H:%M", gmtime(&(m->joined)));
- } else
- strlcpy(s, " --- ", sizeof s);
- if (m->user == NULL) {
- egg_snprintf(s1, sizeof s1, "%s!%s", m->nick, m->userhost);
- m->user = get_user_by_host(s1);
- }
- if (m->user == NULL)
- strlcpy(handle, "*", sizeof handle);
- else
- strlcpy(handle, m->user->handle, sizeof handle);
- get_user_flagrec(m->user, &user, chan->dname);
- /* Determine status char to use */
- if (glob_bot(user) && (glob_op(user)|| chan_op(user)))
- atrflag = 'B';
- else if (glob_bot(user))
- atrflag = 'b';
- else if (glob_owner(user))
- atrflag = 'N';
- else if (chan_owner(user))
- atrflag = 'n';
- else if (glob_master(user))
- atrflag = 'M';
- else if (chan_master(user))
- atrflag = 'm';
- else if (glob_deop(user))
- atrflag = 'D';
- else if (chan_deop(user))
- atrflag = 'd';
- else if (glob_autoop(user))
- atrflag = 'A';
- else if (chan_autoop(user))
- atrflag = 'a';
- else if (glob_op(user) && !privchan(user, chan, PRIV_OP))
- atrflag = 'O';
- else if (chan_op(user) && !privchan(user, chan, PRIV_OP))
- atrflag = 'o';
- else if (glob_quiet(user))
- atrflag = 'Q';
- else if (chan_quiet(user))
- atrflag = 'q';
- else if (glob_voice(user) && !privchan(user, chan, PRIV_VOICE))
- atrflag = 'V';
- else if (chan_voice(user) && !privchan(user, chan, PRIV_VOICE))
- atrflag = 'v';
- else if (glob_kick(user))
- atrflag = 'K';
- else if (chan_kick(user))
- atrflag = 'k';
- else if (glob_wasoptest(user))
- atrflag = 'W';
- else if (chan_wasoptest(user))
- atrflag = 'w';
- else if (glob_exempt(user))
- atrflag = 'E';
- else if (chan_exempt(user))
- atrflag = 'e';
- else
- atrflag = ' ';
- if (chan_hasop(m))
- chanflag[1] = '@';
- else if (chan_hasvoice(m))
- chanflag[1] = '+';
- else
- chanflag[1] = ' ';
- if (m->flags & OPER)
- chanflag[0] = 'O';
- else
- chanflag[0] = ' ';
- if (chan_issplit(m)) {
- egg_snprintf(format, sizeof format,
- "%%c%%c%%-%us %%-%us %%d %%s %%c <- netsplit, %%lus\n",
- maxnicklen, maxhandlen);
- dprintf(idx, format, chanflag[0],chanflag[1], m->nick, handle, s, m->hops, atrflag,
- now - (m->split));
- } else if (!rfc_casecmp(m->nick, botname)) {
- egg_snprintf(format, sizeof format,
- "%%c%%c%%-%us %%-%us %%s %%c <- it's me!\n",
- maxnicklen, maxhandlen);
- dprintf(idx, format, chanflag[0], chanflag[1], m->nick, handle, s, atrflag);
- } else {
- /* Determine idle time */
- if (now - (m->last) > 86400)
- egg_snprintf(s1, sizeof s1, "%2lid", ((now - (m->last)) / 86400));
- else if (now - (m->last) > 3600)
- egg_snprintf(s1, sizeof s1, "%2lih", ((now - (m->last)) / 3600));
- else if (now - (m->last) > 180)
- egg_snprintf(s1, sizeof s1, "%2lim", ((now - (m->last)) / 60));
- else
- strlcpy(s1, " ", sizeof s1);
- egg_snprintf(format, sizeof format, "%%c%%c%%-%us %%-%us %%s %%c %%d %%s %%s\n",
- maxnicklen, maxhandlen);
- dprintf(idx, format, chanflag[0], chanflag[1], m->nick, handle, s, atrflag, m->hops,
- s1, m->userhost);
- }
- if (chan_fakeop(m))
- dprintf(idx, " (%s)\n", IRC_FAKECHANOP);
- if (chan_sentop(m))
- dprintf(idx, " (%s)\n", IRC_PENDINGOP);
- if (chan_sentdeop(m))
- dprintf(idx, " (%s)\n", IRC_PENDINGDEOP);
- if (chan_sentkick(m))
- dprintf(idx, " (%s)\n", IRC_PENDINGKICK);
- }
- }
- dprintf(idx, "%s\n", IRC_ENDCHANINFO);
- }
- static void cmd_topic(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- if (par[0] && (strchr(CHANMETA, par[0]) != NULL)) {
- chan = get_channel(idx, newsplit(&par));
- } else
- chan = get_channel(idx, "");
- if (!chan || !has_op(idx, chan))
- return;
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (!channel_active(chan)) {
- dprintf(idx, "I'm not on %s right now!\n", chan->dname);
- return;
- }
- if (!par[0]) {
- if (chan->channel.topic) {
- dprintf(idx, "The topic for %s is: %s\n", chan->dname,
- chan->channel.topic);
- } else {
- dprintf(idx, "No topic is set for %s\n", chan->dname);
- }
- } else if (channel_optopic(chan) && !me_op(chan)) {
- dprintf(idx, "I'm not a channel op on %s and the channel %s",
- "is +t.\n", chan->dname);
- } else {
- dprintf(DP_SERVER, "TOPIC %s :%s\n", chan->name, par);
- dprintf(idx, "Changing topic...\n");
- putlog(LOG_CMDS, "*", "#%s# (%s) topic %s", dcc[idx].nick,
- chan->dname, par);
- }
- }
- static void cmd_resetbans(int idx, char *par)
- {
- struct chanset_t *chan = get_channel(idx, newsplit(&par));
- if (!chan || !has_op(idx, chan))
- return;
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- putlog(LOG_CMDS, "*", "#%s# (%s) resetbans", dcc[idx].nick, chan->dname);
- dprintf(idx, "Resetting bans on %s...\n", chan->dname);
- resetbans(chan);
- }
- static void cmd_resetexempts(int idx, char *par)
- {
- struct chanset_t *chan = get_channel(idx, newsplit(&par));
- if (!chan || !has_op(idx, chan))
- return;
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- putlog(LOG_CMDS, "*", "#%s# (%s) resetexempts", dcc[idx].nick, chan->dname);
- dprintf(idx, "Resetting exempts on %s...\n", chan->dname);
- resetexempts(chan);
- }
- static void cmd_resetinvites(int idx, char *par)
- {
- struct chanset_t *chan = get_channel(idx, newsplit(&par));
- if (!chan || !has_op(idx, chan))
- return;
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- putlog(LOG_CMDS, "*", "#%s# (%s) resetinvites", dcc[idx].nick, chan->dname);
- dprintf(idx, "Resetting resetinvites on %s...\n", chan->dname);
- resetinvites(chan);
- }
- static void cmd_adduser(int idx, char *par)
- {
- if ((!par[0]) || ((par[0] =='!') && (!par[1]))) {
- dprintf(idx, "Usage: adduser <nick> [handle]\n");
- return;
- }
- char *nick = NULL, *hand = NULL;
- struct chanset_t *chan = NULL;
- struct userrec *u = NULL;
- memberlist *m = NULL;
- char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", s2[MAXPASSLEN + 1] = "", s3[MAXPASSLEN + 1] = "", tmp[50] = "";
- int atr = dcc[idx].user ? dcc[idx].user->flags : 0;
- bool statichost = 0;
- char *p1 = s1;
- putlog(LOG_CMDS, "*", "#%s# adduser %s", dcc[idx].nick, par);
- nick = newsplit(&par);
- /* This flag allows users to have static host (added by drummer, 20Apr99) */
- if (nick[0] == '!') {
- statichost = 1;
- nick++;
- }
- if (!par[0]) {
- hand = nick;
- } else {
- bool ok = 1;
- for (char *p = par; *p; p++)
- if ((*p <= 32) || (*p >= 127))
- ok = 0;
- if (!ok) {
- dprintf(idx, "You can't have strange characters in a nick.\n");
- return;
- } else if (strchr("-,+*=:!.@#;$", par[0]) != NULL) {
- dprintf(idx, "You can't start a nick with '%c'.\n", par[0]);
- return;
- }
- hand = par;
- }
- for (chan = chanset; chan; chan = chan->next) {
- m = ismember(chan, nick);
- if (m)
- break;
- }
- if (!m) {
- dprintf(idx, "%s is not on any channels I monitor\n", nick);
- return;
- }
- if (strlen(hand) > HANDLEN)
- hand[HANDLEN] = 0;
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- if ((u = get_user_by_host(s))) {
- dprintf(idx, "%s is already known as %s.\n", nick, u->handle);
- return;
- }
- u = get_user_by_handle(userlist, hand);
- if (u && (u->flags & (USER_OWNER | USER_MASTER)) &&
- !(atr & USER_OWNER) && egg_strcasecmp(dcc[idx].nick, hand)) {
- dprintf(idx, "You can't add hostmasks to the bot owner/master.\n");
- return;
- }
- if (!statichost)
- maskhost(s, s1);
- else {
- strlcpy(s1, s, sizeof s1);
- p1 = strchr(s1, '!');
- if (strchr("~^+=-", p1[1]))
- p1[1] = '?';
- p1--;
- p1[0] = '*';
- }
- if (!u) {
- userlist = adduser(userlist, hand, p1, "-", USER_DEFAULT, 0);
- u = get_user_by_handle(userlist, hand);
- sprintf(tmp, "%li %s", now, dcc[idx].nick);
- set_user(&USERENTRY_ADDED, u, tmp);
- make_rand_str(s2, MAXPASSLEN);
- set_user(&USERENTRY_PASS, u, s2);
- make_rand_str(s3, MAXPASSLEN);
- set_user(&USERENTRY_SECPASS, u, s3);
- dprintf(idx, "Added [%s]%s with no flags.\n", hand, p1);
- dprintf(idx, "%s's initial password set to \002%s\002\n", hand, s2);
- dprintf(idx, "%s's initial secpass set to \002%s\002\n", hand, s3);
- } else {
- dprintf(idx, "Added hostmask %s to %s.\n", p1, u->handle);
- addhost_by_handle(hand, p1);
- get_user_flagrec(u, &user, chan->dname);
- check_this_user(hand, 0, NULL);
- }
- }
- static void cmd_deluser(int idx, char *par)
- {
- if (!par[0]) {
- dprintf(idx, "Usage: deluser <nick>\n");
- return;
- }
- char *nick = NULL, s[UHOSTLEN] = "", *added = NULL;
- struct chanset_t *chan = NULL;
- memberlist *m = NULL;
- struct userrec *u = NULL;
- nick = newsplit(&par);
- for (chan = chanset; chan; chan = chan->next) {
- m = ismember(chan, nick);
- if (m)
- break;
- }
- if (!m) {
- dprintf(idx, "%s is not on any channels I monitor\n", nick);
- return;
- }
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- egg_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
- if (!(u = get_user_by_host(s))) {
- dprintf(idx, "%s is not a valid user.\n", nick);
- return;
- }
- added = (char *) get_user(&USERENTRY_ADDED, u);
- newsplit(&added);
- get_user_flagrec(u, &victim, NULL);
- if (isowner(u->handle)) {
- dprintf(idx, "You can't remove a permanent bot owner!\n");
- } else if (glob_admin(victim) && !isowner(dcc[idx].nick)) {
- dprintf(idx, "You can't remove an admin!\n");
- } else if (glob_owner(victim)) {
- dprintf(idx, "You can't remove a bot owner!\n");
- } else if (chan_owner(victim) && !glob_owner(user)) {
- dprintf(idx, "You can't remove a channel owner!\n");
- } else if (chan_master(victim) && !(glob_owner(user) || chan_owner(user))) {
- dprintf(idx, "You can't remove a channel master!\n");
- } else if (glob_bot(victim) && !glob_owner(user)) {
- dprintf(idx, "You can't remove a bot!\n");
- } else if (!glob_master(user) && egg_strcasecmp(dcc[idx].nick, added)) {
- dprintf(idx, "Sorry, you may not delete this user as you did not add them.\n");
- } else {
- char buf[HANDLEN + 1] = "";
- strlcpy(buf, u->handle, sizeof buf);
- buf[HANDLEN] = 0;
- if (deluser(u->handle)) {
- dprintf(idx, "Deleted %s.\n", buf); /* ?!?! :) */
- putlog(LOG_CMDS, "*", "#%s# deluser %s [%s]", dcc[idx].nick, nick, buf);
- } else {
- dprintf(idx, "Failed.\n");
- }
- }
- }
- static void cmd_reset(int idx, char *par)
- {
- struct chanset_t *chan = NULL;
- if (par[0]) {
- chan = findchan_by_dname(par);
- if (chan)
- get_user_flagrec(dcc[idx].user, &user, chan->dname);
- if (!chan || privchan(user, chan, PRIV_OP)) {
- dprintf(idx, "%s\n", IRC_NOMONITOR);
- } else {
- get_user_flagrec(dcc[idx].user, &user, par);
- if (!glob_master(user) && !chan_master(user)) {
- dprintf(idx, "You are not a master on %s.\n", chan->dname);
- } else if (!channel_active(chan)) {
- dprintf(idx, "I'm not on %s at the moment!\n", chan->dname);
- } else {
- putlog(LOG_CMDS, "*", "#%s# reset %s", dcc[idx].nick, par);
- dprintf(idx, "Resetting channel info for %s...\n", chan->dname);
- reset_chan_info(chan);
- }
- }
- } else if (!(dcc[idx].user->flags & USER_MASTER)) {
- dprintf(idx, "You are not a Bot Master.\n");
- } else {
- putlog(LOG_CMDS, "*", "#%s# reset all", dcc[idx].nick);
- dprintf(idx, "Resetting channel info for all channels...\n");
- for (chan = chanset; chan; chan = chan->next) {
- if (channel_active(chan))
- reset_chan_info(chan);
- }
- }
- }
- static cmd_t irc_dcc[] =
- {
- {"act", "o|o", (Function) cmd_act, NULL, LEAF},
- {"adduser", "m|m", (Function) cmd_adduser, NULL, LEAF},
- {"authed", "n", (Function) cmd_authed, NULL, LEAF},
- {"channel", "o|o", (Function) cmd_channel, NULL, LEAF},
- {"deluser", "m|m", (Function) cmd_deluser, NULL, LEAF},
- {"deop", "o|o", (Function) cmd_deop, NULL, LEAF},
- {"devoice", "o|o", (Function) cmd_devoice, NULL, LEAF},
- {"getkey", "o|o", (Function) cmd_getkey, NULL, LEAF},
- {"find", "", (Function) cmd_find, NULL, LEAF},
- {"invite", "o|o", (Function) cmd_invite, NULL, LEAF},
- #ifdef CACHE
- {"iop", "o|o", (Function) cmd_iop, NULL, LEAF},
- #endif /* CACHE */
- {"kick", "o|o", (Function) cmd_kick, NULL, LEAF},
- {"kickban", "o|o", (Function) cmd_kickban, NULL, LEAF},
- {"mdop", "n|n", (Function) cmd_mdop, NULL, LEAF},
- {"mop", "n|m", (Function) cmd_mop, NULL, LEAF},
- {"msg", "o", (Function) cmd_msg, NULL, LEAF},
- {"op", "o|o", (Function) cmd_op, NULL, LEAF},
- {"reset", "m|m", (Function) cmd_reset, NULL, LEAF},
- {"resetbans", "o|o", (Function) cmd_resetbans, NULL, LEAF},
- {"resetexempts", "o|o", (Function) cmd_resetexempts, NULL, LEAF},
- {"resetinvites", "o|o", (Function) cmd_resetinvites, NULL, LEAF},
- {"say", "o|o", (Function) cmd_say, NULL, LEAF},
- {"swhois", "n", (Function) cmd_swhois, NULL, LEAF},
- {"topic", "o|o", (Function) cmd_topic, NULL, LEAF},
- {"voice", "o|o", (Function) cmd_voice, NULL, LEAF},
- {NULL, NULL, NULL, NULL, 0}
- };
|