SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 23/09/2009, 06:12 AM   #1
Incognito
Huge Clucker
 
Join Date: May 2006
Posts: 448
Reputation: 487
Default IRC Plugin

IRC Plugin

This plugin allows for the creation and management of IRC bots through the SA-MP server. There are many features, including:
  • SSL support and local IP address binding
  • Automatic reconnection attempts with configurable options
  • Bot grouping (built-in support for message distribution to prevent accidental flooding)
  • No limit on number of concurrent bot connections (support for multiple servers)
  • Efficient channel command system (slightly modified zcmd by Zeex)

Changelog

GitHub Commit History

Refer to the CHANGES file the binary package for the full changelog.

Enumerator

Code:
enum
{
	E_IRC_CONNECT_ATTEMPTS,
	E_IRC_CONNECT_DELAY,
	E_IRC_CONNECT_TIMEOUT,
	E_IRC_RECEIVE_TIMEOUT,
	E_IRC_RESPAWN
}

Natives
  • IRC_Connect(const server[], port, const nickname[], const realname[], const username[], bool:ssl = false, const localip[] = "", const serverpassword[] = "");
    • Connects to an IRC server (returns the botid)
      Note #1: The nickname is the name that everyone will see, the realname will only be visible in a whois, and the username will be in front of the hostname (username@hostname).
      Note #2: SSL connections can be initiated by setting the third-to-last parameter to true and connecting to an SSL-enabled server.
      Note #3: The socket can be optionally bound to a local IP address by entering it in the second-to-last parameter.
      Note #4: A server password can be optionally set by entering it in the last parameter (note that this is NOT the same as a password for an IRC service such as NickServ).

  • IRC_Quit(botid, const message[] = "");
    • Disconnects from an IRC server
      Note: A quit message may be specified, but it is optional.

  • IRC_JoinChannel(botid, const channel[], const key[] = "");
    • Joins a channel
      Note: A channel key may be specified, if necessary.

  • IRC_PartChannel(botid, const channel[], const message[] = "");
    • Parts a channel
      Note: A part message may be specified, but it is optional.

  • IRC_ChangeNick(botid, const nick[]);
    • Changes the bot's current nickname

  • IRC_SetMode(botid, const target[], const mode[]);
    • Sets a user mode or a channel mode
      Note: The target must be either the bot's current nickname or a channel (multiple modes and their parameters may also be set).

  • IRC_Say(botid, const target[], const message[]);
    • Sends a message to a user or a channel

  • IRC_Notice(botid, const target[], const message[]);
    • Sends a notice to a user or a channel

  • IRC_IsUserOnChannel(botid, const channel[], const user[]);
    • Searches for a user in a channel (returns 0 or 1)

  • IRC_InviteUser(botid, const channel[], const user[]);
    • Invites a user to a channel

  • IRC_KickUser(botid, const channel[], const user[], const message[] = "");
    • Kicks a user from a channel
      Note: A kick message may be specified, but it is optional.

  • IRC_GetUserChannelMode(botid, const channel[], const user[], dest[]);
    • Obtains a user's channel mode (voice, halfop, op, protect/admin, or founder/owner)
      Note: This will store "+", "%", "@", "&", "!", "*", "~", ".", or "-" (if the user has no mode) in dest (use the stock functions below to simplify usage).

  • IRC_GetChannelUserList(botid, const channel[], dest[], maxlength = sizeof dest);
    • Obtains a space-delimited list of all users in a channel
      Note: This will store every user's name separated by a single space in dest (make sure that the array size is large enough to fit all of the names).

  • IRC_SetChannelTopic(botid, const channel[], const topic[]);
    • Sets a channel topic
      Note: A blank topic may be set by passing an empty string.

  • IRC_RequestCTCP(botid, const user[], const message[]);
    • Sends a CTCP request to a user

  • IRC_ReplyCTCP(botid, const user[], const message[]);
    • Sends a CTCP reply to a user

  • IRC_SendRaw(botid, const message[]);
    • Sends a raw message to the IRC server

  • IRC_CreateGroup();
    • Creates a group (returns the groupid)

  • IRC_DestroyGroup(groupid);
    • Destroys a group

  • IRC_AddToGroup(groupid, botid);
    • Adds a bot to a group

  • IRC_RemoveFromGroup(groupid, botid);
    • Removes a bot from a group

  • IRC_GroupSay(groupid, const target[], const message[]);
    • Sends a message to a user or a channel using the bot that is next in the group

  • IRC_GroupNotice(groupid, const target[], const message[]);
    • Sends a notice to a user or a channel using the bot that is next in the group

  • IRC_SetIntData(botid, data, value);
    • Adjusts settings for bots (refer to the enumerator for the data parameter)

