Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

procmsgs.c 51.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/******************************************************************************
PROCMSGS.C   Process all incoming TOP messages.

    Copyright 1993 - 2000 Paul J. Sidorsky

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

    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.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
Deucе's avatar
Deucе committed
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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

This module processes all incoming TOP messages from other node.  Most
messages are handled directly in the process_messages() function, which
accounts for its enormous size.  For a detailed list of the actual information
needed by each message, see MESSAGES.TXT.
******************************************************************************/

#include "top.h"

/* process_messages() - Process all incoming TOP messages.
   Parameters:  delname - TRUE to delete the name prompt, otherwise FALSE.
   Returns:  Number of incoming messages processed.
*/
XINT process_messages(char delname)
{
/* Loop counter, number of messages processed, number of messages used
   (displayed), action flag, result code, delname override. */
XINT d, proc = 0, mused = 0, isaction = 0, res, dn;
msg_typ msgin; /* Incoming message buffer. */
/* File name buffer, Temporary short string buffer (usually used for gender-
   specific data in actions), test byte holder. */
char filnam[256], ttt[10], tstbit[2];
unsigned char allowbits = 0; /* Action token allow bits. */
/* Temporary long number holder.  It is named cdc because it was originally
   used for CyberDollar values with the games before they were removed. */
unsigned long cdc;
/* Incoming message file data.  No longer used. */
/* struct ffblk mchg; */
char privchatflag = 0; /* Flag if we are entering private chat. */
/* Unused game variables. */
//|poker_game_typ mgame;
//|char pokcount = 0;
//|XINT pokstackgame[100];
/* Flag if we need to return to the main channel, type of ban/invite
   action. */
char rettomain = 0, baninv = 0;
/* Flag if the last message was used.  It is an int because the number of
   the last message used (relative to mused) is needed, but it amounts to a
   flag.  The sole purpose of this variable is to prevent extra newlines
   in dual-window mode, which turned out to be a very involving process. */
XINT lastmsgused;
char nointerflg = 0; /* Flag if the Interrupt string has been sent. */

/*//|for (d = 0; d < 100; d++)
    {
    pokstackgame[d] = -1;
    }*///|

/* Normal chat mode always needs the message prefix (which is what
   lastmsgused essentially regulates), but dual window mode does not use it
   on the first message to prevent double-spacing. */
lastmsgused = !(user.pref1 & PREF1_DUALWINDOW);
/* If the door kit sends a time message, it can't be sent as a TOP message
   during message processing or it would throw TOP into an infinite loop. */
blocktimemsgs = 1;

/* Scan our byte in the CHGIDX to see if we have new messages. */
lseek(chgfil, (od_control.od_node), SEEK_SET);
rec_locking(REC_LOCK, chgfil, (od_control.od_node), 1L);
read(chgfil, tstbit, 1L);
rec_locking(REC_UNLOCK, chgfil, (od_control.od_node), 1L);

/* If the byte was FALSE, we have no new messages. */
if (!tstbit[0])
	{
    blocktimemsgs = 0;
    return 0;
    }

/* Clear the CHGIDX byte immediately. */
tstbit[0] = 0;
lseek(chgfil, (od_control.od_node), SEEK_SET);
rec_locking(REC_LOCK, chgfil, (od_control.od_node), 1L);
write(chgfil, tstbit, 1L);
rec_locking(REC_UNLOCK, chgfil, (od_control.od_node), 1L);

if (user.pref1 & PREF1_DUALWINDOW)
    {
    /* In dual window mode, restore the last known position in the
       lower (incoming messages) window. */
    // Different for AVT when I find out what the store/recv codes are.
    od_disp_emu("\x1B" "[u", TRUE);
    top_output(OUT_SCREEN, getlang("DWOutputPrefix"));
    }

/* Loop for each message indexed by the MIX file, processing if needed. */
for (d = 0, dn = delname; d < filelength(midxinfil); d++)
	{
    /* Read the byte in the MIX file. */
    res = lseek(midxinfil, (long) d, SEEK_SET);
    if (res == -1)
    	{
        continue;
        }
    rec_locking(REC_LOCK, midxinfil, d, 1L);
    res = read(midxinfil, tstbit, 1L);
    if (res == -1)
    	{
	    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
        continue;
        }
	// This needs changing to a large, malloc()ed, buffered array to
    // improve speed
    if (!tstbit[0])
    	{
        /* If the byte is 0, ignore the message as it has been processed
           and is just leftover garbage. */
	    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
        continue;
        }

    /* Read the actual message. */
    res = lseek(msginfil, (long) d * (long) sizeof(msg_typ), SEEK_SET);
    if (res == -1)
    	{
	    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
        continue;
        }
    rec_locking(REC_LOCK, msginfil, (long) d * (long) sizeof(msg_typ),
    			(long) sizeof(msg_typ));
    res = read(msginfil, &msgin, sizeof(msg_typ));
    rec_locking(REC_UNLOCK, msginfil, (long) d * (long) sizeof(msg_typ),
    			(long) sizeof(msg_typ));
    if (res == -1)
    	{
	    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
        continue;
        }
    /* The byte in the MIX file stays locked so other nodes don't write
       a message in this spot before it's cleared. */

    if (msgin.channel != curchannel && msgin.channel != 0)
    	{
        /* Ignore the message if it isn't global and isn't on our channel. */
        tstbit[0] = 0;
        lseek(midxinfil, (long) d, SEEK_SET);
        write(midxinfil, tstbit, 1L);
	    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
        continue;
        }

    /* Do a little pre-processing preparation. */
    isaction = baninv = 0;
    fixname(msgin.handle, msgin.handle);

    /* At this time, some common steps in message processing will be
       explained so they do not have to be commented each time below.

       !(forgetstatus[msgin.from] & FGT_FORGOTTEN) tests to make sure the
           message isn't coming from someone that we've forgotten.  If it
           is, most messages won't be processed.  This has to be done for
           each message type because there are some messages that aren't
           to be ignored even if the user is forgotten.  These messages
           generally don't involve displaying anything on-screen.
       proc++ increases the number of messages processed, which includes
           ignored messages.
       mused++ increases the number of messages actually used, so it does
           not include ignored messages. */

    if (!dn && lastmsgused && (!forgetstatus[msgin.from] & FGT_FORGOTTEN))
    	{
        /* Essentially, if this is the first message to be shown and the
           user is using normal chat mode, a small string (usually ***) is
           sent to let the user know that their typing is being interrupted.
           This string is never sent if block while typing is on, but the
           test is included for completeness. */
        if (!(user.pref1 & PREF1_DUALWINDOW))
            {
            /* Only send the interrupt string if the user is in the process
               of typing something (onflag == TRUE). */
            if (!nointerflg && onflag && !(user.pref1 & PREF1_BLKWHILETYP))
                {
                top_output(OUT_SCREEN, getlang("Interrupt"));
                /* Don't send the interrupt string again. */
                nointerflg = 1;
                }
            }
        /* Send the message display prefix (usually just a newline). */
        top_output(OUT_SCREEN, getlang("MsgDisplayPrefix"));
        }

    /* The name prompt only has to be deleted once. */
    dn = 0;
    /* Many message types use a numeric value so it is obtained before
       processing begins. */
    cdc = strtoul(msgin.string, NULL, 10);

    /* The lastmsgused flag is figured from the mused total later on. */
    lastmsgused = mused;

    /* Process each type of message.  Most processing is straightforward
       (except for the common items covered above) so comments are kept
       to a minimum. */
	switch(msgin.type)
        {
        /* Normal text (talking). */
        case MSG_TEXT:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
            	{
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("MsgPrefix"), msgin.handle,
                           msgin.string);
                mused++;
                }
            proc++;
            break;
        /* A user has entered TOP. */
        case MSG_ENTRY:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                if (cfg.allowexmessages && msgin.string[0])
                    {
                    /* Send the user's entry message if they have one. */
                    top_output(OUT_SCREEN, getlang("EMsgPrefix"),
                               msgin.string);
                    }
                else
                    {
                    /* Send the default entry message. */
                    top_output(OUT_SCREEN, getlang("EMessage"), msgin.handle);
                    }
                mused++;
                }
            proc++;
            /* Add the new user to the active nodes index and reset the
               forget data for the user's node. */
            fixname(handles[msgin.from].string, msgin.handle);
            activenodes[msgin.from] = 1;
            forgetstatus[msgin.from] = 0;
            break;
        /* A user has left TOP normally (with the QUIT command). */
        case MSG_EXIT:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                if (cfg.allowexmessages && msgin.string[0])
                    {
                    /* Send the user's exit message if they have one. */
                    top_output(OUT_SCREEN, getlang("XMsgPrefix"),
                               msgin.string);
                    }
                else
                    {
                    /* Send the default exit message. */
                    top_output(OUT_SCREEN, getlang("XMessage"), msgin.handle);
                    }
                mused++;
                }
            /* Reset private chat variables if they involve the node that is
               leaving. */
            if (privchatin == msgin.from) privchatin = -1;
            if (privchatout == msgin.from) privchatout = -1;
            activenodes[msgin.from] = 0;
            forgetstatus[msgin.from] = 0;
            /* If we are currently in the personal channel of the user that
               is leaving, we must return to the main channel. */
            if (curchannel ==
                ((unsigned long) msgin.from + 4000000000UL))
                {
                top_output(OUT_SCREEN, getlang("NoLongerOnSystem"),
                           handles[msgin.from].string);
                rettomain = 1;
                }
            proc++;
            break;
        /* A user entered the profile editor. */
        case MSG_INEDITOR:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("InProf"), msgin.handle);
                mused++;
                }
            /* Reset private chat variables if they involve the node that is
               going in the editor. */
            if (privchatin == msgin.from) privchatin = -1;
            if (privchatout == msgin.from) privchatout = -1;
            proc++;
            break;
        /* A user has returned from the profile editor. */
        case MSG_OUTEDITOR:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("OutProf"), msgin.handle);
                mused++;
                }
            proc++;
            break;
        /* Private text, just to us. */
        case MSG_WHISPER:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("WhisperPrefix"), msgin.handle,
                           msgin.string);
                mused++;
                }
            proc++;
            break;
        /* General action. */
        case MSG_GA:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN) &&
                !(user.pref2 & PREF2_ACTIONSOFF))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("GAPrefix"), msgin.handle,
                           msgin.string);
                mused++;
                }
            proc++;
            break;
        /* Posessive general action (largely the same as a normal GA). */
        case MSG_GA2:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN) &&
                !(user.pref2 & PREF2_ACTIONSOFF))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("GA2Prefix"), msgin.handle,
                           msgin.string);
                mused++;
                }
            proc++;
            break;

        /* Actions are handled commonly at the end of the processing loop.
           For now, flag the message as being an action and determine the
           % tokens to allow based on type. */

        /* Singular action verb. */
        case MSG_ACTIONSIN:
            isaction = 1;
            allowbits = ALLOW_ME | ALLOW_SEX | ALLOW_SLF | ALLOW_HESHE;
            proc++;
            break;
        /* Plural action ("done to" somebody). */
        case MSG_ACTIONPLU:
            isaction = 1;
            allowbits = ALLOW_ME | ALLOW_YOU | ALLOW_SEX | ALLOW_POS |
                        ALLOW_SLF | ALLOW_HESHE;
            proc++;
            break;
        /* Singular talktype verb. */
        case MSG_TLKTYPSIN:
            isaction = 1;
            allowbits = ALLOW_ME | ALLOW_SEX | ALLOW_SLF | ALLOW_HESHE;
            proc++;
            break;
        /* Plural talktype (contains text). */
        case MSG_TLKTYPPLU:
            isaction = 1;
            allowbits = ALLOW_ME | ALLOW_SEX | ALLOW_SLF | ALLOW_HESHE;
            proc++;
            break;
        /* Secret (private) plural action that was done to us. */
        case MSG_ACTPLUSEC:
            isaction = 1;
            allowbits = ALLOW_ME | ALLOW_YOU | ALLOW_SEX | ALLOW_POS |
                        ALLOW_SLF | ALLOW_HESHE;
            proc++;
            break;
        /* A user has changed their TOP handle. */
        case MSG_HANDLECHG:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                if (msgin.gender == 0)
                    {
                    strcpy(ttt, getlang("His"));
                    }
                if (msgin.gender == 1)
                    {
                    strcpy(ttt, getlang("Her"));
                    }
                fixname(msgin.string, msgin.string);
                top_output(OUT_SCREEN, getlang("HandleChangeMsg"),
                           handles[msgin.from].string, ttt, msgin.string);
                mused++;
                }
            /* Update the handle in the main handle index. */
            fixname(handles[msgin.from].string, msgin.string);
            proc++;
            break;
        /* A user has changed their biography. */
        case MSG_BIOCHG:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                if (msgin.gender == 0)
                    {
                    strcpy(ttt, getlang("His"));
                    }
                if (msgin.gender == 1)
                    {
                    strcpy(ttt, getlang("Her"));
                    }
                mused++;
                top_output(OUT_SCREEN, getlang("BioChangeMsg"), msgin.handle,
                           ttt);
                }
            proc++;
            break;
        /* A user has changed genders. */
        case MSG_SEXCHG:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("SexChangeMsg"), msgin.handle,
                           msgin.string);
                mused++;
                }
            proc++;
            break;
        /* A user has changed their personal actions. */
        case MSG_PERACTCHG:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                if (msgin.gender == 0)
                    {
                    strcpy(ttt, getlang("His"));
                    }
                if (msgin.gender == 1)
                    {
                    strcpy(ttt, getlang("Her"));
                    }
                top_output(OUT_SCREEN, getlang("PersActChangeMsg"), msgin.handle, ttt);
                mused++;
                }
            proc++;
            break;
        /* A user left TOP abruptly (carrier drop, time expired, etc.) */
        case MSG_TOSSOUT:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("TossOut"), msgin.handle);
                mused++;
                }
            /* The same post-processing is done as for a normal exit. */
            activenodes[msgin.from] = 0;
            forgetstatus[msgin.from] = 0;
            if (curchannel ==
                ((unsigned long) msgin.from + 4000000000UL))
                {
                top_output(OUT_SCREEN, getlang("NoLongerOnSystem"),
                           handles[msgin.from].string);
                rettomain = 1;
                }
            proc++;
            break;
        /* A user has just "forgotten" us. */
        case MSG_FORGET:
            /* Note that we have been forgotten, so we can tell the user
               later if they try to do something to this user. */
            forgetstatus[msgin.from] |= FGT_HASFORGOTME;
            /* Reset private chat variables. */
            if (privchatin == msgin.from) privchatin = -1;
            if (privchatout == msgin.from) privchatout = -1;
            proc++;
            break;
        /* A user has just "remembered" us. */
        case MSG_REMEMBER:
            /* Note that we are no longer forgotten by resetting the
               HasForgotMe bit. */
            forgetstatus[msgin.from] &= (255 - FGT_HASFORGOTME);
            proc++;
            break;
        // these 3 probably need forget mods later on.
        
        /* Although TOP itself currently does not have link support, it may
           in the future, which is why the three link messages were put in.
           However, the external TOPLink utility does in fact use the link
           messages so they should be supported. */

        /* A link has just been established to another BBS. */
        case MSG_LINKUP:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("LinkOn"), msgin.handle, msgin.string);
            strcpy(handles[msgin.from].string, msgin.string);
            mused++;
            proc++;
            break;
        /* Text received from a linked BBS. */
        case MSG_LINKTEXT:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("LinkPrefix"), msgin.handle, msgin.string);
            mused++;
            proc++;
            break;
        /* The link to another BBS has been disconnected. */
        case MSG_UNLINK:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("LinkOff"), msgin.handle);
            strcpy(handles[msgin.from].string, msgin.string);
            activenodes[msgin.from] = 0;
            forgetstatus[msgin.from] = 0;
            mused++;
            proc++;
            break;
        /* A user has changed their entry or exit message. */
        case MSG_EXMSGCHG:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                if (msgin.gender == 0)
                    {
                    strcpy(ttt, getlang("His"));
                    }
                if (msgin.gender == 1)
                    {
                    strcpy(ttt, getlang("Her"));
                    }
                top_output(OUT_SCREEN, getlang("EXMsgChange"), msgin.handle, ttt);
                mused++;
                }
            proc++;
            break;
        /* A sysop just tossed us back to the BBS. */
        case MSG_TOSSED:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("HasTossed"), msgin.handle);
            if (msgin.string[0])
            	{
                top_output(OUT_SCREEN, getlang("TossComment"), msgin.string);
                }
            tstbit[0] = 0;
		    lseek(midxinfil, (long) d, SEEK_SET);
		    write(midxinfil, tstbit, 1L);
		    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
            od_exit(6, FALSE);
            /* Processing continues in case the exit fails. */
            proc++;
            mused++;
            break;
        /* A sysop disconnected us from TOP and the BBS. */
        case MSG_ZAPPED:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("HasZapped"), msgin.handle);
            if (msgin.string[0])
            	{
                top_output(OUT_SCREEN, getlang("TossComment"), msgin.string);
                }
            tstbit[0] = 0;
		    lseek(midxinfil, (long) d, SEEK_SET);
		    write(midxinfil, tstbit, 1L);
		    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
            od_exit(7, TRUE);
            /* Processing continues in case the exit fails. */
            proc++;
            mused++;
            break;
        /* A sysop has reset a crashed node. */
        case MSG_CLEARNODE:
            delprompt(delname);
            itoa(cdc, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("HasCleared"), outnum[0],
                       handles[(XINT) cdc].string, msgin.handle);
        	check_nodes_used(FALSE);
            mused++;
            proc++;
            break;
