cs_logout.c

Go to the documentation of this file.
00001 /* ChanServ core functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * $Id: cs_logout.c 1265 2007-08-26 15:33:06Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_logout(User * u);
00019 void myChanServHelp(User * u);
00020 void make_unidentified(User * u, ChannelInfo * ci);
00021 
00028 int AnopeInit(int argc, char **argv)
00029 {
00030     Command *c;
00031 
00032     moduleAddAuthor("Anope");
00033     moduleAddVersion("$Id: cs_logout.c 1265 2007-08-26 15:33:06Z geniusdex $");
00034     moduleSetType(CORE);
00035 
00036     c = createCommand("LOGOUT", do_logout, NULL, -1, CHAN_HELP_LOGOUT, -1,
00037                       CHAN_SERVADMIN_HELP_LOGOUT,
00038                       CHAN_SERVADMIN_HELP_LOGOUT);
00039     moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
00040 
00041     moduleSetChanHelp(myChanServHelp);
00042 
00043     return MOD_CONT;
00044 }
00045 
00049 void AnopeFini(void)
00050 {
00051 
00052 }
00053 
00054 
00055 
00060 void myChanServHelp(User * u)
00061 {
00062     notice_lang(s_ChanServ, u, CHAN_HELP_CMD_LOGOUT);
00063 }
00064 
00070 int do_logout(User * u)
00071 {
00072     char *chan = strtok(NULL, " ");
00073     char *nick = strtok(NULL, " ");
00074     ChannelInfo *ci;
00075     User *u2 = NULL;
00076     int is_servadmin = is_services_admin(u);
00077 
00078     if (!chan || (!nick && !is_servadmin)) {
00079         syntax_error(s_ChanServ, u, "LOGOUT",
00080                      (!is_servadmin ? CHAN_LOGOUT_SYNTAX :
00081                       CHAN_LOGOUT_SERVADMIN_SYNTAX));
00082     } else if (!(ci = cs_findchan(chan))) {
00083         notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
00084     } else if (!is_servadmin && (ci->flags & CI_VERBOTEN)) {
00085         notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
00086     } else if (nick && !(u2 = finduser(nick))) {
00087         notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, nick);
00088     } else if (!is_servadmin && u2 != u && !is_real_founder(u, ci)) {
00089         notice_lang(s_ChanServ, u, ACCESS_DENIED);
00090     } else {
00091         if (u2) {
00092             make_unidentified(u2, ci);
00093             notice_lang(s_ChanServ, u, CHAN_LOGOUT_SUCCEEDED, nick, chan);
00094             alog("%s: User %s!%s@%s has been logged out of channel %s.",
00095                  s_ChanServ, u2->nick, u2->username, u2->host, chan);
00096         } else {
00097             int i;
00098             for (i = 0; i < 1024; i++)
00099                 for (u2 = userlist[i]; u2; u2 = u2->next)
00100                     make_unidentified(u2, ci);
00101             notice_lang(s_ChanServ, u, CHAN_LOGOUT_ALL_SUCCEEDED, chan);
00102             alog("%s: All users identified have been logged out of channel %s.", s_ChanServ, chan);
00103         }
00104 
00105     }
00106     return MOD_CONT;
00107 }
00108 
00109 void make_unidentified(User * u, ChannelInfo * ci)
00110 {
00111     struct u_chaninfolist *uci;
00112 
00113     if (!u || !ci)
00114         return;
00115 
00116     for (uci = u->founder_chans; uci; uci = uci->next) {
00117         if (uci->chan == ci) {
00118             if (uci->next)
00119                 uci->next->prev = uci->prev;
00120             if (uci->prev)
00121                 uci->prev->next = uci->next;
00122             else
00123                 u->founder_chans = uci->next;
00124             free(uci);
00125             break;
00126         }
00127     }
00128 }

Generated on Sun Dec 30 09:26:47 2007 for Anope by  doxygen 1.5.1-20070107