Callbacks
  • IRC_OnConnect(botid, ip[], port);
    • Called when a bot successfully connects to the IRC server
      Note: Specifically, this is called when the "001" command is received.

  • IRC_OnDisconnect(botid, ip[], port, reason[]);
    • Called when a bot disconnects from the IRC server

  • IRC_OnConnectAttempt(botid, ip[], port);
    • Called when a bot begins a connection attempt

  • IRC_OnConnectAttemptFail(botid, ip[], port, reason[]);
    • Called when a bot fails a connection attempt

  • IRC_OnJoinChannel(botid, channel[]);
    • Called when a bot joins a channel

  • IRC_OnLeaveChannel(botid, channel[], message[]);
    • Called when a bot parts a channel

  • IRC_OnInvitedToChannel(botid, channel[], invitinguser[], invitinghost[]);
    • Called when a bot is invited to a channel

  • IRC_OnKickedFromChannel(botid, channel[], oppeduser[], oppedhost[], message[]);
    • Called when a bot is kicked from a channel

  • IRC_OnUserDisconnect(botid, user[], host[], message[]);
    • Called when a user in a common channel disconnects from the IRC server

  • IRC_OnUserJoinChannel(botid, channel[], user[], host[]);
    • Called when a user joins a common channel

  • IRC_OnUserLeaveChannel(botid, channel[], user[], host[], message[]);
    • Called when a user parts a common channel

  • IRC_OnUserKickedFromChannel(botid, channel[], kickeduser[], oppeduser[], oppedhost[], message[]);
    • Called when a user is kicked from a common channel

  • IRC_OnUserNickChange(botid, oldnick[], newnick[], host[]);
    • Called when a user in a common channel changes his/her nick

  • IRC_OnUserSetChannelMode(botid, channel[], user[], host[], mode[]);
    • Called when a user in a common channel sets a channel mode

  • IRC_OnUserSetChannelTopic(botid, channel[], user[], host[], topic[]);
    • Called when a user in a common channel sets a channel topic

  • IRC_OnUserSay(botid, recipient[], user[], host[], message[]);
    • Called when a user sends a message to a common channel or a private message to a bot (recpient can be either the bot name or the channel name)
      Note: If the bot is part of a group, only the first member of the group will receive this callback.

  • IRC_OnUserNotice(botid, recipient[], user[], host[], message[]);
    • Called when a user sends a notice to a common channel or to a bot (recpient can be either the bot name or the channel name)

  • IRC_OnUserRequestCTCP(botid, user[], host[], message[]);
    • Called when a user sends a CTCP request to a bot

  • IRC_OnUserReplyCTCP(botid, user[], host[], message[]);
    • Called when a user sends a CTCP reply to a bot

  • IRC_OnReceiveNumeric(botid, numeric, message[]);
    • Called when a bot receives a numeric code from the IRC server

  • IRC_OnReceiveRaw(botid, message[]);
    • Called when a bot receives a raw message from the IRC server

Stock Functions

These functions are used to simplify implementation of IRC_GetChannelUserMode. Note that all of the following will return true if the user is at the requested level or higher. For example, IRC_IsVoice will return true if the user is an op.
  • IRC_IsVoice(botid, channel[], user[]);

  • IRC_IsHalfop(botid, channel[], user[]);

  • IRC_IsOp(botid, channel[], user[]);

  • IRC_IsAdmin(botid, channel[], user[]);

  • IRC_IsOwner(botid, channel[], user[]);

Instructions

Create a directory called "plugins" inside of the server directory if one does not already exist. Place the plugin file (irc.dll or irc.so) inside of this directory.

Add the following line to server.cfg so that the plugin will load the next time the server starts:

Windows:
Code:
plugins irc.dll
Linux:
Code:
plugins irc.so
On Windows, add irc.inc to the pawno\include folder. Include this file in any of the scripts the server is running:

Code:
#include <irc>

Recompile the scripts with any desired natives and callbacks provided by the include file. Start the server.

Channel Command System

The command system is identical to zcmd, but messages are parsed in IRC_OnUserSay rather than in OnPlayerCommandText. The function syntax resembles the following (this can be placed anywhere in the script):

Code:
IRCCMD:command(botid, channel[], user[], host[], params[])
{
	/* ... */
}

Note that if two or more bots are present in the same channel, the bot that needs to process the command must be specified. Otherwise, all of the bots will process it, which is usually undesired. For example:

Code:
new botID = IRC_Connect(/* ... */);

IRCCMD:command(botid, channel[], user[], host[], params[])
{
	if (botid == botID)
	{
		/* ... */
	}
}

This is done automatically for bots in groups (IRC_OnUserSay is called only once).

The command prefix ('!') can be changed by editing the COMMAND_PREFIX constant in irc.inc.

Better examples are in the filterscript.

