/*
Thank You For Using SoulFly for IRC-Community Chat Network.
==========================================================================================
| If you want to edit SoulFly, unload the updater file. 
| I am very happy to help you change SoulFly to your liking so please let me know on the 
|    forum about changes you want to make. Others may learn from it and your changes will
|    be considered in future updates.
| SoulFly has many tools available to help scripters.
| I suggest making any changes in a seperate file so you won't lose it during an update.
==========================================================================================

This connection wouldn't exist if it wasn't for my good friend Bharath's help and support all these years. Thanks Mate! I miss you!
Of course, Vexation was a major influence to both of us. Thank You for your style and wit.
Thanks to JD & Tewl for guidance through my first socket connection!
Beta Testers!! Jen, Gary & Gwen THANK YOU!!!!
Thanks to Jen "the Boss"! You helped me so much with this and are simply a great friend and inspiration!
I'd also like to thank Gwen testing previous versions of SF.
Toland, thank you for all of your help and friendship. SoulFly wouldn't exist as it is today if it weren't for you. Thank you.
Paige and Amy, thanks for your encouragement and friendship. I can't wait to see what you do with this!
GaryTN :D Thanks for kicking my butt into gear when I got lazy. :D
DeeJay, thanks for all the help and support you give me!
Thank You Sunny & Moggy! err0r & David(TGK)! Pony, Dodge, Qoob, Boo, av0ider_, Philathelist, AwesomeGreg (My Friend On the Internet) & Vulcan!
And thank you Ms Bexy for keeping me company and being my everything.
Now I know I probably left people out, sorry. Come visit me in the room and give me shit for it!

1.6 testers: Extremity, Garytn, Jen, err0r, Esef, Karen, Enya, Michelle, Sera, Chain, DeeJay, AMBs (even though she won't admit to breaking it), Christian, snakey, Lynx & Donald. Thank You so much!
*/

