-
Notifications
You must be signed in to change notification settings - Fork 0
/
act.social.c
506 lines (428 loc) · 15.4 KB
/
act.social.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
/* ************************************************************************
* File: act.social.c Part of CircleMUD *
* Usage: Functions to handle socials *
* *
* 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. *
************************************************************************ */
#include "conf.h"
#include "sysdep.h"
SVNHEADER("$Id: act.social.c 55 2009-03-20 17:58:56Z pladow $");
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "spells.h"
/* globals */
extern int top_of_socialt;
extern struct social_messg *soc_mess_list;
/* local functions */
char *fread_action(FILE *fl, int nr);
int find_action(int cmd);
ACMD(do_action);
ACMD(do_insult);
void boot_social_messages(void);
void free_social_messages(void);
void free_action(struct social_messg *mess);
void free_command_list(void);
char *which_desc(struct char_data *ch);
int has_intro(struct char_data *ch, struct char_data *target);
ACMD(do_action)
{
char arg[MAX_INPUT_LENGTH], part[MAX_INPUT_LENGTH];
int act_nr;
struct social_messg *action;
struct char_data *vict;
struct obj_data *targ;
if (PLR_FLAGGED(ch, PLR_NOSHOUT)) {
send_to_char(ch, "You cannot do socials when muted.\r\n");
return;
}
if ((act_nr = find_action(cmd)) < 0) {
send_to_char(ch, "That action is not supported.\r\n");
return;
}
action = &soc_mess_list[act_nr];
if (!argument || !*argument) {
send_to_char(ch, "%s\r\n", action->char_no_arg);
act(action->others_no_arg, action->hide, ch, 0, 0, TO_ROOM);
return;
}
two_arguments(argument, arg, part);
if ((!action->char_body_found) && (*part)) {
send_to_char(ch, "Sorry, this social does not support body parts.\r\n");
return;
}
if (!action->char_found)
*arg = '\0';
if (action->char_found && argument)
one_argument(argument, arg);
else
*arg = '\0';
vict = get_char_vis(ch, arg, NULL, FIND_CHAR_ROOM);
if (!vict) {
if (action->char_obj_found) {
targ = get_obj_in_list_vis(ch, arg, NULL, ch->carrying);
if (!targ) targ = get_obj_in_list_vis(ch, arg, NULL, world[IN_ROOM(ch)].contents);
if (targ) {
act(action->char_obj_found, action->hide, ch, targ, 0, TO_CHAR);
act(action->others_obj_found, action->hide, ch, targ, 0, TO_ROOM);
return;
}
}
if (action->not_found)
send_to_char(ch, "%s\r\n", action->not_found);
else
send_to_char(ch, "I don't see anything by that name here.\r\n");
return;
}
if (vict == ch) {
if (action->char_auto)
send_to_char(ch, "%s\r\n", action->char_auto);
else
send_to_char(ch, "Erm, no.");
act(action->others_auto, action->hide, ch, 0, 0, TO_ROOM);
return;
}
if (GET_POS(vict) < action->min_victim_position)
act("$N is not in a proper position for that.", false, ch, 0, vict, TO_CHAR | TO_SLEEP);
else {
if (*part) {
act(action->char_body_found, 0, ch, (struct obj_data *)part, vict, TO_CHAR | TO_SLEEP);
act(action->others_body_found, action->hide, ch, (struct obj_data *)part, vict, TO_NOTVICT);
act(action->vict_body_found, action->hide, ch, (struct obj_data *)part, vict, TO_VICT);
} else {
act(action->char_found, 0, ch, 0, vict, TO_CHAR | TO_SLEEP);
act(action->others_found, action->hide, ch, 0, vict, TO_NOTVICT);
act(action->vict_found, action->hide, ch, 0, vict, TO_VICT);
}
}
}
ACMD(do_insult)
{
char arg[MAX_INPUT_LENGTH];
struct char_data *victim;
one_argument(argument, arg);
if (*arg) {
if (!(victim = get_char_vis(ch, arg, NULL, FIND_CHAR_ROOM)))
send_to_char(ch, "Can't hear you!\r\n");
else {
if (victim != ch) {
send_to_char(ch, "You insult %s.\r\n", has_intro(ch, victim) ? GET_NAME(victim) : GET_SHORT_DESC(victim));
switch (rand_number(0, 2)) {
case 0:
if (GET_SEX(ch) == SEX_MALE) {
if (GET_SEX(victim) == SEX_MALE)
act("$n accuses you of fighting like a woman!", false, ch, 0, victim, TO_VICT);
else
act("$n says that women can't fight.", false, ch, 0, victim, TO_VICT);
} else { /* Ch == Woman */
if (GET_SEX(victim) == SEX_MALE)
act("$n accuses you of having the smallest... (brain?)",
false, ch, 0, victim, TO_VICT);
else
act("$n tells you that you'd lose a beauty contest against a troll.",
false, ch, 0, victim, TO_VICT);
}
break;
case 1:
act("$n calls your mother a bitch!", false, ch, 0, victim, TO_VICT);
break;
default:
act("$n tells you to get lost!", false, ch, 0, victim, TO_VICT);
break;
} /* end switch */
act("$n insults $N.", true, ch, 0, victim, TO_NOTVICT);
} else { /* ch == victim */
send_to_char(ch, "You feel insulted.\r\n");
}
}
} else
send_to_char(ch, "I'm sure you don't want to insult *everybody*...\r\n");
}
void boot_social_messages(void)
{
FILE *fl;
char *trash = NULL;
int itrash = 0;
int nr = 0, hide, min_char_pos, min_pos, min_lvl, curr_soc = -1;
char next_soc[MAX_STRING_LENGTH], sorted[MAX_INPUT_LENGTH];
if (CONFIG_NEW_SOCIALS == true) {
/* open social file */
if (!(fl = fopen(SOCMESS_FILE_NEW, "r"))) {
log("SYSERR: can't open socials file '%s': %s", SOCMESS_FILE_NEW, strerror(errno));
/* SYSERR_DESC:
* This error, from boot_social_messages(), occurs when the server
* fails to open the file containing the social messages. The error
* at the end will indicate the reason why.
*/
exit(1);
}
/* count socials */
*next_soc = '\0';
while (!feof(fl)) {
trash = fgets(next_soc, MAX_STRING_LENGTH, fl);
if (*next_soc == '~') top_of_socialt++;
}
} else { /* old style */
/* open social file */
if (!(fl = fopen(SOCMESS_FILE, "r"))) {
log("SYSERR: can't open socials file '%s': %s", SOCMESS_FILE, strerror(errno));
exit(1);
}
/* count socials */
while (!feof(fl)) {
trash = fgets(next_soc, MAX_STRING_LENGTH, fl);
if (*next_soc == '\n' || *next_soc == '\r') top_of_socialt++; /* all socials are followed by a blank line */
}
}
log("Social table contains %d socials.", top_of_socialt);
rewind(fl);
CREATE(soc_mess_list, struct social_messg, top_of_socialt + 1);
/* now read 'em */
for (;;) {
itrash = fscanf(fl, " %s ", next_soc);
if (*next_soc == '$') break;
if (CONFIG_NEW_SOCIALS == true) {
if (fscanf(fl, " %s %d %d %d %d \n",
sorted, &hide, &min_char_pos, &min_pos, &min_lvl) != 5) {
log("SYSERR: format error in social file near social '%s'", next_soc);
/* SYSERR_DESC:
* From boot_social_messages(), this error is output when the
* server is expecting to find the remainder of the first line of the
* social ('hide' and 'minimum position'). These must follow the
* name of the social with a single space such as: 'accuse 0 5\n'.
* This error often occurs when one of the numbers is missing or the
* social name has a space in it (i.e., 'bend over').
*/
exit(1);
}
curr_soc++;
soc_mess_list[curr_soc].command = strdup(next_soc+1);
soc_mess_list[curr_soc].sort_as = strdup(sorted);
soc_mess_list[curr_soc].hide = hide;
soc_mess_list[curr_soc].min_char_position = min_char_pos;
soc_mess_list[curr_soc].min_victim_position = min_pos;
soc_mess_list[curr_soc].min_level_char = min_lvl;
} else { /* old style */
if (fscanf(fl, " %d %d \n", &hide, &min_pos) != 2) {
log("SYSERR: format error in social file near social '%s'", next_soc);
exit(1);
}
curr_soc++;
soc_mess_list[curr_soc].command = strdup(next_soc);
soc_mess_list[curr_soc].sort_as = strdup(next_soc);
soc_mess_list[curr_soc].hide = hide;
soc_mess_list[curr_soc].min_char_position = POS_RESTING;
soc_mess_list[curr_soc].min_victim_position = min_pos;
soc_mess_list[curr_soc].min_level_char = 0;
}
#ifdef CIRCLE_ACORN
if (fgetc(fl) != '\n')
log("SYSERR: Acorn bug workaround failed.");
/* SYSERR_DESC:
* The only time that this error should ever arise is if you are running
* your CircleMUD on the Acorn platform. The error arises when the
* server cannot properly read a '\n' out of the file at the end of the
* first line of the social (that with 'hide' and 'min position'). This
* is in boot_social_messages().
*/
#endif
soc_mess_list[curr_soc].char_no_arg = fread_action(fl, nr);
soc_mess_list[curr_soc].others_no_arg = fread_action(fl, nr);
soc_mess_list[curr_soc].char_found = fread_action(fl, nr);
/* if no char_found, the rest is to be ignored */
if (CONFIG_NEW_SOCIALS == false && !soc_mess_list[curr_soc].char_found)
continue;
soc_mess_list[curr_soc].others_found = fread_action(fl, nr);
soc_mess_list[curr_soc].vict_found = fread_action(fl, nr);
soc_mess_list[curr_soc].not_found = fread_action(fl, nr);
soc_mess_list[curr_soc].char_auto = fread_action(fl, nr);
soc_mess_list[curr_soc].others_auto = fread_action(fl, nr);
if (CONFIG_NEW_SOCIALS == false)
continue;
soc_mess_list[curr_soc].char_body_found = fread_action(fl, nr);
soc_mess_list[curr_soc].others_body_found = fread_action(fl, nr);
soc_mess_list[curr_soc].vict_body_found = fread_action(fl, nr);
soc_mess_list[curr_soc].char_obj_found = fread_action(fl, nr);
soc_mess_list[curr_soc].others_obj_found = fread_action(fl, nr);
}
/* close file & set top */
fclose(fl);
assert(curr_soc <= top_of_socialt);
top_of_socialt = curr_soc;
}
/* this function adds in the loaded socials and assigns them a command # */
void create_command_list(void)
{
int i, j, k;
struct social_messg temp;
extern struct command_info cmd_info[];
/* free up old command list */
if (complete_cmd_info)
free_command_list();
/* re check the sort on the socials */
for (j = 0; j < top_of_socialt; j++) {
k = j;
for (i = j + 1; i <= top_of_socialt; i++)
if (str_cmp(soc_mess_list[i].sort_as, soc_mess_list[k].sort_as) < 0)
k = i;
if (j != k) {
temp = soc_mess_list[j];
soc_mess_list[j] = soc_mess_list[k];
soc_mess_list[k] = temp;
}
}
/* count the commands in the command list */
i = 0;
while(*cmd_info[i].command != '\n') i++;
i++;
CREATE(complete_cmd_info, struct command_info, top_of_socialt + i + 2);
/* this loop sorts the socials and commands together into one big list */
i = 0;
j = 0;
k = 0;
while (*cmd_info[i].command != '\n') {
complete_cmd_info[k++] = cmd_info[i++];
}
while (j <= top_of_socialt) {
soc_mess_list[j].act_nr = k;
complete_cmd_info[k].command = soc_mess_list[j].command;
complete_cmd_info[k].sort_as = soc_mess_list[j].sort_as;
complete_cmd_info[k].minimum_position = soc_mess_list[j].min_char_position;
complete_cmd_info[k].command_pointer = do_action;
complete_cmd_info[k].minimum_level = soc_mess_list[j++].min_level_char;
complete_cmd_info[k].minimum_admlevel = ADMLVL_NONE;
complete_cmd_info[k++].subcmd = 0;
}
complete_cmd_info[k].command = strdup("\n");
complete_cmd_info[k].sort_as = strdup("zzzzzzz");
complete_cmd_info[k].minimum_position = 0;
complete_cmd_info[k].command_pointer = 0;
complete_cmd_info[k].minimum_level = 0;
complete_cmd_info[k].minimum_admlevel = 0;
complete_cmd_info[k].subcmd = 0;
log("Command info rebuilt, %d total commands.", k);
}
void free_command_list(void)
{
int i;
for (i = 0;*complete_cmd_info[i].command !='\n';i++);
free((char *)complete_cmd_info[i].command); /* special case, the terminator */
free((char *)complete_cmd_info[i].sort_as);
free(complete_cmd_info);
complete_cmd_info = NULL;
}
char *fread_action(FILE *fl, int nr)
{
char buf[MAX_STRING_LENGTH];
char *trash = NULL;
trash = fgets(buf, MAX_STRING_LENGTH, fl);
if (feof(fl)) {
log("SYSERR: fread_action: unexpected EOF near action #%d", nr);
/* SYSERR_DESC:
* fread_action() will fail if it discovers an end of file marker
* before it is able to read in the expected string. This can be
* caused by a truncated socials file.
*/
exit(1);
}
if (*buf == '#')
return (NULL);
buf[strlen(buf) - 1] = '\0';
return (strdup(buf));
}
void free_social_messages(void)
{
struct social_messg *mess;
int i;
for (i = 0;i <= top_of_socialt;i++) {
mess = &soc_mess_list[i];
free_action(mess);
}
free(soc_mess_list);
}
void free_action(struct social_messg *mess) {
if (mess->command) free(mess->command);
if (mess->sort_as) free(mess->sort_as);
if (mess->char_no_arg) free(mess->char_no_arg);
if (mess->others_no_arg) free(mess->others_no_arg);
if (mess->char_found) free(mess->char_found);
if (mess->others_found) free(mess->others_found);
if (mess->vict_found) free(mess->vict_found);
if (mess->char_body_found) free(mess->char_body_found);
if (mess->others_body_found) free(mess->others_body_found);
if (mess->vict_body_found) free(mess->vict_body_found);
if (mess->not_found) free(mess->not_found);
if (mess->char_auto) free(mess->char_auto);
if (mess->others_auto) free(mess->others_auto);
if (mess->char_obj_found) free(mess->char_obj_found);
if (mess->others_obj_found) free(mess->others_obj_found);
memset(mess, 0, sizeof(struct social_messg));
}
int find_action(int cmd)
{
int bot, top, mid;
bot = 0;
top = top_of_socialt;
if (top < 0)
return (-1);
for (;;) {
mid = (bot + top) / 2;
if (soc_mess_list[mid].act_nr == cmd)
return (mid);
if (bot >= top)
return (-1);
if (soc_mess_list[mid].act_nr > cmd)
top = --mid;
else
bot = ++mid;
}
}
ACMD(do_gmote)
{
int act_nr, length;
char arg[MAX_INPUT_LENGTH], buf[MAX_INPUT_LENGTH];
struct social_messg *action;
struct char_data *vict = NULL;
half_chop(argument, buf, arg);
if(subcmd)
for (length = strlen(buf), cmd = 0; *complete_cmd_info[cmd].command != '\n'; cmd++)
if (!strncmp(complete_cmd_info[cmd].command, buf, length))
break;
if ((act_nr = find_action(cmd)) < 0) {
send_to_char(ch, "That's not a social!\r\n");
return;
}
action = &soc_mess_list[act_nr];
if (!action->char_found)
*arg = '\0';
if (!*arg) {
if(!action->others_no_arg || !*action->others_no_arg) {
send_to_char(ch, "Who are you going to do that to?\r\n");
return;
}
snprintf(buf, sizeof(buf), "Gossip: %s", action->others_no_arg);
} else if (!(vict = get_char_vis(ch, arg, NULL, FIND_CHAR_WORLD))) {
send_to_char(ch, "%s\r\n", action->not_found);
return;
} else if (vict == ch) {
if(!action->others_auto || !*action->others_auto) {
send_to_char(ch, "%s\r\n", action->char_auto);
return;
}
snprintf(buf, sizeof(buf), "Gossip: %s", action->others_auto);
} else {
if (GET_POS(vict) < action->min_victim_position) {
act("$N is not in a proper position for that.",
false, ch, 0, vict, TO_CHAR | TO_SLEEP);
return;
}
snprintf(buf, sizeof(buf), "Gossip: %s", action->others_found);
}
act(buf, false, ch, 0, vict, TO_GMOTE);
}