home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / SYSOP.C < prev    next >
C/C++ Source or Header  |  2000-07-13  |  9KB  |  239 lines

  1. /******************************************************************************
  2. SYSOP.C      SYSOP command processor.
  3.  
  4.     Copyright 1993 - 2000 Paul J. Sidorsky
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License, version 2, as
  8.     published by the Free Software Foundation.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. This module processes all SYSOP commands.
  20. ******************************************************************************/
  21.  
  22. #include "top.h"
  23.  
  24. /* Command constants used internally by the sysop_proc() function.  The
  25.    text after SYSOP_ corresponds to the command name. */
  26. #define SYSOP_CLEAR       0     /* Clears a stuck node. */
  27. #define SYSOP_DELETE      1     /* Reserved. */
  28. #define SYSOP_LINK        2     /* Reserved. */
  29. #define SYSOP_MAINT       3     /* Reserved. */
  30. #define SYSOP_TOSS        4     /* Toss a user out of TOP, back to the BBS. */
  31. #define SYSOP_UEDIT       5     /* Reserved. */
  32. #define SYSOP_ZAP         6     /* Hang up a user. */
  33. #define SYSOP_CDGIVE      7     /* Reserved. */
  34. #define SYSOP_CDTAKE      8     /* Reserved. */
  35. #define SYSOP_CDSET       9     /* Reserved. */
  36. #define SYSOP_EDITUSER   10     /* Reserved. */
  37. #define SYSOP_SETSEC     11     /* Change a user's security level. */
  38.  
  39. /* sysop_proc() - SYSOP command processor. */
  40. void sysop_proc(void)
  41. {
  42. /* Command was used flag, command (SYSOP_ constant), flag if there is a node
  43.    to do the command to. */
  44. char sused = 0, scom = -1, yessend = 1;
  45.  
  46. /* This module uses a different approach than other command procesors,
  47.    because most SYSOP commands are very similar.  It first determines the
  48.    command, setting a SYSOP_ constant if one is found.  Then a common
  49.    processor acts. */
  50.  
  51. if (checkcmdmatch(get_word(1), getlang("CmdsSysopToss")) > 0)
  52.     {
  53.     scom = MSG_TOSSED;
  54.     }
  55. if (checkcmdmatch(get_word(1), getlang("CmdsSysopZap")) > 0)
  56.     {
  57.     scom = MSG_ZAPPED;
  58.     }
  59. if (checkcmdmatch(get_word(1), getlang("CmdsSysopClear")) > 0)
  60.     {
  61.     scom = MSG_CLEARNODE;
  62.     yessend = 0;
  63.     }
  64. /* CDxxxx commands are not used.  They are intended for use with games. */
  65. /*if (checkcmdmatch(get_word(1), getlang("CmdsSysopCDGive")) > 0)
  66.     {
  67.     scom = MSG_SYSGIVECD;
  68.     }
  69. if (checkcmdmatch(get_word(1), getlang("CmdsSysopCDTake")) > 0)
  70.     {
  71.     scom = MSG_SYSTAKECD;
  72.     }
  73. if (checkcmdmatch(get_word(1), getlang("CmdsSysopCDSet")) > 0)
  74.     {
  75.     scom = MSG_SYSSETCD;
  76.     }*/
  77. if (checkcmdmatch(get_word(1), getlang("CmdsSysopSetSec")) > 0)
  78.     {
  79.     scom = MSG_SYSSETSEC;
  80.     }
  81.  
  82. if (scom != -1)
  83.     {
  84.     XINT sendto; /* Node to send to. */
  85.     /* Temporary text buffer, temporary "send to" handle buffer. */
  86.     unsigned char tmpstr[256], tmphand[256];
  87.  
  88.     sused = 1;
  89.  
  90.     if (yessend)
  91.         {
  92.         /* Find the node from a name if the command requires one. */
  93.         sendto = find_node_from_name(tmpstr, tmphand,
  94.                                      &word_str[word_pos[2]]);
  95.         }
  96.     else
  97.         {
  98.         /* Command does not require a name. */
  99.         sendto = 0;
  100.         }
  101.  
  102.     if (sendto == -1)
  103.         {
  104.         top_output(OUT_SCREEN, getlang("NotLoggedIn"), tmphand);
  105.         }
  106.     if (sendto == -2)
  107.            {
  108.         top_output(OUT_SCREEN, getlang("NotSpecific"), tmphand);
  109.         }
  110.     /* -3 (HasForgotYou) is not handled because sysops cannot be forgotten. */
  111.     /* Sysop commands are channel-independent. */
  112.     if (sendto == -4)
  113.            {
  114.         sendto = lastsendtonode;
  115.         }
  116.     if (sendto >= 0)
  117.         {
  118.         unsigned long cdc; /* Temporary value holder. */
  119.  
  120.         /* find_node_from_name() returns an untrimmed string, which
  121.            includes the space that follows the name of the user.  For this
  122.            reason, if tmpstr has nothing in it, we need to make sure the
  123.            second character is a \0 as well, because the processor starts
  124.            looking at the second character. */
  125.         if (tmpstr[0] == '\0')
  126.             {
  127.             tmpstr[1] = '\0';
  128.             }
  129.  
  130.         /* Get the value of the rest of the string, not including the
  131.            leading space mentioned above. */
  132.         cdc = strtoul(&tmpstr[1], NULL, 10);
  133.  
  134.         /* SYSOP TOSS command. */
  135.         if (scom == MSG_TOSSED)
  136.             {
  137.             msgsendglobal = 1;
  138.             dispatch_message(scom, &tmpstr[1], sendto, 1, 0);
  139.             top_output(OUT_SCREEN, getlang("HasBeenTossed"),
  140.                        handles[sendto].string);
  141.             od_log_write(top_output(OUT_STRING, getlang("LogTossed"),
  142.                                     handles[sendto].string));
  143.             }
  144.         /* SYSOP ZAP command. */
  145.         if (scom == MSG_ZAPPED)
  146.             {
  147.             msgsendglobal = 1;
  148.             dispatch_message(scom, &tmpstr[1], sendto, 1, 0);
  149.             top_output(OUT_SCREEN, getlang("HasBeenZapped"),
  150.                        handles[sendto].string);
  151.             od_log_write(top_output(OUT_STRING, getlang("LogZapped"),
  152.                                     handles[sendto].string));
  153.             }
  154.         /* SYSOP CLEAR command. */
  155.         if (scom == MSG_CLEARNODE)
  156.             {
  157.             char tmpbit = 0; /* Temporary NODEIDX2 byte. */
  158.             XINT clnod; /* Node to clear. */
  159.  
  160.             strcpy(tmpstr, &word_str[word_pos[2]]);
  161.  
  162.             clnod = atoi(tmpstr);
  163.             if (clnod < 1 || clnod > MAXNODES)
  164.                 {
  165.                 itoa(MAXNODES, outnum[0], 10);
  166.                 top_output(OUT_SCREEN, getlang("InvalidNode"), outnum[0]);
  167.                 }
  168.             else
  169.                 {
  170.                 /* Clear the "receiving" node's NODEIDX2 byte, which should
  171.                    make the node invisible. */
  172.                 lseek(nidx2fil, (long) clnod, SEEK_SET);
  173.                 rec_locking(REC_LOCK, nidx2fil, clnod, 1L);
  174.                 write(nidx2fil, &tmpbit, 1L);
  175.                 rec_locking(REC_UNLOCK, nidx2fil, clnod, 1L);
  176.                 msgsendglobal = 1;
  177.                 dispatch_message(MSG_CLEARNODE, tmpstr, -1, 0, 1);
  178.                 // Clear the who's online file!
  179.                 itoa(clnod, outnum[0], 10);
  180.                 top_output(OUT_SCREEN, getlang("NodeCleared"), outnum[0]);
  181.                 od_log_write(top_output(OUT_STRING, getlang("LogClearedNode"),
  182.                                         outnum[0]));
  183.                 }
  184.             }
  185.         /* The remaining commands use numeric values. */
  186.         ultoa(cdc, outnum[0], 10);
  187. /* Unused CyberCash commands. */
  188. /*        if (scom == MSG_SYSGIVECD)
  189.             {
  190.             top_output(OUT_SCREEN, getlang("CDHasBeenGiven"), outnum[0],
  191.                        getlang (cdc == 1 ? "SingularHas" : "PluralHave"),
  192.                        handles[sendto].string);
  193.             dispatch_message(scom, &tmpstr[1], sendto, 1, 0);
  194.             }
  195.         if (scom == MSG_SYSTAKECD)
  196.             {
  197.             top_output(OUT_SCREEN, getlang("CDHasBeenTaken"), outnum[0],
  198.                        getlang (cdc == 1 ? "SingularHas" : "PluralHave"),
  199.                        handles[sendto].string);
  200.             dispatch_message(scom, &tmpstr[1], sendto, 1, 0);
  201.             }
  202.         if (scom == MSG_SYSSETCD)
  203.             {
  204.             top_output(OUT_SCREEN, getlang("CDHasBeenSetAt"),
  205.                        handles[sendto].string, outnum[0]);
  206.             dispatch_message(scom, &tmpstr[1], sendto, 1, 0);
  207.             }*/
  208.         /* SYSOP SETSEC command. */
  209.         if (scom == MSG_SYSSETSEC)
  210.             {
  211.             top_output(OUT_SCREEN, getlang("SecHasBeenSetAt"),
  212.                        handles[sendto].string, outnum[0]);
  213.             msgsendglobal = 1;
  214.             dispatch_message(scom, &tmpstr[1], sendto, 1, 0);
  215.             }
  216.  
  217.         }
  218.     }
  219.  
  220. /* There was an online user editor at one point, but it was never finished. */
  221. /*if (checkcmdmatch(get_word(1), getlang("CmdsSysopEditUser")))
  222.     {
  223.     // Check ANSI bigtime!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  224.     sused = 1;
  225.     od_disp_emu("\x1B[s", TRUE);  // will screw up screen in AVT mode
  226.     usereditor();
  227.     od_set_attrib(0x07);
  228.     od_disp_emu("\x1B[u\r\n", TRUE);
  229.     }*/
  230.  
  231. if (!sused) ///!!!!!!!!
  232.     {
  233.     /* Command not recognized, show a help file instead. */
  234.     show_helpfile("HELPSYS0");
  235.     }
  236.  
  237. return;
  238. }
  239.