/* Sysop CyberCash transactions, not currently used. */
/*        case MSG_SYSGIVECD:
        	delprompt(delname);
            ultoa(cdc, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("CDGive"), msgin.handle, outnum[0],
                       cdc == 1 ? getlang("CDSingular") :
                                  getlang("CDPlural"));
            user.cybercash += cdc;
            save_user_data(user_rec_num, &user);
            mused++;
            proc++;
            break;
        case MSG_SYSTAKECD:
        	delprompt(delname);
            ultoa(cdc, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("CDTake"), msgin.handle, outnum[0],
                       cdc == 1 ? getlang("CDSingular") :
                                  getlang("CDPlural"));
            user.cybercash -= cdc;
            save_user_data(user_rec_num, &user);
            mused++;
            proc++;
            break;
        case MSG_SYSSETCD:
        	delprompt(delname);
            ultoa(cdc, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("CDSet"), msgin.handle, outnum[0]);
            user.cybercash = cdc;
            save_user_data(user_rec_num, &user);
            mused++;
            proc++;
            break;*///!
/* A poker game message, currently unused. */
/*//|        case MSG_POKER:
            poker_core(msgin.data1, msgin.string);
            if (msgextradata == 1)
            	{
                pokstackgame[pokcount++] = msgin.data1;
                }
        	if (stricmp(msgin.string, "GameOver") &&
                stricmp(msgin.string, "DoRescan"))
                {
                mused++;
                }
            proc++;
            break;*///|
        /* Generic text (usually system messages) to be displayed verbatim. */
        case MSG_GENERIC:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	            delprompt(delname);
                top_output(OUT_SCREEN, msgin.string);
        	    mused++;
                }
            proc++;
            break;
        /* A user has joined our current channel. */
        case MSG_INCHANNEL:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("ChannelIn"),
                           msgin.handle);
        	    mused++;
                }
            proc++;
            break;
        /* A user has left our current channel. */
        case MSG_OUTCHANNEL:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("ChannelOut"),
                           msgin.handle);
    	        mused++;
                }
            proc++;
            break;
        /* Crash protection has detected a stuck node. */
        case MSG_KILLCRASH:
            res = atoi(msgin.string);
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("CrashToss"),
                       msgin.string);
            /* Clear the node's variables so it does not remain visible. */
            activenodes[res] = 0;
            forgetstatus[res] = 0;
            mused++;
            proc++;
            break;
        /* Directed message (not necessarily to us). */
        case MSG_DIRECTED:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("DirectedPrefix"),
                		   handles[msgin.from].string,
                           msgin.doneto == od_control.od_node ?
						   getlang("You") : handles[msgin.doneto].string,
						   msgin.string);
                mused++;
                }
            proc++;
            break;
