All pastes #779581 Raw Edit

evoserver

public text v1 · immutable
·published 2007-11-18 11:57 UTC
rendered paste body
; ========
;  Events
; ========

on *:start:{
  ;socklisten ircserver 6667
  sockudp -k 4x4evodpsocket 1234
  hmake 4x4evo.chatroom 10
  hmake 4x4evo.bans 5
  hadd 4x4evo.chatroom topic Stupid 4x4evo sucks ass
  hadd 4x4evo.chatroom clients _ServerBot
  hadd 4x4evo.chatroom _ServerBot 00000000.0-0-0-0 NunYa.Biz.com chat1.4x4evolution.com _ServerBot H* :0 _ServerBot^0
}

on *:socklisten:ircserver:{
  set -u1 %ircserver.tmpsockname ircserver.socket. $+ $rand(1,99999)
  sockaccept %ircserver.tmpsockname
  echo -s *** Incoming IRC server request from $sock(%ircserver.tmpsockname).ip $+ 
  sockrename %ircserver.tmpsockname ircserver.sock. $+ $sock(%ircserver.tmpsockname).ip $+ : $+ $sock(%ircserver.tmpsockname).port
}

on *:udpread:4x4evodpsocket:{
  set %packet $1- 
  if ($sockerr > 0) { return }
  sockread &testudpsocket
  ;if ($bvar(&testudpsocket, 1, 4) == 255 255 255 255) { [ // $+ [ $eval($bvar(&testudpsocket, 5-).text) ] ] }
  ;if ($bvar(&testudpsocket, 1, 4) == 255 255 255 255) { $eval($bvar(&testudpsocket, 5-).text) }
  ;bset &tes2t 1 $make_string(\x23\x00\x00\x00\x $+ $base($bvar(&testudpsocket, 9), 10, 16) $+ \x $base($bvar(&testudpsocket, 10), 10, 16) $+ \x $+ $base($bvar(&testudpsocket, 11), 10, 16) $+ \x00\x $+ $lower($base($gettok($sock($sockname).saddr,1,46),10,16,2)) $+ \x $+ $lower($base($gettok($sock($sockname).saddr,2,46),10,16,2)) $+ \x $+ $lower($base($gettok($sock($sockname).saddr,3,46),10,16,2)) $+ \x $+ $lower($base($gettok($sock($sockname).saddr,4,46),10,16,2)) $+ \x $+ $lower($left($base($sock($sockname).sport,10,16,4),2)) $+ \x $+ $lower($right($base($sock($sockname).sport,10,16,4),2)) $+ \x00\x00\x00\x00\x00\x $+ $lower($base($numtok($hget(4x4evo.chatroom, clients),124),10,16,2)))
  bset &test 1 $hextoascii(23000000 $+ $lower($base($bvar(&testudpsocket, 9), 10, 16, 2)) $+ $lower($base($bvar(&testudpsocket, 10), 10, 16, 2)) $+ $lower($base($bvar(&testudpsocket, 11), 10, 16, 2)) $+ $lower($base($bvar(&testudpsocket, 12), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 1, 46), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 2, 46), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 3, 46), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 4, 46), 10, 16, 2)) $+ $lower($left($base($sock($sockname).sport, 10, 16, 4) ,2)) $+ $lower($right($base($sock($sockname).sport, 10, 16, 4), 2)) $+ 9999999999 $+ $lower($base($calc($numtok($hget(4x4evo.chatroom, clients), 124) - 1), 10, 16, 2)))
  sockudp testudpsock $sock($sockname).saddr $sock($sockname).sport &test
 ;//echo $bvar(&test2, 1-).text
  ;//echo $sock($sockname).saddr $sock($sockname).sport 6 1 $hextoascii(23000000 $+ $lower($base($bvar(&testudpsocket, 9), 10, 16, 2)) $+ $lower($base($bvar(&testudpsocket, 10), 10, 16, 2)) $+ $lower($base($bvar(&testudpsocket, 11), 10, 16, 2)) $+ $lower($base($bvar(&testudpsocket, 12), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 1, 46), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 2, 46), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 3, 46), 10, 16, 2)) $+ $lower($base($gettok($sock($sockname).saddr, 4, 46), 10, 16, 2)) $+ $lower($left($base($sock($sockname).sport, 10, 16, 4) ,2)) $+ $lower($right($base($sock($sockname).sport, 10, 16, 4), 2)) $+ 9999999999 $+ $lower($base($calc($numtok($hget(4x4evo.chatroom, clients), 124) - 1), 10, 16, 2)))
  unset %hextoascii.*
}

