aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/comproc.c
blob: 5314d5813ed8ac624df220e7c3496b9de7123e87 (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
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
/* comproc.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		email		yy/mm/dd	Change
   Richard Nash			93/10/22	Created
   foxbat			95/03/11	Added filters in cmatch
   Markus Uhlin			23/12/09	Fixed implicit ints
*/

#include "stdinclude.h"

#include "board.h"
#include "command.h"
#include "common.h"
#include "comproc.h"
#include "config.h"
#include "eco.h"
#include "ficsmain.h"
#include "formula.h"
#include "gamedb.h"
#include "gameproc.h"
#include "lists.h"
#include "multicol.h"
#include "network.h"
#include "network.h"
#include "obsproc.h"
#include "playerdb.h"
#include "ratings.h"
#include "rmalloc.h"
#include "talkproc.h"
#include "utils.h"
#include "variable.h"

#include <sys/resource.h>

const int none = 0;
const int blitz_rat = 1;
const int std_rat = 2;
const int wild_rat = 3;
const int light_rat = 4;


PUBLIC int com_rating_recalc(int p, param_list param)
{
  ASSERT(parray[p].adminLevel >= ADMIN_ADMIN);
  rating_recalc();
  return COM_OK;
}

PUBLIC int com_more(int p, param_list param)
{
  pmore_file(p);
  return COM_OK;
}

PUBLIC int num_news = -1;

PUBLIC void rscan_news2(FILE *fp, int p, int num)
{
  char junk[MAX_LINE_SIZE], count[10];
  int crtime;
  char *junkp;

  if (num == 0)
    return;

  fgets(junk, MAX_LINE_SIZE, fp);
  if (feof(fp))
    return;
  sscanf(junk, "%d %s", &crtime, count);
  rscan_news2(fp, p, num - 1);
  junkp = junk;
  junkp = nextword(junkp);
  junkp = nextword(junkp);
  pprintf(p, "%3s (%s) %s", count, fix_time(strltime(&crtime)), junkp);
}

PUBLIC int com_news(int p, param_list param)
{
  FILE *fp;
  char filename[MAX_FILENAME_SIZE];
  char junk[MAX_LINE_SIZE];
  char *junkp;
  int crtime, found = 0;
  char count[10];

  sprintf(filename, "%s/newnews.index", news_dir);
  fp = fopen(filename, "r");

  if (!fp) {
    fprintf(stderr, "Can\'t find news index.\n");
    return COM_OK;
  }

  if (param[0].type == 0) {

    /* no params - then just display index of last ten news items */

    pprintf(p,"Index of recent news items:\n");
    fgets(junk, MAX_LINE_SIZE, fp);
    sscanf(junk, "%d %s", &crtime, count);
    rscan_news2(fp, p, 9);
    junkp = junk;
    junkp = nextword(junkp);
    junkp = nextword(junkp);
    pprintf(p, "%3s (%s) %s", count, fix_time(strltime(&crtime)), junkp);
    fclose(fp);

  } else if ((param[0].type == TYPE_WORD) && !strcmp(param[0].val.word,"all")) {

    /* param all - displays index all news items */

    pprintf(p, "Index of all news items:\n");
    fgets(junk, MAX_LINE_SIZE, fp);
    sscanf(junk, "%d %s", &crtime, count);
    rscan_news(fp, p, 0);
    junkp = junk;
    junkp = nextword(junkp);
    junkp = nextword(junkp);
    pprintf(p, "%3s (%s) %s", count, fix_time(strltime(&crtime)), junkp);
    fclose(fp);

  } else {

    /* check if the specific news file exist in index */

    while (!feof(fp) && !found) {
      junkp = junk;
      fgets(junk, MAX_LINE_SIZE, fp);
      if (feof(fp))
	break;
      sscanf(junkp, "%d %s", &crtime, count);
      if (!strcmp(count, param[0].val.word)) {
	found = 1;
	junkp = nextword(junkp);
	junkp = nextword(junkp);
	pprintf(p, "NEWS %3s (%s) %s\n", count, fix_time(strltime(&crtime)),
		junkp);
      }
    }

    fclose(fp);

    if (!found) {
      pprintf(p, "Bad index number!\n");
      return COM_OK;
    }

    /* file exists - show it */
    sprintf(filename, "%s/news.%s", news_dir, param[0].val.word);
    fp = fopen(filename, "r");
    if (!fp) {
      pprintf(p, "No more info.\n");
      return COM_OK;
    }

    fclose(fp);

    sprintf(filename, "news.%s", param[0].val.word);
    if (psend_file(p, news_dir, filename) < 0) {
      pprintf(p, "Internal error - couldn't send news file!\n");
    }
  }

  return COM_OK;
}

PUBLIC int com_quit(int p, param_list param)
{
  if ((parray[p].game >= 0) && (garray[parray[p].game].status == GAME_EXAMINE)) {
    pcommand(p, "unexamine");
  }

  if (parray[p].game >= 0) {
    pprintf(p, "You can't quit while you are playing a game.\nType 'resign' to resign the game, or you can request an abort with 'abort'.\n");
    return COM_OK;
  }
  psend_logoutfile(p, mess_dir, MESS_LOGOUT);
  return COM_LOGOUT;
}

PUBLIC int com_set(int p, param_list param)
{
  int result;
  int which;
  char *val;

  if (param[1].type == TYPE_NULL)
    val = NULL;
  else
    val = param[1].val.string;
  result = var_set(p, param[0].val.word, val, &which);
  switch (result) {
  case VAR_OK:
    break;
  case VAR_BADVAL:
    pprintf(p, "Bad value given for variable %s.\n", param[0].val.word);
    break;
  case VAR_NOSUCH:
    pprintf(p, "No such variable name %s.\n", param[0].val.word);
    break;
  case VAR_AMBIGUOUS:
    pprintf(p, "Ambiguous variable name %s.\n", param[0].val.word);
    break;
  }
  /* player_save(p); */
  return COM_OK;
}

PUBLIC int FindPlayer(int p, char* name, int *p1, int *connected)
{
  *p1 = player_search(p, name);
  if (*p1 == 0)
    return 0;
  if (*p1 < 0) {		/* player had to be connected and will be
			   removed later */
    *connected = 0;
    *p1 = (-*p1) - 1;
  } else {
    *connected = 1;
    *p1 = *p1 - 1;
  }
  return 1;
}

PRIVATE void com_stats_andify(int *numbers, int howmany, char *dest)
{
  char tmp[10];

  *dest = '\0';
  while (howmany--) {
    sprintf(tmp, "%d", numbers[howmany]);
    strcat(dest, tmp);
    if (howmany > 1)
      sprintf(tmp, ", ");
    else if (howmany == 1)
      sprintf(tmp, " and ");
    else
      sprintf(tmp, ".\n");
    strcat(dest, tmp);
  }
  return;
}

PRIVATE void com_stats_rating(char *hdr, statistics * stats, char *dest)
{
  char tmp[100];

  sprintf(dest, "%-10s%4s    %5.1f   %4d   %4d   %4d   %4d",
	  hdr, ratstr(stats->rating), stats->sterr, stats->win, stats->los, stats->dra, stats->num);
  if (stats->whenbest) {
    sprintf(tmp, "   %d", stats->best);
    strcat(dest, tmp);
    strftime(tmp, sizeof(tmp), " (%d-%b-%y)", localtime((time_t *) & stats->whenbest));
    strcat(dest, tmp);
  }
  strcat(dest, "\n");
  return;
}

PUBLIC int com_stats(int p, param_list param)
{
  int g, i, t;
  int p1, connected;
  char line[255], tmp[255];
  int numbers[MAX_OBSERVE > MAX_SIMUL ? MAX_OBSERVE : MAX_SIMUL];
  int onTime;

   if (param[0].type == TYPE_WORD) {
    if (!FindPlayer(p, param[0].val.word, &p1, &connected))
      return COM_OK;
  } else {
      p1 = p;
      connected = 1;
  }

  sprintf(line, "\nStatistics for %-11s ", parray[p1].name);
  if ((connected) && (parray[p1].status == PLAYER_PROMPT)) {
    sprintf(tmp, "On for: %s", hms_desc(player_ontime(p1)));
    strcat(line, tmp);
    sprintf(tmp, "   Idle: %s\n", hms_desc(player_idle(p1)));
  } else {
    if ((t = player_lastdisconnect(p1)))
      sprintf(tmp, "(Last disconnected %s):\n", strltime(&t));
    else
      sprintf(tmp, "(Never connected.)\n");
  }
  strcat(line, tmp);
  pprintf(p, "%s", line);
  if (parray[p1].simul_info.numBoards) {
    for (i = 0, t = 0; i < parray[p1].simul_info.numBoards; i++) {
      if ((numbers[t] = parray[p1].simul_info.boards[i] + 1) != 0)
	t++;
    }
    pprintf(p, "%s is giving a simul: game%s ", parray[p1].name, ((t > 1) ? "s" : ""));
    com_stats_andify(numbers, t, tmp);
    pprintf(p, tmp);
  } else if (parray[p1].game >= 0) {
    g = parray[p1].game;
    if (garray[g].status == GAME_EXAMINE) {
      pprintf(p, "(Examining game %d: %s vs. %s)\n", g + 1,
            garray[g].white_name, garray[g].black_name);
    } else {
      pprintf(p, "(playing game %d: %s vs. %s)\n", g + 1,
	    parray[garray[g].white].name, parray[garray[g].black].name);
      if (garray[g].link >= 0) {
	pprintf(p, "(partner is playing game %d: %s vs. %s)\n", garray[g].link + 1,
	    parray[garray[garray[g].link].white].name,
	    parray[garray[garray[g].link].black].name);
      }
    }
  }
  if (parray[p1].num_observe) {
    for (i = 0, t = 0; i < parray[p1].num_observe; i++) {
      g = parray[p1].observe_list[i];
      if ((g != -1) && ((parray[p].adminLevel >= ADMIN_ADMIN) || (garray[g].private == 0)))
	numbers[t++] = g + 1;
    }
    if (t) {
      pprintf(p, "%s is observing game%s ", parray[p1].name, ((t > 1) ? "s" : ""));
      com_stats_andify(numbers, t, tmp);
      pprintf(p, tmp);
    }
  }
  if (parray[p1].busy[0]) {
    pprintf(p, "(%s %s)\n", parray[p1].name, parray[p1].busy);
  }
  if (!parray[p1].registered) {
    pprintf(p, "%s is NOT a registered player.\n\n", parray[p1].name);
  } else {
    pprintf(p, "\n         rating     RD     win   loss   draw  total   best\n");
    com_stats_rating("Blitz", &parray[p1].b_stats, tmp);
    pprintf(p, tmp);
    com_stats_rating("Standard", &parray[p1].s_stats, tmp);
    pprintf(p, tmp);
    com_stats_rating("Lightning", &parray[p1].l_stats, tmp);
    pprintf(p, tmp);
    com_stats_rating("Wild", &parray[p1].w_stats, tmp);
    pprintf(p, tmp);
  }
  pprintf(p, "\n");
  if (parray[p1].adminLevel > 0) {
    pprintf(p, "Admin Level: ");
    switch (parray[p1].adminLevel) {
    case 5:
      pprintf(p, "Authorized Helper Person\n");
      break;
    case 10:
      pprintf(p, "Administrator\n");
      break;
    case 15:
      pprintf(p, "Help File Librarian/Administrator\n");
      break;
    case 20:
      pprintf(p, "Master Administrator\n");
      break;
    case 50:
      pprintf(p, "Master Help File Librarian/Administrator\n");
      break;
    case 60:
      pprintf(p, "Assistant Super User\n");
      break;
    case 100:
      pprintf(p, "Super User\n");
      break;
    default:
      pprintf(p, "%d\n", parray[p1].adminLevel);
      break;
    }
  }
  if (parray[p].adminLevel > 0)
    pprintf(p, "Full Name  : %s\n", (parray[p1].fullName ? parray[p1].fullName : "(none)"));
  if (((p1 == p) && (parray[p1].registered)) || (parray[p].adminLevel > 0))
    pprintf(p, "Address    : %s\n", (parray[p1].emailAddress ? parray[p1].emailAddress : "(none)"));
  if (parray[p].adminLevel > 0) {
    pprintf(p, "Host       : %s\n",
	    dotQuad(connected ? parray[p1].thisHost : parray[p1].lastHost));
  }
  if ((parray[p].adminLevel > 0) && (parray[p1].registered))
    if (parray[p1].num_comments)
      pprintf(p, "Comments   : %d\n", parray[p1].num_comments);

  if (connected && parray[p1].registered && (p==p1 ||
     (parray[p].adminLevel > 0))) {
    char *timeToStr = ctime((time_t *) &parray[p1].timeOfReg);

    timeToStr[strlen(timeToStr)-1]='\0';
    pprintf(p, "\n");
    onTime = (time(0) - parray[p1].logon_time) + parray[p1].totalTime;

    pprintf(p, "Total time on-line: %s\n", hms_desc(onTime) );
    pprintf(p, "%% of life on-line:  %3.1f  (since %s)\n",
           (double)((onTime*100)/(double)(time(0)-parray[p1].timeOfReg)),
           timeToStr);
  }

#ifdef TIMESEAL
  if (connected)
    pprintf(p, "\nTimeseal   : %s\n",
	    (con[parray[p1].socket].timeseal) ? "On" : "Off");
  if ((parray[p].adminLevel > 0) && (connected)) {
    if (findConnection(parray[p1].socket) && con[parray[p1].socket].timeseal) {
      pprintf(p, "Unix acc   : %s\nSystem/OS  : %s\n",
             con[parray[p1].socket].user,
             con[parray[p1].socket].sys);
    }
  }
#endif

  if (parray[p1].num_plan) {
    pprintf(p, "\n");
    for (i = 0; i < parray[p1].num_plan; i++)
      pprintf(p, "%2d: %s\n", i + 1, (parray[p1].planLines[i] != NULL) ? parray[p1].planLines[i] : "");
  }
  if (!connected)
    player_remove(p1);
  return COM_OK;
}

PUBLIC int com_password(int p, param_list param)
{
  char *oldpassword = param[0].val.word;
  char *newpassword = param[1].val.word;
  char salt[3];

  if (!parray[p].registered) {
    pprintf(p, "Setting a password is only for registered players.\n");
    return COM_OK;
  }
  if (parray[p].passwd) {
    salt[0] = parray[p].passwd[0];
    salt[1] = parray[p].passwd[1];
    salt[2] = '\0';
    if (strcmp(crypt(oldpassword, salt), parray[p].passwd)) {
      pprintf(p, "Incorrect password, password not changed!\n");
      return COM_OK;
    }
    rfree(parray[p].passwd);
    parray[p].passwd = NULL;
  }
  salt[0] = 'a' + rand() % 26;
  salt[1] = 'a' + rand() % 26;
  salt[2] = '\0';
  parray[p].passwd = xstrdup(crypt(newpassword, salt));
  pprintf(p, "Password changed to \"%s\".\n", newpassword);
  return COM_OK;
}

PUBLIC int com_uptime(int p, param_list param)
{
  unsigned long uptime = time(0) - startuptime;
  struct rusage ru;
  int days  = (uptime / (60*60*24));
  int hours = ((uptime % (60*60*24)) / (60*60));
  int mins  = (((uptime % (60*60*24)) % (60*60)) / 60);
  int secs  = (((uptime % (60*60*24)) % (60*60)) % 60);

  pprintf(p, "Server location: %s   Server version : %s\n", fics_hostname,VERS_NUM);
  pprintf(p, "The server has been up since %s.\n", strltime(&startuptime));
  if ((days==0) && (hours==0) && (mins==0)) {
    pprintf(p, "(Up for %d second%s)\n",
               secs, (secs==1) ? "" : "s");
  } else if ((days==0) && (hours==0)) {
    pprintf(p, "(Up for %d minute%s and %d second%s)\n",
               mins, (mins==1) ? "" : "s",
               secs, (secs==1) ? "" : "s");
  } else if (days==0) {
    pprintf(p, "(Up for %d hour%s, %d minute%s and %d second%s)\n",
               hours, (hours==1) ? "" : "s",
               mins, (mins==1) ? "" : "s",
               secs, (secs==1) ? "" : "s");
  } else {
    pprintf(p, "(Up for %d day%s, %d hour%s, %d minute%s and %d second%s)\n",
               days, (days==1) ? "" : "s",
               hours, (hours==1) ? "" : "s",
               mins, (mins==1) ? "" : "s",
               secs, (secs==1) ? "" : "s");
  }
  pprintf(p, "\nAllocs: %u  Frees: %u  Allocs In Use: %u\n",
	  malloc_count, free_count, malloc_count - free_count);
  if (parray[p].adminLevel >= ADMIN_ADMIN) {
    pprintf(p, "\nplayer size:%d, game size:%d, con size:%d, g_num:%d\n",
	    sizeof(player), sizeof(game), net_consize(), g_num);
    getrusage(RUSAGE_SELF, &ru);
    pprintf(p, "pagesize = %d, maxrss = %d, total = %d\n", getpagesize(), ru.ru_maxrss, getpagesize() * ru.ru_maxrss);
  }
  pprintf(p, "\nPlayer limit: %d\n", max_connections-10);
  pprintf(p, "\nThere are currently %d players, with a high of %d since last restart.\n", player_count(1), player_high);
  pprintf(p, "There are currently %d games, with a high of %d since last restart.\n", game_count(), game_high);
  pprintf(p, "\nCompiled on %s\n", COMP_DATE);
  return COM_OK;
}

PUBLIC int com_date(int p, param_list param)
{
  int t = time(0);
  pprintf(p, "Local time     - %s\n", strltime(&t));
  pprintf(p, "Greenwich time - %s\n", strgtime(&t));
  return COM_OK;
}

char *inout_string[] = {
  "login", "logout"
};

PRIVATE int plogins(p, fname)
int p;
char *fname;
{
  FILE *fp;
  int inout, thetime, registered;
  char loginName[MAX_LOGIN_NAME + 1];
  char ipstr[20];

  fp = fopen(fname, "r");
  if (!fp) {
    pprintf(p, "Sorry, no login information available.\n");
    return COM_OK;
  }
  while (!feof(fp)) {
    if (fscanf(fp, "%d %s %d %d %s\n", &inout, loginName, &thetime,
	       &registered, ipstr) != 5) {
      fprintf(stderr, "FICS: Error in login info format. %s\n", fname);
      fclose(fp);
      return COM_OK;
    }
    pprintf(p, "%s: %-17s %-6s", strltime(&thetime), loginName,
	    inout_string[inout]);
    if (parray[p].adminLevel > 0) {
      pprintf(p, " from %s\n", ipstr);
    } else
      pprintf(p, "\n");
  }
  fclose(fp);
  return COM_OK;
}

PUBLIC int com_llogons(int p, param_list param)
{
  char fname[MAX_FILENAME_SIZE];

  sprintf(fname, "%s/%s", stats_dir, STATS_LOGONS);
  return plogins(p, fname);
}

PUBLIC int com_logons(int p, param_list param)
{
  char fname[MAX_FILENAME_SIZE];

  if (param[0].type == TYPE_WORD) {
    sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, param[0].val.word[0], param[0].val.word, STATS_LOGONS);
  } else {
    sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, parray[p].login[0], parray[p].login, STATS_LOGONS);
  }
  return plogins(p, fname);
}

