-
Notifications
You must be signed in to change notification settings - Fork 0
/
ban.c
326 lines (277 loc) · 7.91 KB
/
ban.c
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
/***************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefitting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************/
/***************************************************************************
* ROM 2.4 is copyright 1993-1996 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@efn.org) *
* Gabrielle Taylor *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************/
#if defined(macintosh)
#include <types.h>
#include <time.h>
#else
#include <sys/types.h>
#endif
#if defined(unix)
#include <sys/time.h>
#else
#include <time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "merc.h"
#include "recycle.h"
BAN_DATA *ban_list;
void save_bans(void)
{
BAN_DATA *pban;
FILE *fp;
bool found = FALSE;
fclose( fpReserve );
if ( ( fp = fopen( BAN_FILE, "w" ) ) == NULL )
{
perror( BAN_FILE );
}
for (pban = ban_list; pban != NULL; pban = pban->next)
{
if (IS_SET(pban->ban_flags,BAN_PERMANENT))
{
found = TRUE;
fprintf(fp,"%-20s %-2d %s\n",pban->name,pban->level,
print_flags(pban->ban_flags));
}
}
fclose(fp);
fpReserve = fopen( NULL_FILE, "r" );
if (!found)
unlink(BAN_FILE);
}
void load_bans(void)
{
FILE *fp;
BAN_DATA *ban_last;
if ( ( fp = fopen( BAN_FILE, "r" ) ) == NULL )
return;
ban_last = NULL;
for ( ; ; )
{
BAN_DATA *pban;
if ( feof(fp) )
{
fclose( fp );
return;
}
pban = new_ban();
pban->name = str_dup(fread_word(fp));
pban->level = fread_number(fp);
pban->ban_flags = fread_flag(fp);
fread_to_eol(fp);
if (ban_list == NULL)
ban_list = pban;
else
ban_last->next = pban;
ban_last = pban;
}
}
bool check_ban(char *site,int type)
{
BAN_DATA *pban;
char host[MAX_STRING_LENGTH];
char *p = host;
strcpy(host,site);
while (*p != '\0')
{
*p = LOWER(*p);
p++;
}
for ( pban = ban_list; pban != NULL; pban = pban->next )
{
if(!IS_SET(pban->ban_flags,type))
continue;
if (IS_SET(pban->ban_flags,BAN_PREFIX)
&& IS_SET(pban->ban_flags,BAN_SUFFIX)
&& strstr(host, pban->name) != NULL)
return TRUE;
if (IS_SET(pban->ban_flags,BAN_PREFIX)
&& !str_suffix(host, pban->name))
return TRUE;
if (IS_SET(pban->ban_flags,BAN_SUFFIX)
&& !str_prefix(host, pban->name))
return TRUE;
}
return FALSE;
}
void ban_site(CHAR_DATA *ch, char *argument, bool fPerm)
{
char buf[MAX_STRING_LENGTH],buf2[MAX_STRING_LENGTH];
char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
char *name;
BUFFER *buffer;
BAN_DATA *pban, *prev;
bool prefix = FALSE,suffix = FALSE;
int type;
argument = one_argument(argument,arg1);
argument = one_argument(argument,arg2);
if ( arg1[0] == '\0' )
{
if (ban_list == NULL)
{
send_to_char("No sites banned at this time.\n\r",ch);
return;
}
buffer = new_buf();
add_buf(buffer,"Banned sites level type status\n\r");
for (pban = ban_list;pban != NULL;pban = pban->next)
{
sprintf(buf2,"%s%s%s",
IS_SET(pban->ban_flags,BAN_PREFIX) ? "*" : "",
pban->name,
IS_SET(pban->ban_flags,BAN_SUFFIX) ? "*" : "");
sprintf(buf,"%-50s %-3d %-7s %s\n\r",
buf2, pban->level,
IS_SET(pban->ban_flags,BAN_NEWBIES) ? "newbies" :
IS_SET(pban->ban_flags,BAN_PERMIT) ? "permit" :
IS_SET(pban->ban_flags,BAN_ALL) ? "all" :
IS_SET(pban->ban_flags,BAN_WARNING) ? "warning" : "",
IS_SET(pban->ban_flags,BAN_PERMANENT) ? "perm" : "temp");
add_buf(buffer,buf);
}
page_to_char( buf_string(buffer), ch );
free_buf(buffer);
return;
}
/* find out what type of ban */
if (arg2[0] == '\0' || !str_prefix(arg2,"all"))
type = BAN_ALL;
else if (!str_prefix(arg2, "newbies"))
type = BAN_NEWBIES;
else if (!str_prefix(arg2, "permit"))
type = BAN_PERMIT;
else if (!str_prefix(arg2, "warning"))
type = BAN_WARNING;
else
{
send_to_char("Acceptable ban types are all, newbies, permit, and warning.\n\r", ch);
return;
}
name = arg1;
if (name[0] == '*')
{
prefix = TRUE;
name++;
}
if (name[strlen(name) - 1] == '*')
{
suffix = TRUE;
name[strlen(name) - 1] = '\0';
}
if (strlen(name) == 0)
{
send_to_char("You have to ban SOMETHING.\n\r",ch);
return;
}
prev = NULL;
for ( pban = ban_list; pban != NULL; prev = pban, pban = pban->next )
{
if (!str_cmp(name,pban->name))
{
if (pban->level > get_trust(ch))
{
send_to_char( "That ban was set by a higher power.\n\r", ch );
return;
}
else
{
if (prev == NULL)
ban_list = pban->next;
else
prev->next = pban->next;
free_ban(pban);
}
}
}
pban = new_ban();
pban->name = str_dup(name);
pban->level = get_trust(ch);
/* set ban type */
pban->ban_flags = type;
if (prefix)
SET_BIT(pban->ban_flags,BAN_PREFIX);
if (suffix)
SET_BIT(pban->ban_flags,BAN_SUFFIX);
if (fPerm)
SET_BIT(pban->ban_flags,BAN_PERMANENT);
pban->next = ban_list;
ban_list = pban;
save_bans();
if (type == BAN_WARNING)
sprintf(buf, "%s has been placed on the warning list.\n\r", pban->name);
else
sprintf(buf,"%s has been banned.\n\r",pban->name);
send_to_char( buf, ch );
send_to_char("Make sure you update the wiki to keep track of why sites have been banned!\n\r", ch);
return;
}
void do_ban(CHAR_DATA *ch, char *argument)
{
ban_site(ch,argument,FALSE);
}
void do_permban(CHAR_DATA *ch, char *argument)
{
ban_site(ch,argument,TRUE);
}
void do_allow( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
char buf[MAX_STRING_LENGTH];
BAN_DATA *prev;
BAN_DATA *curr;
one_argument( argument, arg );
if ( arg[0] == '\0' )
{
send_to_char( "Remove which site from the ban list?\n\r", ch );
return;
}
prev = NULL;
for ( curr = ban_list; curr != NULL; prev = curr, curr = curr->next )
{
if ( !str_cmp( arg, curr->name ) )
{
if (curr->level > get_trust(ch))
{
send_to_char(
"You are not powerful enough to lift that ban.\n\r",ch);
return;
}
if ( prev == NULL )
ban_list = ban_list->next;
else
prev->next = curr->next;
free_ban(curr);
sprintf(buf,"Ban on %s lifted.\n\r",arg);
send_to_char( buf, ch );
save_bans();
return;
}
}
send_to_char( "Site is not banned.\n\r", ch );
return;
}