This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Need help "[ ] { } ' - /"

Help for those learning Tcl or writing their own scripts.
Post Reply
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Need help "[ ] { } ' - /"

Post by garfwen »

Hello

I made a simple auth-sistem with mysql.
It saves your nickname in a table when you AUTH.

But i'm having a little trouble with nicknames with [ ] { } ' - /, the bot just dont read them or add some { }.

Any solution?

Thanks,
GaRfWeN
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Do you think you could post the script?
NML_375
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

Hello.

The scripts is a little big, i'll post the "auth" proc:

Code: Select all

proc auth {nick hand host txt} { 
global botnick ci cf db mainchan mainchanpvt modeauth 
if { $modeauth == 1 } {
if {[onchan $nick $mainchan]} {
	if { [::mysql::sel $db "SELECT auth FROM users WHERE ircnick='[string tolower $nick]' AND ircstatus='1'"] == "1" } {
	puthelp "PRIVMSG $nick :$ci Tu já estas autenticado! $cf" 
	} else {
	set auth [string tolower [lindex [split $txt] 0]]
	set pass [md5 [string tolower [lindex [split $txt] 1]]]
		if { $txt == "" } {
			puthelp "PRIVMSG $nick :$ci Comando inválido, para te autenticares usa /msg $botnick auth <nick> <pass> $cf" 
		} else {
			if { $pass == "" } {
				puthelp "PRIVMSG $nick :$ci Comando inválido, para te autenticares usa /msg $botnick auth <nick> <pass> $cf" 
				} else {
				if {[::mysql::sel $db "SELECT password FROM users WHERE auth='$auth'" -list] == $pass } {
					set check [::mysql::sel $db "SELECT ircstatus FROM users WHERE auth='$auth'" -list]
					if { $check == 1 } {
					set authednick [::mysql::sel $db "SELECT ircnick FROM users WHERE auth='$auth'" -list]
					putserv "privmsg $authednick :$ci O utilizador $nick fez auth na tua conta(#$auth). Deixas-te de estar autenticado $cf"
					}
					set result [::mysql::exec $db "UPDATE users SET ircstatus='1' WHERE auth='$auth'"]
					set result [::mysql::exec $db "UPDATE users SET ircnick='$nick' WHERE auth='$auth'"]
					set level [::mysql::sel $db "SELECT level FROM users WHERE auth='$auth'" -list]
					puthelp "PRIVMSG $nick :$ci Estás agora autenticado como $auth $cf" 
					set auth [::mysql::sel $db "SELECT auth FROM users WHERE ircnick='$nick' AND ircstatus='1'" -list]
					}
				} else {
				putserv "privmsg $mainchanpvt : Tentativa de login falhado por $nick (Auth: #$auth)"
				puthelp "PRIVMSG $nick :$ci Password/nick inválido, para te autenticares usa /msg $botnick auth <nick> <pass>  $cf" 
				} 
			}
		}
	}
	} else {
	puthelp "PRIVMSG $nick :$ci Precisas de estar no canal $mainchan para fazer auth $cf" 
}
} else {
puthelp "PRIVMSG $nick :$ci Esta funcão foi desactivada $cf" 
}
}
( I deleted some code, maybe a } is missing or smthng.)

That proc checks if your on the chan, checks if your already authed, checks if your login/password exists and also checks if they match acording to de mysql db.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Ahh, I do see some unbalanced {}'s but that's probably due to your trimming.

The error at hand however, is that you use the -list option with ::mysql::sel. This makes it return a tcl-list of results, and you'll have to use lindex to retrieve a single item, or join to convert the list into a string.

Fix: change each ::mysql::sel-command like below:

Code: Select all

#This...
if {[::mysql::sel $db "SELECT password FROM users WHERE auth='$auth'" -list] == $pass } {
#Should be changed into this...
if {[join [::mysql::sel $db "SELECT password FROM users WHERE auth='$auth'" -list]] == $pass } {

#This...
set check [::mysql::sel $db "SELECT ircstatus FROM users WHERE auth='$auth'" -list]
#Should be changed into this...
set check [join [::mysql::sel $db "SELECT ircstatus FROM users WHERE auth='$auth'" -list]]

#And so on...
NML_375
g
garfwen
Halfop
Posts: 61
Joined: Wed Mar 12, 2008 5:16 pm

Post by garfwen »

Yep.

Thank you
Post Reply