Anope IRC Services  Version 1.8
ns_noop_convert.c
Go to the documentation of this file.
1 /* ns_noop.c - Allows users to optionaly set autoop to off
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Based on the original module by Rob <rob@anope.org>
7  * Included in the Anope module pack since Anope 1.7.9
8  * Anope Coder: DrStein <drstein@anope.org>
9  *
10  * Please read COPYING and README for further details.
11  *
12  * Send bug reports to the Anope Coder instead of the module
13  * author, because any changes since the inclusion into anope
14  * are not supported by the original author.
15  *
16  */
17 /*************************************************************************/
18 
19 #include "module.h"
20 
21 #define AUTHOR "Rob"
22 #define VERSION VERSION_STRING
23 
24 /* The name of the default database to save info to */
25 #define DEFAULT_DB_NAME "autoop.db"
26 
27 /* Multi-language stuff */
28 #define LANG_NUM_STRINGS 8
29 
30 #define AUTOOP_SYNTAX 0
31 #define AUTOOP_STATUS_ON 1
32 #define AUTOOP_STATUS_OFF 2
33 #define AUTOOP_NO_NICK 3
34 #define AUTOOP_ON 4
35 #define AUTOOP_OFF 5
36 #define AUTOOP_DESC 6
37 #define AUTOOP_HELP 7
38 
39 /*************************************************************************/
40 
42 
44 
45 static int mLoadData(void);
46 static int mLoadConfig(int argc, char **argv);
47 
48 /*************************************************************************/
49 
56 int AnopeInit(int argc, char **argv)
57 {
58  NSAutoOPDBName = NULL;
59 
63 
64  if (mLoadConfig(0, NULL))
65  return MOD_STOP;
66 
67  mLoadData();
68 
69  alog("ns_noop_convert: Your auto-op database has been converted and this module will now");
70  alog("ns_noop_convert: unload itself. You can now remove this module from your config");
71 
72  return MOD_STOP;
73 }
74 
78 void AnopeFini(void)
79 {
80  if (NSAutoOPDBName)
81  free(NSAutoOPDBName);
82 }
83 
84 /*************************************************************************/
85 
90 static int mLoadData(void)
91 {
92  int ret = 0;
93  int len = 0;
94 
95  char *name = NULL;
96 
97  NickAlias *na = NULL;
98  FILE *in;
99 
100  /* will _never_ be this big thanks to the 512 limit of a message */
101  char buffer[2000];
102  if ((in = fopen(NSAutoOPDBName, "r")) == NULL) {
103  alog("ns_noop: WARNING: Can not open database file! (it might not exist, this is not fatal)");
104  ret = 1;
105  } else {
106  while (fgets(buffer, 1500, in)) {
107  name = myStrGetToken(buffer, ' ', 0);
108  if (name) {
109  len = strlen(name);
110  /* Take the \n from the end of the line */
111  name[len - 1] = '\0';
112  if ((na = findnick(name))) {
113  na->nc->flags |= NI_AUTOOP;
114  }
115  free(name);
116  }
117  }
118  fclose(in);
119  }
120  return ret;
121 }
122 
123 /*************************************************************************/
124 
129 static int mLoadConfig(int argc, char **argv)
130 {
131  char *tmp = NULL;
132 
133  Directive d[] = {
134  {"NSAutoOPDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}},
135  };
136 
138 
139  if (NSAutoOPDBName)
140  free(NSAutoOPDBName);
141 
142  if (tmp) {
143  NSAutoOPDBName = tmp;
144  } else {
146  alog("ns_noop: NSAutoOPDBName is not defined in Services configuration file, using default %s", NSAutoOPDBName);
147  }
148 
149  if (!NSAutoOPDBName) {
150  alog("ns_noop: FATAL: Can't read required configuration directives!");
151  return MOD_STOP;
152  } else {
153  alog("ns_noop: Directive NSAutoOPDBName loaded (%s)...",
155  }
156 
157  return MOD_CONT;
158 }
159 
160 /*************************************************************************/
161 
162 /* EOF */
#define AUTHOR
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
void AnopeFini(void)
User * currentUser
static int mLoadConfig(int argc, char **argv)
#define PARAM_RELOAD
Definition: services.h:454
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E char * sstrdup(const char *s)
Definition: memory.c:105
NickCore * nc
Definition: services.h:533
#define MOD_STOP
Definition: modules.h:53
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
static int mLoadData(void)
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
#define NI_AUTOOP
Definition: services.h:1309
E char * myStrGetToken(const char *str, const char dilim, int token_number)
Definition: misc.c:654
MDE int moduleGetConfigDirective(Directive *h)
Definition: modules.c:2553
uint32 flags
Definition: services.h:548
#define PARAM_STRING
Definition: services.h:443
int AnopeInit(int argc, char **argv)
#define DEFAULT_DB_NAME
char * NSAutoOPDBName
#define VERSION