#define WHO_OPEN 0x01
#define WHO_CLOSED 0x02
#define WHO_RATED 0x04
#define WHO_UNRATED 0x08
#define WHO_FREE 0x10
#define WHO_PLAYING 0x20
#define WHO_REGISTERED 0x40
#define WHO_UNREGISTERED 0x80
#define WHO_BUGTEAM 0x100

#define WHO_ALL 0xff

void AddPlayerLists (int p1, char *ptmp)
{
  if ((parray[p1].adminLevel >= 10) && (parray[p1].i_admin))
    strcat(ptmp, "(*)");
  if (in_list(p1, L_COMPUTER, parray[p1].name))
    strcat(ptmp, "(C)");
  if (in_list(p1, L_FM, parray[p1].name))
    strcat(ptmp, "(FM)");
  if (in_list(p1, L_IM, parray[p1].name))
    strcat(ptmp, "(IM)");
  if (in_list(p1, L_GM, parray[p1].name))
    strcat(ptmp, "(GM)");
  if (in_list(p1, L_TD, parray[p1].name))
    strcat(ptmp, "(TD)");
  if (in_list(p1, L_TEAMS, parray[p1].name))
    strcat(ptmp, "(T)");
  if (in_list(p1, L_BLIND, parray[p1].name))
    strcat(ptmp, "(B)");
}

