-
Notifications
You must be signed in to change notification settings - Fork 1
/
illegal.c
590 lines (248 loc) · 9.35 KB
/
illegal.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
/***************************************************************************
* 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 *
***************************************************************************/
/***********************************************************/
/* DISCLAIMER: I do not take responsibility for what this */
/* code may do to your health, your computer, your life, */
/* your MUD, your friends, your house or whatever. */
/* You use this code on your own free will. */
/***********************************************************/
/*
in the current code it is possible to illegalize players that are online and when they
try to reconnect then they won't be able to since their name is illegal so be careful.
And tada, now you can add names that are illegal from within the MUD, notice that
the "never" mode makes it impossible for a name to contain the illegal word.
i.e. if you decide to "illegalize stalin never" then no one can make a char with the word "stalin".
neither "astalin" nor "astalinb" nor "stalinb" nor "stalin", if you get my point.
The "equal" mode makes a name that are exactly the same as the illegalized word unuseable.
i.e. illegalizing the word "stalin" with the mode "equal" would make players unable to use the word
"stalin" as their name BUT they could have the name "astalin", "stalinb" or "astalinb".
The "prefix" mode names a name prefixed with the illegal word unuseable.
i.e. illegalizing the word "sir" with the mode "prefix" would stop everyone with the word "sir"
in the beginning of their name. "esirion" would be useable but not "sirion".
Feel free to add modes yourself, one that could be useful is "suffix".
NOTE: the strange `'s are the colorcodes of Chronopia MUD so feel free to
change them to your specific code.
If you have any questions feel free to email me, and I'll try my best to help.
Peace out!
Feb 16 2000
[-Implementor-] [Shadowmage] Angron of Chronopia
*/
/* Illegalize.c -by Angron of Chronopia (inhuman#mad,scientist.com) */
/* Great thanks to Erwin Andreasen for his "disable"-snippet which gave me inspiration */
/* Please email me if you use this code so I know I'm not wasting my time. */
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "magic.h"
#include "recycle.h"
#include <ctype.h>
ILLEGAL_DATA *illegal_first;
/*
* Parse a name for acceptability.
*/
bool check_parse_name(char *name)
{
if (check_illegal(name))
return FALSE;
if (name[0] == '\0')
return FALSE;
if (strlen(name) < 2)
return FALSE;
if (strlen(name) > 12)
return FALSE;
{
char *pc;
bool fIll, adjcaps = FALSE, cleancaps = FALSE;
int total_caps = 0;
fIll = TRUE;
for (pc = name; *pc != '\0'; pc++) {
if (!isalpha(*pc))
return FALSE;
if (isupper(*pc)) {
if (adjcaps)
cleancaps = TRUE;
total_caps++;
adjcaps = TRUE;
} else
adjcaps = FALSE;
if (LOWER(*pc) != 'i' && LOWER(*pc) != 'l')
fIll = FALSE;
}
if (fIll)
return FALSE;
if (cleancaps || ((unsigned) total_caps > (strlen(name)) / 2 && strlen(name) < 3))
return FALSE;
}
return TRUE;
}
void do_illegalize(CHAR_DATA * ch, char *argument)
{
ILLEGAL_DATA *p, *q;
char pWord[MAX_INPUT_LENGTH];
char pMode[MAX_INPUT_LENGTH];
char buf[MAX_STRING_LENGTH];
char kar;
int col = 0;
argument = one_argument(argument, pWord);
argument = one_argument(argument, pMode);
if (IS_NPC(ch)) {
send_to_char("RETURN first.\n\r", ch);
return;
}
if (pWord[0] == '\0' || pMode[0] == '\0') {
if (!illegal_first) {
send_to_char("There are no illegal names.\n\r", ch);
return;
}
send_to_char("Name: Mode: Name: Mode: Name: Mode: Name: Mode: \n\r", ch);
for (p = illegal_first; p; p = p->next) {
sprintf(buf, "%-12s %-8s", p->word, p->mode == '#' ? "equal" : p->mode == '$' ? "never" : p->mode == '@' ? "prefix" : "null");
send_to_char(buf, ch);
if (++col % 4 == 0)
send_to_char("\n\r", ch);
}
send_to_char("\n\r", ch);
return;
}
if (!str_cmp(pMode, "delete")) {
for (p = illegal_first; p; p = p->next)
if (!str_cmp(pWord, p->word))
break;
if (p) {
if (illegal_first == p) /* node to be removed == head ? */
illegal_first = p->next;
else { /* Find the node before this one */
for (q = illegal_first; q->next != p; q = q->next); /* empty for */
q->next = p->next;
}
free_string(p->word);
free_mem(p, sizeof(ILLEGAL_DATA)); /* free node */
save_illegal(); /* save to disk */
send_to_char("Word deleted.\n\r", ch);
return;
} else {
send_to_char("Word not found in the list.\n\r", ch);
return;
}
}
if (strlen(pWord) > 11) {
send_to_char("Word too long.\n\r", ch);
return;
}
if (check_illegal(pWord)) {
send_to_char("That word is already illegal.\n\r", ch);
return;
}
if (!str_cmp(ch->name, pWord) && ch->level >= MAX_LEVEL) {
send_to_char("You were actually going to illegalize yourself?!\n\r", ch);
return;
}
if (!str_cmp(pMode, "equal"))
kar = '#';
else if (!str_cmp(pMode, "never"))
kar = '$';
else if (!str_cmp(pMode, "prefix"))
kar = '@';
else {
send_to_char("Wrong mode.\n\r", ch);
return;
}
p = alloc_mem(sizeof(ILLEGAL_DATA));
p->mode = kar;
p->word = str_dup(pWord);
p->next = illegal_first;
illegal_first = p; /* add before the current first element */
send_to_char("Word illegalized.\n\r", ch);
save_illegal(); /* save to disk */
return;
}
bool check_illegal(char *name)
{
ILLEGAL_DATA *p;
for (p = illegal_first; p; p = p->next) {
if (p->mode == '#') {
if (!str_cmp(name, p->word) || is_name(name, p->word) || is_exact_name(name, p->word))
return TRUE;
} else if (p->mode == '@') {
if (!str_prefix(p->word, name))
return TRUE;
} else if (p->mode == '$') {
if (!str_cmp(name, p->word) || is_exact_name(name, p->word) || is_name(name, p->word) ||
!str_infix(name, p->word) || !str_prefix(p->word, name) || strstr(name, p->word))
return TRUE;
}
}
return FALSE;
}
void load_illegal()
{
FILE *fp;
ILLEGAL_DATA *p;
char kar;
illegal_first = NULL;
fclose(fpReserve);
fp = fopen(NAME_FILE, "r");
if (!fp)
return;
do {
kar = fread_letter(fp);
if (kar == EOF)
break;
if (kar == '#' || kar == '$' || kar == '@') {
p = alloc_mem(sizeof(ILLEGAL_DATA));
p->mode = kar;
p->word = str_dup(fread_word(fp));
p->next = illegal_first;
illegal_first = p;
}
}
while (kar != EOF);
fclose(fp);
fpReserve = fopen(NULL_FILE, "r");
}
void save_illegal()
{
FILE *fp;
ILLEGAL_DATA *p;
if (!illegal_first) {
unlink(NAME_FILE);
return;
}
fclose(fpReserve);
fp = fopen(NAME_FILE, "w");
if (!fp) {
bug("Could not open " NAME_FILE " for writing", 0);
return;
}
for (p = illegal_first; p; p = p->next)
fprintf(fp, "%c \'%s\'\n", p->mode, p->word);
fclose(fp);
fpReserve = fopen(NULL_FILE, "r");
}
/**************************End Illegal.c************************************'*/