[SNIPPET] DX-IRC

The best and quickest support by a group of top-notch editing specialists, guaranteed!

Moderator: Forum Guards

[SNIPPET] DX-IRC

Postby Alex » Wed Jul 04, 07 12:31 pm

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.
Last edited by Alex on Wed Jul 04, 07 12:48 pm, edited 1 time in total.
Alex
Alpha
 
Posts: 8067
Joined: Wed Nov 12, 03 4:51 pm

Postby Dae » Wed Jul 04, 07 12:45 pm

the script is damn good
User avatar
Dae
Alpha
 
Posts: 12086
Joined: Sat Sep 06, 03 4:40 pm

Postby Alex » Wed Jul 04, 07 12:48 pm

Hehe, just fixed a small bug =/ :P Should work now.
Alex
Alpha
 
Posts: 8067
Joined: Wed Nov 12, 03 4:51 pm

Postby Dae » Wed Jul 04, 07 1:00 pm

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).
User avatar
Dae
Alpha
 
Posts: 12086
Joined: Sat Sep 06, 03 4:40 pm

Postby Alex » Wed Jul 04, 07 1:08 pm

Hmm, I don't think so. At least, the server should ping me, and the bot always timed out.
Alex
Alpha
 
Posts: 8067
Joined: Wed Nov 12, 03 4:51 pm

Postby Dae » Wed Jul 04, 07 1:15 pm

maybe the bot should ping the server ?

also, found that option in mIRC: untick "hide ping/pong events" in Alt + O > IRC > Options
User avatar
Dae
Alpha
 
Posts: 12086
Joined: Sat Sep 06, 03 4:40 pm

Postby ~ô¿ô~Nobody~ » Wed Jul 04, 07 2:10 pm

OH, is that the hax DX irc chat thing? :D
Nobody is perfect...
------------------------------
Longc[A]t wrote:I still think Dae is a russian spambot.

~[A]Daedalus~ wrote:There will be a day when my patience goes away and you, along with all who rant with you, will get banned.

ô¿ô¥[GODZ]¥NOCHANC wrote:I can ban any one I want ANY time I want. You have no rights here.
User avatar
~ô¿ô~Nobody~
Alpha
 
Posts: 2520
Joined: Fri Dec 31, 04 3:20 pm
Location: Proclarush Taonas

Postby Alex » Thu Jul 05, 07 11:40 am

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.
Alex
Alpha
 
Posts: 8067
Joined: Wed Nov 12, 03 4:51 pm


Return to Editing issues

Who is online

Users browsing this forum: No registered users and 5 guests
cron