-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseenserv.c
More file actions
410 lines (381 loc) · 12.3 KB
/
seenserv.c
File metadata and controls
410 lines (381 loc) · 12.3 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/* SeenServ - Nickname Seen Service - NeoStats Addon Module
** Copyright (c) 2003-2005 Justin Hammond, Mark Hetherington, Jeff Lang
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA
**
** SeenServ CVS Identification
** $Id: seenserv.c 53 2005-12-12 14:00:05Z DNB $
*/
#include "neostats.h" /* Required for bot support */
#include "seenserv.h"
static int sns_set_enablechan (const CmdParams *cmdparams, SET_REASON reason);
static int sns_set_seenchan (const CmdParams *cmdparams, SET_REASON reason);
static int sns_set_maxentries (const CmdParams *cmdparams, SET_REASON reason);
static int sns_set_exclusions (const CmdParams *cmdparams, SET_REASON reason);
static int sns_set_eventsignon( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_eventquit( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_eventkill( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_eventnick( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_eventjoin( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_eventpart( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_eventkick( const CmdParams *cmdparams, SET_REASON reason );
static int sns_set_expiretime (const CmdParams *cmdparams, SET_REASON reason);
static int sns_set_dbupdatetime (const CmdParams *cmdparams, SET_REASON reason);
static int sns_set_memorylist (const CmdParams *cmdparams, SET_REASON reason);
/** Copyright info */
const char *sns_copyright[] = {
"Copyright (c) 2005, NeoStats",
"http://www.neostats.net/",
NULL};
const char *sns_about[] = {
"\2Seen Service\2",
"",
"Provides access to SEEN command to see when Users were connected.",
NULL
};
/*
* Commands and Settings
*/
static bot_cmd sns_commands[]=
{
{"SEEN", sns_cmd_seenhost, 1, 0, sns_help_seen},
{"SEENNICK", sns_cmd_seennick, 1, 0, sns_help_seennick},
{"DEL", sns_cmd_del, 1, NS_ULEVEL_ADMIN, sns_help_del},
{"STATUS", sns_cmd_status, 0, NS_ULEVEL_LOCOPER, sns_help_status},
NS_CMD_END()
};
static bot_setting sns_settings[]=
{
{"EXCLUSIONS", &SeenServ.exclusions, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_exclusions, sns_set_exclusions, (void *)1 },
{"ENABLE", &SeenServ.enable, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_enable, NULL, (void *)0 },
{"ENABLESEENCHAN", &SeenServ.enableseenchan, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_enableseenchan, sns_set_enablechan, (void *)0 },
{"SEENCHANNAME", &SeenServ.seenchan, SET_TYPE_CHANNEL, 0, MAXCHANLEN, NS_ULEVEL_ADMIN, NULL, sns_help_set_seenchan, sns_set_seenchan, (void *)"#Seen" },
{"MAXENTRIES", &SeenServ.maxentries, SET_TYPE_INT, 100, 100000, NS_ULEVEL_ADMIN, NULL, sns_help_set_maxentries, sns_set_maxentries, (void *)2000 },
{"EVENTSIGNON", &SeenServ.eventsignon, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventsignon, sns_set_eventsignon, (void *)1 },
{"EVENTQUIT", &SeenServ.eventquit, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventquit, sns_set_eventquit, (void *)1 },
{"EVENTKILL", &SeenServ.eventkill, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventkill, sns_set_eventkill, (void *)1 },
{"EVENTNICK", &SeenServ.eventnick, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventnick, sns_set_eventnick, (void *)1 },
{"EVENTJOIN", &SeenServ.eventjoin, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventjoin, sns_set_eventjoin, (void *)1 },
{"EVENTPART", &SeenServ.eventpart, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventpart, sns_set_eventpart, (void *)1 },
{"EVENTKICK", &SeenServ.eventkick, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_eventkick, sns_set_eventkick, (void *)1 },
{"EXPIRETIME", &SeenServ.expiretime, SET_TYPE_INT, 0, 1000, NS_ULEVEL_ADMIN, NULL, sns_help_set_expiretime, sns_set_expiretime, (void *)0 },
{"DBUPDATETIME", &SeenServ.dbupdatetime, SET_TYPE_INT, 1, 900, NS_ULEVEL_ADMIN, NULL, sns_help_set_dbupdatetime, sns_set_dbupdatetime, (void *)300 },
{"MEMORYLIST", &SeenServ.memorylist, SET_TYPE_BOOLEAN, 0, 0, NS_ULEVEL_ADMIN, NULL, sns_help_set_memorylist, sns_set_memorylist, (void *)1 },
NS_SETTING_END()
};
/*
* Module Info definition
*/
ModuleInfo module_info = {
"SeenServ",
"Seen Service Module For NeoStats",
sns_copyright,
sns_about,
NEOSTATS_VERSION,
MODULE_VERSION,
__DATE__,
__TIME__,
MODULE_FLAG_LOCAL_EXCLUDES,
0,
};
/*
* Module event list
*/
ModuleEvent module_events[] = {
{EVENT_SIGNON, SeenSignon, EVENT_FLAG_EXCLUDE_ME},
{EVENT_NICKIP, SeenSignon, EVENT_FLAG_EXCLUDE_ME},
{EVENT_QUIT, SeenQuit, EVENT_FLAG_EXCLUDE_ME},
{EVENT_KILL, SeenKill, EVENT_FLAG_EXCLUDE_ME},
{EVENT_LOCALKILL, SeenKill, EVENT_FLAG_EXCLUDE_ME},
{EVENT_SERVERKILL, SeenKill, EVENT_FLAG_EXCLUDE_ME},
{EVENT_GLOBALKILL, SeenKill, EVENT_FLAG_EXCLUDE_ME},
{EVENT_NICK, SeenNickChange, EVENT_FLAG_EXCLUDE_ME},
{EVENT_JOIN, SeenJoinChan, EVENT_FLAG_EXCLUDE_ME},
{EVENT_PART, SeenPartChan, EVENT_FLAG_EXCLUDE_ME},
{EVENT_KICK, SeenKicked, EVENT_FLAG_EXCLUDE_ME},
NS_EVENT_END()
};
/** BotInfo */
static BotInfo sns_botinfo =
{
"SeenServ",
"SeenServ1",
"Seen",
BOT_COMMON_HOST,
"Seen Service",
BOT_FLAG_SERVICEBOT|BOT_FLAG_PERSIST,
sns_commands,
sns_settings,
};
/*
* Online event processing
*/
int ModSynch (void)
{
/* Introduce a bot onto the network */
sns_bot = AddBot (&sns_botinfo);
if (!sns_bot)
return NS_FAILURE;
if (SeenServ.enableseenchan) {
irc_join (sns_bot, SeenServ.seenchan, "+o");
irc_chanalert (sns_bot, "Seen Channel Now Available in %s", SeenServ.seenchan);
} else {
irc_chanalert (sns_bot, "Seen Channel Not Enabled");
}
AddTimer (TIMER_TYPE_DAILY, removeagedseenrecords, "removeagedseenrecords", 0, NULL);
AddTimer (TIMER_TYPE_INTERVAL, dbsavetimer, "seenservdbsavetimer", SeenServ.dbupdatetime, NULL);
return NS_SUCCESS;
};
/*
* Init module
*/
int ModInit( void )
{
ModuleConfig (sns_settings);
DBAOpenTable("seendata");
createseenlist();
if( SeenServ.memorylist )
loadseendata();
return NS_SUCCESS;
}
/*
* Exit module
*/
int ModFini( void )
{
DelTimer ("seenservdbsavetimer");
DelTimer ("removeagedseenrecords");
dbsavetimer(NULL);
destroyseenlist();
DBACloseTable("seendata");
return NS_SUCCESS;
}
/*
* Seen Channel Enable/Disable
*/
static int sns_set_enablechan (const CmdParams *cmdparams, SET_REASON reason)
{
if (!SeenServ.seenchan)
return NS_SUCCESS;
if (reason == SET_CHANGE)
{
if (SeenServ.enableseenchan)
{
irc_join (sns_bot, SeenServ.seenchan, "+o");
irc_chanalert (sns_bot, "Seen functions now available in %s", SeenServ.seenchan);
return NS_SUCCESS;
} else {
irc_part (sns_bot, SeenServ.seenchan, NULL);
irc_chanalert (sns_bot, "Seen functions are no longer available in %s", SeenServ.seenchan);
return NS_SUCCESS;
}
}
return NS_SUCCESS;
}
/*
* Seen Channel Setting
*/
static int sns_set_seenchan (const CmdParams *cmdparams, SET_REASON reason)
{
if (!SeenServ.enableseenchan)
return NS_SUCCESS;
if (reason == SET_VALIDATE)
{
irc_prefmsg (sns_bot, cmdparams->source, "Seen Channel changing from %s to %s", SeenServ.seenchan, cmdparams->av[1]);
irc_chanalert (sns_bot, "Seen Channel Changing to %s , Parting %s (%s)", cmdparams->av[1], SeenServ.seenchan, cmdparams->source->name);
irc_chanprivmsg (sns_bot, SeenServ.seenchan, "\0039%s has changed Channels, Seen functions will now be available in %s", cmdparams->source->name, cmdparams->av[1]);
irc_part (sns_bot, SeenServ.seenchan, NULL);
return NS_SUCCESS;
}
if (reason == SET_CHANGE)
{
irc_join (sns_bot, SeenServ.seenchan, "+o");
irc_chanalert (sns_bot, "Seen functions now available in %s", SeenServ.seenchan);
return NS_SUCCESS;
}
return NS_SUCCESS;
}
/*
* Change Max Entries Saved
*/
static int sns_set_maxentries (const CmdParams *cmdparams, SET_REASON reason)
{
if (reason == SET_CHANGE)
{
checkseenlistlimit(SS_LISTLIMIT_COUNT);
return NS_SUCCESS;
}
return NS_SUCCESS;
}
/*
* Enable/Disable Global Exclusions
*/
static int sns_set_exclusions( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
SetAllEventFlags( EVENT_FLAG_USE_EXCLUDE, SeenServ.exclusions );
return NS_SUCCESS;
}
/*
* Enable/Disable Events
*/
static int sns_set_eventsignon( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventsignon)
EnableEvent(EVENT_SIGNON);
else
DisableEvent(EVENT_SIGNON);
}
return NS_SUCCESS;
}
static int sns_set_eventquit( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventquit)
EnableEvent(EVENT_QUIT);
else
DisableEvent(EVENT_QUIT);
}
return NS_SUCCESS;
}
static int sns_set_eventkill( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventkill)
{
EnableEvent(EVENT_KILL);
EnableEvent(EVENT_LOCALKILL);
EnableEvent(EVENT_GLOBALKILL);
EnableEvent(EVENT_SERVERKILL);
} else {
DisableEvent(EVENT_KILL);
DisableEvent(EVENT_LOCALKILL);
DisableEvent(EVENT_GLOBALKILL);
DisableEvent(EVENT_SERVERKILL);
}
}
return NS_SUCCESS;
}
static int sns_set_eventnick( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventnick)
EnableEvent(EVENT_NICK);
else
DisableEvent(EVENT_NICK);
}
return NS_SUCCESS;
}
static int sns_set_eventjoin( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventjoin)
EnableEvent(EVENT_JOIN);
else
DisableEvent(EVENT_JOIN);
}
return NS_SUCCESS;
}
static int sns_set_eventpart( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventpart)
EnableEvent(EVENT_PART);
else
DisableEvent(EVENT_PART);
}
return NS_SUCCESS;
}
static int sns_set_eventkick( const CmdParams *cmdparams, SET_REASON reason )
{
if( reason == SET_LOAD || reason == SET_CHANGE )
{
if (SeenServ.eventkick)
EnableEvent(EVENT_KICK);
else
DisableEvent(EVENT_KICK);
}
return NS_SUCCESS;
}
/*
* Check Entry Saved Time
*/
static int sns_set_expiretime (const CmdParams *cmdparams, SET_REASON reason)
{
if (reason == SET_CHANGE && SeenServ.expiretime > 0)
{
checkseenlistlimit(SS_LISTLIMIT_AGE);
return NS_SUCCESS;
}
return NS_SUCCESS;
}
/*
* Check DB Update Time and update timer interval
*/
static int sns_set_dbupdatetime (const CmdParams *cmdparams, SET_REASON reason)
{
if (reason == SET_CHANGE)
SetTimerInterval( "seenservdbsavetimer", SeenServ.dbupdatetime );
return NS_SUCCESS;
}
/*
* Check Meory List is actually changing, and perform actions as needed
*/
static int sns_set_memorylist (const CmdParams *cmdparams, SET_REASON reason)
{
if (reason == SET_VALIDATE)
{
if( SeenServ.memorylist && !ircstrcasecmp( cmdparams->av[1], "ON" ) )
{
irc_prefmsg (sns_bot, cmdparams->source, "ERROR: MEMORYLIST is already set ON");
return NS_FAILURE;
}
if( !SeenServ.memorylist && !ircstrcasecmp( cmdparams->av[1], "OFF" ) )
{
irc_prefmsg (sns_bot, cmdparams->source, "ERROR: MEMORYLIST is already set OFF");
return NS_FAILURE;
}
}
if (reason == SET_CHANGE)
{
if( SeenServ.memorylist )
{
loadseendata();
checkseenlistlimit(SS_LISTLIMIT_COUNT);
removeagedseenrecords( NULL);
} else {
dbsavetimer( NULL );
}
}
return NS_SUCCESS;
}
/*
* Remove Aged Records if required
*/
int removeagedseenrecords(void *userptr)
{
SET_SEGV_LOCATION();
if( SeenServ.expiretime > 0 )
checkseenlistlimit(SS_LISTLIMIT_AGE);
return NS_SUCCESS;
}