Socket Channel Link

By sk68 on Sep 24, 2010

A quiet little channel link that works entirely on socket connections.

Features
Multi-server
Runs quietly in the background
Mostly self-sufficient
Easy to use

Commands
/startlink [channel2 ...] [server2 [channel2 ...] ...]
/stoplink [reason]

Updates
1.1
Fixed nick changing glitch
Fixed problem with quit/part messages
Custom bot nick
1.2
Bot will now announce channels/servers that are linked upon joining a channel

WARNING! This script will accept unlimited servers and unlimited channels, your PC and/or the servers you connect to will not.

;Config

;Nick for bot to use
alias linkbotnick return LinkBot

;End of Conf

alias startlink { 
  if (*.*.* !iswm $1) { echo -at First parameter must be a server, link aborted 
    return
  }
  var %x 1
  while (%x <= $0) { 
    var %c $gettok($1-,%x,32)
    if (*.*.* iswm %c) { set %linkservers $addtok(%linkservers,%c,32) }
    elseif ($left(%c,1) == $chr(35)) { set %linkchannels. [ $+ [ $gettok(%linkservers,-1,32) ] ] $addtok(%linkchannels. [ $+ [ $gettok(%linkservers,-1,32) ] ],%c,44) }
    else { var %i $addtok(%i,%c,32) }
    inc %x
  }
  if (%i) { echo -at ERROR! Invalid paramters: %i $+ . Parameters must be channels or servers }
  var %s $numtok(%linkservers,32)
  while (%s) {
    if (!%linkchannels. [ $+ [ $gettok(%linkservers,%s,32) ] ]) { var %is $addtok(%is,$gettok(%linkservers,%s,32),32) }
    dec %s
  }
  if (%is) { echo -at ERROR! Channels were not specified for the following servers: %is }
  else { var %x $numtok(%linkservers,32) 
    while (%x) { 
      sockopen $+(linkbot-,$gettok(%linkservers,%x,32)) $gettok(%linkservers,%x,32) 6667
      sockmark $+(linkbot-,$gettok(%linkservers,%x,32)) %linkchannels. [ $+ [ $gettok(%linkservers,%x,32) ] ]
      dec %x
    }
  }
}

on *:SOCKOPEN:linkbot-*:{ 
  sockwrite -nt $sockname nick $linkbotnick
  sockwrite -nt $sockname user LinkBot LinkBot LinkBot :mIRC Socket Link Bot by CodeNinja
  sockwrite -nt $sockname join $replace(%linkchannels. [ $+ [ $gettok($sockname,2-,45) ] ],$chr(32),$chr(44))
}

on *:SOCKREAD:linkbot-*:{ sockread %data
  if ($sockerror) { stoplink $sockname encountered an error | halt }
  tokenize 32 %data
  if (($2 == PRIVMSG || $2 == MODE) && $3 == $linkbotnick) { return }
  elseif ($2 == KICK && $4 == $linkbotnick) { sockwrite -nt $sockname JOIN $3 }
  elseif (47? iswm $2) { delinkchan $gettok($sockname,2-,45) $4 }
  elseif ($1 == PING) { sockwrite -nt $sockname PONG $2 }
  elseif ($2 == JOIN && $+(:,$linkbotnick,!*@*) iswm $1) { showlinks $sockname $right($3,-1) }
  elseif ($regex($2,/(privmsg|topic|mode|kick|nick|quit|part|join)/i)) { botrelay $sockname $2 $remove($1,:) $3- }
}

on *:SOCKCLOSE:linkbot-*:{ stoplink $sockname connection closed }

alias -l botrelay { var %x $sock(linkbot-*,0)
  var %chan $iif($left($4,1) == $chr(35) || $2 == JOIN,$iif($2 == JOIN,$right($4,-1),$4),ALL) 
  while (%x) { 
    var %name $sock(linkbot-*,%x) 
    var %y $numtok($sock(%name).mark,44)
    while (%y) { 
      if ($gettok($sock(%name).mark,%y,44) != %chan) { sockwrite -nt %name PRIVMSG $gettok($sock(%name).mark,%y,44) $+(:,7,$chr(91),14,$replace($gettok($1,2-,45),.,7.14),7/14,%chan,7,$chr(93),) $getlinkstr($gettok($3,1,33),$gettok($3,2,33),$iif($4 == %chan,$5-,$4-)). [ $+ [ $2 ] ] }
      dec %y
    }
    dec %x
  }
}

alias stoplink { var %x $sock(linkbot-*,0)
  while (%x) { 
    sockwrite -nt $sock(linkbot-*,%x) QUIT :Link stopped: $iif($1,$1-,No Reason)
    sockclose $sock(linkbot-*,%x)
    dec %x
  }
  unset %linkservers
  unset %linkchannels.*
}

alias -l getlinkstr { 
  ;Nick Host Params
  ;(privmsg|topic|mode|nick|kick|quit|part)
  ;echo -t @debug $1 $chr(124) $2 $chr(124) $3 $chr(124) $4 $chr(124) $5
  if ($prop == privmsg) { if ($+(:,$chr(1),ACTION,*,$chr(1)) iswm $3-) { return * $1 $right($remove($3,$chr(1)),-8) }
    else { return $+(<,$1,>) $right($3,-1) }
  }
  elseif ($prop == topic) { return * $1 has changed topic to $+(",$right($3,-1),") }
  elseif ($prop == mode) { return * $1 has set mode: $3 }
  elseif ($prop == kick) { return * $1 has kicked $gettok($3,1,32) $+($chr(40),$right($gettok($3,2-,32),-1),$chr(41)) }
  elseif ($prop == quit) { return * $1 $+($chr(40),$2,$chr(41)) has quit $+($chr(40),$right($3,-1),$chr(41)) }
  elseif ($prop == part) { return * $1 $+($chr(40),$2,$chr(41)) has parted $+($chr(40),$right($3,-1),$chr(41)) }
  elseif ($prop == join) { return * $1 $+($chr(40),$2,$chr(41)) has joined }
  elseif ($prop == nick) { return * $1 has changed nick to $right($3,-1) }
}

