- Code: Select all
//=============================================================================
// Link. IRC Tryout
//=============================================================================
class Link extends TCPLink config (IRC);
var config string Server;
var config string Channel;
var config string Username;
var config int Port;
function PostBeginPlay()
{
local Spec _Spec;
_Spec = Spawn(Class'Spec');
if(_Spec != None)
{
_Spec._IRC = self;
}
Super.PostBeginPlay();
StartLink();
SetTimer(20.0,True);
}
function Timer()
{
SendCommand("NICK"@Username); // An ugly hack. To prevent time-outs.
}
function StartLink()
{
Resolve(Server);
}
event ResolveFailed()
{
Log("Error, resolve failed");
}
event Resolved( IpAddr Addr )
{
Addr.Port = Port;
BindPort();
ReceiveMode = RMODE_Event;
LinkMode = MODE_Line;
Open(Addr);
}
event Opened()
{
SendCommand("USER Console hostname servername :Console");
SendCommand("NICK"@Username);
SendCommand("JOIN"@Channel);
}
function SendMessage(string _Msg)
{
SendCommand("PRIVMSG"@Channel@":"$_Msg);
}
function SendCommand(string _Command)
{
SendText(_Command $ Chr(10));
}
event ReceivedLine( string Line )
{
local string _Original;
local string _Sender;
local string _TmpString;
local DeusExPlayer _Player;
_Original = Line;
Line = Left(Line,Len(Line)-2);
// This part here, is the command part. It parses the text send from IRC to DX, and as you can see, it already has 2 command's installed (!talk & !players)
// It's quite old, so please forgive me for the un-tidyness of the code :P
if(instr(Line, "PRIVMSG"@Channel@":") != -1)
{
Line = Right(Line, Len(Line)-instr(Line,"PRIVMSG"@Channel@":")-Len("PRIVMSG"@Channel@":"));
_Sender = Left(_Original, InStr(_Original,"!"));
_Sender = Right(_Sender, Len(_Sender)-1);
if(Left(Line,6) == "!talk ")
{
Line = _Sender$"(IRC):"@Right(Line, Len(Line)-6);
ForEach AllActors(class 'DeusExPlayer', _Player)
{
if(_Player != None)
{
_Player.ClientMessage(Line, 'Say', True);
}
}
}
else if(Left(Line,8) == "!players" && Left(Line,9) == "!players")
{
ForEach AllActors(class 'DeusExPlayer', _Player)
{
if(_Player != None)
{
_TmpString = _TmpString$_Player.PlayerReplicationInfo.PlayerName$"("$_Player.PlayerReplicationInfo.PlayerID$"), ";
}
}
if(Len(_TmpString) == 0)
{
_TmpString = "None...";
}
else
{
_TmpString = Left(_TmpString, Len(_TmpString)-2);
}
_TmpString = "Online Players:"@_TmpString;
SendMessage(_TmpString);
}
}
}
defaultproperties
{
Server="server here"
Channel="#channel"
Username="username"
Port=6667
}
And to send messages from DX into the IRC server, you must use a spectator class:
- Code: Select all
//=============================================================================
// Spectator.
//=============================================================================
class Spec extends MessagingSpectator;
var IRC _IRC;
function ClientMessage(coerce string S, optional name Type, optional bool bBeep)
{
_IRC.SendMessage(S);
}
defaultproperties
{
}
It should work, I had to edit it partially because I have it a bit differently.
But... It's not really useable. I tried it, and my bot got kicked by the irc server (SERVER, not CHANNEL ) for flooding, because there were a lot of messages send by DX to IRC. And almost noone uses IRC here anyways... but I just wanted to post it
EDIT: Fixed a small bug.