/* The sysop has edited the user on this node.  Not used. */
/*        case MSG_SYSUSEREDITED:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("SysopUserEdited"),
            		   msgin.string);
            load_user_data(user_rec_num, &user);
            mused++;
            proc++;
            break;*/
        /* The sysop has changed our security level. */
        case MSG_SYSSETSEC:
        	delprompt(delname);
            ultoa(cdc, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("SecChangeMsg"),
                       msgin.handle, outnum[0]);
            /* Update that security level in the user and NODEIDX files. */
            user.security = cdc;
            save_user_data(user_rec_num, &user);
            node->security = cdc;
            save_node_data(od_control.od_node, node);
            mused++;
            proc++;
            break;
        /* A user has entered private chat mode. */
        case MSG_INPRIVCHAT:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("PrivChatIn"),
                           msgin.handle);
                mused++;
                }
            proc++;
            break;
        /* A user has returned from private chat mode. */
        case MSG_OUTPRIVCHAT:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("PrivChatOut"),
                           msgin.handle);
                mused++;
                }
            proc++;
            break;
        /* A user is requesting a private chat with us. */
        case MSG_WANTSPRIVCHAT:
            if (privchatout >= 0 && msgin.from == privchatout)
                {
                /* If we have previously requested to chat with the other
                   user, enter private chat mode after processing is done. */
                privchatflag = 1;
                }
            /* The other user initiated the chat request. */
            if (privchatin < 0 && privchatout < 0)
                {
                privchatin = msgin.from;
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("PrivChatRequested"),
                           msgin.handle);
                }
            mused++;
            proc++;
            break;
        /* A user has denied this user's request for a private chat. */
        case MSG_DENYPRIVCHAT:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
	        	delprompt(delname);
                top_output(OUT_SCREEN, getlang("PrivChatDenied"),
                           msgin.handle);
                privchatout = -1;
                mused++;
                }
            proc++;
            break;
        /* A moderator has changed our current channel's topic. */
        case MSG_CHANTOPICCHG:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("TopicChangeMsg"),
                       handles[msgin.from].string, msgin.string);
            strcpy(cmibuf.topic, msgin.string);
            mused++;
            proc++;
            break;
        /* BAN, UNBAN, INVITE, and UNINVITE commands from a channel
           moderator, not necessarily done to us.  They are processed
           collectively later. */
        case MSG_CHANBANNED:
        case MSG_CHANUNBANNED:
        case MSG_CHANINVITED:
        case MSG_CHANUNINVITED:
            baninv = (msgin.type - MSG_CHANBANNED) + 1;
            mused++;
            proc++;
            break;
        /* Another user (which could be us) has been made the moderator
           of our current channel. */
        case MSG_CHANMODCHG:
            delprompt(delname);
            top_output(OUT_SCREEN, getlang("ModChangeMsg"),
                       handles[msgin.from].string,
                       msgin.doneto == od_control.od_node ?
                           getlang("You") : handles[msgin.doneto].string);
            cmibuf.modnode = msgin.doneto;
            mused++;
            proc++;
            break;
        /* Force an update of the active nodes index.  Not currently used
           by TOP or any known utility. */
        case MSG_FORCERESCAN:
            check_nodes_used(FALSE);
            proc++;
            break;
        /* A user has entered the biography editor. */
        case MSG_INBIOEDITOR:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("InBioEditor"),
                           msgin.handle);
                mused++;
                }
            if (privchatin == msgin.from) privchatin = -1;
            if (privchatout == msgin.from) privchatout = -1;
            proc++;
            break;
        /* A user has returned from the biography editor. */
        case MSG_OUTBIOEDITOR:
            if (!(forgetstatus[msgin.from] & FGT_FORGOTTEN))
                {
                delprompt(delname);
                top_output(OUT_SCREEN, getlang("OutBioEditor"),
                           msgin.handle);
                mused++;
                }
            proc++;
            break;
        }

    /* Handle incoming actions. */
    if (isaction && !(forgetstatus[msgin.from] & FGT_FORGOTTEN) &&
        !(user.pref2 & PREF2_ACTIONSOFF))
        {
        /* Action text buffer, pictorial action buffer, pictorial action
           extension buffer, final action text pointer, temporary character
           exchange holder. */
        char *tmp = NULL, *buf = NULL, texbuf[5], *str = NULL, xch;
        /* Counter, flag when a % is incountered, flag to process % tokens,
           flag if we're using a dynamic buffer, end of string marker. */
        XINT c, nxt = 0, proctokon = 1, dynam, tmark = 0;

        dynam = 0;
        /* Immediately determine if this is a pictorial action.  Pictorial
           actions require a different setup because of their larger size. */
        if (!strnicmp(msgin.string, "%P", 2))
            {
            FILE *fil = NULL; /* Pictorial action file stream. */

            /* Although it was omitted from the TOP docs, it is possible to
               specify a path along with a pictorial action file base name. */
            if (
#ifndef __unix__
				strchr(&msgin.string[2], ':') == NULL &&
#endif
                strchr(&msgin.string[2], PATH_DELIM) == NULL)
                {
                /* No path characters found, so assume the TOP ANSI Path. */
                sprintf(outbuf, "%s%s", cfg.topansipath, &msgin.string[2]);
                }
            else
                {
                /* Use the path as is. */
                strcpy(outbuf, &msgin.string[2]);
                }
            get_extension(outbuf, texbuf);
            strcat(outbuf, texbuf);

            /* Open the pictorial action file. */
            fil = fopen(outbuf, "rb");
            if (!fil)
                {
                // Err msg
                }
            /* An extra byte is needed because the entire file is treated
               as one big string. */
            buf = malloc(filelength(fileno(fil)) + 1);
            if (buf != NULL)
                {
                /* Read in the entire file. */
                memset(buf, 0, filelength(fileno(fil)) + 1);
                dynam = 1;
                rewind(fil);
                fread(buf, 1, filelength(fileno(fil)), fil);
                }
            fclose(fil);
            }

        /* Allocate a larger temporary buffer to hold the translated output
           text. */
        if (!dynam || buf != NULL)
            {
            /* 1000 extra bytes are allocated to minimize chances of a
               buffer overrun due to excessive % tokens. */
            tmp = malloc(dynam ?
                    (strlen(buf) + 1000) : (strlen(msgin.string) + 1000));
            }
        if (tmp != NULL)
            {
            memset(tmp, 0,
                (dynam ? (strlen(buf) + 1000) : (strlen(msgin.string) + 1000)));
            delprompt(delname);
            mused++;
            /* Assign a common string pointer to whatever buffer we are
               using, for manageability. */
            if (dynam)
                {
                str = buf;
                }
            else
                {
                str = msgin.string;
                }

            /* Loop for each character in the buffer. */
            for (c = 0; c < (dynam ? strlen(buf) : strlen(msgin.string));
                 c++)
                {
                if (msgin.type == MSG_TLKTYPPLU && c == msgin.data1)
                    {
                    /* Disable token processing once we reach the user's
                       text in a talktype, so they can't wreak havoc with
                       extra % codes. */
                    proctokon = 0;
                    }
                if (nxt)
                    {
                    /* The previous character was a %, so we expect a
                       token character. */

                    nxt = 2;

                    /* For token explanations, see TOP.DOC. */

                    /* "Me" token. */
                    if (toupper(str[c]) == 'M' &&
                        (allowbits & ALLOW_ME))
                        {
                        tmark = strlen(tmp);
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionMe"),
                                               msgin.handle));
                        /* Adjust the start of user text (normally used
                           in talktypes). */
                        msgin.data1 -= 2L;
                        msgin.data1 += (long) strlen(tmp) - (long) tmark;
                        }
                    /* "You" token. */
                    if (toupper(str[c]) == 'Y' &&
                        (allowbits & ALLOW_YOU))
                        {
                        tmark = strlen(tmp);
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionYouPrefix")));
                        if (msgin.doneto == od_control.od_node)
                            {
                            strcat(tmp, getlang("You"));
                            }
                        if (msgin.doneto == -2)
                            {
                            strcat(tmp, getlang("All"));
                            }
                        if ((msgin.doneto >= 0) &&
                            (msgin.doneto != od_control.od_node))
                            {
                            strcat(tmp, handles[msgin.doneto].string);
                            }
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionYouSuffix")));
                        /* Adjust the start of user text (normally used
                           in talktypes). */
                        msgin.data1 -= 2L;
                        msgin.data1 += (long) strlen(tmp) - (long) tmark;
                        }
                    /* "His/Her" token. */
                    if (toupper(str[c]) == 'H' &&
                        (allowbits & ALLOW_SEX))
                        {
                        tmark = strlen(tmp);
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionHisHerPrefix")));
                        if (msgin.gender == 0)
                            {
                            strcat(tmp, getlang("His"));
                            }
                        if (msgin.gender == 1)
                            {
                            strcat(tmp, getlang("Her"));
                            }
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionHisHerSuffix")));
                        /* Adjust the start of user text (normally used
                           in talktypes). */
                        msgin.data1 -= 2L;
                        msgin.data1 += (long) strlen(tmp) - (long) tmark;
                        }
                    /* "He/She" token. */
                    if (toupper(str[c]) == 'E' &&
                        (allowbits & ALLOW_HESHE))
                        {
                        tmark = strlen(tmp);
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionHeShePrefix")));
                        if (msgin.gender == 0)
                            {
                            strcat(tmp, getlang("He"));
                            }
                        if (msgin.gender == 1)
                            {
                            strcat(tmp, getlang("She"));
                            }
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionHeSheSuffix")));
                        /* Adjust the start of user text (normally used
                           in talktypes). */
                        msgin.data1 -= 2L;
                        msgin.data1 += (long) strlen(tmp) - (long) tmark;
                        }
                    /* "Himself/Herself" token. */
                    if (toupper(str[c]) == 'F' &&
                        (allowbits & ALLOW_SLF))
                        {
                        tmark = strlen(tmp);
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionSelfPrefix")));
                        if (msgin.gender == 0)
                            {
                            strcat(tmp, getlang("Himself"));
                            }
                        if (msgin.gender == 1)
                            {
                            strcat(tmp, getlang("Herself"));
                            }
                        strcat(tmp, top_output(OUT_STRINGNF,
                                               getlang("ActionSelfSuffix")));
                        /* Adjust the start of user text (normally used
                           in talktypes). */
                        msgin.data1 -= 2L;
                        msgin.data1 += (long) strlen(tmp) - (long) tmark;
                        }
                    /* Possessive token. */
                    if (toupper(str[c]) == 'S' &&
                        (allowbits & ALLOW_POS))
                        {
                        tmark = strlen(tmp);
                        if (msgin.doneto == od_control.od_node)
                            {
                            strcat(tmp, top_output(OUT_STRINGNF,
                                            getlang("ActionYour"),
                                            getlang("YourSuffix")));
                            }
                        else
                            {
                            strcat(tmp, top_output(OUT_STRINGNF,
                                            getlang("ActionPossessive"),
                                            getlang("Pers3Suffix")));
                            }
                        /* Adjust the start of user text (normally used
                           in talktypes). */
                        msgin.data1 -= 2L;
                        msgin.data1 += (long) strlen(tmp) - (long) tmark;
                        }
                    }
                if (nxt == 0)
                    {
                    if (str[c] == '%' && proctokon)
                        {
                        /* Flag the next loop that a % was found. */
                        nxt = 1;
                        }
                    else
                        {
                        /* Copy the character as is. */
                        strncat(tmp, &str[c], 1);
                        }
                    }
                /* Reset the next flag if it was used on this loop. */
                if (nxt == 2)
                    {
                    nxt = 0;
                    }
                }

            /* Append the user text if this is a plural talktype. */
            if (msgin.type == MSG_TLKTYPPLU)
                {
                /* Store the first character of user text and replace it
                   with a \0 so the action text can be printed. */
                xch = tmp[msgin.data1];
                tmp[msgin.data1] = '\0';
                top_output(dynam ? OUT_EMULATE : OUT_SCREEN, tmp);
                /* Restore the user text and print it with language code
                   translation turned off. */
                tmp[msgin.data1] = xch;
                top_output(dynam ? OUT_EMULATE : OUT_SCREEN, "@1&L",
                           &tmp[msgin.data1]);
                }
            else
                {
                top_output(dynam ? OUT_EMULATE : OUT_SCREEN, tmp);
                }
            /* Secret action. */
            if (msgin.type == MSG_ACTPLUSEC)
                {
                top_output(OUT_SCREEN, getlang("Secretly"));
                }
            dofree(tmp);
            }
        if (dynam)
            {
            dofree(buf);
            }
        }

    /* BAN, UNBAN, INVITE, and UNINVITE commands. */
    if (baninv > 0)
        {
        delprompt(delname);

        /* These messages come in globally if the command affects us,
           otherwise they come in on the current channel as a notification. */
        if (msgin.channel != 0)
            {
            /* Notification. */

            /* Copy the right language item name based on the message. */
            switch (baninv)
                {
                case 1: strcpy(outbuf, "HasBeenBanned"); break;
                case 2: strcpy(outbuf, "HasBeenUnBanned"); break;
                case 3: strcpy(outbuf, "HasBeenInvited"); break;
                case 4: strcpy(outbuf, "HasBeenUnInvited"); break;
                }
            top_output(OUT_SCREEN, getlang(outbuf),
                       handles[msgin.from].string,
                       msgin.doneto == od_control.od_node ?
                           getlang("You") : handles[msgin.doneto].string);
            /* BAN and INVITE add the node to the special nodes list. */
            if (baninv == 1 || baninv == 3)
                {
                cmi_setspec(msgin.doneto, 1);
                }
            /* UNBAN and UNINVITE remove the node from the special nodes
               list. */
            if (baninv == 2 || baninv == 4)
                {
                cmi_setspec(msgin.doneto, 0);
                }
            if (baninv == 1 || baninv == 4)
                {
                /* If a BAN or UNINVITE command was done to us and we
                   received the notification, it means we are being thrown
                   out of our current channel, so we have to return the
                   user to the main channel. */
                if (msgin.doneto == od_control.od_node)
                    {
                    rettomain = 1;
                    }
                }
            }
        else
            {
            /* Global message that affects us. */

            /* Select the right language item. */
            /* A switch was not used here because compiler didn't like it
               for some reason, possibly due to the enormous switch used
               for message processing. */
            if (baninv == 1)
                {
                if ((unsigned long) msgin.data1 <= 3999999999UL)
                    strcpy(outbuf, "YouBannedChan");
                if ((unsigned long) msgin.data1 >= 4000000000UL &&
                    (unsigned long) msgin.data1 <= 4000999999UL)
                    strcpy(outbuf, "YouBannedUserChan");
                if ((unsigned long) msgin.data1 >= 4001000000UL)
                    strcpy(outbuf, "YouBannedConf");
                }
            if (baninv == 2)
                {
                if ((unsigned long) msgin.data1 <= 3999999999UL)
                    strcpy(outbuf, "YouUnBannedChan");
                if ((unsigned long) msgin.data1 >= 4000000000UL &&
                    (unsigned long) msgin.data1 <= 4000999999UL)
                    strcpy(outbuf, "YouUnBannedUsChan");
                if ((unsigned long) msgin.data1 >= 4001000000UL)
                    strcpy(outbuf, "YouUnBannedConf");
                }
            if (baninv == 3)
                {
                if ((unsigned long) msgin.data1 <= 3999999999UL)
                    strcpy(outbuf, "YouInvitedChan");
                if ((unsigned long) msgin.data1 >= 4000000000UL &&
                    (unsigned long) msgin.data1 <= 4000999999UL)
                    strcpy(outbuf, "YouInvitedUsChan");
                if ((unsigned long) msgin.data1 >= 4001000000UL)
                    strcpy(outbuf, "YouInvitedConf");
                }
            if (baninv == 4)
                {
                if ((unsigned long) msgin.data1 <= 3999999999UL)
                    strcpy(outbuf, "YouUnInvitedChan");
                if ((unsigned long) msgin.data1 >= 4000000000UL &&
                    (unsigned long) msgin.data1 <= 4000999999UL)
                    strcpy(outbuf, "YouUnInvitedUsCh");
                if ((unsigned long) msgin.data1 >= 4001000000UL)
                    strcpy(outbuf, "YouUnInvitedConf");
                }
            top_output(OUT_SCREEN, getlang(outbuf),
                       channelname((unsigned long) msgin.data1));
            }
        }

    /* Determine if the message just processed was actually used. */
    lastmsgused = mused - lastmsgused; /* TRUE if last used, FALSE if not. */

    /* Clear the bit for this message in the MIX file and finally unlock
       it. */
    tstbit[0] = 0;
    lseek(midxinfil, (long) d, SEEK_SET);
    write(midxinfil, tstbit, 1L);
    rec_locking(REC_UNLOCK, midxinfil, d, 1L);
    }

