mIRC Home    About    Download    Register    News    Help

Print Thread
#129251 03/09/05 10:56 PM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Ok, I've been working on a script that Auto Joins channels but probably different to what you're thinking. What I am doing is giving users the ability to specify the server and the channels for that server.

They can specify another server and specify channels for only that server if you are with me?

Reason being they might want to conenct to a server wheres there is one channel on one and the second server there is not. It works fine thus far but I am needing third-party opinions on how to improve and such.

Now when each server is saved it has its own folder example, its so I could use chans.dat for all servers. smile

autojoin\ukchat.tiscali.co.uk\chans.dat

Keeping in mind I have added each server its own hash table so that can stay example: $hget(ukchat.tiscali.co.uk) it will be used later on in a different script of mine. Other than that here's the code:

Code:
On *:Start: {
  hmake servers 10
  if ($isfile(autojoin\servers.dat)) {
    hload -i servers autojoin\servers.dat
    var %x = $lines(autojoin\servers.dat)
    while (%x) {
      if (*=* iswm $read(autojoin\servers.dat,%x)) {
        hmake $gettok($v2,1,61) 10
        hmake $+($gettok($v2,1,61),_chans) 10
        if ($isfile($+(autojoin\,$gettok($v2,1,61),\,chans.dat))) hload -i $+($gettok($read(autojoin\servers.dat,%x),1,61),_chans) $+(autojoin\,$gettok($read(autojoin\servers.dat,%x),1,61),\,chans.dat)
      }
      dec %x
    }
  }
}

On *:Connect: {
  if (%aj.status == on) {
    if ($isfile(autojoin\servers.dat)) {
      var %x = $lines(autojoin\servers.dat)
      while (%x) {
        if (*=* iswm $read(autojoin\servers.dat,%x)) {
          if ($gettok($v2,1,61) == $server) {
            var %chans = $lines($+(autojoin\,$server,\chans.dat))
            while (%chans) {
              if (*=* iswm $read($+(autojoin\,$server,\chans.dat),%chans)) join $gettok($v2,1,61)
              dec %chans
            }
          }
        }
        dec %x
      }
    }
  }
}
dialog autojoin {
  title "Auto Join Channels by Andy"
  size -1 -1 184 186
  option dbu
  combo 1, 2 3 87 100, size 
  button "Add", 2, 7 126 29 10
  box "Auto Join Status", 5, 63 144 57 20
  check "On", 6, 75 152 31 10, flat
  box "Adding/Removing Servers", 7, 4 116 70 26
  button "Remove", 8, 41 126 29 10
  box "Adding/Removing Chans", 4, 111 116 70 26
  button "Remove", 9, 148 126 29 10
  button "Add", 3, 116 126 29 10
  combo 10, 95 3 87 100, size
  button "[X]", 11, 73 170 37 12
}

On *:Dialog:autojoin:init:0: {
  if (%aj.status == on) did -c $dname 6
  if ($hget(servers)) {
    var %x = $hget(servers,0).item
    while (%x) {
      did -a $dname 1 $hget(servers,%x).data
      dec %x
    }
  }
}

On *:Dialog:autojoin:sclick:1: {
  var %x = $hget($+($did($dname,$did),_chans),0).item
  did -r $dname 10
  while (%x) {
    did -a $dname 10 $hget($+($did($dname,$did),_chans),%x).data
    dec %x
  }
}

On *:Dialog:autojoin:sclick:2: {
  if (!$isdir(autojoin)) mkdir autojoin
  var %aj.server = $did($dname,1).text
  if (%aj.server) {
    if (!$isdir($+(autojoin\,%aj.server))) mkdir $+(autojoin\,%aj.server)
    if (!$hget(%aj.server)) hmake %aj.server 10
    if (!$hget(servers)) hmake servers 10
    hadd servers %aj.server %aj.server
    did -a $dname 1 %aj.server
  }
  hsave -i servers autojoin\servers.dat
}

On *:Dialog:autojoin:sclick:3: {
  if (!$did($dname,1).sel)  {
    echo -a *** Please select a server from the first list to add channels to add channels to. 
    echo -a *** Remember you can specift the channels to join for each different server. :)
  }
  else {
    if (!$did($dname,10)) echo Please enter a channel to add.
    else { 
      if (!$hget($+($did($dname,1),_chans))) hmake $+($did($dname,1),_chans) 10
      hadd $+($did($dname,1),_chans) $did($dname,10) $did($dname,10)
      did -a $dname 10 $did($dname,10)
      hsave -i $+($did($dname,1),_chans) $+(autojoin\,$did($dname,1),\chans.dat)
    }
  }
}

On *:Dialog:autojoin:sclick:6: {
  set %aj.status $iif($did($dname,$did).state == 1,on,off)
}

On *:Dialog:autojoin:sclick:8: {
  if ($did($dname,1).sel) {
    if ($hget($did($dname,1))) {
      hdel servers $did($dname,1)
      hfree $did($dname,1)
    }
    if ($hget($+($did($dname,1),_chans))) hfree $hget($+($did($dname,1),_chans))
    if ($isfile($+(autojoin\,$did($dname,1),\,chans.dat))) .remove $+(autojoin\,$did($dname,1),\,chans.dat)
    rmdir $+(autojoin\,$did($dname,1))
    did -d $dname 1 $did($dname,1).sel
  }
  hsave -i servers autojoin\servers.dat
}

On *:Dialog:autojoin:sclick:9: {
  if (($did($dname,1).sel) && ($did($dname,10).sel)) {
    if ($hget($+($did($dname,1),_chans))) {
      hdel $v1 $did($dname,10)
      did -d $dname 10 $did($dname,10).sel
      hsave -i $+($did($dname,1),_chans) $+(autojoin\,$did($dname,1),\,chans.dat))
    }
  }
}

On *:Dialog:autojoin:sclick:11: {
  dialog -x $dname $dname
}


I look forward to seeing your replies. smile

-Andy

#129252 04/09/05 03:54 AM
Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
As usual... NICE work! gj andy laugh wheres my keyget dialog LOL


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
#129253 04/09/05 04:12 AM
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Thanks man, it seems to work so far but I want to improve my code a little I know it can but everything I code I always take the long way round when there's more simplistic ways.

That dialog you speak of, I couldn't find it at all after spending an hour on it, want to tell me the website and such in prv or send me a message on MSN Messenger? See what I can't do for you, I'll have it written up by tomorrow. smile

-Andy


Link Copied to Clipboard