[FilterScript] IRC (Internet Relay Chat)
#1


IRC (Internet Relay Chat)

WARNING: If you're someone who don't like to read a lot, you can scroll to the bottom of this thread for the Pastebin link of the Filterscript. Questions concerning the filterscript will be answered in the discord server and in the comments section of this thread!
Introduction
This IRC Filterscript and its simple tutorial was created for both new and old members to the field of San Andreas Multiplayer Development. It can be used for any type of gamemode, especially Roleplay and Freeroam. It's detailed with the steps to guide you on setting up the filterscript, and the functions of each part within it. Before I created this, I've looked through the present filterscripts that relates to the IRC plugin, and majority of them are too plain, while the others are spoon fed to the new developers instead of showing them what goes where, one at a time.

Explanation of the Filterscript's Usage

Step One
First thing's first, you'll have to identify and include the plugins needed for this FS to actually work. Without them, a FS isn't a FS.

With that being said, the includes which we'll be adding are a_samp (mandatory), irc (the backbone), foreach (to send a message to each player with a common player feature), and sscanf (used to split the strings).

HTML Code:
#include <a_samp>
#include <irc>
#include <foreach>
#include <sscanf2>
Step Two
After the includes were identified and added to the top of the script, we'll move on to defining the hostname of the IRC server, the port attached to it, and of course, a channel in your IRC server for messages to be sent to, when things are done in-game.

HTML Code:
#define IRC_MAIN_SERVER "host.name.net"
#define IRC_PORT (1111)
#define IRC_CHANNEL "name"
Step Three
After the IRC hostname and its affiliated resources have been defined, the color which we'll be using for sending Admin messages in-game will be Red, so define it:

HTML Code:
#define COLOR_ADMIN   (0xFF6347FF)
Step Four
The next thing to do is define GroupID and BotAdmin. The GroupID will be used for creating a group within the IRC server, and the BotAdmin will be used to connect your bot to the server after it's creation, and make it an Admin.

HTML Code:
new GroupID, BotAdmin;
Step Five
If you're aware of how SAMP works, you should understand that OnGameModeInit is called when the server starts or restarts, and it is used for changes to be effective, such as mappings within the gamemode, loading data from the SQL database, and what not. This is where BotAdmin becomes beneficial, because it connects to the IRC server, using the IRC_Connect function, hostname from IRC_MAIN_SERVER, port from IRC_PORT, nickname, realname, and username.

NOTE: The "nickname", "realname", and "username" must be changed before you compile this FS.

HTML Code:
public OnGameModeInit()
{
	BotAdmin = IRC_Connect(IRC_MAIN_SERVER, IRC_PORT, "nickname", "realname", "username");
	IRC_SetIntData(BotAdmin, E_IRC_CONNECT_DELAY, 5);

	GroupID = IRC_CreateGroup();
	return 1;
}
Step Six
After this, the bot will join the defined IRC channel (IRC_CHANNEL) IF it's an Admin (BotAdmin, as identified above). If it's not an Admin bot (BotAdmin), it won't connect. The bot is then added to the group (GroupID) as well.

HTML Code:
public IRC_OnConnect(botid, ip[], port)
{
	if(botid == BotAdmin)
	{
		IRC_JoinChannel(botid, IRC_CHANNEL, "key");
		IRC_AddToGroup(GroupID, botid);
	}
	return 1;
}
Step Seven
After the IRC channel is disconnected from the SAMP server OR the gamemode stops running, causing the server to stop too, it'll call this function shown below (IRC_OnDisconnect). It basically removes the bot from the group (defined by GroupID)

HTML Code:
public IRC_OnDisconnect(botid, ip[], port, reason[])
{
	IRC_RemoveFromGroup(GroupID, botid);
	return 1;
}
Step Eight
The next thing you'll want to do is add the IRC_OnConnectAttempt function. As the name says, it's called when the connection is attempted. This basically prints the attempt message to server_log.txt

HTML Code:
public IRC_OnConnectAttempt(botid, ip[], port)
{
	printf("AdmWarn: IRC_OnConnectAttempt: Bot ID %d is now attempting to connect to IRC Server with Hostname (IP): %s, attached to port: %d", botid, ip, port);
	return 1;
}
Step Nine
This function (IRC_OnConnectAttemptFail) below must be added to print an error message to the server_log.txt file if the IRC connection was attempted and unfortunately failed.

HTML Code:
public IRC_OnConnectAttemptFail(botid, ip[], port, reason[])
{
	printf("AdmWarn: IRC_OnConnectAttemptFail: Bot ID %d has failed to connect to IRC server with hostname (IP): %s, attached to port %d. The reason for this is %s", botid, ip, port, reason);
	return 1;
}
Step Ten
After the gamemode stops running, and the server stops or shuts down, this common function to SAMP developers (OnGameModeExit) will be called. It will send a message to the channel from the bot, then destroy the group which was created earlier with (GroupID).

