aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/talkproc.c
blob: cfcf6c779c00190fa81f8621907c0b1d9b68426c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
/* talkproc.c
 *
 */

/*
    fics - An internet chess server.
    Copyright (C) 1993  Richard V. Nash

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
*/

/* Revision history:
   name				yy/mm/dd	Change
   hersco and Marsalis         	95/07/24	Created
   Sparky                       95/10/05
                                Modifed tell function for the following
                                changes:  no longer informs you that someone
                                is censoring in tells to channels, whisper or
                                kibitz.  Titles now shown instead of ratings
                                in kibitz and whisper, admins on duty now are
                                shown as (*), and computers marked as (C) as
                                well as with rating.
   Markus Uhlin                 23/12/10	Cleaned up the file
   Markus Uhlin                 23/12/10	Fixed compiler warnings
   Markus Uhlin                 24/01/04	Fixed pprintf() calls
   Markus Uhlin                 24/04/14	Refactored and reformatted ALL
						functions.
*/

#include "stdinclude.h"
#include "common.h"

#include "command.h"
#include "comproc.h"
#include "formula.h"
#include "gamedb.h"
#include "gameproc.h"
#include "lists.h"
#include "maxxes-utils.h"
#include "network.h"
#include "playerdb.h"
#include "talkproc.h"
#include "utils.h"

#include <sys/resource.h>

#define TELL_TELL        0
#define TELL_SAY         1
#define TELL_WHISPER     2
#define TELL_KIBITZ      3
#define TELL_CHANNEL     4

int quota_time;

// hawk: hacked it to fit ALL persons - quota list is not needed anymore
PRIVATE int
CheckShoutQuota(int p)
{
	time_t	timeleft = 0;
	time_t	timenow = time(NULL);

	timeleft = timenow - parray[p].lastshout_a;

	if (timeleft < quota_time && parray[p].adminLevel == 0)
		return (quota_time - timeleft);
	return 0;
}

PUBLIC int
com_shout(int p, param_list param)
{
	int	count = 0;
	int	p1;
	int	timeleft; // time left for quota if applicable

	if (!parray[p].registered) {
		pprintf(p, "Only registered players can use the shout "
		    "command.\n");
		return COM_OK;
	}

	if (in_list(p, L_MUZZLE, parray[p].login)) {
		pprintf(p, "You are muzzled.\n");
		return COM_OK;
	}

	if (param[0].type == TYPE_NULL) {
		if ((timeleft = CheckShoutQuota(p))) {
			pprintf(p, "Next shout available in %d seconds.\n",
			    timeleft);
		} else {
			pprintf(p, "Your next shout is ready for use.\n");
		}

		return COM_OK;
	}

	if ((timeleft = CheckShoutQuota(p))) {
		pprintf(p, "Shout not sent. Next shout in %d seconds.\n",
		    timeleft);
		return COM_OK;
	}

	parray[p].lastshout_a = parray[p].lastshout_b;
	parray[p].lastshout_b = time(NULL);

	if (!printablestring(param[0].val.string)) {
		pprintf(p, "Your message contains some unprintable "
		    "character(s).\n");
		return COM_OK;
	}

	for (p1 = 0; p1 < p_num; p1++) {
		if (p1 == p)
			continue;
		if (parray[p1].status != PLAYER_PROMPT)
			continue;
		if (!parray[p1].i_shout)
			continue;
		if (player_censored(p1, p))
			continue;

		count++;

		pprintf_prompt(p1, "\n%s shouts: %s\n",
		    parray[p].name,
		    param[0].val.string);
	}

	pprintf(p, "(%d) %s shouts: %s\n", count, parray[p].name,
	    param[0].val.string);

	if ((timeleft = CheckShoutQuota(p))) {
		pprintf(p, "Next shout in %d seconds.\n", timeleft);
		return COM_OK;
	}

	return COM_OK;
}

