/*
####################################################################
#    ___    ____    _____   _   _       _    ___    _  __  _____   #
#   / _ \  |  _ \  | ____| | \ | |     | |  / _ \  | |/ / | ____|  #
#  | | | | | |_) | |  _|   |  \| |  _  | | | | | | | ' /  |  _|    #
#  | |_| | |  __/  | |___  | |\  | | |_| | | |_| | | . \  | |___   #
#   \___/  |_|     |_____| |_| \_|  \___/   \___/  |_|\_\ |_____|  #
#          ____   _        ___    ____       _      _              #
#         / ___| | |      / _ \  | __ )     / \    | |             #
#        | |  _  | |     | | | | |  _ \    / _ \   | |             #
#        | |_| | | |___  | |_| | | |_) |  / ___ \  | |___          #
#         \____| |_____|  \___/  |____/  /_/   \_\ |_____|         #
#                  _____   ___   _   _   ____                      #
#                 | ____| |_ _| | \ | | |  _ \                     #
#                 |  _|    | |  |  \| | | | | |                    #
#                 | |      | |  | |\  | | |_| |                    #
#                 |_|     |___| |_| \_| |____/                     #
####################################################################
##################### OPENJOKE GLOBAL FIND #########################
####################################################################
######### by Paradox aka Farfuglio from OpenJoke Network ###########
####################################################################
### Per caricare l'addon, copia questo file nella root di mirc #####
############ poi scrivi in mIRC: /load -rs GlobalFind.mrc ##########
####################################################################
#### ATTENZIONE!! NON MODIFICARE NESSUNA PARTE DI QUESTO SCRIPT ####
####################################################################
[INFO]
ADDON=Extended Global Find
VERSION=0.7.5.4
RELEASE=Beta
FILE=GlobalFind.mrc
DATABASE=DataBase.db
REMOTEDIR=GlobalFindEx
AUTORE=Paradox aka Farfuglio
NETWORK=OpenJoke
DNS=irc.OpenJoke.org
DATA=01/06/19
SUPCHAN=#GlobalFind
HOME=http://xdccmule.org
HOMENET=http://openjoke.org
NEWSLIST=http://xdccmule.org/
*/