on *:sockread:ircserver.sock.*:{
  if ($sockerr > 0) { return }
  :readnext
  sockread [ % $+ [ $sockname $+ [ .sockin ] ] ]
  if ($left([ % $+ [ $sockname $+ [ .sockin ] ] ], 4) == OPER) { }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] != $null) { echo -s *** $gettok($sockname,3,46) <= [ % $+ [ $sockname $+ [ .sockin ] ] ] }
  if ([ % $+ [ $sockname $+ [ .sockin ] ] ] == USRIP) { sockwrite -n $sockname :chat1.4x4evolution.com 302  :unknown=+unknown@ $+ 24.15.251.14 }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ], 9) == CHALLENGE) { sockwrite -n $sockname :chat1.4x4evolution.com 302  :unknown=+unknown@ $+ $sock($sockname).ip }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],4) == PASS) {
    if ($len($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32)) !=6) { sockclose $sockname }
    if ($len($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32)) !=6) { sockclose $sockname }
  } 
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],4) == NICK) {
    if ($numtok([ % $+ [ $sockname $+ [ .sockin ] ] ], 32) != 2) { return }
    set [ % $+ [ $sockname $+ [ .sockin ] ] ] $remove([ % $+ [ $sockname $+ [ .sockin ] ] ], $chr(58))
    if ($sock(ircserver.sock. $+ $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32)).status == active) { sockwrite -n $sockname ERROR :That nick is already in use | cleanup | sockclose $sockname | return }
    if ($hget(4x4evo.chatroom, $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32)) != $null) { sockwrite -n $sockname ERROR :That nick is already in use | cleanup | sockclose $sockname | return }
    if ($hget(4x4evo.chatroom, $gettok($sockname, 3, 46)) != $null) {
      hadd 4x4evo.chatroom $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32) $hget(4x4evo.chatroom, $gettok($sockname, 3, 46))
      hdel 4x4evo.chatroom $gettok($sockname,3,46)
      if ($istok($hget(4x4evo.chatroom,clients),$gettok($sockname,3,46),124) == $true) { hadd 4x4evo.chatroom clients $reptok($hget(4x4evo.chatroom, clients), $gettok($sockname,3,46), $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32), 1, 124) }
      hadd 4x4evo.chatroom $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32) $reptok($hget(4x4evo.chatroom, $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32)), $gettok($sockname,3,46), $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32), 1, 32)
      unset %ircserver.sock. $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+ .sockin
    }

    sockrename $sockname ircserver.sock. $+ $remove($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32), $chr(58))
    unset %ircserver.sock. $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+ .sockin
    return
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],4) == USER) {
    if ($hget(4x4evo.chatroom, $gettok($sockname,3,46)) != $null) { sockwrite -n $sockname ERROR :You may not re-register | return }
    else if ((($gettok($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],5-,32),2,94) != 0) && ($len($gettok($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],5-,32),2,94)) < 6)) || (^^ isin [ % $+ [ $sockname $+ [ .sockin ] ] ]) || ($chr(94) !isin $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],5-,32))) {
      sockwrite -n $sockname ERROR :Closing Link: $sock($sockname).ip (Invalid Name)
      cleanup
      sockclose $sockname
      return
    }
    hadd 4x4evo.chatroom $gettok($sockname,3,46) $+ .temp $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2-,32)
    hadd 4x4evo.chatroom $gettok($sockname,3,46) $gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ .temp),1,32) 0 chat1.4x4evolution.com $gettok($sockname,3,46) H :0 $gettok($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ .temp),4-,32),1,58)
    hdel 4x4evo.chatroom $gettok($sockname,3,46) $+ .temp
    if ($readini(4x4evo1\bans.ini,n,bans,$gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),1,46)) != $null) {
      ;hdel -w 4x4evo.chatroom $gettok($sockname,3,46) $+ *
      sockwrite -n $sockname ERROR :Closing Link: $sock($sockname).ip (Your ID is permanently banned on this server)
      cleanup $gettok($sockname,3,46)
      sockclose $sockname
      return
    }
    elseif ($hget(4x4evo.bans,$gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),1,46)) == 1) {
      sockwrite -n $sockname ERROR :Closing Link: $sock($sockname).ip (Your ID is temporarily banned.  Try again in $round($calc($hget(4x4evo.bans,$gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),1,46)).unset / 60),0) minutes.)
      ;hdel -w 4x4evo.chatroom $gettok($sockname,3,46) $+ *
      cleanup $gettok($sockname,3,46)
      sockclose $sockname
      return
    }
    sockwrite -n $sockname NOTICE $gettok($sockname,3,46) :*** Your host is evoirc.no-ip.org, running version 2.0
    sockwrite -n $sockname :evoirc.homeip.net 375 $gettok($sockname,3,46) :fuck off
    if ($exists(4x4evo1\motd.txt)) {
      hadd 4x4evo.chatroom $gettok($sockname,3,46) $+ motd 1
      while ($hget(4x4evo.chatroom, $gettok($sockname,3,46) $+ motd) <= $lines(4x4evo1\motd.txt)) {
        sockwrite -n $sockname :chat1.4x4evolution.com 372 $gettok($sockname,3,46) :- $read(4x4evo1\motd.txt, $hget(4x4evo.chatroom, $gettok($sockname,3,46) $+ motd))
        hinc 4x4evo.chatroom $gettok($sockname,3,46) $+ motd 1
      }
      hdel 4x4evo.chatroom $gettok($sockname,3,46) $+ motd
    }
    else { sockwrite -n $sockname :chat1.4x4evolution.com 372 $gettok($sockname, 3, 46) :- <br><head>MOTD file was not found.<normal><br><br> }
    sockwrite -n $sockname :chat1.4x4evolution.com 376 $gettok($sockname,3,46) :End of /MOTD command.
    sockwrite -n $sockname : $+ $gettok($sockname,3,46) MODE $gettok($sockname, 3, 46) :+wsi
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],4) == PING) { sockwrite -n $sockname PONG $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32) }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] == LIST) {
    sockwrite -n $sockname :chat1.4x4evolution.com 321 $gettok($sockname,3,46) Channel :Users  Name
    sockwrite -n $sockname :chat1.4x4evolution.com 322 $gettok($sockname,3,46) #ChatÿRoom $numtok($hget(4x4evo.chatroom, clients),124) : $+ $hget(4x4evo.chatroom, topic)
    sockwrite -n $sockname :chat1.4x4evolution.com 323 $gettok($sockname,3,46) :End of /LIST
  }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] == JOIN #ChatÿRoom) {
    if ($findtok($hget(4x4evo.chatroom,clients),$gettok($sockname,3,46),1,124) == $null) { hadd 4x4evo.chatroom clients $hget(4x4evo.chatroom,clients) $+ %pipe $+ $gettok($sockname,3,46) }
    sendtoroom : $+ $gettok($sockname,3,46) JOIN #ChatÿRoom
    sockwrite -n $sockname :chat1.4x4evolution.com 332 $gettok($sockname,3,46) #ChatÿRoom : $+ $hget(4x4evo.chatroom, topic)
  }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] == TOPIC #ChatÿRoom) {
    sockwrite -n $sockname :chat1.4x4evolution.com 332 $gettok($sockname,3,46) #ChatÿRoom : $+ $hget(4x4evo.chatroom, topic)    
  }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] == PART #ChatÿRoom) {
    sendtoroom : $+ $gettok($sockname,3,46) PART #ChatÿRoom
    hadd 4x4evo.chatroom clients $deltok($hget(4x4evo.chatroom,clients),$findtok($hget(4x4evo.chatroom,clients),$gettok($sockname,3,46),1,124),124)
    if ($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H@) {
      tokenize 32 $hget(4x4evo.chatroom,$gettok($sockname,3,46))
      hadd 4x4evo.chatroom $gettok($sockname,3,46) $1 $2 $3 $4 H $6-
    }
  }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] == WHO #ChatÿRoom) {
    hadd 4x4evo.chatroom roomwhois.count 1
    while ($hget(4x4evo.chatroom,roomwhois.count) <= $numtok($hget(4x4evo.chatroom, clients),124)) {
      sockwrite -n $sockname :chat1.4x4evolution.com 352 $gettok($sockname,3,46) #ChatÿRoom $hget(4x4evo.chatroom,$gettok($hget(4x4evo.chatroom, clients),$hget(4x4evo.chatroom,roomwhois.count),124))
      hinc 4x4evo.chatroom roomwhois.count 1
    }
    hdel 4x4evo.chatroom roomwhois.count
    sockwrite -n $sockname :chat1.4x4evolution.com 315 $gettok($sockname,3,46) #ChatÿRoom :End of /WHO list.
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],4) == RCHG) {
    if ((($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,94) != 0) && ($len($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,94)) != 6)) || (^^ isin [ % $+ [ $sockname $+ [ .sockin ] ] ])) { return }
    else {
      tokenize 32 $hget(4x4evo.chatroom,$gettok($sockname,3,46))
      hadd 4x4evo.chatroom $gettok($sockname,3,46) $1 $2 $3 $4 $5 $6 $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2-,58)
      sendtoroom : $+ $gettok($sockname,3,46) RCHG $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2-,32)
    }
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],18) == PRIVMSG #ChatÿRoom) {
    sendmessagetoroom $gettok($sockname,3,46) : $+ $gettok($sockname,3,46) [ % $+ [ $sockname $+ [ .sockin ] ] ]
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],18) == PRIVMSG _ServerBot) {
    if ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],3,32) == :!time) { sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname,3,46) :It's currently $asctime(hh:nn:ss) (EST) on $asctime(mm-dd-yyyy). }
    if ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],3,32) == :!userlist) {
      if (($gettok($hget(4x4evo.chatroom,$gettok($sockname, 3, 46)), 5, 32) == H*) || ($gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46)), 5, 32) == H@)) {
        hadd 4x4evo.chatroom $gettok($sockname, 3, 46) $+ userlistcount 1
        sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname, 3, 46) :----------
        while ($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ userlistcount) <= $hget(4x4evo.chatroom, 0).item) {
          hadd 4x4evo.chatroom $gettok($sockname,3,46) $+ usertmp $hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ userlistcount)).item
          if ($sock(ircserver.sock. $+ $hget(4x4evo.chatroom, $gettok($sockname,3,46) $+ usertmp)) == $null) {
            hinc 4x4evo.chatroom $gettok($sockname, 3, 46) $+ userlistcount 1
            hdel 4x4evo.chatroom $gettok($sockname, 3, 46) $+ usertmp
            continue
          }
          sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname, 3, 46) : $+ $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 7-, 32) ( $+ $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ usertmp)), 4, 32) $+ )
          sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname, 3, 46) : $+ $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ usertmp)), 1, 32) $chr(124) $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 5, 32) $chr(124) $int($calc($sock(ircserver.sock. $+ $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 4, 32)).to / 60)) minutes
          sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname, 3, 46) :----------
          sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname, 3, 46) : $+ $padspace(8, $left($gettok($gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ usertmp)), 1, 32), 1, 46), 8)) $chr(124) $padspace(12, $left($gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ usertmp)), 4, 32), 12)) $chr(124) $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 5, 32) $chr(124) $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 7-, 32) $chr(124) $int($calc($sock(ircserver.sock. $+ $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 4, 32)).to / 60)) minutes
          sockwrite -n $sockname :_ServerBot!_ServerBot@NunYa.Biz.com PRIVMSG $gettok($sockname, 3, 46) :(¤NAME¤: $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 7-, 32) $+ ) (¤IDENT¤: $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ usertmp)), 1, 32) $+ ) (¤NICK¤: $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ usertmp)), 4, 32) $+ ) (¤STATUS¤: $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 5, 32) $+ ) (TIME: $int($calc($sock(ircserver.sock. $+ $gettok($hget(4x4evo.chatroom, $hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ usertmp)), 4, 32)).to / 60)) minutes $+ )

          hdel 4x4evo.chatroom $gettok($sockname, 3, 46) $+ usertmp
          hinc 4x4evo.chatroom $gettok($sockname, 3, 46) $+ userlistcount 1
        }
        hdel 4x4evo.chatroom $gettok($sockname, 3, 46) $+ userlistcount
      }
    }
    elseif ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 3, 32) == :!addserverop) {
      if (($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 4, 32) == $null) || ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 5, 32) == $null) || ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 6, 32) == $null) || ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 7, 32) == $null)) { sockwrite -n $sockname :_ServerBot PRIVMSG $gettok($sockname,3,46) :Syntax is <your account name> <your password> <new account name> <new password> | return }
      if ($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H*) {
        if ($readini(4x4evo/4x4evo.ini, admins, $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 4, 32)) == $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 5, 32)) {
          writeini 4x4evo1/mids.ini operators $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 6, 32) $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 7, 32)
          sockwrite -n $sockname :_ServerBot PRIVMSG $gettok($sockname,3,46) :Server OP account has been successfully added.
        }
      }
    }
    elseif ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 3, 32) == :!deleteserverop) {
      if (($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 4, 32) == $null) || ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 5, 32) == $null) || ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 6, 32) == $null)) { sockwrite -n $sockname :_ServerBot PRIVMSG $gettok($sockname,3,46) :Syntax is <your account name> <your password> <new account name> | return }
      if ($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H*) {
        if ($readini(4x4evo/4x4evo.ini, admins, $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 4, 32)) == $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 5, 32)) {
          if ($readini(4x4evo1\mids.ini, operators, $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 6, 32)) != $null) {
            remini 4x4evo1\mids.ini operators $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 6, 32)
            sockwrite -n $sockname :_ServerBot PRIVMSG $gettok($sockname,3,46) :Server OP account has been successfully deleted.
          }
          else { sockwrite -n $sockname :_ServerBot PRIVMSG $gettok($sockname,3,46) :The specified server OP account was not found. }
        }
      }
    }
    return
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ], 7) == PRIVMSG) {
    sockwrite -n ircserver.sock. $+ $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32) : $+ $gettok($sockname,3,46) $+ ! $+ $gettok($sockname,3,46) $+ @NunYa.Biz.com PRIVMSG $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32) $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],3-,32)
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ], 4) == OPER) {
    if ($gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 2, 32) == $null || $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 3, 32) == $null) { sockwrite -n $sockname 491 $gettok($sockname,3,46) : $+ %message.operloginfail | return }
    elseif ($readini(4x4evo1\mids.ini,operators,$gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32)) == $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],3,32)) {
      tokenize 32 $hget(4x4evo.chatroom,$gettok($sockname,3,46))
      hadd 4x4evo.chatroom $gettok($sockname,3,46) $1 $2 $3 $4 H* $6-
      sockwrite -n $sockname :chat1.4x4evolution MODE $gettok($sockname,3,46) :+aO
      sockwrite -n $sockname :chat1.4x4evolution 381 $gettok($sockname,3,46) : $+ You are now an IRC operator
      write 4x4evo1\goodlogins.txt Successful login.  Account " $+ $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32) $+ ".
      echo -s *** $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32) logged in successfully.
    }
    else {
      write 4x4evo1\badlogins.txt $+ $hget(4x4evo.chatroom,$gettok($sockname,3,46)) $+ | sockwrite -n $sockname 491 $gettok($sockname,3,46) : $+ %message.operloginfail | hdel 4x4evo.chatroom $gettok($sockname,3,46) | sendtoroom 491 : $+ NICK ID $gettok($sockname,3,46) Failed to OPER correctly, disconnecting. | sendtoroom : $+ $gettok($sockname,3,46) QUIT Local-Kill/By-Server | sockclose $sockname | cleanup 
    echo -s *** $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],2,32) failed to login. }
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ], 15) == KICK #ChatÿRoom) {
    hadd 4x4evo.chatroom $gettok($sockname, 3, 46) $+ kick $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],3,32)
    if (($gettok($hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname, 3, 46) $+ kick)), 5, 32) != H*) && (($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H*) || ($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H@))) {
      sendtoroom : $+ $gettok($sockname, 3, 46) $+ ! $+ $gettok($sockname, 3, 46) $+ @NunYa.Biz.com KICK #ChatÿRoom $hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ kick)
      if ($findtok($hget(4x4evo.chatroom,clients),$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ kick), 1, 124) != 0) { hadd 4x4evo.chatroom clients $deltok($hget(4x4evo.chatroom,clients),$findtok($hget(4x4evo.chatroom,clients),$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ kick),1,124),124) }
      if ($gettok($hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ kick)),5,32) == H@) {
        tokenize 32 $hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ kick))
        hadd 4x4evo.chatroom $hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ kick) $1 $2 $3 $4 H $6-
      }
    }
    hdel 4x4evo.chatroom $gettok($sockname,3,46) $+ kick
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],18) == MODE #ChatÿRoom +o) {
    hadd 4x4evo.chatroom $gettok($sockname,3,46) $+ op $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],4,32)
    if ((($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H*) || ($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H@)) && ($gettok($hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ op)),5,32) != H*)) {
      sendtoroom : $+ $gettok($sockname,3,46) MODE #ChatÿRoom +o $hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ op)
      tokenize 32 $hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ op))
      hadd 4x4evo.chatroom $hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ op) $1 $2 $3 $4 H@ $6-
    }
    hdel 4x4evo.chatroom $gettok($sockname,3,46) $+ op
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],18) == MODE #ChatÿRoom -o) {
    hadd 4x4evo.chatroom $gettok($sockname,3,46) $+ deop $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ],4,32)
    if ((($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H*) || ($gettok($hget(4x4evo.chatroom,$gettok($sockname,3,46)),5,32) == H@)) && ($gettok($hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ deop)),5,32) != H*)) {
      sendtoroom : $+ $gettok($sockname,3,46) MODE #ChatÿRoom -o $hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ deop)
      tokenize 32 $hget(4x4evo.chatroom,$hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ deop))
      hadd 4x4evo.chatroom $hget(4x4evo.chatroom,$gettok($sockname,3,46) $+ deop) $1 $2 $3 $4 H $6-
    }
    hdel 4x4evo.chatroom $gettok($sockname,3,46) $+ deop
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ], 14) == BAN #ChatÿRoom) {
    hadd 4x4evo.chatroom $gettok($sockname,3,46) $+ ban $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 3, 32) $+ . $+ $gettok([ % $+ [ $sockname $+ [ .sockin ] ] ], 4, 32)
    if (($gettok($hget(4x4evo.chatroom, $gettok($hget(4x4evo.chatroom, $gettok($gettok($sockname, 3, 46) $+ ban, 1, 46)), 1, 46)), 5, 32) != H*) && (($gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46)), 5, 32) == H*) || ($gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46)), 5, 32) == H@))) {
      sendtoroom : $+ $gettok($sockname, 3, 46) BAN #ChatÿRoom $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46) $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 2, 46)
      if (($gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46)), 5, 32) == H*) && ($gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 2, 46) == 4620)) {
        writeini 4x4evo1\bans.ini bans $gettok($hget(4x4evo.chatroom, $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46)), 1, 46) By: $hget(4x4evo.chatroom, $gettok($sockname, 3, 46))
        sendtoroom :_ServerBot PRIVMSG #ChatÿRoom : $+ $gettok($gettok($hget(4x4evo.chatroom, $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46)), 7-, 32), 1, 94) $+  has been server banned.
        .timerdisconnectbanned $+ $rand(1,9999999) 1 1 disconnectbanned $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46) $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3,46) $+ ban), 2, 46)
        ;disconnectbanned $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46) $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 2, 46)
      }
      else {
        hadd -u $+ $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 2, 46) 4x4evo.bans $gettok($hget(4x4evo.chatroom, $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46)), 1, 46) 1
        .timerdisconnectbanned $+ $rand(1,9999999) 1 1 disconnectbanned $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 1, 46) $gettok($hget(4x4evo.chatroom, $gettok($sockname,3,46) $+ ban), 2, 46)
        ;disconnectbanned $gettok($hget(4x4evo.chatroom, $gettok($sockname,3,46) $+ ban),1,46) $gettok($hget(4x4evo.chatroom, $gettok($sockname, 3, 46) $+ ban), 2, 46)
      }
    }
    hdel 4x4evo.chatroom $gettok($sockname,3,46) $+ ban
  }
  elseif ($left([ % $+ [ $sockname $+ [ .sockin ] ] ],4) == QUIT) {
    if ($findtok($hget(4x4evo.chatroom, clients), $gettok($sockname, 3, 46), 1, 124) != 0) { hadd 4x4evo.chatroom clients $deltok($hget(4x4evo.chatroom, clients), $findtok($hget(4x4evo.chatroom, clients), $gettok($sockname,3,46), 1, 124), 124) }
    cleanup
    sockclose $sockname
    return
  }
  elseif ([ % $+ [ $sockname $+ [ .sockin ] ] ] == !clientquery!) {
    hadd 4x4evo.chatroom $sockname $+ .querycount 2
    while ($hget(4x4evo.chatroom,$sockname $+ .querycount) <= $numtok($hget(4x4evo.chatroom, clients),124)) {
      sockwrite -n $sockname ! $gettok($hget(4x4evo.chatroom, clients),$hget(4x4evo.chatroom,$sockname $+ .querycount),124) $gettok($hget(4x4evo.chatroom,$gettok($hget(4x4evo.chatroom, clients),$hget(4x4evo.chatroom,$sockname $+ .querycount),124)),1,46) $gettok($hget(4x4evo.chatroom,$gettok($hget(4x4evo.chatroom, clients),$hget(4x4evo.chatroom,$sockname $+ .querycount),124)),7-,32)
      hinc 4x4evo.chatroom $sockname $+ .querycount 1
    }
    hdel 4x4evo.chatroom $sockname $+ .querycount
    cleanup
    sockclose $sockname
    return
  }
  if ($sockbr == 0) return
  goto readnext
}