PUBLIC int
com_cshout(int p, param_list param)
{
	int	count = 0;
	int	p1;

	if (!parray[p].registered) {
		pprintf(p, "Only registered players can use the cshout "
		    "command.\n");
		return COM_OK;
	}

	if (in_list(p, L_CMUZZLE, parray[p].login)) {
		pprintf(p, "You are c-muzzled.\n");
		return COM_OK;
	}

	if (!printablestring(param[0].val.string)) {
		pprintf(p, "Your message contains some unprintable "
		    "character(s).\n");
		return COM_OK;
	}

	for (p1 = 0; p1 < p_num; p1++) {
		if (p1 == p)
			continue;
		if (parray[p1].status != PLAYER_PROMPT)
			continue;
		if (!parray[p1].i_cshout)
			continue;
		if (player_censored(p1, p))
			continue;

		count++;

		pprintf_prompt(p1, "\n%s c-shouts: %s\n",
		    parray[p].name,
		    param[0].val.string);
	}

	pprintf(p, "(%d) %s c-shouts: %s\n", count, parray[p].name,
	    param[0].val.string);
	return COM_OK;
}

PUBLIC int
com_it(int p, param_list param)
{
	int	count = 0;
	int	p1;
	int	timeleft;

	if (!parray[p].registered) {
		pprintf(p, "Only registered players can use the it command.\n");
		return COM_OK;
	}

	if (in_list(p, L_MUZZLE, parray[p].login)) {
		pprintf(p, "You are muzzled.\n");
		return COM_OK;
	}

	if (param[0].type == TYPE_NULL) {
		if ((timeleft = CheckShoutQuota(p))) {
			pprintf(p, "Next shout available in %d seconds.\n",
			    timeleft);
		} else {
			pprintf(p, "Your next shout is ready for use.\n");
		}

		return COM_OK;
	}

	if ((timeleft = CheckShoutQuota(p))) {
		pprintf(p, "Shout not sent. Next shout in %d seconds.\n",
		    timeleft);
		return COM_OK;
	}

	parray[p].lastshout_a = parray[p].lastshout_b;
	parray[p].lastshout_b = time(NULL);

	if (!printablestring(param[0].val.string)) {
		pprintf(p, "Your message contains some unprintable "
		    "character(s).\n");
		return COM_OK;
	}

	for (p1 = 0; p1 < p_num; p1++) {
		if (p1 == p)
			continue;
		if (parray[p1].status != PLAYER_PROMPT)
			continue;
		if (!parray[p1].i_shout)
			continue;
		if (player_censored(p1, p))
			continue;

		count++;

		if (!strncmp(param[0].val.string, "\'", 1) ||
		    !strncmp(param[0].val.string, ",", 1) ||
		    !strncmp(param[0].val.string, ".", 1)) {
			pprintf_prompt(p1, "\n--> %s%s\n", parray[p].name,
			    param[0].val.string);
		} else {
			pprintf_prompt(p1, "\n--> %s %s\n", parray[p].name,
			    param[0].val.string);
		}
	}

	if (!strncmp(param[0].val.string, "\'", 1) ||
	    !strncmp(param[0].val.string, ",", 1) ||
	    !strncmp(param[0].val.string, ".", 1)) {
		pprintf(p, "(%d) --> %s%s\n", count, parray[p].name,
		    param[0].val.string);
	} else {
		pprintf(p, "(%d) --> %s %s\n", count, parray[p].name,
		    param[0].val.string);
	}

	if ((timeleft = CheckShoutQuota(p))) {
		pprintf(p, "Next shout in %d seconds.\n", timeleft);
		return COM_OK;
	}

	return COM_OK;
}