PRIVATE void who_terse(int p, int num, int *plist, int type)
{
  char ptmp[80 + 20];		/* for highlight */
  multicol *m = multicol_start(PARRAY_SIZE);
  int i;
  int p1;
  int rat;

  /* altered DAV 3/15/95 */

  for (i = 0; i < num; i++) {
    p1 = plist[i];

    if (type == blitz_rat)
      rat = parray[p1].b_stats.rating;
    else if (type == wild_rat)
      rat = parray[p1].w_stats.rating;
    else if (type == std_rat)
      rat = parray[p1].s_stats.rating;
    else if (type == light_rat)
      rat = parray[p1].l_stats.rating;

    if (type == none) {
      sprintf(ptmp, "     ");
    } else {
      sprintf(ptmp, "%-4s", ratstrii(rat, parray[p1].registered));
      if (parray[p1].simul_info.numBoards) {
	strcat(ptmp, "~");
      } else if ((parray[p1].game >= 0) && (garray[parray[p1].game].status == GAME_EXAMINE)) {
        strcat(ptmp, "#");
      } else if (parray[p1].game >= 0) {
	strcat(ptmp, "^");
      } else if (!parray[p1].open) {
	strcat(ptmp, ":");
      } else if (player_idle(p1) > 300) {
	strcat(ptmp, ".");
      } else {
	strcat(ptmp, " ");
      }
    }

    if (p == p1) {
      psprintf_highlight(p, ptmp + strlen(ptmp), "%s", parray[p1].name);
    } else {
      strcat(ptmp, parray[p1].name);
    }

    AddPlayerLists(p1, ptmp);
    multicol_store(m, ptmp);
  }
  multicol_pprint(m, p, 80, 2);
  multicol_end(m);
  pprintf(p, "\n %d players displayed (of %d). (*) indicates system administrator.\n", num, player_count(1));
}