on *:sockclose:ircserver.sock.*:{
  if ($istok($hget(4x4evo.chatroom,clients),$gettok($sockname,3,46),124) == $true) {
    sendtoroom : $+ $gettok($sockname,3,46) PART #ChatÿRoom
    hadd 4x4evo.chatroom clients $deltok($hget(4x4evo.chatroom,clients),$findtok($hget(4x4evo.chatroom,clients),$gettok($sockname,3,46),1,124),124)
  }
  unset % $+ $sockname $+ .*
  unset %ircserver.sock. $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+ .*
  if ($hget(4x4evo.chatroom, $gettok($sockname,3,46)) != $null) { hdel 4x4evo.chatroom $gettok($sockname,3,46) }
  hdel -w 4x4evo.chatroom $gettok($sockname,3,46) $+ *
}

; =========
;  Aliases
; =========

alias sendtoroom {
  hadd 4x4evo.chatroom sendtoroom.count 2

  while ($hget(4x4evo.chatroom, sendtoroom.count) <= $numtok($hget(4x4evo.chatroom, clients),124)) {
    sockwrite -n ircserver.sock. $+ $gettok($hget(4x4evo.chatroom, clients),$hget(4x4evo.chatroom,sendtoroom.count),124) $1-
    hinc 4x4evo.chatroom sendtoroom.count 1
  }
  hdel 4x4evo.chatroom sendtoroom.count
}