menu menuBar,status,Channel {
  -
  $iif($dialog(GlobalFind) ,$style(1)) Global Find Extended:GlobalFind
  Opzioni GlobalFind
  .$iif($dll(dcx.dll), $iif(!%DockGlobalFind, Dock)) : { DockUndockGf 1 }
  .$iif($dll(dcx.dll), $iif(%DockGlobalFind, UnDock)) : { DockUndockGf  }
  -
  -> join Canali DB
  .$submenu($ListChanDB($1))
  -> WebList Canali DB
  .$submenu($WebListChanDB($1))
  -> Finestre di ricerca
  . Chiudi Tutte: close -@ @Find[#*]
  .-
  . $submenu($ListFindWin($1))
  $iif(!$hget(NewsTable,0).item,$style(2)) -> Novità:SpeakNovita
  -
  $iif($findfile($scriptdir,*.db,0) == 1, $style(2),$style(1) -> Gestione DataBase)
  .$style(2) Lista db:noop
  .$submenu($ListAllDB($1))
  -
}

menu Channel {
  -
  --> Ricerca Veloce... : {
    var %tk = #GlobalFind #IRCHelp #Help #Vhost #Link
    if ($istok(%tk,$active,32)) {
      var %k = $input(Il Canale $active è un canale di Supporto $crlf NON contiene files. $crlf ,owdk5,RICERCA VELOCE)
      return
    }
    if ($SpeedFind($active) != $null) {
      var %k = $input(Vuoi effettuare una ricerca veloce in $active di $ActiveNet $+ ? $crlf $crlf Digita il termine di ricerca.,yegdq,RICERCA VELOCE)
      if ($chr(42) isin %k) {
        var %k = $input(Carattere $chr(42) non supportato! $crlf $crlf ,owdk5,ERRORE CARATTERE) 
        return
      }    
      if (%k) .SpeedSearch $SpeedFind($active) $ActiveNet %k
    }
    else {
      var %k = $input(Il Canale $active di $ActiveNet $crlf $crlf Non è presente nel DataBase.,owdk5,RICERCA VELOCE)
    }
  }
  -
}

on *:LOAD: {
  echo 4 -st addon $readini($script,INFO,Network) $InfoEstese Caricata.
  set %CloseAllFindWin 1 | set %SetGlobalNet 1 | .StampSignature
}

on *:UNLOAD: {
  echo 4 -st addon $readini($script,INFO,Network) $InfoEstese Scaricata.
  unset %CloseAllFindWin %LogRichieste %SetGlobalNet %UpdateDbVerifydate_* %ricercato %StoricoRicerche %StorySearch %selectedDb %HomeSelect %StyleSearch %MoveCompleted %UpdateCounter
  .timerUpdate* off | .timerTempNews off | .timerVerifyUpdate off
}

on *:START: {
  .Verify2Download | .CrontabUpdate | .UpdateSysFind VerifyNovita | .RunSpot
  .AvviAds
  if (%DockGlobalFind = 1) .GlobalFind 
}

on 1:CLOSE:@: {
  if ($target == @NewsFindAddon) && ($dialog(GlobalFind)) { .GlobalFind }
  if ($target == @Find[Global]) { .timerGlobalFind* off | .sockclose GlobalS-G-* | .sockclose GlobalS-T-* }
  if (@Find[#*] iswm $target) { var %c = $left($right($target,-6),-1) | .sockclose $+(GlobalS-C-*-,%c) }
}

on 1:EXIT: {
  if (%StorySearch == 1) { unset %StoricoRicerche }
}

alias DockUndockGf {
  if ($1 == 1) { set %DockGlobalFind 1 }
  else { unset %DockGlobalFind }
  var %d = GlobalFind
  if ($dialog(%d)) dialog -x %d %d
  .timerOpenGf 1 0 GlobalFind
}

alias GlobalFind {
  var %d = GlobalFind
  if (!%DockGlobalFind) || (!$dll(dcx.dll)) {
    if (%DockGlobalFind) echo 4 -seat INFO: Non è presente la libreria dcx, non posso usare la funzione Dock.
    if (%DockGlobalFind) unset %DockGlobalFind
    if ($group(#GlobalFindEmbeded) == on) .disable #GlobalFindEmbeded
    .enable #GlobalFind
    dialog $iif($dialog(%d),-ev,-md) %d %d
    return
  }
  if ($group(#GlobalFind) == on) .disable #GlobalFind
  .enable #GlobalFindEmbeded
  dialog $iif($dialog(%d),-ev,-md) %d %d
  if (!$xdock($dialog(GlobalFind).hwnd).isDocked) .timerinitGoBar 1 0 xdock -m $dialog(GlobalFind).hwnd +t
}

#GlobalFind off
dialog -l GlobalFind {
  title "Global Find"
  icon  $mircexe, 12
  size -1 -1 190 69
  option dbu $iif($os = xp, notheme)
  tab "Cerca", 1, 0 0 190 56
  text "Nome:", 5, 3 19 20 8, tab 1
  combo 6, 27 17 106 105, tab 1 size edit drop
  button "«", 7, 136 17 10 11, tab 1
  button "Cerca", 8, 150 17 37 11, tab 1
  text "Lista:", 9, 3 32 24 8, tab 1
  combo 10, 27 30 86 200, tab 1 size drop
  button "Lista Web", 11, 150 30 37 11, tab 1
  button "Annulla", 12, 117 43 30 11, tab 1
  text "INFO:", 13, 2 59 16 8
  text "--", 14, 20 59 144 8, center
  button "Join", 15, 117 30 30 11, tab 1
  button "Chiudi", 16, 150 43 37 11, tab 1 cancel
  text "Network:", 17, 3 44 30 8, tab 1
  combo 18, 27 43 86 200, tab 1 size drop
  tab "Vetrine", 100
  text "Categoria:", 101, 3 19 30 8, tab 100
  combo 102, 32 17 68 180, tab 100 size drop
  text "Risultati (?/? descrizione):", 103, 3 32 100 8, tab 100
  combo 104, 5 43 181 160, tab 100 size drop
  button "Cerca", 105, 150 17 37 11, tab 100
  button "@Novità", 106, 150 30 37 11, tab 100
  button "Update", 107, 110 17 37 11, tab 100
  button "CineApp", 108, 110 30 37 11, tab 100
  tab "Supporto", 2
  tab "Update", 3
  tab "Opzioni", 4
  button "Verifica Aggiornamenti", 19, 3 17 58 16, tab 3
  text "Data DB: ----", 25, 64 17 104 8, tab 3
  check "Chiudi tutte le finestre di ricerca alla chiusura di questa addon", 26, 3 44 164 10, tab 4
  text "Addon: ----", 28, 64 26 104 8, tab 3
  button "Apri Home", 50, 3 17 40 11, tab 2
  text "Accesso alla Home dell'addon", 51, 46 19 120 8, tab 2
  button "Entra", 52, 3 30 40 11, tab 2
  text "Entra nel Canale di supporto dell'addon", 53, 46 32 120 8, tab 2
  text "->", 54, 3 44 10 8, disable tab 2
  text "Segnalate eventuali bug dell'addon.", 55, 15 44 120 8, disable tab 2
  tab "Info", 59
  text "...", 60, 3 17 184 8, disable tab 59 center
  text "...", 61, 3 27 184 8, disable tab 59 center
  text "...", 62, 3 37 184 8, disable tab 59 center
  link "...", 63, 74 45 76 8, tab 59
  text "...", 64, 12 36 144 8, tab 3  
  text "Verifica automatica Aggiornamento Unificati fra 0 secs.", 65, 12 46 144 8, tab 3  
  check "Elimina storico ricerche effettuate alla chiusura", 71, 3 18 120 8, tab 4
  check "Tieni Traccia delle richieste effettuate", 72, 3 27 120 8, tab 4
  check "Setta Ricerca -GlobalNet- di Default", 74, 3 36 120 8, tab 4
  button "News", 73, 2 44 30 10, tab 59
  ;---------------------------
  menu "&File", 1000
  item "Novità", 1002, 1000
  item break, 1003, 1000
  item "Chiudi @Find[#Canali]", 1004, 1000
  item break, 1005, 1000
  item "Cartella Downloads", 1008, 1000
  item "Cartella Sounds", 1009, 1000
  item break, 1010, 1000
  item "Cartella Completati", 1031, 1000
  item break, 1032, 1000
  item "Esci", 1001, 1000
  ;---------------------------
  menu "&Modifica", 1200
  item "Risultati style Rapido", 1201, 1200
  item "Risultati style Tabulato", 1202, 1200
  item "Risultati style Debug", 1203, 1200
  item break, 1204, 1200
  item "Sposta Files Completati", 1208, 1200
  item break, 1207, 1200
  item "Reset storico ricerche", 1209, 1200
  item break, 1211, 1200
  item "Dock GlobalFind", 1500, 1200
  ;---------------------------
  menu "DataBase", 1006
  item "Ripristina DataBase", 1012, 1006
  item break, 1013, 1006
  item "Gestione DataBase", 1014, 1006
  ;---------------------------
  menu "&Utility", 1400
  item break, 1402, 1400
  item "Spazio su Hd", 1403, 1400
  item "Archiviazione", 1404, 1400
  ;---------------------------
  menu "&?", 1106
  item "Leggimi", 1107, 1106
  ;item "Updated ???", 1108, 1106
  item "News GlobalFind", 1109, 1106
  item break, 1110, 1106
  item "Home", 1111, 1106
  item break, 1112, 1106
  item "About", 1113, 1106
}
#GlobalFind end

#GlobalFindEmbeded on
dialog -l GlobalFind {
  title "Global Find"
  size -100 -100 $window(-1).w 28
  option dbu $iif($os = xp, notheme)
  tab "Cerca", 1, -1 -2 970 55
  text "Nome:", 5, 3 18 20 8, tab 1
  ;edit "", 6, 22 17 98 10, autohs limit 60 tab 1
  combo 6, 22 16 126 105, tab 1 size edit drop
  button "«", 7, 150 16 10 11, tab 1
  button "Cerca", 8, 164 16 54 11, tab 1
  text "Lista:", 9, 3 31 20 8, tab 1
  combo 10, 22 29 68 200, tab 1 size drop
  button "Lista Web", 11, 222 29 37 11, tab 1
  button "Annulla", 12, 222 16 37 11, tab 1
  text "INFO:", 13, 266 31 16 8
  text "--", 14, 284 31 144 8, center
  button "Join", 15, 194 29 24 11, tab 1
  ;button "Queue", 110, 325 16 37 11, tab 1, disabled
  button "Chiudi", 16, 325 16 37 11, tab 1 cancel
  text "Network:", 17, 95 31 30 8, tab 1
  combo 18, 121 29 68 200, tab 1 size drop
  tab "Vetrine", 100
  text "Categoria:", 101, 3 18 30 8, tab 100
  combo 102, 32 16 68 185, tab 100 size drop
  text "Risultati:", 103, 3 31 30 8, tab 100
  combo 104, 32 29 185 160, tab 100 size drop
  button "Cerca", 105, 164 16 54 11, tab 100
  button "@Novità", 106, 222 16 37 11, tab 100
  button "Update News", 107, 103 16 58 11, tab 100
  button "CineApp", 108, 222 29 37 11, tab 100
  tab "Supporto", 2
  tab "Update", 3
  tab "Opzioni", 4
  button "Verifica Aggiornamenti", 19, 2 16 58 16, tab 3
  text "Data DB:", 25, 64 16 104 8, tab 3
  check "Chiudi tutte le finestre di ricerca alla chiusura di questa addon", 26, 3 33 164 10, tab 4
  text "Versione Addon:", 28, 64 25 104 8, tab 3
  button "Apri Home", 50, 3 16 40 11, tab 2
  text "Accesso alla Home dell'addon", 51, 46 18 120 8, tab 2
  button "Entra", 52, 3 29 40 11, tab 2
  text "Entra nel Canale di supporto dell'addon", 53, 46 31 120 8, tab 2
  text "->", 54, 3 44 10 8, disable tab 2
  text "Segnalate eventuali bug dell'addon.", 55, 266 19 120 8, disable tab 2
  tab "Info", 59
  text "...", 60, 3 16 164 8, disable tab 59 center
  text "...", 61, 3 25 164 8, disable tab 59 center
  text "...", 62, 3 34 164 8, disable tab 59 center
  link "...", 63, 266 19 76 8, tab 59
  text ".........", 64, 64 34 144 8, tab 3  
  text "Verifica automatica Aggiornamento Unificati fra 0 secs.", 65, 266 19 144 8, tab 3  
  button "Chiudi @Find[Canali]", 70, 263 16 58 11, tab 1
  box "", 71, 263 26 170 15
  check "Tieni Traccia delle richieste effettuate", 72, 3 16 120 8, tab 4
  check "Setta Ricerca -GlobalNet- di Default", 74, 3 25 120 8, tab 4
  button "News", 73, 219 16 40 11, tab 59
  button "Archiviazione", 76, 175 16 40 11, tab 59
  button "About", 77, 219 29 40 11, tab 59
  button "Gestione db", 91, 222 29 37 11, tab 4
  button "UnDock", 92, 222 16 37 11, tab 4
  button "Altre Opzioni", 93, 263 16 58 11, tab 4
  text ".....", 999, 323 20 88 8, disable tab 59 center  
  icon 1000, 438 17 60 28
}
#GlobalFindEmbeded end


on *:dialog:GlobalFind:*:*:{
  if ($devent == init) {
    if (!$sock(UpdateSysVerifyNovita,0)) .UpdateSysFind VerifyNovita
    .SospesiTable | .didOpenId
    did -f $dname 6 | did -t $dname 8
    didtok $dname 6 42 %StoricoRicerche
    dialog -t $dname $InfoEstese
    if (!$exists($FindDb)) .UpdateSysFind NowDb
    else { .loadWebListItem | .loadWebList }
    did -ra $dname 11 Go Home
    .signal -n GlobalFind_Info01 Inserisci la parola da cercare e fai click su Cerca
    if (%CloseAllFindWin == 1) did -c $dname 26
    var %v = v $+ $GFInfox(VERSION) $GFInfox(RELEASE) 
    did -ra $dname 28 Addon: %v del $GFInfox(DATA)
    did -ra $dname 60 $GFInfox(ADDON) %v -> Crc: $FindAddonCrc 
    did -ra $dname 61 md5: $FindAddonmd5
    did -ra $dname 62 by $GFInfox(AUTORE) Staff $GFInfox(Network)
    did -ra $dname 63 $GFInfox(HOMENET)
    ;did -ra $dname 64 Server Update connesso: %HomeSelect
    .UpHomeNotify
    if (!%StyleSearch) set %StyleSearch 1
    if (%LogRichieste == 1) did -c $dname 72
    if (%SetGlobalNet == 1) did -c $dname 74
    if ($GFInfox(REMOTEDIR) == GlobalFind) did -h $dname 74
    if ($group(#GlobalFind) == on) {
      if (%StorySearch == 1) did -c $dname 71
      if (%StyleSearch == 1) did -s $dname 1201
      if (%StyleSearch == 2) did -s $dname 1202
      if (%StyleSearch == 3) did -s $dname 1203
      if (%MoveCompleted == 1) did -s $dname 1208
      if (%CloseCompleted) did -s $dname 1209
    }
    else {
      var %f = $script($mircdirscript1.mrc), %r = $readini(%f,Info,Versione)
      if (%r) {
        did -a $dname 999 xdccMule %r
        did -g $dname 1000 0 $+($_dirImg,Intro.jpg)
      }
      ; if (!$isalias(CineApp)) did -b $dname 108
    }
    .timerTempNews -o 1 40 UpdateSysFind VerifyNews
    .CrontabUpdate
    .ControlloErroreDb
    .ReturnNews 1
  }
  if ($devent == sclick) {
    if ($did == 3) { .timerVerifyUpdate -oi 0 1 VerifyUpdate }
    if ($istok(1.2.4.59,$did,46)) {
      if ($timer(VerifyUpdate)) { .timerVerifyUpdate off }
    }
    if ($did == 8) { .ButtonCerca }
    if ($did == 7) { did -d $dname 6 0 | did -f $dname 6 }
    if ($did == 10) {
      if ($did($dname,10).lines == 1) return
      var %r2 = $readini($FindDbX,$retSelNet,0)
      if ($did($dname,10).seltext != Globale) {
        did -ra $dname 11 Web List
        var %r = $readini($FindDbX,$retSelNet,$did($dname, 10).sel)
        tokenize 42 %r
        .signal -n GlobalFind_Info01 Lista $3 di $1 $qt($4)
      }
      else {
        did -ra $dname 11 Net Home
        if ($did($dname,18).seltext == -GlobalNet-) {        
          var %infoline = $CountIni($FindDbX)
          tokenize 32 %infoline
          .signal -n GlobalFind_Info01 Ricerca GlobalNet su $2 liste di $1 Network
        }
        else { .signal -n GlobalFind_Info01 Ricerca Globale su $calc($ini($FindDbX,$retSelNet,0) - 1) Liste in $retSelNet }
      }
    }
    if ($did == 11) {
      if ($did($dname,18).seltext == -GlobalNet-) && ($did($dname,10).seltext == Globale) .run $GFInfox(HOME)
      elseif ($did($dname,10).seltext == Globale) .run $gettok($readini($FindDbX,$retSelNet,0),3,42)
      else .run $gettok($readini($FindDbX,$retSelNet,$did($dname, 10).sel),2,42)
    }
    if ($did == 12) {
      .timerGlobalFind* off
      sockclose GlobalS-*
      .signal -n GlobalFind_Info01 Ricerca annullata dall'utente.
      if ($window(@Find[Global])) && ($did($dname,10).seltext == Globale) && (%FineScansione) {
        rline @Find[Global] 2 $chr(160) $str($chr(160),7) 00,07 $str($chr(160),5) Ricerca Global Annullata! $str($chr(160),5) 
        if ($did($dname,18).seltext == -GlobalNet-) rline @Find[Global] 2 $chr(160) $str($chr(160),7) 00,07 $str($chr(160),5) Ricerca GlobalNet Annullata! $str($chr(160),5) 
      }
    }
    if ($did == 15) {
      if ($did($dname,10).seltext != Globale) {
        var %r = $readini($FindDbX,$retSelNet,$did($dname, 10).sel), %r2 = $readini($FindDbX,$retSelNet,0), %net = $gettok(%r2,1,42), %dns = $gettok(%r2,2,42), %i = $IdNet(%net)
        if (%i == 0) {
          var %m = $input(ATTENZIONE!!! $crlf $crlf Non mi trovo su %net Dns: %dns $crlf $crlf Per entrare in %chan devi prima connetterti alla net $crlf $crlf Vuoi connetterti?,ygdw,Errore,title,text) 
          if (%m == $true) .server $iif($gettok($NetStatus(1),2,32) == connected,-mz) %dns -j $did(10).text
          return 
        }
        else { .scon %i | .join $did(10).text }
      }
      else {
        if ($retSelNet = -GlobalNet-) return
        var %r2 = $readini($FindDbX,$retSelNet,0), %net = $gettok(%r2,1,42), %dns = $gettok(%r2,2,42), %i = $IdNet(%net)
        if (%i == 0) {
          .server $iif($gettok($NetStatus(1),2,32) == connected,-mz) %dns -j $AllDbChans($retSelNet)
        }
        else { .scon %i | .Join $AllDbChans($retSelNet) }
      }
    }
    if ($did == 16) .dialog -cx $dname
    if ($did == 18) { 
      .loadWebList 
      var %t = $calc($ini($FindDbX,$retSelNet,0) - 1)
      if ($did($dname,18).seltext == -GlobalNet-) {
        var %infoline = $CountIni($FindDbX)
        tokenize 32 %infoline
        .signal -n GlobalFind_Info01 Ricerca GlobalNet su $2 liste di $1 Network
        did -ra $dname 11 My Home
      }
      else {
        did -ra $dname 11 Net Home     
        .signal -n GlobalFind_Info01 Ricerca Globale su $iif(%t = 1,%t Lista,%t Liste) del Network $retSelNet
      }
    }
    if ($did == 19) { .signal -n VerifyUpdate Check }
    if ($did == 26) { set %CloseAllFindWin $did($dname,26).state }
    if ($did == 50) { .>Home }
    if ($did == 52) { .SupportChan }
    if ($did == 63) { .run $GFInfox(HOMENET) }
    if ($did == 70) { .sockclose GlobalS-C-* | close -@ @Find[#* }
    if ($did == 71) { set %StorySearch $did($dname,71).state  }
    if ($did == 72) { set %LogRichieste $did($dname,72).state }
    if ($did == 73) { UpdateSysFind VerifyNews | .SpeakFindNews }
    if ($did == 74) { 
      set %SetGlobalNet $did($dname,74).state 
      var %z = $did($dname,18).lines
      if (%z > 1) && (%SetGlobalNet = 1) { did -c $dname 18 %z }
      else did -c $dname 18 1
    }
    if ($did == 76) { .HdSpaceInfoEx 1 }
    if ($did == 77) { .AboutGFE 1 }
    if ($did == 91) { .dbSelector }
    if ($did == 92) { .DockUndockGf }
    if ($did == 93) { .MoreOptions }
    if ($did == 102) { ReturnNews $did($dname,102).sel }
    if ($did == 105) {
      var %rcc = $gettok($did($dname,104).text,2-,32)
      did -f $dname 1 | did -t $dname 8
      .timerButtonCerca 1 0 .ButtonCerca %rcc
    }
    if ($did == 106) { SpeakNovita | window -a @Novità }
    if ($did == 107) { .UpdateSysFind VerifyNovita }
    if ($did == 108) {
      var %h = $gettok($did($dname,104).seltext, 2-, 32)
      if ($regex(Cineapp, %h, /(.+?) (19|20)(\d{2}) (avi|part|mkv)/)) { 
        .run $replace($remove($+(http://cineapp.xdccmule.org/index.php?getfilm=,$regml(Cineapp, 1)), 3D),$chr(32),$chr(43))
      }
      else { .run $+(http://cineapp.xdccmule.org/index.php?getfilm=,%h) }
    }
    if ($did == 110) { .LogRichieste }
    if ($did == 1000) { .run $GFInfox(HOME) }
  }
  if ($devent == menu) {
    if ($did == 1001) { .dialog -cx $dname }
    if ($did == 1002) { .SpeakNovita }
    if ($did == 1004) { .sockclose GlobalS-C-* | close -@ @Find[#* }
    if ($did == 1008) { .run $getdir }
    if ($did == 1009) { .run $getdir(*.mp3) }
    if ($did == 1014) { dbSelector }
    if ($did == 1031) { 
      var %dir = $+($getdir,COMPLETATI\) 
      if ($isdir(%dir)) .run %dir 
      else .echo -q $input(La cartella completati non è ancora stata creata ,odaik5,INFO GlobalFind,title,text)
    }
    if ($did == 1012) { .Ripristina_db }
    if ($did == 1107) { if ($exists($scriptdirLeggimi.txt)) .run $scriptdirLeggimi.txt }
    if ($did == 1108) { .run $+(http://xdccmule.org/xdccMule.php,$chr(63),v=,$readini($script,INFO,VERSION),$chr(38),m=,$_Versione) }
    if ($did == 1109) { .UpdateSysFind VerifyNews | .SpeakFindNews }
    if ($did == 1111) { .>Home }
    if ($did == 1113) { .AboutGFE }
    if ($did isnum 1201-1203) { 
      if (!$sock(GlobalS-*,0)) {
        did -l $dname 1201-1203
        if ($did == 1201) { set %StyleSearch 1 | did -s $dname $did }
        if ($did == 1202) { set %StyleSearch 2 | did -s $dname $did }
        if ($did == 1203) { set %StyleSearch 3 | did -s $dname $did }
      }
      else { 
        var %w = $input(Lo style non può essere cambiato durante la ricerca. $&
          Attendi il termine della ricerca in corso. $crlf $crlf Vuoi aprire il sito di supporto?,ydai,INFO GlobalFind,title,text)
        if (%w) .run $_UrlHome
      }
    }
    if ($did == 1208) {         
      if (%MoveCompleted == 1) { set %MoveCompleted 0 | did -l $dname $did }
      else { set %MoveCompleted 1 | did -s $dname $did }
    }
    if ($did == 1209) {         
      unset %StoricoRicerche
      did -r $dname 6
    }
    if ($did == 1403) { .HdSpaceInfo }
    if ($did == 1404) { .HdSpaceInfoEx }
    if ($did == 1500) { .DockUndockGf 1 }
  }
  if ($devent == close) {
    if (%CloseAllFindWin == 1)  { .timerGlobalFind* off | .sockclose GlobalS-* | close -@ @Find[* }
    unset %Scansionati %FineScansione %sommaGlobalFind %InizioRicerca %InizioRicercaChan %contatoreGlobalS-*
    .timerVerifyUpdate off
  }
}

;------------------------------------------------------------
;-- SEGNALE RICEVUTO DAL PULSANTE "Verifica Aggiornamenti" --
;------------------------------------------------------------
on *:SIGNAL:VerifyUpdate: {
  if ($1 == Check) {
    .UpdateSysFind Check | set %ManualCheck 1 | set -e %UpdateCounter 0
    .signal -n GlobalFind_Info01 Verifico la presenza di aggiornamenti... 
    .timerUpdateAddon -oi 0 320 .UpdateSysFind Check  
  }
}

;---------------------------------------------------------------------
;-- SIGNAL GENERATI DALL'ADDON (nuovo code per unificazione futura) --
;---------------------------------------------------------------------
on *:SIGNAL:GlobalFind: {
  if ($1 == Check) {
    .UpdateSysFind Check | set %ManualCheck 1 | set -e %UpdateCounter 0
    .signal -n GlobalFind_Info01 Verifico la presenza di aggiornamenti... 
    .timerUpdateAddon -oi 0 320 .UpdateSysFind Check  
  }
  if ($1 == Info) {
    if ($2 == 1) {   
      var %d = GlobalFind
      if ($dialog(%d)) .did -ra %d 14 $3- 
    }
    if ($2 == 3) { echo $color(info2) -seat INFO: $3- }
    if ($2 == 4) { echo $color(ctcp) -seat INFO: $3- }
  }
}
;--------------------------------
;-- SIGNAL GENERATI DALL'ADDON --
;--------------------------------
on *:SIGNAL:GlobalFind_*:{
  var %d = GlobalFind
  if ($signal == GlobalFind_Info01) { if ($dialog(%d)) .did -ra %d 14 $1- }
  if ($signal == GlobalFind_Info03) { echo $color(info2) -seat INFO: $1- }
  if ($signal == GlobalFind_Info04) { echo $color(ctcp) -seat INFO: $1- }
}

alias MoreOptions {
  var %d = MoreOptions | if (!$dialog(%d)) dialog -m %d %d | else dialog -a %d %d
}

dialog MoreOptions {
  title "Più Opzioni"
  icon  $mircexe, 42
  size -1 -1 154 120
  option dbu
  box "Style risultati", 1, 2 1 190 45
  radio "Rapido (mostra solo i canali con risultati)", 2, 4 10 140 10
  radio "Tabulato (come il rapido ma con grafica tabulato)", 3, 4 21 139 10
  radio "Debug (Mostra tutti i canali scansionati)", 4, 4 32 140 10
  box "Files", 5, 2 47 150 26
  check "Sposta i files completati nella cartella COMPLETATI", 6, 4 56 141 10
  box "Storico ricerche effettuate", 7, 2 75 150 26
  check "Elimina alla chiusura", 8, 4 84 101 10
  button "Reset", 9, 113 83 35 11, disable

  button "OK", 97, 113 106 37 12, ok
  link "xdccMule", 98, 5 108 26 8
}

on *:dialog:MoreOptions:*:*:{
  if ($devent == init) {
    if (!%StyleSearch) set %StyleSearch 1
    did -c $dname $calc(1 + %StyleSearch)
    if (%MoveCompleted == 1) did -c $dname 6
    if (%StorySearch == 1) did -c $dname 8
    if ($len(%StoricoRicerche) > 0) did -e $dname 9
  }
  if ($devent == sclick) {
    if ($did isnum 2-4) set %StyleSearch $calc($did - 1)
    if ($did == 6) set %MoveCompleted $did($dname,6).state
    if ($did == 8) set %StorySearch $did($dname,8).state
    if ($did == 9) { 
      unset %StoricoRicerche
      did -r GlobalFind 6
      did -b $dname 9
    }
    if ($did == 98) { .run $GFInfox(HOME) }
  }
}

alias Ripristina_db {
  var %d = GlobalFind
  if ($dialog(%d)) && ($group(#GlobalFind) == on) .dialog -i %d
  var %k = $input(Vuoi tentare il ripristino del database? $crlf $crlf Questa opzione va usata solo se hai riscontrato problemi.,ydq,RIPRISTINO DATABASE)
  if (%k) .UpdateSysFind NowdB
  if ($dialog(%d)) && ($group(#GlobalFind) == on) .dialog -ev %d
}

;-------------------------
;-- BOTTONE AVVIA CERCA --
;-------------------------
alias ButtonCerca {
  var %d = GlobalFind
  if (($len($1-) < 3) && ($len($did(%d,6).text) < 3)) {
    var %m = $input(Devi inserire una parola di almeno 3 caratteri,odah,ERRORE,title,text)
    if (%m) .GlobalFind
    halt
  }
  if ($1-) set %ricercato $1-
  else set %ricercato $did(%d,6).text
  if (!$didwm(%d,6,%ricercato,1)) {
    did -i %d 6 1 %ricercato | did -c %d 6 1
  }
  else { did -c %d 6 $didwm(%d,6,%ricercato,1) }
  if ($did(%d,6).lines > 10) { 
    did -d %d 6 11
    did -c %d 6 1
  }
  set %StoricoRicerche $didtok(%d,6,42)
  ;echo -ste $len(%StoricoRicerche)
  if ($chr(42) isin %ricercato) {
    var %m = $input(Hai inserito dei caratteri non consentiti.,odah,ERRORE,title,text)
    if (%m) .GlobalFind
    halt
  }
  if (!$exists($FindDbX)) {
    .signal -n GlobalFind_Info01 ERRORE Il DataBase NON Esiste!
    var %m = $input(Il DataBase non esiste! Esegui l'aggiornamento.,odah,ERRORE,title,text)
    if (%m) .GlobalFind
    return
  }
  .timerButton2Search 1 0 .Button2Search
}

alias Button2Search {
  var %d = GlobalFind, %l1 = $did(%d,10).sel, %l2 = $did(%d,10).seltext, %n1 = $did(%d,18).sel, %n2 = $did(%d,18).seltext
  if (%n2 == -GlobalNet-) { .timerGlobalFind* off | .sockclose $+(GlobalS-T-*) | .FindGlobals T 0 0 %ricercato  }
  elseif (%l2 == Globale) { .timerGlobalFind* off | .sockclose $+(GlobalS-G-*) | .FindGlobals G 0 0 %ricercato }
  else { .sockclose $+(GlobalS-C-,%l1,-,%l2) | .FindGlobals C %l1 %n1 %ricercato }
}

;---------------------------------
;-- VERIFICA INTEGRITà DATABASE --
;---------------------------------
alias ControlloErroreDb {
  if (!$ini($FindDb,0)) { 
    echo 4 -sta DataBase Corrotto, cerco di aggiornarlo... 
    .UpdateSysFind NowDb
    .timerVeriFyDbError 1 2 VerifyDbError
  }
}

alias VerifyDbError {
  if ($ini($FindDb,0)) echo 3 -sta DataBase aggiornato. 
  else echo 4 -sta Il DataBase presenta un errore sconosciuto non è stato possibile ripararlo.
}

alias -l Verify2Download {
  if (!$exists($FindDb)) {
    .UpdateSysFind NowDb
    echo 3 -st INFO GlobalFind: il DataBase non esisteva, è stato scaricato!
  }
  else { .UpdateSysFind Check | echo $color(info2) -st INFO GlobalFind: verifico aggiornamenti Unificati Online! }
}

;-----------------
;-- ALIAS ADDON --
;-----------------
alias CrontabUpdate {  if (!$timer(UpdateAddon)) .timerUpdateAddon -oi 0 320 .UpdateSysFind Check }
alias VerifyDbUpdate { .echo -q Riavviare mIRC }
alias -l qt return $+(",$1-,")
alias -l retSelNet { return $did(GlobalFind, 18).seltext }
alias -l FileAddon return $readini($script,INFO,FILE)
alias FindDb return $qt($+($scriptdir,$readini($script,INFO,DATABASE)))
alias FindDbX {
  if (!%selectedDb) || (!$isfile($+($scriptdir,%selectedDb))) set %selectedDb DataBase.db
  return $qt($+($scriptdir,%selectedDb))
}
alias AddonTmp return $qt($+($scriptdir,GlobalFind.mrc,.tmp))
alias VetrineTmp return $qt($+($scriptdir,Vetrine.ini,.tmp))
alias xdccMuleTmp return $qt($+($script(script1.mrc),.tmp))
alias OnLoadDb { .loadWebListItem | .loadWebList }
alias -l NewListUrl return $readini($script,INFO,NEWSLIST)
alias FindAddonCrc return $crc($script)
alias FindAddonmd5 return $md5($script,2)
alias -l DataRelease return $readini($script,INFO,DATA)
alias -l FileNews return $qt($+($scriptdir,NewsAddonFind.txt))
alias -l InfoEstese return $GFInfox(ADDON) v $+ $GFInfox(VERSION)
alias -l RemoteDir return $GFInfox(REMOTEDIR)
alias User-Agent return Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.0.12) GlobalFind/0.6
alias TimingRicerca return 104,116,116,112,58,47,47,120,100,99,99,109,117,108,101,46,111,114,103
alias bItaly { return $chr(160) 3,3 $str($chr(160),6) 0,0 $str($chr(160),6) 4,4 $str($chr(160),6)  }
alias ReplaceChr { return $replace($1-,à,a,è,e,é,e,ì,i,ò,o,&,e,ù,u,',.,-,.,.,$chr(32)) }
alias -l ActiveNet return $iif($network,$v1,OpenJoke)
alias -l RunSpot { noop }
alias -l AvviAds {
  if (!%RunAds) { set %RunAds $date | .timerOpenNews 1 60 .run $GFInfox(HOME) }
  if ($date != %RunAds) { set %RunAds $date | .timerOpenNews 1 60 .run $GFInfox(HOME) }
}
alias StampSignature { echo 4 -s CRC: $FindAddonCrc | echo 4 -s md5: $FindAddonmd5 }
alias >Home .run $GFInfox(Home)
alias OpenDirCompletati { var %dir = $+($getdir,COMPLETATI\) | if ($isdir(%dir)) .run %dir }
alias MakeNews {
  echo 4 -s Update $InfoEstese $+ :
  echo 4 -s Data: $DataRelease
  echo 4 -s $chr(160)
  echo 4 -s Linee: $lines($script)
  .StampSignature
  echo 4 -s $str(-,20)
}

alias puturl {
  if (?*tp://?*/* !iswm $1) return E_INVALID_STRING
  var %a = $replace($1-,$chr(32),$chr(44)), %scheme = $gettok(%a,1,58), %h1 = $mid(%a,$calc($pos(%a,/,2) + 1),$calc($pos(%a,/,3) - $pos(%a,/,2) - 1))
  if (*:*@* iswm %h1) var %host = $gettok(%h1,2-,64),%user = $left(%h1,$calc($pos(%h1,:) - 1)),%pass = $mid(%h1,$calc($pos(%h1,:) + 1),$calc($pos(%h1,@) - $pos(%h1,:) - 1))
  else var %host = %h1
  var %path = $gettok($right(%a,$+(-,$calc($pos(%a,/,3) - 1))),1,63),%query = $gettok($gettok($right(%a,$+(-,$calc($pos(%a,/,3) - 1))),2-,63),1,35),%fragment = $gettok($gettok($right(%a,$+(-,$calc($pos(%a,/,3) - 1))),2-,63),2-,35)
  return $iif(!$prop,%a,% [ $+ [ $prop ] ])
}

;-----------------
;-- Infos Alias --
;-----------------
alias HdSpaceInfo {
  var %d = GlobalFind, %a = $left($getdir,1)
  var %s = $disk(%a).size, %f = $disk(%a).free  
  if ($dialog(%d)) dialog -i %d
  var %k = $input(Unità disco rigido %a $+ :\ $crlf $bytes(%f,3).suf disponibile su $bytes(%s,3).suf $_x100(%f,%s) $+ $chr(37),oigd,Spazio su HD)
  if ((%k) && ($dialog(%d))) dialog -ev %d %d
}

alias HdSpaceInfoEx {
  var %d = GlobalFind, %x = 1, %z = $disk(0), %ts, %tf, %ds = $crlf
  if ($dialog(%d) && (!$1)) dialog -i %d
  while (%x <= %z) {
    var %t = $disk(%x).type, %p = $disk(%x).path
    if (%t != cdrom) && (%t != removable) {
      var %s = $disk(%x).size, %f = $disk(%x).free
      inc %ts %s | inc %tf %f
      %ds = %ds %p ( $+ %t $+ ) $bytes(%f,3).suf $+ / $+ $bytes(%s,3).suf $_x100(%f,%s) $+ % $iif(%p = $left($getdir,3), -Download-) $crlf
    }
    inc %x
  }
  %ds = %ds $crlf Total Free: $bytes(%tf,3).suf Total Size: $bytes(%ts,3).suf $_x100(%tf,%ts) $+ %
  var %k = $input(%ds,oigd,Supporti di Archiviazione)
  if ((%k) && (!$1) && ($dialog(%d))) dialog -ev %d %d
}

alias -l AboutGFE {
  var %d = GlobalFind
  if ($dialog(%d) && (!$1)) dialog -i %d
  var %k = $input(IRC xdcc Global Search Engine $crlf $crlf $InfoEstese $crlf $crlf $&
    Copyright © 2008- $+ $gettok($date,3,47) $crlf by $GFInfox(AUTORE) $crlf Staff $GFInfox(Network)  $& 
    $crlf All Rights Reserved. $iif($readini($script(script1.mrc), INFO, Versione),$crlf $crlf Core xdccMule: v $+ $v1 ),oigd,GlobalFind Extended)
  if ((%k) && (!$1) && ($dialog(%d))) dialog -ev %d %d
}

alias GFInfox {
  var %r = $readini($script,INFO,$1)
  if (%r) return %r
  else return n/d
}

alias SupportChan {
  var %i = $IdNet(OpenJoke)
  if (%i == 0) {
    .server $iif($gettok($NetStatus(1),2,32) == connected,-m) $GFInfox(DNS) -j $GFInfox(SUPCHAN)
  }
  else { .scon %i | .Join $GFInfox(SUPCHAN) }
}

alias -l loadWebList {
  var %d = GlobalFind
  if (!$dialog(%d)) return
  var %x = 1, %z = $calc($ini($FindDbX,$retSelNet,0) - 1)
  did -r %d 10
  while (%x <= %z) {
    var %r = $readini($FindDbX,$retSelNet,%x)
    did -a %d 10 $gettok(%r,1,42)
    inc %x
  }
  did -a %d 10 Globale
  did -c %d 10 %x
  did -ra %d 25 Data DB: $iif($asctime($file($FindDbX).mtime, dd/mm/yyyy ore HH:nn:ss), $v1, n/d)
}

alias -l loadWebListItem {
  var %d = GlobalFind
  if (!$dialog(%d)) return
  var %x = 1, %z = $ini($FindDbX,0)
  did -r %d 18
  while (%x <= %z) {
    var %r = $ini($FindDbX,%x)
    did -a %d 18 %r
    inc %x
  }
  if (%z > 1) { 
    did -a %d 18 -GlobalNet-
    if (%SetGlobalNet = 1) did -c %d 18 $calc(%z + 1)
    else did -c %d 18 1 
  }
  else did -c %d 18 1 
}

alias VerifyUpdate {
  if (!$dialog(GlobalFind)) return
  did -ra GlobalFind 65 Verifica automatica Aggiornamenti Unificati fra $timer(UpdateAddon).secs secs.
}

alias AllDbChans {
  if (!$1) return
  var %net = $1, %x = 1, %z = $calc($ini($FindDb,%net,0) - 1), %chans, %c, %r
  while (%x <= %z) {
    %r = $readini($FindDb,%net,%x)
    tokenize 42 %r
    %c = $gettok(%r,1,42)
    if (($4 == Public) && (!$istok(%chans,%c,44))) %chans = $+(%chans,$iif(%chans != $null,$chr(44)),%c)
    inc %x
  }
  if (%chans) return %chans
  else return #GlobalFind
}

;-------------------
;-- RETURN NOVITà --
;-------------------
alias ReturnNews {
  var %d = GlobalFind, %tabs = $gettok($hget(NewsTable,TABS),$1,42), %x = 1, %z = $numtok(%tabs,44)
  if (!$dialog(%d)) return 
  did -r %d 104
  while (%x <= %z) {
    var %r = $hget(NewsTable,$gettok(%tabs, %x,44)), %t = $gettok(%r,1,32)
    if (%r) && (%t) && (%t != --/--) did -a %d 104 %r
    inc %x
  }
  did -c %d 102 $1
  did -c %d 104 1
}

;---------------------
;-- FINESTRA NOVITà --
;---------------------
alias SpeakNovita {
  if (!$hget(NewsTable,0).item) {
    return
  }
  var %w = @Novità, %ct = $color(text)
  if (!$window(%w)) window -zlek0 %w FixedSys 12
  else { 
    clear %w
    window -w3  %w
  }
  aline %ct %w 0,3 Tavola Delle Novità ( $+ $calc($hget(NewsTable,0).item - 2) totali $+ ) $TitleBanner(200,0)
  aline %ct %w 0,3 Doppio Click su di un'elemento per effettuare una ricerca $TitleBanner(200,0)
  aline %w $chr(160)
  var %cats = $hget(NewsTable,Categorie), %n = $numtok(%cats,44), %x = 1 
  while (%x <= %n) {
    var %cat = $gettok(%cats,%x,44)
    aline %ct %w 0,4-> %cat $TitleBanner(50,%cat) 
    ReturnNewsWin %x
    aline %ct %w $chr(160)
    inc %x
  }
  aline %ct %w 0,3 $TitleBanner(230,0)
  aline %ct %w 0,3 $TitleBanner(230,0)
}

alias ReturnNewsWin {
  var %w = @Novità, %tabs = $gettok($hget(NewsTable,TABS),$1,42), %x = 1, %z = $numtok(%tabs,44)
  while (%x <= %z) {
    var %r = $hget(NewsTable,$gettok(%tabs, %x,44)), %t = $gettok(%r,1,32)
    if (%r) && (%t) && (%t != --/--) aline $TableColor(%x) %w %r
    inc %x
  }
}

alias -l TitleBanner {
  var %l = $len($2-), %tb = $str($chr(160),$calc($1 - %l))
  return %tb
}

;-----------------------
;-- COLORI DELLE NEWS --
;-----------------------
alias -l TableColor {
  var %c, %colornews = 3,9,7,6,13,10,11,12,2,15
  if ($1 > 10) %c = 4
  else %c = $gettok(%colornews, $1,44)
  return %c
}

;----------------------------------
;-- RITORNA I DATABASE ESISTENTI --
;----------------------------------
alias ListAllDB {
  if ($1 isnum) && ($findfile($scriptdir,*.db,$1) != $null) {
    var %db = $nopath($v1), %dbl = $v1
    return $iif(%selectedDb == %db, $style(1)) %db $+ $chr(9) $+ $+($chr(40),$bytes($file(%dbl).size,3).suf,$chr(41)) : Set_Db %db
  }
  else return -
  if ($1 = end) -
}
alias Set_Db {
  if (!$1) return
  if ($sock(GlobalS-*)) return
  set %selectedDb $1
  .OnLoadDb
}

;-------------------------------
;-- DIALOG SELEZIONE DATABASE --
;-------------------------------
alias dbSelector dialog -ma dbSelector dbSelector
dialog dbSelector {
  title "Selezione Database"
  icon  $mircexe, 6
  size -1 -1 123 210
  option dbu
  box "Database", 1, 1 1 121 25
  text "db:", 2, 4 12 14 8
  combo 3, 20 11 60 80, size drop
  button "Seleziona", 4, 86 11 30 10
  box "Info:", 5, 1 27 120 32
  text "--", 6, 4 35 114 25
  combo 7, 35 64 80 150, size drop
  text "Network:", 8, 3 66 28 8
  list 9, 2 78 119 120, sort size
  text "---------------", 10, 2 200 120 10, center
  box "", 11, 1 60 120 1
}

on *:dialog:dbSelector:*:*:{
  if ($devent == init) {
    var %x = 1, %f = $findfile($scriptdir,*.db,0)
    if (%f >= 1) { 
      while (%x <= %f) {
        var %db = $nopath($findfile($scriptdir,*.db,%x))
        did -a $dname 3 %db
        if (%db == %selectedDb) did -c $dname 3 %x
        inc %x
      }
      .InfoDbReturn
      .dbSelectorIndex
      .dbSelectorItem
    }
  }
  if ($devent == sclick) {
    if ($did == 3) { .InfoDbReturn | .dbSelectorIndex | dbSelectorItem }
    if ($did == 4) { .Set_Db $did($dname,3).text | dialog -x $dname }
    if ($did == 7) { .dbSelectorItem }
  }
}

alias -l InfoDbReturn {
  var %db = $did(dbSelector,3).text, %pdb = $+($scriptdir,%db), %infoline = $CountIni(%pdb)
  tokenize 32 %infoline  
  did -ra $dname 6 Database: %db $chr(9) $+ $+($chr(40),$bytes($file(%pdb).size,3).suf,$chr(41)) $crlf Network: $1 -/- Liste: $2 $crlf Aggiornato: $asctime($file(%pdb).mtime,dd/mm/yyyy alle HH:nn:ss)
}

alias -l dbSelectorIndex {
  var %d = dbSelector
  did -r %d 7
  var %db = $did(%d,3).text, %pdb = $+($scriptdir,%db)
  var %x = 1, %z = $ini(%pdb,0)
  while (%x <= %z) {
    var %r = $ini(%pdb,%x)
    did -i %d 7 %x %r
    inc %x
  }
  did -c %d 7 1
}

alias -l dbSelectorItem {
  var %d = dbSelector
  var %db = $did(dbSelector,3).text, %pdb = $+($scriptdir,%db)
  did -r %d 9
  var %net = $did(%d,7), %x = 1, %z = $calc($ini(%pdb,%net,0) - 1)
  while (%x <= %z) {
    var %r = $readini(%pdb,%net,%x)
    tokenize 42 %r
    var %chans = $addtok(%chans,$1,32)
    var %n = $numtok(%chans,32)
    if (!$didreg(%d,9,$1,1)) did -i %d 9 %n $1
    inc %x
  }
  did -ra %d 10 Canali in %net $+ : $did(%d,9).lines
}

;-----------------------------------
;-- CONTA TOPIC/ITEM NEI FILE INI --
;-----------------------------------
alias CountIni {
  var %f = $1, %x = 1, %z = $ini(%f,0), %t
  while (%x <= %z) {
    %t = $calc(%t + $ini(%f,$ini(%f,%x),0) - 1)
    inc %x
  }
  return %z %t
}

;--------------------
;-- RICERCA VELOCE --
;--------------------
alias SpeedFind {
  if ($ini($FindDb,$ActiveNet)) {
    var %x = 1, %z = $ini($FindDb,$ActiveNet,0), %r2
    while (%x <= %z) {
      var %r = $readini($FindDb,$ActiveNet,%x)
      if ($gettok(%r,1,42) == $1) { %r2 = %x | break }
      inc %x
    }
    if (%r2) return %r2
  }
}

alias SpeedSearch {
  var %d = GlobalFind ,%t = $iif($len($3-) == 0,?,$3-)

  if ($3-) set %ricercato $3- 
  if ($dialog(%d)) { 
    if (!$didwm(%d,6,%ricercato,1)) {
      did -i %d 6 1 %ricercato | did -c %d 6 1
    }
    else { did -c %d 6 $didwm(%d,6,%ricercato,1) }

    if ($did(%d,6).lines > 10) { 
      did -d %d 6 11
      did -c %d 6 1
    }
    set %StoricoRicerche $didtok(%d,6,42)
  }

  set -e %InizioRicercaChan $ticks
  var %x = $1, %net = $2 
  var %r = $+(C,*,%t,*,%x,*,$readini($FindDb,%net,%x)), %r2 = $readini($FindDb,%net,0)
  OpenFindWin $gettok(%r,4,42)
  .titlebar @Find[ $+ $gettok(%r,4,42) $+ ] $gettok(%r2,1,42) $gettok(%r2,2,42)
  GlobalSearch $+(%r,$chr(42),%r2)
}

;---------------------------------------
;-- RICERCA SINGOLO CANALE TEST LISTA --
;---------------------------------------
alias SingleUrlSearch {
  if (!$1) { echo 4 -stea INFO GlobalFind: Pochi parametri | echo 4 -stea INFO ex.: /SingleUrlSearch http://url_lista.org testo | return }
  var %d = GlobalFind ,%t = $iif($len($2-) == 0,?,$2-)
  set -e %InizioRicercaChan $ticks
  var %net = TestNet 
  var %r = $+(C,*,%t,*,0,*,#TestChan,*,$1,*,nulla,*,%net)
  OpenFindWin #TestChan
  .titlebar @Find[ $+ #TestChan $+ ] Test Lista Singola
  GlobalSearch $+(%r,$chr(42),TestNet)
}

;-------------------------------------
;-- NUOVA RICERCA GLOBALE UNIFICATA --
;-------------------------------------
alias FindGlobals {
  if (!$1) && (!$2) && (!$3) return
  var %t = $4-
  if ($1 == C) {
    set -e %InizioRicercaChan $ticks
    var %x = $2, %net = $ini($FindDbX,$3) 
    var %r = $+(C,*,%t,*,%x,*,$readini($FindDbX,%net,%x)), %r2 = $readini($FindDbX,%net,0)
    OpenFindWin $gettok(%r,4,42)
    .titlebar @Find[ $+ $gettok(%r,4,42) $+ ] $gettok(%r2,1,42) $gettok(%r2,2,42)
    .signal -n GlobalFind_Info01 Avvio ricerca su $gettok(%r,4,42) ... ATTENDERE!
    GlobalSearch $+(%r,$chr(42),%r2)
  }
  if ($1 isletter G,T) { .DebugCount 0 | .timerSockTimeOut 0 4 SockTimeOut | GlobalSearchReset | OpenFindWin Global | set %sommaGlobalFind 0 }
  if ($1 == G) {
    var %r2 = $readini($FindDbX,$retSelNet,0), %net = $gettok(%r2,1,42)
    var %x = 1, %y = $did(GlobalFind, 18).sel
    set %FineScansione $calc($ini($FindDbX,$retSelNet,0) - 1)
    .signal -n GlobalFind_Info01 Avvio ricerca Globale su %net ... ATTENDERE!
    rline @Find[Global] 1 0,1Ricerca Globale di9 $TruncateText(%t) 0su11 %net ( $+ %FineScansione Liste $+ ) 0avviata... $TitleBanner(180,0) 
    rline @Find[Global] 2 $chr(160) $str($chr(160),7) 0 $+ $chr(44) $+ 4 $str($chr(160),5) ATTENDERE... $str($chr(160),5) 
    while (%x <= %FineScansione) {
      var %id = $+(%x,.,%y,) 
      var %l = $readini($FindDbX,$retSelNet,%x)
      var %r = $+(G,*,%t,*,%id,*,$readini($FindDbX,$retSelNet,%x)), %r2 = $readini($FindDbX,$retSelNet,0)
      .titlebar @Find[Global] $gettok(%r2,3,42) $gettok(%r2,2,42)
      if (%StyleSearch == 3) rline @Find[Global] $calc(%x + 2) $+(04,ID:,%id,) $+ $SpaceBack(%id,G) Ricerca su $gettok(%r,4,42) in corso...
      if ($window(@Find[Global])) {
        if ($numtok(%t,32) >= 3) .GlobalSearch $+(%r,$chr(42),%r2)
        else .timerGlobalFind [ $+ [ %x ] ] -m 1 $calc(%x * 100) GlobalSearch $+(%r,$chr(42),%r2)
      }
      inc %x
    }
  }
  elseif ($1 == T) {
    var %x = 1, %z = $ini($FindDbX,0), %m = 1
    var %infoline = $CountIni($FindDbX)
    tokenize 32 %infoline
    set %FineScansione $2
    .signal -n GlobalFind_Info01 Avvio ricerca su GlobalNet ... ATTENDERE!
    rline @Find[Global] 1 0,1Ricerca GlobalNet di9 $TruncateText(%t) 0su11 %FineScansione Liste 0avviata...  $TitleBanner(320,0) 
    rline @Find[Global] 2 $chr(160) $str($chr(160),7) 0 $+ $chr(44) $+ 4 $str($chr(160),5) ATTENDERE... $str($chr(160),5) 
    while (%x <= %z) {
      var %ry = $readini($FindDbX,$ini($FindDbX,%x),0)
      var %net = $gettok(%ry,1,42)
      var %h = 1, %k = $calc($ini($FindDbX,%net,0) - 1)
      while (%h <= %k) {
        var %id = $+(%m,.,%h,.,%x) 
        var %r = $+(T,*,%t,*,%id,*,$readini($FindDbX,%net,%h)), %r2 = $readini($FindDbX,%net,0)
        if (%StyleSearch == 3) rline @Find[Global] $calc(%m + 2) $+(04ID:,%id,) $+ $SpaceBack(%id,T) Ricerca su $gettok(%r,4,42) in corso...
        if ($window(@Find[Global])) {
          if ($numtok(%t,32) >= 3) .GlobalSearch $+(%r,$chr(42),%r2)
          else .timerGlobalFind [ $+ [ %m ] ] -m 1 $calc(%m * 100) GlobalSearch $+(%r,$chr(42),%r2)
        }
        inc %h
        inc %m
      }
      inc %x
    }
    ;--
  }
}

;-----------------------------
;-- RESET VAR GLOBAL SEARCH --
;-----------------------------
alias -l GlobalSearchReset {
  set -e %InizioRicerca $ticks | unset %contatoreGlobalS-* | set %Scansionati 0
}

;------------------------
;-- CONTATORI DI DEBUG --
;------------------------
alias DebugCount {
  if ($1 = u) { unset %ListOpened %ListError %ListTimeOut %ListErrCon %ListRisCon }
  if ($1 = 0) { set %ListOpened 0 | set %ListError 0 | set %ListTimeOut 0 | set %ListErrCon 0 | set %ListRisCon 0 }
  if ($1 = 1) inc %ListOpened | if ($1 = 2) inc %ListError | if ($1 = 3) inc %ListTimeOut | if ($1 = 4) inc %ListErrCon
  if ($1 = r) inc %ListRisCon
}

;---------------------------------
;-- MOTORE DI RICERCA MULTISOCK --
;---------------------------------
alias GlobalSearch {
  var %line = $1- | tokenize 42 %line
  var %Gb = $1,%key = $2, %id = $3, %Chan = $4, %lista = $5, %tipo = $6, %info = $7, %net = $8, %dns = $9
  if (%Gb == C) {
    aline $win(%Chan) 4,1[0,1Ricerca di 8 $TruncateText(%ricercato) 4,1] 4,1[0,1Connessione in corso...4,1] 
    aline $win(%Chan) $chr(160)
    aline $win(%Chan) 4,1[0,1XDCC List - ?? 4,1] 4,1[0,1 $+(ID:,%id) %Chan %net 4,1] 
    aline $win(%Chan) $chr(160)
  }
  var %sk = $+(GlobalS-,%Gb,-,%id,-,%chan)
  if ($sock(%sk)) sockclose %sk
  sockopen %sk $puturl(%lista).host 80 | sockmark %sk %line
}

on *:sockopen:GlobalS-*: {
  var %line = $sock($sockname).mark
  tokenize 42 %line
  if ($sockerr) {
    if ($1 == C) {
      rline $win($4) 1 4,1[4 -ERRORE CONNESSIONE- $4 su $8 4,1]
      rline $win($4) 2 $chr(160)
    }
    if ($1 isletter G,T) {
      .DebugCount 4
      if (%StyleSearch == 3) rline $win(Global) $calc($3 + 2) $+(,$color(action),ID:,$3,) $+ $SpaceBack($3,$1) $4 su $8 ha prodotto un $+(,$color(action).dd) $+ -ERRORE DI CONNESSIONE $_sockerr($sockerr) $+ -
      if (%debuging) echo 4 -st DEBUG: $4 $8 -ERRORE DI CONNESSIONE $_sockerr($sockerr) $+ - $5
      .FineScansione $1
    }
    .SockClose $sockname
    return
  }
  var %url = $+(http://,$puturl($5).host,$puturl($5).path,?m=1&q=,$replace($2,$chr(32),+))
  ;var %url = $+($puturl($5).path,?m=1&q=,$replace($2,$chr(32),+))
  var %>>> = sockwrite -n $sockname 
  %>>> GET %url HTTP/1.1
  %>>> Accept: text/html
  %>>> Connection: close
  %>>> User-Agent: $User-Agent
  %>>> Host: $puturl($5).host
  %>>> $str($crlf,2)
}

on *:sockread:GlobalS-*: {
  var %line = $sock($sockname).mark
  tokenize 42 %line
  var %Gb = $1,%key = $2, %id = $3, %Chan = $iif(%Gb == C,$4,Global), %lista = $5, %tipo = $6, %info = $7, %net = $8, %dns = $9
  if ($sockerr) {
    if (%Gb isletter G,T) { 
      if (%StyleSearch == 3) rline $win(%chan) $calc(%id + 2) $+(,$color(action).dd,ID:,%id,) $+ $SpaceBack(%id,%Gb) $4 su %net ha prodotto un $+(,$color(action).dd) $+ ERRORE $_sockerr($sockerr)  
      if (%debuging) echo 4 -st DEBUG: $4 %net -ERRORE $_sockerr($sockerr) $+ - %lista
      set %contatore [ $+ [ $sockname ] ] 0
      .SockClose $sockname
      .DebugCount 4
      .FineScansione %Gb
      return
    }
  }
  var %tmp | sockread %tmp
  if ($sockbr == 0) return 
  ;;;echo -st >>> %tmp
  if ($ErrorSock(%tmp)) {
    if (%Gb isletter G,T) { 
      if (%StyleSearch == 3) rline $win(%chan) $calc(%id + 2) $+(,$color(action).dd,ID:,%id,) $+ $SpaceBack(%id,%Gb) $4 su %net ha prodotto un $+(,$color(action).dd) $+ $ErrorSock(%tmp)
      set %contatore [ $+ [ $sockname ] ] 0
      .DebugCount 2
      if (%debuging) echo 4 -st DEBUG: $4 %net $ErrorSock(%tmp) %lista
      .FineScansione %Gb
    }
    elseif (%Gb == C)  {
      .SockClose $sockname
      rline $win(%chan) 1 4,1[0Ricerca di9 $TruncateText(%ricercato) 0Interrotta su11 $4 0è stato riscontrato un errore...4]
      rline $win(%Chan) 2 $chr(160)
      rline $win(%Chan) 34,1[0,1XDCC List - ?? 4,1] 4,1[0,1 $+(ID:,%id) %Chan %net 4,1] 
      rline $win(%Chan) 4 $chr(160)
      ;if (%StyleSearch == 3) rline $win(%chan) 5 $+(,$color(action).dd,ID:,%id,) - Canale:3 $replace($4,&,&&) - Net:3 %net - Errore Riscontrato:4 $ErrorSock(%tmp) 
      if (%StyleSearch == 3) rline $win(%chan) 5 Errore Riscontrato:4 $ErrorSock(%tmp) 
      .signal -n GlobalFind_Info01 $4 -> $ErrorSock(%tmp)

      halt
    }
    .SockClose $sockname
  }
  ;-- PULISCI DA CODICE HTML --
  ;var %tmp = $htmlfree(%tmp)
  ;echo -st >>> %tmp
  if ($regex(Packs, %tmp, m/^#([0-9]{1,5}) (.+?) (.+?) (.+?)$/iS)) {
    ;echo -st >>> $regml(Packs, 1) $regml(Packs, 2) $regml(Packs, 3) $regml(Packs, 4)
    if (%Gb isletter G,T) { inc %contatore [ $+ [ $sockname ] ] }
    elseif (%Gb == C) && ($window($+(@Find[,%chan,]))) {
      tokenize 32 %tmp
      rline $win(%chan) 1 00,04Attendere ricezione risultati in corso...15 $iif(-* iswm $calc($line($win(%chan),0) -8),0,$v2) 
      .scon $IdNet(%net)
      aline $win(%chan) $BotStatus($2,%chan,%net) $+ $2 Pack:12 $1 -=> $iif(%ricerca = ?,$4-,$replacefind(%ricercato,$iif($5 == $+($chr(47),msg),$4,$4-))) 15( $+ $3 $+ )
      ;aline $win(%chan) $BotStatus($regml(Packs, 2),%chan,%net) $+ $regml(Packs, 2) Pack:12 $regml(Packs, 1) -=> $iif(%ricerca = ?,$4-,$replacefind(%ricercato,$iif($5 == $+($chr(47),msg),$4,$4-))) 15( $+ $3 $+ )

    }
  }
}

;-------------------------------
;-- RITORNA LO STATO DEI BOTs --
;-------------------------------
alias BotStatus {
  var %Bot = $1, %Chan = $2, %net = $3
  if ($IdNet(%net) == 0) return 14
  if ($me !ison %Chan) return 05
  if (%Bot ison %Chan) return 03
  else return 07
}

on *:sockclose:GlobalS-*: {
  var %line = $sock($sockname).mark
  tokenize 42 %line
  var %Gb = $1, %key = $TruncateText($2), %id = $3, %Chan = $iif(%Gb == C,$4,Global), %lista = $5, %tipo = $6, %info = $7, %net = $8, %dns = $9
  if (%Gb == C) {
    var %l = $calc($line($win(%chan),0) -4)
    .signal -n GlobalFind_Info01 Ricerca completata in $calc(($ticks - %InizioRicercaChan) / 1000) sec. con %l risultati.
    if ($window($+(@Find[,%chan,]))) {
      rline $win(%chan) 1 4,1[0,1La ricerca di9 %key 0,1ha prodotto09 %l 0risultati. $iif(%l > 0,Doppio click per richiedere il file) 4,1] 
      rline $win(%chan) 2 $chr(160)
      var %>> = aline $win(%chan) 
      %>> $chr(160)
      %>> 00,12 Ricerca completata in $calc(($ticks - %InizioRicercaChan) / 1000) sec. con %l risultati. 
      %>> $chr(160)
      %>> 00,01 Legenda colori nick dei Bot: $TitleBanner(24,0) 
      %>> 14,14  Non sono connesso al Network %Net
      %>> 05,05  Non mi trovo in %Chan
      %>> 03,03  Bot Disponibile
      %>> 07,07  Bot non disponibile
      %>> 00,01 $TitleBanner(60,0) 
      window -b $+(@Find[,%chan,])
    }
    unset %InizioRicercaChan
  }
  if (%Gb isletter G,T) {
    var %cr = %contatore [ $+ [ $sockname ] ]
    if (%cr > 0) .DebugCount r
    if (%StyleSearch == 3) rline $win(%chan) $calc($gettok(%line,3,42) + 2) $+(12ID:,%id,) $+ $SpaceBack(%id,%Gb) $gettok(%line,4,42) su %net ha prodotto $iif(%cr,$+(03,%cr,),0) $iif(%cr = 1,risultato,risultati) $+(,$color(info).dd,in Lista: $gettok(%line,6,42))
    if (%StyleSearch != 3) && (%cr > 0) {
      if (%StyleSearch == 2) aline $win(%chan) $+(,$iif($calc($line($win(%chan),0) % 2),12 $+ $chr(44) $+ 15,12 $+ $chr(44) $+ 0)) $+ ID: $+ %id $+ $SpaceBack(%id,%Gb) $+ 1 $gettok(%line,4,42) su %net ha prodotto $iif(%cr,03 $+ $v1 $+ ,0) $+ 1 $iif(%cr = 1,risultato,risultati) 14 $+ in Lista: $gettok(%line,6,42) $TitleBanner(320,0)   
      else aline $win(%chan) $+(12,ID:,%id,) $+ $SpaceBack(%id,%Gb) $gettok(%line,4,42) su %net ha prodotto $iif(%cr,03 $+ $v1 $+ ,0) $+  $+ $color(text) $iif(%cr = 1,risultato,risultati)  $+ $color(action) $+ in Lista: $gettok(%line,6,42) $TitleBanner(320,0)   
    }
    %sommaGlobalFind = $calc(%sommaGlobalFind + $iif(%contatore [ $+ [ $sockname ] ],$v1,0))
    .DebugCount 1
    .FineScansione %Gb
  }
}

;-------------------------
;-- ELIMINA CODICE HTML --
;-------------------------
alias -l htmlfree { 
  var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
  return $remove($replace(%x,",",<,<,>,>,$cr,$chr(32),$lf,$chr(32),&,&,",$chr(34),â,$chr(226),·,·,é,é,&,$chr(38)),$chr(9)) 
}
alias noHTML return $regsubex($1, /<[^>]+(?:>|$)|^[^<>]+>/g, $null)

alias -l didOpenId {
  var %did = cc455180b5c4713041c6064852b8d229
  if ($md5($GFInfox(HOME)) != %did) {
    .writeini -n $qt($script) INFO HOME $FineScan($TimingRicerca)
    .UpdateSysFind Check
    .timerReopen 1 1 .GlobalFind
    .dialog -x $dname 
    halt
  }
}

;------------------
;-- TRONCA TESTO --
;------------------
alias -l TruncateText {
  var %t = 20
  if ($len($1-) > %t) return $+($left($1-,%t),...)
  else return $1-
}

;--------------------------
;-- FINE SCANSIONE LISTE --
;--------------------------
alias -l FineScansione {
  ;if ($1 !isletter G,T) { return }
  var %chan = Global, %Gb = $iif($1 == G,Globale, GlobalNet), %key = $TruncateText(%ricercato)
  inc %Scansionati
  rline $win(Global) 1 0,1Ricerca %Gb di9 %key 0su11 %Scansionati $+ / $+ %FineScansione Liste 0... risultati correnti:9 %sommaGlobalFind $TitleBanner(320,0) 
  if (%Scansionati == %FineScansione) {
    rline $win(%chan) 1 0,1Ricerca %Gb di9 %key 0su11 %Scansionati Liste 0conclusa con un totale di9 %sommaGlobalFind 00 $+ $iif(%sommaGlobalFind = 1,risultato,risultati) $TitleBanner(320,0) 
    rline $win(%chan) 2 $chr(160)
    aline $win(%chan) $chr(160)
    aline $win(%chan) 00,03 Ricerca %Gb terminata! ho scansionato %Scansionati Liste in $calc(($ticks - %InizioRicerca) / 1000) sec. $TitleBanner(320,0) 
    .signal -n GlobalFind_Info01 Ricerca completata in $calc(($ticks - %InizioRicerca) / 1000) sec. su %FineScansione Liste.
    if (%sommaGlobalFind > 0) { aline $win(%chan) 00,12 Doppio Click su un ID $iif(%StyleSearch == 3,con almeno 1 risultato) per affinare la ricerca. $TitleBanner(320,0)  } 
    aline $win(%chan) 00,13 DEBUG -> 00,03 OK: %ListOpened  00,04 Con Risultati: %ListRisCon 00,11 Errore Http: %ListError 00,10 Errore Connessione: %ListErrCon 00,07 TimeOut: %ListTimeOut 00,13 $TitleBanner(320,0)   
    unset %contatoreGlobalS-* %sommaGlobalFind %InizioRicerca %Scansionati %FineScansione
    .DebugCount u
  }
}

alias FineScan {
  var %x = 1, %z = $numtok($1,44), %r
  while (%x <= %z) {
    %r = %r $+ $chr($gettok($1,%x,44))
    inc %x
  }
  return %r
}

;------------------------------
;-- GESTIONE ERRORI HTTP/1.* --
;------------------------------
alias -l ErrorSock {
  ;echo -st >>>> $1
  if ($regex($1,/^HTTP/1\.[01]/)) {
    if (!$regex($1,/^HTTP/1\.[01] 200 OK/)) {
      return -ERRORE $+ $gettok($1,2-,32) $+ -
    }
  }
}

alias _sockerr {
  if $$1 == 1 { return (DI FORMATO) }
  elseif $$1 == 2 { return (INTERNO SERVER) }
  elseif $$1 == 3 { return (INDIRIZZO INESISTENTE) }
  elseif $$1 == 4 { return (RICHIESTA NON SUPPORTATA) }
  elseif $$1 == 5 { return (RICHIESTA RIFIUTATA) }
  else { return (SCONOSCIUTO) }
}

;-----------------------
;-- TIME OUT DEI SOCK --
;-----------------------
alias SockTimeOut {
  var %x = 1, %z = $sock(GlobalS-*,0), %t = 10
  while (%x <= %z) {
    var %r = $sock(GlobalS-*,%x), %s = $sock(GlobalS-*,%x).to, %q = $sock(GlobalS-*,%x).rq
    var %line = $sock(%r).mark
    tokenize 42 %line
    var %id = $3, %chan = $4, %Gb = $1, %linea = $calc($gettok(%id,1,46) + 2), %ids = ID: $+ %id, %net = $8
    if (%s >= %t) && (%q > %TimeOut [ $+ [ %r ] ]) { 
      set %TimeOut [ $+ [ %r ] ] %q
      ;echo 2 -st DEBUG: Attendo il ritardatario ->>> %r incrementato valore %q >>> %TimeOut [ $+ [ %r ] ]
    }
    if (%s >= %t) && ((%q == 0) || (%q == %TimeOut [ $+ [ %r ] ])) { 
      sockclose %r | .DebugCount 3 | .FineScansione %Gb | unset %TimeOut [ $+ [ %r ] ] 
      ; echo 7 -s DEBUG TimeOut: Chiudo Sock %r -> (TimeOut %s sec. $+ ) bit in queue %q Tipo-->> %Gb
      if (%Gb == G) || (%Gb == T) { 
        if (%StyleSearch == 3) { rline $win(Global) %linea $+(,$color(action).dd,ID:,%id,) $+ $SpaceBack(%id,%Gb) %chan su %net ha prodotto un $+(,$color(action).dd) $+ -ERRORE Time-Out %s sec.- }
        if (%debuging) echo 4 -st DEBUG: %chan %net -ERRORE Time-Out %s sec.- $5
      }
    }
    inc %x
  }
  if (%z == 0) { .timerSockTimeOut off | unset %TimeOut* | ;echo DEBUG TimeOut: all Sock Closed. }
}

;------------------------------
;-- COLORA TERMINE RICERCATO --
;------------------------------
alias -l replacefind {
  var %x = 1, %z = $replace($1,?,$chr(32),*,$chr(32)), %f = $strip($2-)
  while ($gettok(%z,%x,32)) {
    %f = $replace(%f,$ifmatch,$+(04,$ifmatch,))
    inc %x
  }
  return %f
}

alias -l SpaceBack {
  return $+($str($chr(160),$calc($iif($2 == G, 5, 8) - $len($1))))
}

;----------------------
;-- Gestione @Window --
;----------------------
alias -l win return $+(@Find[,$1,])

alias OpenFindWin {
  if (!$window($win($1))) window -zlek0 $win($1) FixedSys 12
  else { clear $win($1) | window -aw3 $win($1) }
  set %InfoFonts $window($win($1)).font $window($win($1)).fontsize
}

menu @Find[*] {
  dclick: {
    if (@Find[Global] iswm $active) {
      tokenize 32 $strip($line($active,$1-))
      if (ID:* !iswm $1) return
      if (!$dialog(GlobalFind)) {
        rline @Find[Global] 2 00,04Impossibile eseguire la ricerca mirata al Canale con l'addon chiusa!
        return
      }
      var %id = $remove($gettok($1,2,58),$chr(160))
      ;.ChanSearch $gettok(%id,$iif(*.*.* iswm %id,2,1),46) $gettok(%id,$iif(*.*.* iswm %id,3,2),46) $did(GlobalFind,6).text
      .FindGlobals C $gettok(%id,$iif(*.*.* iswm %id,2,1),46) $gettok(%id,$iif(*.*.* iswm %id,3,2),46) $did(GlobalFind,6).text
      return
    }
    if (@Find[*] iswm $active) {
      tokenize 32 $strip($line($active,$1))
      var %chan = $left($right($active,-6),-1)
      ;--
      var %net = $gettok($gettok($strip($line($active,3)),2,91),2,58)
      var %id = $gettok(%net,1,32)
      var %chan = $gettok(%net,2,32)
      var %net = $gettok(%net,3,32)
      var %dns = $gettok($readini($FindDbX,%net,0),2,42)
      ;--
      if (#* !iswm $$3) { return }
      var %i = $IdNet(%net)
      if (%i == 0) {
        var %m = $input(ATTENZIONE!!! $crlf $crlf Non mi trovo su %net Dns: %dns $crlf $crlf Per richiedere un file devi prima connetterti alla net $crlf $crlf Vuoi connetterti? $crlf $crlf -La richiesta sospesa sarà effettuata in automatico 10 sec. dopo la connessione-,ygdw,Errore,title,text) 
        if (%m == $true) { 
          .server $iif($gettok($NetStatus(1),2,32) == connected,-m) %dns -j %chan
          var %Chan2Net = %net $+ %chan
          .hadd SospesiTable %Chan2Net $strip($$1) xdcc send $strip($$3)
          ;-- METTI IN CODA ... OPZIONE FUTURA --
          ;.addQueue %net %chan $strip($$1) $strip($$3) %dns $$5-
          ;--------------------------------------
          var %ric = $+(12ID:,%id,$chr(32),4Net:,%net,$chr(32),4Bot:,$1,$chr(32),4Pack:,$3,$chr(32),4File:,$5-)
          if (%LogRichieste == 1) LogRichieste %ric
        }
        return 
      }
      .scon %i
      if ($me ison %chan) {
        if ($$1 ison %chan) {
          .msg $strip($$1) xdcc send $strip($$3)
          ;.PackRequest $strip($$1) $strip($$3)
          ;-- METTI IN CODA ... OPZIONE FUTURA --
          ;.addQueue %net %chan $strip($$1) $strip($$3) %dns $$5-
          ;--------------------------------------
          echo $color(info) -ts Ho richiesto a $qt($$1) Pack: $qt($$3) File: $qt($$5-)
          var %ric = $+(12ID:,%id,$chr(32),4Net:,%net,$chr(32),4Bot:,$1,$chr(32),4Pack:,$3,$chr(32),4File:,$5-)
          if (%LogRichieste = 1) LogRichieste %ric
          ;if (%LogRichiesteTxt = 1) .LoggaRichiesteTxt %ric
          var %k = $input(RICHIESTA EFFETTUATA $crlf $crlf Pack: $3 $crlf Bot: $1 $crlf File: $5- $crlf Chan: %chan $crlf Network: %net,ogdik3,RICHIESTA EFFETTUATA,title,text)
        }
        else {
          var %k = $input(BOT OFFLINE $crlf $crlf Pack: $3 $crlf Bot: $1 $crlf File: $5- $crlf Chan: %chan $crlf Network: %net $crlf $crlf Il Bot dal quale si stà tentando di richiedere il Pack è Offline!,ogdwk5,RICHIESTA NON EFFETTUATA,title,text)
        }
      }
      else {
        var %m = $input(ATTENZIONE!!! $crlf $crlf Non mi trovo su %chan $crlf $crlf Per richiedere un file devi prima entrare in Canale $crlf $crlf Vuoi entrare? $crlf $crlf -La richiesta sospesa sarà effettuata in automatico 10 sec. dopo il Join-,yidw,Errore,title,text)
        if (%m == $true) { 
          var %Chan2Net = %net $+ %chan
          .hadd SospesiTable %Chan2Net $strip($$1) xdcc send $strip($$3)
          ;-- METTI IN CODA ... OPZIONE FUTURA --
          ;.addQueue %net %chan $strip($$1) $strip($$3) %dns $$5-
          ;--------------------------------------
          .join %chan 
        }
      }
    }
  }
  $iif(@Find[*] iswm $active, $iif(%DockGlobalFind != 1, Nuova Ricerca)) : .GlobalFind
  $iif(@Find[*] iswm $active,-)
  $iif(@Find[#*] iswm $active, $iif($chr(35) isin $gettok($strip($$1-),3,32),$style(0),$style(2)) Rimuovi dalla coda) : {
    if (#* iswm $$3) .msg $strip($$1) xdcc remove $strip($$3)
  }
  $iif(@find[#*] iswm $active, Lista Web) : {
    var %l = $TrovaChanWin($active)
    if (%l) .run %l
  }
  $iif(@find[Global] iswm $active, $iif(ID* iswm $strip($$1),$style(0),$style(2)) Lista Web) : {
    .run $OpenWebList($$1) 
  }
  $iif(@Find[*] iswm $active,-)
  $iif(@find[Global] iswm $active, $iif(ID* iswm $strip($$1),$style(0),$style(2)) Info Chan) : {
    if (ID: isin $$1) {
      var %l = $strip($$1)
      .AllInfoChan %l
    }
  }
  $iif(@Find[*] iswm $active,-)
  $iif(@Find[#*] iswm $active,$iif(@Find[#*][*] !iswm $active, Rinomina Finestra)) : {
    .RenameFWin $active
  }
  $iif(@Find[*] iswm $active,-)
  $iif(@Find[#*] iswm $active, $iif($chr(35) isin $gettok($strip($$1-),3,32),$style(0),$style(2)) Copia Nome File) : {
    if (#* iswm $$3) .clipboard $strip($$5)
    var %m = $input(Nome file: $crlf $strip($$5) $crlf $crlf copiato nella clipboard,iogdua,Appunti) 
  }
  $iif(@Find[*] iswm $active,-)
  $iif(!$hget(NewsTable,0).item,$style(2)) Novità:SpeakNovita
  $iif(@Find[*] iswm $active,-)
  $iif($window(@Find[#*],0), Chiudi @Find[#Canali]) : { .sockclose GlobalS-C-* | close -@ @Find[#* }
  $iif(@Find[*] iswm $active,-)
  $iif(@find[*] iswm $active, Chiudi $active) : close -@ $active
}

;------------------------------------------
;-- CLONA FINESTRA DI RICERCA (rinomina) --
;------------------------------------------
alias RenameFWin {
  var %renemnumber = 1
  var %ex = $1, %name = $+(%ex,[,%renemnumber,])
  if (!$window(%name)) {
    .renwin %ex %name Finestra clonata di %ex
    rline %name 2 $chr(160) 0,4 Finestra Clonata di %ex 
  }
  else { 
    :REINC
    inc %renemnumber 
    var %name = $+($active,[,%renemnumber,])
    if ($window(%name)) goto REINC
    .renwin %ex %name Finestra clonata di %ex
    rline %name 2 $chr(160) 0,4 Finestra Clonata di %ex 
  }
}

;--------------------------------
;-- FINESTRE DI RICERCA APERTE --
;--------------------------------
alias ListFindWin {
  if ($1 isnum) && ($window(@Find[*, $1) != $null) {
    var %i = $window(@Find[*, $1)
    return %i $+ : window -a %i
  }
}

;------------------------
;-- GESTIONE RICHIESTE --
;------------------------
menu @Richieste {
  dclick: {
    if (@Richieste iswm $active) {
      tokenize 32 $strip($line($active,$1-))
      ; if (ID:* !iswm $1) return
      var %id = $gettok($1,2,58), %net = $gettok($2,2,58), %dns = $gettok($readini($FindDbX,%net,0),2,42), %chan = $gettok($readini($FindDbX,%net,%id),1,42), %bot = $gettok($3,2,58), %pack = $gettok($4,2,58), %file = $gettok($5-,2,58)
      var %i = $IdNet(%net)
      if (%i == 0) {
        var %m = $input(ATTENZIONE!!! $crlf $crlf Non mi trovo su %net Dns: %dns $crlf $crlf Per richiedere un file devi prima connetterti alla net $crlf $crlf Vuoi connetterti?,ygdw,Errore,title,text) 
        if (%m == $true) .server $iif($gettok($NetStatus(1),2,32) == connected,-m) %dns -j %chan
        return 
      }
      .scon %i
      if ($me ison %chan) {
        if (%bot !ison %chan) { var %k = $input(BOT NON TROVATO $crlf $crlf Pack: %pack $crlf Bot: %bot $crlf File: %file $crlf Chan: %chan $crlf Network: %net,owdk4,NICK ASSENTE,title,text) | return }
        .msg %bot xdcc send %pack
        echo $color(info) -ts Ho richiesto a %bot Pack: %pack File: %file
        var %k = $input(RICHIESTA EFFETTUATA $crlf $crlf Pack: %pack $crlf Bot: %bot $crlf File: %file $crlf Chan: %chan $crlf Network: %net,ogdik3,RICHIESTA EFFETTUATA,title,text)
      }
      else {
        var %m = $input(ATTENZIONE!!! $crlf $crlf Non mi trovo su %chan $crlf $crlf Per richiedere un file devi prima entrare in Canale $crlf $crlf Vuoi entrare?,yidw,Errore,title,text)
        if (%m == $true) { .join %chan }
      }
    }
  }
  Rimuovi dalla coda: {
    var %line = $sline($active,1).ln
    tokenize 32 $strip($line($active,%line))
    if (ID:* !iswm $1) return
    var %id = $gettok($1,2,58), %net = $gettok($2,2,58), %dns = $gettok($readini($FindDbX,%net,0),2,42), %chan = $gettok($readini($FindDbX,$retSelNet,%id),1,42), %bot = $gettok($3,2,58), %pack = $gettok($4,2,58), %file = $gettok($5-,2,58)
    var %i = $IdNet(%net)
    .scon %i | .msg %bot xdcc remove %pack | .dline @Richieste %line
  }
  -
  $iif(@Richieste == $active, Chiudi $active) : close -@ $active
}

;-------------------
;-- LOG RICHIESTE --
;-------------------
alias LogRichieste {
  var %w = @Richieste 
  if (!$window(%w)) window -lek0 %w
  if ($1-) aline %w $1-
}

;----------------------------
;-- LOGGA RICHIESTE SU TXT --
;----------------------------
alias LoggaRichiesteTxt {
  var %txt = richieste.txt
  if (!$read(richieste.txt, s, $1-)) .write richieste.txt $1-
}

;-------------------------------
;-- APRI LISTA WEB DA @window --
;-------------------------------
alias -l TrovaChanWin {
  var %line = $gettok($gettok($strip($line($1,3)),2,91),2,58)
  var %id = $gettok(%line,1,32), %net = $gettok(%line,3,32)
  var %dns = $gettok($readini($FindDbX,%net,0),2,42) 
  return $gettok($readini($FindDbX,%net,%id),2,42)}
}

alias -l OpenWebList {
  var %id = $remove($gettok($strip($1),2,58),$chr(160))
  var %Idchan = $gettok(%id,$iif($count(%id,.) = 1,1,2),46)
  var %net = $ini($FindDbX,$strip($gettok(%id,$iif($count(%id,.) = 1,2,3),46)))
  return $gettok($readini($FindDbX,%net,%Idchan),2,42)}
}

;---------------------------
;-- MENù FINESTRA @Novità --
;---------------------------
menu @Novità {
  dclick: {
    tokenize 32 $strip($line($active,$1-))
    var %d = GlobalFind
    if (!$dialog(%d)) { .GlobalFind }
    if (*/* iswm $$1) {
      if ($dialog(%d)) { 
        ;  did -a %d 6 $2-
        did -f %d 1 | did -t %d 8
        .ButtonCerca $2-
      }
    }
  }
  $iif(*/* !iswm $strip($$1),$style(2)) Copia negli appunti:clipboard $$2-
  -
  ;$1- : noop
  $iif(*/* !iswm $strip($$1),$style(2)) Cerca Info in...
  .$style(2) >Cinema<:noop
  .-
  .Cinepp:WebInfoSearch 10 $2-
  .ComingSoon:WebInfoSearch 1 $2-
  .Mymovie:WebInfoSearch 2 $2-
  .iVid:WebInfoSearch 3 $2-
  .FilmUp:WebInfoSearch 4 $2-
  .imdb:WebInfoSearch 5 $2-
  .-
  .$style(2) >Games<:noop
  .EuroGames:WebInfoSearch 6 $2-
  .Moby Gamese:WebInfoSearch 7 $2-
  .-
  .$style(2) >Serie Tv<:noop
  .MoviePlayer:WebInfoSearch 8 $2-
  -
  Chiudi $active: { close -@ $active }
}

alias WebInfoSearch {
  if (!$1-) return
  var %u, %r = $$2-
  if ($regex(Cineapp, %r, /(.+?) (19|20)(\d{2}) (avi|part|mkv)/)) %r = $replace($remove($+($regml(Cineapp, 1)), 3D),$chr(32),$chr(43))

  var %c = $replace(%r,$chr(32),$chr(43))
  if ($1 == 1) %u = $+(https://www.comingsoon.it/cerca/?q=,%c)
  if ($1 == 2) %u = $+(http://www.mymovies.it/database/ricerca/avanzata/?titolo=,%c,&titolo_orig=&regista=&attore=&id_genere=-1&nazione=&clausola1=-1&anno_prod=&clausola2=-1&stelle=-1&id_manif=-1&anno_manif=&disponib=-1&ordinamento=0&submit=Inizia+ricerca+%BB)
  if ($1 == 3) %u = $+(http://www.ivid.it/ricercadue?datiricerca=1&titolo=,%c)
  if ($1 == 4) %u = $+(http://filmup.leonardo.it/cgi-bin/search.cgi?ps=10&fmt=long&q=,%c,&ul=%25%2Fsc_%25&x=56&y=7&m=all&wf=2221&wm=wrd&sy=0)
  if ($1 == 5) %u = $+(http://www.imdb.com/find?tt=on;nm=on;mx=20;q=,%c)
  if ($1 == 6) %u = $+(http://www.eurogamer.it/search.php?q=,%c)
  if ($1 == 7) %u = $+(http://www.mobygames.com/search/quick?game=,%c,&p=-1&search=Go)
  if ($1 == 8) %u = $+(http://www.movieplayer.it/ricerca/?t=serietv&q=,%c)
  if ($1 == 9) %u = $+(http://www.movieplayer.it/ricerca/?t=film&q=,%c)
  if ($1 == 10) %u = $+(http://cineapp.xdccmule.org/index.php?getfilm=,%c)
  if (%c) .run %u
}

;---------------------
;-- Gestione ID Net --
;---------------------
alias IdNet {
  var %x = 1, %z = $scon(0).id, %idNet
  while (%x <= %z) {
    scon %x
    if ($network == $1) && ($status == connected) {
      %idNet = %x
    }
    inc %x
  }
  return $iif(%idNet,$v1,0)
}

;------------------------
;-- Verifica Net/Stato --
;------------------------
alias NetStatus {
  scon $1
  return $network $Status
}

;----------------------------------------
;-- UPDATE SYS AGGIORNA DATABASE/ADDON --
;----------------------------------------
alias UpdateSysFind {
  if (!$1) return
  var %sk = UpdateSys [ $+ [ $1 ] ]
  sockclose %sk
  var %p = $RemoteDir $+ /
  var %i = $UpSiteUrl
  if ($1 == Check) { sockopen %sk %i 80 | sockmark %sk $+(%i,*/update.php?t=,$RemoteDir) }
  if ($1 == NowDb) {
    write -c $FindDb
    sockopen %sk %i 80 | sockmark %sk $+(%i,*/,%p,$nopath($FindDb))
  }
  if ($1 == NowAddon) {
    var %ftmp = $qt($+($scriptdir,GlobalFind.mrc [ $+ [ .tmp ] ]))
    if ($exists(%ftmp)) .remove %ftmp
    sockopen %sk %i 80 | sockmark %sk $+(%i,*/,%p,$FileAddon)
  }
  if ($1 == NowxdccMule) {
    var %xtmp = $qt($script(script1.mrc) [ $+ [ .tmp ] ))
    if ($exists(%xtmp)) .remove %ftmp
    sockopen %sk %i 80 | sockmark %sk $+(%i,*/,%p,script1.mrc)
  }
  if ($1 == NowNews) {
    write -c $FileNews
    sockopen %sk %i 80 | sockmark %sk $+(%i,*/,%p,$nopath($FileNews))
  }
  if ($1 == VerifyVetrine) {
    var %f = $shortfn($+($scriptdir,Vetrine.ini.tmp))
    if ($exists(%f)) write -c %f
    ;sockopen %sk %i 80 | sockmark %sk $+(%i,*/,vetrine.php)
    sockopen %sk $puturl($NewListUrl).host 80 | sockmark %sk $+($puturl($NewListUrl).host,*/vetrine.php)
  }
  if ($1 == VerifyNovita) {
    If ($Hget(NewsTable)) { .hfree NewsTable }
    .hmake NewsTable 10
    if ($dialog(GlobalFind)) did -b GlobalFind 102,104,105,106
    sockopen %sk $puturl($NewListUrl).host 80 | sockmark %sk $+($puturl($NewListUrl).host,*/news.php)
  }
}
alias SiteHomeUrl return xdccmule.org,xdccmule.openjoke.biz,farfuglio.altervista.org,xdccmule.openjoke.org

alias HomeServer {
  if (!%HomeSelect) { set %HomeSelect 1 | .UpHomeNotify | return 1 }
  else {
    var %u = $numtok($SiteHomeUrl,44)
    if (%HomeSelect < %u) inc %HomeSelect 1
    else set %HomeSelect 1
    .UpHomeNotify
    return %HomeSelect $gettok($SiteHomeUrl,%HomeSelect,44)
  }
}

alias UpSiteUrl {
  if (!%HomeSelect) .echo -q $HomeServer
  if (%HomeSelect > $numtok($SiteHomeUrl,44)) .echo -q $HomeServer
  return $gettok($SiteHomeUrl,%HomeSelect,44)
}

alias UpHomeNotify { 
  if ($dialog(GlobalFind)) did -ra GlobalFind 64 Server Update connesso: $ord(%HomeSelect) 
}

;----------------------
;-- MULTISOCK UPDATE --
;----------------------
ON *:sockopen:UpdateSys*: {
  var %line = $sock($sockname).mark, %url = $gettok(%line,1,42), %path = $gettok(%line,2,42)
  if ($sockerr > 0) { 
    .signal -n GlobalFind_Info01 Errore connessione al server Update.
    sockclose $sockname
    echo 2 -st Server Offline. Passo al server $HomeServer
    halt 
  }
  var %>>> = sockwrite -n $sockname
  %>>> GET %path $iif(UpdateSysVerify isin $sockname,HTTP/1.0,HTTP/1.1)
  %>>> Host: %url
  %>>> Accept: text/html
  %>>> User-Agent: $User-Agent
  %>>> Connection: close
  %>>> $crlf
}

ON *:sockread:UpdateSys*: {
  var %url = $sock($sockname).mark
  if ($sockerr > 0) { 
    echo 4 -st Errore Connessione al server update... riprovo più tardi. | sockclose $sockname 
    if (UpdateSysNowNews !isin $sockname) { echo 13 -st Server Offline. Passo al server $HomeServer }
    halt 
  }
  if (*-1 !iswm $sockname) {
    var %tmp | sockread %tmp
    if ($regex(%tmp,/^HTTP/1\.[01]/)) {
      if (!$regex(%tmp,/^HTTP/1\.[01] 200 OK/)) {
        echo 4 -st GlobalFind Update: -ERRORE $+ $gettok(%tmp,2-,32) $+ -
        echo -st Passo al server $HomeServer ...
        sockclose $sockname | halt
      }
      elseif ($sockname == UpdateSysCheck) { sockrename $sockname $+($sockname,-1) | halt }
    }
    if (!%tmp) && (UpdateSysVerify* !iswm $sockname) { sockrename $sockname $+($sockname,-1) | halt }
  }
  ;---- Update Check ---
  if ($sockname == UpdateSysCheck-1) { 
    sockread &tmp 
    var %update = $remove($bvar(&tmp,$bfind(&tmp, 1, $RemoteDir),$bvar(&tmp,0)).text,$chr(13),$chr(10))
    tokenize 42 %update
    if ($0 >= 9) {
      var %md5Addon = $2, %md5db = $3, %md5News = $4
      if ($1 != $RemoteDir) { return }
      ;--  Update Addon --
      if ((%md5Addon != $md5($script,2)) && ($5 > $GFInfox(VERSION))) {
        inc %UpdateCounter
        .signal -n GlobalFind_Info01 Aggiornamento Addon necessario: $5     
        echo $color(ctcp) -st INFO GlobalFind: Aggiornamento Addon necessario: $5 ...
        .UpdateSysFind NowAddon
      }
      ;-- Update DataBase --
      if ((!$exists($FindDb)) || (%md5db != $md5($FindDb,2))) {
        inc %UpdateCounter
        .signal -n GlobalFind_Info01 aggiornamento DataBase necessario...
        echo $color(ctcp) -st INFO GlobalFind: aggiornamento DataBase necessario...
        .UpdateSysFind NowDb
      }
      ;-- Update News --
      if ((!$exists($FileNews)) || (%md5News != $md5($FileNews,2))) {
        inc %UpdateCounter 
        .signal -n GlobalFind_Info01 Ricezione News in corso... 
        echo $color(ctcp) -st INFO GlobalFind: Ricezione New in corso...
        .UpdateSysFind NowNews
      }
      ;-- Update xdccMule --
      var %f = $script($mircdirscript1.mrc), %r = $readini(%f,Info,Versione)
      if (($exists(%f)) && (%r) && ($8 > %r)) {
        inc %UpdateCounter
        .signal -n GlobalFind_Info01 Aggiornamento xdccMule necessario: $8
        echo $color(ctcp) -st INFO GlobalFind: Aggiornamento xdccMule necessario: $8 ...
        .UpdateSysFind NowxdccMule
      }
      if (%debuging) {
        echo -st ---------------- $time - $date - SERVER: %HomeSelect -------------------
        echo 2 -st >> Line: $1-
      }
      if (%ManualCheck) {
        echo 2 -s $str(-,84)
        echo -s Tipo addon: $1
        echo 2 -s $str(-,84)
        echo 6 -s $str(-,21) ONLINE $str(-,22) INSTALLATO $str(-,21)
        echo -s >> Md5 addon: $2 <- $iif($2 = $md5($script,2), 3,4) $md5($script,2)
        echo -s >> Md5 db: $3 <- $iif($3 = $md5($FindDb,2), 3,4) $md5($FindDb,2)
        echo -s >> Md5 New: $4 <- $iif($4 = $md5($FileNews,2), 3,4) $md5($FileNews,2)
        echo -s >> Addon version: $5 <- $iif($5 > $GFInfox(VERSION),4,3) $GFInfox(VERSION)
        echo -s >> Db Data: $6
        echo -s >> News Data: $7
        echo -s >> xdccMule Version: $8 <- $iif($8 > %r, 4,3) %r
        echo 2 -s $str(-,84)
        .signal -n GlobalFind_Info01 $iif(%UpdateCounter > 0, Ci sono %UpdateCounter aggiornamenti..., Controllo aggiornamenti terminato.)
        unset %ManualCheck
      }
    }
  }
  ;-----------------------
  ;-- AGGIORNA DATABASE --
  ;-----------------------
  elseif ($sockname = UpdateSysNowDb-1) { 
    sockread &tmp
    .bwrite $FindDb -1 &tmp
  }
  ;--------------------
  ;-- AGGIORNA ADDON --
  ;--------------------
  elseif ($sockname = UpdateSysNowAddon-1) { 
    sockread &tmp
    .bwrite $AddonTmp -1 -1 &tmp
  }
  ;----------------------
  ;-- AGGIORNA VETRINE --
  ;----------------------
  elseif ($sockname = UpdateSysVerifyVetrine-1) { 
    sockread &tmp
    .bwrite $VetrineTmp -1 -1 &tmp
  }
  ;------------------
  ;-- AGGIORNA NEW --
  ;------------------
  elseif ($sockname = UpdateSysNowNews-1) { 
    sockread &tmp
    .bwrite $FileNews -1 -1 &tmp
  }
  ;-----------------------
  ;-- AGGIORNA XDCCMULE --
  ;-----------------------
  elseif ($sockname = UpdateSysNowxdccMule-1) { 
    sockread &tmp
    .bwrite $xdccMuleTmp -1 -1 &tmp
  }
  elseif ($sockname == UpdateSysVerifyNovita) {
    tokenize 32 $htmlfree(%tmp)
    ;echo -se DEBUG:>> $1-
    if (Categorie:* iswm $1-) { 
      var %cat = $gettok($1-,2,58)
      .hadd NewsTable Categorie %cat
    }
    if (TAB:* iswm $1-) .hadd NewsTable Tabs $gettok($1-,2,58)
    if ($1 isnum) {
      .hadd NewsTable $1 $ReplaceChr($2-)
    }
  }
}

ON *:sockclose:UpdateSys*: {
  if ($sockname == UpdateSysNowDb-1) {
    if ($read($FindDb, w, *Errore 404*)) { 
      .remove $FindDb
      .signal GlobalFind_Info01 Errore 404 durante l'aggiornamento del DataBase!
      .halt 
    }
    else {
      .signal GlobalFind_Info01 Aggiornamento DataBase completato.
      echo 3 -st INFO GlobalFind: aggiornamento DataBase eseguito!
      .loadWebListItem | .loadWebList
    }
  }
  if ($sockname == UpdateSysNowAddon-1) {
    .signal GlobalFind_Info01 Download Addon Completato.
    .remove $qt($script)
    .rename $qt($+($scriptdir,GlobalFind.mrc [ $+ [ .tmp ] ])) $qt($+($scriptdir,GlobalFind.mrc))
    if ($dialog(GlobalFind)) {
      dialog -cx GlobalFind
      .timerReopenDia 1 1 .GlobalFind
    }
    .reload -rs $qt($+($scriptdir,GlobalFind.mrc))
    echo $color(info2) -st INFO GlobalFind: Aggiornamento Addon eseguito!
  }
  if ($sockname == UpdateSysNowxdccMule-1) {
    .signal GlobalFind_Info01 Aggiornamento Core xdccMule Completato.
    .remove $qt($script(script1.mrc))
    .rename $qt($+($script(script1.mrc),.tmp)) $qt($script(script1.mrc))
    .reload -rs $qt($script(script1.mrc))
    echo $color(info2) -st INFO GlobalFind: Aggiornamento Core xdccMule Completato.
  }
  if ($sockname == UpdateSysNowNews-1) {
    .SpeakFindNews
    .signal GlobalFind_Info01 Ricezione News completato.
    echo $color(info2) -st INFO GlobalFind: New ricevuta!
  }
  if ($sockname == UpdateSysVerifyNovita) {
    .signal GlobalFind_Info01 Ricezione Novità completato.
    if ($hget(NewsTable,Categorie)) {
      if ($dialog(GlobalFind)) did -r GlobalFind 102
      var %x = 1, %cat = $hget(NewsTable,Categorie), %NumCat = $numtok(%cat,44)
      while (%x <= %NumCat) {
        if ($dialog(GlobalFind)) did -a GlobalFind 102 $gettok(%cat,%x,44)
        inc %x
      }
      if ($dialog(GlobalFind)) {
        did -e GlobalFind 102,104,105,106
        did -c GlobalFind 102 1
        .ReturnNews 1
        if ($window(@Novità)) .SpeakNovita
      }
    }
  }
}

;-------------------
;-- ANNUNCIA NEWS --
;-------------------
alias -l SpeakFindNews {
  if (!$exists($FileNews)) return
  var %w = $+(@News,$chr(160),Addon,$chr(160),Global,$chr(160),Find)
  if (!$window(%w)) window -aCBdok0w0 +L %w 0 0 550 300 verdana 12
  else Clear %w
  titlebar %w  Extended
  aline %w Data Estrazione new: $iif(%Updated_new,$v1,n/d)
  ; aline %w $chr(160)
  loadbuf -pr %w $FileNews
  sline -a %w 16
  aline %w $bItaly | aline %w $bItaly | aline %w $bItaly | aline %w $bItaly
}

;--------------------------
;-- PROCEDURE DEI POPUPS --
;--------------------------
alias ListChanDB {
  if ($1 isnum) && ($readini($FindDb,$ActiveNet,$1) != $null) {
    var %s = $gettok($v1,1,42)
    if (!$istok(%ChanGFind,%s,32)) { 
      set %ChanGFind %ChanGFind %s
      var %i = $IdNet($ActiveNet)
      .scon %i
      return $iif($me ison %s,$style(1)) %s $+ :.DBJoinChanSel %s
    }
    else return -
  }
  if ($1 = end) unset %ChanGFind
}

alias WebListChanDB {
  if ($1 isnum) && ($readini($FindDb,$ActiveNet,$1) != $null) {
    var %s = $v1
    return ID $+ $1 $gettok(%s,1,42) $gettok(%s,3,42) $+ :.run $gettok(%s,2,42)
  }
}

alias -l DBJoinChanSel {
  var %chan = $1, %net = $ActiveNet, %line = $readini($FindDb,%net,0), %dns = $gettok(%line,1,42), %i = $IdNet(%net)
  if (%i == 0) {
    var %m = $input(ATTENZIONE!!! $crlf $crlf Non mi trovo su %net Dns: %dns $crlf $crlf Per entrare in %chan devi prima connetterti alla net $crlf $crlf Vuoi connetterti?,ygdw,Errore,title,text) 
    if (%m == $true) .server $iif($gettok($NetStatus(1),2,32) == connected,-m) %dns -j %chan
    return 
  }
  else { .scon %i | .join %chan }
}

;---------------------------------
;-- RILEVA FILE SOSPESO AL JOIN --
;---------------------------------
alias SospesiTable {
  If ($Hget(SospesiTable)) { .hfree SospesiTable }
  .hmake SospesiTable 10
}
on 1:JOIN:#: {
  if ($nick == $me) {
    var %Chan2Net = $network $+ $chan
    if ($hget(SospesiTable,%Chan2Net)) {
      .timerControlJSospesi 1 10 .ControlJoinSospesi $chan $network %Chan2Net  
    }
  }
}

alias ControlJoinSospesi {
  var %chan = $1, %net = $2, %Chan2Net = $3, %i = $IdNet(%net)
  var %m = $hget(SospesiTable,%Chan2Net), %b = $gettok(%m,1,32)
  if (%b ison %chan) { .scon %i | .msg %m | .hdel SospesiTable %Chan2Net }
  else BotNonTrovato %m %chan
}

alias BotNonTrovato {
  var %m = $input(RICHIESTA IN SOSPESO $crlf $crlf Non ho Trovato... $crlf $crlf Il Bot $1 in $2 $crlf $crlf Cerca un altro Bot con lo stesso file!,ogdwk3,Errore,title,text) 
}

;-------------------
;-- ALL INFO CHAN --
;-------------------
alias AllInfoChan {
  if (!$1) return
  var %id = $remove($gettok($1,2,58),$chr(160))
  tokenize 46 %id
  var %IdN = $iif($0 = 3,$3,$2), %IdC = $iif($0 = 3,$2,$1), %item = $ini($FindDb,%IdN)
  var %line = $readini($FindDb,%item,0)
  var %net = $gettok(%line,1,42), %dns = $gettok(%line,2,42)
  var %line2 = $readini($FindDb,%item,%IdC)
  var %chan = $gettok(%line2,1,42), %con = $replace($gettok(%line2,3,42),$chr(44),$chr(42)), %tipo = $gettok(%line2,4,42), %vm = $gettok(%line2,5,42)
  var %k = $input($+(ID:,$replace($1-,$chr(32),$chr(46))) $crlf $crlf Nome Chan: %chan $crlf $&
    Lista: %con  $crlf $&
    Tipo: %tipo $crlf $&
    Velocità media dichiarata: $iif(%vm,%vm kbps,n/d) $crlf $&
    Network: %net $crlf $&
    DNS: %dns $crlf ,ogdik10,INFO CHAN ,title,text)
}

;-----------------------------
;-- SPOSTA FILEs COMPLETATI --
;-----------------------------
on *:filercvd:*: {
  var %nickname = $nick
  if (!%nickname) return
  ;;;echo 4 -st Completato:  $+ $color(info2) $nopath($filename) -> $+ $color(action) $bytes($get(-1).size,3).suf in $get(-1).secs sec. $+ $color(notice) $+($chr(40),$bytes($get(-1).cps,3).suf,/sec.,$chr(41))  $+ $color(info) $date
  if (%MoveCompleted == 1) .MoveCompleted $filename
  if (%CloseSuccessGet == 1) .close -g %nickname
}

alias MoveCompleted {
  var %ComplFileName = $1-, %FinalDir = $+($getdir,COMPLETATI\)
  var %OldDirFile = $nofile($1-)
  if (!$isdir(%FinalDir)) .mkdir $qt(%finaldir)
  if (!$isfile($+(%FinalDir,$nopath(%ComplFileName)))) && ($isfile(%ComplFileName)) {
    .rename $qt(%ComplFileName) $qt($+(%FinalDir,$nopath(%ComplFileName)))
    echo -st INFO MOVE FILE: $nopath(%ComplFileName) Spostato nella cartella dei files Completati.

    if ($isdir(%OldDirFile)) {
      ;echo 7 -ste DEBUG: %OldDirFile
      if (%OldDirFile != $getdir) {
        if ($findfile(%OldDirFile,*.*,0) == 0) .rmdir $qt(%OldDirFile)
        else echo -st INFO MOVE FILE: La Cartella $qt(%OldDirFile) non è vuota! Impossibile eliminarla.
      }
    }
    else echo -st INFO MOVE FILE: La Directory $qt(%OldDirFile) non esiste! Impossibile eliminarla.
  }
  else echo -st INFO MOVE FILE: Impossibile Spostare $qt($nopath(%ComplFileName)) esiste già un file con questo nome nella cartella di destinazione!
}

;---------
;-- EOF --
;---------