alias -l init {
  .unset %sf_dc %sf.dc %opchk.* %axismade.* %inv_* %sfq_* %sfw_*
  if ($nopath($script(1)) != sfb_conn.mrc) load -rs1 sfb_conn.mrc
  if ($script(sfb_alias.ini)) .unload -rs $qt($ifmatch)
  if (!$alias(sfb_alias.ini)) {
    if ($findfile($mircdir,sfb_alias.ini,1)) {
      .load -a $qt($ifmatch)
      echo 11 -s 4ERROR Missing sfb_alias.ini - File Found and Loaded.
    }
    else {
      echo 11 -s You are missing an important file. 4sfb_alias.ini
      echo 9 -s SoulFly cannot operate without this file and will shut down now.
      .timersdon 1 4 /exit -n
    }
  }
  if (!$script(menu_1-6.ini)) && (!%sfb_menu) {
    if ($input(Would You Like To Install The SoulFly Menu's?,y,$v_ Menu Install)) .load -rs $qt($findfile($mircdir,menu_1-6.ini,1))
    else set %sfb_menu $true
  }
  if ($script(menu_1-6.ini)) && (*menu_*.ini !iswm $script(2)) .load -rs2 menu_1-6.ini
  if (!$isdir(lists\axis)) {
    if (!$isdir(lists)) mkdir lists
    mkdir lists\axis
  }
  if (!$isdir(lists\users)) mkdir lists\users
  h_make
  hdel -w soulfly 353.*
  hdel soulfly upd8x
  hdel soulfly away
  hdel -w soulfly sfw_*
  h_save
  if (%server = $null) set %server 167.114.203.107
  set %c160 $utfencode($chr(160))
  if (%c_ = $null) set %c_ 1
  if (%_cc = $null) set %_cc 1
  if (!%tbar) || (!$isfile(%tbar)) set %tbar imgs\1x.ico
  if ($isfile(%tbar)) .dll dlls\coreicon.dll SetIcon mirc > %tbar
  if (!$hget(soulfly,font)) hadd soulfly font ff:Trebuchet MS;
  if (!$hget(soulfly,fcolor)) hadd soulfly fcolor co:#4D9939;
  if (%error_dur = $null) set %error_dur 7
  if (!%fav) set %fav #_SoulFly_
  if (!%vrr.1) set %vrr.1 join #_SoulFly_
}
on *:start:{
  writeini soulfly.ini version $nopath($script) 1.6e
  if ($upd8_sfb_conn) writeini soulfly.ini version $ifmatch
  if ($hget(soulfly,upd8)) { hdel soulfly upd8 | return }
  init
  sf_conn
  hadd soulfly port 7778
  if (!%user.st) {
    window -efHk0l58nz @User -1 -1
    aline -c15lp @User TIME : NICKNAME : ADDRESS : ROOM
    echo 0 @User Welcome to the $unhex($ver) User List $me
    echo 8 @user Move your mouse cursor to the top right to view the recently joined users list.
    editbox @user Enter Gatekeeper Address to search for a user.
  }
  if (!$hget(soulfly,upd8x)) && ($script(upd8_2.ini)) .timerupdate 1 7 /updateme x
  credits
  if (!%f_run) {
    set %f_run $true
    .timerf_run 1 5 noop $dcx(MsgBox,asterisk $chr(9) $v_ $chr(9) Thank You For Using SoulFly for IRC-Community. $&
      $crlf =============================================== $crlf If you want to edit SoulFly, $&
      unload the updater file. $crlf $crlf I am happy to help you edit SoulFly to suit your needs so $&
      let me know on the forum about any changes you want to make. Others may learn from it and your ideas may $&
      be considered for future updates. $crlf $crlf SoulFly has many tools available to help scripters. $crlf $crlf I suggest making $&
      any changes in a seperate file so you won't lose it during an update. $crlf $&
      ===============================================)
  }
  if (%default) && (%default != %lastadd) set %lastadd %default
  if (%lastadd) {
    if ($hget(soulfly,autojoin)) return
    else fav
  }
  else sf
}
on *:disconnect:{
  if (%sf_re) return
  h_save
  if (%xdc) return
  else .timerdc 1 1 /sf_dc1
}
on *:exit:{
  if (%sf_rb) { unset %sf_rb | return }
  .unset %sf_dc %#*
  xit
}
on *:unload:remini soulfly.ini version $nopath($script)
on me:*:quit:xit
on *:active:?:{
  if ($hget(prot,$+(dw,$target)) = 4) && ($window($target)) window -c $target
  elseif (!$hget(soulfly,$+(sfw_,$target))) hadd soulfly $+(sfw_,$target) $lactive
}
on *:active:#:{
  if (# isin %wchat) {
    dll dlls\nHTMLn_2.95.dll select $window(#).hwnd
    dll dlls\nHTMLn_2.95.dll execScript scroll(0,9999999999)
  }
  if ($dialog(axis)) && ($me isop #) && (%axis.chan != #) axis #
}
on ^*:kick:#:{
  if ($knick = $me) && (# isin $hget(soulfly,away)) hpp soulfly away #
  elseif ($window($knick)) echo %_cc -t $ifmatch $asctime(|HH:nn:ss|) $knick was kicked from $hcd(#)
}

on *:close:?:{
  var %tr = $+(sfw_,$nick)
  .unset %qsound. [ $+ [ $nick ] ] %sfq_ [ $+ [ $nick ] ] %sfw_ [ $+ [ $nick ] ]
  if ($hget($+(sf,$nick))) hfree $+(sf,$nick)
  hdel soulfly %tr
}
on me:*:join:#:{
  set %sf_dc $addtok(%sf_dc,$right(#,-1),44)
  if ($right(#,-1) !isin %idl. [ $+ [ %lastadd ] ]) v_addrr $right(#,-1)
  if (# = %cr_room) {
    set %sf_dc $addtok(%sf_dc,$right(#,-1),44)
    q_ sockwrite -n $+(sf.,#) prop # unlock $+(category,$crlf,prop) # language $+(%cr_lang,$crlf,prop) # category $+(%cr_cat,$crlf,mode) # +l %cr_lim
    if (%cr_topic) q_ prop # topic %cr_topic
    if (%cr_key) {
      q_ prop # ownerkey %cr_key
      hadd prot $+(q,#) %cr_key
    }
    if (%cr_mode) q_ mode # $ifmatch
    if (%cr_welcome) q_ prop # onjoin $ifmatch 
    if (%cr_rkey) mode # +k %cr_rkey
    if (%cr_welcome) echo %_cc -t %cr_room $str($chr(160),5) $iif(%cr_welcome,$ifmatch,You are now in $hcd(%cr_room) $+ .)
    q_ sockwrite $+(sf.,#) prop # lock $+(category,$crlf,prop) # lock language
    unset %rc_did %cr_*
    if ($dialog(rc_mode)) dialog -x rc_mode rc_mode
    if ($dialog(rc_edit)) dialog -x rc_edit rc_edit
    if ($dialog(roomcreate)) dialog -x roomcreate roomcreate
  }
  .timerjchk $+ # 1 5 /op_chk #
  .timerwho $+ # 1 3 /who #
}
on ^!*:join:#:{
  if ($hget(soulfly,$+(joinsound,#))) $+(.timerjs_,#) 1 1 splay $hget(soulfly,$+(joinsound,#))
  if ($right($gettok($rawmsg,1,33),-1) !ison #) $+(.timerjnk,$address,#) 1 2 name_chk #
  if (!%nicks) $+(.timernick,$address) 1 4 /nicks $nick $address # $asctime(HH:nn)
  if (# isin $hget(soulfly,autovoice)) && ($me isop #) $+(.timerjv_,$nick,#) 1 1 pvoice 4 # $nick
  if ($window($nick)) $+(.timerqj_,$nick,#) 1 1 echo %_cc $ifmatch $asctime(|HH:nn:ss|) $nick has joined 6 $hget(soulfly,#) ...
}
on me:*:part:#:{
  if (# isin $hget(soulfly,away)) hpp soulfly away #
  if (%hop [ $+ [ # ] ]) return
  if ($hget($+(axis.,$hget(soulfly,#)))) {
    hfree $ifmatch
    unset %axismade. [ $+ [ $hget(soulfly,#) ] ] 
    if ($timer($+(autoax,#))) $+(.timerautoax,#) off
  }
  hdel soulfly #
  set %sf_dc $remtok(%sf_dc,$right(#,-1),44)
  hdel prot $+(mode,#)
  hdel prot $+(jf,#)
  hdel prot $+(818,#)
  h_save
  if (!%kick [ $+ [ $mid(#,2) ] ]) unset #
}
on ^!*:part:#:{
  $+(.timername,#) 1 1 /name_chk # $nick(#,0) $nick
  if ($window($nick)) echo %_cc -t $ifmatch $asctime(|HH:nn:ss|) $nick has left 3 $hget(soulfly,#) 
}
on ^@*:rawmode:#:{
  hadd prot $+(mode,#) $chan(#).mode  
  if ($hget(soulfly,auto-v)) {
    if ($1 = +m) && (# !isin $hgeT(soulfly,autovoice)) hpp soulfly autovoice #
    elseif ($1 = -m) && (# isin $hget(soulfly,autovoice)) hpp soulfly autovoice #
  }
}
on ^*:nick:{
  if ($nick = $null) haltdef
}
on *:op:#:{
  if ($opnick = $me) op_chk #
}
on *:owner:#:{
  if ($opnick = $me) op_chk #
}
on ^*:ctcpreply:*:haltdef
on ^*:ctcp:*:haltdef
#theme on
on ^*:text:*:#:haltdef
on ^*:notice:*:#:haltdef
#theme end
#themeq on
on ^*:text:*:?:haltdef
#themeq end
on *:notice:*:#:{
  if ($hget(prot,notice)) || ($hget(prot,$+(not.,$gettok($gettok($address,1,64),-1,33)))) || ($ignore($+(*!,$address))) || (%notic. [ $+ [ $nick ] ] > 3) return
  inc -u11 %notic. [ $+ [ $nick ] ]
  if ($1 = BZZZ!) {
    if ($isfile($hgeT(soulfly,buzz))) splay $hgeT(soulfly,buzz)
    if (!$hget(soulfly,buzz_p)) error -b $v_ $crlf $crlf $bdc($nick) has Buzzed you from $+($hget(soulfly,#),!!)
  }
  if ($6 = Kiss!) && (!$hget(soulfly,kiss)) {
    if ($active != #) echo %_cc -ta $str(%c160,3) [4KISS] %c160 6 $nick has given you a $+(%c160,13xx4KISS13xx,%c160) in 2 $+($hget(soulfly,#),!)
    splay sounds\kiss.wav
  }
  halt
}
on ^*:invite:#:{
  if (%invite_ [ $+ [ $nick ] ]) || (%invite) || ($ignore($+(*!,$address))) halt
  inv $nick #
  haltdef
}
alias inv {
  set %inv_nick $1
  set %inv_chan $2
  set -u5 %invite_ [ $+ [ $1] ] $true
  dialog $iif($dialog(invite),-v,-mh) invite invite
}
dialog invite {
  title "Invite"
  size -1 -1 150 76
  option dbu
  icon %tbar
  text "", 100, 0 0 79 11
  icon 101, 43 -3 144 17, imgs\sf1.jpg, 0, noborder
  text "", 102, 157 0 3 10
  button "close", 1, 2 -2 27 14
  text "", 2, 6 14 146 10
  text "", 3, 0 30 150 12, center
  box "Would You Like To Join?", 4, 4 46 142 28
  button "Yes", 5, 12 57 56 14
  button "No", 6, 82 57 56 14, ok
  check "Disable Invites", 7, 32 1 44 10
}
on *:dialog:invite:init:*:{
  ;;mdx_head
  ;;xmdx SetDialog invite bgcolor $rgb(255,255,255) 
  ;;xmdx SetFont invite 1,3,5,6 20 500 Trebuchet MS Bold
  ;;xmdx SetFont invite 2,4 20 500 Palatino Linotype bold 
  ;;xmdx SetColor invite 2,3,4,5,6 background $rgb(255,255,255)
  ;;xmdx SetColor invite 2,3,4 textbg $rgb(255,255,255) 
  ;;;xmdx SetColor invite 3 text $rgb(128,128,192)
  did -ra invite 2 $bdc(%inv_nick) has invited you to join | did -ra invite 3 $remove($hcd(%inv_chan),!!!)
  did -f invite 101
}
on *:dialog:invite:sclick:*:{
  if ($did = 0) return
  elseif ($did = 5) { join %inv_chan | goto tool }
  elseif ($did = 7) { set %invite $true | goto tool }
  :tool
  unset %inv_*
  $iif($did isin 5.7,.timer1 -m 1 500) dialog -x invite invite
}
on *:dialog:invite:close:*:unset %inv_*
on *:socklisten:open:{ sockaccept SoulFly | sockclose open }
on *:sockopen:sf.*:{
  if (%sock. [ $+ [ $sockname ] ]) return
  ;if (!$window($+(@,$sockname))) window -e $+(@,$sockname)
  if ($sock($sockname).wserr isnum 10060-10061) {
    var %qi_ = $right($sockname,-4)
    echo %_cc -st Unable to connect to $+(%server,.) Error: $sock($sockname).wsmsg
    echo %_cc -st Attempting to join $+(%qi_,...)
    echo %_cc -s $chr(160)
    sockclose $sockname
    $+(.timerqi_,$sockname)) 1 7 join %qi_
  }
  set -u1 %sock. [ $+ [ $sockname ] ] $true
  if (!$sock($sockname)) sf_dc
  else {
    if ($readini(soulfly.ini,nick,%lastadd)) var %me = $ifmatch
    else var %me = $me
    set $right($sockname,-3) $right($sockname,-3)
    sockwrite -n $sockname $u_h(55736572) %me %me %me $+(:,$v_,$crlf,$iif($hget(soulfly,operh),operh,loginh)) $+($sock($sockname).mark,$crlf,clientmode) cd1
  }
  :error
  if ($error) reseterror
}
on *:sockclose:sf.*:{
  if ($me ison $right($sockname,-3)) && (!%sf_re) $+(.timersf_c,$right($sockname,-3)) 1 2 /sf_dc
}
on *:sockread:sf.*:{
  if ($sockerr > 0) return
  if (!$sock(SoulFly)) && (!%sf_re) { sf_dc1 | return }
  ;if (!$window($+(@,$sockname))) window -e $+(@,$sockname)
  sockread -n &sfr
  if ($bvar(&sfr,0) > 0) {
    tokenize 32 $bvar(&sfr,1-).text
    var %hn = $right($gettok($1,1,33),-1), %sfc = $right($sockname,-3)
    if ($1) && (%sfc) {
      if ($2 !isnum) && ($2 != :IC_Panther01) {
        inc -u1 $+(%,sf_fld.,%sfc,.,$2)
        if ($($+(%,sf_fld.,%sfc,.,$2),2) = 21) echo 4 -t %sfc 1,8 WARNING! 11,1 $2 9,1 Flood detected in %sfc .
        elseif ($v1 > 21) {
          if ($2 isin join.part) $+(.timerflood,%sfc) 1 3 name_chk %sfc
          return
        }
      }
    }
    ;if ($1) echo -t $+(@,$sockname) Read: $1-
    if ($2 = 999) && (!$hget(soulfly,operh)) { error -e $v_ $crlf $crlf You have exceeded the allowed 20 connections per IP. | sockclose $sockname | return }
    if ($2 = privmsg) {
      if (FINGER isin $5) return
      elseif ($4 = :VERSION) $+(.timernotice,#) 1 2 /notice $3 %hn $+($chr(2),VERSION,$chr(2),Ajax) IRCwx Client 1.0 beta 1, buzz1 interface
      elseif ($4 = $me) && ($5 = :TIME) {
        if (%time. [ $+ [ %hn ] ] > 3) || ($hget(soulfly,timex)) || (%sf_time > 4) return
        elseif (%time. [ $+ [ %hn ] ] = 3) {
          set -u30 %time. [ $+ [ %hn ] ] 5
          msg $3 %hn is trying to flood me with time messages!
        }
        else {
          inc -u2 %sf_time
          inc -u4 %time. [ $+ [ %hn ] ]
          echo 9 -t $3 4 %hn  Checked your TIME.
          if ($readini(soulfly.ini,misc,time)) var %rply = [ $ifmatch ]
          else var %rply = $asctime(ddd mmm dd HH:nn:ss) GMT [ $asctime(zz yyyy) ]
          sockwrite -n $sockname NOTICE $3 %hn $+($Chr(2),TIME,$chr(2),%rply)
        }
      }
      elseif ($regex($1,/^:%#/)) {
        if (!%names_ [ $+ [ $3 ] ]) {
          $+(.timer333,$3) -m 1 600 /echo $3 $chr(160)
          $+(.timer333,$3) -m 1 650 /echo $3 $str($chr(160),3) 3Welcome: $chr(160) 10 $xfont($right($4-,-1))
        }
      }
      elseif (Action !isin $4) {
        if (!$hget(soulfly,thm_chn)) {
          if ($bfind(&sfr,1-,co:)) var %pv_b = $calc($ifmatch + 3), %pv_c = $bvar(&sfr,%pv_b,$calc($bfind(&sfr,$+(%pv_b,-),;) - %pv_b)).text
          else var %pv_c = 0
          _privmsg $+(%pv_c,$chr(44),$1-)
          sockwrite -n soulfly $1-3 $remove($sfont($4-),$chr(1)) | return
        }
      }
      else sockwrite -n SoulFly $1-4 $xfont($5-)
      return
    }
    elseif ($2 = 0999) {
      if ($isalias(bzn_999)) bzn_999 $1-
      return
    }
    elseif ($2 = 001) {
      if ($gettok($sock($sockname).mark,3,32) = create) sockwrite -n $sockname CREATE %sfc
      else sockwrite -n $sockname join %sfc
    }
    elseif ($2 = 352) && ($9 = G) $+(.timercline,$8) 1 3 _cline 15 $4 $8
    elseif ($2 = 353) && (, isin $left($6,6)) {
      var %353_ = $right($6-,-1), %353x = 1, %353x_, %353_u, %353_v
      while ($gettok(%353_,%353x,32)) {
        %353_u = $ifmatch
        if ($right($gettok(%353_u,1,44),1) = v) && (!$istok(.-@-%-',$mid(%353_u,6,1),45)) %353_v = +
        else %353_v = $null
        %353x_ = $addtok(%353x_,$+(%353_v,$right(%353_u,-5)),32)
        inc %353x
      }
      sockwrite -n SOULFLY $1-5 $+(:,%353x_)
      $+(.timerclineme,$5) 1 3 _cline 11 $5 $me
      return
    }
    elseif ($2 = 401) echo %_cc %sfc $str($chr(160),3) 4ERROR:12 $3  $4-
    elseif ($2 = 433) {
      $+(.timer433,%sfc) 1 2 /jroom %sfc
      sockclose $sockname
      if (!%433 [ $+ [ $4 ] ]) {
        echo $_cc -at 9,10 Disconnect: $hcd(%sfc) 11,10 $bdc($4) in use. Rejoining ...
        inc -u6 %433 [ $+ [ $4 ] ]
      }
    }
    elseif ($2 = 442) && (!%sf_re) && ($sock($+(sf.,$4))) && ($5- = :You're not on that channel) { unset %join. [ $+ [ $remove($4,$chr(37)) ] ] | jroom $4 }
    elseif ($2 = 471) {
      echo %_cc -as $hcd($4) $u_h(69732066756C6C2E)
      if ($hget(prot,banretry)) || (!$window($4)) set %sf_dc $remtok(%sf_dc,$right($4,-1),44)
      sockclose $sockname
    }
    elseif ($2 = 473) {
      echo %_cc -as $hcd($4) $u_h(697320696E76697465206F6E6C792E)
      if ($hget(prot,banretry)) || (!$window($4)) set %sf_dc $remtok(%sf_dc,$right($4,-1),44)
      sockclose $sockname
    }
    elseif ($2 = 474) {
      echo %_cc -s $u_h(596F75206172652062616E6E65642066726F6D) 11 $4
      if ($hget(prot,banretry)) || (!$window($4)) set %sf_dc $remtok(%sf_dc,$right($4,-1),44)
      sockclose $sockname
    }
    elseif ($2 = 475) && ($hget(prot,banretry)) set %sf_dc $remtok(%sf_dc,$right($4,-1),44)
    elseif ($2 = 482) echo %_cc -t $4 4 $right($5,-1) $6  $7- ( $hget(soulfly,$4) )
    elseif ($2 = 803) {
      if ($5 != :start) return
      var %a_i = $+(axis.,$hget(soulfly,$4))
      ;hfree %a_i
      ;hmake %a_i 110
    }
    elseif ($2 = 804) {
      if (%axisfin) return
      ax_add $+(axis.,$hget(soulfly,$4)) $iif($len($6) > 10,$remove($6,<,*,$,@,ICMember),$remove($6,ICMember)) $5-
      if ($dialog(axis)) && ($4 = %axis.chan) did -a axis 2 $5 $chr(9) $6 $chr(9) $7 $chr(9) $bdc($right($9-,-1))
      return
    }
    elseif ($2 = 805) {
      if ($me !ison $4) return
      if (!$hget(soulfly,ax_save)) && (!$exists($+(lists\axis\,$+($hget(soulfly,$4),_ax),.txt))) $+(.timeraxissave.,$4) 1 3 /axis.save $4
      if ($dialog(axis)) && (!%axisfin) set %axisfin $true
    }
    elseif ($2 = NICK) {
      if ($right($3,-1) = $me) writeini soulfly.ini nick %lastadd $right($3,-1)
      if (%hn)  { echo -tc info %sfc %hn is now known as $right($3,-1) | name_chk %sfc }
      return
    }
    elseif ($1-2 = ERROR :Closing) jroom %sfc
    elseif ($1 = PING) {
      if ($2 = :IC_Panther01) sockwrite -n $sockname PONG
      return
    }
    elseif ($1 = PONG) {
      if ($2 = :IC_Panther01) && ($timer($sockname)) $+(.timer,$sockname) off
      return
    }
    elseif ($2 = AUTHUSER) sockwrite -n $sockname $iif($hget(soulfly,operh),operh,loginh)) $sock($sockname).mark
    elseif ($2 = NOTICE) {
      if ($1 = :IC_Panther01) {
        if ($3 = Warning) sockwrite -n $sockname $iif($hget(soulfly,operh),operh,loginh)) $sock($sockname).mark
        elseif ($3 = AUTH) {
          if ($5 = bad) var %x_p = Incorrect Login Info
          elseif ($7 = user) var %x_p = User Not Found
          if (%x_p != $null) && (!$dialog(sf)) {
            error -e $v_ $crlf Login: %lastadd $crlf $crlf %x_p
            sockclose $sockname
            sf
          }
          return
        }
        elseif ($regex($3,/^%#/)) {
          echo %_cc -t $3 >4Broadcast $right($5-,-1)
          sockwrite -n SOULFLY $1-4 $sfont($5-)
        }
        return
      }
      elseif ($3 = IC_Panther01) { echo %sfc $chr(160) | echo %_cc -t %sfc >4Broadcast from 2 %hn  | echo %_cc -t %sfc $4- | echo %sfc $chr(160) | return }
      elseif ($regex($4,/^%#/)) {
        if ($3 isin %wchat) { necho $3 $str($mico(blank),2) <font face="Marlett" size="2" color="#999999">8<font face="Arial" color="#DF120D">Room Broadcast <font face="Arial" color="#000000"> - $emotereplace($replace($strip($xfont($replace($right($5-,-1),[br],%c160,&nbsp;,%c160))),<,&lt;,>,&gt;)) }
        else $iif($me !ison $4,$+(.timernotice,$4) 1 2) echo -i7t $4 $str(%c160,2) >4Room Broadcast: $str(%c160,3) $strip($xfont($replace($right($5-,-1),[br],%c160,&nbsp;,%c160)))
        sf_events $1-
        return
      }
      if ($hget(prot,$+(not.,$gettok($gettok($1,1,64),-1,33)))) || ($hget(prot,notice)) || ($ignore($+(*!,$gettok($1,-1,33)))) || (%notic [ $+ [ $right($gettok($1,1,33),-1) ] ] > 3) return
      elseif ($regex($3,/^%#/)) {
        if ($4 != $me) echo -t $3 4[ %hn ] 12Notice:10 $sfont($iif($left($4,-1) = :,$right($4,-1),$4) $5-)
        else $iif($me !ison $4,$+(.timernotice,$4) 1 2) echo -t $3 4[ %hn ] 12Notice:10 $sfont($iif($left($5,1) = :,$right($5,-1),$5) $6-)
      }
      else $iif($me !ison $4,$+(.timernotice,$4) 1 2) echo -t %sfc 4[ %hn ] 12Notice:10 $sfont($iif($left($5,1) = :,$right($5,-1),$5) $6-)
      sockwrite -n SOULFLY $1-3 $sfont($5-)
      return
    }
    elseif ($2 = kick) && ($4 = $me) && (!$hget(prot,rejoin)) sockwrite -n $sockname join $3
    elseif ($2 = join) {
      sockwrite -n SOULFLY $1-2 $+(:,%sfc)
      elseif (%sfc isin $hget(soulfly,profile)) && (%hn != $me) && (!$istok(^.>,$left(%hn,1),46)) q_ prof_chk $right($1,-1) %sfc $3
      return
    }
    elseif ($2 = part) {
      if (%hn = $me) && (!%hop [ $+ [ $3 ] ]) {
        if ($timer($sockname)) $+(.timer,$sockname) off
        sockclose $sockname
      }
      else sockwrite -n SOULFLY $1-
      return
    }
    elseif ($2 = whisper) {
      if (%sf_query > 4) {
        set -u30 %sf_query 10
        if (!$ignore($+(*!,$gettok($1,-1,33)))) ignore -u7777 $ial(%hn,3).addr
      }
      if ($ignore($+(*!,$gettok($1,-1,33)))) || (%hn isin $hget(prot,queryblock)) || (%sfc isin $hget(prot,chn.query)) || (%whisper. [ $+ [ %hn ] ] > 8) return
      elseif (%whisper. [ $+ [ %hn ] ] = 8) {
        error -e Whisper Flood Detected $crlf $chr(160) $crlf Flooding from %hn detetced.
        return
      }
      if (%hn !isop $3) && (!$hget(soulfly,queryflood)) inc -u2 %whisper. [ $+ [ %hn ] ]
      if ($hget(soulfly,noquery)) {
        if ($hget(soulfly,queryh)) && (%hn !isop $3) return
        elseif (!$hget(soulfly,queryh)) return
      }
      if ($hget(soulfly,query)) && (!%qsound. [ $+ [ %hn ] ]) {
        if ($line(%hn,0) = $null) || ($line(%hn,0) <= 3) q_sound
        if ($hget(soulfly,queryn)) set %qsound. [ $+ [ %hn ] ] $true
        elseif (!%qsound. [ $+ [ %hn ] ]) q_sound
      }
      sockwrite -n SoulFly $1 PRIVMSG %hn $+(:,$sfont($right($5-,-1)))
      if (%sfw_ [ $+ [ %hn ] ]) && (!$hget(soulfly,bznquery)) { hadd -m $+(sf,%hn) $calc($hget($+(sf,%hn),0).item + 1) $sfont($right($5-,-1)) | return }
      hadd soulfly $+(sfw_,%hn) $3
      if (%qflash) flash -r %hn %hn is whispering you.
      if (!$hget(soulfly,thm_q)) {
        if (!$query(%hn)) {
          inc -u5 %sf_query
          if (%sf_query > 3) return
          query %hn
          set -e $+(%,sfq_,%hn) %hn
          set -e $+(%,sfw_,%hn) $sfont($right($5-,-1))
          if (!$hget(soulfly,bznquery)) {
            sockwrite -n $sockname DATA %sfc %hn CMWHISP :WHISPACCEPTNEEDED
            echo %_cc -t %hn %c160 7 %hn  %c160) has sent you a whisper from 12 $hget(soulfly,%sfc)  . %c160 ( %c160 9Accept %c160 - %c160 9Decline %c160 )
            echo %hn $chr(160) | echo 14 %hn $str(%c160,3) $+(%hn,:) %sfw_ [ $+ [ %hn ] ] | return
          }
        }
        var %qval, %q_x = $regsub($replace($right($5-,-1),&nbsp;,%c160),/\[(/)?style([^\]]+)?\]/gi,$null,%qval)
        if ($hget(soulfly,nocolor)) { echo -ct normal %hn ( %hn ) %c160 %qval | return }
        if ($bfind(&sfr,1-,co:)) var %pv_b = $calc($ifmatch + 3), %pv_c = $_col($bvar(&sfr,%pv_b,$calc($bfind(&sfr,$+(%pv_b,-),;) - %pv_b)).text)
        else var %pv_c = %c_
        var %font = $regml(1), %u_ = $iif($istok(%font,u,59),), %b_ = $iif($istok(%font,b,59),)
        echo -t %hn $+($chr(40),,%pv_c,%hn,,$chr(41)) $+(,%pv_c,%u_,%b_) %qval
      }
      return
    }
    if ($1-) sockwrite -n SoulFly $1-
    return
    :error
    if ($error) reseterror
  }
}
raw 1:*:halt
raw 332:*:{
  if ($me isop $2) writeini -n soulfly.ini topic $2 $3-
  if (!%names_ [ $+ [ $2 ] ]) {
    $+(.timer,$2) -m 1 600 /echo 14 $2 $str($chr(160),2) 4 $hcd($2) - Topic:  $chr(160) $xfont($3-)
    $+(.timerx,$2) -m 1 650 echo $2 $chr(160)
  }
  halt
}
raw 315:*:{
  if ($2 isin %scheck) set %scheck $remtok(%scheck,$2,44)
  if ($2 isin %kscheck) set %kscheck $remtok(%kscheck,$2,44)
  halt
}
raw 352:*:{
  if (%scheck. [ $+ [ $6 ] ]) {
    if ($9- != anon) echo -c info $2 [4Script] - $6 is not webchat. 12 $9-
    else echo -c info $2 9,1 $6  is not a script.
    unset %scheck. [ $+ [ $6 ] ]
    halt
  }
  if ($9- != anon) {
    if ($2 isin %scheck) {
      if (!$window(@Script_Check)) window @Script_Check
      echo -c info @Script_Check $hget(soulfly,$2) - [4Script] - $6 is not webchat. 12 $9-
    }
    if ($2 isin %kscheck) && (!$hget(prot,$+(all.,$3))) && ($6 != $me) q_ .raw access $2 add deny $+($3,@,$4) 15 $+(:ScriptCheck,$crlf,kick) $2 $6 ScriptCheck
    if (%s_nix) q_ _cline 7 $2 $6
  }
  noop $ini_array(lists\users\nix,nix,$3,$6).add
  halt
}
raw 403:*:{
  if (!%join. [ $+ [ $2 ] ]) echo -a .403 $2
  elseif (%cr_room = $2) || ($hget(soulfly,a_create)) sockwrite -n $+(sf.,$2) create $2
  else {
    sockclose $+(sf.,$2)
    echo %_cc -a SoulFly Error: 4 $2  does not exist!
    dxist $2
  }
  halt
}
raw 404:*:{
  error -n Notice $crlf $2 $crlf $3-
  halt
}
raw 475:*:{
  if (!%u475- [ $+ [ $2 ] ]) $+(.timerr475,$2) -m 1 300 rpass $2
  halt
}
raw 818:*:{
  if ($3 = ownerkey) hadd prot $+(q,$2) $4
  elseif ($3 = hostkey) hadd prot $+(o,$2) $4
  elseif ($3 = locked) hadd prot $+(818,$2) $4-
  halt
}
raw 821:*:{
  var %821_n = $right($gettok($rawmsg,1,33),-1)
  if ($hget(prot,$+(a_821,%821_n)) > 5) halt
  if (%821_n ison $1) q_ _cline $iif(%821_n = $me,11,9) $1 %821_n
  if (%821_n != $me) hinc -u4 prot $+(a_821,%821_n)
  if ($ignore($+(*!,$address))) halt
  if ($1 isin %wchat) necho $1 $str($mico(blank),2) <font face="Marlett" size="2" color="#999999">8<font face="Arial"> %821_n has returned.
  else echo -ct info $1 %821_n has returned.
  haltdef
}
raw 822:*:{
  var %822_n = $right($gettok($rawmsg,1,33),-1)
  if (%822_n != $me) hinc -u4 prot $+(a_822,%822_n)
  if (%822_n ison $1) q_ _cline 15 $1 %822_n
  if ($ignore($+(*!,$address))) || ($hget(prot,$+(a_822,%822_n)) > 5) halt
  if ($count($2-,[style ) > 1) var %val, %xfont = $regsub($replace($2-,[br],$chr(160)),/\[(/)?style([^\]]+)?\]/gi,$null,%val), %awymsg = %val
  if ($1 isin %wchat) necho $1 $str($mico(blank),2) <font face="Marlett" size="2" color="#999999">8<font face="Arial"> %822_n is now away. $iif(%awymsg,%awymsg,$sfont($2-))
  else echo -ct info $1 %822_n is now away: 6 $utfencode($iif(%awymsg,%awymsg,$sfont($2-)))
  haltdef
}
raw 908:*:{ echo %_cc -t $2 $+(4,$u_h(5B4572726F725D),:) $u_h(536F727279) $1 $u_h(5468617420636F6D6D616E64206973206C6F636B65642E) | halt }
raw data:*:{
  if ($3 = CMWHISP) && ($window($nick)) {
    if ($hget(soulfly,bznquery)) halt
    if ($4 = WHISPACCEPTNEEDED) {
      if (%wct [ $+ [ $nick ] ] > 3) return
      inc -u3 %wct [ $+ [ $nick ] ]
      echo 11 -t $nick ... Requesting a whisper from $nick
    }
    elseif ($4 = WHISPACCEPTED) echo 11 -t $nick ... Your whisper with $nick has been accepted.
    elseif ($4 = WHISPDECLINED) { echo 11 -t $nick ... Sorry, $nick has declined your whisper. | hinc -u2000 prot $+(dW,$nick) }
    elseif ($4 = WHISPWNDCLOSED) echo 11 -t $nick ... $nick has closed their whisper window.
  }
  elseif ($2 = PID) {
    if (%prov. [ $+ [ $3 ] ]) { sf_prof.get $4 webpage $3 $ifmatch | unset prov.* }
    if (%pro. [ $+ [ $3 ] ]) { sf_prof.get $4 v_pro $3 $4 $ifmatch | unset pro. [ $+ [ $3 ] ] }
    if (%pro_nk. [ $+ [ $3 ] ]) { noop $ini_array(lists\users\pid,pid,$ifmatch,$4).add | unset %pro_nk.* }
  }
  halt
}
raw prop:*:{
  if ($2 = category) { echo %_cc -t $1 $utfencode($str($chr(160),3)) 9- $nick changed $+($hget(soulfly,$1),'s) category to 4 $_cat($3) $+([,$3,]) }
  elseif ($2 = Language) { echo %_cc -t $1 $utfencode($str($chr(160),3)) 9- $nick changed $+($hget(soulfly,$1),'s) language to 4 $_lang($3) $+([,$3,]) }
  elseif ($2 = onjoin) { echo %_cc -t $1 $utfencode($str($chr(160),3)) 9- $nick changed $+($hget(soulfly,$1),'s) onjoin message to 4 | echo %_cc $1 $str($chr(160),3) $3- }
  elseif ($2 = onpart) { echo %_cc -t $1 $utfencode($str($chr(160),3)) 9- $nick changed $+($hget(soulfly,$1),'s) onpart message to 4 | echo %_cc $1 $str($chr(160),3) $3- }
  haltdef
}
raw *:*:{
  if ($regex($numeric,/[2-5]|265|315|329|353|366|801|819/)) halt
}
on *:sockclose:SoulFly:{
  if (!%sf_re) sf_dc1
}
on *:sockread:SoulFly:{
  ;if (!$window(@soufly)) { window -e @soulfly }
  if ($sockerr > 0) return
  var %lh | sockread %lh | tokenize 32 %lh
  ;echo %_cc @soulfly > $1-
  if ($1 = JOIN) {
    if (!$2) sockwrite -n SoulFly Please include the room name!
    elseif (!%sf_re) jroom $2-
  }
  elseif ($1 = USER) {
    if (!$sock(soulfly)) || (%sf_re) return
    if (!%addr.1) || (!%lastadd) login
    elseif (%sf_dc) jroom %SF_dc
    elseif ($hget(soulfly,autojoin)) && (%idl. [ $+ [ %lastadd ] ] != $null) jroom %idl. [ $+ [ %lastadd ] ]
    else fav
  }
  elseif ($sock($+(sf.,$2))) Sockwrite -n $v1 $1-
}
on *:INPUT:#:{
  if ($server != IC_Panther01) return
  if (!$sock($+(sf.,#))) { sf_dc | return }
  inc -u1 %input [ $+ [ # ] ]
  if (/* !iswm $1) {
    if ($hget(soulfly,nocolor)) { echo -ct own # ( $me ) %c160 $1- | sockwrite -n $+(sf.,#) PRIVMSG # $font_($1-) | haltdef }
    if ($readini(mirc.ini,fonts,$+(f,$h_ini(#)))) && ($gettok($ifmatch,2,44) >= 714) var %bd = $true
    elseif ($gettok($readini(mirc.ini,fonts,fchannel),2,44) >= 700) var %bd = $true
    var %qb_ = $iif(b isin $hget(soulfly,style) && !%bd,), %qu_ = $iif(u isin $hget(soulfly,style),), %qc_ = $_col($mid($hget(soulfly,fcolor),4,7))
    echo -i11t # ( $+(,%_cc,$me,) ) $+(%qb_,%qu_,,%qc_) $1-
    $iif(%input [ $+ [ # ] ] > 6,q_) sockwrite -n $+(sf.,#) PRIVMSG # $font_($1-)
    haltdef
  }
}
on *:INPUT:?:{
  if ($server != IC_Panther01) return
  var %t = $target, %w = $+(sfw_,%t)
  if ($hget(soulfly,%w)) && (!$sock($+(sf.,$ifmatch))) { sf_dc | return }
  elseif (!$sock($+(sf.,$comchan(%t,1)))) { sf_dc | return }
  if (/* !iswm $1) {
    if ($hgeT(soulfly,nocolor)) echo -ct own %t ( $me ) $1-
    else {
      if (($readini(mirc.ini,fonts,$+(f,%t))) || ($readini(mirc.ini,fonts,fquery))) && ($gettok($ifmatch,2,44) >= 714) var %bd = $true
      var %qb_ = $iif(b isin $hget(soulfly,style) && !%bd,), %qu_ = $iif(u isin $hget(soulfly,style),), %qc_ = $_col($mid($hget(soulfly,fcolor),4,7))     
      echo -t %t ( $+(,$hget(soulfly,_cc),$bdc($me),) ) $+(%qb_,%qu_,,%qc_) $1-
    }
    if (!$hget(soulfly,%w)) {
      if ($hget(prot,$+(d,%w)) = 3) { echo $hget(soulfly,_cc) %t Blocking %t | hadd -u2000 prot $+(d,%w) 4 | .timerclo 1 2 /window -c %t | return }
      else sockwrite -n $+(sf.,$comchan(%t,1)) WHISPER $comchan(%t,1) %t $font_($1-)
      haltdef
    }
    else sockwrite -n $+(sf.,$hget(soulfly,%w)) WHISPER $hget(soulfly,%w) %t $font_($1-)
    haltdef
  }
}
on ^1:hotlink:*:$($+(%,sfq_,$active)):{
  if ($1 = Accept) || ($1 = Decline) return
  else halt
}
on 1:hotlink:*:$($+(%,sfq_,$active)):{
  if ($1 = Accept) {
    if ($sock($+(sf.,$hget(soulfly,$+(sfw_,$active))))) sockwrite -n $ifmatch DATA $hget(soulfly,$+(sfw_,$active)) $active CMWHISP :WHISPACCEPTED
    clear $active | echo 11 -t $active $u_h(596F752068617665206163636570746564) $+($active,'s) $u_h(776869737065722E2E2E) | echo $active $chr(160) | echo %_cc -t $active $+($active,:) %sfw_ [ $+ [ $active ] ]
    if ($hgeT($+(sf,$active),0).item) {
      var %htg = $ifmatch, %hti = 1
      while (%hti <= %htg) {
        echo %_cc -t $active $+($active,:) $hget($+(sf,$active),%hti)
        inc %hti
      }
      hfree $+(sf,$active)
      unset %sfw_ [ $+ [ $active ] ]
    }
  }
  elseif ($1 = Decline) {
    if (%declined [ $+ [ $active ] ] >= 4) {
      clear $active | echo %_cc $active Whispers from $active will now be blocked.
      hadd prot queryblock $addtok($hget(prot,querydeny),$active,44)
      unset %declined [ $+ [ $active ] ]
      if ($hget($+(sf,$active))) hfree $+(sf,$active)
      unset %sfw_ [ $+ [ $active ] ]
      return
    }
    inc -u500 %declined [ $+ [ $active ] ]
    if ($sock($+(sf.,$hget(soulfly,$+(sfw_,$active))))) sockwrite -n $ifmatch DATA $hget(soulfly,$+(sfw_,$active)) $active CMWHISP :WHISPDECLINED
    echo 11 -t $active You have declined $+($active,'s) whisper.
  }
  unset %sfw_ [ $+ [ $active ] ]
}

;User Window
on ^1:hotlink:Profile:@user:return
on 1:hotlink:Profile:@user:{
  if (!$chan(1)) error -e $v_ - User Window $crlf $crlf You are not connected.
  else prof_chk $+(%i_user,!,%n_user) $chan(1) v-
}
menu @user {
  lbclick:{
    if ($$1- = $null) return
    set -e %i_user $strip($gettok($line(@user,$$1,1),-3,58))
    set -e %n_user $strip($gettok($line(@user,$$1,1),-2,58))
    user_win %i_user %n_user
  }
}
on *:input:@USER:{
  var %fu = $fline(@user,$+(*,$1-,*),1,1).text
  if (!%FU) {
    if ($gettok($1,2,64)) var %sx = $gettok($1,1,64)
    else var %sx = $1
    if ($ini_array(lists\users\nix,nix,%sx).chk) {
      set %i_user $gettok($gettok($ifmatch,2,32),1,149)
      set %n_user %sx
      user_win %i_user %n_user
    }
    else error -n $v_ $crlf User Management $crlf $crlf $bdc($1-) was not found.
  }
  else {
    set %i_user $strip($gettok(%fu,-3,58))
    set %n_user $strip($gettok(%fu,-2,58))
    user_win %i_user %n_user
  }
}
alias sf {
  if (!$readini(soulfly.ini,accts,%lastadd)) sf_login
  else {

    %sf = $iif(!$1,$readini(soulfly.ini,accts,%lastadd),$1)
    dialog $iif($dialog(sf),-v,-mh) sf sf
  }
}
dialog sf {
  title ""
  size -1 -1 200 88
  option dbu
  icon imgs\1x.ico
}
on *:dialog:sf:close:*:{
  unset %sf %tcol %sfemail %sfpass %sf56_*
}
on *:dialog:sf:init:*:{
  dcx Mark sf sf_cb
  dialog -t sf [Accounts] $chr(160) $v_
  set -u3 %sfstart $true
  xdialog -g sf +b $rgb(255,255,255)
  xdialog -c sf 100 text 0 0 3 21
  xdialog -c sf 101 text 53 0 200 21
  xdialog -c sf 103 text 396 0 3 21
  xdialog -c sf 2 button 3 -3 50 26
  xdialog -c sf 102 text 53 5 105 12 center
  xdialog -c sf 3 image 252 0 144 24
  xdialog -c sf 4 comboex 45 34 160 200 tabstop dropedit
  xdialog -c sf 5 edit 45 70 248 22 tabstop autohs
  xdialog -c sf 6 edit 45 100 248 22 tabstop autohs
  xdialog -c sf 7 button 210 33 56 29 tabstop
  xdialog -c sf 9 button 270 36 24 24 tabstop tooltip
  xdialog -c sf 20 text 8 75 30 12
  xdialog -c sf 21 text 10 104 30 13
  xdialog -c sf 99 check 6 33 36 29 pushlike
  xdialog -c sf 8 button 307 68 80 24 tabstop
  xdialog -c sf 10 button 307 36 80 24 tabstop
  xdialog -c sf 11 text 0 138 396 33 center transparent
  xdialog -c sf 14 check 308 100 80 20 tabstop
  xdid -t sf 99 main
  xdid -h sf 99
  xdid -t sf 20 email
  xdid -t sf 21 pass
  xdid -t sf 14 Underline
  xdid -t sf 2 close
  xdid -i sf 3 +h imgs\sf1.jpg
  xdid -t sf 7 Add
  xdid -t sf 8 color
  xdid -w sf 9 +n 0 imgs\64.ico
  xdid -t sf 10 font
  xdid -t sf 11 $v_
  xdid -C sf 11 +t $h_d($mid($hget(soulfly,fcolor),4,7))
  xdid -f sf 11 $+(+a,$remove($hget(soulfly,style),;)) ansi 18 $left($mid($hget(soulfly,font),4),-1)
  xdid -C sf 7,8,9,10,14,20,21,99 +b $rgb(255,255,255)
  xdid -C sf 100,101,102,103 +bk $rgb(224,223,228) | xdid -f sf 2,7 +ab ansi 12 trebuchet ms
  xdid -f sf 20,21 +ab ansi 8 tahoma | xdid -f sf 4,5,6,8,9,10,14 +ab ansi 10 trebuchet ms | xdid -t sf 102 $bdc($me)
  xdid -w sf 4 + 0 imgs\1x.ico
  if (u isin $hget(soulfly,style)) xdid -c sf 14
  addy8
}
alias sf_cb {
  if ($2 = edit) && (!%sfstart) && (!%sclick) {
    if ($3 = 4) && (!%sf4_) { xdid -t sf 7 Add | set -u9 %sf4_ $true }
    if ($istok(5.6,$3,46)) && (!%sf56_ [ $+ [ $3 ] ]) {
      var %nx = $xdid(sf,4).num, %nr = $xdid(sf,4,0).text
      while (%nx) {
        if ($xdid(sf,4,%nx).text = %nr) {
          set -u9 %sf56_ [ $+ [ $3 ] ] $true
          xdid -t sf 7 Edit
          return
        }
        dec %nx
      }
    }
  }
  elseif ($2 = sclick) && (!%fav_sclick) {
    if (!$istok(4.5.6,$3,46)) set -u3 %sclick $3
    if ($3 = 8) {
      var %cr_x = $dcx(ColorDialog, $h_d($mid($hget(soulfly,fcolor),5,6)) owner $dialog(sf).hwnd fullopen anycolor), %cr_z = $d_h(%cr_x)
      if (%cr_x != -1) {
        xdid -C sf 11 +t %cr_x
        hadd soulfly fcolor $+(co:,%cr_z,;)
      }
    }
    elseif ($3 = 14) {
      var %84s = $hget(soulfly,style), %84
      if (u isin %84s) %84 = $remove(%84s,u;)
      else %84 = $+(%84s,u;)
      hadd soulfly style %84
      xdid $iif(u isin $hget(soulfly,style),-c,-u) sf 14
      xdid -f sf 11 $+(+a,$remove($hget(soulfly,style),;)) ansi 18 $left($mid($hget(soulfly,font),4),-1)
      xdid -t sf 11 $v_
      goto sclick2
    }
    elseif ($3 = 10) {      
      if ($dcx(FontDialog,default $+(+,$remove($hget(soulfly,style),;)) ansi 10 $left($mid($hget(soulfly,font),4),-1) $chr(9) owner $dialog(sf).hwnd)) {
        var %if = $ifmatch
        hadd soulfly font $+(ff:,$gettok(%if,5-,32),;)
        if ($gettok($gettok(%if,2,32),1,43)) {
          %if = $ifmatch
          if ($len(%if) = 2) hadd soulfly style b;i;
          else hadd soulfly style $+(%if,;)
        }
        elseif ($hget(soulfly,style)) hdel soulfly style
        xdid -t sf 11 $v_
        xdid -f sf 11 $+(+a,$remove($hget(soulfly,style),;)) ansi 18 $left($mid($hget(soulfly,font),4),-1)
      }
    }
    elseif ($3 = 2) {
      unset %sf %tcol %sfemail %sfpass
      unset %sf56_*
      dialog -x sf sf sf
    }
    elseif ($3 = 4) {
      set -u3 %sf4_ $true 
      var %4x = $remove($xdid(sf,4,$4).text,$chr(160)), %4xi = $readini(soulfly.ini,accts,%4x)
      xdid -s sf 99
      if (%4xi = %default) xdid -c sf 99
      elseif ($xdid(sf,99).state = 1) xdid -u sf 99
      xdid -t sf 7 login
      if (%4xi) xdid -o sf 5 %4xi
      xdid -t sf 102 $bdc($readini(soulfly.ini,nick,%4xi))
      xdid -r sf 6 1
    }
    elseif ($3 = 9) {
      var %x9 = $xdid(sf,4,0).text
      if (%x9 = Accounts) return
      if (!$input(Are you sure you would like to delete: $crlf $crlf %x9,iyd,[Accounts] $v_)) return
      if ($readini(soulfly.ini,Accts,%x9)) {
        var %zz = $ifmatch, %qr = $readini(soulfly.ini,accts,%zz)
        addy_d %zz
        remini soulfly.ini login %zz | remini soulfly.ini accts %zz | remini soulfly.ini accts %qr
        addy8
        xdid -r sf 5,6 | xdid -t sf 102
        if (!%addr.1) unset %lastadd %default
      }
    }
    elseif ($3 = 12) { hadd soulfly fcolor $+(co:,%tcol,;) | xdid -b sf 12 }
    elseif ($3 = 99) {
      if (%sclick != 99) return
      var %99x = $remove($xdid(sf,4,0).text,$chr(160))
      if ($xdid(sf,99).state = 0) unset %default
      elseif ($xdid(sf,99).state = 1) {
        if ($readini(soulfly.ini,accts,%99x)) set %default $ifmatch
        else error -e [Accounts] $v_ $crlf %99x does not have a valid email address. $crlf Please check the account.
      }
      xdid -F sf 100
      return
    }
    elseif ($3 = 7) {
      var %7x = $xdid(sf,4,0).text
      if ($xdid(sf,7).text = login) {
        if ($readini(soulfly.ini,accts,%7x)) {
          var %7if = $ifmatch
          error -n [Login] $v_ $crlf Now using %7x $crlf $crlf ( %7if )
          error -n3 [Accounts] $v_ $crlf SoulFly will now log you in as $crlf %7x $crlf ( %7if )
          sf_re %7if
        }
        else error -e [Login] $v_ $crlf $crlf Sorry, $crlf %7x is not a valid account name. $crlf $crlf Please edit your information.
      }
      else {
        var %act = $xdid(sf,4,0).text, %ae = $xdid(sf,5).text, %ap = $xdid(sf,6).text, %ao = $readini(soulfly.ini,accts,%act)
        if ((!%act) || (%act = Accounts)) && ($dcx(MsgBox,ok $chr(9) Error: Account Edit $chr(9) Please Enter An Account Name)) return
        elseif ($xdid(sf,7).text = Edit) {
          if (!$ini(soulfly.ini,accts,%act)) && ($dcx(MsgBox,ok $chr(9) Error: Account Creation $chr(9) Account $+([,%act,]) Does Not Exist.)) return
          if (%ae) && (%ao !iswmcs %ae) {
            if (%ap) { remini soulfly.ini login %ao | writeini soulfly.ini login %ae $md5(%ap) }
            else {
              writeini soulfly.ini login %ae $readini(soulfly.ini,login,%ao)
              remini soulfly.ini login %ao
            }
            if (%lastadd = %ao) set %lastadd %ae
            c_add %ao %ae
            remini soulfly.ini accts %act
            remini soulfly.ini accts %ao
            writeini soulfly.ini accts %act %ae
            writeini soulfly.ini accts %ae %act
          }
          elseif (%ap) writeini soulfly.ini login %ao $md5(%ap)
          elseif ((!%ae) || (!%ap)) && ($dcx(MsgBox,ok $chr(9) Error: Account Edit $chr(9) Account $+([,%act,]) No Informtion Given)) return
          error -n3 $v_ $crlf $crlf Succesfully Edited %act
          xdid -t sf 7 Login
        }
        elseif ($ini(soulfly.ini,accts,%act)) && ($dcx(MsgBox,ok $chr(9) Error: Account Creation $chr(9) Account Already Exists $crlf %act $crlf Please Create A New One.)) return
        elseif (!%ae) && ($dcx(MsgBox,ok $chr(9) Error: Account Creation $chr(9) Please Enter Your Email Address)) return
        elseif (!%ap) && ($dcx(MsgBox,ok $chr(9) Error: Account Creation $chr(9) Please Enter Your Password)) return
        else {
          if (!%lastadd) set %lastadd %ae
          writeini soulfly.ini accts %act %ae
          writeini soulfly.ini accts %ae %act
          v_addy %ae $md5(%ap)
          addy8 | xdid -t sf 7 Login
          xdid -r sf 5,6 | xdid -t sf 102
        }
      }
    }
    return
    :sclick2
    if ($dialog(sf)) {
      set -u1 %fav_sclick $true
      xdid -F sf 3
    }
  }
}
alias c_add {
  var %cq = $var(%addr.*,0)
  while (%cq) {
    if (%addr. [ $+ [ %cq ] ] = $1) { set %addr. [ $+ [ %cq ] ] $2 | return }
    dec %cq
  }
}
alias addy8 {
  if (%addy_8) return
  set -u3 %addy_8 $true
  var %8_addy = $var(%addr.*,0), %8_adv, %8_adx
  xdid -r sf 4
  while (%8_addy) {
    %8_adv = $readini(soulfly.ini,Accts,%addr. [ $+ [ %8_addy ] ]) | %8_adx = $iif($readini(soulfly.ini,Accts,%8_adv) = %lastadd,1,0)
    if ($dialog(sf)) xdid -a sf 4 0 1 %8_adx %8_adx 0 %8_adv
    dec %8_addy
  }
  xdid -a sf 4 -1 0 0 1 0 Accounts
}
;FAV DIALOG
alias fav dialog $iif($dialog(join),-v,-m) join join
dialog join {
  title "Join Options"
  size -1 -1 112 101
  option dbu
  icon %tbar
}
on *:dialog:join:init:*:{
  dcx Mark join fav_cb | xdialog -g join +b $rgb(255,255,255)
  xdialog -c join 100 text 0 0 3 21 | xdialog -c join 101 text 53 0 40 21
  xdialog -c join 2 button 3 -3 50 26
  xdialog -c join 3 image 79 0 144 24 | xdialog -c join 4 button 154 37 63 103
  xdialog -c join 20 comboex 7 37 140 280 dropdown
  xdialog -c join 22 comboex 7 77 140 280 dropdown
  xdialog -c join 24 comboex 7 117 140 280 dropdown tooltip | xdid -t join 4 Ok
  xdialog -c join 30 button 154 154 63 38 | xdid -t join 30 delete
  xdialog -c join 31 comboex 7 169 140 200 dropdown
  xdialog -c join 50 check 76 152 70 12 | xdid -t join 50 Auto Join | xdid -C join 100,101 +b $rgb(224,223,228)
  xdid -C join 4,30,50 +b $rgb(255,255,255) | xdid -t join 2 close | xdid -i join 3 +h imgs\sf1.jpg
  xdid -a join 22 0 0 0 0 0 Recent Rooms | xdid -a join 22 0 0 0 0 0 ---------
  xdid -a join 24 0 0 0 0 0 Room List | xdid -a join 24 0 0 0 0 0 Open Room Lister

  xdid -f join 4 +ab ansi 24 trebuchet ms
  xdid -f join 20,22,24,31,50 +ab ansi 8 Tahoma | xdid -f join 2 +ab ansi 12 trebuchet ms
  xdid -c join 20,22,24,31 1 | j_rr | xdid -f join 30 +ab ansi 12 trebuchet ms
  j_fv | j_idl
  if ($hget(soulfly,autojoin)) xdid -c join 50
}
on *:dialog:join:close:*:unset %_fav %_d
alias fav_cb {
  if ($2 = sclick) {
    if ($3 = 2) { dialog -x join join | unset %_fav %_d }
    elseif ($3 = 4) {
      if (%_fav) { $ifmatch | unset %_fav %_d | dialog -x join join }
      else return
    }
    elseif ($3 = 30) {
      if ($gettok(%_d,1,32) = faves) && ($gettok(%_d,2,32) !isin %fav) return
      elseif ($gettok(%_d,1,32) = idl) && ($gettok(%_d,2,32) !isin %idl. [ $+ [ %lastadd ] ]) return
      %_d | j_fv | j_idl
    }
    elseif ($3 = 20) { set %_fav join $gettok(%fav,$calc($4 - 2),44) | set %_d faves $gettok(%fav,$calc($4 - 2),44) }
    elseif ($3 = 22) set %_fav %vrr. [ $+ [ $calc($4 - 2) ] ]
    elseif ($3 = 24) { list }
    elseif ($3 = 31) { set %_fav join $gettok(%idl. [ $+ [ %lastadd ] ],$calc($4 - 2),44) | set %_d idl $gettok(%idl. [ $+ [ %lastadd ] ],$calc($4 - 2),44) }
    elseif ($3 = 50) { hpp soulfly autojoin $true | xdid $iif($hget(soulfly,autojoin),-c,-u) join 50 | xdid -F join 3 }
  }
}
alias j_idl {
  xdid -r join 31 | xdid -a join 31 0 0 0 0 0 Idle List
  xdid -a join 31 0 0 0 0 0 ---------
  var %idl_t = $numtok(%idl. [ $+ [ %lastadd ] ],44), %idl_i = 1
  while (%idl_i <= %idl_t) { xdid -a join 31 0 0 0 0 0 $hcd($gettok(%idl. [ $+ [ %lastadd ] ],%idl_i,44)) | inc %idl_i }
  xdid -c join 31 1
}
alias j_fv {
  xdid -r join 20 | xdid -a join 20 0 0 0 0 0 Favorites | xdid -a join 20 0 0 0 0 0 ---------
  var %fv_t = $numtok(%fav,44), %fv_i = 1
  while (%fv_i <= %fv_t) { xdid -a join 20 0 0 0 0 0 $hcd($gettok(%fav,%fv_i,44)) | inc %fv_i }
  xdid -c join 20 1
}
alias j_rr {
  var %rr_t = $var(%vrr.*,0), %rr_i = 1
  while (%rr_i <= %rr_t) {
    if (%vrr. [ $+ [ %rr_i ] ]) xdid -a join 22 0 0 0 0 0 $hcd($mid($ifmatch,6))
    inc %rr_i
  }
}
alias vlist {
  echo -a $1-
}
;ÅXIS
dialog axis {
  title "SoulFly Åxis "
  size -1 -1 300 210
  option dbu
  box "Clear", 63, 4 133 75 21
  icon %tbar
  list 2, 3 3 294 130, size extsel
  list 60, 140 137 150 2, size
  list 62, 8 140 70 16, size
  button "Set by:", 67, 2 164 21 10
  edit "", 64, 26 164 266 10, read autohs
  button "Notes:", 69, 2 192 21 10
  edit "", 65, 26 192 266 10, read autohs
  button "Mask:", 70, 2 178 21 10
  edit "", 68, 26 178 266 10, read autohs
  button "Nick:", 72, 81 151 21 10
  edit "", 73, 103 151 108 10, read autohs
  button "", 74, 212 151 80 10
}
on *:dialog:axis:init:*:{
  dialog -t axis Åxis $str($chr(160),3) $chr(91) %axis.id $chr(93) 
  ;;mdx_head
  did -b axis 72 | did -h axis 73,74
  ;;xmdx SetControlMDX axis 2 ListView nosortheader grid showsel rowselect single labeltip report > dlls\views.mdx
  did -i axis 2 1 headerdims 59:1 250:2 49:3 208:4 | did -i axis 2 1 headertext + 0 $+(Level,$chr(9),+) 0 $+(Mask,$chr(9),+c) 0 $+(Length,$chr(9),+) 0 Notes
  ;;xmdx SetControlMDX axis 60 ToolBar nodivider list > dlls\bars.mdx
  ;;xmdx SetControlMDX axis 62 ToolBar nodivider wrap > dlls\bars.mdx 
  ;;xmdx SetBorderStyle axis 60,62 
  ;;xmdx SetFont axis 2,64,65,68 12 500 Tahoma
  did -i axis 60,62 1 bmpsize 16 16 | did -i axis 60 1 setimage 0 icon small imgs\147.ico
  did -i axis 60 1 setimage 0 icon small imgs\off.ico | did -i axis 60 1 setimage 0 icon small imgs\dn.ico
  did -i axis 60 1 setimage 0 icon small imgs\up.ico | did -i axis 60 1 setimage 0 icon small imgs\refresh.ico
  did -a axis 60 +a 1 Add | did -a aXIS 60 +a 2 Remove | did -a axis 60 +a 3 Save | did -a axis 60 +a 4 Load | did -a axis 60 +a 5 Refresh
  did -i axis 62 1 setimage icon small imgs\64.ico | did -i axis 62 1 setimage icon small imgs\owner.ico
  did -i axis 62 1 setimage icon small imgs\host.ico | did -i axis 62 1 setimage icon small imgs\man.ico
  did -i axis 62 1 setimage icon small imgs\9.ico
  did -i axis 62 1 setimage icon small imgs\user.ico
  did -a axis 62 +a 1 $chr(9) Clear Deny | did -a axis 62 +a 2 $chr(9) Clear Owners | did -a axis 62 +a 3 $chr(9) Clear Hosts
  did -a axis 62 +a 4 $chr(9) Clear Voiced
  did -a axis 62 +a 5 $chr(9) Clear Grants | did -a axis 62 +a 6 $chr(9) Clear All
}
on *:dialog:axis:sclick:*:{
  if ($did = 2) {
    did -r axis 73,74
    var %hg = $hget($+(axis.,%axis.id),$remove($gettok($gettok($did(2).seltext,11,32),1,32),<,*,$,@,ICMember)), %anix = $gettok($had($remove($gettok(%hg,2,32),!,$chr(42))),1,33)
    did -ra axis 68 $BDC($gettok($gettok($did(2).seltext,11,32),1,32)) | did -ra axis 64 $bdc($gettok(%hg,4,32)) | did -ra axis 65 $right($bdc($gettok(%hg,5-,32)),-1)
    if (%anix) { did -e axis 72 | did -v axis 73,74 | did -ra axis 73 %anix | did -ra axis 74 $bdc(%anix) }
    if (rclick* !iswm $did(2,1)) return
    axis_pop $gettok($gettok($did(2).seltext,11,32),1,32) $gettoK($did(2).seltext,6,32)    
  }
  elseif ($did = 60) {
    var %60 = $did(60).sel
    if (%60 = 2) axis.add.acc
    elseif (%60 = 3) axis.remove $gettok($gettok($did(2).seltext,11,32),1,32) $gettoK($did(2).seltext,6,32)
    elseif (%60 = 4) axis.save
    elseif (%60 = 5) axis.load
    elseif (%60 = 6) axis.refresh
  }
  elseif ($did = 62) {
    var %62 = $did(62).sel
    if (%62 = 2) access %axis.chan clear deny
    if (%62 = 3) access %axis.chan clear owner
    if (%62 = 4) access %axis.chan clear host
    if (%62 = 5) access %axis.chan clear voice
    if (%62 = 6) access %axis.chan clear grant
    if (%62 = 7) access %axis.chan $+(clear,$crlf,access) %axis.chan add $iif($nick(%axis.chan,$me,' .),owner,host) $address($me,10) 0
    axis.refresh
  }
  elseif ($did = 67) clipboard $did(64)
  elseif ($did = 69) clipboard $did(65)
  elseif ($did = 70) clipboard $did(68)
  elseif ($did = 72) && ($did(73) != $null) clipboard $did(73)
  elseif ($did = 74) && ($did(74) != $null) clipboard $did(74)
}
alias axis_pop {
  if ($xpopup(axis).ismenu) xpopup -d axis
  xpopup -c axis graderev
  xpopup -x axis +p
  xpop -a axis 1 $chr(9) +g 0 0 $iif(!$1,Axis,$1)
  xpop -a axis 2 $chr(9) + 0 0 -
  xpop -a axis 3 $chr(9) + 1 0 Remove
  xpop -a axis 4 $chr(9) + 2 0 Add $bdc($me)
  xpop -a axis 5 $chr(9) + 3 0 Deny Guests
  xpop -a axis 6 $chr(9) + 4 0 Save List
  xpop -a axis 7 $chr(9) + 5 0 Load List
  xpop -a axis 8 $chr(9) + 6 0 Refresh
  xpopup -s axis +c $Mouse.dx $Mouse.dy
}
ON *:SIGNAL:Xpopup-axis:{
  if ($1 = 1) axis.remove $gettok($gettok($did(axis,2).seltext,11,32),1,32) $gettoK($did(axis,2).seltext,6,32)
  elseif ($1 = 2) { access %axis.chan add $iif($nick(%axis.chan,$me,' .),owner,host) $address($me,3) 0 :Axis add $me | axis.refresh }
  elseif ($1 = 3) { access %axis.chan add deny *!*@GuestGate* | axis.refresh }
  elseif ($1 = 4) axis.save
  elseif ($1 = 5) axis.load
  elseif ($1 = 6) axis.refresh
}
on *:dialog:axis:close:*:unset %axis*
;ERROR
dialog error {
  title "SoulFly Notice"
  size -1 -1 166 74
  option dbu
  icon imgs\1x.ico
  icon 101, -14 -5 101 23, imgs\sf1.jpg, 0, noborder
  text "", 102, 0 0 72 1
  text "", 3, 72 0 76 12, center
  button "close", 1, 55 59 110 13, ok
  text "", 2, 5 16 158 42, center wrap
  check "", 4, 4 62 8 8
  text "Do Not Show This Window", 5, 15 59 40 20, wrap
  text "", 6, 148 0 20 12
}
on *:dialog:error:init:*:{
  did -f error 101 | $iif(!%err_d,set %err_d $iif(%error_dur,$v1,4))
  ;;mdx_head 
  ;;xmdx SetDialog error bgcolor $rgb(255,255,255)
  ;;xmdx SetFont error 6 24 500 comic sans ms 
  ;;xmdx SetFont error 1,3 22 500 Palatino Linotype bold
  ;;xmdx SetFont error 2 18 500 arial bold
  ;;xmdx SetColor error 6 text $rgb(255,255,255)
  ;;xmdx SetColor error 3 text $rgb(61,114,180)
  ;;xmdx SetColor error 1,2,4,5 background $rgb(255,255,255)
  ;;xmdx SetColor error 2,5 textbg $rgb(255,255,255)
  did -ra error 6 %err_d
  .timererrord %err_d 1 error_d 
  ;;xmdx SetColor error 3,6,102,151 background $rgb(224,223,228)
  ;;xmdx SetColor error 3,6 textbg $rgb(224,223,228)
  if (%err_t) { dialog -t error %err_t | did -ra error 3 %err_t }
  if (%err_r) did -ra error 2 %err_r
  did $iif($hget(SoulFly,error),-c,-u) error 4
}
on *:dialog:error:sclick:1:{ $iif($timer(errord),.timererrord off) | unset %err_* }
on *:dialog:error:sclick:4:{ $iif($hget(SoulFly,errorx),hdel,hadd) SoulFly errorx ON | dialog -x error error }
on *:dialog:error:close:*:{ $iif($timer(errord),.timererrord off) | unset %err_* }
alias roomkeyz {
  if (!$1) && ($regex($active,/^%#/)) set %rk_chan $active
  else set %rk_chan $1
  dialog $iif($dialog(rkeyz),-v,-mh) rkeyz rkeyz
}
dialog rkeyz {
  title "Room Keys"
  size -1 -1 104 64
  option dbu
  icon %tbar
  list 101, 33 17 69 8, size
  list 102, 33 42 69 8, size
  edit "", 1, 2 27 100 10
  edit "", 2, 2 52 100 10
  text "Owner", 3, 2 16 25 8
  text "Host", 4, 2 42 30 8
  combo 100, 2 1 100 80, drop size
}
on *:dialog:rkeyz:init:*:{
  if (!%rk_chan) set %rk_chan $iif($regex($active,/^%#/),$active,Choose Channel)
  ;;mdx_head
  ;;xmdx SetDialog rkeyz bgcolor $rgb(255,255,255)
  ;;xmdx SetColor rkeyz 1,2,3,4,100,101,102 background $rgb(255,255,255)
  ;;xmdx SetColor rkeyz 3,4 textbg $rgb(255,255,255)
  ;;xmdx SetColor rkeyz 1,2,100 text $rgb(1,111,201)
  ;;xmdx SetFont rkeyz 3,4,100 18 500 Palatino Linotype Bold
  ;;xmdx SetFont rkeyz 101,102 14 500 Arial
  ;;xmdx SetControlMDX rkeyz 101,102 ToolBar flat nodivider list > dlls\bars.mdx 
  ;;xmdx SetBorderStyle rkeyz 101,102
  did -i rkeyz 101,102 1 bmpsize 1 6 | did -a rkeyz 101 +W 43 Reset
  did -a rkeyz 101 +W 53 Random | did -a rkeyz 101 -
  did -a rkeyz 101 +W 31 Set | did -a rkeyz 102 +W 43 Reset
  did -a rkeyz 102 +W 53 Random | did -a rkeyz 102 -
  did -a rkeyz 102 +W 31 Set
  if (%rk_chan != Choose Channel) && (!$nick(%rk_chan,$me,' .)) did -ra rkeyz 1 You are not an OP in $hget(soulfly,%rk_chan) !
  did -a rkeyz 100 %rk_chan
  did100
  if ($hget(prot,q $+ %rk_chan)) did -ra rkeyz 1 $v1
  if ($hget(prot,o $+ %rk_chan)) did -ra rkeyz 2 $v1
}
on *:dialog:rkeyz:sclick:100:{
  set %rk_chan $did(100)
  if ($hget(prot,$+(q,%rk_chan))) did -ra rkeyz 1 $v1
  if ($hget(prot,$+(o,%rk_chan))) did -ra rkeyz 2 $v1
}
on *:dialog:rkeyz:sclick:101:{
  if ($did(101).sel = 2) did -ra rkeyz 1 $hget(prot,$+(q,%rk_chan))
  elseif ($did(101).sel = 3) did -ra rkeyz 1 $rkey
  elseif ($did(101).sel = 5) {
    hadd prot $+(q,%rk_chan) $did(1)
    prop %rk_chan ownerkey $did(1)
    echo %_cc -a OwnerKey changed to $did(1)
  }
}
on *:dialog:rkeyz:sclick:102:{
  if ($did(102).sel = 2) did -ra rkeyz 2 $hget(prot,$+(o,%rk_chan))
  elseif ($did(102).sel = 3) did -ra rkeyz 2 $rkey
  elseif ($did(102).sel = 5) { hadd prot $+(o,%rk_chan) $did(2) | prop %rk_chan hostkey $did(2) | echo %_cc %rk_chan HostKey changed to $did(2) }
}
on *:dialog:rkeyz:close:*:unset %rk_chan
alias did100 {
  var %k, %ci_, %chan = $chan(0)
  while (%chan) {
    %ci_ = $chan(%chan)
    if ($nick(%ci_,$me,' .)) && (%ci_ != %rk_chan) %k = $addtok(%k,%ci_,44)
    dec %chan
  }
  if ($dialog(rkeyz)) { 
    didtok rkeyz 100 44 %k
    did -c rkeyz 100 $findtok($didtok(rkeyz,100,44),%rk_chan,44)
  }
}
;EMOTES
dialog emote {
  title "Emotes"
  size -1 -1 193 154
  option dbu
  icon %tbar
}
on *:dialog:emote:init:*:{
  dcx Mark emote em_cb
  xdialog -b emote +coty | xdialog -c emote 1 image 0 0 382 307
  xdid -i emote 1 +h imgs\emote.jpg
}
;time adjust
alias time_adj dialog $iif($dialog(time),-vo,-mho) time time
dialog time {
  title "Time Reply Options"
  size -1 -1 164 90
  option dbu
  icon %tbar
  text "", 100, 0 0 90 10
  text "", 102, 162 0 2 10
  icon 101, 76 -7 100 24, imgs\sf1.jpg, 0, noborder
  button "close", 5, 3 -2 28 14
  edit "", 1, 3 43 158 30, multi autovs limit 110
  button "Default", 2, 40 76 34 10
  button "Set", 3, 76 76 34 10, ok
  text "", 4, 0 22 164 20, center
  button "Test", 6, 3 76 34 10
  button "", 7, 124 76 38 10
}
on *:dialog:time:init:*:{
  ;;mdx_head 
  did -f time 101
  ;;xmdx SetDialog time bgcolor $rgb(255,255,255)
  ;;xmdx SetFont time 5 24 500 Trebuchet MS bold
  ;;xmdx SetFont time 1,2,3,6,7 20 500 Palatino Linotype bold
  ;;xmdx SetFont time 4 16 500 Arial bold
  ;;xmdx SetColor time 4 textbg $rgb(255,255,255)
  ;;xmdx SetColor time 2,3,4,6,7 background $rgb(255,255,255)
  did -ra time 4 $iif($readini(soulfly.ini,misc,time),$ifmatch,$asctime(ddd mmm dd HH:nn:ss) GMT $+ $asctime(zz yyyy))
  did -ra time 1 $iif($readini(soulfly.ini,misc,time),$ifmatch,$!asctime(ddd mmm dd HH:nn:ss) GMT $!+ $!asctime(zz yyyy)) | did -ra time 7 Turn $iif(!$hget(soulfly,timex),Off,On)
}
on *:dialog:time:sclick:*:{
  if ($did = 5) dialog -x time time
  elseif ($did = 2) { did -ra time 1 $!asctime(ddd mmm dd HH:nn:ss) GMT $!+ $!asctime(zz yyyy) | did -ra time 4 $asctime(ddd mmm dd HH:nn:ss) $+(GMT,$asctime(zz yyyy)) | remini soulfly.ini misc time | set %trply_d $true }
  elseif ($did = 3) && (!%trply_d) { writeini soulfly.ini misc time $didtok(1,32) }
  elseif ($did = 6) { did -ra time 4 [ [ $didtok(1,32) ] ] }
  elseif ($did = 7) { hpp soulfly timex $true | did -ra time 7 Turn $iif(!$hget(soulfly,timex),Off,On) }
}
on *:dialog:time:close:*:unset %trply_d
alias aj {
  if (%sha) return
  dialog $iif($dialog(dxist),-vh,-m)) dxist dxist
}
dialog aj {
  title "Auto-Join"
  size -1 -1 110 76
  option dbu
  icon %tbar
  icon 101, -14 -5 101 23, imgs\sf1.jpg, 0, noborder
  text "", 102, 0 0 76 1
  text "", 3, 72 0 38 12, center
  button "close", 1, 2 64 106 11
  text "", 9, 3 13 104 10, center
  text "Does Not Exist", 7, 3 25 104 10, center
  text "Would You Like To Create It?", 8, 3 34 104 10, center
  button "Yes", 10, 5 47 46 14
  button "No", 11, 59 47 46 14
}
;dxist
alias dxist {
  if ($1) set %dxist $1
  dialog $iif($dialog(dxist),-vh,-m)) dxist dxist
}
dialog dxist {
  title ""
  size -1 -1 110 60
  option dbu
  icon %tbar
  icon 101, -14 -5 101 23, imgs\sf1.jpg, 0, noborder
  text "", 102, 0 0 76 1
  text "", 3, 72 0 38 12, center
  button "Close", 1, 66 46 42 12
  text "", 9, 0 16 110 10, center
  text "Room Does Not Exist", 7, 5 28 93 10
  text "Would You Like To Create It?", 8, 5 35 93 10
  button "Yes", 10, 3 46 30 12
  button "No", 11, 34 46 24 12
}
on *:dialog:dxist:init:*:{
  ;;mdx_head
  ;;xmdx SetColor dxist 3,102 background $rgb(224,223,228)
  ;;xmdx SetDialog dxist bgcolor $rgb(255,255,255)
  ;;xmdx SetFont dxist 1,7,8,9,10,11 18 500 Trebuchet MS bold
  ;;xmdx SetColor dxist 1,7,8,9,10,11 background $rgb(255,255,255)
  ;;xmdx SetColor dxist 7,8,9 textbg $rgb(255,255,255)
  ;;xmdx SetColor dxist 7,8 text $rgb(34,60,159)
  if (%dxist) { dialog -t dxist $V_ | did -ra dxist 9 $remove(%dxist,%,$chr(35)) }
  did -f dxist 101
}
on *:dialog:dxist:sclick:*:{
  if ($did = 1) || ($did = 11) {
    unset $eval(%dxist) %dxist
    dialog -x dxist dxist
  }
  elseif ($did = 10) {
    create $right(%dxist,-2)
    unset %dxist
    dialog -x dxist dxist
  }
}
alias create {
  unset %rc_* %cr
  if ($1) set %cr_xx $1-
  dialog $iif($dialog(roomcreate),-vh,-m)) roomcreate roomcreate
}
dialog roomcreate {
  title "Room Creator"
  size -1 -1 194 99
  option dbu
  icon %tbar
  text "", 100, 0 0 116 10
  icon 101, 80 -4 144 17, imgs\sf1.jpg, 0, noborder
  text "", 102, 188 0 6 10
  combo 3, 2 14 85 80, size drop edit
  combo 6, 2 32 120 80, size drop edit
  edit "", 8, 2 49 100 12, center autohs
  button "Pass", 9, 104 49 18 12
  combo 10, 126 32 66 80, size drop right
  edit "100", 11, 92 14 30 12, autohs
  combo 13, 126 14 66 80, size drop
  button "close", 14, 2 -2 27 13
  button "Save", 15, 126 66 32 12
  button "Create", 16, 126 48 66 16
  edit "Welcome Message", 18, 2 66 120 12, center autohs
  button "Del", 19, 160 66 32 12
  text "", 22, 0 87 194 9
  text "", 21, 110 87 64 9, right
  button ">>", 20, 176 86 14 11
  button "modes", 99, 5 86 35 11
}
alias cr_load {
  did -r roomcreate 3
  var %f_ = lists\rooms.ini, %rx_ = $ini(%f_,0)
  while (%rx_) {
    if ($ini(%f_,%rx_) != topic) did -ca roomcreate 3 $v1
    dec %rx_
  }
  if ($1 = init) {
    %rx_ = $ini(lists\rooms.ini,topic,0)
    while ($readini(lists\rooms.ini,topic,%rx_)) {
      did -ca roomcreate 6 $ifmatch
      dec %rx_
    }
  }
  elseif ($1) did -ca roomcreate 3 $1
}
on *:dialog:roomcreate:init:*:{
  ;;mdx_head
  ;;xmdx SetDialog roomcreate bgcolor $rgb(255,255,255)
  ;;xmdx SetColor roomcreate 100,102,103,104 background $rgb(224,223,228)
  ;;xmdx SetColor roomcreate 3,6,8,10,11,13,18 text $rgb(48,105,254)
  ;;xmdx SetFont roomcreate 14,15,16,19,20,99 24 500 Trebuchet MS Bold
  ;; xmdx SetFont roomcreate 3,6,8,10,11,13,18 16 500 arial
  ;;xmdx SetFont roomcreate 21 20 500 Trebuchet MS Bold
  did -b roomcreate 15,19
  ;;xmdx SetColor roomcreate 15,16,19 background $rgb(255,255,255)
  did -ra roomcreate 8 Password
  cr_load init
  did -ca roomcreate 6 Room Topic
  didtok roomcreate 13 44 English,Dutch,French,German,Spanish,Italian,Chinese,Arabic,Urdu,Turkish,Portuguese,Malayalam,Japanese,Indonesian,Hindi,Hebrew,Finnish,Greek,Danish | did -c roomcreate 13 1
  didtok roomcreate 10 46 $_ct
  did -c roomcreate 10 14
  did -ra roomcreate 21 $iif($dialog(rc_edit),Close, Open) Text Editor
  if (%cr_xx) did -ca roomcreate 3 %cr_xx
  else did -ca roomcreate 3 Room Name
  did -f roomcreate 101
}
on *:dialog:roomcreate:edit:*:{
  set %rc_did $rc_did($did) $did($did)
  if ($did isin 3 6) did -e roomcreate 15,16,19
}
alias rc_did {
  if ($1 = 3) return Name
  elseif ($1 = 6) return Topic
  elseif ($1 = 8) return Password
  elseif ($1 = 18) return Welcome
  elseif ($1 = Topic) return 6
  elseif ($1 = Room Name) return 3
  elseif ($1 = Password) return 8
  elseif ($1 = Welcome) return 18
  else return Select...
}
on *:dialog:roomcreate:sclick:15:{
  if ($ini(lists\rooms.ini,$did(3))) && (!$input($did(3) Exists. Would you like to overwrite?,ywd,Saved Room Exists)) return
  cr_save
}
on *:dialog:roomcreate:sclick:16:cr_save join
on *:dialog:roomcreate:sclick:19:{
  if ($did(3) = Room Name) || ($did(3) = $null) noop $tip(sf_rc,$v_ $str($chr(160),24) Room Create:,Room Creation Error $crlf $crlf Please enter a room name,%error_dur,%tbar)
  elseif (!$ini(lists\rooms.ini,$did(3))) noop $tip(sf_rc,$v_ $str($chr(160),24) Room Create:,Room Creation Error $crlf $crlf $did(3) does not exist!,%error_dur,%tbar)
  else { remini lists\rooms.ini $did(3) | noop $tip(sf_rc,$v_ $str($chr(160),24) Room Create:,Room Creation Error $crlf $crlf Successfully removed $did(3),%error_dur,%tbar) }
}
on *:dialog:roomcreate:sclick:*:{
  if ($did = 3) {
    did -e roomcreate 15,19
    var %fv_ = $did(3)
    if (!$ini(lists\rooms.ini,%fv_)) return
    did -ca roomcreate 6 $readini(lists\rooms.ini,%fv_,topic)
    did -ra roomcreate 8 $readini(lists\rooms.ini,%fv_,Pass)
    did -ca roomcreate 10 $_cat($readini(lists\rooms.ini,%fv_,Category))
    did -ra roomcreate 11 $readini(lists\rooms.ini,%fv_,limit)
    did -ca roomcreate 13 $_lang($readini(lists\rooms.ini,%fv_,language))
    did -ra roomcreate 18 $readini(lists\rooms.ini,%fv_,welcome)
  }
  elseif ($did = 6) did -e roomcreate 15,19
  elseif ($did = 9) { did -ra roomcreate 8 $rkey | did -f roomcreate 8 }
  elseif ($did = 14) {
    unset %rc_did %cr_*
    if ($dialog(rc_mode)) dialog -x rc_mode rc_mode
    if ($dialog(rc_edit)) dialog -x rc_edit rc_edit
    dialog -x roomcreate roomcreate
  }
  elseif ($did = 20) {
    dialog $iif($dialog(rc_edit),-x,-m) rc_edit rc_edit
    did -ra roomcreate 20 $iif($dialog(rc_edit),<<,>>)
    did -ra roomcreate 21 $iif($dialog(rc_edit),Close,Open) Text Editor
  }
  elseif ($did = 99) {
    if ($dialog(rc_mode)) dialog -x rc_mode rc_mode
    else rc_mode
  }
}
on *:dialog:roomcreate:close:*:{
  unset %rc_did %cr_*
  if ($dialog(rc_mode)) dialog -x rc_mode rc_mode
  if ($dialog(rc_edit)) dialog -x rc_edit rc_edit
}
alias rc_mode dialog $iif($dialog(rc_mode),-vh,-m) rc_mode rc_mode
dialog -l rc_mode {
  title "Room Create: Modes"
  size -1 -1 110 82
  option dbu
  icon %tbar
  text "", 99, 0 0 110 14
  text "", 1, 3 1 107 12
  button "Ok", 100, 90 -2 18 17, ok
  check " Private", 2, 2 20 40 10
  check " Secret", 3, 2 30 40 10
  check "Flood Prot", 4, 2 40 40 10
  check " Invite Only", 5, 2 50 40 10
  check "Moderated", 6, 58 30 40 10
  check "Show Knocks", 7, 58 40 40 10
  check "Topic Lock", 8, 58 20 40 10
  check "Remove Formatting", 9, 58 50 40 8
  check "Block Queries", 10, 2 60 40 8
  check "No Guest Query", 11, 58 60 50 8
  check "Key", 13, 2 71 17 10, group
  edit "", 14, 22 71 86 9
}
alias -l rc_modes {
  if ($readini(lists\rooms.ini,$1,Mode)) || (%cr_mode) var %rm = $ifmatch
  if ($readini(lists\rooms.ini,$1,key)) || (%cr_rkey) var %rm_key = $ifmatch
  if (p isletter %rm) did -c rc_mode 2
  if (s isin %rm) did -c rc_mode 3
  if (P isletter %rm) did -c rc_mode 4
  if (i isin %rm) did -c rc_mode 5
  if (m isin %rm) did -c rc_mode 6
  if (u isin %rm) did -c rc_mode 7
  if (t isin %rm) did -c rc_mode 8
  if (w isletter %rm) did -c rc_mode 10
  if (W isletter %rm) did -c rc_mode 11
  if (f isin %rm) did -c rc_mode 9
  if (%rm_key) {
    did -c rc_mode 13
    did -nra rc_mode 14 $ifmatch
  }
}
on *:dialog:rc_mode:init:*:{
  ;mdx_head
  did -m rc_mode 14
  ;; xmdx SetDialog rc_mode bgcolor $rgb(255,255,255)
  did -ra rc_mode 1 $did(roomcreate,3)
  ;;xmdx SetColor rc_mode 2,3,4,5,6,7,8,9,10,11,13 background $rgb(255,255,255)
  ;; xmdx SetFont rc_mode 1,100 22 500 Trebuchet MS Bold
  rc_modes $did(roomcreate,3)
}
on *:dialog:rc_mode:sclick:*:{
  if ($did = 13) {
    if ($did(13).state) did -fn rc_mode 14
    else did -mr rc_mode 14
  }
  elseif ($did = 100) {
    set %cr_mode $+(+,$iif($did(10).state,w),$iif($did(11).state,W),$iif($did(9).state,f),$iif($did(2).state,p),$iif($did(3).state,s),$iif($did(4).state,P),$iif($did(5).state,i),$iif($did(6).state,m),$iif($did(7).state,u),$iif($did(8).state,t))
    if ($did(13).state) set %cr_rkey $iif($did(14),$ifmatch,key)
  }
}
alias rc_edit dialog $iif($dialog(rc_edit),-vh,-m)) rc_edit rc_edit
dialog -l rc_edit {
  title "Room Create Editor"
  size -1 -1 180 60
  option dbu
  icon %tbar
  combo 1, 2 2 80 50, size drop
  edit "", 2, 2 17 176 40, multi autovs vsbar
  icon 101, 68 -3 148 22, imgs\sf1.jpg, 0, noborder
  button "Ok", 5, 84 1 18 14, ok
}
on *:dialog:rc_edit:init:*:{
  ;; mdx_head
  ;;xmdx SetFont rc_edit 1,2 16 500 arial
  ;;xmdx SetFont rc_edit 5 24 500 Trebuchet MS Bold
  didtok rc_edit 1 44 Room Name,Topic,Welcome
  if (%rc_did) {
    did -ca rc_edit 1 $gettok(%rc_did,1,32)
    did -ra rc_edit 2 $gettok(%rc_did,2-,32)
  }
  else did -ca rc_edit 1 $did(roomcreate,3)
}
on *:dialog:rc_edit:sclick:*:{
  if ($did = 1) {
    if ($rc_did($did(1))) did -ra rc_edit 2 $did(roomcreate,$ifmatch)
  }
  if ($did = 5) && ($did(2)) {
    if (!$did(1)) { error -e Room Create: $crlf Please select a category for your edited message! | dialog -f rc_edit 1 | return }
    else did -ca roomcreate $rc_did($did(1)) $did(2)
  }
}
on *:dialog:rc_edit:close:*:{
  if (!$dialog(roomcreate)) return
  did -ra roomcreate 21 Open Text Editor | did -ra roomcreate 20 >>
}
alias cr_save {
  var %d3 = $remove($replace($did(roomcreate,3),$chr(32),\b),$chr(37),$chr(35)), %ct = $did(roomcreate,10), %lm = $did(roomcreate,11), %lg = $did(roomcreate,13)
  if (!%d3) { noop $tip(sf_rc,$v_ $str($chr(160),24) Room Create:,Room Creation Error $crlf $crlf No Channel Name,%error_dur,%tbar) | goto re }
  if (!$did(roomcreate,6)) {
    if ($input(No topic given. Are you sure you do not want a topic?,ywd,Room Creation)) set %cr_topic $false
    else goto re
  }
  else set %cr_topic $did(roomcreate,6)
  if (%ct = $null) || (%ct = Category) { noop $tip(sf_rc,$v_ $str($chr(160),24) Room Create:,Room Creation Error $crlf $crlf No Category Selected,%error_dur,%tbar) | goto re }
  else set %cr_cat $_cat(%ct)
  if (!%lm) || (%lm !isnum) set %cr_lim 100
  else set %cr_lim %lm
  if (%lg = $null) || (%lg = Language) set %cr_lang EN
  else set %cr_lang $_lang(%lg)
  if (!%cr_mode) && ($readini(lists\rooms.ini,$remove(%d3,$chr(37),$chr(35)),mode)) set %cr_mode $ifmatch
  if ($did(roomcreate,8)) set %cr_key $ifmatch
  else set %cr_key $false
  if ($did(roomcreate,18)) set %cr_welcome $ifmatch
  else set %cr_welcome $false
  if (%cr_topic) {
    writeini lists\rooms.ini %d3 Topic %cr_topic
    cr_mode_topic %cr_topic
  }
  if (%cr_cat) writeini lists\rooms.ini %d3 Category %cr_cat
  if (%cr_lang) writeini lists\rooms.ini %d3 Language %cr_lang
  if (%cr_key) writeini lists\rooms.ini %d3 Pass %cr_key
  if (%cr_lim) writeini lists\rooms.ini %d3 Limit %cr_lim
  if (%cr_welcome) writeini lists\rooms.ini %d3 Welcome %cr_welcome
  if (%cr_mode) writeini lists\rooms.ini %d3 Mode %cr_mode
  if (%cr_rkey) writeini lists\rooms.ini %d3 Key %cr_rkey
  echo -a 0,10 [RoomCreate] 9,1 Saved 0,1 %d3 9,1 channel properties. 
  if ($1 = join) {
    var %fy_ = $e($+($chr(35),%d3))
    set %fy_ %fy_
    set %cr_room %fy_
    jroom %cr_room
  }
  else cr_load %d3
  return
  :re {
    if ($dialog(roomcreate)) dialog -v roomcreate roomcreate
  }
}
alias cr_mode_topic {
  var %ct = $ini(lists\rooms.ini,topic,0)
  if (!%ct) { writeini lists\rooms.ini topic 1 $1- | return }
  while (%ct) {
    if ($1- = $readini(lists\rooms.ini,topic,%ct)) return
    dec %ct
  }
  writeini lists\rooms.ini topic $calc($ini(lists\rooms.ini,topic,0) + 1) $1-
  return
}
;Manage User Lists
alias lists dialog $iif($dialog(lists),-v,-mh) lists lists
dialog lists {
  title "User Lists"
  size -1 -1 216 141
  option dbu
  icon %tbar
  icon 101, 130 -3 100 22, imgs\sf1.jpg, 0, noborder
  button "close", 5, 1 -2 23 15
  list 6, 12 16 203 124, extsel size
  combo 7, 28 2 40 80, drop size
  list 10, 0 28 11 62
  button "copy", 11, 70 0 18 16
  edit "", 12, 90 2 52 12, read autohs
}
on *:dialog:lists:init:*:{
  dialog -t lists User List $str($chr(160),10) [Ignore]
  ;;mdx_head
  ;;xmdx SetControlMDX $dname 6 ListView nosortheader showsel grid rowselect single labeltip report > dlls\views.mdx
  ;;xmdx SetControlMDX lists 10 ToolBar nodivider wrap > dlls\bars.mdx
  ;;xmdx SetBorderStyle lists 10 | did -i lists 10 1 bmpsize 16 16
  did -i lists 10 1 setimage icon small imgs\64.ico | did -i lists 10 1 setimage icon small imgs\up.ico
  did -i lists 10 1 setimage icon small imgs\dn.ico
  did -a lists 10 +a 2 $chr(9) Add | did -a lists 10 +a 3 $chr(9) Remove
  did -a lists 10 +ad $chr(9) | did -a lists 10 +a 1 $chr(9) Remove All
  did -i lists 6 1 headerdims 138:1 263:2 | did -i lists 6 1 headertext + 0 User $+($chr(9),+) 0 User Mask
  ;;xmdx SetColor lists 6,10,11,12 background $rgb(224,223,228)
  ;;xmdx SetDialog lists bgcolor $rgb(224,223,228)
  ;;xmdx SetFont lists 5 22 500 Trebuchet MS Bold
  ;;xmdx SetFont lists 6,12 16 500 Arial
  ;;xmdx SetFont lists 7,11 16 500 Arial bold
  didtok lists 7 44 Q Key,Op Key,Whisper,Notice
  did -ca lists 7 Ignore
  if ($script(sfb_prot.mrc)) && ($readini(soulfly.ini,version,sfb_prot.mrc) >= 1.4) didtok lists 7 44 Banned,Allowed,Mute
  L_init | did -f lists 101
}
on *:dialog:lists:sclick:5:dialog -x lists lists
on *:dialog:lists:Sclick:6:{
  if ($mouse.x isnum 40-172) did -ra lists 12 $gettok($did(6).seltext,6,32)
  elseif ($mouse.x isnum 181-421) did -ra lists 12 $gettok($did(6).seltext,-1,32)
}
on *:dialog:lists:sclick:7:{
  did -f lists 101
  dialog -t lists User List $str($chr(160),10) $+([,$did(7),])
  L_init
}
on *:dialog:lists:sclick:10:{
  var %qt = $did(10).sel
  if (%qt = 2) L_add $did(7).seltext $gettok($did(6).seltext,6,32)
  elseif (%qt = 3) L_remove $did(7).seltext $gettok($did(6).seltext,-1,32) $gettok($did(6).seltext,6,32)
  elseif (%qt = 5) L_remove $did(7).seltext all
}
on *:dialog:lists:sclick:11:clipboard $did(12)
alias credits {
  clear -s | echo -s $chr(160)
  echo -s $str($chr(160),12) 11,0 $chr(160) $str($chr(150),24) $chr(160) 
  echo -s $str($chr(160),12) 2,0 $+ $chr(160) -= Welcome to IRC-Community =- 
  echo -s $str($chr(160),12) 11,0 $chr(160) $str($chr(150),24) $chr(160) 
  echo -s $str($chr(160),12) 10,0 $str($chr(160),7) on $v_  | echo -s $chr(160)
  if (%lastadd) { echo -s 2,0 Logging In:  | echo -s $str($chr(160),3) 10,0 > 4,0 %lastadd $chr(160)  }
  echo -s $chr(160) | echo -s $chr(160)
  echo -s 3 Thank You for choosing 10,9 SoulFly  | echo -s $chr(160)
  echo -s 2 Please visit the SoulFly forum for any support or to report any bugs you may find.
  echo -s $chr(160) | echo 12 -s $str($chr(160),10) www.SoulFly-iRC.com
  echo -s $chr(160) | echo 2 -s I hope you enjoy SoulFly!
}
