[Tutorial] Fixing connect flooding with the IRC plugin
#1

Hi folks,

The IRC.tl servers have issued dozens of network bans recently due to misbehaving gamemodes flooding the network with half-open connections. This is due to scripters' poor handling of disconnection events with the IRC plugin.

If you use the IRC plugin and know that you have explicit disconnect/reconnect handling, it's advisable to check whether or not any of the following applies to you.
If you have been directed here because your host has been banned by an IRC network, then following the steps below should fix your issues.

1) IRC PLUGIN UPGRADE
Version 1.4.6 of the IRC plugin features a couple of tweaks and bugfixes for disconnect handling. If you are running an earlier version, you need to upgrade it, particularly if you use the IRC_Quit function in your gamemode.

Download links: https://sampforum.blast.hk/showthread.php?tid=98803

2) IRC_ONDISCONNECT HANDLING
If a bot's connection to the IRC server fails, the IRC plugin will automatically attempt to reconnect the bot. That means that the IRC_OnDisconnect callback should not be interpreted as the "bot is about to be destroyed" callback - the bot is only destroyed if it was disconnected by the IRC_Quit function, not if the connection failed unintentionally.

A lot of misbehaving bots have code similar to the following:
pawn Code:
public IRC_OnDisconnect(botID, ip[], port, reason[]) {
    // I presume that the bot has been destroyed, so let's create a new one!
    MyIRCBotConnectFunction();

    /* other stuff */
}
This is WRONG. Wrong, wrong, wrong. The existing IRC bot has NOT been destroyed, and will be automatically reconnected to the server. This code will duplicate the bot: the existing botID will automatically reconnect, and you've created a new bot as well.

If you have code that looks like this, there are two ways to fix it. Either:
  • Remove your reconnection code from IRC_OnDisconnect, and allow the IRC plugin to automatically reconnect for you.
    pawn Code:
    public IRC_OnDisconnect(botID, ip[], port, reason[]) {
        // The bot is going to reconnect automatically if its connection failed,
        // so no need to manually reconnect here.

        /* other stuff */
    }
  • Alternatively, you can disable the automatic reconnection feature, and keep your manual reconnection code in IRC_OnDisconnect.
    pawn Code:
    MyIRCBotConnectFunction() {
        new MyBotID = IRC_Connect(MyIRCServer, MyIRCPort, MyIRCBotNick, MyIRCBotUsername);

        // Disable IRC auto-reconnect
        IRC_SetIntData(MyBotID, E_IRC_RESPAWN, 0);
    }

    public IRC_OnDisconnect(botID, ip[], port, reason[]) {
        // The bot is *NOT* going to reconnect automatically, so let's do it manually!
        MyIRCBotConnectFunction();

        /* other stuff */
    }
    Bear in mind that if you use this method, there's no intrinsic way to tell whether the bot has disconnected because you told it to (IRC_Quit) or because its connection failed.
Happy scripting, and Merry Christmas!

- R
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)