HTML Code:
public OnGameModeExit()
{
	IRC_Quit(BotAdmin, "AdmWarn: The server has shut down and the gamemode will stop running.");
	IRC_DestroyGroup(GroupID);
	return 1;
}
Step Eleven
When a player connects (OnPlayerConnect) to the server, it'll send a message to the defined IRC channel (IRC_CHANNEL), notifying others who are viewing the channel at the same time.

NOTE: You'll see the new ReturnName and SendAdminMessage functions from this point onwards, but do not worry because their functions will be provided at the end of this thread.

HTML Code:
public OnPlayerConnect(playerid)
{
	new string[128];

	format(string, sizeof(string), "AdmWarn: Character %s (ID: %d) joined the server.", ReturnName(playerid), playerid);
	IRC_GroupSay(GroupID, IRC_CHANNEL, string);
	return 1;
}
Step Twelve
In contrast, if a player disconnects (OnPlayerDisconnect) from the server, this function is commonly called, and as a result, the disconnect message is sent to the IRC channel.

HTML Code:
public OnPlayerDisconnect(playerid, reason)
{
	new string[200];
	
	format(string, sizeof(string), "AdmWarn: Character %s (ID: %d) disconnected from the server.", ReturnName(playerid), playerid);
	IRC_GroupSay(GroupID, IRC_CHANNEL, string);
	return 1;
}
Step Thirteen
The OnPlayerDeath function is called when a player dies, and must be added to your FS afterwards. If a player is killed by another player, it sends a message to both the SAMP and IRC servers. On the other hand, if the player dies naturally, it'll state that.

Code:
public OnPlayerDeath(playerid, killerid, reason)
{
	new string[200];
	if(killerid != INVALID_PLAYER_ID)
	{
		format(string, sizeof(string), "AdmWarn: %s (ID: %d) died (Killer: %s ID: %d).", ReturnName(playerid), playerid, ReturnName(killerid), killerid);
		SendAdminMessage(COLOR_ADMIN, string);

		format(string, sizeof(string), "AdmWarn: %s (ID: %d) died (Killer: %s ID: %d).", ReturnName(playerid), playerid, ReturnName(killerid), killerid);
		IRC_GroupSay(GroupID, IRC_CHANNEL, string);
	}
	else
	{
		format(string, sizeof(string), "AdmWarn: %s (ID: %d) died.", ReturnName(playerid), playerid);
		SendAdminMessage(COLOR_ADMIN, string);

		format(string, sizeof(string), "AdmWarn: %s (ID: %d) died.", ReturnName(playerid), playerid);
		IRC_GroupSay(GroupID, IRC_CHANNEL, string);
	}
	return 1;
}
Step Fourteen
Similarly to how a player dies, a vehicle can be destroyed too. When a vehicle is destroyed by a player, their ID and character name can be identified by this function (OnVehicleDeath), and called to send a message.

Code:
public OnVehicleDeath(vehicleid, killerid)
{
	new string[200];
	format(string, sizeof(string), "AdmWarn: Vehicle ID %d was destroyed by %s.", vehicleid, ReturnName(killerid));
	IRC_GroupSay(GroupID, IRC_CHANNEL, string);
	return 1;
}
Step Fifteen
Remember those two things which you read about? The ReturnName and SendAdminMessage functions/stocks. Well, here they are:

Code:
stock ReturnName(playerid)
{
	new name[90], character[MAX_PLAYER_NAME];
	GetPlayerName(playerid, character, sizeof(character));
	name = character;
	return name;
}

stock SendAdminMessage(color, const str[])
{
	foreach(new i : Player)
	{
		if(IsPlayerAdmin(i))
		{
			SendClientMessage(i, color, str);
		}
	}
	return 1;
}
ReturnName: This stock gets the actual and FULL name which was used by the player to connect to the server, no matter what the size is (I doubt anyone would use a name which has 20+ characters), and returns it.

NOTE: The underscore can be removed anytime, but I made this tutorial a bit simple.

SendAdminMessage: This checks for all players who are connected to the server and are RCON Admins at the same time, then sends the message to them.

Step Sixteen
The Commands! (Yeap, I added two commands for you, FOR NOW )
One command is used for communicating with RCON admins from IRC to in-game, while the other is used for kicking players from IRC.

Code:
IRCCMD:a(botid, channel[], user[], host[], params[])
{
	if (IRC_IsOp(botid, channel, user))
	{
	    new	string[200];
	    
		if(isnull(params))
		{
                        format(string, sizeof(string), "Usage: !a [Admin Message]");
			IRC_GroupSay(GroupID, IRC_CHANNEL, string);
		}
		else
  		{
			format(string, sizeof(string), "IRC Admin: %s: %s", user, params);
			SendAdminMessage(0x6CEFF0FF, string);
		}
	}
	return 1;
}

