All pastes #815854 Raw Edit

Auth_system V2.0

public text v1 · immutable
·published 2007-12-14 13:13 UTC
rendered paste body

;##########################################################
;#####Snpster auth/user system(gamesurge) #Plutonic########
;##########################################################
on *:TEXT:.*:*: {
  set %my.chan $chan
  set %auth.nick $nick
  set %auth.command $1-
  as userinfo $nick
}
;$address($me,-1)
;#########################################################
;############### Muli`chan Commands ######################
;#########################################################
;#########################################################
on *:NOTICE:*authenticated to*:*:{
  set %auth.user $remove($left($6,-1),$chr(2))
  if (%auth_ban == 1 ) {
    set %auth.level $null
    set %auth.level $readini(data.ini,users,%auth.user)
    if (!%auth.level) || (%auth.level !isnum) || (%auth.level < 0) {
      set %auth.level 0
    }
    if (%auth.level >= %b.auth_level) {
      msg %my.chan %skin.start Ban %skin.mid $3 $+ ( $+ %auth.nick $+ ) has equal or greater access, you cannot ban them %skin.end
      set %auth_ban 0
    }
    elseif (%auth.level < %b.auth_level) {
      msg chanserv %my.chan ban %auth.nick %auth.b_msg
      msg %my.chan %skin.start Ban %skin.mid $3 $+ ( $+ %auth.nick $+ ) has been Banned Reason:5 %auth.k_msg %skin.end
      set %auth_ban 0
    }
  }




  if (%auth_kick == 1) {
    set %auth.level $null
    set %auth.level $readini(data.ini,users,%auth.user)
    if (!%auth.level) {
      set %auth.level 0
    }
    if (%auth.level >= %k.auth_level) {
      msg %my.chan %skin.start Kick %skin.mid $3 $+ ( $+ %auth.nick $+ ) has equal or greater access, you cannot kick them %skin.end
      set %auth_kick 0
    }
    elseif (%auth.level < %k.auth_level) {
      msg chanserv %my.chan kick %auth.nick %auth.k_msg
      msg %my.chan %skin.start Kick %skin.mid $3 $+ ( $+ %auth.nick $+ ) has been kicked Reason:5 %auth.k_msg %skin.end
      set %auth_kick 0
    }
  }





  elseif (%auth_add.user == 1) {
    writeini data.ini users %auth.user %auth_add.level
    msg %my.chan %skin.start User(s) %skin.mid $3 $+ ( $+ %auth.nick $+ ) has been added with access %auth_add.level %skin.end
    set %auth_add.user 0
  } 




  elseif (%auth_del.user == 1) {
    set %auth.level $readini(data.ini,users,%auth.user)
    if (%auth.level >= %auth_del.level) { 
      msg %my.chan %skin.start User(s) %skin.mid $3 $+ ( $+ %auth.nick $+ ) has not been deleted, your access is to low %skin.end
      set %auth_del.user 0
    } 
    else {
      writeini data.ini users %auth.user 0
      msg %my.chan %skin.start User(s) %skin.mid $3 $+ ( $+ %auth.nick $+ ) has been removed %skin.end
      set %auth_del.user 0
    }
  }





  elseif (%auth_axs.status == 1) {
    set %auth_axs.status 0
    set %auth.level 0
    set %auth.level $readini(data.ini,users,%auth.user)
    if (%auth.level < 0) || (%auth.level !isnum) {
      set %auth.level 0
    }
    if (%auth.level >= 0) {
      msg %my.chan %skin.start User(s) %skin.mid %auth_axs.nick2 $+ ( $+ %auth.user $+ ) has %auth.level access to Me(4 $+ $me $+ 15) %skin.end
    }
    else {
      msg %my.chan %skin.start User(s) %skin.mid %auth_axs.nick2 $+ ( $+ %auth.user $+ ) has 0 access to Me(4 $+ $me $+ 15) %skin.end
    }
  }





  elseif (%auth_clvl.user == 1) {
    set %auth_clvl.user 0
    set %auth.level $null
    set %auth.level $readini(data.ini,users,%auth.user)
    if (!%auth.level) {
      set %auth.level 0
    }
    if (%auth.level < %auth_clvl.level2) && (%auth.level > 0) {
      writeini data.ini users %auth.user %auth_clvl.level
      msg %my.chan %skin.start User(s) %skin.mid %auth.nick $+ ( $+ %auth.user $+ ) now has %auth_clvl.level access to Me(4 $+ $me $+ 15) %skin.end
    }
    elseif (%auth.level >= %auth_clvl.level2) {
      msg %my.chan %skin.start User(s) %skin.mid %auth.nick $+ ( $+ %auth.user $+ ) has equal or greater access to Me(4 $+ $me $+ 15) - 4Permission Denied %skin.end
    }
    else {
      msg %my.chan %skin.start User(s) %skin.mid %auth.nick $+ ( $+ %auth.user $+ ) does not have access to Me(4 $+ $me $+ 15) %skin.end
    }
  }





  else {
    set %auth.level $null
    set %auth.level $readini(data.ini,users,%auth.user)
    if (%auth.level < 400) {
      ignore %auth.nick
      .timer $+ %auth.nick $+ ignore 1 5 /ignore -r %auth.nick
    }
    auth_commands %auth.command
  }
}

raw 401:*: {
  set %auth.user Not Authed
}
on *:CONNECT:{
  auto_channel
  timerz
}


