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.

login to bot to use command

Help for those learning Tcl or writing their own scripts.
Post Reply
K
Kingy
Voice
Posts: 3
Joined: Mon Dec 15, 2008 11:47 pm

login to bot to use command

Post by Kingy »

Ok so what i'm trying to do is let users log into the bot so they can use commands. When they login it gives them a specific flag (+G) and then all commands are based off G. when they part/quit it takes it away.

Now i have the login all working and it adds/takes the flag, but users can't seem to use the commands. Here is some of the code

Code: Select all

bind msg G .commands proc_commands
bind msg - .login proc_login
bind msg G .logout proc_logout

proc proc_login { nick uhost hand text } {
  global host user pass db

  set con [::mysql::connect -host $host -user $user -password $pass]
  set res [::mysql::use $con $db]

  set md5pass [md5 $text]

  set query [::mysql::query $con "SELECT * FROM users WHERE username='$nick' AND password='$md5pass'"]

  if {[set row [::mysql::fetch $query]] == ""} {
    putserv "PRIVMSG $nick :Incorrect Login"
  } else {
    putserv "PRIVMSG $nick :Logged in"
    adduser $nick
    chattr $nick +G
  }
  ::mysql::endquery $query
  ::mysql::close $con
}

proc proc_commands { nick uhost hand text } {
  putserv "PRIVMSG $nick :All commands can be accessed in this private chat, or by typing /msg K1-Bot <command>"
  putserv "PRIVMSG $nick :-"
  putserv "PRIVMSG $nick :Commands:"
  putserv "PRIVMSG $nick :.logout (Logs you out of the bot)"
}

Now, when i login it seems to work, but doesn't work when another user does it. Any reason why?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

adduser <handle> [hostmask]
Description: creates a new user entry with the handle and hostmask given
(with no password and the default flags)
Returns: 1 if successful; 0 if the handle already exists
Module: core
Then have a look at this part of the code:

Code: Select all

adduser $nick
chattr $nick +G
Basically, you're creating a new user-account (based on nickname), but neglect to add any hostmasks to it. Hence your eggdrop cannot identify the user as the user-account. Add a proper hostmask.
Also, I would strongly suggest that you add some mechanism to check that the added handle-name does not already exists (or test the result of the adduser command).
NML_375
Post Reply