SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 06/01/2020, 02:17 AM   #1
KevTheJoker
Big Clucker
 
KevTheJoker's Avatar
 
Join Date: Dec 2018
Posts: 51
Reputation: 6
Default IRC (Internet Relay Chat)


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

KevTheJoker is offline   Reply With Quote
Old 06/01/2020, 03:51 AM   #2
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,892
Reputation: 1321
Default Re: IRC (Internet Relay Chat)

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.
Pottus is offline   Reply With Quote
Old 06/01/2020, 04:04 AM   #3
KevTheJoker
Big Clucker
 
KevTheJoker's Avatar
 
Join Date: Dec 2018
Posts: 51
Reputation: 6
Default Re: IRC (Internet Relay Chat)

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.
KevTheJoker is offline   Reply With Quote
Old 07/01/2020, 12:07 AM   #4
TheDiego
Little Clucker
 
Join Date: Sep 2019
Location: Join Date: 00/00/2006
Posts: 15
Reputation: 2
Default Re: IRC (Internet Relay Chat)

Great!
TheDiego is offline   Reply With Quote
Old 07/01/2020, 01:15 AM   #5
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,892
Reputation: 1321
Default Re: IRC (Internet Relay Chat)

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.
Pottus is offline   Reply With Quote
Old 07/01/2020, 01:02 PM   #6
KevTheJoker
Big Clucker
 
KevTheJoker's Avatar
 
Join Date: Dec 2018
Posts: 51
Reputation: 6
Default Re: IRC (Internet Relay Chat)

I'm not gonna continue arguing with you. No one found this to be an issue, except you.
KevTheJoker is offline   Reply With Quote
Old 07/01/2020, 01:30 PM   #7
Hazon
Big Clucker
 
Hazon's Avatar
 
Join Date: May 2018
Location: Who cares ?
Posts: 171
Reputation: 29
Default Re: IRC (Internet Relay Chat)

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.
Hazon is offline   Reply With Quote
Old 07/01/2020, 01:53 PM   #8
Maxwell
Little Clucker
 
Join Date: May 2019
Posts: 2
Reputation: 0
Default Re: IRC (Internet Relay Chat)

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.
Maxwell is offline   Reply With Quote
Old 07/01/2020, 04:54 PM   #9
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,892
Reputation: 1321
Default Re: IRC (Internet Relay Chat)

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?
Pottus is offline   Reply With Quote
Old 07/01/2020, 05:17 PM   #10
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,892
Reputation: 1321
Default Re: IRC (Internet Relay Chat)

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.
Pottus 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
[Tutorial] About IRC (Internet Relay Chat) iZN Tutorials 11 24/08/2016 12:08 PM
[Tutorial] Internet Relay Chat (IRC) Inn0cent Tutorials 2 14/03/2015 08:14 PM
Admin Chat < Admins can't see chat or my text, but I can see their chat Andy_McKinley Help Archive 37 17/05/2011 08:26 PM
IRC: Internet Relay Chat Doesnt work? Slash01 Server Support 5 02/05/2011 10:06 PM
[Opinion Request] Internet Relay Chat Based Console Client maij Help Archive 6 16/03/2009 04:12 PM


All times are GMT. The time now is 12:46 PM.


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