on *:udpread:mta.*: var %a,%b | !sockread &a | !dll $+(",$scriptdir,mta.dll,") data $right($sockname,1) $bvar(&a,1)
/*
///////////////////////////////////////////////////////
///////////////        WARNING:         ///////////////
///////////////////////////////////////////////////////
// Editing this script will give an Failed CRC check //
// Please don't edit this script or the dll          //
///////////////////////////////////////////////////////
*/
alias mta.log {
  if ($did(mta,$1 $+ 02).lines == 290) !did -ra mta $1 $+ 02 * Cleared.
  if ($did(mta,$1 $+ 02,$did(mta,$1 $+ 02).lines)) !did -a mta $1 $+ 02 $crlf
  if ($lf isin $3-) !didtok mta $1 $+ 02 10 $2-
  else !did -a mta $1 $+ 02 $2-
  if ($readini($scriptdir $+ mta.ini,$1,log)) !write $+(",$scriptdir,logs\,$asctime(dd-mm-yy),@,$did(mta,$1 $+ 09),;,$did(mta,$1 $+ 10),.txt,") $timestamp $2-
}
alias -l mta.dll !dll $+(",$scriptdir,mta.dll,") $1-
alias mta.name !return $right($readini($+($scriptdir,$1,.ini),n,ID $+ $2,name),-1)
alias mta.kills !return $readini($+($scriptdir,$1,.ini),ID $+ $2,kills)
alias mta.ping !return $readini($+($scriptdir,$1,.ini),ID $+ $2,ping)
alias mta.deaths !return $readini($+($scriptdir,$1,.ini),ID $+ $2,deaths)
alias mta.idle !return $calc(($ticks -$readini($+($scriptdir,$1,.ini),ID $+ $2,idle))/1000)
alias mta.online !return $calc(($ticks -$readini($+($scriptdir,$1,.ini),ID $+ $2,online))/1000)
alias mta.game !return $readini($+($scriptdir,$1,.ini),ID $+ $2,game)
alias mta.type !return $did(mta,$1 $+ 22)
alias mta.server !return $did(mta,$1 $+ 09)
alias mta.players !return $ini($+($scriptdir,$1,.ini),0)
alias mta.maxplayers !return $readini($scriptdir $+ mta.ini,$1,max)
alias mta.say mta.dll say $1 $replace($2-,$chr(124),$chr(5))
alias mta.kick mta.dll kick $1-
alias mta.ban mta.dll ban $1-
alias mta.shutdown mta.dll shutdown $1
alias mta.motd {
  if ($isid) !return $replace($readini($scriptdir $+ mta.ini,$1,motd),~,$lf)
  else mta.dll motd $1
}
alias mta.unban mta.dll unban $1-
alias mta.close {
  var %a = 1,%b = !writeini -n $+(",$scriptdir,mta.ini,")
  while (%a <= 8) {
    if ($did(mta,%a $+ 09)) %b %a host $did(mta,%a $+ 09)
    if ($did(mta,%a $+ 10)) %b %a port $did(mta,%a $+ 10)
    if ($did(mta,%a $+ 11)) %b %a pass $did(mta,%a $+ 11)
    if ($did(mta,%a $+ 12)) %b %a nick $did(mta,%a $+ 12)
    if ($did(mta,%a $+ 23)) %b %a note $didtok(mta,%a $+ 23,$lf)
    if (D* iswm $did(mta,%a $+ 08)) mta.dis %a Quit.
    !inc %a
  }
  !dll -u $+(",$scriptdir,mta.dll,")
  !dialog -x mta
  if ($dialog(options)) !dialog -x options
  if ($dialog(scripts)) !dialog -x scripts
  if ($dialog(stats)) !dialog -x stats
}
alias mta.con {
  if (!$dialog(mta).active) mta
  if ($did(mta,$1 $+ 12) == $null) mta.log $1 * Nick missing.
  elseif (!$regex($did(mta,$1 $+ 09),^[1-2]?[0-9]?[0-9][.][1-2]?[0-9]?[0-9][.][1-2]?[0-9]?[0-9][.][1-2]?[0-9]?[0-9]$)) mta.log $1 * Invalid IP.
  elseif ($did(mta,$1 $+ 10) !isnum) mta.log $1 * Invalid port.
  else {
    !remini $+(",$scriptdir,mta.ini,") $1 motd
    !.remove $+(",$scriptdir,$1,.ini,")
    !did -ra mta $1 $+(Server,$1,*)
    !did -ra mta $1 $+ 08 Cancel
    !did -b mta $+($1,09,$chr(44),$1,10,$chr(44),$1,11,$chr(44),$1,12)
    !did -r mta $1 $+ 02
    mta.log $1 * Connecting...
    !.timerto $+ $1 1 10 mta.dis $1 Timed out.
    mta.dll join $1
  }
}
alias mta.dis {
  !.timerto $+ $1 off
  mta.dll part $1
  var %a = mta. $+ $1
  mta.log $1 * Disconnected: $2-
  mta.log $1 * Send: $bytes($sock(%a).sent,3).suf $chr(124) Recieved: $bytes($sock(%a).rcvd,3).suf $chr(124) Time: $duration($sock(%a).to)
  !sockclose %a
  !did -ra mta $1 Server $+ $1
  !did -ra mta $1 $+ 08 Connect
  !did -e mta $+($1,09,$chr(44),$1,10,$chr(44),$1,11,$chr(44),$1,12)
  !did -b mta $+($1,03,$chr(44),$1,14,$chr(44),$1,15,$chr(44),$1,16,$chr(44),$1,17,$chr(44),$1,24)
  !did -r mta $+($1,01,$chr(44),$1,03,$chr(44),$1,21,$chr(44),$1,22,$chr(44),$1,27)
  !.remove $+(",$scriptdir,$1,.ini,")
  if ($isalias(mta.disconnect)) mta.disconnect $1-
}
alias mta {
  var %a = 1
  if (($version => 6.12) || ($input(You have not mIRC 6.12 or higher this could give problems. Continue?,ywd,MTA mIRC Admin))) {
    if (!$exists($scriptdir $+ mta.dll)) {
      %a = $input(mta.dll not found!,ohd,MTA mIRC Admin)
      mta.close
    }
    else {
      !.events on
      if (!$dialog(mta)) {
        !dialog -md mta mta
        if ($readini($scriptdir $+ mta.ini,0,update) != 0) mta.update
        !mkdir $+(",$scriptdir,logs,")
        while (%a <= 8) {
          if ($readini($scriptdir $+ mta.ini,%a,conn)) mta.con %a
          !inc %a
        }
        if ($isalias(mta.start)) mta.start
      }
      else !dialog -v mta
    }
  }
}
alias mta.active {
  if ($dialog(mta)) {
    var %a = 1
    while (!$did(mta,%a $+ 01).visible) inc %a
    return %a
  }
}
alias -l mta.list {
  var %a = 1,%b,%c
  while (%a <= $mta.players($1)) {
    %b = $right($ini($+($scriptdir,$1,.ini),%a),-2)
    %c = %c $+ %b $mta.kills($1,%b) $mta.name($1,%b) $+ $chr(124)
    !inc %a
  }
  %b = $sorttok($left(%c,-1),124,n)
  !did -r mta $1 $+ 01
  !didtok mta $1 $+ 01 124 %b
  !did -a mta $1 $+ 21 $mta.players($1) / $mta.maxplayers($1)
}
alias -l mta.dex {
  var %a = 1,%b
  while (%a <= $len($1-)) {
    %b = %b $asc($mid($1-,%a,1))
    !inc %a
  }
  !return %b
}
dialog -l mta {
  title "MTA mIRC Admin v1.222 by Aeron"
  size -1 -1 260 160
  option dbu
  icon $scriptdir $+ mta.ico, 0
  tab "Server1", 1, -3 -3 263 165
  list 101, 2 14 56 144, tab 1 size vsbar
  edit "", 102, 60 14 126 132, tab 1 read multi autovs vsbar
  combo 103, 60 148 96 50, disable size edit drop tab 1 autohs
  text "Host:", 104, 188 14 17 8, tab 1
  text "Port:", 105, 188 24 17 8, tab 1
  text "Pass:", 106, 188 34 17 8, tab 1
  text "Nick:", 107, 188 44 17 8, tab 1
  button "Connect", 108, 188 80 34 12, tab 1
  edit "", 109, 206 14 48 10, tab 1 autohs
  edit "", 110, 206 24 48 10, tab 1
  edit "", 111, 206 34 48 10, tab 1 pass
  edit "", 112, 206 44 48 10, tab 1
  text "Notes:", 113, 188 52 17 8, tab 1
  button "Send", 114, 158 148 27 10, disable tab 1
  button "Kick", 115, 188 92 34 12, disable tab 1
  button "Ban", 116, 188 104 34 12, disable tab 1
  button "Shutdown server", 117, 188 116 69 12, disable tab 1
  button "Options", 118, 223 80 34 12, tab 1
  text "Players:", 119, 188 130 25 8, tab 1
  text "Mode:", 120, 188 140 25 8, tab 1
  text "", 121, 216 130 31 8, tab 1
  text "", 122, 216 140 31 8, tab 1
  edit "", 123, 188 60 68 20, tab 1 multi return vsbar
  button "Unban", 124, 223 104 34 12, tab 1 disable
  button "Scripts", 125, 223 92 34 12, tab 1
  text "Ping:", 126, 188 150 25 8, tab 1
  text "", 127, 216 150 31 8, tab 1
  tab "Server2", 2
  list 201, 2 14 56 144, tab 2 size vsbar
  edit "", 202, 60 14 126 132, tab 2 read multi autovs vsbar
  combo 203, 60 148 96 50, disable size edit drop tab 2 autohs
  text "Host:", 204, 188 14 17 8, tab 2
  text "Port:", 205, 188 24 17 8, tab 2
  text "Pass:", 206, 188 34 17 8, tab 2
  text "Nick:", 207, 188 44 17 8, tab 2
  button "Connect", 208, 188 80 34 12, tab 2
  edit "", 209, 206 14 48 10, tab 2 autohs
  edit "", 210, 206 24 48 10, tab 2
  edit "", 211, 206 34 48 10, tab 2 pass
  edit "", 212, 206 44 48 10, tab 2
  text "Notes:", 213, 188 52 17 8, tab 2
  button "Send", 214, 158 148 27 10, disable tab 2
  button "Kick", 215, 188 92 34 12, disable tab 2
  button "Ban", 216, 188 104 34 12, disable tab 2
  button "Shutdown server", 217, 188 116 69 12, disable tab 2
  button "Options", 218, 223 80 34 12, tab 2
  text "Players:", 219, 188 130 25 8, tab 2
  text "Mode:", 220, 188 140 25 8, tab 2
  text "", 221, 216 130 31 8, tab 2
  text "", 222, 216 140 31 8, tab 2
  edit "", 223, 188 60 68 20, tab 2 multi return vsbar
  button "Unban", 224, 223 104 34 12, tab 2 disable
  button "Scripts", 225, 223 92 34 12, tab 2
  text "Ping:", 226, 188 150 25 8, tab 2
  text "", 227, 216 150 31 8, tab 2
  tab "Server3", 3
  list 301, 2 14 56 144, tab 3 size vsbar
  edit "", 302, 60 14 126 132, tab 3 read multi autovs vsbar
  combo 303, 60 148 96 50, disable size edit drop tab 3 autohs
  text "Host:", 304, 188 14 17 8, tab 3
  text "Port:", 305, 188 24 17 8, tab 3
  text "Pass:", 306, 188 34 17 8, tab 3
  text "Nick:", 307, 188 44 17 8, tab 3
  button "Connect", 308, 188 80 34 12, tab 3
  edit "", 309, 206 14 48 10, tab 3 autohs
  edit "", 310, 206 24 48 10, tab 3
  edit "", 311, 206 34 48 10, tab 3 pass
  edit "", 312, 206 44 48 10, tab 3
  text "Notes:", 313, 188 52 17 8, tab 3
  button "Send", 314, 158 148 27 10, disable tab 3
  button "Kick", 315, 188 92 34 12, disable tab 3
  button "Ban", 316, 188 104 34 12, disable tab 3
  button "Shutdown server", 317, 188 116 69 12, disable tab 3
  button "Options", 318, 223 80 34 12, tab 3
  text "Players:", 319, 188 130 25 8, tab 3
  text "Mode:", 320, 188 140 25 8, tab 3
  text "", 321, 216 130 31 8, tab 3
  text "", 322, 216 140 31 8, tab 3
  edit "", 323, 188 60 68 20, tab 3 multi return vsbar
  button "Unban", 324, 223 104 34 12, tab 3 disable
  button "Scripts", 325, 223 92 34 12, tab 3
  text "Ping:", 326, 188 150 25 8, tab 3
  text "", 327, 216 150 31 8, tab 3
  tab "Server4", 4
  list 401, 2 14 56 144, tab 4 size vsbar
  edit "", 402, 60 14 126 132, tab 4 read multi autovs vsbar
  combo 403, 60 148 96 50, disable size edit drop tab 4 autohs
  text "Host:", 404, 188 14 17 8, tab 4
  text "Port:", 405, 188 24 17 8, tab 4
  text "Pass:", 406, 188 34 17 8, tab 4
  text "Nick:", 407, 188 44 17 8, tab 4
  button "Connect", 408, 188 80 34 12, tab 4
  edit "", 409, 206 14 48 10, tab 4 autohs
  edit "", 410, 206 24 48 10, tab 4
  edit "", 411, 206 34 48 10, tab 4 pass
  edit "", 412, 206 44 48 10, tab 4
  text "Notes:", 413, 188 52 17 8, tab 4
  button "Send", 414, 158 148 27 10, disable tab 4
  button "Kick", 415, 188 92 34 12, disable tab 4
  button "Ban", 416, 188 104 34 12, disable tab 4
  button "Shutdown server", 417, 188 116 69 12, disable tab 4
  button "Options", 418, 223 80 34 12, tab 4
  text "Players:", 419, 188 130 25 8, tab 4
  text "Mode:", 420, 188 140 25 8, tab 4
  text "", 421, 216 130 31 8, tab 4
  text "", 422, 216 140 31 8, tab 4
  edit "", 423, 188 60 68 20, tab 4 multi return vsbar
  button "Unban", 424, 223 104 34 12, tab 4 disable
  button "Scripts", 425, 223 92 34 12, tab 4
  text "Ping:", 426, 188 150 25 8, tab 4
  text "", 427, 216 150 31 8, tab 4
  tab "Server5", 5
  list 501, 2 14 56 144, tab 5 size vsbar
  edit "", 502, 60 14 126 132, tab 5 read multi autovs vsbar
  combo 503, 60 148 96 50, disable size edit drop tab 5 autohs
  text "Host:", 504, 188 14 17 8, tab 5
  text "Port:", 505, 188 24 17 8, tab 5
  text "Pass:", 506, 188 34 17 8, tab 5
  text "Nick:", 507, 188 44 17 8, tab 5
  button "Connect", 508, 188 80 34 12, tab 5
  edit "", 509, 206 14 48 10, tab 5 autohs
  edit "", 510, 206 24 48 10, tab 5
  edit "", 511, 206 34 48 10, tab 5 pass
  edit "", 512, 206 44 48 10, tab 5
  text "Notes:", 513, 188 52 17 8, tab 5
  button "Send", 514, 158 148 27 10, disable tab 5
  button "Kick", 515, 188 92 34 12, disable tab 5
  button "Ban", 516, 188 104 34 12, disable tab 5
  button "Shutdown server", 517, 188 116 69 12, disable tab 5
  button "Options", 518, 223 80 34 12, tab 5
  text "Players:", 519, 188 130 25 8, tab 5
  text "Mode:", 520, 188 140 25 8, tab 5
  text "", 521, 216 130 31 8, tab 5
  text "", 522, 216 140 31 8, tab 5
  edit "", 523, 188 60 68 20, tab 5 multi return vsbar
  button "Unban", 524, 223 104 34 12, tab 5 disable
  button "Scripts", 525, 223 92 34 12, tab 5
  text "Ping:", 526, 188 150 25 8, tab 5
  text "", 527, 216 150 31 8, tab 5
  tab "Server6", 6
  list 601, 2 14 56 144, tab 6 size vsbar
  edit "", 602, 60 14 126 132, tab 6 read multi autovs vsbar
  combo 603, 60 148 96 50, disable size edit drop tab 6 autohs
  text "Host:", 604, 188 14 17 8, tab 6
  text "Port:", 605, 188 24 17 8, tab 6
  text "Pass:", 606, 188 34 17 8, tab 6
  text "Nick:", 607, 188 44 17 8, tab 6
  button "Connect", 608, 188 80 34 12, tab 6
  edit "", 609, 206 14 48 10, tab 6 autohs
  edit "", 610, 206 24 48 10, tab 6
  edit "", 611, 206 34 48 10, tab 6 pass
  edit "", 612, 206 44 48 10, tab 6
  text "Notes:", 613, 188 52 17 8, tab 6
  button "Send", 614, 158 148 27 10, disable tab 6
  button "Kick", 615, 188 92 34 12, disable tab 6
  button "Ban", 616, 188 104 34 12, disable tab 6
  button "Shutdown server", 617, 188 116 69 12, disable tab 6
  button "Options", 618, 223 80 34 12, tab 6
  text "Players:", 619, 188 130 25 8, tab 6
  text "Mode:", 620, 188 140 25 8, tab 6
  text "", 621, 216 130 31 8, tab 6
  text "", 622, 216 140 31 8, tab 6
  edit "", 623, 188 60 68 20, tab 6 multi return vsbar
  button "Unban", 624, 223 104 34 12, tab 6 disable
  button "Scripts", 625, 223 92 34 12, tab 6
  text "Ping:", 626, 188 150 25 8, tab 6
  text "", 627, 216 150 31 8, tab 6
  tab "Server7", 7
  list 701, 2 14 56 144, tab 7 size vsbar
  edit "", 702, 60 14 126 132, tab 7 read multi autovs vsbar
  combo 703, 60 148 96 50, disable size edit drop tab 7 autohs
  text "Host:", 704, 188 14 17 8, tab 7
  text "Port:", 705, 188 24 17 8, tab 7
  text "Pass:", 706, 188 34 17 8, tab 7
  text "Nick:", 707, 188 44 17 8, tab 7
  button "Connect", 708, 188 80 34 12, tab 7
  edit "", 709, 206 14 48 10, tab 7 autohs
  edit "", 710, 206 24 48 10, tab 7
  edit "", 711, 206 34 48 10, tab 7 pass
  edit "", 712, 206 44 48 10, tab 7
  text "Notes:", 713, 188 52 17 8, tab 7
  button "Send", 714, 158 148 27 10, disable tab 7
  button "Kick", 715, 188 92 34 12, disable tab 7
  button "Ban", 716, 188 104 34 12, disable tab 7
  button "Shutdown server", 717, 188 116 69 12, disable tab 7
  button "Options", 718, 223 80 34 12, tab 7
  text "Players:", 719, 188 130 25 8, tab 7
  text "Mode:", 720, 188 140 25 8, tab 7
  text "", 721, 216 130 31 8, tab 7
  text "", 722, 216 140 31 8, tab 7
  edit "", 723, 188 60 68 20, tab 7 multi return vsbar
  button "Unban", 724, 223 104 34 12, tab 7 disable
  button "Scripts", 725, 223 92 34 12, tab 7
  text "Ping:", 726, 188 150 25 8, tab 7
  text "", 727, 216 150 31 8, tab 7
  tab "Server8", 8
  list 801, 2 14 56 144, tab 8 size vsbar
  edit "", 802, 60 14 126 132, tab 8 read multi autovs vsbar
  combo 803, 60 148 96 50, disable size edit drop tab 8 autohs
  text "Host:", 804, 188 14 17 8, tab 8
  text "Port:", 805, 188 24 17 8, tab 8
  text "Pass:", 806, 188 34 17 8, tab 8
  text "Nick:", 807, 188 44 17 8, tab 8
  button "Connect", 808, 188 80 34 12, tab 8
  edit "", 809, 206 14 48 10, tab 8 autohs
  edit "", 810, 206 24 48 10, tab 8
  edit "", 811, 206 34 48 10, tab 8 pass
  edit "", 812, 206 44 48 10, tab 8
  text "Notes:", 813, 188 52 17 8, tab 8
  button "Send", 814, 158 148 27 10, disable tab 8
  button "Kick", 815, 188 92 34 12, disable tab 8
  button "Ban", 816, 188 104 34 12, disable tab 8
  button "Shutdown server", 817, 188 116 69 12, disable tab 8
  button "Options", 818, 223 80 34 12, tab 8
  text "Players:", 819, 188 130 25 8, tab 8
  text "Mode:", 820, 188 140 25 8, tab 8
  text "", 821, 216 130 31 8, tab 8
  text "", 822, 216 140 31 8, tab 8
  edit "", 823, 188 60 68 20, tab 8 multi return vsbar
  button "Unban", 824, 223 104 34 12, tab 8 disable
  button "Scripts", 825, 223 92 34 12, tab 8
  text "Ping:", 826, 188 150 25 8, tab 8
  text "", 827, 216 150 31 8, tab 8
}
on *:DIALOG:mta:edit:*: if (*03 iswm $did) !did -t mta $left($did,1) $+ 14
on *:DIALOG:mta:init:0: {
  var %a = 1
  while (%a <= 8) {
    !did -a mta %a $+ 09 $readini($scriptdir $+ mta.ini,%a,host)
    !did -a mta %a $+ 10 $readini($scriptdir $+ mta.ini,%a,port)
    !did -a mta %a $+ 11 $readini($scriptdir $+ mta.ini,%a,pass)
    !did -a mta %a $+ 12 $readini($scriptdir $+ mta.ini,%a,nick)
    !didtok -a mta %a $+ 23 44 $readini($scriptdir $+ mta.ini,%a,note)
    !inc %a
  }
}
on *:DIALOG:mta:close:0: mta.close
on *:DIALOG:mta:sclick:*: {
  var %a = $left($did,1),%b
  if (*08 iswm $did) {
    if (Co* iswm $did(mta,%a $+ 08)) mta.con %a
    else mta.dis %a User.
  }
  if ((*14 iswm $did) && ($did(mta,%a $+ 03))) {
    if (/* iswm $did(mta,%a $+ 03)) {
      tokenize 32 $did(mta,%a $+ 03)
      if ($1 == /close) mta.close
      elseif ($1 == /update) mta.update
      else mta.log %a * $1 Unknown command.
    }
    else mta.say %a $did(mta,%a $+ 03)
    !did -i mta %a $+ 03 1 $did(mta,%a $+ 03)
    !did -d mta %a $+ 03 0
  }
  if (*15 iswm $did) {
    if (!$did(mta,%a $+ 01).seltext) %b = $input(No nickname selected!,owd,MTA mIRC Admin)
    else mta.dll kick %a $gettok($did(mta,%a $+ 01).seltext,1,32)
    !dialog -v mta
  }
  if (*16 iswm $did) {
    if (!$did(mta,%a $+ 01).seltext) %b = $input(No nickname selected!,owd,MTA mIRC Admin)
    elseif ($input(Are you sure to ban $gettok($did(mta,%a $+ 01).seltext,3-,32) ?,yqd,MTA mIRC Admin)) mta.dll ban %a $gettok($did(mta,%a $+ 01).seltext,1,32)
    !dialog -v mta
  }
  if ((*17 iswm $did) && ($input(Are you sure to shutdown server $chr(35) $+ %a ?,yqd,MTA mIRC Admin))) mta.dll shutdown %a
  if (*18 iswm $did) {
    if (!$dialog(options)) !dialog -md options options
    else !dialog -v options
  }
  if (*24 iswm $did) { 
    mta.dll unban %a $$input(Enter IP:,e,MTA mIRC Admin)
    !dialog -v mta
  }
  if (*25 iswm $did) {
    if (!$dialog(scripts)) !dialog -md scripts scripts
    else !dialog -v scripts
  }
}
dialog -l options {
  title "Options"
  size -1 -1 105 54
  option dbu
  icon $scriptdir $+ mta.ico, 0
  check "Enable logging", 1, 4 8 46 10
  check "Auto connect", 2, 4 18 46 10
  box "", 3, 2 2 50 40
  box "General", 4, 54 2 50 28
  button "OK", 5, 60 40 43 12, ok
  check "Auto start", 6, 58 8 44 10
  link "http://www.mtavc.com", 7, 2 44 58 8
  button "Refresh Motd", 8, 4 28 45 12
  check "Live update", 9, 58 18 44 10
}
on *:DIALOG:options:sclick:7: !run iexplore http://www.mtavc.com
on *:DIALOG:options:sclick:8: mta.dll motd $right($did(options,3),1)
on *:DIALOG:options:init:0: {
  !did -a options 3 Server: $mta.active
  !did -c options 9
  if (D* !iswm $did(mta,$mta.active $+ 08)) !did -b options 8
  if ($readini($scriptdir $+ mta.ini,$mta.active,log)) !did -c options 1
  if ($readini($scriptdir $+ mta.ini,$mta.active,conn)) !did -c options 2
  if ($readini($scriptdir $+ mta.ini,0,auto)) !did -c options 6
  if ($readini($scriptdir $+ mta.ini,0,update) == 0) !did -u options 9
}
on *:DIALOG:options:close:0: {
  var %a = !writeini -n $+(",$scriptdir,mta.ini,")
  %a $right($did(options,3),1) log $did(options,1).state
  %a $right($did(options,3),1) conn $did(options,2).state
  %a 0 auto $did(options,6).state
  %a 0 update $did(options,9).state
}
dialog -l scripts {
  title "Scripts"
  size -1 -1 105 26
  option dbu
  icon $scriptdir $+ mta.ico, 0
  combo 1, 2 12 60 50, size drop
  button "Load / OK", 2, 66 12 37 12, ok
  text "Loaded:", 3, 2 2 21 8
  text "", 4, 24 2 79 8
}
on *:DIALOG:scripts:init:0: {
  var %a = 1,%b
  %b = $findfile($scriptdir,*,0,0,if ((*.mrc iswm $1-) && ($nopath($script($1-)) != mta.mrc)) !didtok scripts 1 44 $nopath($1-))
  while (%a <= $script(0)) {
    if (($read($script(%a),w,alias mta*)) && ($nopath($script(%a)) != mta.mrc)) {
      !did -a scripts 4 $nopath($script(%a))
      !halt
    }
    !inc %a
  }
  !did -a scripts 4 No MTA script loaded.
}
on *:DIALOG:scripts:close:0: {
  if ((No* !iswm $did(scripts,4)) && ($did(scripts,1).seltext)) !.unload -rs $+(",$scriptdir,$did(scripts,4),")
  if ($did(scripts,1).seltext != $null) !.load -rs $+(",$scriptdir,$did(scripts,1).seltext,")
}
on *:DIALOG:mta:dclick:*: {
  var %a = $left($did,1)
  if ((*01 iswm $did) && ($did(mta,%a $+ 01).seltext)) {
    if (!$dialog(stats)) !dialog -md stats stats
    else !dialog -v stats
  }
}
dialog -l stats {
  title "Stats"
  size -1 -1 68 82
  option dbu
  icon $scriptdir $+ mta.ico, 0
  text "Nickname:", 1, 2 2 25 8
  text "", 2, 28 2 37 8
  text "ID:", 3, 2 10 25 8
  text "", 4, 28 10 37 8
  text "Ping:", 5, 2 18 25 8
  text "", 6, 28 18 37 8
  text "Kills:", 7, 2 26 25 8
  text "", 8, 28 26 37 8
  text "Deaths:", 9, 2 34 25 8
  text "", 10, 28 34 37 8
  text "Online:", 11, 2 42 25 8
  text "", 12, 28 42 37 8
  text "Idle:", 13, 2 50 25 8
  text "", 14, 28 50 37 8
  text "Status:", 15, 2 58 25 8
  text "", 16, 28 58 37 8
  button "OK", 17, 15 68 37 12, ok
}
on *:DIALOG:stats:init:0: {
  var %a = $mta.active,%b = $gettok($did(mta,%a $+ 01).seltext,1,32)
  !did -a stats 2 $mta.name(%a,%b)
  !did -a stats 4 %b
  !did -a stats 6 $mta.ping(%a,%b)
  !did -a stats 8 $mta.kills(%a,%b)
  !did -a stats 10 $mta.deaths(%a,%b)
  !did -a stats 12 $duration($mta.online(%a,%b))
  !did -a stats 14 $duration($mta.idle(%a,%b))
  !did -a stats 16 $iif($mta.game(%a,%b) == 1,Out Game,In Game)
}
on *:START: if ($readini($scriptdir $+ mta.ini,0,auto)) mta
alias -l mta.update {
  if ($dialog(update)) !dialog -x update
  var %a = $findfile($mircdir,*.tmp,0,!.remove $1-)
  !sockclose mta.update
  !sockopen mta.update home.deds.nl 80
}
dialog -l update {
  title "Live update"
  size -1 -1 94 94
  option dbu
  icon $scriptdir $+ mta.ico, 0
  button "Yes", 1, 8 80 37 12
  button "No", 2, 52 80 37 12, ok
  edit "", 3, 2 2 90 54, multi return vsbar
  text "Status:", 4, 2 58 19 8
  text "", 5, 22 58 69 8
  edit "", 6, 2 68 90 10, disable
}
on *:sockopen:mta.update: !sockwrite -n mta.update GET /~aeron/files/mta.txt HTTP/1.1 $+ $crlf $+ Accept: */* $+ $crlf $+ User-Agent: mIRC $+ $crlf $+ Host: home.deds.nl $+ $crlf $+ Connection: Close $+ $crlf $+ $crlf
on *:sockread:mta.update:{ 
  !sockread %temp
  while ($sockbr != 0) {
    !write mta.tmp %temp
    !sockread %temp
  }
}
on *:sockclose:mta.update:{ 
  var %a = $read(mta.tmp,11)
  if ($right($gettok($dialog(mta).title,4,32),-1) < %a) {
    !dialog -md update update
    !did -m update 3
    !did -a update 5 Download version %a $+ ?
    %a = 10
    while (%a <= $lines(mta.tmp)) {
      !did -a update 3 $read(mta.tmp,%a) $+ $lf
      !inc %a
    }
  }
  else !.remove mta.tmp
}
on *:sockopen:mta.dl: {
  !tokenize 32 $read(mta.tmp,$sock(mta.dl).mark)
  if ($1 == Fixes:) {
    !did -ra update 5 Finished.
    !did -ra update 2 Install
    !sockclose mta.dl
  }
  else {
    !did -a update 5 Downloading $1
    !sockwrite -n mta.dl GET /~aeron/files/ $+ $1 HTTP/1.1 $+ $crlf $+ Accept: */* $+ $crlf $+ User-Agent: mIRC $+ $crlf $+ Host: home.deds.nl $+ $crlf $+ Connection: Close $+ $crlf $+ $crlf
  }
}
on *:sockread:mta.dl:{ 
  !tokenize 32 $read(mta.tmp,$sock(mta.dl).mark)
  !sockread -f &a
  while ($sockbr != 0) {
    !did -ra update 6 $str(|,$calc(42/ $2 * $sock(mta.dl).rcvd))
    !bwrite $1 $+ .tmp -1 &a
    !sockread -f &a
  }
}
on *:sockclose:mta.dl: {
  !tokenize 32 $read(mta.tmp,$sock(mta.dl).mark)
  !.timer -m 1 1 mta.dl $calc(1+$sock(mta.dl).mark)
}
alias mta.dl {
  !sockopen mta.dl home.deds.nl 80
  !sockmark mta.dl $1
}
on *:DIALOG:update:sclick:1: {
  mta.close
  !did -a update 5 Connencting...
  !did -h update 1
  !did -ra update 2 Cancel
  !sockclose mta.dl
  mta.dl 13
}
on *:DIALOG:update:close:0: var %a = $findfile($mircdir,*.tmp,0,!.remove $1-)
on *:DIALOG:update:sclick:2: {
  if (I* iswm $did(update,2)) {
    var %a = 13
    while ($read(mta.tmp,%a) != Fixes:) {
      !tokenize 32 $read(mta.tmp,%a)
      !.remove $+(",$scriptdir,$1,")
      !bread $1 $+ .tmp 1 $file($1 $+ .tmp).size &a
      !bcopy -c &a 1 &a $calc($bfind(&a,%a,10 13 10)+3) -1
      !bwrite $+(",$scriptdir,$1,") 0 &a
      !inc %a
    }
    !.timer -m 1 100 !.load -rs $script
    !.timer -m 1 200 mta
    !.unload -rs $script
  }
}
