| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718 |
- /*
- * Copyright (C) 1997 Robey Pointer
- * Copyright (C) 1999 - 2002 Eggheads Development Team
- * Copyright (C) 2002 - 2008 Bryan Drewery
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /*
- * msgcmds.c -- part of irc.mod
- * all commands entered via /MSG
- *
- */
- #include "src/core_binds.h"
- static int msg_bewm(char *nick, char *host, struct userrec *u, char *par)
- {
- struct chanset_t *chan = NULL;
- if (!homechan[0] || !(chan = findchan_by_dname(homechan)))
- return BIND_RET_BREAK;
- if (!channel_active(chan))
- return BIND_RET_BREAK;
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- if (!u) {
- dprintf(DP_SERVER, STR("PRIVMSG %s :---- (%s!%s) attempted to gain secure invite, but is not a recognized user.\n"),
- chan->dname, nick, host);
- putlog(LOG_CMDS, "*", STR("(%s!%s) !*! BEWM"), nick, host);
- return BIND_RET_BREAK;
- }
- if (u->bot)
- return BIND_RET_BREAK;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- get_user_flagrec(u, &fr, chan->dname, chan);
- if (!chk_op(fr, chan)) {
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! !BEWM"), nick, host, u->handle);
- dprintf(DP_SERVER, STR("PRIVMSG %s :---- %s (%s!%s) attempted to gain secure invite, but is missing a flag.\n"),
- chan->dname, u->handle, nick, host);
- return BIND_RET_BREAK;
- }
- dprintf(DP_SERVER, "PRIVMSG %s :\001ACTION has invited \002%s\002 (%s!%s) to %s.\001\n"
- , chan->dname, u->handle, nick, host, chan->dname);
- cache_invite(chan, nick, host, u->handle, 0, 0);
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! BEWM"), nick, host, u->handle);
- return BIND_RET_BREAK;
- }
- static int msg_pass(char *nick, char *host, struct userrec *u, char *par)
- {
- char *old = NULL, *mynew = NULL;
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- if (!u) {
- putlog(LOG_CMDS, "*", "(%s!%s) !*! PASS", nick, host);
- return BIND_RET_BREAK;
- }
- if (u->bot)
- return BIND_RET_BREAK;
- if (!par[0]) {
- dprintf(DP_HELP, "NOTICE %s :%s\n", nick, u_pass_match(u, "-") ? "You don't have a password set." : "You have a password set.");
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! PASS?", nick, host, u->handle);
- return BIND_RET_BREAK;
- }
- old = newsplit(&par);
- if (!u_pass_match(u, "-") && !par[0]) {
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
- dprintf(DP_HELP, "NOTICE %s :You already have a password set.\n", nick);
- return BIND_RET_BREAK;
- }
- if (par[0]) {
- if (!u_pass_match(u, old)) {
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
- dprintf(DP_HELP, "NOTICE %s :Incorrect password.\n", nick);
- return BIND_RET_BREAK;
- }
- mynew = newsplit(&par);
- } else {
- mynew = old;
- }
- if (strlen(mynew) > MAXPASSLEN)
- mynew[MAXPASSLEN] = 0;
- if (!goodpass(mynew, 0, nick)) {
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! $b!$bPASS...", nick, host, u->handle);
- return BIND_RET_BREAK;
- }
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! PASS", nick, host, u->handle);
- set_user(&USERENTRY_PASS, u, mynew);
- dprintf(DP_HELP, "NOTICE %s :%s '%s'.\n", nick,
- mynew == old ? "Password set to:" : "Password changed to:", mynew);
- return BIND_RET_BREAK;
- }
- static int msg_op(char *nick, char *host, struct userrec *u, char *par)
- {
- struct chanset_t *chan = NULL;
- char *pass = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- pass = newsplit(&par);
- if (homechan[0]) {
- struct chanset_t *hchan = NULL;
- hchan = findchan_by_dname(homechan);
- if (hchan && channel_active(hchan) && !ismember(hchan, nick)) {
- putlog(LOG_CMDS, "*", "(%s!%s) !*! failed OP %s (not in %s)", nick, host, par, homechan);
- if (par[0])
- dprintf(DP_SERVER, "PRIVMSG %s :---- (%s!%s) attempted to OP for %s but is not currently in %s.\n",
- homechan, nick, host, par, homechan);
- else
- dprintf(DP_SERVER, "PRIVMSG %s :---- (%s!%s) attempted to OP but is not currently in %s.\n",
- homechan, nick, host, homechan);
- return BIND_RET_BREAK;
- }
- }
- if (u_pass_match(u, pass)) {
- if (!u_pass_match(u, "-")) {
- if (par[0]) {
- chan = findchan_by_dname(par);
- if (chan && channel_active(chan)) {
- get_user_flagrec(u, &fr, par, chan);
- if (chk_op(fr, chan)) {
- if (do_op(nick, chan, 0, 1)) {
- stats_add(u, 0, 1);
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! OP %s", nick, host, u->handle, par);
- if (manop_warn && chan->manop)
- dprintf(DP_HELP, "NOTICE %s :%s is currently set to punish for manual op.\n", nick, chan->dname);
- }
- }
- return BIND_RET_BREAK;
- }
- } else {
- int stats = 0;
- for (chan = chanset; chan; chan = chan->next) {
- get_user_flagrec(u, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- if (do_op(nick, chan, 0, 1)) {
- stats++;
- if (manop_warn && chan->manop)
- dprintf(DP_HELP, "NOTICE %s :%s is currently set to punish for manual op.\n", nick, chan->dname);
- }
- }
- }
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! OP", nick, host, u->handle);
- if (stats)
- stats_add(u, 0, 1);
- return BIND_RET_BREAK;
- }
- }
- }
- putlog(LOG_CMDS, "*", "(%s!%s) !*! failed OP", nick, host);
- return BIND_RET_BREAK;
- }
- static int msg_ident(char *nick, char *host, struct userrec *u, char *par)
- {
- char s[UHOSTLEN] = "", s1[UHOSTLEN] = "", *pass = NULL, who[NICKLEN] = "";
- struct userrec *u2 = NULL;
- if (match_my_nick(nick) || (u && u->bot))
- return BIND_RET_BREAK;
- pass = newsplit(&par);
- if (!par[0])
- strlcpy(who, nick, sizeof(nick));
- else {
- strlcpy(who, par, sizeof(who));
- who[NICKMAX] = 0;
- }
- u2 = get_user_by_handle(userlist, who);
- if (u2 && rfc_casecmp(who, origbotname) && !u2->bot) {
- /* This could be used as detection... */
- if (u_pass_match(u2, "-")) {
- putlog(LOG_CMDS, "*", "(%s!%s) !*! IDENT %s", nick, host, who);
- } else if (!u_pass_match(u2, pass)) {
- putlog(LOG_CMDS, "*", "(%s!%s) !*! failed IDENT %s", nick, host, who);
- return BIND_RET_BREAK;
- } else if (u == u2) {
- dprintf(DP_HELP, "NOTICE %s :I recognize you there.\n", nick);
- return BIND_RET_BREAK;
- } else if (u) {
- dprintf(DP_HELP, "NOTICE %s :You're not %s, you're %s.\n", nick, who, u->handle);
- return BIND_RET_BREAK;
- } else {
- putlog(LOG_CMDS, "*", "(%s!%s) !*! IDENT %s", nick, host, who);
- simple_snprintf(s, sizeof s, "%s!%s", nick, host);
- maskaddr(s, s1, 0); /* *!user@host */
- dprintf(DP_HELP, "NOTICE %s :Added hostmask: %s\n", nick, s1);
- addhost_by_handle(who, s1);
- check_this_user(who, 0, NULL);
- return BIND_RET_BREAK;
- }
- }
- putlog(LOG_CMDS, "*", "(%s!%s) !*! failed IDENT %s", nick, host, who);
- return BIND_RET_BREAK;
- }
- static int msg_invite(char *nick, char *host, struct userrec *u, char *par)
- {
- char *pass = NULL;
- struct chanset_t *chan = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- pass = newsplit(&par);
- if (u_pass_match(u, pass) && !u_pass_match(u, "-")) {
- if (par[0] == '*') {
- for (chan = chanset; chan; chan = chan->next) {
- get_user_flagrec(u, &fr, chan->dname, chan);
- if (chk_op(fr, chan) && (chan->channel.mode & CHANINV)) {
- cache_invite(chan, nick, host, u->handle, 0, 0);
- }
- }
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! INVITE ALL", nick, host, u->handle);
- return BIND_RET_BREAK;
- }
- if (!(chan = findchan_by_dname(par))) {
- dprintf(DP_HELP, "NOTICE %s :Usage: /MSG %s %s <pass> <channel>\n", nick, botname, msginvite);
- return BIND_RET_BREAK;
- }
- if (!channel_active(chan)) {
- dprintf(DP_HELP, "NOTICE %s :%s: Not on that channel right now.\n", nick, par);
- return BIND_RET_BREAK;
- }
- /* We need to check access here also (dw 991002) */
- get_user_flagrec(u, &fr, par, chan);
- if (chk_op(fr, chan)) {
- cache_invite(chan, nick, host, u->handle, 0, 0);
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! INVITE %s", nick, host, u->handle, par);
- return BIND_RET_BREAK;
- }
- }
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! failed INVITE %s", nick, host, (u ? u->handle : "*"), par);
- return BIND_RET_BREAK;
- }
- static void reply(char *, struct chanset_t *, const char *, ...) __attribute__((format(printf, 3, 4)));
- static void reply(char *nick, struct chanset_t *chan, const char *format, ...)
- {
- va_list va;
- char buf[1024] = "";
- va_start(va, format);
- egg_vsnprintf(buf, sizeof buf, format, va);
- va_end(va);
- if (chan)
- dprintf(DP_HELP, "PRIVMSG %s :%s", chan->name, buf);
- else
- dprintf(DP_HELP, "NOTICE %s :%s", nick, buf);
- }
- static void logc(const char *cmd, Auth *a, char *chname, char *par)
- {
- if (chname && chname[0])
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! %s %c%s %s", a->nick, a->host, a->handle, chname, auth_prefix[0], cmd, par ? par : "");
- else
- putlog(LOG_CMDS, "*", "(%s!%s) !%s! %c%s %s", a->nick, a->host, a->handle, auth_prefix[0], cmd, par ? par : "");
- }
- #define LOGC(cmd) logc(cmd, a, chname, par)
-
- static int msg_authstart(char *nick, char *host, struct userrec *u, char *par)
- {
- if (!u)
- return 0;
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- if (u && u->bot)
- return BIND_RET_BREAK;
- if (!ischanhub()) {
- putlog(LOG_WARN, "*", STR("(%s!%s) !%s! Attempted AUTH? (I'm not a chathub (+c))"), nick, host, u->handle);
- return BIND_RET_BREAK;
- }
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! AUTH?"), nick, host, u->handle);
- Auth *auth = Auth::Find(host);
- if (auth) {
- if (auth->Authed()) {
- dprintf(DP_HELP, STR("NOTICE %s :You are already authed.\n"), nick);
- return 0;
- }
- } else
- auth = new Auth(nick, host, u);
- /* Send "auth." if they are recognized, otherwise "auth!" */
- auth->Status(AUTH_PASS);
- dprintf(DP_HELP, STR("PRIVMSG %s :auth%s %s\n"), nick, u ? "." : "!", conf.bot->nick);
- return BIND_RET_BREAK;
- }
- static void
- AuthFinish(Auth *auth)
- {
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! +AUTH"), auth->nick, auth->host, auth->handle);
- auth->Done();
- dprintf(DP_HELP, STR("NOTICE %s :You are now authorized for cmds, see %chelp\n"), auth->nick, auth_prefix[0]);
- }
- static int msg_auth(char *nick, char *host, struct userrec *u, char *par)
- {
- char *pass = NULL;
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- if (u && u->bot)
- return BIND_RET_BREAK;
- Auth *auth = Auth::Find(host);
- if (!auth || auth->Status() != AUTH_PASS)
- return BIND_RET_BREAK;
- pass = newsplit(&par);
- if (u_pass_match(u, pass) && !u_pass_match(u, "-")) {
- auth->user = u;
- if (strlen(auth_key) && get_user(&USERENTRY_SECPASS, u)) {
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! AUTH"), nick, host, u->handle);
- auth->Status(AUTH_HASH);
- auth->MakeHash();
- dprintf(DP_HELP, STR("PRIVMSG %s :-Auth %s %s\n"), nick, auth->rand, conf.bot->nick);
- } else {
- /* no auth_key and/or no SECPASS for the user, don't require a hash auth */
- AuthFinish(auth);
- }
- } else {
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! failed AUTH"), nick, host, u->handle);
- delete auth;
- }
- return BIND_RET_BREAK;
- }
- static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
- {
- if (strlen(auth_key) && get_user(&USERENTRY_SECPASS, u)) {
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- if (u && u->bot)
- return BIND_RET_BREAK;
- Auth *auth = Auth::Find(host);
- if (!auth || auth->Status() != AUTH_HASH)
- return BIND_RET_BREAK;
- if (!strcmp(auth->hash, par)) { /* good hash! */
- AuthFinish(auth);
- } else { /* bad hash! */
- char s[300] = "";
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! failed +AUTH"), nick, host, u->handle);
- dprintf(DP_HELP, STR("NOTICE %s :Invalid hash.\n"), nick);
- simple_snprintf(s, sizeof(s), "*!%s", host);
- addignore(s, origbotname, STR("Invalid auth hash."), now + (60 * ignore_time));
- delete auth;
- }
- return BIND_RET_BREAK;
- }
- return BIND_RET_LOG;
- }
- static int msg_unauth(char *nick, char *host, struct userrec *u, char *par)
- {
- if (match_my_nick(nick))
- return BIND_RET_BREAK;
- if (u && u->bot)
- return BIND_RET_BREAK;
- Auth *auth = Auth::Find(host);
- if (!auth)
- return BIND_RET_BREAK;
- delete auth;
- dprintf(DP_HELP, STR("NOTICE %s :You are now unauthorized.\n"), nick);
- putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! UNAUTH"), nick, host, u->handle);
- return BIND_RET_BREAK;
- }
- /* MSG COMMANDS
- *
- * Function call should be:
- * int msg_cmd("handle","nick","user@host","params");
- *
- * The function is responsible for any logging. Return 1 if successful,
- * 0 if not.
- */
- static cmd_t C_msg[] =
- {
- {"auth?", "", (Function) msg_authstart, NULL, LEAF},
- {"auth", "", (Function) msg_auth, NULL, LEAF},
- {"+auth", "", (Function) msg_pls_auth, NULL, LEAF},
- {"unauth", "", (Function) msg_unauth, NULL, LEAF},
- {"ident", "", (Function) msg_ident, NULL, LEAF},
- {"invite", "", (Function) msg_invite, NULL, LEAF},
- {"op", "", (Function) msg_op, NULL, LEAF},
- {"pass", "", (Function) msg_pass, NULL, LEAF},
- {"bewm", "", (Function) msg_bewm, NULL, LEAF},
- {NULL, NULL, NULL, NULL, 0}
- };
- static int msgc_test(Auth *a, char *chname, char *par)
- {
- char *cmd = NULL;
- LOGC("TEST");
- cmd = newsplit(&par);
- if (a->GetIdx(chname)) {
- check_auth_dcc(a, cmd, par);
- }
- return BIND_RET_BREAK;
- }
- static int msgc_op(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- int force = 0;
- memberlist *m = NULL;
- if (chname && chname[0]) {
- chan = findchan_by_dname(chname);
- if (chan)
- m = ismember(chan, a->nick);
- }
- LOGC("OP");
- if (par[0] == '-') { /* we have an option! */
- char *tmp = NULL;
- par++;
- tmp = newsplit(&par);
- if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f"))
- force = 1;
- else {
- dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
- return 0;
- }
- }
- if (par[0] || chan) {
- if (!chan)
- chan = findchan_by_dname(par);
- if (chan && channel_active(chan)) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- if (do_op(a->nick, chan, 0, force))
- stats_add(a->user, 0, 1);
- }
- return BIND_RET_BREAK;
- }
- } else {
- for (chan = chanset; chan; chan = chan->next) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- if (do_op(a->nick, chan, 0, force))
- stats_add(a->user, 0, 1);
- }
- }
- }
- return BIND_RET_BREAK;
- }
- static int msgc_voice(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- int force = 0;
- memberlist *m = NULL;
- if (chname && chname[0]) {
- chan = findchan_by_dname(chname);
- if (chan)
- m = ismember(chan, a->nick);
- }
- LOGC("VOICE");
- if (par[0] == '-') { /* we have an option! */
- char *tmp = NULL;
- par++;
- tmp = newsplit(&par);
- if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f"))
- force = 1;
- else {
- dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
- return 0;
- }
- }
- if (par[0] || chan) {
- if (!chan)
- chan = findchan_by_dname(par);
- if (chan && channel_active(chan)) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (!chk_devoice(fr)) { /* dont voice +q */
- add_mode(chan, '+', 'v', a->nick);
- }
- return BIND_RET_BREAK;
- }
- } else {
- for (chan = chanset; chan; chan = chan->next) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (!chk_devoice(fr)) { /* dont voice +q */
- add_mode(chan, '+', 'v', a->nick);
- }
- }
- }
- return BIND_RET_BREAK;
- }
- static int msgc_channels(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- char list[1024] = "";
- LOGC("CHANNELS");
- for (chan = chanset; chan; chan = chan->next) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- if (me_op(chan))
- strlcat(list, "@", sizeof(list));
- strlcat(list, chan->dname, sizeof(list));
- strlcat(list, " ", sizeof(list));
- }
- }
- if (list[0])
- reply(a->nick, NULL, "You have access to: %s\n", list);
- else
- reply(a->nick, NULL, "You do not have access to any channels.\n");
- return BIND_RET_BREAK;
- }
- static int msgc_getkey(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- if (chname && chname[0])
- return 0;
- if (!par[0])
- return 0;
- LOGC("GETKEY");
- chan = findchan_by_dname(par);
- if (chan && channel_active(chan) && !channel_pending(chan)) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- if (chan->channel.key[0]) {
- reply(a->nick, NULL, "Key for %s is: %s\n", chan->name, chan->channel.key);
- } else {
- reply(a->nick, NULL, "%s has no key set.\n", chan->name);
- }
- }
- }
- return BIND_RET_BREAK;
- }
- static int msgc_help(Auth *a, char *chname, char *par)
- {
- LOGC("HELP");
- char outbuf[201] = "";
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- bind_entry_t *entry = NULL;
- bind_table_t *table = NULL;
- get_user_flagrec(a->user, &fr, chname ? chname : NULL);
- table = bind_table_lookup("msgc");
- for (entry = table->entries; entry && entry->next; entry = entry->next)
- if (((chname && chname[0] && entry->cflags & AUTH_CHAN) ||
- ((!chname || !chname[0]) && entry->cflags & AUTH_MSG)) && flagrec_ok(&entry->user_flags, &fr)) {
- if (outbuf[0])
- strlcat(outbuf, " ", sizeof(outbuf));
- strlcat(outbuf, entry->mask, sizeof(outbuf));
- }
- reply(a->nick, NULL, "%s\n", outbuf);
- return BIND_RET_BREAK;
- }
- static int msgc_md5(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- LOGC("MD5");
- if (chname && chname[0])
- chan = findchan_by_dname(chname);
- reply(a->nick, chan, "MD5(%s) = %s\n", par, MD5(par));
- return BIND_RET_BREAK;
- }
- static int msgc_sha1(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- LOGC("SHA1");
- if (chname && chname[0])
- chan = findchan_by_dname(chname);
- reply(a->nick, chan, "SHA1(%s) = %s\n", par, SHA1(par));
- return BIND_RET_BREAK;
- }
- static int msgc_invite(Auth *a, char *chname, char *par)
- {
- struct chanset_t *chan = NULL;
- struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
- int force = 0;
- if (chname && chname[0])
- return 0;
-
- LOGC("INVITE");
- if (par[0] == '-') {
- char *tmp = NULL;
- par++;
- tmp = newsplit(&par);
- if (!strcasecmp(tmp, "force") || !strcasecmp(tmp, "f"))
- force = 1;
- else {
- dprintf(DP_HELP, "NOTICE %s :Invalid option: %s\n", a->nick, tmp);
- return 0;
- }
- }
- if (par[0] && (!chname || (chname && !chname[0]))) {
- chan = findchan_by_dname(par);
- if (chan && channel_active(chan) && !ismember(chan, a->nick)) {
- if ((!(chan->channel.mode & CHANINV) && force) || (chan->channel.mode & CHANINV)) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- cache_invite(chan, a->nick, a->host, a->handle, 0, 0);
- }
- return BIND_RET_BREAK;
- }
- }
- } else {
- for (chan = chanset; chan; chan = chan->next) {
- if (channel_active(chan) && !ismember(chan, a->nick)) {
- if ((!(chan->channel.mode & CHANINV) && force) || (chan->channel.mode & CHANINV)) {
- get_user_flagrec(a->user, &fr, chan->dname, chan);
- if (chk_op(fr, chan)) {
- cache_invite(chan, a->nick, a->host, a->handle, 0, 0);
- }
- }
- }
- }
- }
- return BIND_RET_BREAK;
- }
- static cmd_t C_msgc[] =
- {
- {"test", "a", (Function) msgc_test, NULL, LEAF|AUTH_CHAN|AUTH_MSG},
- {"channels", "", (Function) msgc_channels, NULL, LEAF|AUTH_CHAN|AUTH_MSG},
- {"getkey", "", (Function) msgc_getkey, NULL, LEAF|AUTH_MSG},
- {"help", "", (Function) msgc_help, NULL, LEAF|AUTH_CHAN|AUTH_MSG},
- {"invite", "", (Function) msgc_invite, NULL, LEAF|AUTH_MSG},
- {"md5", "", (Function) msgc_md5, NULL, LEAF|AUTH_MSG|AUTH_CHAN},
- {"op", "", (Function) msgc_op, NULL, LEAF|AUTH_CHAN|AUTH_MSG},
- {"sha1", "", (Function) msgc_sha1, NULL, LEAF|AUTH_CHAN|AUTH_MSG},
- {"voice", "", (Function) msgc_voice, NULL, LEAF|AUTH_CHAN|AUTH_MSG},
- {NULL, NULL, NULL, NULL, 0}
- };
|