alias sendmessagetoroom {
  hadd 4x4evo.chatroom sendtoroom.count 2
  while ($hget(4x4evo.chatroom,sendtoroom.count) <= $numtok($hget(4x4evo.chatroom, clients), 124)) {
    if ($gettok($hget(4x4evo.chatroom, clients), $hget(4x4evo.chatroom,sendtoroom.count),124) != $1) { sockwrite -n ircserver.sock. $+ $gettok($hget(4x4evo.chatroom, clients),$hget(4x4evo.chatroom,sendtoroom.count),124) $2- }
    hinc 4x4evo.chatroom sendtoroom.count 1
  }
  hdel 4x4evo.chatroom sendtoroom.count
}

alias cleanup {
  if ($1 != $null) {
    unset %ircserver.sock. $+ $1 $+ *
    if ($hget(4x4evo.chatroom, $1) != $null) { hdel -w 4x4evo.chatroom $1 $+ * | hdel 4x4evo.chatroom $1 }
    if ($istok($hget(4x4evo.chatroom, clients), $1, 1, 124) == $true) { hadd 4x4evo.chatroom clients $deltok($hget(4x4evo.chatroom, clients), $findtok($hget(4x4evo.chatroom, clients), $1, 1, 124), 124) }
  }
  else {
    unset % $+ $sockname $+ .*
    unset %ircserver.sock. $+ $sock($sockname).ip $+ : $+ $sock($sockname).port $+ .*
    if ($hget(4x4evo.chatroom, $gettok($sockname, 3, 46)) != $null) { hdel -w 4x4evo.chatroom $gettok($sockname, 3, 46) $+ * | hdel 4x4evo.chatroom $gettok($sockname, 3, 46) }
    if ($istok($hget(4x4evo.chatroom, clients), $gettok($sockname, 3, 46), 1, 124) == $true) { hadd 4x4evo.chatroom clients $deltok($hget(4x4evo.chatroom, clients), $findtok($hget(4x4evo.chatroom, clients), $gettok($sockname, 3, 46), 1, 124), 124) }
  }
  return
}

