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

moderate.c 11.6 KB
Newer Older
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
/******************************************************************************
MESSAGES.C   MODERATOR command processor.

    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
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

This module processes the MODERATOR command which lets users control aspects
about their current channel, including who is inside it.
******************************************************************************/

#include "top.h"

/* mod_proc() - MODERATOR command processor.
   Parameters:  None.
   Returns:  Nothing.
*/
void mod_proc(void)
    {
    XINT sendto; /* Node a command is being done to. */
    /* String buffer, handle buffer. */
    unsigned char tmpstr[256], tmphand[256];
    XINT res; /* Result code. */
    XINT baninvflg = 0; /* Action to perform ((un)ban or (un)invite). */
    long tmpcdef; /* Channel definition number holder. */
    node_idx_typ nmod; /* Node index data buffer for "receiving" node. */

    /* Find a channel record for the current channel. */
    tmpcdef = findchannelrec(curchannel);
    /* The user can't perform a moderatorship command if certain conditions are
       true.  The complex test below tests:  if the user is not listed
       as a moderator, if it is not the user's own personal channel, if the
       channel is not defined (in CHANNELS.CFG) and the user is not a sysop, or
       the user's security is below the defined moderatorship security.  All
       conditions must be true (and more often than not they are) to prohibit
       the user from moderating. */
    if (cmibuf.modnode != od_control.od_node &&
        curchannel != ((unsigned long) od_control.od_node + 4000000000UL) &&
        (tmpcdef == -1L || user.security < chan[tmpcdef].modsec) &&
        user.security < cfg.sysopsec)
        {
        top_output(OUT_SCREEN, getlang("NotModerator"));
        return;
        }

    /* Nobody can moderate the main channel because all users must have
       unconditional access to it in the event a user is tossed out of a
       channel or if a technical problem occurs. */
    if (curchannel == cfg.defaultchannel)
        {
        top_output(OUT_SCREEN, getlang("CantModInMain"));
        return;
        }

    /* All commands first refresh (reload) the channel data, which also
       locks it.  After copying new information, the command saves the
       new data, which unlocks it. */

    /* Change channel topic. */
    if (checkcmdmatch(get_word(1), getlang("CmdsModTopicChg")))
        {
        res = cmi_load(curchannel);
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            return;
            }
        /* Copy the topic, which begins at the 3rd word of the input. */
        memset(cmibuf.topic, 0, 71);
        strncpy(cmibuf.topic, &word_str[word_pos[2]], 70);
        res = cmi_save();
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            return;
            }
        dispatch_message(MSG_CHANTOPICCHG, cmibuf.topic, -1, 0, 0);
        top_output(OUT_SCREEN, getlang("ChangedTopic"));
        return;
        }
    /* Change the moderator, or add a new one. */
    if (checkcmdmatch(get_word(1), getlang("CmdsModModChg")))
        {
        /* Find the specified user. */
        sendto = find_node_from_name(tmpstr, tmphand,
                                     &word_str[word_pos[2]]);
        if (sendto == -1)
    		{
            top_output(OUT_SCREEN, getlang("NotLoggedIn"), tmphand);
            return;
    	    }
	    if (sendto == -2)
		   	{
            top_output(OUT_SCREEN, getlang("NotSpecific"), tmphand);
            return;
    	    }
        if (sendto == -3)
            {
            top_output(OUT_SCREEN, getlang("HasForgotYou"),
                       handles[sendto].string);
            return;
            }

        res = cmi_load(curchannel);
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            return;
            }
        /* Assign the new moderator.  This can remove this user's moderator
           status depending on the channel.  See CHANNELS.TXT for more
           information. */
        cmibuf.modnode = sendto;
        res = cmi_save();
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            return;
            }
        /* Notify everybody about the change. */
        dispatch_message(MSG_CHANMODCHG, "\0", sendto, 0, 0);
        top_output(OUT_SCREEN, getlang("ChangedMod"),
                   handles[sendto].string);
        return;
        }

    /* Ban, unban, invite, or uninvite a user.  The commands are handled by
       the same code as they are so similar.  baninvflg is set to control
       which action to do.  The codes are only used in this function. */
    if (checkcmdmatch(get_word(1), getlang("CmdsModBan")))
        {
        baninvflg = 1;
        }
    if (checkcmdmatch(get_word(1), getlang("CmdsModUnBan")))
        {
        baninvflg = 2;
        }
    if (checkcmdmatch(get_word(1), getlang("CmdsModInvite")))
        {
        baninvflg = 3;
        }
    if (checkcmdmatch(get_word(1), getlang("CmdsModUnInvite")))
        {
        baninvflg = 4;
        }

    /* The user can't ban in a personal channel.  The test is done using
       hardcoded internal channel numbers but probably should use the CHAN_
       channel type constants instead. */
    if (curchannel >= 4000000000 && curchannel <= 4000999999 &&
        baninvflg >= 1 && baninvflg <= 2)
        {
        top_output(OUT_SCREEN, getlang("CantBanFromHere"));
        return;
        }
    /* The user can't invite in normal channels or conferences.  Again
       the test uses hardcoded channel numbers. */
    if ((curchannel <= 3999999999 || curchannel >= 4001000000) &&
        baninvflg >= 3 && baninvflg <= 4)
        {
        top_output(OUT_SCREEN, getlang("CantInvFromHere"));
        return;
        }

    /* Proces a ban or invite command. */
    if (baninvflg > 0)
        {
        XINT cmsgtyp = MSG_NULL; /* Message type holder. */

        /* Determine which user is affected by the command. */
        sendto = find_node_from_name(tmpstr, tmphand,
                                     &word_str[word_pos[2]]);
        if (sendto == -1)
    		{
            top_output(OUT_SCREEN, getlang("NotLoggedIn"), tmphand);
            return;
    	    }
	    if (sendto == -2)
		   	{
            top_output(OUT_SCREEN, getlang("NotSpecific"), tmphand);
            return;
    	    }
        /* Users cannot be unbanned or invited if they have forgotten
           this user. */
        if (sendto == -3 && (baninvflg == 2 || baninvflg == 3))
            {
            top_output(OUT_SCREEN, getlang("HasForgotYou"),
                       handles[sendto].string);
            return;
            }
        /* Ban and invite messages are channel and forget ignorant, except
           as described above. */
        if (sendto == -3 || sendto == -4)
            {
            sendto = lastsendtonode;
            }

        /* You can't moderate yourself, for technical reasons only.  I
           never place arbitrary restrictions on user actions unless I
           absolutely have to. */
        if (sendto == od_control.od_node)
            {
            top_output(OUT_SCREEN, getlang("CantDoCmdToSelf"));
            return;
            }

        /* Load the receiving user's data to see if we're trying to block
           a sysop, which is also a no-no.  This restriction is to give
           sysops complete control over TOP. */
        get_node_data(sendto, &nmod);
        if (nmod.security >= cfg.sysopsec && (baninvflg == 1 ||
            baninvflg == 4))
            {
            top_output(OUT_SCREEN, getlang("CantModToSysop"));
            return;
            }

        res = cmi_load(curchannel);
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            return;
            }
        /* Ban and invite commands add the user to the special nodes
           list.  See CMI.C and CHANNELS.TXT for more information on
           special nodes. */
        if (baninvflg == 1 || baninvflg == 3)
            {
            /* Add the user to the special nodes list. */
            res = cmi_setspec(sendto, 1);
            if (res == CMIERR_FULL)
                {
                top_output(OUT_SCREEN,
                           getlang(baninvflg == 1 ?
                                   "CantBan" : "CantInvite"),
                           handles[sendto].string);
                cmi_save();
                return;
                }
            }
        /* Unban and Uninvite remove the user from the special nodes list. */
        if (baninvflg == 2 || baninvflg == 4)
            {
            /* Clear the user from the special nodes list. */
            res = cmi_setspec(sendto, 0);
            if (res == CMIERR_NOTFOUND)
                {
                top_output(OUT_SCREEN,
                           getlang(baninvflg == 2 ?
                                   "WasntBanned" : "WasntInvited"),
                           handles[sendto].string);
                cmi_save();
                return;
                }
            }
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            cmi_save();
            return;
            }
        res = cmi_save();
        if (res != CMI_OKAY)
            {
            top_output(OUT_SCREEN, getlang("CantDoModCmd"));
            return;
            }

        /* Set the message type to send depending on the command code. */
        switch (baninvflg)
            {
            case 1: cmsgtyp = MSG_CHANBANNED; break;
            case 2: cmsgtyp = MSG_CHANUNBANNED; break;
            case 3: cmsgtyp = MSG_CHANINVITED; break;
            case 4: cmsgtyp = MSG_CHANUNINVITED; break;
            }
        /* Tell everybody in this channel what we just did. */
        dispatch_message(cmsgtyp, "\0", sendto, 0, 0);
        /* Global messages store the current channel in the data1 field. */
        msgextradata = (long) curchannel;
        /* Send a global message to the user the action was done to, who
           could be anywhere in TOP. */
        msgsendglobal = 1;
        dispatch_message(cmsgtyp, "\0", sendto, 1, 0);
        /* Set the appropriate language item name to display. */
        switch (baninvflg)
            {
            case 1: strcpy(outbuf, "BannedUser"); break;
            case 2: strcpy(outbuf, "UnBannedUser"); break;
            case 3: strcpy(outbuf, "InvitedUser"); break;
            case 4: strcpy(outbuf, "UnInvitedUser"); break;
            }
        /* Confirm the action by displaying a message. */
        top_output(OUT_SCREEN, getlang(outbuf), handles[sendto].string);
        /* If we just banned or uninvited a user, they are no longer in
           our channel. */
        if (baninvflg == 1 || baninvflg == 4)
            {
            activenodes[sendto] = 2;
            }
        return;
        }

    /* Command not recognized, show help file instead. */
    show_helpfile("helpmod0");

    return;
    }