IRCCMD:kick(botid, channel[], user[], host[], params[])
{
	if(IRC_IsOp(botid, channel, user))
	{
		new playerid, reason[64];

		if(sscanf(params, "ds[64]", playerid, reason))
		{
			IRC_Say(botid, user, "Usage: !kick [playerid] [reason]");
			return 1;
		}

		if(IsPlayerConnected(playerid))
		{
			new	string[128];

			format(string, sizeof(string), "AdmCmd: %s was kicked by %s (IRC), Reason: %s", ReturnName(playerid), user, reason);
			IRC_GroupSay(GroupID, IRC_CHANNEL, string);
			Kick(playerid);
		}
	}
	return 1;
}
Download Links
IRC Include: https://falcon-host.org/uploads/irc.rar
IRC Plugin: https://falcon-host.org/uploads/irc-plugin.rar

sscanf Include: https://falcon-host.org/uploads/sscanf.rar
sscanf Plugin: https://falcon-host.org/uploads/sscanf-plugin.rar

foreach Include: https://falcon-host.org/uploads/foreach.rar

a_samp Include: https://falcon-host.org/uploads/a_samp.rar

YouTube Video of what I just did: https://www.youtube.com/watch?v=jtMGBsTtcVo&t=11s (It's my new YouTube channel, so can you please like the video, subscribe to my channel and comment? Your comment doesn't have to be good, it can be bad or based on criticism. I like to work while criticizing and challenging myself.)

Discord Server for Support: https://discordapp.com/invite/jr5Ywkm https://discord.io/ChaoticTheDev

Pastebin (If you're LAZY and just want the actual thing ) https://pastebin.com/Ap0JXBZh

Reply
#2

This isn't a release! It's a lousy tutorial and a basic filterscript that anyone could write in a short period of time.

1-Star from me.
Reply
#3

If it's lousy, why did you reply to it? Kudos to you.

I said I can take criticism but being an asshole isn't a good way to positively criticize something or someone. We all started from the bottom. You did, ALL developers did and I did, so I don't see the reason for seeking attention by acting foolish. I bet you'll reply to this, just to make yourself look more stupid than you already are.
Reply
#4

Great!
Reply
#5

Quote:
Originally Posted by KevTheJoker
View Post
If it's lousy, why did you reply to it? Kudos to you.

I said I can take criticism but being an asshole isn't a good way to positively criticize something or someone. We all started from the bottom. You did, ALL developers did and I did, so I don't see the reason for seeking attention by acting foolish. I bet you'll reply to this, just to make yourself look more stupid than you already are.
I can't help it..... The only constructive criticism I can come up with is do something that does something in a way no one has seen before and save tutorials for the tutorial section.

This is simply too basic to be a release.
Reply
#6

I'm not gonna continue arguing with you. No one found this to be an issue, except you.
Reply
#7

Quote:
Originally Posted by Pottus
View Post
This is simply too basic to be a release.
As we are talking about a something is "too basic to be a release", let's go back in 2013 and your "basic" releases.
Reply
#8

What a douche. KevinTheJoker's correct. Pottus acts as if he was born a developer. No wonder why new SAMP developers are demotivated to continue coding.
Reply
#9

Quote:
Originally Posted by Hazon
View Post
As we are talking about a something is "too basic to be a release", let's go back in 2013 and your "basic" releases.
At least I did stuff that was rare and made joke scripts. Anyways how can I support a release when it is so bare bones anyone could do it? My point is this is so basic there is absolutely no creativity not trying to be an asshole but if something sucks ass it sucks ass. This release sucks ass so what? I would be happy hearing that at least then I know what isn't right so I can fix it. If everyone said "nice", "good" you would never know what is fucked up right?
Reply
#10

Quote:
Originally Posted by Dignity
View Post
Imagine writing a release and moaning when someone criticizes your post

How will you ever improve?

Jesus lmfao this community, yall need to get a thicker skin u forget ur on the internet
Skin is so thin these hemophiliac's are bleeding to death from a pin prick.
Reply
#11

Yup, whats the big deal anyways? Learn to love what people don't like!
Reply
#12

Oh, the two of you are still here making love? Jeez, find a room.
Reply
#13

Hey bella, go find yourself a new fella.. This is the wrong section plebs
Reply
#14

Quote:
Originally Posted by KevTheJoker
View Post
Oh, the two of you are still here making love? Jeez, find a room.
You know we always get love from the homies.
Reply
#15

Great Brother
Reply
#16

Mate this is a tutorial why putting it in this section?
Reply
#17

Quote:
Originally Posted by Flofey
View Post
Mate this is a tutorial why putting it in this section?
How dumber can you be?

At the top of this thread, I said:

WARNING: If you're someone who don't like to read a lot, you can scroll to the bottom of this thread for the Pastebin link of the FILTERSCRIPT. Questions concerning the FILTERSCRIPT will be answered in the discord server and in the comments section of this thread!

Plus, it's more of a GUIDE, than a filterscript. So again, what's your point?

In case you didn't get that, lemme echo it for you:

FILTERSCRIPT
FILTERSCRIPT
FILTERSCRIPT
FILTERSCRIPT
FILTERSCRIPT
FILTERSCRIPT
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)