PRIVATE int
tell(int p, int p1, char *msg, int why, int ch)
{
	char	tmp[MAX_LINE_SIZE] = { '\0' };
	int	rating1;
	int	rating;

	if (!printablestring(msg)) {
		pprintf(p, "Your message contains some unprintable "
		    "character(s).\n");
		return COM_OK;
	}

	if ((!parray[p1].i_tell) && (!parray[p].registered)) {
		pprintf(p, "Player \"%s\" isn't listening to unregistered "
		    "tells.\n", parray[p1].name);
		return COM_OK;
	}

	if (player_censored(p1, p) && parray[p].adminLevel == 0) {
		if (why != TELL_KIBITZ ||
		    why != TELL_WHISPER ||
		    why != TELL_CHANNEL) {
			pprintf(p, "Player \"%s\" is censoring you.\n",
			    parray[p1].name);
		}

		return COM_OK;
	}

	switch (why) {
	case TELL_SAY:
		pprintf_highlight(p1, "\n%s", parray[p].name);
		pprintf_prompt(p1, " says: %s\n", msg);
		break;
	case TELL_WHISPER:
	case TELL_KIBITZ:
		rating = GetRating(&parray[p], TYPE_BLITZ);

		if (rating < (rating1 = (GetRating(&parray[p], TYPE_STAND))))
			rating = rating1;

		if (in_list(p, L_FM, parray[p].name)) {
			pprintf(p1, "\n%s(FM)", parray[p].name);
		} else if (in_list(p, L_IM, parray[p].name)) {
			pprintf(p1, "\n%s(IM)", parray[p].name);
		} else if (in_list(p, L_GM, parray[p].name)) {
			pprintf(p1, "\n%s(GM)", parray[p].name);
		} else if (parray[p].adminLevel >= 10 && parray[p].i_admin) {
			pprintf(p1, "\n%s(*)", parray[p].name);
		} else if ((rating >= parray[p1].kiblevel) ||
		    ((parray[p].adminLevel >= 10) && (parray[p].i_admin))) {
			if (!parray[p].registered) {
				pprintf(p1, "\n%s(++++)", parray[p].name);
			} else if (rating != 0) {
				if (in_list(p, L_COMPUTER, parray[p].name)) {
					pprintf(p1, "\n%s(%d)(C)",
					    parray[p].name,
					    rating);
				} else {
					pprintf(p1, "\n%s(%d)",
					    parray[p].name,
					    rating);
				}
			} else {
				pprintf(p1, "\n%s(----)", parray[p].name);
			}
		} else {
			break;
		}

		if (why == TELL_WHISPER)
			pprintf_prompt(p1, " whispers: %s\n", msg);
		else
			pprintf_prompt(p1, " kibitzes: %s\n", msg);
		break;
	case TELL_CHANNEL:
		pprintf(p1, "\n%s", parray[p].name);
		pprintf_prompt(p1, "(%d): %s\n", ch, msg);
		break;
	case TELL_TELL:
	default:
		if (parray[p1].highlight) {
			pprintf_highlight(p1, "\n%s", parray[p].name);
		} else {
			pprintf(p1, "\n%s", parray[p].name);
		}

		pprintf_prompt(p1, " tells you: %s\n", msg);
		break;
	}

	tmp[0] = '\0';

	if (!(parray[p1].busy[0] == '\0')) {
		msnprintf(tmp, sizeof tmp, ", who %s (idle: %s)",
		    parray[p1].busy,
		    hms_desc(player_idle(p1)));
	} else {
		if (((player_idle(p1) % 3600) / 60) > 2) {
			msnprintf(tmp, sizeof tmp, ", who has been idle %s",
			    hms_desc(player_idle(p1)));
		}
	}

	if (why == TELL_SAY || why == TELL_TELL) {
		pprintf(p, "(told %s%s)\n", parray[p1].name,
		    (((parray[p1].game >= 0) &&
		    (garray[parray[p1].game].status == GAME_EXAMINE)) ?
		    ", who is examining a game" :
		    (parray[p1].game >= 0 &&
		    (parray[p1].game != parray[p].game)) ?
		    ", who is playing" : tmp));
		parray[p].last_tell = p1;
	}

	return COM_OK;
}

/*
 * Tells partner - doesn't change last tell.
 */