PRIVATE void
who_verbose(int p, int num, int plist[])
{
	char	 p1WithAttrs[255];
	char	 playerLine[255];
	char	 tmp[255];
	int	 p1;
	int	 ret, too_long;

	pprintf(p, " +---------------------------------------------------------------+\n");
	pprintf(p, " |      User              Standard    Blitz        On for   Idle |\n");
	pprintf(p, " +---------------------------------------------------------------+\n");

	for (int i = 0; i < num; i++) {
		p1 = plist[i];
		strcpy(playerLine, " |");

		if (parray[p1].game >= 0)
			sprintf(tmp, "%3d", parray[p1].game + 1);
		else
			sprintf(tmp, "   ");

		strcat(playerLine, tmp);

		if (!parray[p1].open)
			sprintf(tmp, "X");
		else
			sprintf(tmp, " ");

		strcat(playerLine, tmp);

		if (parray[p1].registered) {
			if (parray[p1].rated)
				sprintf(tmp, " ");
			else
				sprintf(tmp, "u");
		} else {
			sprintf(tmp, "U");
		}

		strcat(playerLine, tmp);
		strcpy(p1WithAttrs, parray[p1].name);
		AddPlayerLists(p1, p1WithAttrs);
		p1WithAttrs[17] = '\0';

		if (p == p1) {
			strcpy(tmp, " ");
			psprintf_highlight(p, tmp + strlen(tmp), "%-17s",
			    p1WithAttrs);
		} else {
			ret = snprintf(tmp, sizeof tmp, " %-17s", p1WithAttrs);
			too_long = (ret < 0 || (size_t)ret >= sizeof tmp);
			if (too_long) {
				fprintf(stderr, "FICS: %s: warning: "
				    "snprintf truncated\n", __func__);
			}
		}

		strcat(playerLine, tmp);
		sprintf(tmp, " %4s        %-4s        %5s  ",
		    ratstrii(parray[p1].s_stats.rating,
		    parray[p1].registered),
		    ratstrii(parray[p1].b_stats.rating,
		    parray[p1].registered),
		    hms(player_ontime(p1), 0, 0, 0));
		strcat(playerLine, tmp);

		if (player_idle(p1) >= 60) {
			sprintf(tmp, "%5s   |\n",
			    hms(player_idle(p1), 0, 0, 0));
		} else {
			sprintf(tmp, "        |\n");
		}

		strcat(playerLine, tmp);
		pprintf(p, "%s", playerLine);
	}

	pprintf(p, " |                                                               |\n");
	pprintf(p, " |    %3d Players Displayed                                      |\n", num);
	pprintf(p, " +---------------------------------------------------------------+\n");
}

PRIVATE void who_winloss(p, num, plist)
int p;
int num;
int plist[];
{
  int i, p1;
  char playerLine[255], tmp[255];	/* for highlight */
  char p1WithAttrs[255];

  pprintf(p,
	  "Name               Stand     win loss draw   Blitz    win loss draw    idle\n"
    );
  pprintf(p,
	  "----------------   -----     -------------   -----    -------------    ----\n"
    );

  for (i = 0; i < num; i++) {
    playerLine[0] = '\0';
    p1 = plist[i];

    /* Modified by hersco to include lists in 'who n.' */
    strcpy (p1WithAttrs, parray[p1].name);
    AddPlayerLists(p1, p1WithAttrs);
    p1WithAttrs[17] = '\0';

    if (p1 == p) {
      psprintf_highlight(p, playerLine, "%-17s", p1WithAttrs);
    } else {
      sprintf(playerLine, "%-17s", p1WithAttrs);
    }
    sprintf(tmp, "  %4s     %4d %4d %4d   ",
	    ratstrii(parray[p1].s_stats.rating, parray[p1].registered),
	    (int) parray[p1].s_stats.win,
	    (int) parray[p1].s_stats.los,
	    (int) parray[p1].s_stats.dra);
    strcat(playerLine, tmp);

    sprintf(tmp, "%4s    %4d %4d %4d   ",
	    ratstrii(parray[p1].b_stats.rating, parray[p1].registered),
	    (int) parray[p1].b_stats.win,
	    (int) parray[p1].b_stats.los,
	    (int) parray[p1].b_stats.dra);
    strcat(playerLine, tmp);

    if (player_idle(p1) >= 60) {
      sprintf(tmp, "%5s\n", hms(player_idle(p1), 0, 0, 0));
    } else {
      sprintf(tmp, "     \n");
    }
    strcat(playerLine, tmp);

    pprintf(p, "%s", playerLine);
  }
  pprintf(p, "    %3d Players Displayed.\n", num);
}