/* It is now safe for door kit time messages to be treated as TOP messages. */
blocktimemsgs = 0;

/* Some poker post-processing which is not used. */
/*//|for (res = 0; res < pokcount; res++)
	{
    poker_lockgame(pokstackgame[res]);
    poker_loadgame(pokstackgame[res], &mgame);
    poker_unlockgame(pokstackgame[res]);

    poker_sendmessage(MSG_POKER, 1, pokstackgame[res], 1, "Finished",
					  &mgame);
    }*///|

/* Enter private chat if needed. */
if (privchatflag)
    {
    dispatch_message(MSG_INPRIVCHAT, user.handle, -1, 0, 0);
    node->task |= TASK_PRIVATECHAT;
    save_node_data(od_control.od_node, node);
    cmi_busy();
    privatechat(privchatout);
    cmi_unbusy();
    node->task = node->task & (0xFF - TASK_PRIVATECHAT);
    save_node_data(od_control.od_node, node);
    dispatch_message(MSG_OUTPRIVCHAT, user.handle, -1, 0, 0);
    }

/* Return to main channel if needed. */
if (rettomain)
    {
    top_output(OUT_SCREEN, getlang("ReturnToMain"));
    /* Leave the current channel.  Even though the user is likely being
       forced out, it is actually voluntary as to whether TOP complies
       with the request to remove the user.  Obviously, this should always
       be done to prevent confusion for both other users and possibly TOP
       itself. */
    res = cmi_unjoin(curchannel);
    if (res != CMI_OKAY)
        {
        top_output(OUT_SCREEN, getlang("UnJoinError"));
        }
    /* Join the main channel. */
    res = cmi_join(cfg.defaultchannel);
    if (res != CMI_OKAY)
        {
        /* Join our personal channel if for some reason the main channel
           cannot be joined.  This likely means the CMI is corrupt. */
        res = cmi_join(4000000000UL + (unsigned long) od_control.od_node);
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("SevereJoinError"));
            od_exit(230, FALSE);
            }
        else
            {
            curchannel = 4000000000UL + (unsigned long) od_control.od_node;
            }
        }
    node->channel = curchannel = cfg.defaultchannel;
    save_node_data(od_control.od_node, node);
    dispatch_message(MSG_INCHANNEL, "\0", -1, 0, 0);
    channelsummary();
    }