PUBLIC int
com_ptell(int p, param_list param)
{
	char	tmp[MAX_LINE_SIZE];
	int	p1;

	if (parray[p].partner < 0) {
		pprintf(p, "You do not have a partner at present.\n");
		return COM_OK;
	}

	p1 = parray[p].partner;

	if (p1 < 0 ||
	    parray[p1].status == PLAYER_PASSWORD ||
	    parray[p1].status == PLAYER_LOGIN) {
		pprintf(p, "Your partner is not logged in.\n");
		return COM_OK;
	}

	if (parray[p1].highlight) {
		pprintf_highlight(p1, "\n%s", parray[p].name);
	} else {
		pprintf(p1, "\n%s", parray[p].name);
	}

	pprintf_prompt(p1, " (your partner) tells you: %s\n",
	    param[0].val.string);
	tmp[0] = '\0';

	if (!(parray[p1].busy[0] == '\0')) {
		msnprintf(tmp, sizeof tmp, ", who %s (idle: %s)",
		    parray[p1].busy,
		    hms_desc(player_idle(p1)));
	} else {
		if (((player_idle(p1) % 3600) / 60) > 2) {
			msnprintf(tmp, sizeof tmp, ", who has been idle %s",
			    hms_desc(player_idle(p1)));
		}
	}

	pprintf(p, "(told %s%s)\n", parray[p1].name,
	    (((parray[p1].game >= 0) &&
	    (garray[parray[p1].game].status == GAME_EXAMINE)) ?
	    ", who is examining a game" :
	    (parray[p1].game >= 0 &&
	    (parray[p1].game != parray[p].game)) ?
	    ", who is playing" : tmp));
	return COM_OK;
}

PRIVATE int
chtell(int p, int ch, char *msg)
{
	int	p1, count = 0;

	if (ch == 0 && parray[p].adminLevel == 0) {
		pprintf(p, "Only admins may send tells to channel 0.\n");
		return COM_OK;
	}

	if (ch < 0) {
		pprintf(p, "The lowest channel number is 0.\n");
		return COM_OK;
	}

	if (ch >= MAX_CHANNELS) {
		pprintf(p, "The maximum channel number is %d.\n",
		    (MAX_CHANNELS - 1));
		return COM_OK;
	}

	for (p1 = 0; p1 < p_num; p1++) {
		if (p1 == p || parray[p1].status != PLAYER_PROMPT)
			continue;
		if (on_channel(ch, p1) && !player_censored(p1, p)) {
			tell(p, p1, msg, TELL_CHANNEL, ch);
			count++;
		}
	}

	if (count)
		parray[p].last_channel = ch;

	pprintf(p, "(%d->(%d))\n", ch, count);

	if (!on_channel(ch, p))
		pprintf(p, " (You're not listening to channel %d.)\n", ch);
	return COM_OK;
}

PUBLIC int
com_whisper(int p, param_list param)
{
	int	count = 0;
	int	g;
	int	p1;

	if (!parray[p].num_observe && parray[p].game < 0) {
		pprintf(p, "You are not playing or observing a game.\n");
		return COM_OK;
	}

	if (!parray[p].registered && (parray[p].game == -1)) {
		pprintf(p, "You must be registered to whisper other people's "
		    "games.\n");
		return COM_OK;
	}

	if (parray[p].game >= 0)
		g = parray[p].game;
	else
		g = parray[p].observe_list[0];

	for (p1 = 0; p1 < p_num; p1++) {
		if (p1 == p)
			continue;
		if (parray[p1].status != PLAYER_PROMPT)
			continue;
		if (player_is_observe(p1, g) ||
		    (garray[g].link >= 0 &&
		    player_is_observe(p1, garray[g].link))) {
			tell(p, p1, param[0].val.string, TELL_WHISPER, 0);

			if (parray[p].adminLevel >= ADMIN_ADMIN ||
			    !garray[g].private)
				count++;
		}
	}

	pprintf(p, "whispered to %d.\n", count);
	return COM_OK;
}