Notes
  • Although the number of concurrent bot connections is unlimited, nearly all IRC servers do have session limits, and this can result in a network ban if the server is flooded with too many bots under the same address. The main reason for the presence of this feature (other than to prevent accidental message flooding) is to give users the flexibility to connect to multiple servers simultaneously instead of just one.
  • Bots are set to reconnect automatically by default. The default connect attempts is 5, the default connect delay is 20 seconds, and the default connect timeout is 10 seconds. The receive timeout is disabled by default, but it can by set manually.
  • Refer to RFC 1459 and RFC 2812 for more information on raw IRC messages.

Download

The latest compiled binaries will always be here:

GitHub Releases Page

The source can be browsed here. This repository can also be cloned.

The Windows version requires the Microsoft Visual C++ 2015 Redistributable Package.

The OpenSSL library is required for the SSL version of the plugin. If the server is running Windows, download the Win32 OpenSSL Light Installer from Shining Light Productions. If the server is running Linux, install the "openssl" package.

Last edited by Incognito; 31/01/2016 at 09:41 PM.
Incognito is offline   Reply With Quote
Old 23/09/2009, 06:31 AM   #2
Blacklite
Huge Clucker
 
Join Date: Mar 2009
Location: am kiwi
Posts: 419
Reputation: 45
Default Re: [REL] IRC Plugin v1.0

Woaaaah.

Awesome. About time we got something like this!

Really good stuff man, keep it up!
__________________

Blacklite is offline   Reply With Quote
Old 23/09/2009, 06:56 AM   #3
lpfthings
Huge Clucker
 
Join Date: Apr 2008
Posts: 223
Reputation: 0
Default Re: [REL] IRC Plugin v1.0

Last night I was wondering if there was a more stable script for this!

I'll try it out on my server, and the .3 server too
lpfthings is offline   Reply With Quote
Old 23/09/2009, 08:41 AM   #4
VIRUXE
Big Clucker
 
Join Date: Dec 2006
Location: Portugal
Posts: 149
Reputation: 0
Default Re: [REL] IRC Plugin v1.0

Good thing you've really managed to create a proper IRC Plugin for us. Thanks.
VIRUXE is offline   Reply With Quote
Old 23/09/2009, 09:49 AM   #5
Correlli
Godfather
 
Correlli's Avatar
 
Join Date: May 2009
Location: Slovenia
Posts: 7,168
Reputation: 353
Default Re: [REL] IRC Plugin v1.0

Keep up the good work.
Correlli is offline   Reply With Quote
Old 23/09/2009, 11:28 AM   #6
KingJ
Beta Tester
 
Join Date: Feb 2008
Location: UK
Posts: 552
Reputation: 64
Default Re: [REL] IRC Plugin v1.0

Great work!

I'm sure a lot of servers will find this extremely useful.
__________________
KINGJ.NET Game Servers is now owned by SmartBytes LLC. Click here for more information!
KingJ is offline   Reply With Quote
Old 23/09/2009, 11:55 AM   #7
[JIeXa]
Little Clucker
 
Join Date: Jul 2008
Posts: 44
Reputation: 0
Default Re: [REL] IRC Plugin v1.0

Very good job! Could you write a plugin to work with sockets?
[JIeXa] is offline   Reply With Quote
Old 23/09/2009, 01:15 PM   #8
Jay_
Beta Tester
 
Jay_'s Avatar
 
Join Date: Jul 2009
Posts: 661
Reputation: 183
Default Re: [REL] IRC Plugin v1.0

Excellent! Using at my server
__________________
Jay_ is offline   Reply With Quote
Old 23/09/2009, 03:34 PM   #9
gijsmin
Huge Clucker
 
Join Date: Aug 2008
Posts: 429
Reputation: 0
Default Re: [REL] IRC Plugin v1.0

Greaaat!!!!
Really Great thanks 100000x
Thanks!!!

EDIT:
if i want to compile this i get a error:
Code:
1>------ Build started: Project: irc, Configuration: Release Win32 ------
1>Compiling...
1>main.cpp
1>h:\irc plugin\source\main.h(37) : fatal error C1083: Cannot open include file: 'boost/algorithm/string.hpp': No such file or directory
1>irc.cpp
1>h:\irc plugin\source\main.h(37) : fatal error C1083: Cannot open include file: 'boost/algorithm/string.hpp': No such file or directory
1>amxplugin.cpp
1>Build log was saved at "file://h:\IRC Plugin\source\Release\BuildLog.htm"
1>irc - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
gijsmin is offline   Reply With Quote
Old 23/09/2009, 04:05 PM   #10
Westie
Gangsta
 
Westie's Avatar
 
Join Date: Jul 2009
Posts: 863
Reputation: 63
Default Re: [REL] IRC Plugin v1.0

That's pretty obvious, you'll need the boost library.
Westie is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very good plugin suggestion (for scripters) and easy to make for the Plugin Developers! Xentiarox Plugin Development 5 29/07/2012 10:48 PM
[help][plugin] Can't load mysql plugin mariomako Help Archive 8 16/07/2011 02:37 PM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 02:32 PM


All times are GMT. The time now is 05:05 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.