1# DCC channels.. by Ian Frechette (shoot me now) (make it stop) 2# Started 2-13-93 3# To use.. 4# /load dccchan 5# /makeid nickname 6# /openport port (to listen for connection on port) or 7# /closeport port (close listening port) 8# /opencon host port (to connect to existing dcc channel) 9# /whoon (list who is on the channel) 10# /query /d_msg 11# type to your hearts content 12# 13# /dpart to leave 14 15@ RCS.dccchan = [$$Header: /home/cvs/ircii/script/dccchan,v 1.2 2001/08/12 15:44:17 mrg Exp $$] 16@ dchan.portnum = 7000 17 18# open listening connection on the specified port number 19# the $dchan.portnum is default if not given. 20alias openport { 21 if (myuniquid) 22 { 23 if ([$0]) 24 { @ dchan.portnum = [$0] } 25 echo *** Opening listen on port $listen($dchan.portnum) 26 } 27 { 28 echo *** Please use /makeid <nick> before opening port 29 } 30} 31 32alias closeport { 33 if ([$0]) 34 { 35 if ([$0]) 36 { @ dchan.portnum = [$0] } 37 echo *** closing listen on port $dchan.portnum 38 dcc close raw_listen $dchan.portnum 39 } 40 { 41 echo *** Please specify portnumber. /closeport <portnum> 42 } 43} 44 45# generate a unique_id NICK_TIME and nickname 46alias makeid { 47 if ([$0]) 48 { 49 if (!myuniquid) 50 { 51 @ myuniquid = encode($0_$time()) 52 @ mynick = [$0] 53 } 54 echo *** Your nickname is $mynick and uniquid is $decode($myuniquid) 55 } 56 { 57 echo *** Please supply a nickname. /makeid nickname 58 } 59} 60 61# opencon open a connection to another machine and port 62# $0 == name of machine 63# $1 == port number 64alias opencon { 65 if (myuniquid) 66 { 67 echo *** Opening a connection to $0 on port $1 68 @ ctmp = connect($0 $1) 69 if (ctmp) 70 { 71 eval @ co.$ctmp = [$ctmp $0] 72 update_co $ctmp 73 echo *** Connection to $0 established on port $1 74 } 75 { 76 echo *** Failed to connect to $0 on port $1 77 } 78 } 79 { 80 echo *** Please use /makeid <nick> before opening port 81 } 82} 83 84# strip ^M's from a line 85alias sm @ function_return = strip( 86 $*) 87 88# strip the colon from the beginning of a line if there is 1. 89alias sc @temp = [$*];if ([$[1]0] == [:]) { @function_return = mid(1 ${@temp -1} $temp) } { @ function_return = temp } 90 91 92^on #-dcc_raw -45 * debug RAW: $* 93^on ^dcc_raw * 94^on #^dcc_raw 45 "% % N *" add_connection $0 $1 95^on #^dcc_raw 45 "% % C*" remove_connection $sm($0) 96^on #^dcc_raw 45 "% % D MEMBER *" add_member $sm($0 $4 $5) 97^on #^dcc_raw 45 "% % D R_MEMBER *" rem_member $sm($0 $4) 98^on #^dcc_raw 45 "% % D MSG *" do_msg $sm($0 $4-) 99^on #^dcc_raw 45 "% % D NICK *" do_nick $sm($0 $4 $5) 100^on #^dcc_raw 45 "% % D END *" # do nothing for now 101 102 103# d_msg - send a message to everyone else on channel 104alias d_msg { 105 toall MSG $myuniquid $* 106 xecho -level DCC +> $* 107} 108 109# do_msg - display message and pass on to rest of tree 110# $0 == id 111# $1 == NICK_TIME 112# $2- == content of message 113alias do_msg { 114 if (rstat[$0] > 0) 115 { 116 xecho -level DCC +$nicks[$1]+ $2- 117 toallbutone $0 MSG $1 $2- 118 } 119} 120 121# structure co.<connection id> stores <con id> and <host> 122# Add a connection when someone connects to this node 123alias add_connection { 124 debug ADD_CONNECTION: $* 125 eval @ co.$0 = [$0 $1] 126 # rstat is registered status. 0 - no members, >0 - members registered 127 eval @ rstat.$0 = 0 128 update_co $0 129} 130 131# update_co - update information for remote connection.. Basically 132# just send it everything we know. 133# $0 == id of link to fill in. 134alias update_co { 135 smsg $0 MEMBER $myuniquid $mynick 136 foreach nicks ii { 137 smsg $0 MEMBER $ii $nicks[$ii] 138 debug SENDMEMBER: $ii $nicks[$ii] 139 } 140 # not used yet, but for future expandability 141 smsg $0 END MEMBER 142} 143 144# add_member - add a node to the database 145# other nodes will send MEMBER 146# $0 == id 147# $1 == NICK_TIME (nick encoded + time) unique id 148# $2 == nick 149alias add_member { 150 if (member[$1]) 151 { 152 debug ADD_MEMBER Dup.. removing $* 153 # remove connection silently 154 # if we told the rest of the net members would be removed 155 # accidentally.. Just pretend this connection didn't happen 156 # ARRRRG.. can't do this.. can't remove a dcc connection from 157 # inside an ON DCC. If I delay with timer 0 close.. then it 158 # defeats the purpose here which was to try to head off any 159 # already pending garbage. 160 timer 0 ^dcc close raw $co[$0] 161 ^assign -co.$0 } 162 { 163 debug ADD_MEMBER Adding: $* 164 # needs to send MEMBER <nick> <time> to other members 165 eval @ rstat.$0 = rstat.$0 + 1 166 toallbutone $0 MEMBER $1- 167 eval @ cons.$0.$1 = [$0] 168 # struct member.NICK_TIME id 169 eval @ member.$1 = [$0] 170 eval @ nicks.$1 = [$2] 171 echo *** Info: $2 \($decode($1)\) has joined the channel 172 } 173} 174 175# rem_member remove a node/member from the database 176# $0 == id 177# $1 == NICK_TIME (uniqid) 178alias rem_member { 179 debug REM_MEMBER $* 180 if (rstat[$0]) 181 { 182 echo *** Info: $nicks[$1] \($decode($1)\) has left the channel 183 toallbutone $0 R_MEMBER $1 184 ^assign -member.$1 185 ^assign -nicks.$1 186 ^assign -cons.$0.$1 187 if ((rstat[$0] = rstat[$0] - 1) == 0) {^assign -rstat.$0} 188 } 189} 190 191# remove_connection remove a connection 192# $0 == id of connection to remove 193alias remove_connection { 194 timer 0 ^dcc close raw $co[$0] 195 debug REM_CONNECTION: ^dcc close raw $co[$0] 196 # remove any members introduced by this connection 197 # All of them.. all parts. This should only happen 198 # when a local connection closes. 199 # The removal of rstat.$0 is handled within rem_member 200 foreach cons.$0 ii { 201 ^assign -cons.$0.$ii 202 ^rem_member $0 $ii 203 } 204 # remove connection info 205 ^assign -co.$0 206} 207 208 209# alias toallbutone - send message to all but one direction 210# $0 omit 211# $1 COMMAND 212# $2- args 213alias toallbutone { 214 foreach co ii { 215 if (ii != [$0]) {smsg $ii $1 $2-} 216 } 217} 218 219# alias toall - send message to all connections 220# $0 COMMAND 221# $1- args 222alias toall { 223 foreach co ii { 224 smsg $ii $0- 225 } 226} 227 228# alias smsg Send a line through a given link 229# smsg <id> <COMMAND> <args> 230# send a message to a specific connection. 231# $0 == id 232# $1 == COMMAND 233# $2- == args to command or text 234alias smsg { 235 dcc raw $co[$0] $1- 236} 237 238 239# output debugging information to window 1 240# $* == line with any text 241alias debug { 242 if (ddebug) { xecho -window 1 $* } 243} 244 245# whoon show who is on channel 246# no args. 247alias whoon { 248 echo *** Current channel members online 249 echo *** Nick Unique ID 250 echo *** $[30]mynick $decode($myuniquid) 251 foreach nicks ii { 252 echo *** $[30]nicks[$ii] $decode($ii) 253 } 254} 255 256 257# d_nick Send a nick change request to update nickname. 258# $0 == new nickname 259alias d_nick { 260 if ([$0]) 261 { 262 toall NICK $myuniquid $0 263 echo *** DCC Nickname changed from $mynick to $0 264 @ mynick = [$0] 265 } 266 { echo *** please specify a nickname. /d_nick nickname } 267} 268 269# do_nick Change the nickname information and send a notice to 270# all other channel members 271# $0 == id 272# $1 == uniquid 273# $2 == New nickname 274alias do_nick { 275 if (rstat[$0] > 0) 276 { 277 xecho -level DCC *** Info: $nicks[$1] has changed their nick to $2 278 if (nicks[$1]) { 279 @ nicks[$1] = [$2] 280 toallbutone $0 NICK $1 $2 281 } 282 } 283} 284 285 286# d_part part the dcc channel.. close the connection 287# No args.. 288alias d_part { 289 xecho -level DCC *** Leaving channel. 290 foreach co ii { 291 debug D_PART: remove connection $ii 292 remove_connection $ii 293 } 294} 295 296# d_help 297# provide help 298 299if (RCS.ircIId != []) 300{ 301 echo *** You cannote currently load both dccchan and ircIId 302 echo *** certain functions are now corrupt 303} 304