]> jfr.im git - irc/quakenet/newserv.git/blob - helpmod2/haccount.c
TRUSTS: use correct socket opt...
[irc/quakenet/newserv.git] / helpmod2 / haccount.c
1
2 #include <string.h>
3 #include <stdlib.h>
4 #include <time.h>
5
6 #include "../lib/sstring.h"
7 #include "../lib/irc_string.h"
8
9 #include "haccount.h"
10 #include "helpmod.h"
11 #include "huser.h"
12 #include "hgen.h"
13
14 haccount *haccount_get_by_name(const char *name)
15 {
16 haccount *tmp;
17
18 if (name == NULL)
19 return NULL;
20
21 if (*name == '#')
22 name++;
23
24 tmp = haccounts;
25 for (;tmp;tmp = tmp->next)
26 if (!ircd_strcmp(tmp->name->content, name))
27 return tmp;
28
29 return NULL;
30 }
31
32 haccount *haccount_add(const char *name, hlevel lvl)
33 {
34 haccount *tmp;
35
36 if (haccount_get_by_name(name))
37 {
38 Error("helpmod", ERR_ERROR, "Attempt to add a duplicate account: %s", name);
39 return haccount_get_by_name(name);
40 }
41
42 if (*name == '#')
43 name++;
44
45 tmp = (haccount*)malloc(sizeof (haccount));
46 tmp->name = getsstring(name, strlen(name));
47 tmp->level = lvl;
48 tmp->flags = H_ACCFLAGS_DEFAULT;
49 tmp->last_activity = time(NULL);
50 tmp->stats = NULL;
51
52 tmp->next = haccounts;
53 haccounts = tmp;
54
55 return tmp;
56 }
57
58 int haccount_del(haccount *hack)
59 {
60 huser *h_ptr = husers;
61 haccount **ptr = &haccounts;
62
63 for (;h_ptr;h_ptr = h_ptr->next)
64 if (h_ptr->account == hack)
65 h_ptr->account = NULL;
66
67 for (;*ptr;ptr = &(*ptr)->next)
68 if (*ptr == hack)
69 {
70 hstat_account *tmp_stat;
71 haccount *tmp = (*ptr)->next;
72
73 while ((*ptr)->stats)
74 {
75 tmp_stat = (*ptr)->stats->next;
76 free((*ptr)->stats);
77 (*ptr)->stats = tmp_stat;
78 }
79
80 freesstring((*ptr)->name);
81 free(*ptr);
82
83 *ptr = tmp;
84 return 0;
85 }
86
87 return 0;
88 }
89
90 void haccount_clear_inactives(void)
91 {
92 haccount **ptr = &haccounts;
93 while (*ptr)
94 if ((time(NULL) - (*ptr)->last_activity > HELPMOD_ACCOUNT_EXPIRATION[(*ptr)->level]) && !((*ptr)->flags & H_NO_EXPIRE))
95 haccount_del(*ptr);
96 else
97 ptr = &(*ptr)->next;
98 }
99
100 void haccount_set_level(haccount *hack, hlevel lvl)
101 {
102 if (hack == NULL)
103 return;
104 hack->level = lvl;
105 }
106
107 const char *haccount_get_state(haccount* hacc, int mask)
108 {
109 if (hacc->flags & mask)
110 return "Yes";
111 else
112 return "No";
113 }
114
115 int haccount_count(hlevel lvl)
116 {
117 haccount *hacc = haccounts;
118 int count = 0;
119 for (;hacc;hacc = hacc->next)
120 if (lvl == H_ANY)
121 count++;
122 else if (hacc->level == lvl)
123 count++;
124 return count;
125 }
126
127 const char *haccount_get_sname(int index)
128 {
129 switch (index)
130 {
131 case 0:
132 return "Send replies as private messages";
133 case 1:
134 return "Send replies as notices";
135 case 2:
136 return "Do not send verbose messages";
137 case 3:
138 return "Auto-op on join";
139 case 4:
140 return "Auto-voice on join";
141 case 5:
142 return "Suppress unknown command error";
143 default:
144 return "Error. Please contact strutsi";
145 }
146 }