Downloading File
Filename: rlx conn
/* rlx A BCN connection script, using no DLLs or external files. Makes no connections other than to BCN. Uses one socket per room Kills sockets for rooms you're not in after 30 seconds. Designed to be built upon - make your own addons. Usage: /bcn <username> <password> Each /join on that server window uses that account information.. ..Or you could just click the popups, if that's your thing. For scripters, if you wish to sockwrite commands, use $rsock($chan) That way you'll always get the correct room socket for that room. Otherwise, it's rlxroom. $+ $cid $+ .* for all sockets on that server window. There is an alias in the queue code that you may want to set: q.wait q.wait is the delay between 11-line sends, lowering the value makes it faster, but less stable. Have fun. Relax. Updated: 04/05/09 Creator: ~ataraxia_ */ ;################################# ;# Connection aliases. ;################################# ;Main connect alias. alias bcn { ;If there's no server windows open, use a beginning CID of 1, else increase the CID by 1. if (!$server) { hadd -m rlx lcid 1 } else { hinc rlx lcid } ;Start a local socket for the server-window to connect to, mark it with account info. socklisten rlxinit. $+ $lcid sockmark rlxinit. $+ $lcid $$1 $$2 ;Open a (new?) server-window to local socket. server $iif($server,-m) localhost $sock(rlxinit. $+ $lcid).port } ;lcid returns the next available CID for socket opening purposes. alias lcid return $hget(rlx,lcid) ;Roomsock provided for ease of editting, and writing sockwrites in events ;;Usage: $rsock($chan) alias rsock return $hget(rlx,$cid $+ .roomsock. $+ $1) alias rlx.tag return :4[15things4/14indifferent4] ;################################# ;# Connection socket events. ;# In order, more or less. ;################################# on *:socklisten:rlxinit.*:{ ;set connection id to latest server window and rename socket to $cid window. scon $scon(0) sockrename $sockname rlxinit. $+ $scid tokenize 32 $sock($sockname).mark writeini rlx.ini current passport $1- hadd -m rlx account. $+ $cid $1 ;Kludge - I hope you don't use 32 character long passports. hadd -m rlx passwdh. $+ $cid $iif($len($2) = 32,$2,$md5($2)) sockaccept rlxlocal. $+ $scon($scon(0)) sockclose $sockname ;Fake up the connect raws, give it a connected msg. sockwrite -tn rlxlocal. $+ $cid :[Things/Indifferent] 001 : $+ $me echo -s * Local socket relay connected. echo -s * 180 second heartbeat established for all sockets. echo -s * Ready for /join attempt. .timer.connection $+ $cid 0 180 pingtest $cid } on *:sockopen:rlx*.*:{ ;s.g is socket name without appended channel name ;s.c is CID for current socket/server-window combination var %s.g $gettok($sockname,1,46), %s.c $gettok($sockname,2,46) if (%s.g = rlxroom) { if ($sockerr) { .timer 1 5 resock $sockname halt } sockwrite -tn $sockname LOGINH $hget(rlx,account. $+ %s.c) $hget(rlx,passwdh. $+ %s.c) sockwrite -tn $sockname USER x x x $rlx.tag sockwrite -tn $sockname CREATE $gettok($sockname,3,46) swrite $sockname WHO $gettok($sockname,3,46) } } on *:sockread:rlx*.*:{ while ($sock($sockname).rq) { var %s.g $gettok($sockname,1,46), %s.c $gettok($sockname,2,46), %r $null | sockread %r if ($sockbr = 0) return ;set active connid to the cid from the sockname. (prevents errors with $cid, etc) if ($scid($gettok($sockname,2,46))) scid $gettok($sockname,2,46) ;-- Localhost sockread. if (%s.g = rlxlocal) { tokenize 32 %r ;Local pingtest command. if ($1 = PINGTEST) { var %x $chan(0) while (%x) { var %s rlxroom. $+ $cid $+ . $+ $chan(%x) if (!$sock(%s)) { resock %s } else { sockwrite -tn %s ping pingtest .timer. $+ %s 1 5 resock %s } dec %x } halt } ;Local timeout command. if ($1 = RESOCK) { echo -at * Reconnecting socket: $2 var %s $2 q.clr %s sockclose %s .timer -m 1 500 sockopen %s irc.buzzen.com 6667 halt } ;If we want to /join a room, open a new socket unless it already exists. :] if ($1 = JOIN) || ($1 = CREATE) { if ($sock(rlxroom. $+ %s.c $+ . $+ $2)) { sockwrite -tn rlxroom. $+ %s.c $+ . $+ $2 $1- $+ $crlf $+ WHO $2 halt } sockopen rlxroom. $+ %s.c $+ . $+ $2 irc.buzzen.com 6667 hadd -m rlx $cid $+ .roomsock. $+ $2 rlxroom. $+ %s.c $+ . $+ $2 } ;Send /parts along to the appropriate room socket. elseif ($1 = part) { if ($sock(rlxroom. $+ %s.c $+ . $+ $2)) { sockwrite -tn rlxroom. $+ %s.c $+ . $+ $2 $1- .timerclose! $+ rlxroom. $+ %s.c $+ . $+ $2 1 30 sockclose rlxroom. $+ %s.c $+ . $+ $2 halt } } ;Stop mIRC from disconnecting due to timeout. Stop uselesss mIRC raw data sending on logon. elseif (($1 == PING) && ($2 == :TIMEOUTCHECK)) sockwrite -tn $sockname PONG :TIMEOUTCHECK ;;--- I'm an idiot. 12/03/09. ;( ~av0ider_ elseif ($1 = NICK) || ($1 = USER) halt ;Send PRIVMSG to appropriate room socket if in chan. If whisper, send to all roomsockets for CID. elseif ($1 = PRIVMSG) { if ($left($2,1) != $chr(37)) swrite -tn rlxroom. $+ %s.c $+ .* WHISPER $comchan($2,1) $2 $3- else { swrite -tn rlxroom. $+ %s.c $+ . $+ $2 $1- } } else { if ($sock(rlxroom. $+ %s.c $+ . $+ $2)) swrite -tn $v1 $1- elseif ($sock(rlxroom. $+ %s.c $+ *)) swrite -tn $v1 $1- } } ;--Channel sockread. if (%s.g = rlxroom) { ;Tokenize data, while stripping style codes and replacing basic HTML entities with their plaintext equivalents. tokenize 32 $replace($regsubex(%r,/(\[style (ff:.*?;|co:.*?;|b;|i;|\bundefined\b)*?\]|\[\/style\])/ig,$null), ,$chr(32),&,&) ;Send NICK command on connect. Reply to PING. if ($2 = 001) sockwrite -tn rlxlocal. $+ $cid : $+ $me nick $3 ;Reply to pings if room socket open, close room socket if you're not in that room anymore. if ($1 = PING) { sockwrite -tn $sockname PONG lulz. if (!$chan($gettok($sockname,3,46))) sockclose $sockname } ;Close room sockets in these cases.. if ($2 = JOIN) && ($remove($gettok($1,1,33),:) = $me) .timerclose! $+ rlxroom. $+ %s.c $+ . $+ $right($3,-1) off if ($2 = KICK) && ($4 = $me) .timerclose! $+ rlxroom. $+ %s.c $+ . $+ $3 1 30 sockclose rlxroom. $+ %s.c $+ . $+ $3 ;If people are in too many rooms, let them know.. if ($2 = 999) { echo -s * You have reached your maximum connection limit. sockclose $sockname } ;Reconnect on "nickname in use." - 5 attempted retries in one minute. if ($2 = 433) { hinc -mu20 rlx inuse. $+ $sockname echo -s * Nickname already in use in $gettok($sockname,3,46) $+ . if ($hget(rlx,inuse. $+ $sockname) > 5) { sockclose $sockname | halt } .timer 1 10 resock $sockname echo -s * $ord($hget(rlx,inuse. $+ $sockname)) retry attempt of 5 - 10 second delay. } ;Ping reply for connection time-out check. if ($2 = pingtest) { .timer. $+ $sockname off halt } ;Rewrite WHISPER as PRIVMSG to make life easier for mIRC. if ($2 = WHISPER) { sockwrite -tn rlxlocal. $+ %s.c $1 PRIVMSG $4- halt } ;Send preformatted, style stripped data to mIRC for further processing. sockwrite -tn rlxlocal. $+ %s.c $1- ;Echo debug data (non-tokenized, non-stripped) to debug window if open. if ($window(@debug)) echo @debug $sockname : %r } } } on *:sockclose:rlx*.*:{ var %s.g $gettok($sockname,1,46), %s.c $gettok($sockname,2,46) ;When a localhost-socket closes, close all associated room sockets. if (%s.g = rlxlocal) sockclose rlxroom. $+ %s.c $+ * ;When a roomsocket closes, reconnect it. if (%s.g = rlxroom) resock $sockname } ;################################# ;# Queuing code. ;################################# ;Main called alias for queue. alias swrite { ;If someone mistakenly used -tn, strip it. if ($1 = -tn) || ($1 = -t) || ($1 = -n) tokenize 32 $2- ;If there's no hashtable for the socket, create one, allow instant sending. if (!$hget(q. $+ $1)) { q.ini $1 var %go 1 } ;If the queue has 0 items, add an item and begin the send. if ($q.tot($1) = 0) { ;If queue code has been initiated once in the last 800ms, wait 1500ms, otherwise, wait 10ms. .timer.q.advance. $+ $1 -m 1 $iif($hget(q. $+ $1,wait) > 8,$q.wait,10) q.advance $1 hinc -mz q. $+ $1 wait 1 .timer.q.wait. $+ $1 -m 1 800 hdel q. $+ $1 wait } ;Otherwise, just add an item. q.add $1- ;If queue was only just created, begin IMMEDIATE send. if (%go) q.advance $1 } ;Create hastables, add requisite entries. alias q.ini { hmake dataq. $+ $1 100 hmake q. $+ $1 10 hadd q. $+ $1 cur 1 } ;Alias to clear the queue of a socket, and remove timers. alias q.clr { .timer.q.* $+ . $+ $1 off hdel -w dataq. $+ $1 * hadd q. $+ $1 cur 1 } ;Various aliases, in order: ;- queue total, queue current item, queue data for item N, add data to queue, queue wait time in milliseconds. alias q.tot return $hget(dataq. $+ $1,0).item alias q.cur return $hget(q. $+ $1,cur) alias q.data return $hget(dataq. $+ $1,$2) alias q.add hadd dataq. $+ $1 $calc($q.tot($1) + 1) $$2- alias q.wait return 1200 ;Loop through queue and send data. alias q.advance { var %x 0 ;For every ten items.. while (%x <= 10) { inc %x ;If there's data to send, send it. if ($q.tot($1) >= $q.cur($1)) { if ($sock($1)) sockwrite -n $1 $q.data($1,$q.cur($1)) hinc q. $+ $1 cur 1 } ;Otherwise, stop sending. else { if ($q.tot($1) = 0) halt hdel -w dataq. $+ $1 * hadd q. $+ $1 cur 1 } } ;Continue the queue in 1500ms. .timer.q.advance. $+ $1 -m 1 $q.wait q.advance $1 } ;################################# ;# Dialogs, and individual dialog ;# related aliases. ;################################# alias pport dialog $iif($dialog(passports),-v,-m) passports passports dialog passports { title "Passport [/pport]" option dbu toolbar size -1 -1 108 45 combo 1, 3 4 103 39, size drop button "Connect with selected passport", 2, 3 17 102 12, flat button "Create new passport...", 3, 3 31 102 12, flat } on *:dialog:passports:*:*: { if ($devent = init) ppdlg.init if ($devent = sclick) { if ($did = 2) { bcn $did(1) $readini(rlx.ini,passports,$did(1)) dialog -x $dname } if ($did = 3) newpp } } alias newpp dialog $iif($dialog(newpassport),-v,-m) newpassport newpassport dialog newpassport { title "New Passport. [/newpp]" option dbu toolbar size -1 -1 120 40 text "Address:", 1, 5 5 28 8, right text "Password:", 2, 5 16 28 8, right edit "", 3, 33 4 85 10 edit "", 4, 33 15 85 10, pass button "Add passport", 5, 4 26 114 11, flat } on *:dialog:newpassport:sclick:5: { if (!$did(4)) || (!$did(3)) { noop $input(Not enough parameters specified. $crlf $+ Please make sure that all fields are filled out.,ow,Error adding passport.) halt } writeini rlx.ini passports $did(3) $md5($did(4)) ppdlg.init dialog -x $dname } alias ppdlg.init { if ($lines(rlx.ini) > 1) { var %x $ifmatch did -r passports 1 ;Fill the dropdown with passports. while (%x > 1) { if ($chr(64) isin $gettok($read(rlx.ini,%x),1,61)) did -a passports 1 $v2 dec %x } did -c passports 1 1 } } dialog accesslist { title "Access List [/acc]" option dbu size -1 -1 155 140 list 1, 2 3 151 82, size button "Delete selected", 2, 3 86 74 12, flat button "Refresh list", 3, 78 86 74 12, flat box "Selected access information:", 4, 2 99 151 39 list 5, 158 3 175 143, size text "Access type:", 6, 5 106 70 8 text "Duration:", 7, 76 106 75 8 text "Placed by:", 8, 5 114 145 8 text "Matches user:", 9, 5 121 147 8 text "Reason given:", 10, 5 128 147 8 } on *:dialog:accesslist:sclick:*:{ if ($did(1).sel) tokenize 32 $utfdecode($did(5,$did(1).sel)) if ($did = 1) { ;Fill in the access information. did -ra $dname 6 Access type: $1 did -ra $dname 7 Duration: $iif($3 = 0,Permanent.,$3 minutes.) did -ra $dname 8 Placed by: $gettok($4,1,33) did -ra $dname 9 Matches user: $iif($ial($2,1),$utfdecode($ial($2,1).nick),Unknown user.) did -ra $dname 10 Reason given: $5- } if ($did = 2) { access $hget(rlx,acc.chan) delete $1-2 did -r $dname 1 acc $hget(rlx,acc.chan) } if ($did = 3) { did -r $dname 1 acc $hget(rlx,acc.chan) } } alias acc { if (!$chan) && (!$1) halt var %c $iif($1,$1,$chan) hadd -m4 rlx acc. $+ %c true hadd -m rlx acc.chan %c dialog $iif($dialog(accesslist),-v,-m) accesslist accesslist access %c list } raw *:*:{ var %n $numeric if (!$hget(rlx,acc. $+ $2)) halt if (%n = 804) && ($dialog(accesslist)) { did -a accesslist 5 $3- did -a accesslist 1 $4 } if (%n = 805) hdel rlx acc. $+ $2 } ;################################# ;# Popups and themey suchlike. ;################################# ;--Stupid nickname echos. on ^*:NICK:if (!$nick) || ($nick = $me) || ($newnick = $me) haltdef menu status { rlx .Connection passport setup:pport .Open $iif($server,new) connection with last passport:bcn $readini(rlx.ini,current,passport) .$iif($server != [Things/Indifferent],$style(2)) Disconnect current rlx server window:unbcn } menu channel { rlx .Access list...:acc .Connection passport setup...:pport .Open new connection with last passport:bcn $readini(rlx.ini,current,passport) .$iif($server != [Things/Indifferent],$style(2)) Disconnect rlx:unbcn } menu nicklist { $iif($$1 isowner #,$style(1)) Owner:mode # $iif($1 isowner #,-q,+q) $$1 $iif($$1 isop #,$iif($$1 !isowner #,$style(1))) Host:mode # $iif($1 isop #,-o,+o) $$1 $iif($$1 ishop #,$style(1)) Halfop:mode # $iif($1 ishop #,-h,+h) $$1 $iif($$1 isvo #,$style(1)) Voice:mode # $iif($1 isvo #,-v,+v) $$1 - Make participant: mode # -qohv $$1 $$1 $$1 $$1 - $iif($numtok($snicks,44) < 2,$style(2)) Mass user mode .+voice: mmode +v $$snicks .-voice: mmode -v $$snicks .- .+hop: mmode +h $$snicks .-hop: mmode -h $$snicks .- .+host: mmode +o $$snicks .-host: mmode -o $$snicks .- .+owner: mmode +q $$snicks .-owner: mmode -q $$snicks .- .Kick: ..Are you sure?:mkick $$snicks } alias mkick { var %n $$1, %x 1 while (%x <= $numtok(%n,44)) { kick # $gettok(%n,%x,44) - $gettok(%n,%x,44) inc %x } } alias mmode { var %m $$1, %n $$2, %x 1 while (%x <= $numtok(%n,44)) { mode # %m $gettok(%n,%x,44) inc %x } } alias unbcn { var %z $cid disconnect sockclose rlx. $+ $cid $+ .* } ;--EOF. ;-- ~ataraxia_