PRIVATE int who_ok(int p, unsigned int sel_bits)
{
  int p2;
  if (parray[p].status != PLAYER_PROMPT)
    return 0;
  if (sel_bits == WHO_ALL)
    return 1;
  if (sel_bits & WHO_OPEN)
    if (!parray[p].open)
      return 0;
  if (sel_bits & WHO_CLOSED)
    if (parray[p].open)
      return 0;
  if (sel_bits & WHO_RATED)
    if (!parray[p].rated)
      return 0;
  if (sel_bits & WHO_UNRATED)
    if (parray[p].rated)
      return 0;
  if (sel_bits & WHO_FREE)
    if (parray[p].game >= 0)
      return 0;
  if (sel_bits & WHO_PLAYING)
    if (parray[p].game < 0)
      return 0;
  if (sel_bits & WHO_REGISTERED)
    if (!parray[p].registered)
      return 0;
  if (sel_bits & WHO_UNREGISTERED)
    if (parray[p].registered)
      return 0;
  if (sel_bits & WHO_BUGTEAM) {
    p2 = parray[p].partner;
    if (p2 < 0 || parray[p2].partner != p)
      return 0;
    }
  return 1;
}


PRIVATE int blitz_cmp(const void *pp1, const void *pp2)
{
  register int p1 = *(int *) pp1;
  register int p2 = *(int *) pp2;
  if (parray[p1].status != PLAYER_PROMPT) {
    if (parray[p2].status != PLAYER_PROMPT)
      return 0;
    else
      return -1;
  }
  if (parray[p2].status != PLAYER_PROMPT)
    return 1;
  if (parray[p1].b_stats.rating > parray[p2].b_stats.rating)
    return -1;
  if (parray[p1].b_stats.rating < parray[p2].b_stats.rating)
    return 1;
  if (parray[p1].registered > parray[p2].registered)
    return -1;
  if (parray[p1].registered < parray[p2].registered)
    return 1;
  return strcmp(parray[p1].login, parray[p2].login);
}

PRIVATE int light_cmp(const void *pp1, const void *pp2)
{
  register int p1 = *(int *) pp1;
  register int p2 = *(int *) pp2;
  if (parray[p1].status != PLAYER_PROMPT) {
    if (parray[p2].status != PLAYER_PROMPT)
      return 0;
    else
      return -1;
  }
  if (parray[p2].status != PLAYER_PROMPT)
    return 1;
  if (parray[p1].l_stats.rating > parray[p2].l_stats.rating)
    return -1;
  if (parray[p1].l_stats.rating < parray[p2].l_stats.rating)
    return 1;
  if (parray[p1].registered > parray[p2].registered)
    return -1;
  if (parray[p1].registered < parray[p2].registered)
    return 1;
  return strcmp(parray[p1].login, parray[p2].login);
}

PRIVATE int stand_cmp(const void *pp1, const void *pp2)
{
  register int p1 = *(int *) pp1;
  register int p2 = *(int *) pp2;
  if (parray[p1].status != PLAYER_PROMPT) {
    if (parray[p2].status != PLAYER_PROMPT)
      return 0;
    else
      return -1;
  }
  if (parray[p2].status != PLAYER_PROMPT)
    return 1;
  if (parray[p1].s_stats.rating > parray[p2].s_stats.rating)
    return -1;
  if (parray[p1].s_stats.rating < parray[p2].s_stats.rating)
    return 1;
  if (parray[p1].registered > parray[p2].registered)
    return -1;
  if (parray[p1].registered < parray[p2].registered)
    return 1;
  return strcmp(parray[p1].login, parray[p2].login);
}

PRIVATE int wild_cmp(const void *pp1, const void *pp2)
{
  register int p1 = *(int *) pp1;
  register int p2 = *(int *) pp2;
  if (parray[p1].status != PLAYER_PROMPT) {
    if (parray[p2].status != PLAYER_PROMPT)
      return 0;
    else
      return -1;
  }
  if (parray[p2].status != PLAYER_PROMPT)
    return 1;
  if (parray[p1].w_stats.rating > parray[p2].w_stats.rating)
    return -1;
  if (parray[p1].w_stats.rating < parray[p2].w_stats.rating)
    return 1;
  if (parray[p1].registered > parray[p2].registered)
    return -1;
  if (parray[p1].registered < parray[p2].registered)
    return 1;
  return strcmp(parray[p1].login, parray[p2].login);
}

PRIVATE int alpha_cmp(const void *pp1, const void *pp2)
{
  register int p1 = *(int *) pp1;
  register int p2 = *(int *) pp2;
  if (parray[p1].status != PLAYER_PROMPT) {
    if (parray[p2].status != PLAYER_PROMPT)
      return 0;
    else
      return -1;
  }
  if (parray[p2].status != PLAYER_PROMPT)
    return 1;
  return strcmp(parray[p1].login, parray[p2].login);
}

PUBLIC void sort_players(int players[PARRAY_SIZE],
			  int ((*cmp_func) (const void *, const void *)))
{
  int i;

  for (i = 0; i < p_num; i++) {
    players[i] = i;
  }
  qsort(players, p_num, sizeof(int), cmp_func);
}