alias -l showlinks { var %l
  var %x $numtok(%linkservers,32)
  while (%x) { 
    var %l $addtok(%l,$gettok(%linkservers,%x,32),32)
    var %l $addtok(%l,%linkchannels. [ $+ [ $gettok(%linkservers,%x,32) ] ],32)
    dec %x
  }
  sockwrite -nt $1 PRIVMSG $2 :The following servers/channels are linked: %l
}

alias -l delinkchan { set %linkchannels. [ $+ [ $1 ] ] $remtok(%linkchannels. [ $+ [ $1 ] ],$2,44)
  if (!%linkchannels. [ $+ [ $1 ] ]) { set %linkservers $remtok(%linkservers,$1,32)
    sockclose linkbot- [ $+ [ $1 ] ]
  }
}

Comments

Sign in to comment.
Jabblez   -  Oct 12, 2011

Pretty useful if you have multiple channels over multiple networks.

 Respond  
Pangaea   -  Oct 12, 2011

what are u changing the nick in the code for?
its a chan relay ...
room1 on server1 (users= bot, me)

me waves from server1 room2 on server2 (users= bot, me) me@server1: me waves from server1 me waves back to server1 from server2 room1 on server1 me@server2: me waves back to server1 from server2 :)
 Respond  
TheWhistler   -  Oct 11, 2011

ok i got it to connect to 2 different servers with the same channel , now just what is the purpose of this, are you suppose to see each channel text as 1 channel from both servers
for the nick change i just change all from LinkBot to BillyBob
is this suppose to relay channel text to both channels on different servers???

 Respond  
Pangaea   -  Oct 11, 2011

heya
um im not entirely sure how to firstly set this up and secondly what exactly it dose.
Is this like a multiserver channel relay bot?
only this comment___
sk68
The Whistler, the script runs on sockets, meaning it creates its own bot and uses that to link, you dont have to have a bot running, thats the beauty of it :)

Also, if no bot is joining your channel, make sure the nick it is trying to use (LinkBot by default) is available, as of now there is no support for alt nicks though, this will be added to a future update


make me think otherwise ... so the bot dosent need to be on 2 servers? or 2 chans? im a little confused there.

anyway, regarding setting this up, im also a bit confused.. you said:
/startlink [channel2 ...] [server2 [channel2 ...] ...]

  1. i assuminged initialy i do something like this
    /startlink euroserv.fr.quakenet.org #pangaea irc.undernet.org #pangaea
    = * Invalid format: $gettok (line 14, MULTI-SERVER-RELAY-2222)

  2. i thought thought the brackets should be left in so i did something like this
    /startlink <#pangaea> [irc.undernet.org <#pangaea> ]
    = * Invalid format: $gettok (line 14, MULTI-SERVER-RELAY-2222)

i tried a few other things, but same thing.. also while trying to work out how to set this up i notice this in status:
x@channels.undernet.org No such nick

x@channels.undernet.org No such nick

x@channels.undernet.org No such nick .. etc etc

anyway, not quite sure how i set it up, also i notice you have used () and [] .. is there any difference? or are you trying to emphasises that something else must go in either the () or []? or are the meant to be there as part of the code? :/
anyway looks like a nice script

 Respond  
sk68   -  Jul 25, 2011

Thanks so much, jaytea. I probably wouldn't have been able to identify the problem myself, even if I had been actively checking...

 Respond  
jaytea   -  Apr 16, 2011

i can't say for certain, but i imagine that sk68 may have been able to identify the 14th line in his script at some point during the last 6 months.

while this is bumped and in case this problem continues to plague anyone, i'll just point out that this error comes from a version of mIRC that is almost 5 years old and happens because the ',%x' is seen as being a separate local variable declaration, leaving '$gettok(' unclosed. there are two possible fixes. add the = sign, as the help file has always advised:

var %c = $gettok($1-,%x,32)

or, make sure that '%x' is separated from the comma behind it:

var %c $gettok($1-,$(%x),32)

 Respond  
Merbo   -  Apr 15, 2011

sk68: I believe line 14 is:

 var %c $gettok($1-,%x,32) 
 Respond  
sk68   -  Oct 26, 2010

hm...whats line 14? I must be looking at the wrong one :S

 Respond  
AngahX   -  Oct 26, 2010
  • Invalid format: $gettok (line 14, botlink)

can anyone help me?

 Respond  
sk68   -  Oct 02, 2010

UPDATE

 Respond  
sk68   -  Sep 26, 2010

The Whistler, the script runs on sockets, meaning it creates its own bot and uses that to link, you dont have to have a bot running, thats the beauty of it :)

Also, if no bot is joining your channel, make sure the nick it is trying to use (LinkBot by default) is available, as of now there is no support for alt nicks though, this will be added to a future update

 Respond  
TheWhistler   -  Sep 25, 2010

is the startlink suppose to work bot ways in the channel for each server relaying or just 1 way ?? only worked on the server and room it was link to, could not receive back from where it was started at , also is the rooms suppose to be registered for it to work??

 Respond  
sk68   -  Sep 25, 2010

UPDATE!

 Respond  
Cados   -  Sep 25, 2010

Good but nick change doesn't work.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.