]>
Commit | Line | Data |
---|---|---|
c86edd1d Q |
1 | #include <time.h> |
2 | #include <string.h> | |
3 | #include <stdlib.h> | |
4 | #include <assert.h> | |
5 | ||
6 | #include "../channel/channel.h" | |
7 | #include "../nick/nick.h" | |
8 | #include "../lib/sstring.h" | |
9 | #include "../localuser/localuserchannel.h" | |
10 | ||
11 | #include "hban.h" | |
12 | #include "hchannel.h" | |
13 | #include "huser.h" | |
14 | #include "helpmod.h" | |
15 | #include "hgen.h" | |
16 | ||
17 | hban *hban_add(const char* pat, const char* rsn, time_t exp, int now) | |
18 | { | |
19 | hban *ptr; | |
20 | chanban *tmp; | |
21 | ||
22 | if (hban_get(pat) || exp <= time(NULL)) | |
23 | return NULL; | |
24 | ||
25 | if ((tmp = makeban(pat)) == NULL) /* bad ban */ | |
26 | return NULL; | |
27 | ||
28 | ptr = (hban*)malloc(sizeof(hban)); | |
29 | ptr->real_ban = tmp; | |
30 | ptr->expiration = exp; | |
31 | ||
32 | if (rsn == NULL) | |
33 | ptr->reason = NULL; | |
34 | else | |
35 | ptr->reason = getsstring(rsn, strlen(rsn)); | |
36 | ||
37 | ptr->next = hbans; | |
38 | hbans = ptr; | |
39 | ||
40 | { /* additional logic here */ | |
41 | huser* tmpu; | |
3a839281 | 42 | for (tmpu = husers;tmpu;tmpu = tmpu->next) |
873f4217 | 43 | if (nickmatchban(tmpu->real_user, tmp, 0) && !IsOper(tmpu->real_user)) |
c86edd1d Q |
44 | { |
45 | hchannel *assert_hchan = NULL; | |
46 | while (tmpu->hchannels) | |
47 | { | |
48 | if (tmpu->hchannels->hchan == assert_hchan) | |
49 | { | |
50 | Error("helpmod", ERR_ERROR, "hban.c hban_add() current channel is the previous channel. Preventing lockup."); | |
51 | break; | |
52 | } | |
53 | assert_hchan = tmpu->hchannels->hchan; | |
54 | helpmod_setban(tmpu->hchannels->hchan, bantostring(ptr->real_ban), HELPMOD_BAN_DURATION, MCB_ADD, now); | |
2c6379d2 | 55 | helpmod_kick(tmpu->hchannels->hchan, tmpu, "%s", hban_get_reason(ptr)); |
c86edd1d | 56 | } |
3a839281 | 57 | } |
c86edd1d Q |
58 | } |
59 | ||
60 | return ptr; | |
61 | } | |
62 | ||
e908ecfa | 63 | hban *hban_huser(huser *husr, const char* rsn, time_t exp, int now) |
c86edd1d | 64 | { |
e908ecfa | 65 | const char *banmask = hban_ban_string(husr->real_user, HBAN_HOST); |
c86edd1d Q |
66 | |
67 | return hban_add(banmask, rsn, exp, now); | |
68 | } | |
69 | ||
70 | hban *hban_del(hban* hb, int now) | |
71 | { | |
72 | hban **ptr = &hbans; | |
73 | for (;*ptr;ptr = &(*ptr)->next) | |
74 | if (*ptr == hb) | |
75 | { | |
76 | hban *tmp = (*ptr)->next; | |
77 | ||
78 | { /* additional logic here */ | |
79 | hchannel *hchan; | |
80 | for (hchan = hchannels;hchan;hchan = hchan->next) | |
81 | helpmod_setban(hchan, bantostring((*ptr)->real_ban), 0, MCB_DEL, now); | |
82 | } | |
83 | ||
84 | freechanban((*ptr)->real_ban); /* evil ? */ | |
85 | freesstring((*ptr)->reason); | |
86 | free(*ptr); | |
87 | ||
88 | *ptr = tmp; | |
89 | return NULL; | |
90 | } | |
91 | return hb; | |
92 | } | |
93 | ||
94 | hban *hban_get(const char* pat) | |
95 | { | |
96 | hban *tmp = hbans; | |
97 | for (;tmp;tmp = tmp->next) | |
98 | if (!ci_strcmp(bantostring(tmp->real_ban),pat)) | |
99 | return tmp; | |
100 | ||
101 | return NULL; | |
102 | } | |
103 | ||
104 | int hban_count(void) | |
105 | { | |
106 | int count = 0; | |
107 | hban *hb = hbans; | |
108 | for (;hb;hb = hb->next) | |
109 | count++; | |
110 | return count; | |
111 | } | |
112 | ||
113 | hban *hban_check(nick *nck) | |
114 | { | |
115 | hban *ptr = hbans; | |
116 | for (;ptr;ptr = ptr->next) | |
873f4217 | 117 | if (nickmatchban(nck, ptr->real_ban, 0)) |
c86edd1d Q |
118 | return ptr; |
119 | return NULL; | |
120 | } | |
121 | ||
122 | void hban_remove_expired(void) | |
123 | { | |
124 | hban **ptr = &hbans; | |
125 | while (*ptr) | |
126 | if ((*ptr)->expiration <= time(NULL)) /* expired */ | |
127 | hban_del(*ptr, 0); | |
128 | else | |
129 | ptr = &(*ptr)->next; | |
130 | hcommit_modes(); | |
131 | } | |
132 | ||
133 | void hban_del_all(void) | |
134 | { | |
135 | while (hbans) | |
136 | hban_del(hbans, 1); | |
137 | } | |
138 | ||
139 | const char *hban_get_reason(hban* hb) | |
140 | { | |
141 | if (hb == NULL) | |
142 | return "error (please contact strutsi)"; | |
143 | else if (hb->reason == NULL) | |
144 | return "banned"; | |
145 | else | |
146 | return hb->reason->content; | |
147 | } | |
148 | ||
149 | const char *hban_ban_string(nick *nck, int banflags) | |
150 | { | |
151 | static char buffer[256]; | |
152 | buffer[0] = '\0'; | |
153 | ||
154 | if (banflags & HBAN_NICK) | |
155 | strcat(buffer, nck->nick); | |
156 | else | |
157 | strcat(buffer, "*"); | |
158 | ||
159 | strcat(buffer, "!"); | |
160 | ||
161 | if (banflags & HBAN_IDENT) | |
162 | strcat(buffer, nck->ident); | |
163 | else | |
164 | strcat(buffer, "*"); | |
165 | ||
166 | strcat(buffer, "@"); | |
167 | ||
660b35f8 | 168 | if ((banflags & HBAN_HOST) && IsAccount(nck) && IsHideHost(nck)) |
b808acb7 | 169 | { |
170 | strcat(buffer, nck->authname); | |
171 | strcat(buffer, ".users.quakenet.org"); | |
172 | } | |
0ff84868 | 173 | else if ((banflags & HBAN_REAL_HOST) || ((banflags & HBAN_HOST))) |
25f8c244 CP |
174 | { |
175 | if (IsSetHost(nck)) | |
176 | strcat(buffer, nck->sethost->content); | |
177 | else | |
c86edd1d | 178 | strcat(buffer, nck->host->name->content); |
25f8c244 | 179 | } |
c86edd1d Q |
180 | else |
181 | strcat(buffer, "*"); | |
182 | ||
183 | assert(strcmp(buffer, "*!*@*")); | |
184 | ||
185 | return buffer; | |
186 | } |