-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcb.c
2490 lines (2162 loc) · 61.4 KB
/
cb.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
/*
cbd.c
"cbd.c" is the main code for the CB simulator.
Copyright (c) 1992, Gary Grossman. All rights reserved.
Send comments and questions to: [email protected]
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/signal.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <arpa/telnet.h>
#include <unistd.h>
void add_recent ();
/* The default port the server is running on */
#define DEF_PORT 5492
/* Maximum screen width */
#define MAXWIDTH 132
/* Lengths of strings used in the program */
#define MAXINPUT 256 /* Maximum length of any input */
#define MAXID 15 /* Maximum length of a user ID */
#define MAXHANDLE 33 /* Maximum length of a handle */
#define MAXMSG 256 /* Maximum length of a message */
#define MAXFMT 64 /* Maximum length of a format string */
#define MAXHOST 64 /* Maximum length of a hostname */
#define MAXPW 8 /* Maximum length of a password */
/* Size of output and stopped outut buffers */
#define MAXSTOPQ 4096
#define MAXOUTQ 2048
/* Version string */
#define CB_VERSION "Unix-CB 1.0 Beta 11/11/92 Revision 01"
/* Telnet control sequence processing */
#define TS_NONE 0
#define TS_IAC 1
#define TS_WILL 2
#define TS_WONT 3
#define TS_DO 4
#define TS_DONT 5
/* Character-oriented queue for output buffers.
When it overflows, it "eats" the old data line by line. */
struct queue {
char *qbase,
*qread,
*qwrite;
int qoverflow,
qsize;
};
/* Structure for user accounts. */
struct account {
char id[MAXID],
handle[MAXHANDLE],
pw[MAXPW];
int chan,
width,
level;
char nlchar;
unsigned listed: 1,
nostat: 1,
newlines: 1,
mon: 1;
char activefmt[MAXFMT],
msgfmt[MAXFMT];
};
/* Definition of slot data structure. Each connection gets a slot. */
struct slot {
void (*readfunc) ();
int tsmode;
struct account acct;
long acct_pos;
time_t login_time;
fd_set squelch, reverse;
int inmax;
char wrap_base[MAXWIDTH + 1],
*wrap_ptr;
struct queue outq,
stopq;
char in[MAXINPUT],
*inp;
char pmail[MAXID];
void (*dispid) ();
void (*cleanup) ();
char *temp;
char hostname[MAXHOST];
time_t last_typed;
unsigned on: 1, /* Set if user is logged in and active */
wrap: 1, /* Set if word wrap is on */
lurk: 1, /* Set if user is "lurking" */
stopped: 1, /* Set if incoming input is stopped */
spy: 1, /* Set if user can spy */
gotcr: 1, /* Set if CR was received */
echo: 1, /* Set if input echos back to user */
wstop: 1; /* Set if writing to stop queue */
};
/* slotbase is a pointer to the slot array, numslots is the number
of elements in it. slot is the currently executing slot. */
struct slot *slotbase,
*slot;
int numslots;
/* inet_port is the IP port the program is running on */
int inet_port = DEF_PORT;
/* startup is the system time at program start up */
time_t startup;
/* login_count is the number of users that have logged in since startup */
int login_count = 0;
/* used indicates which file descriptor (slots) are used */
fd_set used;
/* sock is the file descriptor for the socket */
int sock;
/* squelched: returns nonzero if sp is squelching sq */
int squelched (sp, sq)
struct slot *sp,
*sq;
{
return FD_ISSET (sq - slotbase, &sp -> squelch);
}
/* reversed: returns nonzero if sp is reverse squelching sq */
int reversed (sp, sq)
struct slot *sp,
*sq;
{
return FD_ISSET (sq - slotbase, &sp -> reverse);
}
/* xatoi: converts an ASCII string to an integer, returns -1 on error */
int xatoi (s)
char *s;
{
register int i = 0;
while (*s)
if (isdigit (*s))
i = 10 * i + *s++ - '0';
else
return (-1);
return i;
}
/* slotname returns a pointer to the slot with user "id" in it, or
NULL if none exists. If a user is lurking he will not show up. */
struct slot *slotname (id)
char *id;
{
struct slot *sp;
int i;
if (!id[0])
return NULL;
if ((i = xatoi (id)) != -1) {
if (i < 0 || i >= numslots)
return NULL;
sp = slotbase + i;
if (sp -> on)
return (sp -> lurk && !slot -> spy) ? NULL : sp;
else
return NULL;
}
for (sp = slotbase; sp < slotbase + numslots; sp++)
if (sp -> on && !strcmp (sp -> acct.id, id))
return (sp -> lurk && !slot -> spy) ? NULL : sp;
return NULL;
}
/* read_user: reads account with user-id "id" into "acct" */
long read_user (id, acct)
char *id;
struct account *acct;
{
FILE * fp;
long pos;
if ((fp = fopen ("cb.accounts", "rb")) == NULL)
return - 1;
pos = 0;
while (fread (acct, sizeof (struct account), 1, fp)) {
if (!strcmp (id, acct -> id)) {
fclose (fp);
return pos;
}
pos += sizeof (struct account);
}
fclose (fp);
return - 1;
}
/* delete_user: deletes user with user-id "id" */
int delete_user (id)
char *id;
{
FILE * fp;
struct slot *sp;
long pos,
newlen;
struct account acct;
if ((pos = read_user (id, &acct)) < 0)
return 0;
if ((fp = fopen ("cb.accounts", "r+b")) == NULL)
return 0;
fseek (fp, -(long) sizeof (struct account) , 2);
if ((newlen = ftell (fp)) != pos) {
fread (&acct, sizeof acct, 1, fp);
if ((sp = slotname (acct.id)) != NULL)
sp -> acct_pos = pos;
fseek (fp, pos, 0);
fwrite (&acct, sizeof acct, 1, fp);
}
ftruncate (fileno (fp), newlen);
fclose (fp);
return 1;
}
/* create_user: appends "acct" to the account file and returns offset */
long create_user (acct)
struct account *acct;
{
FILE * fp;
long pos;
if ((fp = fopen ("cb.accounts", "ab")) == NULL)
return - 1;
fseek (fp, 0L, 2);
pos = ftell (fp);
fwrite (acct, sizeof (struct account) , 1, fp);
fclose (fp);
return pos;
}
/* write_user: writes account "acct" at account file offset "pos" */
int write_user (pos, acct)
long pos;
struct account *acct;
{
FILE * fp;
if ((fp = fopen ("cb.accounts", "r+b")) == NULL)
if ((fp = fopen ("cb.accounts", "wb")) == NULL)
return 0;
fseek (fp, pos, 0);
fwrite (acct, sizeof (struct account) , 1, fp);
fclose (fp);
return 1;
}
/* qnext: return the incremented value of queue pointer "s" */
char *qnext (q, s)
struct queue *q;
char *s;
{
return (s == q -> qbase + q -> qsize - 1) ? q -> qbase : s + 1;
}
/* qprev: return the decremented value of queue pointer "s" */
char *qprev (q, s)
struct queue *q;
char *s;
{
return (s == q -> qbase) ? q -> qbase + q -> qsize - 1 : s - 1;
}
/* qnextline: return the line-incremented value of queue pointer */
char *qnextline (q, s)
struct queue *q;
char *s;
{
char ch;
for (;;) {
ch = *s;
s = qnext (q, s);
if (ch == '\n')
return s;
}
}
/* qinsert inserts a character into a queue */
void qinsert (q, ch)
struct queue *q;
char ch;
{
*q -> qwrite = ch;
q -> qwrite = qnext (q, q -> qwrite);
if (q -> qwrite == q -> qread) {
q -> qoverflow = 1;
q -> qread = qnextline (q, q -> qread);
}
}
/* qempty returns nonzero if a queue is empty, or zero otherwise. */
int qempty (q)
struct queue *q;
{
return q -> qread == q -> qwrite;
}
/* qflush returns nonzero if a queue is empty, or zero otherwise. */
void qflush (q)
struct queue *q;
{
q -> qread = q -> qwrite = q -> qbase;
}
/* qdispose disposes of a queue. */
void qdispose (q)
struct queue *q;
{
if (q -> qbase != NULL)
free (q -> qbase);
}
/* qcreate creates a queue. */
int qcreate (q, size)
struct queue *q;
{
if ((q -> qbase = malloc (size)) == NULL)
return 0;
q -> qsize = size;
q -> qoverflow = 0;
q -> qread = q -> qwrite = q -> qbase;
return 1;
}
/* qwrite transmits data in queue q to slot sp. */
void qwrite (sp, q)
struct slot *sp;
struct queue *q;
{
struct iovec iov[2];
if (!qempty (q)) {
if (q -> qread < q -> qwrite)
q -> qread += write (sp - slotbase, q -> qread,
q -> qwrite - q -> qread);
else {
iov[0].iov_base = q -> qread;
iov[0].iov_len = q -> qsize - (q -> qread - q -> qbase);
iov[1].iov_base = q -> qbase;
iov[1].iov_len = q -> qwrite - q -> qbase;
q -> qread += writev (sp - slotbase, iov, 2);
if (q -> qread >= q -> qbase + q -> qsize)
q -> qread -= q -> qsize;
}
}
}
/* qlength returns the current length of a queue */
int qlength (q)
struct queue *q;
{
if (q -> qread > q -> qwrite)
return (q -> qwrite - q -> qbase) + q -> qsize - (q -> qread - q -> qbase);
else
return (q -> qwrite - q -> qread);
}
/* insert inserts a character into sp's output queue if output is not
stopped, or the stop queue if sp's output is stopped. */
void insert (sp, ch)
struct slot *sp;
char ch;
{
if (ch == '\n')
insert (sp, '\r');
qinsert (sp -> wstop ? &sp -> stopq : &sp -> outq, ch);
if (qlength (&sp -> outq) > sp -> outq.qsize * 3 / 4)
qwrite (sp, &sp -> outq);
}
/*
Function: setread(func, max)
Purpose: Sets the "read" function for the current slot to "func".
The largest line it will receive will be "max" chars long.
*/
void setread (func, max)
void (*func) ();
{
slot -> readfunc = func;
slot -> inmax = max;
}
/* select_stop selects the stop queue for writing ONLY IF IT IS NECESSARY */
void select_stop (sp)
struct slot *sp;
{
if (sp -> stopped)
sp -> wstop = 1;
}
/* clear_stop deselects the stop queue for writing, resuming normal output */
void clear_stop (sp)
struct slot *sp;
{
sp -> wstop = 0;
}
/* select_wrap selects word wrap */
void select_wrap (sp)
struct slot *sp;
{
sp -> wrap = 1;
}
/* clear_wrap deselects word wrap */
void clear_wrap (sp)
struct slot *sp;
{
sp -> wrap = 0;
}
/* insert_buf is used by wrap_writech to write chunks into the output queue */
void insert_buf (sp, buf, n)
struct slot *sp;
char *buf;
int n;
{
while (--n >= 0)
insert (sp, *buf++);
}
/* wrap_writech is similar to writech but supports word wrap */
void wrap_writech (sp, ch)
struct slot *sp;
char ch;
{
char *space,
buf[MAXWIDTH + 1];
if (ch == '\n') {
insert_buf (sp, sp -> wrap_base, sp -> wrap_ptr - sp -> wrap_base);
insert (sp, '\n');
sp -> wrap_ptr = sp -> wrap_base;
}
else
if (isprint (ch)) {
*sp -> wrap_ptr++ = ch;
if (sp -> wrap_ptr - sp -> wrap_base == sp -> acct.width - 1) {
for (space = sp -> wrap_ptr; space != sp -> wrap_base; space--)
if (isspace (*space)) {
insert_buf (sp, sp -> wrap_base,
space - sp -> wrap_base);
insert (sp, '\n');
*sp -> wrap_ptr = '\0';
strcpy (buf, space + 1);
strcpy (sp -> wrap_base, " ");
strcat (sp -> wrap_base, buf);
sp -> wrap_ptr = sp -> wrap_base +
strlen (sp -> wrap_base);
return;
}
insert_buf (sp, sp -> wrap_base,
sp -> wrap_ptr - sp -> wrap_base);
insert (sp, '\n');
sp -> wrap_ptr = sp -> wrap_base;
}
}
}
/* writech writes a character to slot sp */
void writech (sp, ch)
struct slot *sp;
char ch;
{
if (sp -> wrap)
wrap_writech (sp, ch);
else
insert (sp, ch);
}
/* writestr writes a string to slot sp */
void writestr (sp, s)
struct slot *sp;
char *s;
{
while (*s)
writech (sp, *s++);
}
/* writeerr writes an error message before disconnection */
void writeerr (sp, s)
struct slot *sp;
char *s;
{
write (sp - slotbase, s, strlen (s));
}
/* writeint writes an integer value to slot sp */
void writeint (sp, i)
struct slot *sp;
int i;
{
if (i >= 10)
writeint (sp, i / 10);
writech (sp, i % 10 + '0');
}
/* writetwodig writes a two-digit value to slot sp */
void writetwodig (sp, i)
struct slot *sp;
{
if (i >= 100)
writeint (sp, i);
else {
writech (sp, i / 10 + '0');
writech (sp, i % 10 + '0');
}
}
void startqueue (sp)
struct slot *sp;
{
sp -> stopped = 1;
}
/* clearqueue clears the queue flag and dumps what's in the queue
in the user's lap, so to speak. */
void clearqueue (sp)
struct slot *sp;
{
sp -> stopped = 0;
}
void sendpub ();
/* alloctemp allocates temporary space, or prints an error message if
it cannot be allocated. */
int alloctemp (sp, size)
struct slot *sp;
{
if ((sp -> temp = malloc (size)) == NULL) {
writestr (sp, "Insufficient memory.\n");
return 0;
}
return 1;
}
/* freetemp frees a slot's temporary space (must exist!) */
void freetemp (sp)
struct slot *sp;
{
free (sp -> temp);
sp -> temp = NULL;
}
/* collapse closes a slot. It disposes of its queue memory, takes it off the
active list, closes its socket, gets rid of any squelch and reverse flags
that apply to it, and whatever other cleanup I have to add in the future.
It can be called to get rid of a person, or after a person is already
gone. */
void collapse (sp)
struct slot *sp;
{
struct slot *sq;
qdispose (&sp -> outq);
qdispose (&sp -> stopq);
if (sp -> on) {
add_recent (sp);
sp -> on = 0;
for (sq = slotbase; sq < slotbase + numslots; sq++) {
FD_CLR (sp - slotbase, &sq -> squelch);
FD_CLR (sp - slotbase, &sq -> reverse);
}
if (sp -> acct_pos != -1)
write_user (sp -> acct_pos, &sp -> acct);
}
if (sp -> cleanup != NULL)
sp -> cleanup ();
if (sp -> temp != NULL)
freetemp (slot);
FD_CLR (sp - slotbase, &used);
close (sp - slotbase);
}
void transmit (sp)
struct slot *sp;
{
if (!qempty (&sp -> outq))
qwrite (sp, &sp -> outq);
if (qempty (&sp -> outq) && !qempty (&sp -> stopq) && !sp -> stopped)
qwrite (sp, &sp -> stopq);
}
void readid2 (id)
char *id;
{
struct slot *sp;
if (!id[0]) {
setread (sendpub, MAXMSG);
return;
}
if ((sp = slotname (id)) == NULL) {
writestr (slot, "User not logged in.\n");
setread (sendpub, MAXMSG);
return;
}
slot -> dispid (sp);
}
void readid (dispatch)
void (*dispatch) ();
{
slot -> dispid = dispatch;
setread (readid2, MAXID);
}
char levels[] = "#$%@";
#define MAXNL 20
int shared_spec (con, about, ch)
struct slot *con,
*about;
char ch;
{
static char lc1[] = "([{<";
static char lc2[] = ")]}>";
switch (ch) {
case '%':
writech (con, '%');
break;
case 's':
writetwodig (con, about - slotbase);
break;
case 'S':
writeint (con, about - slotbase);
break;
case 'c':
if (about -> acct.chan == con -> acct.chan || con -> spy ||
about -> acct.listed || about -> acct.chan == 1)
writetwodig (con, about -> acct.chan);
else
writestr (con, "**");
break;
case 'C':
if (about -> acct.chan == con -> acct.chan || con -> spy ||
about -> acct.listed || about -> acct.chan == 1)
writeint (con, about -> acct.chan);
else
writech (con, '*');
break;
case '<':
writech (con, lc1[about -> acct.level]);
break;
case '>':
writech (con, lc2[about -> acct.level]);
break;
case 'u':
writestr (con, about -> acct.id);
break;
case 'h':
writestr (con, about -> acct.handle);
break;
case '$':
writech (con, levels[about -> acct.level]);
break;
case '@':
writestr (con, about -> hostname);
break;
default:
return 0;
}
return 1;
}
void writemsg (sp, msg, typ)
struct slot *sp;
char *msg;
int typ;
{
int nlcount;
char *s,
*t;
select_stop (sp);
select_wrap (sp);
s = sp -> acct.msgfmt;
while (*s) {
if (*s == '%')
switch (*++s) {
case '\\':
writech (sp, '\\');
break;
case '_':
writech (sp, '_');
break;
case 'm':
nlcount = 0;
while (*msg) {
if (*msg == slot -> acct.nlchar &&
sp -> acct.newlines && nlcount < MAXNL) {
writestr (sp, "\n ");
nlcount++;
}
else
writech (sp, *msg);
msg++;
}
break;
default:
if (shared_spec (sp, slot, *s))
break;
writech (sp, '%');
if (!*s)
s--;
else
writech (slot, *s);
}
else
if (*s == '_') {
t = index (++s, '_');
if (typ == 2) {
if (t != NULL)
*t = '\0';
writestr (sp, s);
if (t != NULL)
*t = '_';
}
if (t == NULL)
break;
else
s = t;
}
else
if (*s == '\\') {
t = index (++s, '\\');
if (typ == 1) {
if (t != NULL)
*t = '\0';
writestr (sp, s);
if (t != NULL)
*t = '\\';
}
if (t == NULL)
break;
else
s = t;
}
else
writech (sp, *s);
s++;
}
writech (sp, '\n');
clear_stop (sp);
clear_wrap (sp);
}
/* Routines for the last users list */
#define MAX_RECENT 20
int recent_head = 0,
recent_tail = 0;
struct {
char id[MAXID];
time_t login_time, logout_time;
} recent_users[MAX_RECENT];
void add_recent (sp)
struct slot *sp;
{
strcpy (recent_users[recent_tail].id, sp -> acct.id);
recent_users[recent_tail].login_time = sp -> login_time;
time (&recent_users[recent_tail].logout_time);
if (++recent_tail == MAX_RECENT)
recent_tail = 0;
if (recent_tail == recent_head)
if (++recent_head == MAX_RECENT)
recent_head = 0;
}
void list_recent () {
int i;
char *s;
if ((i = recent_head) == recent_tail)
writestr (slot, "Nobody has been online\n");
else
while (i != recent_tail) {
s = ctime (&recent_users[i].login_time);
s[24] = '\0';
writestr (slot, s);
writestr (slot, " to ");
s = ctime (&recent_users[i].logout_time);
s[24] = '\0';
writestr (slot, s);
writestr (slot, " ");
writestr (slot, recent_users[i].id);
writech (slot, '\n');
if (++i == MAX_RECENT)
i = 0;
}
}
/* These are the implementations for the various commands. */
void active () {
struct slot *sp;
char *s;
int first = 1;
for (sp = slotbase; sp < slotbase + numslots; sp++)
if (sp -> on) {
if (sp -> lurk && !slot -> spy)
continue;
s = slot -> acct.activefmt;
while (*s) {
if (*s == '%')
switch (*++s) {
case 't':
if (sp != slot && sp -> stopped)
writestr (slot, " (typing)");
if (slot -> acct.level >= 2) {
if (sp -> lurk)
writestr (slot, " {lurk}");
if (sp -> spy)
writestr (slot, " <spy>");
}
break;
default:
if (shared_spec (slot, sp, *s))
break;
writech (slot, '%');
if (!*s)
s--;
else
writech (slot, *s);
}
else
writech (slot, *s);
s++;
}
writech (slot, '\n');
first = 0;
}
if (first)
writestr (slot, "Nobody currently online\n");
}
void typing () {
struct slot *sp;
int first = 1;
for (sp = slotbase; sp < slotbase + numslots; sp++)
if (sp != slot && sp -> on && sp -> stopped) {
if (sp -> lurk && !slot -> spy)
continue;
if (first) {
first = 0;
writestr (slot, "Users currently typing:\n");
}
writestr (slot, " ");
writestr (slot, sp -> acct.id);
writech (slot, '/');
writestr (slot, sp -> acct.handle);
writech (slot, '\n');
}
if (first)
writestr (slot, "Nobody currently typing\n");
}
void operact (from, to, msg)
struct slot *from,
*to;
char *msg;
{
struct slot *sp;
for (sp = slotbase; sp < slotbase + numslots; sp++)
if (sp != from && sp -> on && sp -> acct.level >= 2) {
select_stop (sp);
select_wrap (sp);
writestr (sp, "* ");
writestr (sp, from -> acct.id);
writech (sp, '/');
writestr (sp, from -> acct.handle);
writech (sp, ' ');
writestr (sp, msg);
if (to != NULL) {
writech (sp, ' ');
writestr (sp, to -> acct.id);
writech (sp, '/');
writestr (sp, to -> acct.handle);
}
writech (sp, '\n');
clear_stop (sp);
clear_wrap (sp);
}
}
void paabout (slot, msg, chan)
struct slot *slot;
char *msg;
int chan;
{
struct slot *sp;
for (sp = slotbase; sp < slotbase + numslots; sp++)