]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
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 = (haccount*)malloc(sizeof (haccount)); | |
35 | ||
e908ecfa | 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 | ||
c86edd1d Q |
42 | if (*name == '#') |
43 | name++; | |
44 | ||
45 | tmp->name = getsstring(name, strlen(name)); | |
46 | tmp->level = lvl; | |
47 | tmp->flags = H_ACCFLAGS_DEFAULT; | |
48 | tmp->last_activity = time(NULL); | |
49 | tmp->stats = NULL; | |
50 | ||
51 | tmp->next = haccounts; | |
52 | haccounts = tmp; | |
53 | ||
54 | return tmp; | |
55 | } | |
56 | ||
57 | int haccount_del(haccount *hack) | |
58 | { | |
59 | huser *h_ptr = husers; | |
60 | haccount **ptr = &haccounts; | |
61 | ||
62 | for (;h_ptr;h_ptr = h_ptr->next) | |
63 | if (h_ptr->account == hack) | |
64 | h_ptr->account = NULL; | |
65 | ||
66 | for (;*ptr;ptr = &(*ptr)->next) | |
67 | if (*ptr == hack) | |
68 | { | |
69 | hstat_account *tmp_stat; | |
70 | haccount *tmp = (*ptr)->next; | |
71 | ||
72 | while ((*ptr)->stats) | |
73 | { | |
74 | tmp_stat = (*ptr)->stats->next; | |
75 | free((*ptr)->stats); | |
76 | (*ptr)->stats = tmp_stat; | |
77 | } | |
78 | ||
79 | freesstring((*ptr)->name); | |
80 | free(*ptr); | |
81 | ||
82 | *ptr = tmp; | |
83 | return 0; | |
84 | } | |
85 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | void haccount_clear_inactives(void) | |
90 | { | |
91 | haccount **ptr = &haccounts; | |
92 | while (*ptr) | |
93 | if (time(NULL) - (*ptr)->last_activity > HELPMOD_ACCOUNT_EXPIRATION[(*ptr)->level]) | |
94 | haccount_del(*ptr); | |
95 | else | |
96 | ptr = &(*ptr)->next; | |
97 | } | |
98 | ||
99 | void haccount_set_level(haccount *hack, hlevel lvl) | |
100 | { | |
101 | if (hack == NULL) | |
102 | return; | |
103 | hack->level = lvl; | |
104 | } | |
105 | ||
106 | const char *haccount_get_state(haccount* hacc, int mask) | |
107 | { | |
108 | if (hacc->flags & mask) | |
109 | return "On"; | |
110 | else | |
111 | return "Off"; | |
112 | } | |
113 | ||
114 | int haccount_count(hlevel lvl) | |
115 | { | |
116 | haccount *hacc = haccounts; | |
117 | int count = 0; | |
118 | for (;hacc;hacc = hacc->next) | |
119 | if (lvl == H_ANY) | |
120 | count++; | |
121 | else if (hacc->level == lvl) | |
122 | count++; | |
123 | return count; | |
124 | } | |
125 | ||
126 | const char *haccount_get_sname(int index) | |
127 | { | |
128 | switch (index) | |
129 | { | |
130 | case 0: | |
131 | return "Send replies as private messages"; | |
132 | case 1: | |
133 | return "Send replies as notices"; | |
134 | case 2: | |
135 | return "Do not send verbose messages"; | |
136 | case 3: | |
137 | return "Auto-op on join"; | |
138 | case 4: | |
139 | return "Auto-voice on join"; | |
04f3fbba | 140 | case 5: |
141 | return "Suppress unknown command error"; | |
c86edd1d Q |
142 | default: |
143 | return "error. Please contact strutsi"; | |
144 | } | |
145 | } |