/* This is the of the most compliclicated commands in terms of parameters */
PUBLIC int com_who(int p, param_list param)
{
  int style = 0;
  float stop_perc = 1.0;
  float start_perc = 0;
  unsigned int sel_bits = WHO_ALL;
  int sortlist[PARRAY_SIZE], plist[PARRAY_SIZE];
  int ((*cmp_func) (const void *, const void *)) = blitz_cmp;
  int startpoint;
  int stoppoint;
  int i, len;
  int tmpI, tmpJ;
  char c;
  int p1, count, num_who;
  int sort_type = blitz_rat;

  if (param[0].type != TYPE_NULL) {
    len = strlen(param[0].val.string);
    for (i = 0; i < len; i++) {
      c = param[0].val.string[i];
      if (isdigit(c)) {
	if (i == 0 || !isdigit(param[0].val.string[i - 1])) {
	  tmpI = c - '0';
	  if (tmpI == 1) {
	    start_perc = 0.0;
	    stop_perc = 0.333333;
	  } else if (tmpI == 2) {
	    start_perc = 0.333333;
	    stop_perc = 0.6666667;
	  } else if (tmpI == 3) {
	    start_perc = 0.6666667;
	    stop_perc = 1.0;
	  } else if ((i == len - 1) || (!isdigit(param[0].val.string[i + 1])))
	    return COM_BADPARAMETERS;
	} else {
	  tmpI = c - '0';
	  tmpJ = param[0].val.string[i - 1] - '0';
	  if (tmpI == 0)
	    return COM_BADPARAMETERS;
	  if (tmpJ > tmpI)
	    return COM_BADPARAMETERS;
	  start_perc = ((float) tmpJ - 1.0) / (float) tmpI;
	  stop_perc = ((float) tmpJ) / (float) tmpI;
	}
      } else {
	switch (c) {
        case ' ':
        case '\n':
        case '\t':
          break;
	case 'o':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_OPEN;
	  else
	    sel_bits |= WHO_OPEN;
	  break;
	case 'r':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_RATED;
	  else
	    sel_bits |= WHO_RATED;
	  break;
	case 'f':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_FREE;
	  else
	    sel_bits |= WHO_FREE;
	  break;
	case 'a':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_FREE | WHO_OPEN;
	  else
	    sel_bits |= (WHO_FREE | WHO_OPEN);
	  break;
	case 'R':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_REGISTERED;
	  else
	    sel_bits |= WHO_REGISTERED;
	  break;
	case 'l':		/* Sort order */
	  cmp_func = alpha_cmp;
	  sort_type = none;
	  break;
	case 'A':		/* Sort order */
	  cmp_func = alpha_cmp;
	  break;
	case 'w':		/* Sort order */
	  cmp_func = wild_cmp;
	  sort_type = wild_rat;
	  break;
	case 's':		/* Sort order */
	  cmp_func = stand_cmp;
	  sort_type = std_rat;
	  break;
	case 'b':		/* Sort order */
	  cmp_func = blitz_cmp;
	  sort_type = blitz_rat;
	  break;
        case 'L':               /* Sort order */
          cmp_func = light_cmp;
          sort_type = light_rat;
          break;
	case 't':		/* format */
	  style = 0;
	  break;
	case 'v':		/* format */
	  style = 1;
	  break;
	case 'n':		/* format */
	  style = 2;
	  break;
	case 'U':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_UNREGISTERED;
	  else
	    sel_bits |= WHO_UNREGISTERED;
	  break;
	case 'B':
	  if (sel_bits == WHO_ALL)
	    sel_bits = WHO_BUGTEAM;
	  else
	    sel_bits |= WHO_BUGTEAM;
	  break;
	default:
	  return COM_BADPARAMETERS;
	  break;
	}
      }
    }
  }
  sort_players(sortlist, cmp_func);
  count = 0;
  for (p1 = 0; p1 < p_num; p1++) {
    if (!who_ok(sortlist[p1], sel_bits))
      continue;
    count++;
  }
  startpoint = floor((float) count * start_perc);
  stoppoint = ceil((float) count * stop_perc) - 1;
  num_who = 0;
  count = 0;
  for (p1 = 0; p1 < p_num; p1++) {
    if (!who_ok(sortlist[p1], sel_bits))
      continue;
    if ((count >= startpoint) && (count <= stoppoint)) {
      plist[num_who++] = sortlist[p1];
    }
    count++;
  }

  if (num_who == 0) {
    pprintf(p, "No logged in players match the flags in your who request.\n");
    return COM_OK;
  }

  switch (style) {
  case 0:			/* terse */
    who_terse(p, num_who, plist, sort_type);
    break;
  case 1:			/* verbose */
    who_verbose(p, num_who, plist);
    break;
  case 2:			/* win-loss */
    who_winloss(p, num_who, plist);
    break;
  default:
    return COM_BADPARAMETERS;
    break;
  }

  return COM_OK;
}

PUBLIC int com_refresh(int p, param_list param)
{
  int g, p1;

  if (param[0].type == TYPE_NULL) {
    if (parray[p].game >= 0) {
      send_board_to(parray[p].game, p);
    } else {			/* Do observing in here */
      if (parray[p].num_observe) {
	for (g = 0; g < parray[p].num_observe; g++) {
	  send_board_to(parray[p].observe_list[g], p);
	}
      } else {
        pprintf(p, "You are neither playing, observing nor examining a game.\n");
        return COM_OK;
      }
    }
  } else {
    g = GameNumFromParam (p, &p1, &param[0]);
    if (g < 0)
      return COM_OK;
    if ((g >= g_num) || ((garray[g].status != GAME_ACTIVE)
                        && (garray[g].status != GAME_EXAMINE))) {
      pprintf(p, "No such game.\n");
    } else if (garray[g].private && parray[p].adminLevel==ADMIN_USER) {
      pprintf (p, "Sorry, game %d is a private game.\n", g+1);
    } else {
      if (garray[g].private)
        pprintf(p, "Refreshing PRIVATE game %d\n", g+1);
      send_board_to(g, p);
    }
  }
  return COM_OK;
}

PUBLIC int com_prefresh(int p, param_list param)
{
  int retval, part = parray[p].partner;

  if (part < 0) {
    pprintf(p, "You do not have a partner.\n");
    return COM_OK;
  }
  retval = pcommand (p, "refresh %s", parray[part].name);
  if (retval == COM_OK)
    return COM_OK_NOPROMPT;
  else
    return retval;
}

PUBLIC int com_open(int p, param_list param)
{
  int retval;
  ASSERT(param[0].type == TYPE_NULL);
  if ((retval = pcommand(p, "set open")) != COM_OK)
    return retval;
  else
    return COM_OK_NOPROMPT;
}

PUBLIC int com_simopen(int p, param_list param)
{
  int retval;
  ASSERT(param[0].type == TYPE_NULL);
  if ((retval = pcommand(p, "set simopen")) != COM_OK)
    return retval;
  else
    return COM_OK_NOPROMPT;
}

PUBLIC int com_bell(int p, param_list param)
{
  int retval;
  ASSERT(param[0].type == TYPE_NULL);
  if ((retval = pcommand(p, "set bell")) != COM_OK)
    return retval;
  else
    return COM_OK_NOPROMPT;
}

PUBLIC int com_flip(int p, param_list param)
{
  int retval;
  ASSERT(param[0].type == TYPE_NULL);
  if ((retval = pcommand(p, "set flip")) != COM_OK)
    return retval;
  else
    return COM_OK_NOPROMPT;
}

PUBLIC int com_highlight(int p, param_list param)
{
  pprintf(p, "Obsolete command. Please do set highlight <0-15>.\n");
  return COM_OK;
}

PUBLIC int com_style(int p, param_list param)
{
  int retval;
  ASSERT(param[0].type == TYPE_INT);
  if ((retval = pcommand(p, "set style %d", param[0].val.integer)) != COM_OK)
    return retval;
  else
    return COM_OK_NOPROMPT;
}

PUBLIC int com_promote(int p, param_list param)
{
  int retval;
  ASSERT(param[0].type == TYPE_WORD);
  if ((retval = pcommand(p, "set promote %s", param[0].val.word)) != COM_OK)
    return retval;
  else
    return COM_OK_NOPROMPT;
}