PUBLIC int
com_kibitz(int p, param_list param)
{
	int	count = 0;
	int	g;
	int	p1;

	if (!parray[p].num_observe && parray[p].game < 0) {
		pprintf(p, "You are not playing or observing a game.\n");
		return COM_OK;
	}

	if (!parray[p].registered && (parray[p].game == -1)) {
		pprintf(p, "You must be registered to kibitz other people's "
		    "games.\n");
		return COM_OK;
	}

	if (parray[p].game >= 0)
		g = parray[p].game;
	else
		g = parray[p].observe_list[0];

	for (p1 = 0; p1 < p_num; p1++) {
		if (p1 == p)
			continue;
		if (parray[p1].status != PLAYER_PROMPT)
			continue;
		if ((player_is_observe(p1, g) ||
		    parray[p1].game == g ||
		    (garray[g].link >= 0 &&
		    (player_is_observe(p1, garray[g].link) ||
		    parray[p1].game == garray[g].link))) &&
		    parray[p1].i_kibitz) {
			tell(p, p1, param[0].val.string, TELL_KIBITZ, 0);

			if (parray[p].adminLevel >= ADMIN_ADMIN ||
			    !garray[g].private ||
			    parray[p1].game == g)
				count++;
		}
	}

	pprintf(p, "kibitzed to %d.\n", count);
	return COM_OK;
}

PUBLIC int
com_tell(int p, param_list param)
{
	int	p1;

	if (param[0].type == TYPE_NULL)
		return COM_BADPARAMETERS;

	if (param[0].type == TYPE_WORD) {
		stolower(param[0].val.word);

		if (!strcmp(param[0].val.word, ".")) {
			if (parray[p].last_tell < 0) {
				pprintf(p, "No one to tell anything to.\n");
				return COM_OK;
			} else {
				return tell(p, parray[p].last_tell,
				    param[1].val.string, TELL_TELL, 0);
			}
		}

		if (!strcmp(param[0].val.word, ",")) {
			if (parray[p].last_channel < 0) {
				pprintf(p, "No previous channel.\n");
				return COM_OK;
			} else {
				return chtell(p, parray[p].last_channel,
				    param[1].val.string);
			}
		}

		p1 = player_find_part_login(param[0].val.word);

		if (p1 < 0 ||
		    parray[p1].status == PLAYER_PASSWORD ||
		    parray[p1].status == PLAYER_LOGIN) {
			pprintf(p, "No user named \"%s\" is logged in.\n",
			    param[0].val.word);
			return COM_OK;
		}

		return tell(p, p1, param[1].val.string, TELL_TELL, 0);
	} else {	// Channel
		return chtell(p, param[0].val.integer, param[1].val.string);
	}
}

PUBLIC int
com_xtell(int p, param_list param)
{
	char	*msg;
	char	 tmp[2048];
	int	 p1;

	msg	= param[1].val.string;
	p1	= player_find_part_login(param[0].val.word);

	if (p1 < 0 ||
	    parray[p1].status == PLAYER_PASSWORD ||
	    parray[p1].status == PLAYER_LOGIN) {
		pprintf(p, "No user named \"%s\" is logged in.\n",
		    param[0].val.word);
		return COM_OK;
	}

	if (!printablestring(msg)) {
		pprintf(p, "Your message contains some unprintable "
		    "character(s).\n");
		return COM_OK;
	}

	if ((!parray[p1].i_tell) && (!parray[p].registered)) {
		pprintf(p, "Player \"%s\" isn't listening to unregistered "
		    "tells.\n", parray[p1].name);
		return COM_OK;
	}

	if (player_censored(p1, p) && parray[p].adminLevel == 0) {
		pprintf(p, "Player \"%s\" is censoring you.\n",
		    parray[p1].name);
		return COM_OK;
	}

	if (parray[p1].highlight) {
		pprintf_highlight(p1, "\n%s", parray[p].name);
	} else {
		pprintf(p1, "\n%s", parray[p].name);
	}

	pprintf_prompt(p1, " tells you: %s\n", msg);
	tmp[0] = '\0';

	if (!(parray[p1].busy[0] == '\0')) {
		msnprintf(tmp, sizeof tmp, ", who %s (idle: %s)",
		    parray[p1].busy,
		    hms_desc(player_idle(p1)));
	} else {
		if (((player_idle(p1) % 3600) / 60) > 2) {
			msnprintf(tmp, sizeof tmp, ", who has been idle %s",
			    hms_desc(player_idle(p1)));
		}
	}

	pprintf(p, "(told %s%s)\n", parray[p1].name,
	    ((parray[p1].game >= 0 &&
	    garray[parray[p1].game].status == GAME_EXAMINE) ?
	    ", who is examining a game" :
	    (parray[p1].game >= 0 && parray[p1].game != parray[p].game) ?
	    ", who is playing" : tmp));

	return COM_OK;
}