alias auth_commands {
  if ($1 == .add) {



    if ($2 == quote) && (%auth.level >= 498) {



      write quotes.txt $3-
      msg %my.chan %skin.start Quote %skin.mid 14" $+ $3- $+ "15 added to quotes %skin.end
    }
    if ($2 == user) {



      if ($4 >= %auth.level) {
        msg $my.chan %skin.start User(s) %skin.mid You do not have $4 access to add someone %skin.end
        halt
      }
      if (!$3) || (!$4) { msg %my.chan %skin.start User(s) %skin.mid Incorrect Syntax, .add user <user> <level> %skin.end | halt }
      set %auth_add.user 1
      set %auth_add.nick %auth.nick
      set %auth.nick $3
      set %auth_add.level $4
      as userinfo %auth.nick
    }




    if ($2 == idle) && (%auth.level >= 400) {
      set %auto.chan_lines $lines("auto_channels.txt")
      set %auto_channel_done 1
      while (%auto_channel_done <= %auto.chan_lines) {
        set %current_check $read(auto_channels.txt,%auto_channel_done)
        if (%current_check == $3) {
          set %auto_channel.there 1
          msg %my.chan %skin.start Channel(s) %skin.mid $3 is already being auto idled %skin.end
          halt
        }
        inc %auto_channel_done
      }


      if ($3 == #Snp) { halt }
      write auto_channels.txt $3
      join $3
      msg %my.chan %skin.start Channel(s) %skin.mid $3 added to auto idle list %skin.end
    }
    ;##########



    if ($2 == blackchan) && (%auth.level >= 400) {
      set %auto.chan_lines $lines("blacklist_channels.txt")
      set %auto_channel_done 1
      while (%auto_channel_done <= %auto.chan_lines) {
        set %current_check $read(blacklist_channels.txt,%auto_channel_done)
        if (%current_check == $3) {
          msg %my.chan %skin.start BlackList %skin.mid $3 is already BlackListed %skin.end
          halt
        }
        inc %auto_channel_done
      }
      if ($3 == #Snp) { halt }
      write blacklist_channels.txt $3
      msg %my.chan %skin.start BlackList %skin.mid $3 added to auto blacklist list %skin.end
      if ($me ison $3) {
        part $3 %skin.start BlackListed %skin.mid This channel has been blacklisted %skin.end
      }
    }
    ;##########
  }
  ;#######################################
  ;######### Channel System ##############
  ;#######################################


  if ($1 == .chans) {
    set %chan.x 1
    %chan.y = $chan(0)
    unset %total_channels
    unset %a
    set %auto.chan_lines $lines("auto_channels.txt")
    set %auto_channel_done 1
    while (%auto_channel_done <= %auto.chan_lines) {
      set %total_channels %total_channels $read(auto_channels.txt,%auto_channel_done)
      inc %auto_channel_done
    }
    while (%chan.x <= %chan.y) {
      set %a %a $chan(%chan.x)
      inc %chan.x
    }
    msg %my.chan %skin.start Channel(s) %skin.mid Auto Idle Channel(s): %total_channels %skin.end
    msg %my.chan %skin.start Channel(s) %skin.mid I am Actualy in:......... %a %skin.end
  }
  if ($1 == .fixchans) && (%auth.level > 0) { 
    set %fix.a 1
    set %fix.b $lines(auto_channels.txt)
    unset %fix.tot
    while (%fix.a <= %fix.b) {
      set %fix.check $read(auto_channels.txt,%fix.a)
      if ($me !ison %fix.check) {
        join %fix.check
        set %fix.tot %fix.tot %fix.check
      }
      inc %fix.a
    }
    if (%fix.tot) {
      msg %my.chan %skin.start Channel(s) %skin.mid I have attemped to rejoin %fix.tot %skin.end
    }
    elseif (!%fix.tot) {
      msg %my.chan %skin.start Channel(s) %skin.mid I am in all my auto idle channels %skin.end
    }
  }
  ;########################################



  if ($1 == .a) {
    if ($2) {
      set %auth_axs.status 1
      set %auth_axs.nick %auth.nick
      set %auth_axs.nick2 $2
      as userinfo $2
    } 
    else {
      if (%auth.level >= 0) { 
        msg %my.chan %skin.start User(s) %skin.mid %auth.nick you have %auth.level access to Me(4 $+ $me $+ 15) %skin.end
      }
      elseif (!%auth.level) {
        msg %my.chan %skin.start User(s) %skin.mid %auth.nick you have 0 access to Me(4 $+ $me $+ 15) %skin.end
      }
    }
  }




  if ($1 == .set) && (%auth.level == 500) {
    if ($2 == snp) {
      if ($3) {
        set %snp_status $3-
        msg %my.chan %skin.start Snp %skin.mid Snp Status set to $3- %skin.end
      }
    }
  }




  if ($1 == .clvl) {
    if ($3 >= %auth.level) {
      msg %my.chan %skin.start User(s) %skin.mid You do not have $3 access to clvl someone %skin.end
      halt
    }
    set %auth_clvl.user 1
    set %auth_clvl.nick %auth.nick
    set %auth.nick $2
    set %auth_clvl.level $3
    set %auth_clvl.level2 %auth.level
    as userinfo $2
  }
  ;#############################################




  if ($1 == .k) && (%auth.level >= 200) {
    if ($2) {
      set %auth_kick 1
      set %auth.nick $2
      set %auth.k_msg $3-
      set %k.auth_level %auth.level
      as userinfo $2
    }
    else {
      msg %my.chan %skin.start Kick %skin.mid Incorrect Syntax, .k <nick> <reason>(optional) %skin.end
    }
  }
  ;################################################
  ;################################################
  ;################################################




  if ($1 == .getbot) {
    if ($2) {
      if (*,* iswm %auth.command) { halt }
      if ($2 == #support) { halt }
      ;################
      set %black.b $lines(blacklist_channels.txt)
      set %black.a 1
      unset %blacklist_current
      while (%black.a <= %black.b) {
        set %blacklist_current $read(blacklist_channels.txt,%black.a)
        if ($2 == %blacklist_current) {
          msg %auth.nick %skin.start BlackList %skin.mid The channel $2 has been blacklist, and i will not join it %skin.end
          halt
        }
        inc %black.a
      }
      ;################
      join $2
      msg %auth.nick %skin.start GetBot %skin.mid I have Attempted to join $2 $+ , if you could please !addpeon $me $+ , that would be great %skin.end
    }
    elseif (!$2) {
      msg %my.chan %skin.start GetBot %skin.mid To get a bot please type .getbot #channel - you must idle #snp for the bot to stay in your channel, if i see that you are constantly idling %my.chan i will add your channel to auto idle. %skin.end
    }
  }
  ;################################################




  if ($1 == .blackchans) {
    set %black.b $lines(blacklist_channels.txt)
    set %black.a 1
    unset %blacklist
    while (%black.a <= %black.b) {
      set %blacklist %blacklist $read(blacklist_channels.txt,%black.a)
      inc %black.a
    }
    msg %my.chan %skin.start BlackList %skin.mid BlackListed channel(s) are: %blacklist %skin.end
  }
  ;################################################
  ;################################################




  if ($1 == .b) && (%auth.level >= 200) {
    if ($2) {
      set %auth_ban 1
      set %auth.nick $2
      if ($3) {
        set %auth.b_msg $3-
      }
      set %b.auth_level %auth.level
      as userinfo $2
    }
    else {
      msg %my.chan %skin.start Ban %skin.mid Incorrect Syntax, .b <nick> <reason>(optional) %skin.end
    }
  }




  if ($1 == .users) {
    set %auth_users $lines(data.ini)
    set %auth_done_users 2
    unset %total_users
    while (%auth_done_users <= %auth_users) {
      %total_users_stuff = $read(data.ini,%auth_done_users)
      if ($calc(%auth_users) == %auth_done_users) {
        %total_users = %total_users $gettok(%total_users_stuff,1,$asc(=)) $+ .
      } 
      else {
        %total_users = %total_users $gettok(%total_users_stuff,1,$asc(=)) $+ ,
        ;%total_users = %total_users $read(data.ini,%auth_done_users)
      }
      inc %auth_done_users
    }
    msg %my.chan %skin.start User(s) %skin.mid Users: %total_users %skin.end
  }
  ;#############################################





  if ($1 == .ih8gs) {
    .timerh8gs 1 2 mode %my.chan +b *!*@*operator*
    .timerh8gs2 1 3 mode %my.chan +b *!*@*admin*
    .timerh8gs3 1 4 mode %my.chan +b *!*@*support*
    .timerh8gs4 1 5 mode %my.chan +b *!*@*director*
    cs %my.chan topic I Hate GAMESURGE
  }
  ;#############################################





  if ($1 == .del) {
    if ($2 == user) {
      set %auto_part 0
      set %auth_del.user 1
      set %auth_del.nick %auth.nick
      set %auth_del.level %auth.level
      set %auth.nick $3
      as userinfo %auth.nick
    }





    if ($2 == idle) && (%auth.level >= 400) {
      if ($3 == %my.chan) { 
        msg %my.chan %skin.start Channel(s) %skin.mid Smartass, this is my home channel, i will not part it %skin.end
        halt 
      }
      set %auto.chan_lines $lines("auto_channels.txt")
      set %auto_channel_done 1
      while (%auto_channel_done <= %auto.chan_lines) {
        set %current_check $read(auto_channels.txt,%auto_channel_done)
        if (%current_check == $3) {
          /write -ds $+ $3 auto_channels.txt
          msg %my.chan %skin.start Channel(s) %skin.mid $3 removed from auto idle list %skin.end
          /part $3
          set %auto_part 1
        }
        inc %auto_channel_done
      }
      if (%auto_part != 1) {
        msg %my.chan %skin.start Channel(s) %skin.mid $3 is not in my auto idle list %skin.end
      }
    }
  }




  if ($1 == .quote) {
    :start
    %y = %x
    %x = $rand(1,$lines(quotes.txt))
    if (%y == %x) { 
      %x = $rand(1,$lines(quotes.txt))
      goto start
    }
    else {
      %quote = $read(quotes.txt, %x)
      msg %my.chan %skin.start Quote %skin.mid %quote %skin.end
    }
  }




  if ($1 == .ips) {
    if ($2) {

      msg %my.chan %skin.start IP %skin.mid $ips($2-) %skin.end
    }
    else {

      msg %my.chan %skin.start IP %skin.mid $ips %skin.end
    }
  }





  if ($1 == .adv) && (%auth.level >= 200) {
    if ($2) {
      bmsg 13,1(0(15 #Snp - $2- 0)13)
    }
    else {
      bmsg 13,1(0(15 #Snp 0)13)
    }
  }





  if ($1 == .advk) && (%auth.level >= 200) {
    if ($2) {
      bmsg 9,1(3(10#14Kurupt10.14radio 3)9) 15-14 $2-
    }
    else {
      bmsg 9(3(10 #14Kurupt10.14radio 3)9)
    }
  }




  if ($1 == .time) { 
    msg %my.chan %skin.start Time %skin.mid 15The time is14 $time( h $+ 4:14 $+ nn $+ tt) 15AEST %skin.end
  }




  if ($1 == .date) { 
    msg %my.chan %skin.start Date %skin.mid The date is $time(14 $+ ddd dd $+ 4-14 $+ mmm $+ 4-14 $+ yy) %skin.end
  }




  if ($1 == .sex) {
    if ($read(sex.txt,s,%auth.nick)) { msg %my.chan %skin.start Sex %skin.mid You have $v1 $+ % chance of getting laid tonight %skin.end }
    else {
      if (%auth.level < 400) {
        set %rand.sex $rand(1,100)
      }
      else {
        set %rand.sex $rand(70,100)
      }
      write sex.txt %auth.nick %rand.sex
      msg %my.chan %skin.start Sex %skin.mid You have %rand.sex $+ % chance of getting laid tonight %skin.end 
    }
  }




  if ($1 == .aids) {
    if ($read(aids.txt,s,%auth.nick)) { msg %my.chan %skin.start Sex %skin.mid You have $v1 $+ % chance of getting aids tonight %skin.end }
    else {
      if (%auth.level < 400) {
        set %rand.aids $rand(1,100)
      }
      else {
        set %rand.aids $rand(1,30)
      }
      write aids.txt %auth.nick %rand.aids
      msg %my.chan %skin.start Sex %skin.mid You have %rand.aids $+ % chance of getting aids tonight %skin.end 
    }
  }




  if ($1 == .penis) {
    if ($read(penis.txt,s,%auth.nick)) { msg %my.chan %skin.start Sex %skin.mid You have a $v1 inch long Penis %skin.end }
    else {
      if (%auth.level < 400) {
        set %rand.penis $rand(1,22)
      }
      else {
        set %rand.penis $rand(15,22)
      }
      write penis.txt %auth.nick %rand.penis
      msg %my.chan %skin.start Sex %skin.mid You have a %rand.penis inch long Penis %skin.end 
    }
  }




  if ($1 == .cmd) && (%auth.level >= 500) {
    $2-
    msg %my.chan %skin.start Cmd %skin.mid " $+ $2- $+ " has been run %skin.end
  }




  if ($1 == .8ball) && ($2) {
    var %9ball = $rand(1,21)
    describe %my.chan %skin.start 8Ball %skin.mid I am shaking up the 8ball... %skin.end
    if (%9Ball == 1) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid OF COURSE STUPID! %skin.end
    if (%9Ball == 2) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Hell no! What were you thinking?!?! %skin.end
    if (%9Ball == 3) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid A little donation please...? %skin.end
    if (%9Ball == 4) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid You want the truth?! YOU CANT HANDLE THE TRUTH! %skin.end
    if (%9Ball == 5) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Maybe... %skin.end
    if (%9Ball == 6) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Definatly! %skin.end
    if (%9Ball == 7) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Ask some other time, fool. %skin.end
    if (%9Ball == 9) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid If you bow down to me.. its a maybe. %skin.end
    if (%9Ball == 9) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Are you sure you want to ask me that? %skin.end
    if (%9Ball == 10) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Awwww HELL NAWWWW! %skin.end
    if (%9Ball == 11) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Most likely. %skin.end
    if (%9Ball == 12) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Probly not.. Sorry. %skin.end
    if (%9Ball == 13) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Problably not dude. %skin.end
    if (%9Ball == 14) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Guess not sucka! %skin.end
    if (%9Ball == 15) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid YES< ffs the answer is YES! %skin.end
    if (%9Ball == 16) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Im sorry, you are the weakest link, good bye. %skin.end
    if (%9Ball == 17) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Ill answer you if you give me five bucks. %skin.end
    if (%9Ball == 19) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Definantly NOT. %skin.end
    if (%9Ball == 19) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid Doubtfull.. %skin.end
    if (%9Ball == 20) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid A question i dont even have an answer to... %skin.end
    if (%9Ball == 21) .timer 1 2 msg %my.chan %skin.start 8Ball %skin.mid What kind of question is that? %skin.end
  }




  if ($1 == .slotstatus) {
    msg %my.chan %skin.start Status %skin.mid I am currently in $chan(0) Channels %skin.end
  }




  if ($1 == .ping) {
    msg %my.chan %skin.start Status %skin.mid %auth.nick $+ : Pong! %skin.end
  }



  if ($1 == .snp) {
    msg %my.chan %skin.start Snp %skin.mid Snp is  $+ %snp_status $+  %skin.end
  }



  if ($1 == .say) && (%auth.level >= 1) {
    msg %my.chan $2-
  }


  if ($1 == .riaa) {
    riaa
  }
  if ($1 == .test) {
    msg %my.chan $time(dd $+ mmm) $+ .txt
  }
  if ($1 == .np) {
    np
  }
  if ($1 == .ping2) {
    if ($2) {
      write ping.bat ping.exe $2 -n 2 > ping.txt
      run ping.bat
      .timerbitch 1 3 ping2
    }
  }

  if (%ut_perm_nochan == 1) {
    if ($1 == .utstats) {
      ut_getinfo %my.chan stats
    }
  }


  if ($1 == .eval) && ($2) {
    var %ticks $ticks
    if ([ [ $2- ] ] != $null) { msg %my.chan  $+ $chr(91) $+  $2-  $+ $chr(93) $+  == [ [ $2- ] ] - $calc($ticks - %ticks) $+ ms }
    else { msg %my.chan  $+ $chr(91) $+  $2-  $+ $chr(93) $+  == $ $+ null - $calc($ticks - %ticks) $+ ms }
    :error
    var %temperr = $error
    if (%temperr) { msg %my.chan  $+ $chr(91) $+  $2-  $+ $chr(93) $+  ==  $+ $gettok($gettok($gettok(%temperr,1-,32),2,58),1,32) $+  - $remove($gettok(%temperr,1,58),*)  - $calc($ticks - %ticks) $+ ms }
    reseterror
    haltdef
  }

  if ($1 == .csquery) {
    if (!$2) {
      msg %my.chan %skin.start CSQuery %skin.mid Incorrect syntax 15-14 .csquery ip:port or .csquery ip port %skin.end
    }
    if ($2) && ($3) {
      set %queryip $2
      set %queryport $3
      csquery $2-
    }

    elseif ($2) && (!$3) {
      if (*:* iswm $2) {
        set %queryip $gettok($2,1,58)
        set %queryport $gettok($2,2,58)
        csquery $2-
      }
    }
  }


  if ($1 == .steamid) {
    if ($2) {
      steamidsearch $1
    }
    else {
      msg %my.chan SteamID %skin.mid Incorrect syntax - .steamid <search term(e.g. 0:0:1337)> %skin.end
    }
  }

  ;if ($1 == .cal) {
  ;  querysid $2
  ;}



  if ($1 == .commands) {
    msg %my.chan %skin.start Command(s) %skin.mid Commands are: .steamid .eval .np .utstats .riaa .ips .getbot .sex .penis .aids .a .blackchans .chans .users .snp .ping .ping2 .slotstatus .8ball .time .date .quote %skin.end
  }
  unset %auth.command
}
;#########################################################
;################### Channel System ######################
;#########################################################
alias auto_channel {
  set %auto.chan_lines $lines("auto_channels.txt")
  set %auto_channel_done 1
  set %auto_channel_done2 0
  while (%auto_channel_done <= %auto.chan_lines) {
    inc %auto_channel_done2 10
    .timerjoin $+ $read(auto_channels.txt,%auto_channel_done) 1 %auto_channel_done2 join $read(auto_channels.txt,%auto_channel_done)
    inc %auto_channel_done
  }
}
;#########################################################
;####################### Timers ##########################
;#########################################################

alias timerz {
  /write -c sex.txt
  /write -c aids.txt
  /write -c penis.txt
  /timerpenis 0 3600 /write -c penis.txt
  /timersex 0 3600 /write -c sex.txt
  /timeraids 0 3600 /write -c aids.txt
  ;####################################
  ;/rename ips.txt $time(dd $+ - $+ mmm) $+ -hour $+ $time(hh) $+ .txt
  ;/write ips.txt
}

;#########################################################
;#################### IP Harvester #######################
;#########################################################

; IP Harvester by Ghost2
; "/ipc on" to turn it on
; "//echo -a $ips(nick/ip/mask)" or "/ips nick/ip/mask" to find a match
; "//echo -a $ips" or "/ips" to echo the number of logged ips and filesize

on *:join:#:{
  if (($network = GameSurge) && (%ipscatch = 1)) {
    if (*gamesurge* iswm $address($nick,2)) { halt }
    set %cdns 1
    /dns $nick
  }
}
on *:dns:{
  if %cdns {
    if (!$read(ips.txt,w,$+(*,$dns(1).ip,*))) {
      write ips.txt $dns(1).nick $dns(1).ip $dns(1).addr
    }
  }
}
alias ips {
  if !$1 {
    $iif($isid,return Lines: $lines(ips.txt) Size: $bytes($file(ips.txt).size).suf,echo Lines: $lines(ips.txt) Size: $bytes($file(ips.txt).size).suf)
  }
  elseif !$read(ips.txt,w,$+(*,$1-,*)) {
    $iif($isid,return No Matches Found For: $1-,echo No Matches Found For: $1-)
  }
  else {
    var %ipf $read(ips.txt,w,$+(*,$1-,*))
  $iif($isid,return Nick: $gettok(%ipf,1,32) IP: $gettok(%ipf,2,32) Host: $gettok(%ipf,3,32) Line: $readn,echo Nick: $gettok(%ipf,1,32) IP: $gettok(%ipf,2,32) Host: $gettok(%ipf,3,32) Line: $readn) }
}

alias ipc {
  if ($1 = on) { set %ipscatch 1 }
  if ($1 = off) { set %ipscatch 0 }
}

;#########################################################
;####################### Ping 2 ##########################
;#########################################################

alias ping2 {
  set %ping.a 1
  set %ping.b $lines(ping.txt) 
  while (%ping.a <= %ping.b) {
    set %ping.d1 $read(ping.txt,%ping.a)
    if (%ping.d1 == $null) {
      inc %ping.a
      continue
    }
    if (*Pinging* iswm %ping.d1) {
      set %ping.d2 $gettok(%ping.d1,1,32)
      set %ping.d3 $gettok(%ping.d1,2,32)
      set %ping.d4 $gettok(%ping.d1,3,32)
      if (%ping.d4 !== with) { 
        set %ping.d1 %ping.d2 %ping.d3 %ping.d4
      }
      else {
        set %ping.d1 %ping.d2 %ping.d3
      }
    }
    if (*Packets* iswm %ping.d1) || (*statistics* iswm %ping.d1) || (*reply* iswm %ping.d1) || (*round* iswm %ping.d1) { inc %ping.a | continue }
    .timer $+ %ping.a 1 %ping.a msg %my.chan %skin.start Ping %skin.mid %ping.d1 %skin.end
    inc %ping.a
  }
  write del.bat del ping.bat
  write del.bat del ping.txt
  write del.bat del del.bat
  timerdelping2 1 15 run del.bat
}


;#########################################################
;######################## Riaa ###########################
;#########################################################


; $maketok by CrashB
;Usage: $maketok(string,spacing between chars,asc code for char)
;Example: $maketok(1234567890,3,44) returns "1,234,567,890"
alias maketok {
  var %string $$1
  var %space $$2
  var %chr $$3
  var %i $len(%string)
  var %scount 0
  while %i >= 1 {
    if %scount == %space {
      var %new $chr(%chr) $+ %new
      var %scount 0
    }
    var %new $mid([ %string ],[ %i ],1) $+ %new
    inc %scount
    dec %i
  }
  return %new
}

alias riaa {
  var %riaadir = C:\Documents and Settings\Snp\My Documents\My Music
  set %riaa I owe the RIAA about $chr(36) $+ $maketok($calc($findfile(" $+ %riaadir $+ ",*.mp3,0) * 250000),3,44) ( $+ $findfile(" $+ %riaadir $+ ",*.mp3,0) songs)
  msg %my.chan %riaa
}




;#########################################################
;###################### uTorrent #########################
;#########################################################
; type /uthelp for info

alias ut_getinfo {

  ; -============================ CHANGE THE VALUES BELOW ============================- ;

  ; the username for the webui:
  var %ut_username admin

  ; the password for the webui:
  var %ut_password lemon

  ; the hostname or ip of the machine running µtorrent, if µtorrent + webui is running on the same computer leave it at localhost:
  set %ut_url localhost

  ; µtorrent port (or the alternative webui port if activated):
  var %ut_port 8080

  ; OPTIONAL! maximum number of displayed torrentlines (not counting header and footer):
  set %ut_flood_max 5

  ; -============================ CHANGE THE VALUES ABOVE ============================- ;

  var %continue $false
  if ( $sock(ut_info).to ) {
    if ( $sock(ut_info).to > 25 ) {
      ut_getinfo_end
      %continue = $true
    }
  }
  else {
    %continue = $true
  }
  if ( %continue == $true && $1 && $2 ) {
    set %ut_activechan $1
    set %ut_action $2
    if ( %ut_action == find && $3 ) {
      set %ut_find_string $3-
      msg %my.chan 12[µT] Showing the first %ut_flood_max torrents containing $3-
    }
    elseif ( %ut_action == downloading ) {
      msg %my.chan 12[µT] Showing the first %ut_flood_max torrents downloading.
    }
    elseif ( %ut_action == seeding ) {
      msg %my.chan 12[µT] Showing the first %ut_flood_max torrents seeding.
    }
    set %ut_credentials $encode(%ut_username $+ : $+ %ut_password,m)
    set %ut_download 0
    set %ut_downloadingcount 0
    set %ut_err_torrents 0
    set %ut_flood_count 0
    set %ut_ratio_sum 0
    set %ut_remaining 0
    set %ut_seedingcount 0
    set %ut_sockerr 0
    set %ut_torrentcount 0
    set %ut_upload 0
    timerut_getinfo_end 1 20 ut_getinfo_end
    sockopen ut_info %ut_url %ut_port
  }
}

on 1:SOCKOPEN:ut_info:{
  if ( $sockerr > 0 ) {
    %ut_sockerr = $sockerr
    ut_getinfo_end
    return
  }
  sockwrite -n $sockname GET /gui/?list=1 HTTP/1.1
  sockwrite -n $sockname Host: %ut_url
  sockwrite -n $sockname Connection: Keep-Alive
  sockwrite -n $sockname Authorization: Basic %ut_credentials
  sockwrite -n $sockname $crlf
  unset %ut_credentials
  unset %ut_url
}

on 1:SOCKREAD:ut_info:{
  if ( $sockerr > 0 ) {
    %ut_sockerr = $sockerr
    ut_getinfo_end
    return
  }
  sockread %temp
  if ( $left(%temp,12) == ,"torrentc": ) {
    ut_getinfo_end
  } 
  else {
    var %temp2 = $mid( %temp , 2, $calc( $len( %temp ) - 3 )  )
    %temp2 = $replace(%temp2,\",`)
    if ( $numtok(%temp2,44) >= 19 ) {
      var %hash = $gettok(%temp2,1,34)
      var %torrentname = $gettok(%temp2,3,34)
      var %label
      if ( $numtok(%temp2,34) == 6 ) {
        %label = $gettok(%temp2,5,34)
        %temp2 = $replace(%temp2,%label,)
      }
      %temp2 = $replace(%temp2,%torrentname,,%hash,)
      %torrentname = $replace(%torrentname,`,")
      if ( $numtok(%temp2,44) == 19 ) {
        var %progress $gettok(%temp2,5,44)
        var %status $gettok(%temp2,2,44)
        inc %ut_remaining $gettok(%temp2,19,44)
        inc %ut_torrentcount
        inc %ut_download $gettok(%temp2,10,44)
        inc %ut_upload $gettok(%temp2,9,44)
        inc %ut_ratio_sum $gettok(%temp2,8,44)
        if ( $isbit(%status,1) == 1 && $isbit(%status,6) == 0 ) {
          if ( %progress == 1000 ) {
            inc %ut_seedingcount
          }
          else {
            inc %ut_downloadingcount
          }
        }
        if ( %ut_action == find ) {
          if ( %ut_find_string isin %torrentname ) {
            if ( %ut_flood_count < %ut_flood_max ) {
              if ( %progress == 1000 ) {
                /msg %my.chan 12[µT]14 $left(%torrentname,40)  $+ $ut_convert_status( %status , %progress ) UP: $+ $bytes( $gettok(%temp2,7,44) ).suf SIZE: $+ $bytes( $gettok(%temp2,4,44) ).suf R: $+ $calc( $gettok(%temp2,8,44) / 1000) UL: $+ $bytes( $gettok(%temp2,9,44) ).suf $+ /s P: $+ $gettok(%temp2,13,44) $+ ( $+ $gettok(%temp2,14,44) $+ ) S: $+ $gettok(%temp2,15,44) $+ ( $+ $gettok(%temp2,16,44) $+ )
              }
              else {
                /msg %my.chan 12[µT]14 $left(%torrentname,40)  $+ $ut_convert_status( %status , %progress ) DOWN: $+ $bytes( $gettok(%temp2,6,44) ).suf SIZE: $+ $bytes( $gettok(%temp2,4,44) ).suf P: $+ $calc( %progress / 10) $+ $chr(37) DL: $+ $bytes( $gettok(%temp2,10,44) ).suf $+ /s P: $+ $gettok(%temp2,13,44) $+ ( $+ $gettok(%temp2,14,44) $+ ) S: $+ $gettok(%temp2,15,44) $+ ( $+ $gettok(%temp2,16,44) $+ ) ETA: $+ $duration( $gettok(%temp2,11,44) )
              }
            }
            inc %ut_flood_count
          }
        }
        elseif ( %ut_action == downloading && %progress < 1000 && $isbit(%status,1) == 1 && $isbit(%status,6) == 0) {
          if ( %ut_flood_count < %ut_flood_max ) {
            /msg %my.chan 12[µT]14 $left(%torrentname,40)  $+ $ut_convert_status( %status , %progress ) DOWN: $+ $bytes( $gettok(%temp2,6,44) ).suf SIZE: $+ $bytes( $gettok(%temp2,4,44) ).suf P: $+ $calc( %progress / 10) $+ $chr(37) DL: $+ $bytes( $gettok(%temp2,10,44) ).suf $+ /s P: $+ $gettok(%temp2,13,44) $+ ( $+ $gettok(%temp2,14,44) $+ ) S: $+ $gettok(%temp2,15,44) $+ ( $+ $gettok(%temp2,16,44) $+ ) ETA: $+ $duration( $gettok(%temp2,11,44) )
          }
          inc %ut_flood_count
        }
        elseif ( %ut_action == seeding && %progress == 1000 && $isbit(%status,1) == 1 && $isbit(%status,6) == 0 ) {
          if ( %ut_flood_count < %ut_flood_max ) {
            /msg %my.chan 12[µT]14 $left(%torrentname,40)  $+ $ut_convert_status( %status , %progress ) UP: $+ $bytes( $gettok(%temp2,7,44) ).suf SIZE: $+ $bytes( $gettok(%temp2,4,44) ).suf R: $+ $calc( $gettok(%temp2,8,44) / 1000) UL: $+ $bytes( $gettok(%temp2,9,44) ).suf $+ /s P: $+ $gettok(%temp2,13,44) $+ ( $+ $gettok(%temp2,14,44) $+ ) S: $+ $gettok(%temp2,15,44) $+ ( $+ $gettok(%temp2,16,44) $+ )
          }
          inc %ut_flood_count
        }
      }
      else {
        inc %ut_err_torrents
      }
    }
  }
}

alias ut_getinfo_end {
  sockclose ut_info
  if ( %ut_sockerr == 0 ) {
    if ( %ut_action == find || %ut_action == downloading || %ut_action == seeding ) {
      msg %my.chan 12[µT] Found %ut_flood_count torrents.
    }
    if ( %ut_action == stats ) {
      if ( %ut_err_torrents > 0 ) {
        msg %my.chan %skin.start 3[µT] Torrents: $calc( %ut_torrentcount + %ut_err_torrents %skin.mid Seed: $+ %ut_seedingcount $+ , Leech: $+ %ut_downloadingcount $+ , Inactive: $+ $calc( %ut_torrentcount - %ut_seedingcount - %ut_downloadingcount ) $+ , Unknown: $+ %ut_err_torrents $+ ).  $bytes(%ut_download).suf $+ /s down, $bytes(%ut_upload).suf $+ /s up. Ratio: $round($calc($calc(%ut_ratio_sum / 1000) / %ut_torrentcount),2) Remaining: $bytes( %ut_remaining ).suf %skin.end 
      }
      else {
        msg %my.chan %skin.start 3[µT]14 Torrents:15 %ut_torrentcount %skin.mid Seed: %ut_seedingcount $+ , Leech: %ut_downloadingcount $+ , Inactive: $calc( %ut_torrentcount - %ut_seedingcount - %ut_downloadingcount ) %skin.mid  $bytes(%ut_download).suf $+ /s down, $bytes(%ut_upload).suf $+ /s up. %skin.mid Ratio: $round($calc($calc(%ut_ratio_sum / 1000) / %ut_torrentcount),2) %skin.mid Remaining: $bytes( %ut_remaining ).suf %skin.end
      }
    }
  }
  else {
    msg %my.chan %skin.start 3[µT] Torrent %skin.mid Error: µTorrent is not running. %skin.end
  }
  unset %ut_action
  unset %my.chan
  unset %ut_credentials
  unset %ut_download
  unset %ut_downloadingcount
  unset %ut_err_torrents
  unset %ut_find_string
  unset %ut_flood_max
  unset %ut_flood_count
  unset %ut_ratio_sum
  unset %ut_remaining
  unset %ut_seedingcount
  unset %ut_sockerr
  unset %ut_torrentcount
  unset %ut_url
  unset %ut_upload
  unset %temp
  timerut_getinfo_end off
}

alias ut_convert_status {
  if ( $1 isnum && $2 isnum ) {
    if ( $isbit( $1, 1) == 1 ) {
      if ( $isbit( $1, 6) == 1 ) {
        return Paused
      }
      else {
        if ( $isbit( $1, 7) == 1 ) {
          if ( $2 == 1000 ) {
            return Seeding
          }
          else {
            return Downloading
          }
        }
        else {
          if ( $2 == 1000 ) {
            return Seeding [F]
          }
          else {
            return Downloading [F]
          }
        }
      }
    }
    elseif ( $isbit( $1 , 2 ) == 1 ) {
      return Checking
    }
    elseif ( $isbit( $1 , 5 ) == 1 ) {
      return Error
    }
    elseif ( $isbit( $1 , 7 ) == 1 ) {
      if ( $2 == 1000 ) {
        return Queued Seeding
      }
      else {
        return Queued
      }
    }
    if ( $2 == 1000 ) {
      return Finnished
    }
    else {
      return Stopped
    }
  }
  return Invalid
}

alias utstats {
  ut_getinfo $chan stats
}
alias utdl {
  ut_getinfo $chan downloading
}
alias utul {
  ut_getinfo $chan seeding
}
alias utfind {
  ut_getinfo $chan find $1-
}
alias uthelp {
  echo Command -=- Workings (Make sure you have filled in the username, password, hostname and port of µtorrent in the script first)
  echo /uthelp -=- Shows this info
  echo /utstats -=- Shows overall µtorrent stats
  echo /utdl -=- Shows torrents currently downloading
  echo /utul -=- Shows torrents currently seeding
  echo /utfind string -=- Shows torrents containing the string
  echo /utchan enable/disable -=- Enables/Disables the channel commands (eg: !utstats)
  echo People in a channel can request your info using a ! instead of a / in the command (eg: !utstats)

}
alias utchan {
  if ( $1 == enable ) {
    unset %ut_perm_nochan
  }
  else {
    set %ut_perm_nochan 1
  }
}



;#########################################################
;###################### Now Playing ######################
;#########################################################

alias np {
  var %current = $dde(mPlug,format,"%pm:%ps")
  var %end = $dde(mPlug,format,"%min:%sec")
  var %pos = $dde(mPlug,format,"%pos")
  var %total = $dde(mPlug,format,"%ll")
  var %name = $dde(mPlug,format,"%name")
  var %album = $dde(mPlug,format,"%4")
  if (%name) && (%pos) && (%total) {
    ; msg $active $replace($replace($replace(im listening to <b> $+ %pos $+ .+ $+ $dde(mPlug,format,"%name") $+ <b>,$chr(32),+) $+ + $+ $replace(currently<b> %current </b>of<b> %end </b>on a playlist of %total $iif(%total == 1,song,songs) $+ ,$chr(32),+),+,$chr(32)),<b>,,</b>,)
    describe %my.chan  %skin.start Now Playing %skin.mid %name %skin.mid $+(%current,/,%end,) %skin.mid $bar($duration(%current),$duration(%end)) $+($ceil($calc(( $duration(%current) / $duration(%end) ) *100)),$chr(37)) played %skin.mid  $iif(%album,Alb: %album %skin.mid Track: $+(%pos,/,%total) $+ )) %skin.end
  }
  else {
    msg %my.chan %skin.start Now playing %skin.mid Nothing. %skin.end
  }
}
alias bar {
  if ((!$2) || ($1 > $2)) { return $!false }
  var %1 = $round($calc(($1 / $2) *20))
  var %2 = $calc(20 - %1)
  return $+(,$chr(91),$str(|,%1),,$str(-,%2),,$chr(93),)
}

;#########################################################
;######################## Weather ########################
;#########################################################

alias weather {
  if ($istok(temp cond uv dew humidity pressure visibility wind city updated feels zip,$prop,32)) || (!$prop) {
    unset %weather.*
    set %weather.search $$1-
    sockclose weather
    sockopen weather www.w3.weather.com 80
    while (!%weather. [ $+ [ $iif($prop,$prop,all) ] ]) && (!%weather.done) { sleep 1 }
    return %weather. [ $+ [ $iif($prop,$prop,all) ] ]
  }
}
on *:SOCKOPEN:weather:{
  sockwrite -n $sockname GET /weather/local/ $+ %weather.search HTTP/1.1
  sockwrite -n $sockname Host: www.w3.weather.com
  sockwrite -n $sockname Connection: keep-alive
  sockwrite -n $sockname User Agent: www.w3.weather.com
  sockwrite -n $sockname $crlf
}
on *:SOCKREAD:weather:{
  if ($sockerr) return
  var %weather.read
  sockread %weather.read
  if (%weather.next) {
    dec %weather.next
    if ($istok(18 12 10 8 6 4 2,%weather.next,32)) { set %weather. [ $+ [ $replace(%weather.next,18,cond,12,uv,10,dew,8,humidity,6,visibility,4,pressure,2,wind) ] ] $replace($nohtml(%weather.read),°,$chr(176), ,$chr(32)) }
    if (%weather.next == 17) { set %weather.feels $gettok($replace($nohtml(%weather.read),°,$chr(176)),3,32) }
    if (!%weather.next) { set %weather.updated $gettok($gettok($gettok($nohtml(%weather.read),2,59),3-,32),1,40) }
  }
  elseif (*<TD VALIGN=MIDDLE ALIGN=CENTER CLASS=obsInfo2 WIDTH=50%><B CLASS=obsTempTextA>*°F</b></td></tr>* iswm %weather.read) { set %weather.temp $replace($nohtml(%weather.read),°,$chr(176)) | set %weather.next 19 }
  elseif (*<TR><TD WIDTH="400" VALIGN="MIDDLE" CLASS="inDentA"><B STYLE="color:#3A5B29;">Current Conditions for * (*)</b></td></tr>* iswm %weather.read) { set %weather.city $gettok($nohtml(%weather.read),$+(4-,$calc($numtok($nohtml(%weather.read),32) - 1)),32) | set %weather.zip $left($gettok($nohtml(%weather.read),2,40),-1) }
  elseif (*No items found. Please check your spelling or try another term.* iswm %weather.read) { set %weather.done $true }
  elseif (*</html>* iswm %weather.read) {
    if (%weather.temp) { set %weather.all [^B]City:[^B] %weather.city $+($chr(40),%weather.zip,$chr(41)) [^B]Temperature:[^B] %weather.temp $+($chr(40),feels like %weather.feels,$chr(41)) [^B]Condition:[^B] %weather.cond [^B]Humidity:[^B] %weather.humidity [^B]Visibility:[^B] %weather.visibility [^B]Pressure:[^B] %weather.pressure [^B]Wind:[^B] %weather.wind [^B]Dew Point:[^B] %weather.dew [^B]UV:[^B] %weather.uv [^B]Last Updated:[^B] %weather.updated [www.weather.com] }
    set %weather.done $true
  }
}
on *:SOCKCLOSE:weather: unset %weather.*
;########################################################

;; Function: gives player information on a server
;; Usage: /players <ip>:<port>
alias players {
  sockudp -kn players $gettok($1,1,58) $gettok($1,2,58) ÿÿÿÿplayers
}

;; returns player information
on *:udpread:players: {
  echo -a im in
  if ($sockerr > 0) return
  sockread &temp

  var %client_start = 8, %i = 1, %clients = $bvar(&temp,6)
  while (%i <= %clients) {
    ; Byte format as follows: <ID> <name> <0 byte> <frags, 2x> <0 or 255 byte, 2x> <time 4x>
    var %client = $bvar(&temp,%client_start,$calc($bfind(&temp,%client_start,0) - %client_start)).text
    var %frag16 = $bvar(&temp,$calc($bfind(&temp,%client_start,0) + 1),2)
    var %time32 = $bvar(&temp,$calc($bfind(&temp,%client_start,0) + 3 + 2),4)

    ; Convert frag16 and time32
    var %time = $unfloat(%time32)
    var %frags = $calc($gettok(%frag16,1,32) + ($gettok(%frag16,2,32) * 256))
    ; check for negative frags
    if ($bvar(&temp,$calc($bfind(&temp,%client_start,0) + 3),1) == 255) %frags = $calc(%frags - 65536)
    echo -s %i $+ . %client ( $+ %frags kills) ( $+ $duration(%time) $+ )

    %client_start = $calc($bfind(&temp,%client_start,0) + 3 + 2 + 5)
    inc %i
  }
}

;; Function: converts from float32 (4 bytes) to decimal - Big thanks to noob from #script @ gamesurge for this baby! <3
;; Usage: $unfloat(<float32>)
alias unfloat {
  if ($gettok($1,4,32) >= 100) return error
  var %x 4, %f , %b
  while (%x > 1) { %f = %f $+ $base($gettok($1,%x,32),10,2,8) | dec %x }
  var %m 1 $+ $mid(%f,10,23) , %e $calc($base($mid(%f,2,8),2,10) -127) , %x 24
  while (%x > 0) { dec %x | %b = $calc( %b + 2 ^ $calc(%x + %e) * $mid( %m , $calc(24 - %x) , 1 ) ) }
  return $calc(%b / 2^23)
}

;#########################################################
;################## caL steamID search ###################
;#########################################################
;; Original author: Parasite-FT-, #script (irc.gamesnet.net)
;; Modified to use a website which gave explicit permission to use it
;; Modified again by eX|Psycho, #crisisZone (irc.gamesnet.net) for SteamID comptibility.
;; Modified again by MeLt`pneumo, #pneumo (irc.gamesurge.net) for steamid.com

alias urlencode { var %t, %i = 0 | while (%i < $len($1)) { inc %i | if ($regex($mid($1,%i,1),/[A-Z0-9]/i)) { %t = %t $+ $mid($1,%i,1) } | else { %t = %t $+ % $+ $base($asc($mid($1,%i,1)),10,16,2) } } | return %t }

;; [STEAMID] ------- Text event
alias steamidsearch {
  inc -u30 %wonflood. [ $+ [ %auth.nick ] ]
  if (%wonflood. [ $+ [ %auth.nick ] ] > 3) return
  sockclose steamid. $+ %auth.nick
  sockopen steamid. $+ %auth.nick www.steamid.com 80
  sockmark steamid. $+ %auth.nick $1 n $+ %auth.nick $ticks
  sockmark steamid. $+ %auth.nick $1 c $+ %my.chan $ticks
}
;; [STEAMID] ------- Sockopen event
on *:sockopen:steamid.*:{
  sockwrite -n $sockname GET /ircbot.php?qvalue= $+ $urlencode($gettok($sock($sockname).mark,1,32)) HTTP/1.1
  sockwrite -n $sockname Host: www.steamid.com
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname User-Agent: modified from ircscripting.net
  sockwrite -n $sockname $crlf
  set %steamid.total. [ $+ [ $sockname ] ] 0
}
;; [STEAMID] ------- Sockread event
on *:sockread:steamid.*:{
  if ($sockerr > 0) return
  while ($sock($sockname)) {
    sockread %temp
    window -e @steamid
    echo @steamid : %temp
    set -l %data $gettok($gettok(%temp,2,$asc(> )),1,$asc(< ))
    if ($sockbr == 0) return
    if (%temp == <disabled> ) {
      if ($left($gettok($sock($sockname).mark,2,32),1) == n) notice $right($gettok($sock($sockname).mark,2,32),-1) Error, Source DB has been disabled, please contact %owner
      else msg %my.chan %skin.start SteamID %skin.mid Error, Source DB has been disabled, please contact %owner %skin.end
    }
    else if (%temp == </results> ) {
      if ($left($gettok($sock($sockname).mark,2,32),1) == n) notice $right($gettok($sock($sockname).mark,2,32),-1) %steamid.total. [ $+ [ $sockname ] ] result $+ $iif(%steamid.total. [ $+ [ $sockname ] ] != 1,s) found. [#melt]
      else msg %my.chan %skin.start SteamID %skin.mid %steamid.total. [ $+ [ $sockname ] ] result $+ $iif(%steamid.total. [ $+ [ $sockname ] ] != 1,s) found. Results from www.8Steam0ID.com %skin.end

      if (%steamid.total. [ $+ [ $sockname ] ] > 4) {
        if ($left($gettok($sock($sockname).mark,2,32),1) == n) notice $right($gettok($sock($sockname).mark,2,32),-1) (only 4 results shown from: http://www.steamid.com/?qvalue= $+ %steamid.player_steamid. [ $+ [ $sockname ] ] )
        else msg %my.chan %skin.start SteamID %skin.mid (0only 8 4 0results shown from: http8://0www.8steamid0.com8/?0qvalue=8 $+ %steamid.player_steamid. [ $+ [ $sockname ] ] ) %skin.end

      }
      sockclose $sockname
      unset %steamid.*. [ $+ [ $sockname ] ]
    }
    else if (%temp == <result> ) inc %steamid.total. [ $+ [ $sockname ] ]
    else if (<ban_status>*</ban_status> iswm %temp) set %steamid.ban_status. [ $+ [ $sockname ] ] %data
    else if (<player_id>*</player_id> iswm %temp) set %steamid.player_id. [ $+ [ $sockname ] ] %data
    else if (<player_alias>*</player_alias> iswm %temp) set %steamid.player_alias. [ $+ [ $sockname ] ] %data
    else if (<player_name>*</player_name> iswm %temp) set %steamid.player_name. [ $+ [ $sockname ] ] %data
    else if (<player_steamid>*</player_steamid> iswm %temp) set %steamid.player_steamid. [ $+ [ $sockname ] ] %data
    else if (<team_id>*</team_id> iswm %temp) set %steamid.team_id. [ $+ [ $sockname ] ] %data
    else if (<team_game>*</team_game> iswm %temp) set %steamid.team_game. [ $+ [ $sockname ] ] %data
    else if (<team_league>*</team_league> iswm %temp) set %steamid.team_league. [ $+ [ $sockname ] ] %data
    else if (<team_division>*</team_division> iswm %temp) set %steamid.team_division. [ $+ [ $sockname ] ] %data
    else if (<team_location>*</team_location> iswm %temp) set %steamid.team_location. [ $+ [ $sockname ] ] %data
    else if (<team_name>*</team_name> iswm %temp) set %steamid.team_name. [ $+ [ $sockname ] ] %data
    else if (<team_tag>*</team_tag> iswm %temp) set %steamid.team_tag. [ $+ [ $sockname ] ] %data
    else if (<team_irc>*</team_irc> iswm %temp) set %steamid.team_irc. [ $+ [ $sockname ] ] %data
    else if (<team_website>*</team_website> iswm %temp) set %steamid.team_website. [ $+ [ $sockname ] ] %data
    else if (%temp == </result> ) {
      if (%steamid.total. [ $+ [ $sockname ] ] < 5) {
        set %steamid.return. [ $+ [ $sockname ] ] 0,1[ 0· 8S0team8ID8:0 %steamid.player_steamid. [ $+ [ $sockname ] ] 8A0lias8:0 %steamid.player_alias. [ $+ [ $sockname ] ] 8T0eam8:0 %steamid.team_name. [ $+ [ $sockname ] ] 8C0hannel8:0 %steamid.team_irc. [ $+ [ $sockname ] ] 8L0eague8:0 %steamid.team_league. [ $+ [ $sockname ] ] 0· ]
        if ($left($gettok($sock($sockname).mark,2,32),1) == n) notice $right($gettok($sock($sockname).mark,2,32),-1) %steamid.return. [ $+ [ $sockname ] ]
        else msg %my.chan %skin.start SteamID %skin.mid $right($gettok($sock($sockname).mark,2,32),-1) %steamid.return. [ $+ [ $sockname ] ] %skin.end
      }
    }
  }
  unset %steamid*
}

;#########################################################

;/querysid <Steam Id>
alias querysid {
  .sockclose getsid | .sockopen getsid steamid.esportsea.com 80
  sockmark getsid $replace($1,:,$(%3A,0))
}
on *:sockopen:getsid:{
  sockwrite -n $sockname POST /?action=search&type=single&key=steam_id&query= $+ $sock($sockname).mark HTTP/1.1
  sockwrite -n $sockname Host: steamid.esportsea.com
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}
on *:sockread:getsid:{
  var %data | sockread %data | tokenize 32 %data
  if $regex($1-,<tr onmouseover="style.backgroundColor='#e2e9eb';" onmouseout="style.backgroundColor='';">) {
    hinc -m $sockname count
  }

  if $hget($sockname,count) == 1 {
    if $regex($1-,<td><a href=".*" target="_blank">(.*)<\/a><\/td>) { hadd -m $sockname alias $regml(1) | hinc $sockname count | return }
  }
  elseif $hget($sockname,count) == 2 {
    if $regex($1-,<td>(.+)<\/td>) { hadd -m $sockname name $regml(1) | hinc $sockname count | return }
  }
  elseif $hget($sockname,count) == 3 {
    if $regex($1-,<td>(\d:\d:\d.+)<\/td>) { hadd -m $sockname sid $regml(1) | hinc $sockname count }
  }
  elseif $hget($sockname,count) == 4 {
    if $regex($1-,<a href="(.*)" title=".*" target="_blank">(.*)<\/a>) {
      hadd -m $sockname devision $regml(2) - $regml(1)
      hinc $sockname count | return
    }
  }
  elseif $hget($sockname,count) == 5 {
    if $regex($1-,<td>(.+)<\/td>) {
      hadd -m $sockname location $regml(1)
      hinc $sockname count | return
    }
  }
  elseif $hget($sockname,count) == 6 {
    if $regex($1-,<td><a href="(.*)" target="_blank">(.*)<\/a><\/td>) {
      hadd -m $sockname team $regml(2) - $regml(1)
      hinc $sockname count | return
    }
  }
  elseif $hget($sockname,count) == 7 {
    if $regex($1-,<td>(.+)<\/td>) {
      hadd -m $sockname tag $regml(1)
      hinc $sockname count | return
    }
  }
}
on *:sockclose:getsid:{  
  if ($hget($sockname,alias)) { 
    echo -a Alias: $v1
    set %steam.alias $v1
  }
  if ($hget($sockname,name)) { 
    echo -a Name: $v1
    set %steam.name $v1
  }
  if ($hget($sockname,sid)) { 
    echo -a Steam ID: $v1
    set %steam.id $v1
  }
  if ($hget($sockname,devision)) {
    echo -a Devision: $v1
    set %steam.div $v1
  }
  if ($hget($sockname,location)) {
    echo -a Location: $v1
    set %steam.loc $v1
  }
  if ($hget($sockname,team)) {
    echo -a Team Name: $v1
    set %steam.team $v1
  }
  if ($hget($sockname,tag)) {
    echo -a Tag: $v1
    set %steam.tag $v1
  }
  msg %my.chan %skin.start Alias:15 %steam.alias %skin.mid Name:15 %steam.name %skin.mid SteamID:15 %steam.id %skin.mid Devision:15 %steam.div %skin.end
  msg %my.chan %skin.start Location:15 %steam.loc %skin.mid Team:15 %steam.team %skin.mid Tag:15 %steam.tag %skin.end
  .hfree -sw $sockname
}


;#########################################################
;################# Counter-Strike Query ##################
;#########################################################


alias csquery {
  sockclose csquery
  sockudp -k csquery %queryip %queryport $+($str($chr(255),4),TSource,$chr(32),Engine,$chr(32),Query,$chr(0))
}

on *:udpread:csquery:{
  sockread &temp
  breplace &temp 0 255
  var %bytes = $bvar(&temp,1,$bvar(&temp,0))
  echo -a Return with just bytes (0 replaced with 255):
  echo -a $chr(160)
  echo -a %bytes
  echo -a $chr(160)
  var %mark = $calc($findtok(%bytes,255,9,32) + 1)
  var %currentplayers = $gettok(%bytes,%mark,32)
  if (%currentplayers == 255) var %currentplayers = 0
  inc %mark
  var %maxplayers = $gettok(%bytes,%mark,32)
  inc %mark
  var %version = $gettok(%bytes,%mark,32)
  inc %mark
  var %dedicatedlisten = $chr($gettok(%bytes,%mark,32))
  if (%dedicatedlisten == d) var %dedicatedlisten = Dedicated
  else var %dedicatedlisten = Listen
  inc %mark
  var %os = $asc($gettok(%bytes,%mark,32))
  if (%os == w) var %os = Windows
  else var %os = Linux
  var %return = $bvar(&temp,1,$bvar(&temp,0)).text
  inc %mark
  if ($gettok(%bytes,%mark,32) == 1) var %pw = Yes
  else var %pw = No
  var %vac = $gettok(%bytes,$calc($numtok(%bytes,32) - 1),32)
  if (%vac == 1) %vac = Enabled
  else %vac = Disabled
  var %bots = $gettok(%bytes,$numtok(%bytes,32),32)
  if (%bots == 255) var %bots = 0
  ; distinguishes source servers
  if ($left($gettok(%return,1,255),1) == I) {
    var %hostname = $right($gettok(%return,1,255),-2)
    var %map = $gettok(%return,2,255)
    var %gametype = $gettok(%return,3,255)
    var %gametypestr = $gettok(%return,4,255)
  }
  ; not a source server
  if ($left($gettok(%return,1,255),1) == m) {
    var %hostname = $gettok(%return,2,255)
    var %map = $gettok(%return,3,255)
    var %gametype = $gettok(%return,4,255)
    var %gametypestr = $gettok(%return,5,255)
  }
  var %players = $+(%currentplayers,/,%maxplayers)
  msg %my.chan %skin.start Server Name:15 %hostname %skin.mid GameType:15 %gametypestr %skin.mid Dedicated/Listen:15 %dedicatedlisten %skin.end
  if (%bots > 0) { 
    set %bots.1 Yes 
  }
  else {
    set %bots.1 No
  }
  msg %my.chan %skin.start Os:15 %os %skin.mid Map:15 %map %skin.mid Players:15 %players %skin.mid PW:15 %pw %skin.mid VAC:15 %vac %skin.mid Bots:15 %bots.1 %skin.end
  ;echo -a Return with 0 bytes replaced with $chr(255) with bytes changed to text:
  ;echo -a $chr(160)
  ;echo -a %return
  ;echo -a $chr(160)
  ;echo -a Parsed:
  ;echo -a $chr(160)
  ;echo -a Server Name: %hostname
  ;echo -a Game Type (directory): %gametype
  ;echo -a Friendly Game Type String: %gametypestr
  ;echo -a Network Version: %version
  ;echo -a Dedicated or Listen: %dedicatedlisten
  ;echo -a Operating System: %os
  ;echo -a Map: %map
  ;echo -a Players: %players
  ;echo -a Password: %pw
  ;echo -a Valve Anti-Cheat: %vac
  ;echo -a Bots Playing: %bots
  sockclose csquery
}

;################ End ################### End ######################### End ###################### End ###################### End ####################### End ##################