forked from sneezymud/dikumud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomm.c
1201 lines (928 loc) · 23.9 KB
/
comm.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
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ************************************************************************
* file: comm.c , Communication module. Part of DIKUMUD *
* Usage: Communication, central game loop. *
* Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
* All Rights Reserved *
* Using *any* part of DikuMud without having read license.doc is *
* violating our copyright.
************************************************************************* */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <sys/time.h>
#include <fcntl.h>
#include <signal.h>
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#define DFLT_PORT 4000 /* default port */
#define MAX_NAME_LENGTH 15
#define MAX_HOSTNAME 256
#define OPT_USEC 250000 /* time delay corresponding to 4 passes/sec */
extern int errno; /* Why isn't this done in errno.h on alfa??? */
/* externs */
/* extern struct char_data *character_list; */
extern struct room_data *world; /* In db.c */
extern int top_of_world; /* In db.c */
extern struct time_info_data time_info; /* In db.c */
extern char help[];
extern bool wizlock;
/* local globals */
struct descriptor_data *descriptor_list, *next_to_process;
int lawful = 0; /* work like the game regulator */
int slow_death = 0; /* Shut her down, Martha, she's sucking mud */
int clean_shutdown = 0; /* clean shutdown */
int reboot = 0; /* reboot the game after a shutdown */
int no_specials = 0; /* Suppress ass. of special routines */
int maxdesc, avail_descs;
int tics = 0; /* for extern checkpointing */
int get_from_q(struct txt_q *queue, char *dest);
/* write_to_q is in comm.h for the macro */
int run_the_game(int port);
int game_loop(int s);
int init_socket(int port);
int new_connection(int s);
int new_descriptor(int s);
int process_output(struct descriptor_data *t);
int process_input(struct descriptor_data *t);
void close_sockets(int s);
void close_socket(struct descriptor_data *d);
struct timeval timediff(struct timeval *a, struct timeval *b);
void flush_queues(struct descriptor_data *d);
void nonblock(int s);
void parse_name(struct descriptor_data *desc, char *arg);
/* extern fcnts */
struct char_data *make_char(char *name, struct descriptor_data *desc);
void boot_db(void);
void zone_update(void);
void affect_update( void ); /* In spells.c */
void point_update( void ); /* In limits.c */
void free_char(struct char_data *ch);
void log_message(char *str);
void mobile_activity(void);
void string_add(struct descriptor_data *d, char *str);
void perform_violence(void);
void stop_fighting(struct char_data *ch);
void show_string(struct descriptor_data *d, char *input);
void gr(int s);
void check_reboot(void);
/* *********************************************************************
* main game loop and related stuff *
********************************************************************* */
int main(int argc, char **argv)
{
int port;
char buf[512];
int pos = 1;
char *dir;
port = DFLT_PORT;
dir = DFLT_DIR;
while ((pos < argc) && (*(argv[pos]) == '-'))
{
switch (*(argv[pos] + 1))
{
case 'l':
lawful = 1;
log_message("Lawful mode selected.");
break;
case 'd':
if (*(argv[pos] + 2))
dir = argv[pos] + 2;
else if (++pos < argc)
dir = argv[pos];
else
{
log_message("Directory arg expected after option -d.");
exit(0);
}
break;
case 's':
no_specials = 1;
log_message("Suppressing assignment of special routines.");
break;
default:
sprintf(buf, "Unknown option -% in argument string.",
*(argv[pos] + 1));
log_message(buf);
break;
}
pos++;
}
if (pos < argc)
if (!isdigit(*argv[pos]))
{
fprintf(stderr, "Usage: %s [-l] [-s] [-d pathname] [ port # ]\n",
argv[0]);
exit(0);
}
else if ((port = atoi(argv[pos])) <= 1024)
{
printf("Illegal port #\n");
exit(0);
}
sprintf(buf, "Running game on port %d.", port);
log_message(buf);
if (chdir(dir) < 0)
{
perror("chdir");
exit(0);
}
sprintf(buf, "Using %s as data directory.", dir);
log_message(buf);
srandom(time(0));
run_the_game(port);
return(0);
}
#define PROFILE(x)
/* Init sockets, run game, and cleanup sockets */
int run_the_game(int port)
{
int s;
PROFILE(extern etext();)
void signal_setup(void);
int load(void);
void coma_0(void);
PROFILE(monstartup((int) 2, etext);)
descriptor_list = NULL;
log_message("Signal trapping.");
signal_setup();
log_message("Opening mother connection.");
s = init_socket(port);
if (lawful && load() >= 6)
{
log_message("System load too high at startup.");
coma_0();
}
boot_db();
log_message("Entering game loop.");
game_loop(s);
close_sockets(s);
PROFILE(monitor(0);)
if (reboot)
{
log_message("Rebooting.");
exit(52); /* what's so great about HHGTTG, anyhow? */
}
log_message("Normal termination of game.");
}
/* Accept new connects, relay commands, and call 'heartbeat-functs' */
int game_loop(int s)
{
int tmp_room, old_len;
fd_set input_set, output_set, exc_set;
struct timeval last_time, now, timespent, timeout, null_time;
static struct timeval opt_time;
char comm[MAX_INPUT_LENGTH];
struct descriptor_data *t, *point, *next_point;
int pulse = 0, mask;
null_time.tv_sec = 0;
null_time.tv_usec = 0;
opt_time.tv_usec = OPT_USEC; /* Init time values */
opt_time.tv_sec = 0;
gettimeofday(&last_time, NULL);
maxdesc = s;
avail_descs = getdtablesize() - 2; /* !! Change if more needed !! */
mask = sigmask(SIGUSR1) | sigmask(SIGUSR2) | sigmask(SIGINT) |
sigmask(SIGPIPE) | sigmask(SIGALRM) | sigmask(SIGTERM) |
sigmask(SIGURG) | sigmask(SIGXCPU) | sigmask(SIGHUP) |
sigmask(SIGVTALRM);
/* Main loop */
while (!clean_shutdown)
{
/* Check what's happening out there */
FD_ZERO(&input_set);
FD_ZERO(&output_set);
FD_ZERO(&exc_set);
FD_SET(s, &input_set);
for (point = descriptor_list; point; point = point->next)
{
FD_SET(point->descriptor, &input_set);
FD_SET(point->descriptor, &exc_set);
FD_SET(point->descriptor, &output_set);
}
/* check out the time */
gettimeofday(&now, NULL);
timespent = timediff(&now, &last_time);
timeout = timediff(&opt_time, ×pent);
last_time.tv_sec = now.tv_sec + timeout.tv_sec;
last_time.tv_usec = now.tv_usec + timeout.tv_usec;
if (last_time.tv_usec >= 1000000)
{
last_time.tv_usec -= 1000000;
last_time.tv_sec++;
}
sigsetmask(mask);
if (select(maxdesc + 1, &input_set, &output_set, &exc_set, &null_time)
< 0)
{
perror("Select poll");
return(-1);
}
if (select(0, (fd_set *) 0, (fd_set *) 0, (fd_set *) 0, &timeout) < 0)
{
perror("Select sleep");
exit(1);
}
sigsetmask(0);
/* Respond to whatever might be happening */
/* New connection? */
if (FD_ISSET(s, &input_set))
if (new_descriptor(s) < 0)
perror("New connection");
/* kick out the freaky folks */
for (point = descriptor_list; point; point = next_point)
{
next_point = point->next;
if (FD_ISSET(point->descriptor, &exc_set))
{
FD_CLR(point->descriptor, &input_set);
FD_CLR(point->descriptor, &output_set);
close_socket(point);
}
}
for (point = descriptor_list; point; point = next_point)
{
next_point = point->next;
if (FD_ISSET(point->descriptor, &input_set))
if (process_input(point) < 0)
close_socket(point);
}
/* process_commands; */
for (point = descriptor_list; point; point = next_to_process)
{
next_to_process = point->next;
if ((--(point->wait) <= 0) && get_from_q(&point->input, comm))
{
if (point->character && point->connected == CON_PLYNG &&
point->character->specials.was_in_room != NOWHERE)
{
if (point->character->in_room != NOWHERE)
char_from_room(point->character);
char_to_room(point->character,
point->character->specials.was_in_room);
point->character->specials.was_in_room = NOWHERE;
act("$n has returned.", TRUE, point->character, 0, 0, TO_ROOM);
affect_total(point->character);
}
point->wait = 1;
if (point->character)
point->character->specials.timer = 0;
point->prompt_mode = 1;
if (point->str)
string_add(point, comm);
else if (!point->connected)
if (point->showstr_point)
show_string(point, comm);
else
command_interpreter(point->character, comm);
else
nanny(point, comm);
}
}
for (point = descriptor_list; point; point = next_point)
{
next_point = point->next;
if (FD_ISSET(point->descriptor, &output_set) && point->output.head)
if (process_output(point) < 0)
close_socket(point);
else
point->prompt_mode = 1;
}
/* give the people some prompts */
for (point = descriptor_list; point; point = point->next)
if (point->prompt_mode)
{
if (point->str)
write_to_descriptor(point->descriptor, "] ");
else if (!point->connected)
if (point->showstr_point)
write_to_descriptor(point->descriptor,
"*** Press return ***");
else
write_to_descriptor(point->descriptor, "> ");
point->prompt_mode = 0;
}
/* handle heartbeat stuff */
/* Note: pulse now changes every 1/4 sec */
pulse++;
if (!(pulse % PULSE_ZONE))
{
zone_update();
if (lawful)
gr(s);
}
if (!(pulse % PULSE_MOBILE))
mobile_activity();
if (!(pulse % PULSE_VIOLENCE))
perform_violence();
if (!(pulse % (SECS_PER_MUD_HOUR*4))){
weather_and_time(1);
affect_update();
point_update();
if ( time_info.hours == 1 )
update_time();
}
if (pulse >= 2400) {
pulse = 0;
if (lawful)
night_watchman();
check_reboot();
}
tics++; /* tics since last checkpoint signal */
}
}
/* ******************************************************************
* general utility stuff (for local use) *
****************************************************************** */
int get_from_q(struct txt_q *queue, char *dest)
{
struct txt_block *tmp;
/* Q empty? */
if (!queue->head)
return(0);
tmp = queue->head;
strcpy(dest, queue->head->text);
queue->head = queue->head->next;
free(tmp->text);
free(tmp);
return(1);
}
void write_to_q(char *txt, struct txt_q *queue)
{
struct txt_block *new;
CREATE(new, struct txt_block, 1);
CREATE(new->text, char, strlen(txt) + 1);
strcpy(new->text, txt);
/* Q empty? */
if (!queue->head)
{
new->next = NULL;
queue->head = queue->tail = new;
}
else
{
queue->tail->next = new;
queue->tail = new;
new->next = NULL;
}
}
struct timeval timediff(struct timeval *a, struct timeval *b)
{
struct timeval rslt, tmp;
tmp = *a;
if ((rslt.tv_usec = tmp.tv_usec - b->tv_usec) < 0)
{
rslt.tv_usec += 1000000;
--(tmp.tv_sec);
}
if ((rslt.tv_sec = tmp.tv_sec - b->tv_sec) < 0)
{
rslt.tv_usec = 0;
rslt.tv_sec =0;
}
return(rslt);
}
/* Empty the queues before closing connection */
void flush_queues(struct descriptor_data *d)
{
char dummy[MAX_STRING_LENGTH];
while (get_from_q(&d->output, dummy));
while (get_from_q(&d->input, dummy));
}
/* ******************************************************************
* socket handling *
****************************************************************** */
int init_socket(int port)
{
int s;
char *opt;
char hostname[MAX_HOSTNAME+1];
struct sockaddr_in sa;
struct hostent *hp;
struct linger ld;
bzero(&sa, sizeof(struct sockaddr_in));
gethostname(hostname, MAX_HOSTNAME);
hp = gethostbyname(hostname);
if (hp == NULL)
{
perror("gethostbyname");
exit(1);
}
sa.sin_family = hp->h_addrtype;
sa.sin_port = htons(port);
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0)
{
perror("Init-socket");
exit(1);
}
if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR,
(char *) &opt, sizeof (opt)) < 0)
{
perror ("setsockopt REUSEADDR");
exit (1);
}
ld.l_onoff = 1;
ld.l_linger = 1000;
if (setsockopt(s, SOL_SOCKET, SO_LINGER, &ld, sizeof(ld)) < 0)
{
perror("setsockopt LINGER");
exit(1);
}
if (bind(s, &sa, sizeof(sa)) < 0)
{
perror("bind");
close(s);
exit(1);
}
listen(s, 3);
return(s);
}
int new_connection(int s)
{
struct sockaddr_in isa;
/* struct sockaddr peer; */
int i;
int t;
char buf[100];
i = sizeof(isa);
getsockname(s, &isa, &i);
if ((t = accept(s, &isa, &i)) < 0)
{
perror("Accept");
return(-1);
}
nonblock(t);
/*
i = sizeof(peer);
if (!getpeername(t, &peer, &i))
{
*(peer.sa_data + 49) = '\0';
sprintf(buf, "New connection from addr %s.\n", peer.sa_data);
log_message(buf);
}
*/
return(t);
}
int new_descriptor(int s)
{
int desc;
struct descriptor_data *newd;
int size;
struct sockaddr_in sock;
struct hostent *from;
char buf[10];
if ((desc = new_connection(s)) < 0)
return (-1);
if (wizlock)
{
write_to_descriptor(desc, "The game is wizlocked...");
close(desc);
return(0);
}
if ((desc + 1) >= avail_descs)
{
write_to_descriptor(desc, "Sorry.. The game is full...\n\r");
close(desc);
return(0);
}
else
if (desc > maxdesc)
maxdesc = desc;
CREATE(newd, struct descriptor_data, 1);
/* find info */
size = sizeof(sock);
if (getpeername(desc, (struct sockaddr *) &sock, &size) < 0)
{
perror("getpeername");
*newd->host = '\0';
}
else if (!(from = gethostbyaddr((char*)&sock.sin_addr,
sizeof(sock.sin_addr), AF_INET)))
{
strcpy(newd->host, inet_ntoa(sock.sin_addr));
}
else
{
strncpy(newd->host, from->h_name, 49);
*(newd->host + 49) = '\0';
}
/* init desc data */
newd->descriptor = desc;
newd->connected = 1;
newd->wait = 1;
newd->prompt_mode = 0;
*newd->buf = '\0';
newd->str = 0;
newd->showstr_head = 0;
newd->showstr_point = 0;
*newd->last_input= '\0';
newd->output.head = NULL;
newd->input.head = NULL;
newd->next = descriptor_list;
newd->character = 0;
newd->original = 0;
newd->snoop.snooping = 0;
newd->snoop.snoop_by = 0;
/* prepend to list */
descriptor_list = newd;
SEND_TO_Q(GREETINGS, newd);
SEND_TO_Q("By what name do you wish to be known? ", newd);
return(0);
}
int process_output(struct descriptor_data *t)
{
char i[MAX_STRING_LENGTH + 1];
if (!t->prompt_mode && !t->connected)
if (write_to_descriptor(t->descriptor, "\n\r") < 0)
return(-1);
/* Cycle thru output queue */
while (get_from_q(&t->output, i))
{
if(t->snoop.snoop_by)
{
write_to_q("% ",&t->snoop.snoop_by->desc->output);
write_to_q(i,&t->snoop.snoop_by->desc->output);
}
if (write_to_descriptor(t->descriptor, i))
return(-1);
}
if (!t->connected && !(t->character && !IS_NPC(t->character) &&
IS_SET(t->character->specials.act, PLR_COMPACT)))
if (write_to_descriptor(t->descriptor, "\n\r") < 0)
return(-1);
return(1);
}
int write_to_descriptor(int desc, char *txt)
{
int sofar, thisround, total;
total = strlen(txt);
sofar = 0;
do
{
thisround = write(desc, txt + sofar, total - sofar);
if (thisround < 0)
{
perror("Write to socket");
return(-1);
}
sofar += thisround;
}
while (sofar < total);
return(0);
}
int process_input(struct descriptor_data *t)
{
int sofar, thisround, begin, squelch, i, k, flag;
char tmp[MAX_INPUT_LENGTH+2], buffer[MAX_INPUT_LENGTH + 60];
sofar = 0;
flag = 0;
begin = strlen(t->buf);
/* Read in some stuff */
do
{
if ((thisround = read(t->descriptor, t->buf + begin + sofar,
MAX_STRING_LENGTH - (begin + sofar) - 1)) > 0)
sofar += thisround;
else
if (thisround < 0)
if(errno != EWOULDBLOCK)
{
perror("Read1 - ERROR");
return(-1);
}
else
break;
else
{
log_message("EOF encountered on socket read.");
return(-1);
}
}
while (!ISNEWL(*(t->buf + begin + sofar - 1)));
*(t->buf + begin + sofar) = 0;
/* if no newline is contained in input, return without proc'ing */
for (i = begin; !ISNEWL(*(t->buf + i)); i++)
if (!*(t->buf + i))
return(0);
/* input contains 1 or more newlines; process the stuff */
for (i = 0, k = 0; *(t->buf + i);)
{
if (!ISNEWL(*(t->buf + i)) && !(flag = (k >= (MAX_INPUT_LENGTH - 2))))
if(*(t->buf + i) == '\b') /* backspace */
if (k) /* more than one char ? */
{
if (*(tmp + --k) == '$')
k--;
i++;
}
else
i++; /* no or just one char.. Skip backsp */
else
if (isascii(*(t->buf + i)) && isprint(*(t->buf + i)))
{
/* trans char, double for '$' (printf) */
if ((*(tmp + k) = *(t->buf + i)) == '$')
*(tmp + ++k) = '$';
k++;
i++;
}
else
i++;
else
{
*(tmp + k) = 0;
if(*tmp == '!')
strcpy(tmp,t->last_input);
else
strcpy(t->last_input,tmp);
write_to_q(tmp, &t->input);
if(t->snoop.snoop_by)
{
write_to_q("% ",&t->snoop.snoop_by->desc->output);
write_to_q(tmp,&t->snoop.snoop_by->desc->output);
write_to_q("\n\r",&t->snoop.snoop_by->desc->output);
}
if (flag)
{
sprintf(buffer,
"Line too long. Truncated to:\n\r%s\n\r", tmp);
if (write_to_descriptor(t->descriptor, buffer) < 0)
return(-1);
/* skip the rest of the line */
for (; !ISNEWL(*(t->buf + i)); i++);
}
/* find end of entry */
for (; ISNEWL(*(t->buf + i)); i++);
/* squelch the entry from the buffer */
for (squelch = 0;; squelch++)
if ((*(t->buf + squelch) =
*(t->buf + i + squelch)) == '\0')
break;
k = 0;
i = 0;
}
}
return(1);
}
void close_sockets(int s)
{
log_message("Closing all sockets.");
while (descriptor_list)
close_socket(descriptor_list);
close(s);
}
void close_socket(struct descriptor_data *d)
{
struct affected_type *af;
struct descriptor_data *tmp;
char buf[100];
close(d->descriptor);
flush_queues(d);
if (d->descriptor == maxdesc)
--maxdesc;
/* Forget snooping */
if (d->snoop.snooping)
d->snoop.snooping->desc->snoop.snoop_by = 0;
if (d->snoop.snoop_by)
{
send_to_char("Your victim is no longer among us.\n\r",d->snoop.snoop_by);
d->snoop.snoop_by->desc->snoop.snooping = 0;
}
if (d->character)
if (d->connected == CON_PLYNG)
{
save_char(d->character, NOWHERE);
act("$n has lost $s link.", TRUE, d->character, 0, 0, TO_ROOM);
sprintf(buf, "Closing link to: %s.", GET_NAME(d->character));
log_message(buf);
d->character->desc = 0;
}
else
{
sprintf(buf, "Losing player: %s.", GET_NAME(d->character));
log_message(buf);
free_char(d->character);
}
else
log_message("Losing descriptor without char.");
if (next_to_process == d) /* to avoid crashing the process loop */
next_to_process = next_to_process->next;
if (d == descriptor_list) /* this is the head of the list */
descriptor_list = descriptor_list->next;
else /* This is somewhere inside the list */
{
/* Locate the previous element */
for (tmp = descriptor_list; (tmp->next != d) && tmp;
tmp = tmp->next);
tmp->next = d->next;
}
if (d->showstr_head)
free(d->showstr_head);
free(d);
}
void nonblock(int s)
{
if (fcntl(s, F_SETFL, FNDELAY) == -1)
{
perror("Noblock");
exit(1);
}
}
#define COMA_SIGN \
"\n\r\
DikuMUD is currently inactive due to excessive load on the host machine.\n\r\
Please try again later.\n\r\
\n\r\
Sadly,\n\r\
\n\r\
the DikuMUD system operators\n\r\n\r"
/* sleep while the load is too high */
void coma_1(int s)
{
fd_set input_set;
static struct timeval timeout =
{
60,
0
};
int conn;
int workhours(void);
int load(void);
log_message("Entering comatose state.");
sigsetmask(sigmask(SIGUSR1) | sigmask(SIGUSR2) | sigmask(SIGINT) |
sigmask(SIGPIPE) | sigmask(SIGALRM) | sigmask(SIGTERM) |
sigmask(SIGURG) | sigmask(SIGXCPU) | sigmask(SIGHUP) |
sigmask(SIGVTALRM));
while (descriptor_list)