PUBLIC int
com_say(int p, param_list param)
{
	if (parray[p].opponent < 0) {
		if (parray[p].last_opponent < 0) {
			pprintf(p, "No one to say anything to, try tell.\n");
			return COM_OK;
		} else {
			return tell(p, parray[p].last_opponent,
			    param[0].val.string, TELL_SAY, 0);
		}
	}

	return tell(p, parray[p].opponent, param[0].val.string, TELL_SAY, 0);
}

PUBLIC int
com_inchannel(int p, param_list param)
{
	char	 tmp[18];
	int	 p1, count = 0;

	if (param[0].type == TYPE_NULL) {
		pprintf(p, "inchannel [no params] has been removed\n");
		pprintf(p, "Please use inchannel [name] or inchannel"
		    "[number]\n");
		return COM_OK;
	}

	if (param[0].type == TYPE_WORD) {
		p1 = player_find_part_login(param[0].val.word);

		if ((p1 < 0) || (parray[p1].status != PLAYER_PROMPT)) {
			pprintf(p, "No user named \"%s\" is logged in.\n",
			    param[0].val.word);
			return COM_OK;
		}

		pprintf(p, "%s is in the following channels:", parray[p1].name);

		if (list_channels(p, p1))
			pprintf(p, " No channels found.\n");
		return COM_OK;
	} else {
		msnprintf(tmp, sizeof tmp, "%d", param[0].val.integer);

		for (p1 = 0; p1 < p_num; p1++) {
			if (parray[p1].status != PLAYER_PROMPT)
				continue;
			if (in_list(p1, L_CHANNEL, tmp)) {
				if (!count) {
					pprintf(p, "Channel %d:",
					    param[0].val.integer);
				}

				pprintf(p, " %s%s", parray[p1].name,
				    (((parray[p1].adminLevel >= 10) &&
				    (parray[p1].i_admin) &&
				    (param[0].val.integer < 2)) ? "(*)" : ""));

				count++;
			}
		}

		if (!count) {
			pprintf(p, "Channel %d is empty.\n",
			    param[0].val.integer);
		} else {
			pprintf(p, "\n%d %s in channel %d.\n", count,
			    (count == 1 ? "person is" : "people are"),
			    param[0].val.integer);
		}

		return COM_OK;
	}
}

PUBLIC int
com_sendmessage(int p, param_list param)
{
	int p1, connected = 1;

	if (!parray[p].registered) {
		pprintf(p, "You are not registered and cannot send messages."
		    "\n");
		return COM_OK;
	}

	if (param[0].type == TYPE_NULL || param[1].type == TYPE_NULL) {
		pprintf(p, "No message sent.\n");
		return COM_OK;
	}

	if (!FindPlayer(p, param[0].val.word, &p1, &connected))
		return COM_OK;

	if (!parray[p1].registered) {
		pprintf(p, "Player \"%s\" is unregistered and cannot receive "
		    "messages.\n", parray[p1].name);
		return COM_OK;
	}

	if (player_censored(p1, p) && parray[p].adminLevel == 0) {
		pprintf(p, "Player \"%s\" is censoring you.\n",
		    parray[p1].name);

		if (!connected)
			player_remove(p1);
		return COM_OK;
	}

	if (player_add_message(p1, p, param[1].val.string)) {
		pprintf(p, "Couldn't send message to %s. "
		    "Message buffer full.\n", parray[p1].name);
	} else {
		if (connected) {
			pprintf(p1, "\n%s just sent you a message:\n",
			    parray[p].name);
			pprintf_prompt(p1, "    %s\n", param[1].val.string);
		}
	}

	if (!connected)
		player_remove(p1);
	return COM_OK;
}

