Anope IRC Services  Version 1.8
cs_logout.c
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_logout(User * u);
18 static void myChanServHelp(User * u);
19 static void make_unidentified(User * u, ChannelInfo * ci);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34 
35  c = createCommand("LOGOUT", do_logout, NULL, -1, CHAN_HELP_LOGOUT, -1,
36  CHAN_SERVADMIN_HELP_LOGOUT,
37  CHAN_SERVADMIN_HELP_LOGOUT);
39 
41 
42  return MOD_CONT;
43 }
44 
48 void AnopeFini(void)
49 {
50 
51 }
52 
53 
54 
59 static void myChanServHelp(User * u)
60 {
61  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_LOGOUT);
62 }
63 
69 static int do_logout(User * u)
70 {
71  char *chan = strtok(NULL, " ");
72  char *nick = strtok(NULL, " ");
73  ChannelInfo *ci;
74  User *u2 = NULL;
75  int is_servadmin = is_services_admin(u);
76 
77  if (!chan || (!nick && !is_servadmin)) {
78  syntax_error(s_ChanServ, u, "LOGOUT",
79  (!is_servadmin ? CHAN_LOGOUT_SYNTAX :
80  CHAN_LOGOUT_SERVADMIN_SYNTAX));
81  } else if (!(ci = cs_findchan(chan))) {
82  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
83  } else if (!is_servadmin && (ci->flags & CI_VERBOTEN)) {
84  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
85  } else if (nick && !(u2 = finduser(nick))) {
86  notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, nick);
87  } else if (!is_servadmin && u2 != u && !is_real_founder(u, ci)) {
88  notice_lang(s_ChanServ, u, ACCESS_DENIED);
89  /* Since founders can not logout we should tell them -katsklaw */
90  } else if (u2 == u && is_real_founder(u, ci)) {
91  notice_lang(s_ChanServ, u, CHAN_LOGOUT_FOUNDER_FAILED, chan);
92  } else {
93  if (u2) {
94  make_unidentified(u2, ci);
95  notice_lang(s_ChanServ, u, CHAN_LOGOUT_SUCCEEDED, nick, chan);
96  alog("%s: User %s!%s@%s has been logged out of channel %s.",
97  s_ChanServ, u2->nick, u2->username, u2->host, chan);
98  } else {
99  int i;
100  for (i = 0; i < 1024; i++)
101  for (u2 = userlist[i]; u2; u2 = u2->next)
102  make_unidentified(u2, ci);
103  notice_lang(s_ChanServ, u, CHAN_LOGOUT_ALL_SUCCEEDED, chan);
104  alog("%s: All users identified have been logged out of channel %s.", s_ChanServ, chan);
105  }
106 
107  }
108  return MOD_CONT;
109 }
110 
111 static void make_unidentified(User * u, ChannelInfo * ci)
112 {
113  struct u_chaninfolist *uci;
114 
115  if (!u || !ci)
116  return;
117 
118  for (uci = u->founder_chans; uci; uci = uci->next) {
119  if (uci->chan == ci) {
120  if (uci->next)
121  uci->next->prev = uci->prev;
122  if (uci->prev)
123  uci->prev->next = uci->next;
124  else
125  u->founder_chans = uci->next;
126  free(uci);
127  break;
128  }
129  }
130 }
char nick[NICKMAX]
Definition: services.h:875
struct user_::u_chaninfolist * founder_chans
void AnopeFini(void)
Definition: cs_logout.c:48
#define CI_VERBOTEN
Definition: services.h:725
char * host
Definition: services.h:878
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
uint32 flags
Definition: services.h:669
static void make_unidentified(User *u, ChannelInfo *ci)
Definition: cs_logout.c:111
struct u_chaninfolist * next
Definition: services.h:905
E User * finduser(const char *nick)
Definition: users.c:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
E int is_real_founder(User *user, ChannelInfo *ci)
Definition: chanserv.c:2277
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
User * next
Definition: services.h:873
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
char * username
Definition: services.h:877
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
E char * s_ChanServ
Definition: extern.h:285
E User * userlist[1024]
Definition: extern.h:1138
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
static int do_logout(User *u)
Definition: cs_logout.c:69
static void myChanServHelp(User *u)
Definition: cs_logout.c:59
#define MOD_UNIQUE
Definition: module.h:11
int AnopeInit(int argc, char **argv)
Definition: cs_logout.c:27