if (delname && mused > 0 && lastmsgused)
	{
    top_output(OUT_SCREEN, getlang("MessageTrailer"));
    }

if (user.pref1 & PREF1_DUALWINDOW)
    {
    /* "Reactivate" the upper window in dual window mode. */
    if (onflag)
        {
        top_output(OUT_SCREEN, getlang("DWRestorePrefix"));
        }
    // Different for AVT when I find out what the store/recv codes are.
    od_disp_emu("\x1B" "[s", TRUE);

    }

/* In dual window mode, TOP prepares the screen for a message before it is
   known if the message will actually be used.  Therefore, if no messages
   were used but at least one was processed, we have to fool the calling
   function into thinking at least one message was used so it will restore
   the screen. */
if (mused == 0 && (user.pref1 & PREF1_DUALWINDOW) && proc > 0)
    {
    mused = 1;
    }

return mused;
}

/* delprompt() - Deletes the name prompt.
   Parameters:  dname - Flag whether or not to delete the name (see notes).
   Return:  Nothing.
   Notes:  The dname parameter essentially controls whether or not this
           function actually does anything.  If it is TRUE, TOP will delete
           the name prompt as planned.  If it is FALSE, TOP will do nothing.
           This parameter is needed because the function can be called
           several times during message processing, but the name prompt
           only needs to be deleted once, and attempting to delete it
           multiple times would mess up the screen.
*/
void delprompt(char dname)
{
XINT dd; /* Counter. */

if (dname)
    {
    if (user.pref1 & PREF1_DUALWINDOW)
        {
        /* At the moment, no action is taken under dual window mode. */
 //       top_output(OUT_SCREEN, getlang("DWClearInput"));
        }
    else
        {
        top_output(OUT_SCREEN, getlang("DelPromptPrefix"));
        /* Backspace out the name prompt. */
        for (dd = 0;
             dd < strlen(top_output(OUT_STRING, getlang("DefaultPrompt"),
                                    user.handle)); dd++)
            {
            top_output(OUT_SCREEN, getlang("DelPrompt"));
            }
        top_output(OUT_SCREEN, getlang("DelPromptSuffix"));
        }
    }

}