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.

Help please

Help for those learning Tcl or writing their own scripts.
Post Reply
b
blake
Master
Posts: 201
Joined: Mon Feb 23, 2009 9:42 am
Contact:

Help please

Post by blake »

Hey I found the following script here on the forums and want to try see if it works on my server but i get the following error on the partyline

Also would like to beable to get it to work for any channels i set in the script not just one channel
Tcl error [joins]: bad option "--": must be -nocase or -length
This is the script

Code: Select all

package require mysqltcl 

#-> Change the information below to connect to your MySQL database 
set mysqlserver localhost; 
set mysqluser ***; 
set mysqlpwd ***; 
set mysqldb ***; 

#-> Change the chan below for the chan you wish to monitor 
set userChan "#test" 

bind join - * joins 
proc joins {nick host hand chan} {
	global userChan 
	if {[string equal -nocase -- $chan $userChan]} {
		set db_handle [mysqlconnect -h $::mysqlserver -u $::mysqluser -password $::mysqlpwd]; 
		mysqluse $db_handle $::mysqldb 
		set sql "SELECT id FROM users WHERE username='[mysqlescape $nick]'" 
		set result [mysqlsel $db_handle $sql -list] 
	} 
	set result [mysqlsel $db_handle $sql -list] 
	if {$result > 0 } { 
		putserv "NOTICE $userChan $nick :welcome" 
	} else { 
		putserv "kick $userChan $nick :To join this channel you first need to register at http://cwukchat.com/modules/profile/register.php" 
		mysqlclose $db_handle; 
	}
} 
Many Thanks
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

if {[string equal -nocase -- $chan $userChan]} {
Have you tried removing -- in this line?
Once the game is over, the king and the pawn go back in the same box.
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

Please note that this script is unsafe.
I can choose one of the new users on the site and join the chan with such a nick, and change the nick after that to my real nick like Johannes13

An other thing is that the mysql handle is not closed when the nick is valid.
PROTIP: warp all the stuff after mysqlconnect with a catch, so if there is an error, it will still close the mysql handle

Ok, here a version (it still only checks the nicks, but probably you want to make sure that the nick is registered with nickserv or smillar (by setting a channel mode that let only registered users join etc..)

Code: Select all

package require mysqltcl

#-> Change the information below to connect to your MySQL database
set mysqlserver localhost;
set mysqluser ***;
set mysqlpwd ***;
set mysqldb ***;

#-> Change the chan below for the chan you wish to monitor
setudef flag checknick

bind join - * joins
proc joins {nick host hand chan} {
	if {[channel get $chan checknick]} {
		set db_handle [mysqlconnect -h $::mysqlserver -u $::mysqluser -password $::mysqlpwd];
		set code [catch {
			mysqluse $db_handle $::mysqldb
			set sql "SELECT id FROM users WHERE username='[mysqlescape $nick]'"
			set result [mysqlsel $db_handle $sql -list]
		} res opt]
		mysqlclose $db_handle
		if {$code != 0} {
			return -opt $opt $res
		}
		if {$result > 0 } {
			putserv "NOTICE $nick :welcome"
		} else {
			putserv "kick $chan $nick :To join this channel you first need to register at http://cwukchat.com/modules/profile/register.php"
		}
	}

}
And it uses now a flag, so you can activate that script for more than 1 channel. (use .chanset #channel +checknick)

PS.: I think, I used again some Tcl 8.5 features.. so if you have an older version of Tcl installed, it does not work.
Post Reply