Page 1 of 1

[SNIPPET] DX-IRC

PostPosted: Wed Jul 04, 07 12:31 pm
by Alex
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 :P

EDIT: Fixed a small bug.

PostPosted: Wed Jul 04, 07 12:45 pm
by Dae
the script is damn good

PostPosted: Wed Jul 04, 07 12:48 pm
by Alex
Hehe, just fixed a small bug =/ :P Should work now.

PostPosted: Wed Jul 04, 07 1:00 pm
by Dae
Code: Select all
SendCommand("NICK"@Username); // An ugly hack. To prevent time-outs.

Isn't there some "ping? pong!" action in IRC? In earlier versions of mIRC in network status those messages were constantly appearing (now they're hidden by default).

PostPosted: Wed Jul 04, 07 1:08 pm
by Alex
Hmm, I don't think so. At least, the server should ping me, and the bot always timed out.

PostPosted: Wed Jul 04, 07 1:15 pm
by Dae
maybe the bot should ping the server ?

also, found that option in mIRC: untick "hide ping/pong events" in Alt + O > IRC > Options

PostPosted: Wed Jul 04, 07 2:10 pm
by ~ô¿ô~Nobody~
OH, is that the hax DX irc chat thing? :D

PostPosted: Thu Jul 05, 07 11:40 am
by Alex
I don't know if the bot pings the server. Another thing by the way: The script was synchronized on quicknet.nl (the irc server), so I'm not sure if it works on other irc servers.