PUBLIC int
com_messages(int p, param_list param)
{
	int start;

	if (!parray[p].registered) {
		pprintf(p, "Unregistered players may not send or receive "
		    "messages.\n");
		return COM_OK;
	}

	if (param[0].type == TYPE_NULL) {
		player_show_messages(p);
	} else if (param[0].type == TYPE_WORD) {
		if (param[1].type != TYPE_NULL)
			return com_sendmessage(p, param);
		else
			ShowMsgsBySender(p, param);
	} else {
		start = param[0].val.integer;
		ShowMsgRange(p, start, start);
	}

	return COM_OK;
}

PUBLIC int
com_clearmessages(int p, param_list param)
{
	int start;

	if (player_num_messages(p) <= 0) {
		pprintf(p, "You have no messages.\n");
		return COM_OK;
	}

	if (param[0].type == TYPE_NULL) {
		pprintf(p, "Messages cleared.\n");
		player_clear_messages(p);
	} else if (param[0].type == TYPE_WORD) {
		ClearMsgsBySender(p, param);
	} else if (param[0].type == TYPE_INT) {
		start = param[0].val.integer;
		ClrMsgRange(p, start, start);
	}

	return COM_OK;
}

PUBLIC int
com_mailmess(int p, param_list param)
{
	char	*buffer[1000];
	char	 filename[MAX_FILENAME_SIZE];
	char	 fname[MAX_FILENAME_SIZE];
	char	 mdir[MAX_FILENAME_SIZE];
	char	 subj[120];
	int	 ret, too_long;

	if (!parray[p].registered) {
		pprintf(p, "Only registered people can use the mailmess "
		    "command.\n");
		return COM_OK;
	}

	snprintf(filename, sizeof filename, "%s.messages", parray[p].login);
	snprintf(mdir, sizeof mdir, "%s/player_data/%c/", stats_dir,
	    parray[p].login[0]);

	if (search_directory(mdir, filename, buffer, ARRAY_SIZE(buffer))) {
		snprintf(subj, sizeof subj, "Your FICS messages from server %s",
		    fics_hostname);

		ret = snprintf(fname, sizeof fname, "%s/%s", mdir, filename);
		too_long = (ret < 0 || (size_t)ret >= sizeof fname);

		if (!too_long) {
			mail_file_to_user(p, subj, fname);
			pprintf(p, "Messages sent to %s\n",
			    parray[p].emailAddress);
		}
	} else {
		pprintf(p, "You have no messages.\n");
	}

	return COM_OK;
}

PUBLIC int
com_znotify(int p, param_list param)
{
	int	p1, count = 0;

	for (p1 = 0; p1 < p_num; p1++) {
		if (player_notified(p, p1)) {
			if (!count) {
				pprintf(p, "Present company on your notify "
				    "list:\n  ");
			}

			pprintf(p, " %s", parray[p1].name);
			count++;
		}
	}

	if (count)
		pprintf(p, ".\n");
	else
		pprintf(p, "No one from your notify list is logged on.\n");

	count = 0;

	for (p1 = 0; p1 < p_num; p1++) {
		if (player_notified(p1, p) &&
		    parray[p1].status == PLAYER_PROMPT) {
			if (!count) {
				pprintf(p, "The following players have you "
				    "on their notify list:\n  ");
			}

			pprintf(p, " %s", parray[p1].name);
			count++;
		}
	}

	if (count)
		pprintf(p, ".\n");
	else
		pprintf(p, "No one logged in has you on their notify list.\n");
	return COM_OK;
}