alias disconnectbanned {
  ;hdel -w 4x4evo.chatroom $1 $+ *
  if ($2 == 4620) { sockwrite -n ircserver.sock. $+ $1 ERROR :Closing Link: (Your ID is permanently banned on this server) }
  else { sockwrite -n ircserver.sock. $+ $1 ERROR :Closing Link: (Your ID has been banned for $calc($2 / 60) minutes.) }
  cleanup $1
  .timerdisconnectbanned $+ $rand(1,9999999) 1 1 sockclose ircserver.sock. $+ $1
}

alias -l make_string {
  var %i = 1, %j
  while ($gettok($replace($1,\x,\),0,92) >= %i) {
    %j = %j $bin($gettok($replace($1,\x,\),%i,92))
    inc %i
  }
  return %j
}

alias -l bin {
  if ($len($1) != 2) { return }
  var %i, %j, %k
  if ($left($1,1) !isnum) { %i = $calc($asc($left($1,1)) -87)) }
  else { %i = $left($1,1) }
  if ($right($1,1) !isnum) { %j = $calc($asc($right($1,1)) -87)) }
  else { %j = $right($1,1) }
  while (%i) { %k = %k + 16 | dec %i }
  return $calc(%k + %j)
}

alias hextoascii {
  set %hextoascii.count 1
  while (%hextoascii.count < $len($1)) {
    set %hextoascii.text %hextoascii.text $base($mid($1,%hextoascii.count,2),16,10)
    inc %hextoascii.count 2
  }
  return %hextoascii.text
}

