/
olc.c
executable file
·364 lines (323 loc) · 9.07 KB
/
olc.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* ************************************************************************
* File: olc.c Part of CircleMUD *
* Usage: online creation *
* *
* All rights reserved. See license.doc for complete information. *
* *
* Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University *
* CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. *
************************************************************************ */
/*
* PLEASE, FOR THE LOVE OF GOD, DON'T TRY TO USE THIS YET!!!
* *** DO *** NOT *** SEND ME MAIL ASKING WHY IT DOESN'T WORK -- IT'S
* NOT DONE!!
*/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "olc.h"
/* OLC command format:
*
* olc {"." | {<"room"|"mobile"|"object"> <number>}} <arguments>
* olc {"set"|"show"} <attribute> <arguments>
*/
#define OLC_USAGE "Usage: olc { . | set | show | obj | mob | room} [args]\r\n"
extern struct room_data *world;
extern struct obj_data *obj_proto;
extern struct char_data *mob_proto;
struct char_data *olc_ch;
/* local functions */
void olc_interpreter(void *targ, int mode, char *arg);
void olc_set_show(struct char_data * ch, int olc_mode, char *arg);
void olc_string(char **string, size_t maxlen, char *arg);
int can_modify(struct char_data * ch, int vnum);
ACMD(do_olc);
void olc_bitvector(int *bv, const char **names, char *arg);
const char *olc_modes[] = {
"set", /* set OLC characteristics */
"show", /* show OLC characteristics */
".", /* repeat last modification command */
"room", /* modify a room */
"mobile", /* modify a mobile */
"object", /* modify an object */
"\n"
};
const char *olc_commands[] = {
"copy",
"name",
"description",
"aliases",
"\n", /* many more to be added */
};
/* The actual do_olc command for the interpreter. Determines the target
entity, checks permissions, and passes control to olc_interpreter */
ACMD(do_olc)
{
void *olc_targ = NULL;
char mode_arg[MAX_INPUT_LENGTH];
room_rnum rnum;
room_vnum vnum = NOWHERE;
int olc_mode;
/* WARNING! **DO NOT** under any circumstances remove the code below!!!! */
if (strcmp(GET_NAME(ch), "Ras")) {
send_to_char("OLC is not yet complete. Sorry.\r\n", ch);
return;
}
/* WARNING! **DO NOT** under any circumstances remove the code above!!!! */
/* first, figure out the first (mode) argument */
half_chop(argument, mode_arg, argument);
if ((olc_mode = search_block(mode_arg, olc_modes, FALSE)) < 0) {
sprintf(buf, "Invalid mode '%s'.\r\n", mode_arg);
send_to_char(buf, ch);
send_to_char(OLC_USAGE, ch);
return;
}
switch (olc_mode) {
case OLC_SET:
case OLC_SHOW:
olc_set_show(ch, olc_mode, argument);
return;
case OLC_REPEAT:
if (!(olc_mode = GET_LAST_OLC_MODE(ch)) ||
((olc_targ = GET_LAST_OLC_TARG(ch)) == NULL)) {
send_to_char("No last OLC operation!\r\n", ch);
return;
}
break;
case OLC_ROOM:
if (isdigit(*argument)) {
/* room specified. take the numeric argument off */
argument = one_argument(argument, arg);
if ((vnum = atoi(arg)) < 0) {
sprintf(buf, "Invalid room vnum '%s'.\r\n", arg);
send_to_char(buf, ch);
return;
}
if ((rnum = real_room(vnum)) == NOWHERE) {
send_to_char("No such room!\r\n", ch);
return;
}
} else {
rnum = IN_ROOM(ch);
vnum = GET_ROOM_VNUM(IN_ROOM(ch));
sprintf(buf, "(Using current room %d)\r\n", vnum);
send_to_char(buf, ch);
}
/* if (!ROOM_FLAGGED(rnum, ROOM_OLC))
send_to_char("That room is not modifyable.\r\n", ch);
else
*/
olc_targ = (void *) &(world[rnum]);
break;
case OLC_MOB:
argument = one_argument(argument, arg);
if ((vnum = atoi(arg)) < 0) {
sprintf(buf, "Invalid mob vnum '%s'.\r\n", arg);
send_to_char(buf, ch);
return;
}
if ((rnum = real_mobile(vnum)) < 0)
send_to_char("No such mobile vnum.\r\n", ch);
else
olc_targ = (void *) &(mob_proto[rnum]);
break;
case OLC_OBJ:
argument = one_argument(argument, arg);
if ((vnum = atoi(arg)) < 0) {
sprintf(buf, "Invalid obj vnum '%s'\r\n", arg);
send_to_char(buf, ch);
return;
}
if ((rnum = real_object(vnum)) < 0) {
sprintf(buf, "No object with vnum %d.\r\n", vnum);
send_to_char(buf, ch);
} else
olc_targ = (void *) &(obj_proto[rnum]);
break;
default:
send_to_char("Usage: olc {.|set|show|obj|mob|room} [args]\r\n", ch);
return;
}
if (olc_targ == NULL)
return;
if (!can_modify(ch, vnum)) {
send_to_char("You can't modify that.\r\n", ch);
return;
}
GET_LAST_OLC_MODE(ch) = olc_mode;
GET_LAST_OLC_TARG(ch) = olc_targ;
olc_ch = ch;
olc_interpreter(olc_targ, olc_mode, argument);
/* freshen? */
}
/* OLC interpreter command; called by do_olc */
void olc_interpreter(void *targ, int mode, char *arg)
{
int error = 0, command;
char command_string[MAX_INPUT_LENGTH];
struct char_data *olc_mob = NULL;
struct room_data *olc_room = NULL;
struct obj_data *olc_obj = NULL;
half_chop(arg, command_string, arg);
if ((command = search_block(command_string, olc_commands, FALSE)) < 0) {
sprintf(buf, "Invalid OLC command '%s'.\r\n", command_string);
send_to_char(buf, olc_ch);
return;
}
switch (mode) {
case OLC_ROOM:
olc_room = (struct room_data *) targ;
break;
case OLC_MOB:
olc_mob = (struct char_data *) targ;
break;
case OLC_OBJ:
olc_obj = (struct obj_data *) targ;
break;
default:
log("SYSERR: Invalid OLC mode %d passed to interp.", mode);
return;
}
switch (command) {
case OLC_COPY:
switch (mode) {
case OLC_ROOM:
break;
case OLC_MOB:
break;
case OLC_OBJ:
break;
default:
error = 1;
break;
}
break;
case OLC_NAME:
switch (mode) {
case OLC_ROOM:
olc_string(&(olc_room->name), MAX_ROOM_NAME, arg);
break;
case OLC_MOB:
olc_string(&olc_mob->player.short_descr, MAX_MOB_NAME, arg);
break;
case OLC_OBJ:
olc_string(&olc_obj->short_description, MAX_OBJ_NAME, arg);
break;
default:
error = 1;
break;
}
break;
case OLC_DESC:
switch (mode) {
case OLC_ROOM:
olc_string(&olc_room->description, MAX_ROOM_DESC, arg);
break;
case OLC_MOB:
olc_string(&olc_mob->player.long_descr, MAX_MOB_DESC, arg);
break;
case OLC_OBJ:
olc_string(&olc_obj->description, MAX_OBJ_DESC, arg);
break;
default:
error = 1;
break;
}
break;
case OLC_ALIASES:
switch (mode) {
case OLC_ROOM:
break;
case OLC_MOB:
break;
case OLC_OBJ:
break;
default:
error = 1;
break;
}
}
}
/* can_modify: determine if a particular char can modify a vnum */
int can_modify(struct char_data * ch, int vnum)
{
return (1);
}
/* generic fn for modifying a string */
void olc_string(char **string, size_t maxlen, char *arg)
{
skip_spaces(&arg);
if (!*arg) {
sprintf(buf, "Enter new string (max of %d characters); "
"use '@' on a new line when done.\r\n", (int) maxlen);
send_to_char(buf, olc_ch);
**string = '\0';
string_write(olc_ch->desc, string, maxlen, 0, NULL);
} else {
if (strlen(arg) > maxlen) {
sprintf(buf, "String too long (cannot be more than %d chars).\r\n",
(int) maxlen);
send_to_char(buf, olc_ch);
} else {
if (*string != NULL)
free(*string);
*string = str_dup(arg);
send_to_char(OK, olc_ch);
}
}
}
/* generic fn for modifying a bitvector */
void olc_bitvector(int *bv, const char **names, char *arg)
{
int newbv, flagnum, remove = 0;
char *this_name;
skip_spaces(&arg);
if (!*arg) {
send_to_char("Flag list or flag modifiers required.\r\n", olc_ch);
return;
}
/* determine if this is 'absolute' or 'relative' mode */
if (*arg == '+' || *arg == '-')
newbv = *bv;
else
newbv = 0;
while (*arg) {
arg = one_argument(arg, buf); /* get next argument */
/* change to upper-case */
for (this_name = buf; *this_name; this_name++)
CAP(this_name);
/* determine if this is an add or a subtract */
if (*buf == '+' || *buf == '-') {
this_name = buf + 1;
if (*buf == '-')
remove = TRUE;
else
remove = FALSE;
} else {
this_name = buf;
remove = FALSE;
}
/* figure out which one we're dealing with */
if ((flagnum = search_block(this_name, names, TRUE)) < 0) {
sprintf(buf2, "Unknown flag: %s\r\n", this_name);
send_to_char(buf2, olc_ch);
} else {
if (remove)
REMOVE_BIT(newbv, (1 << flagnum));
else
SET_BIT(newbv, (1 << flagnum));
}
}
*bv = newbv;
sprintbit(newbv, names, buf);
sprintf(buf2, "Flags now set to: %s\r\n", buf);
send_to_char(buf2, olc_ch);
}
void olc_set_show(struct char_data * ch, int olc_mode, char *arg)
{
}