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.

Error in my tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dlpt
Voice
Posts: 4
Joined: Fri Sep 18, 2009 10:50 am

Error in my tcl

Post by dlpt »

need help in my tcl.

Code: Select all

proc whois { nick uhost hand chan arg }
	global color1 color2 bd_user bd_pass bd_host bd_dbase bd_table
	set bd [::mysql::connect -host $bd_host -user $bd_user -password $bd_pass]
	if { $login_ok == 1 } {

	set sd [::mysql::whois $db "SELECT username, level FROM $db_table" -list]
	foreach wl $sd {
	if { $wl != "" } {
		set wl_split [split $wl]
		set user_name [lindex $wl_split 0]
		set user_level [lindex $wl_split 2]
	putquick "privmsg $chan :$color1 $n $color2$color1 Info level $user_level $color2"
	}
	if { $login_ok == 0 } {
	putquick "privmsg $chan :$color1 dont cry. $color2"
I try ON eggdrop and:

Code: Select all

[12:02] wrong # args: should be "proc name args body"
    while executing
"proc whois { nick uhost hand arg }"
    (file "scripts/test.tcl" line 12)
Any idea ?
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Seems to be indicating that whatever calls/triggers the proc provides/requires a different number of arguments than are accounted for in the proc definition.

For one thing, your proc says this :-

Code: Select all

proc whois { nick uhost hand chan arg }
But your error says this :-

Code: Select all

proc whois { nick uhost hand arg }
We need to see what triggers it to be more help. Looks like some sort of Eggdrop Tcl BIND.
I must have had nothing to do
d
dlpt
Voice
Posts: 4
Joined: Fri Sep 18, 2009 10:50 am

Post by dlpt »

sorry, error lol, the code are:

Code: Select all

set bd_user "fxp_egg"
set bd_pass "password"
set bd_host "localhost"
set bd_dbase "fxp_test"
set bd_table "users"

bind msgm - "*" auth

bind pub - !whois whois

#####Code by tomekk

proc auth { nick uhost hand arg } {
   global msql_user msql_pass msql_host msql_dbase msql_table invite_chan color1 color2 adminchannel

   set all_prv_args [split $arg]
   set priv_command [lindex $all_prv_args 0]
   set priv_username [lindex $all_prv_args 1]
   set priv_password [lindex $all_prv_args 2]

   set login_ok 0

   if {($priv_command == "auth") && ($priv_username != "") && ($priv_password != "")} {
      set m_hand [::mysql::connect -host $msql_host -user $msql_user -password $msql_pass]
      ::mysql::use $m_hand $msql_dbase

      set users_passwords [::mysql::sel $m_hand "SELECT username, password FROM $msql_table" -list]

      ::mysql::close $m_hand

      foreach u_and_p $users_passwords {
         if {$u_and_p != ""} {
            set u_and_p_split [split $u_and_p]
            set user_name [lindex $u_and_p_split 0]
            set user_pass [lindex $u_and_p_split 1]

            if {$priv_username == $user_name} {
               if {$priv_password == $user_pass} {
                  set login_ok 1
		putquick "privmsg $nick :$color1 Login ok! $color2"
               }
            }
         }
      }

      if {$login_ok == 0} {
         putquick "PRIVMSG $nick :$color1 Login ERROR! $color2"
      }
   }
}

#####End code by Tomekk####

proc whois { nick uhost hand chan arg }
   global color1 color2 bd_user bd_pass bd_host bd_dbase bd_table
   set bd [::mysql::connect -host $bd_host -user $bd_user -password $bd_pass]
   if { $login_ok == 1 } {

   set sd [::mysql::whois $db "SELECT username, level FROM $db_table" -list]
   foreach wl $sd {
   if { $wl != "" } {
      set wl_split [split $wl]
      set user_name [lindex $wl_split 0]
      set user_level [lindex $wl_split 2]
   putquick "privmsg $chan :$color1 $n $color2$color1 Info level $user_level $color2"
   }
   if { $login_ok == 0 } {
   putquick "privmsg $chan :$color1 dont cry. $color2"
I record via the database users and meto the desired level

Table:

Code: Select all

create table users (
        id int(4) auto_increment,
        username varchar(12),
        password varchar(12),
        level varchar(12),
        primary key(id)
); 
btw, you could do me the code to record starting at php and give the automatic level one . A kind of small php script to log in

dlpt,
thanks
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I assume you corrected the original error, since the whois proc has the required number of arguments for a PUB bind. I would avoid using 'arg' as an argument variable name because it is uncomfortably close to 'args' which has special meaning in Tcl. The generally accepted norm is to use 'text' or 'rest'.

Sorry, it's a very long time since I did any php. it would be like learning all over again. In any case this would not be the right forum for php script requests.
I must have had nothing to do
d
dlpt
Voice
Posts: 4
Joined: Fri Sep 18, 2009 10:50 am

Post by dlpt »

the error continues :s

Code: Select all

[15:06] Tcl error in file 'myegg.conf':
[15:06] wrong # args: should be "proc name args body"
    while executing
"proc whois { nick uhost hand chan txt }"
    (file "scripts/test.tcl" line 54)
    invoked from within
"source scripts/test.tcl"
    (file "myegg.conf" line 1310)
[15:06] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
I do not understand why :oops:

Code: Select all

set bd_user "fxp_egg"
set bd_pass "password"
set bd_host "localhost"
set bd_dbase "fxp_test"
set bd_table "users"

bind msgm - "*" auth

bind pub - !whois whois

#####Code by tomekk#####

proc auth { nick uhost hand arg } {
   global msql_user msql_pass msql_host msql_dbase msql_table invite_chan color1 color2 adminchannel

   set all_prv_args [split $arg]
   set priv_command [lindex $all_prv_args 0]
   set priv_username [lindex $all_prv_args 1]
   set priv_password [lindex $all_prv_args 2]

   set login_ok 0

   if {($priv_command == "auth") && ($priv_username != "") && ($priv_password != "")} {
      set m_hand [::mysql::connect -host $msql_host -user $msql_user -password $msql_pass]
      ::mysql::use $m_hand $msql_dbase

      set users_passwords [::mysql::sel $m_hand "SELECT username, password FROM $msql_table" -list]

      ::mysql::close $m_hand

      foreach u_and_p $users_passwords {
         if {$u_and_p != ""} {
            set u_and_p_split [split $u_and_p]
            set user_name [lindex $u_and_p_split 0]
            set user_pass [lindex $u_and_p_split 1]

            if {$priv_username == $user_name} {
               if {$priv_password == $user_pass} {
                  set login_ok 1
      putquick "privmsg $nick :$color1 Login ok! $color2"
               }
            }
         }
      }

      if {$login_ok == 0} {
         putquick "PRIVMSG $nick :$color1 Login ERROR! $color2"
      }
   }
}

#####End code by Tomekk####

proc whois { nick uhost hand chan txt }
   global color1 color2 bd_user bd_pass bd_host bd_dbase bd_table
   

set bd [::mysql::connect -host $bd_host -user $bd_user -password $bd_pass]
   if { $login_ok == 1 } {
	::mysql::use $db $msql_dbase 
   set sd [::mysql::whois $db "SELECT username, level FROM $db_table" -list]
	::mysql::close $db
  foreach wl $sd {
   if { $wl != "" } {
      set wl_split [split $wl]
      set user_name [lindex $wl_split 0]
      set user_level [lindex $wl_split 2]
   putquick "privmsg $chan :$color1 $n $color2$color1 Info level $user_level $color2"
			}
		}
	}
   if { $login_ok == 0 } {
   putquick "privmsg $chan :$color1 dont cry. $color2"
	}
Hm, ok, I'll see if I learn.

dlpt,
Thanks
Last edited by dlpt on Fri May 07, 2010 10:16 am, edited 1 time in total.
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Missing opening brace :-

Code: Select all

proc whois { nick uhost hand chan txt }
Should be :-

Code: Select all

proc whois {nick uhost hand chan txt} {
I have also removed the unnecessary spaces preceding and following the proc arguments.
I must have had nothing to do
d
dlpt
Voice
Posts: 4
Joined: Fri Sep 18, 2009 10:50 am

Post by dlpt »

Now another error -.-'

Code: Select all

[15:20] missing close-brace
    while executing
"proc whois {nick uhost hand chan txt} {
   global color1 color2 bd_user bd_pass bd_host bd_dbase bd_table
   
   if { $login_ok == 1 } {
      set m_h..."
    (file "scripts/test.tcl" line 54)
    invoked from within
"source scripts/test.tcl"
    (file "myegg.conf" line 1310)
any idea ? :)
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I think you need to get yourself a syntax aware editor. The code is a bit of a mess.
Issues like the following can lead to 'false' errors, such as the one you have encountered.
I can't really understand how you managed to load the script, let alone get errors
Since Tomekk wouldn't write such rubbish, I can only assume you are editing somebody else's code and don't have a clue what you are doing

Use of undefined variable n :-

Code: Select all

putquick "privmsg $chan :$color1 $n $color2$color1 Info level $user_level $color2"
Use of undefined variable db (bd is defined, did you mean that) :-

Code: Select all

set sd [::mysql::whois $db "SELECT username, level FROM $db_table" -list]
Use of undefined variable db_table (bd_table is defined, did you mean that) :-

Code: Select all

set sd [::mysql::whois $db "SELECT username, level FROM $db_table" -list]
Use of undefined variable login_ok :-

Code: Select all

if { $login_ok == 1 } {
Missing close brace to conclude the following foreach statement :-

Code: Select all

foreach wl $sd {
Missing close braces to conclude one or both of the following :-

Code: Select all

if { $login_ok == 0 } {
if { $login_ok == 1 } {
I must have had nothing to do
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

i will just add to this post,

the code between marks "#####Code by tomekk#####" is not the same like mine from:
http://forum.egghelp.org/viewtopic.php?t=16547
Post Reply