alias padspace {
  if (($1 != $null) && ($2 != $null)) {
    if ($len($2-) < $1) {
      return $2- $+ $str($chr(160), $calc($1 - $len($2-)))
    }
    else { return $2- }
  }
}

; =======
;  Menus
; =======

menu nicklist {
  4x4 Evo
  .Change name:{
    ;tokenize 32 $hget(4x4evo.chatroom,$1)
    hadd 4x4evo.chatroom $1 $gettok($hget(4x4evo.chatroom,$1),1,32) $gettok($hget(4x4evo.chatroom,$1),2,32) $gettok($hget(4x4evo.chatroom,$1),3,32) $gettok($hget(4x4evo.chatroom,$1),4,32) $gettok($hget(4x4evo.chatroom,$1),5,32) $gettok($hget(4x4evo.chatroom,$1),6,32)  $?="Change to name: (ex: Someone^0)"
    sendtoroom : $+ $1 RCHG $!
  }
}
menu Status {
  MSG from ServerBot:{ sendtoroom :_ServerBot PRIVMSG #ChatÿRoom : $+ $$?="Message from bot:" }
  Send Server Text:{ sendtoroom 491 : $+ $$?="Text to send:" }
  Fix server:{
    hadd 4x4evo.chatroom topic fuck you mofo's
    hadd 4x4evo.chatroom clients _ServerBot
    hadd 4x4evo.chatroom _ServerBot 00000000.0-0-0-0 NunYa.Biz.com chat1.4x4evolution.com _ServerBot H* :0 ServerBot^0
  }
  Cleanup variables:unset %ircserver.sock. $+ *
}