soucis sur un bind join.
#12
Salut,

je vais encore me répéter mais bon,
Pourquoi aller trifouiller dans le fichier à chaque fois?
bref, voila le tcl que j ai codé il y a quelques temps maintenant et que tu cherches a reproduire:
tcl
namespace eval autorise {
 variable salons "#test"
 variable data
 variable file [file join scripts autorised.db]
 
  if ![file exists $file] {
    catch {open $file w+} p
    catch {close $p}
  }
  set data ""
  catch {open $file r} p
  while {![eof $p]} {
    if {[gets $p d]!=""} {lappend data $d}
  }
  catch {close $p}
  unset p
 
  bind evnt - save autorise::save_file
 
  proc save_file {type} {
   variable data
   variable file
    if {$data==""} return
    catch {open $file w+} p
    foreach d $data {
      if {$d!=""} {puts $p [join $d]}
    }
    catch {close $p}
    putlog "Sauvegarde du fichier autorised.db"
  }
 
  proc stgcomp {arg1 arg2} {string equal -nocase $arg1 $arg2}
 
  proc hostcomp {host1 host2} {
    string match -nocase [string map {"\[" "." "\]" ","} [join $host1]] [string map {"\[" "." "\]" ","} [join $host2]]
  }

  #################################
 
  bind pub - .+autorise autorise::add
  bind pub - .-autorise autorise::del
  bind join - * autorise::join_chan 
 
  proc add {nick host hand chan arg} {
   variable data
   variable salons
    if {[lsearch -nocase $salons $chan]==-1} return
    if {[llength $arg]!=1} {puthelp "NOTICE $nick :syntaxe: .+autorise <pseudo>";return}
    foreach d $data {
      if {[stgcomp [lindex $d 0] $chan] && [stgcomp [lindex $d 1] $arg]} {
        putserv "NOTICE $nick :ce pseudo est déjà autorisé sur $chan."
        return
      }
    }
    lappend data [string tolower "$chan $arg"]
    putserv "NOTICE $nick :$arg est a été ajouté sur $chan."
  }
 
  proc del {nick host hand chan arg} {
   variable data
   variable salons
    if {[lsearch -nocase $salons $chan]==-1} return
    if {[llength $arg]!=1} {puthelp "NOTICE $nick :syntaxe: .-autorise <pseudo>";return}
    set x 0
    set y 0
    foreach d $data {
      if {[stgcomp [lindex $d 0] $chan] && [stgcomp [lindex $d 1] $arg]} {
        set data [lreplace $data $x $x]
        incr y
      }
      incr x
    }
    if $y {
      putserv "NOTICE $nick :$arg est a été supprimé sur $chan."
    } else {
      putserv "NOTICE $nick :$arg n'est pas autorisé sur $chan."
    }
  }
 
  proc join_chan {nick host hand chan} {
   variable data
   variable salons
    if [isbotnick $nick] return
    if {[lsearch -nocase $salons $chan]==-1} return
    if [string match *|* $nick] {set n [lindex [split $nick |] 0]} else {set n $nick}
    set k 1
    foreach d $data {
      if ![stgcomp [lindex $d 0] $chan] continue
      if [hostcomp [lindex $d 1] $n] {set k 0;break}
    }
    if $k {
      putquick "PRIVMSG $chan :Authentification \00304°\00314Refusée\00304°\00314 pour \002$nick"
      putquick "MODE $chan +b *!$host"
      putquick "KICK $chan $nick :Accès refusé."
    } else {
      putquick "PRIVMSG $chan :Authentification \00303°\00314Acceptée\00303°\00314 pour \002$nick"
      puthelp "MODE $chan +v $nick"
    }
  }
}


C'est en reconnaissant ses erreurs que l'on progresse Wink
Répondre Avertir


Messages dans ce sujet
soucis sur un bind join. - par aliasangelius - 22/10/2011, 09:26
RE: soucis sur un bind join. - par CrazyCat - 22/10/2011, 10:31
RE: soucis sur un bind join. - par CrazyCat - 22/10/2011, 10:46
RE: soucis sur un bind join. - par CrazyCat - 22/10/2011, 11:15
RE: soucis sur un bind join. - par DnS - 22/10/2011, 11:35
RE: soucis sur un bind join. - par DnS - 22/10/2011, 18:39
RE: soucis sur un bind join. - par DnS - 22/10/2011, 18:58
RE: soucis sur un bind join. - par djkenny - 22/10/2011, 20:15
RE: soucis sur un bind join. - par djkenny - 22/10/2011, 23:49
RE: soucis sur un bind join. - par djkenny - 23/10/2011, 10:25
RE: soucis sur un bind join. - par cestlemien - 23/10/2011, 13:09
RE: soucis sur un bind join. - par CrazyCat - 23/10/2011, 13:16

Atteindre :


Utilisateur(s) parcourant ce sujet : 1 visiteur(s)
Tchat 100% gratuit -Discutez en toute liberté