PUBLIC int com_alias(int p, param_list param)
{
  int al;

  if (param[0].type == TYPE_NULL) {
    for (al = 0; al < parray[p].numAlias; al++) {
      pprintf(p, "%s -> %s\n", parray[p].alias_list[al].comm_name,
	      parray[p].alias_list[al].alias);
    }
    return COM_OK;
  }
  al = alias_lookup(param[0].val.word, parray[p].alias_list, parray[p].numAlias);
  if (param[1].type == TYPE_NULL) {
    if (al < 0) {
      pprintf(p, "You have no alias named '%s'.\n", param[0].val.word);
    } else {
      pprintf(p, "%s -> %s\n", parray[p].alias_list[al].comm_name,
	      parray[p].alias_list[al].alias);
    }
  } else {
    if (al < 0) {
      if (parray[p].numAlias >= MAX_ALIASES - 1) {
	pprintf(p, "You have your maximum of %d aliases.\n", MAX_ALIASES - 1);
      } else {

	if (!strcmp(param[0].val.string, "quit")) {	/* making sure they
							   can't alias quit */
	  pprintf(p, "You can't alias this command.\n");
	} else if (!strcmp(param[0].val.string, "unalias")) {	/* making sure they
								   can't alias unalias
								   :) */
	  pprintf(p, "You can't alias this command.\n");
	} else {
	  parray[p].alias_list[parray[p].numAlias].comm_name =
	    xstrdup(param[0].val.word);
	  parray[p].alias_list[parray[p].numAlias].alias =
	    xstrdup(param[1].val.string);
	  parray[p].numAlias++;
	  pprintf(p, "Alias set.\n");

	}
      }
    } else {
      rfree(parray[p].alias_list[al].alias);
      parray[p].alias_list[al].alias = xstrdup(param[1].val.string);
      pprintf(p, "Alias replaced.\n");
    }
    parray[p].alias_list[parray[p].numAlias].comm_name = NULL;
  }
  return COM_OK;
}

PUBLIC int com_unalias(int p, param_list param)
{
  int al;
  int i;

  ASSERT(param[0].type == TYPE_WORD);
  al = alias_lookup(param[0].val.word, parray[p].alias_list, parray[p].numAlias);
  if (al < 0) {
    pprintf(p, "You have no alias named '%s'.\n", param[0].val.word);
  } else {
    rfree(parray[p].alias_list[al].comm_name);
    rfree(parray[p].alias_list[al].alias);
    for (i = al; i < parray[p].numAlias; i++) {
      parray[p].alias_list[i].comm_name = parray[p].alias_list[i + 1].comm_name;
      parray[p].alias_list[i].alias = parray[p].alias_list[i + 1].alias;
    }
    parray[p].numAlias--;
    parray[p].alias_list[parray[p].numAlias].comm_name = NULL;
    pprintf(p, "Alias removed.\n");
  }
  return COM_OK;
}

PUBLIC int com_servers(int p, param_list param)
{
/*
  int i;

  ASSERT(param[0].type == TYPE_NULL);
  if (numServers == 0) {
         */ pprintf(p, "There are no other servers known to this server.\n");
  return COM_OK;
}
 /* pprintf(p, "There are %d known servers.\n", numServers); pprintf(p, "(Not
    all of these may be active)\n"); pprintf(p, "%-30s%-7s\n", "HOST",
    "PORT"); for (i = 0; i < numServers; i++) pprintf(p, "%-30s%-7d\n",
    serverNames[i], serverPorts[i]); return COM_OK; } */

PUBLIC int com_index(int p, param_list param)
{
  int i;
  char index_default[] = "_index";
  char *iwant, *filenames[100];	/* enough for all index filenames */

  if (param[0].type == TYPE_NULL) {
    iwant = index_default;
  } else {
    iwant = param[0].val.word;
    if (!safestring(iwant)) {
      pprintf(p, "Illegal character in category %s.\n", iwant);
      return COM_OK;
    }
  }

  i = search_directory(index_dir, iwant, filenames, 1000);
  if (i == 0) {
    pprintf(p, "No index entry for \"%s\".\n", iwant);
  } else if ((i == 1) || !strcmp(*filenames, iwant)) {
    if (psend_file(p, index_dir, *filenames)) {
      /* we should never reach this unless the file was just deleted */
      pprintf(p, "Index file %s could not be found! ", *filenames);
      pprintf(p, "Please inform an admin of this. Thank you.\n");
    }
  } else {
    pprintf(p, "Matches:");
    display_directory(p, filenames, i);
  }
  return COM_OK;
}

PUBLIC int com_help(int p, param_list param)
{
  int i, UseLang = parray[p].language;
  char help_default[] = "_help";
  char *iwant, *filenames[1000];	/* enough for all helpfile names */

  if (param[0].type == TYPE_NULL) {
    iwant = help_default;
  } else {
    iwant = param[0].val.word;
    if (!safestring(iwant)) {
      pprintf(p, "Illegal character in command %s.\n", iwant);
      return COM_OK;
    }
  }
  i = search_directory(help_dir[UseLang], iwant, filenames, 1000);
  if (i == 0) {
    if (UseLang != LANG_DEFAULT) {
      i += search_directory(help_dir[LANG_DEFAULT], iwant, filenames, 1000);
      if (i > 0) {
        pprintf(p, "No help available in %s; using %s instead.\n",
                Language(UseLang), Language(LANG_DEFAULT));
        UseLang = LANG_DEFAULT;
      }
    }
    if (i==0) {
      pprintf(p, "No help available on \"%s\".\n", iwant);
      return COM_OK;
    }
  }
  if ((i == 1) || !strcmp(*filenames, iwant)) {
    if (psend_file(p, help_dir[UseLang], *filenames)) {
      /* we should never reach this unless the file was just deleted */
      pprintf(p, "Helpfile %s could not be found! ", *filenames);
      pprintf(p, "Please inform an admin of this. Thank you.\n");
    }
  } else {
    pprintf(p, "Matches:");
    display_directory(p, filenames, i);
    pprintf(p, "[Type \"info\" for a list of FICS general information files.]\n");
  }
  return COM_OK;
}

PUBLIC int com_info(int p, param_list param)
{
  int n;
  char *filenames[1000];

  if ((n = search_directory(info_dir, NULL, filenames, 1000)) > 0)
    display_directory(p, filenames, n);
  return COM_OK;
}

PRIVATE int FindAndShowFile(int p, param_list param, char *dir)
{
  int i;
  static char nullify = '\0';
  char *iwant, *filenames[1000];	/* enough for all helpfile names */

  if (param[0].type == TYPE_NULL) {
    iwant = &nullify;
  } else {
    iwant = param[0].val.word;
    if (!safestring(iwant)) {
      pprintf(p, "Illegal character in filename %s.\n", iwant);
      return COM_OK;
    }
  }

  i = search_directory(dir, iwant, filenames, 1000);
  if (i == 0) {
    pprintf(p, "No information available on \"%s\".\n", iwant);
  } else if ((i == 1) || !strcmp(*filenames, iwant)) {
    if (psend_file(p, dir, *filenames)) {
      /* we should never reach this unless the file was just deleted */
      pprintf(p, "File %s could not be found! ", *filenames);
      pprintf(p, "Please inform an admin of this. Thank you.\n");
    }
  } else {
    if (*iwant)
      pprintf(p, "Matches:\n");
    display_directory(p, filenames, i);
  }
  return COM_OK;
}

