Anope IRC Services  Version 1.8
os_defcon.c
Go to the documentation of this file.
1 /* OperServ 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 #ifdef _WIN32
18 extern MDE time_t DefContimer;
19 extern MDE void runDefCon(void);
20 #endif
21 static int do_defcon(User * u);
22 static void defcon_sendlvls(User * u);
23 
24 static void myOperServHelp(User * u);
25 
32 int AnopeInit(int argc, char **argv)
33 {
34  Command *c;
35 
36  moduleAddAuthor("Anope");
37  moduleAddVersion(VERSION_STRING);
39 
41  OPER_HELP_DEFCON, -1, -1, -1, -1);
43 
45 
46  return MOD_CONT;
47 }
48 
52 void AnopeFini(void)
53 {
54 
55 }
56 
57 
62 static void myOperServHelp(User * u)
63 {
64  if (is_services_admin(u)) {
65  notice_lang(s_OperServ, u, OPER_HELP_CMD_DEFCON);
66  }
67 }
68 
79 static int do_defcon(User * u)
80 {
81  char *lvl = strtok(NULL, " ");
82  int newLevel = 0;
83  char *langglobal;
84  langglobal = getstring(NULL, DEFCON_GLOBAL);
85 
86  if (!DefConLevel) { /* If we dont have a .conf setting! */
87  notice_lang(s_OperServ, u, OPER_DEFCON_NO_CONF);
88  return MOD_CONT;
89  }
90 
91  if (!lvl) {
92  notice_lang(s_OperServ, u, OPER_DEFCON_CHANGED, DefConLevel);
93  defcon_sendlvls(u);
94  return MOD_CONT;
95  }
96  newLevel = atoi(lvl);
97  if (newLevel < 1 || newLevel > 5) {
98  syntax_error(s_OperServ, u, "DEFCON", OPER_DEFCON_SYNTAX);
99  return MOD_CONT;
100  }
101  DefConLevel = newLevel;
103  DefContimer = time(NULL);
104  notice_lang(s_OperServ, u, OPER_DEFCON_CHANGED, DefConLevel);
105  defcon_sendlvls(u);
106  alog("Defcon level changed to %d by Oper %s", newLevel, u->nick);
107  anope_cmd_global(s_OperServ, getstring2(NULL, OPER_DEFCON_WALL),
108  u->nick, newLevel);
109  /* Global notice the user what is happening. Also any Message that
110  the Admin would like to add. Set in config file. */
111  if (GlobalOnDefcon) {
112  if ((DefConLevel == 5) && (DefConOffMessage)) {
113  oper_global(NULL, "%s", DefConOffMessage);
114  } else {
115  oper_global(NULL, langglobal, DefConLevel);
116  }
117  }
118  if (GlobalOnDefconMore) {
119  if ((DefConOffMessage) && DefConLevel == 5) {
120  } else {
121  oper_global(NULL, "%s", DefconMessage);
122  }
123  }
124  /* Run any defcon functions, e.g. FORCE CHAN MODE */
125  runDefCon();
126  return MOD_CONT;
127 }
128 
129 
130 
134 static void defcon_sendlvls(User * u)
135 {
137  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_NO_NEW_CHANNELS);
138  }
140  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_NO_NEW_NICKS);
141  }
143  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_NO_MLOCK_CHANGE);
144  }
146  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_FORCE_CHAN_MODES,
148  }
150  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_REDUCE_SESSION,
152  }
154  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_NO_NEW_CLIENTS);
155  }
157  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_OPER_ONLY);
158  }
160  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_SILENT_OPER_ONLY);
161  }
163  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_AKILL_NEW_CLIENTS);
164  }
166  notice_lang(s_OperServ, u, OPER_HELP_DEFCON_NO_NEW_MEMOS);
167  }
168 }
static void defcon_sendlvls(User *u)
Definition: os_defcon.c:134
static int do_defcon(User *u)
Definition: os_defcon.c:79
char nick[NICKMAX]
Definition: services.h:875
#define DEFCON_FORCE_CHAN_MODES
Definition: services.h:1257
E int checkDefCon(int level)
Definition: operserv.c:1608
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E void oper_global(char *nick, char *fmt,...)
Definition: operserv.c:691
#define getstring(na, index)
Definition: extern.h:731
E int DefConLevel
Definition: extern.h:561
#define MDE
Definition: modules.h:89
#define getstring2(nc, index)
Definition: extern.h:733
E void runDefCon(void)
Definition: operserv.c:1648
E int DefConSessionLimit
Definition: extern.h:565
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E char * DefConChanModes
Definition: extern.h:568
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
#define DEFCON_NO_MLOCK_CHANGE
Definition: services.h:1256
#define DEFCON_OPER_ONLY
Definition: services.h:1260
#define OPERSERV
Definition: modules.h:62
E char * DefconMessage
Definition: extern.h:571
E char * s_OperServ
Definition: extern.h:289
#define DEFCON_REDUCE_SESSION
Definition: services.h:1258
#define DEFCON_NO_NEW_CLIENTS
Definition: services.h:1259
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
#define DEFCON_AKILL_NEW_CLIENTS
Definition: services.h:1262
Command * c
Definition: ns_recover.c:17
E void alog(const char *fmt,...) FORMAT(printf
#define EVENT_DEFCON_LEVEL
Definition: events.h:58
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
#define DEFCON_NO_NEW_CHANNELS
Definition: services.h:1254
void AnopeFini(void)
Definition: os_defcon.c:52
E int is_services_admin(User *u)
Definition: operserv.c:591
#define DEFCON_NO_NEW_MEMOS
Definition: services.h:1263
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 int GlobalOnDefcon
Definition: extern.h:569
#define DEFCON_SILENT_OPER_ONLY
Definition: services.h:1261
E time_t DefContimer
Definition: extern.h:1015
E char * DefConOffMessage
Definition: extern.h:573
int AnopeInit(int argc, char **argv)
Definition: os_defcon.c:32
static void myOperServHelp(User *u)
Definition: os_defcon.c:62
#define DEFCON_NO_NEW_NICKS
Definition: services.h:1255
E int GlobalOnDefconMore
Definition: extern.h:570
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define MOD_UNIQUE
Definition: module.h:11
E void anope_cmd_global(char *source, const char *fmt,...)
Definition: ircd.c:506