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

  1. /******************************************************************************
  2. MESSAGES.C   MODERATOR 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 the MODERATOR command which lets users control aspects
  20. about their current channel, including who is inside it.
  21. ******************************************************************************/
  22.  
  23. #include "top.h"
  24.  
  25. /* mod_proc() - MODERATOR command processor.
  26.    Parameters:  None.
  27.    Returns:  Nothing.
  28. */
  29. void mod_proc(void)
  30.     {
  31.     XINT sendto; /* Node a command is being done to. */
  32.     /* String buffer, handle buffer. */
  33.     unsigned char tmpstr[256], tmphand[256];
  34.     XINT res; /* Result code. */
  35.     XINT baninvflg = 0; /* Action to perform ((un)ban or (un)invite). */
  36.     long tmpcdef; /* Channel definition number holder. */
  37.     node_idx_typ nmod; /* Node index data buffer for "receiving" node. */
  38.  
  39.     /* Find a channel record for the current channel. */
  40.     tmpcdef = findchannelrec(curchannel);
  41.     /* The user can't perform a moderatorship command if certain conditions are
  42.        true.  The complex test below tests:  if the user is not listed
  43.        as a moderator, if it is not the user's own personal channel, if the
  44.        channel is not defined (in CHANNELS.CFG) and the user is not a sysop, or
  45.        the user's security is below the defined moderatorship security.  All
  46.        conditions must be true (and more often than not they are) to prohibit
  47.        the user from moderating. */
  48.     if (cmibuf.modnode != od_control.od_node &&
  49.         curchannel != ((unsigned long) od_control.od_node + 4000000000UL) &&
  50.         (tmpcdef == -1L || user.security < chan[tmpcdef].modsec) &&
  51.         user.security < cfg.sysopsec)
  52.         {
  53.         top_output(OUT_SCREEN, getlang("NotModerator"));
  54.         return;
  55.         }
  56.  
  57.     /* Nobody can moderate the main channel because all users must have
  58.        unconditional access to it in the event a user is tossed out of a
  59.        channel or if a technical problem occurs. */
  60.     if (curchannel == cfg.defaultchannel)
  61.         {
  62.         top_output(OUT_SCREEN, getlang("CantModInMain"));
  63.         return;
  64.         }
  65.  
  66.     /* All commands first refresh (reload) the channel data, which also
  67.        locks it.  After copying new information, the command saves the
  68.        new data, which unlocks it. */
  69.  
  70.     /* Change channel topic. */
  71.     if (checkcmdmatch(get_word(1), getlang("CmdsModTopicChg")))
  72.         {
  73.         res = cmi_load(curchannel);
  74.         if (res != CMI_OKAY)
  75.             {
  76.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  77.             return;
  78.             }
  79.         /* Copy the topic, which begins at the 3rd word of the input. */
  80.         memset(cmibuf.topic, 0, 71);
  81.         strncpy(cmibuf.topic, &word_str[word_pos[2]], 70);
  82.         res = cmi_save();
  83.         if (res != CMI_OKAY)
  84.             {
  85.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  86.             return;
  87.             }
  88.         dispatch_message(MSG_CHANTOPICCHG, cmibuf.topic, -1, 0, 0);
  89.         top_output(OUT_SCREEN, getlang("ChangedTopic"));
  90.         return;
  91.         }
  92.     /* Change the moderator, or add a new one. */
  93.     if (checkcmdmatch(get_word(1), getlang("CmdsModModChg")))
  94.         {
  95.         /* Find the specified user. */
  96.         sendto = find_node_from_name(tmpstr, tmphand,
  97.                                      &word_str[word_pos[2]]);
  98.         if (sendto == -1)
  99.             {
  100.             top_output(OUT_SCREEN, getlang("NotLoggedIn"), tmphand);
  101.             return;
  102.             }
  103.         if (sendto == -2)
  104.                {
  105.             top_output(OUT_SCREEN, getlang("NotSpecific"), tmphand);
  106.             return;
  107.             }
  108.         if (sendto == -3)
  109.             {
  110.             top_output(OUT_SCREEN, getlang("HasForgotYou"),
  111.                        handles[sendto].string);
  112.             return;
  113.             }
  114.  
  115.         res = cmi_load(curchannel);
  116.         if (res != CMI_OKAY)
  117.             {
  118.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  119.             return;
  120.             }
  121.         /* Assign the new moderator.  This can remove this user's moderator
  122.            status depending on the channel.  See CHANNELS.TXT for more
  123.            information. */
  124.         cmibuf.modnode = sendto;
  125.         res = cmi_save();
  126.         if (res != CMI_OKAY)
  127.             {
  128.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  129.             return;
  130.             }
  131.         /* Notify everybody about the change. */
  132.         dispatch_message(MSG_CHANMODCHG, "\0", sendto, 0, 0);
  133.         top_output(OUT_SCREEN, getlang("ChangedMod"),
  134.                    handles[sendto].string);
  135.         return;
  136.         }
  137.  
  138.     /* Ban, unban, invite, or uninvite a user.  The commands are handled by
  139.        the same code as they are so similar.  baninvflg is set to control
  140.        which action to do.  The codes are only used in this function. */
  141.     if (checkcmdmatch(get_word(1), getlang("CmdsModBan")))
  142.         {
  143.         baninvflg = 1;
  144.         }
  145.     if (checkcmdmatch(get_word(1), getlang("CmdsModUnBan")))
  146.         {
  147.         baninvflg = 2;
  148.         }
  149.     if (checkcmdmatch(get_word(1), getlang("CmdsModInvite")))
  150.         {
  151.         baninvflg = 3;
  152.         }
  153.     if (checkcmdmatch(get_word(1), getlang("CmdsModUnInvite")))
  154.         {
  155.         baninvflg = 4;
  156.         }
  157.  
  158.     /* The user can't ban in a personal channel.  The test is done using
  159.        hardcoded internal channel numbers but probably should use the CHAN_
  160.        channel type constants instead. */
  161.     if (curchannel >= 4000000000 && curchannel <= 4000999999 &&
  162.         baninvflg >= 1 && baninvflg <= 2)
  163.         {
  164.         top_output(OUT_SCREEN, getlang("CantBanFromHere"));
  165.         return;
  166.         }
  167.     /* The user can't invite in normal channels or conferences.  Again
  168.        the test uses hardcoded channel numbers. */
  169.     if ((curchannel <= 3999999999 || curchannel >= 4001000000) &&
  170.         baninvflg >= 3 && baninvflg <= 4)
  171.         {
  172.         top_output(OUT_SCREEN, getlang("CantInvFromHere"));
  173.         return;
  174.         }
  175.  
  176.     /* Proces a ban or invite command. */
  177.     if (baninvflg > 0)
  178.         {
  179.         XINT cmsgtyp = MSG_NULL; /* Message type holder. */
  180.  
  181.         /* Determine which user is affected by the command. */
  182.         sendto = find_node_from_name(tmpstr, tmphand,
  183.                                      &word_str[word_pos[2]]);
  184.         if (sendto == -1)
  185.             {
  186.             top_output(OUT_SCREEN, getlang("NotLoggedIn"), tmphand);
  187.             return;
  188.             }
  189.         if (sendto == -2)
  190.                {
  191.             top_output(OUT_SCREEN, getlang("NotSpecific"), tmphand);
  192.             return;
  193.             }
  194.         /* Users cannot be unbanned or invited if they have forgotten
  195.            this user. */
  196.         if (sendto == -3 && (baninvflg == 2 || baninvflg == 3))
  197.             {
  198.             top_output(OUT_SCREEN, getlang("HasForgotYou"),
  199.                        handles[sendto].string);
  200.             return;
  201.             }
  202.         /* Ban and invite messages are channel and forget ignorant, except
  203.            as described above. */
  204.         if (sendto == -3 || sendto == -4)
  205.             {
  206.             sendto = lastsendtonode;
  207.             }
  208.  
  209.         /* You can't moderate yourself, for technical reasons only.  I
  210.            never place arbitrary restrictions on user actions unless I
  211.            absolutely have to. */
  212.         if (sendto == od_control.od_node)
  213.             {
  214.             top_output(OUT_SCREEN, getlang("CantDoCmdToSelf"));
  215.             return;
  216.             }
  217.  
  218.         /* Load the receiving user's data to see if we're trying to block
  219.            a sysop, which is also a no-no.  This restriction is to give
  220.            sysops complete control over TOP. */
  221.         get_node_data(sendto, &nmod);
  222.         if (nmod.security >= cfg.sysopsec && (baninvflg == 1 ||
  223.             baninvflg == 4))
  224.             {
  225.             top_output(OUT_SCREEN, getlang("CantModToSysop"));
  226.             return;
  227.             }
  228.  
  229.         res = cmi_load(curchannel);
  230.         if (res != CMI_OKAY)
  231.             {
  232.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  233.             return;
  234.             }
  235.         /* Ban and invite commands add the user to the special nodes
  236.            list.  See CMI.C and CHANNELS.TXT for more information on
  237.            special nodes. */
  238.         if (baninvflg == 1 || baninvflg == 3)
  239.             {
  240.             /* Add the user to the special nodes list. */
  241.             res = cmi_setspec(sendto, 1);
  242.             if (res == CMIERR_FULL)
  243.                 {
  244.                 top_output(OUT_SCREEN,
  245.                            getlang(baninvflg == 1 ?
  246.                                    "CantBan" : "CantInvite"),
  247.                            handles[sendto].string);
  248.                 cmi_save();
  249.                 return;
  250.                 }
  251.             }
  252.         /* Unban and Uninvite remove the user from the special nodes list. */
  253.         if (baninvflg == 2 || baninvflg == 4)
  254.             {
  255.             /* Clear the user from the special nodes list. */
  256.             res = cmi_setspec(sendto, 0);
  257.             if (res == CMIERR_NOTFOUND)
  258.                 {
  259.                 top_output(OUT_SCREEN,
  260.                            getlang(baninvflg == 2 ?
  261.                                    "WasntBanned" : "WasntInvited"),
  262.                            handles[sendto].string);
  263.                 cmi_save();
  264.                 return;
  265.                 }
  266.             }
  267.         if (res != CMI_OKAY)
  268.             {
  269.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  270.             cmi_save();
  271.             return;
  272.             }
  273.         res = cmi_save();
  274.         if (res != CMI_OKAY)
  275.             {
  276.             top_output(OUT_SCREEN, getlang("CantDoModCmd"));
  277.             return;
  278.             }
  279.  
  280.         /* Set the message type to send depending on the command code. */
  281.         switch (baninvflg)
  282.             {
  283.             case 1: cmsgtyp = MSG_CHANBANNED; break;
  284.             case 2: cmsgtyp = MSG_CHANUNBANNED; break;
  285.             case 3: cmsgtyp = MSG_CHANINVITED; break;
  286.             case 4: cmsgtyp = MSG_CHANUNINVITED; break;
  287.             }
  288.         /* Tell everybody in this channel what we just did. */
  289.         dispatch_message(cmsgtyp, "\0", sendto, 0, 0);
  290.         /* Global messages store the current channel in the data1 field. */
  291.         msgextradata = (long) curchannel;
  292.         /* Send a global message to the user the action was done to, who
  293.            could be anywhere in TOP. */
  294.         msgsendglobal = 1;
  295.         dispatch_message(cmsgtyp, "\0", sendto, 1, 0);
  296.         /* Set the appropriate language item name to display. */
  297.         switch (baninvflg)
  298.             {
  299.             case 1: strcpy(outbuf, "BannedUser"); break;
  300.             case 2: strcpy(outbuf, "UnBannedUser"); break;
  301.             case 3: strcpy(outbuf, "InvitedUser"); break;
  302.             case 4: strcpy(outbuf, "UnInvitedUser"); break;
  303.             }
  304.         /* Confirm the action by displaying a message. */
  305.         top_output(OUT_SCREEN, getlang(outbuf), handles[sendto].string);
  306.         /* If we just banned or uninvited a user, they are no longer in
  307.            our channel. */
  308.         if (baninvflg == 1 || baninvflg == 4)
  309.             {
  310.             activenodes[sendto] = 2;
  311.             }
  312.         return;
  313.         }
  314.  
  315.     /* Command not recognized, show help file instead. */
  316.     show_helpfile("HELPMOD0");
  317.  
  318.     return;
  319.     }
  320.  
  321.