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.

private channel user checked against mysql

Help for those learning Tcl or writing their own scripts.
Post Reply
r
rickity
Voice
Posts: 3
Joined: Sun Feb 13, 2011 9:27 pm

private channel user checked against mysql

Post by rickity »

hi
im trying to make a script so the eggdrop checks against a mysql db
if a user that is not in the database tries to enter the room he/she is kicked

ive been trying to modify a script all is good except when it comes to executing the kick ,or welcoming a member into the room.

Code: Select all

package require mysqltcl


###### Set Site address ###########################

set site_add "http://www.******"


###### Setup Your database info here ##############


set dbuser "****"
set dbpassword "****"
set name "****"
set portno "3306"

##### Set site channels ##########################


set chanmember "#test"
set memberclassno "1"

##################################################
# Connect to Database #
##################################################

set db_handle [mysqlconnect -host localhost -port $portno -user $dbuser -password $dbpassword -db $name]

##################################################
# #
##################################################

global db_handle chanmember 

set sql "SELECT  id FROM users WHERE username='[mysqlescape $nick]'"
set result [mysqlsel $db_handle $sql -list]

if {$result > 1} {


putserv "NOTICE $nick :welcome to $nick to the members IRC-Channel!"

} else {

}

if {$result < 1} {
putserv "MODE +k $nick" 
putserv "NOTICE KICK $nick :your names not down your not comming in" 



mysqlendquery $db_handle
}
any help would be appreciated ty
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, it would seem that you forgot to place your code as part of a proc declaration:

Code: Select all

proc procname {argument list here} {
  code here...
}
Secondly, your script lacks a binding to trigger this proc. I would assume you'd like the check to be done as a user joins the channel; so thus you need to use the join-binding:
bind join - "#test *" procname
You'll also have to make sure that your proc accepts the proper parameters (see the argument list). Join bindings pass the following parameters to the proc when it triggers: nickname, user@host, handle, channel

Code: Select all

proc procname {nick host handle channel} {
  code goes here...
}
Thirdly, "MODE +k $nick" is not a valid MODE command. The first parameter is expected to be the target; either a channel name, or the name of the bot. In your case, this would probably be the channel. Next, the +k mode is channel key, not kick/ban/etc. I doubt you intended to lock the channel with the offender's nickname as key/password, but rather you intended to ban him/her. Use +b mode along with a proper banmask for this instead.

Passing the -list option to mysqlsel causes it to return a list of Result Sets. Doing a simple less-then/greater-then check is technically not correct, though I think you'll get away with it in this case.
NML_375
r
rickity
Voice
Posts: 3
Joined: Sun Feb 13, 2011 9:27 pm

Post by rickity »

i manged to work it out thanks to your help
im over the moon :D :D

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 args} {

        global userChan

        if {$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 :your names not down your not comming in!"


mysqlclose $db_handle;
}
} 
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

A few things..
Don't use "args" as an argument name unless you know what you are doing. Unless you intend to re-use the proc for other bindings such as pub and/or pubm, there'd be no point in using it here.

Code: Select all

proc joins {nick host hand chan} {
$chan == $userChan
This test is case-sensitive, and the value of $chan is whatever the user used to join the channel. Irc-servers on the other hand, treat channel-names in a case-insensitive manner; #test and #Test is the same channel. Use the "string" command instead:

Code: Select all

if {[string equal -nocase -- $chan $userChan]} {
NML_375
r
rickity
Voice
Posts: 3
Joined: Sun Feb 13, 2011 9:27 pm

Post by rickity »

works brilliantly ty so much :D :D
Post Reply