summaryrefslogtreecommitdiff
path: root/src/modules/ns_noop_convert.c
blob: 39dc7227bdc8a33c99b365a28a64dab944d039f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* ns_noop.c - Allows users to optionaly set autoop to off
 *
 * (C) 2003-2012 Anope Team
 * Contact us at team@anope.org
 *
 * Based on the original module by Rob <rob@anope.org>
 * Included in the Anope module pack since Anope 1.7.9
 * Anope Coder: DrStein <drstein@anope.org>
 *
 * Please read COPYING and README for further details.
 *
 * Send bug reports to the Anope Coder instead of the module
 * author, because any changes since the inclusion into anope
 * are not supported by the original author.
 *
 */
/*************************************************************************/

#include "module.h"

#define AUTHOR "Rob"
#define VERSION VERSION_STRING

/* The name of the default database to save info to */
#define DEFAULT_DB_NAME "autoop.db"

/* Multi-language stuff */
#define LANG_NUM_STRINGS  8

#define AUTOOP_SYNTAX     0
#define AUTOOP_STATUS_ON  1
#define AUTOOP_STATUS_OFF 2
#define AUTOOP_NO_NICK    3
#define AUTOOP_ON         4
#define AUTOOP_OFF        5
#define AUTOOP_DESC       6
#define AUTOOP_HELP       7

/*************************************************************************/

User *currentUser;
static int m_isIRCop = 0;

char *NSAutoOPDBName;

static int myNickServAutoOpHelp(User * u);
static void myNickServHelp(User * u);

static int noop(User * u);
static int mEventJoin(int argc, char **argv);
static int setAutoOp(User * u);
static int UnsetAutoOp(User * u);

static int mLoadData(void);
static int mSaveData(int argc, char **argv);
static int mLoadConfig(int argc, char **argv);

static void m_AddLanguages(void);

/*************************************************************************/

/**
 * AnopeInit is called when the module is loaded
 * @param argc Argument count
 * @param argv Argument list
 * @return MOD_CONT to allow the module, MOD_STOP to stop it
 **/
int AnopeInit(int argc, char **argv)
{
    NSAutoOPDBName = NULL;

    moduleAddAuthor(AUTHOR);
    moduleAddVersion(VERSION);
    moduleSetType(SUPPORTED);

    if (mLoadConfig(0, NULL))
        return MOD_STOP;

    mLoadData();
	
    alog("ns_noop_convert: Your auto-op database has been converted and this module will now");
    alog("ns_noop_convert: unload itself.  You can now remove this module from your config");

    return MOD_STOP;
}

/**
 * Unload the module
 **/
void AnopeFini(void)
{
    if (NSAutoOPDBName)
        free(NSAutoOPDBName);
}

/*************************************************************************/

/** 
 * Load data from the db file, and populate the autoop setting
 * @return 0 for success
 **/
static int mLoadData(void)
{
    int ret = 0;
    int len = 0;

    char *name = NULL;

    NickAlias *na = NULL;
    FILE *in;

    /* will _never_ be this big thanks to the 512 limit of a message */
    char buffer[2000];
    if ((in = fopen(NSAutoOPDBName, "r")) == NULL) {
        alog("ns_noop: WARNING: Can not open database file! (it might not exist, this is not fatal)");
        ret = 1;
    } else {
        while (fgets(buffer, 1500, in)) {
            name = myStrGetToken(buffer, ' ', 0);
            if (name) {
                len = strlen(name);
                /* Take the \n from the end of the line */
                name[len - 1] = '\0';
                if ((na = findnick(name))) {
	    	    na->nc->flags |= NI_AUTOOP;
                }
                free(name);
            }
        }
        fclose(in);
    }
    return ret;
}

/*************************************************************************/

/** 
 * Load the configuration directives from Services configuration file.
 * @return 0 for success
 **/
static int mLoadConfig(int argc, char **argv)
{
    char *tmp = NULL;

    Directive d[] = {
        {"NSAutoOPDBName", {{PARAM_STRING, PARAM_RELOAD, &tmp}}},
    };

    moduleGetConfigDirective(d);

    if (NSAutoOPDBName)
        free(NSAutoOPDBName);

    if (tmp) {
        NSAutoOPDBName = tmp;
    } else {
        NSAutoOPDBName = sstrdup(DEFAULT_DB_NAME);
        alog("ns_noop: NSAutoOPDBName is not defined in Services configuration file, using default %s", NSAutoOPDBName);
    }

    if (!NSAutoOPDBName) {
        alog("ns_noop: FATAL: Can't read required configuration directives!");
        return MOD_STOP;
    } else {
        alog("ns_noop: Directive NSAutoOPDBName loaded (%s)...",
             NSAutoOPDBName);
    }

    return MOD_CONT;
}

/*************************************************************************/

/* EOF */