]> jfr.im git - irc/quakenet/newserv.git/blame - helpmod/helpmod_user.c
Initial Import
[irc/quakenet/newserv.git] / helpmod / helpmod_user.c
CommitLineData
c86edd1d
Q
1#include "helpmod_user.h"
2#include "helpmod_entries.h"
3
4helpmod_user helpmod_get_user(long numeric)
5{
6
7 helpmod_user *tmp,tmp2;
8 for(tmp=&helpmod_users;*tmp;tmp=&(*tmp)->next)
9 if ((*tmp)->numeric == numeric)
10 {
11 (*tmp)->last_active = time(NULL);
12 return *tmp;
13 }
14 tmp2 = *tmp;
15 *tmp = (helpmod_user)malloc(sizeof(struct helpmod_user_struct));
16 (*tmp)->next = tmp2;
17 (*tmp)->last_active = time(NULL);
18 (*tmp)->numeric = numeric;
19 (*tmp)->state = helpmod_base;
20 return *tmp;
21}
22
23void helpmod_clear_users(void)
24{
25 helpmod_user tmp;
26 while (helpmod_users)
27 {
28 tmp = helpmod_users->next;
29 free(helpmod_users);
30 helpmod_users = tmp;
31 }
32 helpmod_users = NULL;
33}
34
35void helpmod_init_users(void)
36{
37 helpmod_users = NULL;
38}
39
40void helpmod_clear_inactives(void)
41{
42 helpmod_user *tmp, tmp2;
43 for (tmp = &helpmod_users;*tmp;tmp = &(*tmp)->next)
44 while (time(NULL) - (*tmp)->last_active > HELPMOD_USER_TIMEOUT)
45 {
46 tmp2 = (*tmp)->next;
47 free(*tmp);
48 *tmp = tmp2;
49 if (!*tmp)
50 return;
51 }
52}
53
54long helpmod_user_count(void)
55{
56 helpmod_user *tmp;
57 long counter;
58 for (counter=0, tmp = &helpmod_users;*tmp;counter++, tmp = &(*tmp)->next);
59 return counter;
60}