PUBLIC int
com_qtell(int p, param_list param)
{
	char buffer1[MAX_STRING_LENGTH];	// no highlight and no bell
	char buffer2[MAX_STRING_LENGTH];	// no highlight and bell
	char buffer3[MAX_STRING_LENGTH];	// highlight and no bell
	char buffer4[MAX_STRING_LENGTH];	// highlight and and bell
	char dummy[2];
	char tmp[MAX_STRING_LENGTH];
	int i, count;
	int p1;

	if (!in_list(p, L_TD, parray[p].name)) {
		pprintf(p, "Only TD programs are allowed to use this command."
		    "\n");
		return COM_OK;
	}

	mstrlcpy(buffer1, ":\0", sizeof buffer1);
	mstrlcpy(buffer2, ":\0", sizeof buffer2);
	mstrlcpy(buffer3, ":\0", sizeof buffer3);
	mstrlcpy(buffer4, ":\0", sizeof buffer4);

	msnprintf(tmp, sizeof tmp, "%s", param[1].val.string);

	count = 0;
	i = 0;
	while (tmp[i] != '\0' && count < 1029) {
		if (tmp[i] == '\\' && tmp[i + 1] == 'n') {
			mstrlcat(buffer1, "\n:", sizeof buffer1);
			mstrlcat(buffer2, "\n:", sizeof buffer2);
			mstrlcat(buffer3, "\n:", sizeof buffer3);
			mstrlcat(buffer4, "\n:", sizeof buffer4);

			count += 2;
			i += 2;
		} else if (tmp[i] == '\\' && tmp[i + 1] == 'b') {
			mstrlcat(buffer2, "\007", sizeof buffer2);
			mstrlcat(buffer4, "\007", sizeof buffer4);

			count++;
			i += 2;
		} else if (tmp[i] == '\\' && tmp[i + 1] == 'H') {
			mstrlcat(buffer3, "\033[7m", sizeof buffer3);
			mstrlcat(buffer4, "\033[7m", sizeof buffer4);

			count += 4;
			i += 2;
		} else if (tmp[i] == '\\' && tmp[i + 1] == 'h') {
			mstrlcat(buffer3, "\033[0m", sizeof buffer3);
			mstrlcat(buffer4, "\033[0m", sizeof buffer4);

			count += 4;
			i += 2;
		} else {
			dummy[0] = tmp[i];
			dummy[1] = '\0';

			mstrlcat(buffer1, dummy, sizeof buffer1);
			mstrlcat(buffer2, dummy, sizeof buffer2);
			mstrlcat(buffer3, dummy, sizeof buffer3);
			mstrlcat(buffer4, dummy, sizeof buffer4);

			count++;
			i++;
		}
	} // while

	if (param[0].type == TYPE_WORD) {
		if ((p1 = player_find_bylogin(param[0].val.word)) < 0) {
			pprintf(p, "*qtell %s 1*\n", param[0].val.word);
			return COM_OK;
		}

		pprintf_prompt(p1, "\n%s\n",
		    (parray[p1].highlight && parray[p1].bell) ?
		    buffer4 :
		    (parray[p1].highlight && !parray[p1].bell) ?
		    buffer3 :
		    (!parray[p1].highlight && parray[p1].bell) ?
		    buffer2 : buffer1);
		pprintf(p, "*qtell %s 0*\n", parray[p1].name);
	} else {
		int	ch = param[0].val.integer;
		int	p1;

		if (ch == 0) {
			pprintf(p, "*qtell %d 1*\n", param[0].val.integer);
			return COM_OK;
		}
		if (ch < 0) {
			pprintf(p, "*qtell %d 1*\n", param[0].val.integer);
			return COM_OK;
		}
		if (ch >= MAX_CHANNELS) {
			pprintf(p, "*qtell %d 1*\n", param[0].val.integer);
			return COM_OK;
		}

		msnprintf(tmp, sizeof tmp, "%d", param[0].val.integer);

		for (p1 = 0; p1 < p_num ; p1++) {
			if (p1 == p || player_censored(p1, p) ||
			    parray[p1].status != PLAYER_PROMPT)
				continue;
			if (in_list(p1, L_CHANNEL, tmp)) {
				pprintf_prompt(p1, "\n%s\n",
				    (parray[p1].highlight && parray[p1].bell) ?
				    buffer4 :
				    (parray[p1].highlight && !parray[p1].bell) ?
				    buffer3 :
				    (!parray[p1].highlight && parray[p1].bell) ?
				    buffer2 : buffer1);
			}
		}

		pprintf(p, "*qtell %d 0*\n", param[0].val.integer);
	}

	return COM_OK;
}

PUBLIC int
on_channel(int ch, int p)
{
	char tmp[20];

	snprintf(tmp, sizeof tmp, "%d", ch);
	return in_list(p, L_CHANNEL, tmp);	// since needs 'ch' converted
						// to a string keep hidden from
						// view
}