PUBLIC int com_uscf(int p, param_list param)
{
  return FindAndShowFile (p, param, uscf_dir);
}

PUBLIC int com_adhelp(int p, param_list param)
{
  return FindAndShowFile (p, param, adhelp_dir);
}

PUBLIC int
com_mailsource(int p, param_list param)
{
	char		*buffer[1000];
	char		*iwant;
	char		 fname[MAX_FILENAME_SIZE];
	char		 subj[120];
	int		 count;
	static char	 nullify = '\0';

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

	if (param[0].type == TYPE_NULL)
		iwant = &nullify;
	else
		iwant = param[0].val.word;

	if ((count = search_directory(source_dir, iwant, buffer, 1000)) == 0) {
		pprintf(p, "Found no source file matching \"%s\".\n", iwant);
	} else if ((count == 1) || !strcmp(iwant, *buffer)) {
		snprintf(subj, sizeof subj, "FICS source file from server "
		    "%s: %s",
		    fics_hostname,
		    *buffer);
		snprintf(fname, sizeof fname, "%s/%s",
		    source_dir,
		    *buffer);

		mail_file_to_user(p, subj, fname);

		pprintf(p, "Source file %s sent to %s\n", *buffer,
		    parray[p].emailAddress);
	} else {
		pprintf(p, "Found %d source files matching that:\n", count);

		if (*iwant) {
			display_directory(p, buffer, count);
		} else { // this junk is to get *.c *.h
			char		*s;
			multicol	*m = multicol_start(count);

			for (int i = 0; i < count; i++) {
				s = (buffer[i] + strlen(buffer[i]) - 2);

				if (s >= buffer[i] &&
				    (!strcmp(s, ".c") || !strcmp(s, ".h")))
					multicol_store(m, buffer[i]);
			}

			multicol_pprint(m, p, 78, 1);
			multicol_end(m);
		}
	}

	return COM_OK;
}

PUBLIC int
com_mailhelp(int p, param_list param)
{
	char		*buffer[1000];
	char		*iwant;
	char		 fname[MAX_FILENAME_SIZE];
	char		 subj[120];
	int		 count;
	int		 lang = parray[p].language;
	static char	 nullify = '\0';

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

	if (param[0].type == TYPE_NULL)
		iwant = &nullify;
	else
		iwant = param[0].val.word;

	count = search_directory(help_dir[lang], iwant, buffer, 1000);

	if (count == 0 && lang != LANG_DEFAULT) {
		count += search_directory(help_dir[LANG_DEFAULT], iwant, buffer,
		    1000);

		if (count > 0) {
			pprintf(p, "No help available in %s; "
			    "using %s instead.\n",
			    Language(lang),
			    Language(LANG_DEFAULT));
			lang = LANG_DEFAULT;
		}
	}

	if (count == 0) {
		pprintf(p, "Found no help file matching \"%s\".\n", iwant);
	} else if (count == 1 || !strcmp(*buffer, iwant)) {
		snprintf(subj, sizeof subj, "FICS help file from server %s: %s",
		    fics_hostname,
		    *buffer);
		snprintf(fname, sizeof fname, "%s/%s",
		    help_dir[lang],
		    *buffer);

		mail_file_to_user(p, subj, fname);

		pprintf(p, "Help file %s sent to %s\n", *buffer,
		    parray[p].emailAddress);
	} else {
		pprintf(p, "Found %d helpfiles matching that:\n", count);
		display_directory(p, buffer, count);
	}

	return COM_OK;
}

PUBLIC int com_handles(int p, param_list param)
{
  char *buffer[1000];
  char pdir[MAX_FILENAME_SIZE];
  int count;

  sprintf(pdir, "%s/%c", player_dir, param[0].val.word[0]);
  count = search_directory(pdir, param[0].val.word, buffer, 1000);
  pprintf(p, "Found %d names.\n", count);
  if (count > 0)
    display_directory(p, buffer, count);
  return COM_OK;
}

PUBLIC int com_getpi(int p, param_list param)
{
  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;
  }
  if (((p1 = player_find_bylogin(param[0].val.word)) < 0) || (parray[p1].registered == 0)) {
    /* Darkside suggested not to return anything */
    return COM_OK;
  }
  if (!parray[p1].registered) {
    pprintf(p, "*getpi %s -1 -1 -1*\n", parray[p1].name);
  } else {
    pprintf(p, "*getpi %s %d %d %d*\n", parray[p1].name,
	    parray[p1].w_stats.rating,
	    parray[p1].b_stats.rating,
	    parray[p1].s_stats.rating);
  }
  return COM_OK;
}

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

  if ((((p1 = player_find_bylogin(param[0].val.word)) < 0) || (parray[p1].registered == 0)) || (parray[p1].game < 0)) {

    pprintf(p, "*status %s 1*\n", param[0].val.word);
    return COM_OK;
  }
  pprintf(p, "*status %s 0 %s*\n", parray[p1].name, parray[(parray[p1].opponent)].name);
  return COM_OK;
}
PUBLIC int com_limits(int p, param_list param)
{
  pprintf(p, "\nCurrent hardcoded limits:\n");
  pprintf(p, "  Max number of players: %d\n", MAX_PLAYER);
  pprintf(p, "  Max number of channels and max capacity: %d\n", MAX_CHANNELS);
  pprintf(p, "  Max number of channels one can be in: %d\n", MAX_INCHANNELS);
  pprintf(p, "  Max number of people on the notify list: %d\n", MAX_NOTIFY);
  pprintf(p, "  Max number of aliases: %d\n", MAX_ALIASES - 1);
  pprintf(p, "  Max number of games you can observe at a time: %d\n", MAX_OBSERVE);
  pprintf(p, "  Max number of requests pending: %d\n", MAX_PENDING);
  pprintf(p, "  Max number of people on the censor list: %d\n", MAX_CENSOR);
  pprintf(p, "  Max number of people in a simul game: %d\n", MAX_SIMUL);
  pprintf(p, "  Max number of messages one can receive: %d\n", MAX_MESSAGES);
  pprintf(p, "  Min number of games to be active: %d\n", PROVISIONAL);
  if ((parray[p].adminLevel < ADMIN_ADMIN) && (!titled_player(p,parray[p].login))) {
    pprintf(p, "  Size of journal (entries): %d\n", MAX_JOURNAL);
  } else {
    pprintf(p, "  Size of journal (entries): 26\n");
  }
  pprintf(p, "\nAdmin settable limits:\n");
  pprintf(p, "  Shout quota gives two shouts per %d seconds.\n", quota_time);
  return COM_OK;
}