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.

raw binding

Help for those learning Tcl or writing their own scripts.
Post Reply
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

raw binding

Post by geek »

I write this small tcl script to understand raw binding:

Code: Select all

#
#	raw 352	risposta al WHO "vanilla"
#
#	raw 354	risposta al WHOX che è la versione "extended"
#
#
#
#	nel RFC 1459 ( https://www.rfc-editor.org/rfc/rfc1459.txt )
#							402	ERR_NOSUCHSERVER
#							352	RPL_WHOREPLY
#							315	RPL_ENDOFWHO
#

bind pub - !testraw ldm:who


proc ldm:who {nick host hand chan arg} {


	set nickname [stripcodes * $arg]
	set nickname [string trim $nickname]

	set arguments [llength $nickname]

	if { $arguments > 1 } {
		puthelp "PRIVMSG $chan :specificare un utente alla volta"
		return
	} elseif { $arguments == 0 } {
		puthelp "PRIVMSG $chan :specificare il nickname"
		return
	}

	if { ![onchan $nickname $chan] } {
		puthelp "PRIVMSG $chan :nickname non trovato"
		return
	}

	putserv "WHO $nickname"


#	bind raw - "315" ldm:whoraw
	bind raw - "352" ldm:whoraw
#	bind raw - "354" ldm:whoraw
#	bind raw - "402" ldm:whoraw



	return
}


proc ldm:whoraw {from key text} {

	puthelp "PRIVMSG #prova :$text"

	return
}

is this script secure? are there potential problems with other scripts?

the question is: when I use it, does "ldm:whoraw" capture ONLY the /who command inside this script or is there the possibility that catch /who command from others scripts too?

(sorry for my english)
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

The ldm:whoraw will catch any who response sent to the eggdrop.
You can simply test that: in party-line, do a .tcl putserv "WHO $botnick" and your proc will work.

A bind catch a specific server event, it's totally independant of who/what asked the server to react.

But your script is secure as it just displays server's who replies to a particular channel. If it's just a test script, you'd better use a putlog and check in party-line, to avoid flood on your server.
Online
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: raw binding

Post by willyw »

geek wrote: ...
the question is: when I use it, does "ldm:whoraw" capture ONLY the /who command inside this script or is there the possibility that catch /who command from others scripts too?
...
If this is a concern, here's an idea to consider. It is what I usually do.

Code: Select all

proc ldm:who {nick host hand chan arg} {

   bind raw - "352" ldm:whoraw 
   utimer 5 [list unbind raw - "352" ldm:whoraw]

   < continue with the rest of the procedure's code here >

}
The idea is to create the bind that you will need.
Then, a few seconds later, unbind it.

Of course, you should adjust the value of the utimer to whatever you think is best.


I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

CrazyCat wrote:The ldm:whoraw will catch any who response sent to the eggdrop.
and if are there more than one scripts that catch the same raw number? is it a problem?
very tnx CrazyCat

willyw wrote:It is what I usually do.

Code: Select all

...
The idea is to create the bind that you will need.
Then, a few seconds later, unbind it.
yes, I'll use your code :)
and very tnx willyw
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

geek wrote:
CrazyCat wrote:The ldm:whoraw will catch any who response sent to the eggdrop.
and if are there more than one scripts that catch the same raw number? is it a problem?
very tnx CrazyCat
You can have multiple scripts using the same raw number without any trouble.
geek wrote:
willyw wrote:It is what I usually do.

Code: Select all

...
The idea is to create the bind that you will need.
Then, a few seconds later, unbind it.
yes, I'll use your code :)
and very tnx willyw
This is a quite good idea to use utimer to unbind, but you can have side effects.
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

CrazyCat wrote: You can have multiple scripts using the same raw number without any trouble.
thanks :)
CrazyCat wrote:This is a quite good idea to use utimer to unbind, but you can have side effects.
what kind of side effects?
Online
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

geek wrote: ...
yes, I'll use your code :)
and very tnx willyw
And test it. Then test it some more. :)

One way: use
.binds raw
from the partyline, to be sure that the bind is first there, and then gone, when you expect both.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

and if I want pass a variable from ldm:whoraw to ldm:who ?

something like:

Code: Select all

proc ldm:whoraw {from key text} {

   set ident [lindex $text 2]

   return
}
and in ldm:who

Code: Select all

puthelp "PRIVMSG #test :$ident"

I get always Tcl error: can't read "ident": no such variable
User avatar
CrazyCat
Revered One
Posts: 1306
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Use global variable:

Code: Select all

set ::ident [lindex $text 2]
...
puthelp "PRIVMSG #test :$::ident"
Take care about 2 things:

1. ident is too generic, better to use something like ldmident
2. your variable is set with the answer of the /who command, but the /who is initiated by your ldm:who proc. So you can't already have this value.
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

CrazyCat wrote: 1. ident is too generic, better to use something like ldmident
yes :)
CrazyCat wrote:2. your variable is set with the answer of the /who command, but the /who is initiated by your ldm:who proc. So you can't already have this value.
you mean in ldm:who:

example1)
puthelp "PRIVMSG #test :$::ldmident"
putserv "WHO $nickname"

example2)
putserv "WHO $nickname"
puthelp "PRIVMSG #test :$::ldmident"

1 -> not work / error
2 -> work

right?



EDIT: NO!

perhaps now I have understand
I try example2 and I get "no such variable" error again
You mean that "it takes some time" for ::ldmident to be available and use it
right?
Online
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

yes tnx, global var ::ldmident works


BUT

there is a kind of "lag" between the WHO command and the availability of the value compute in ldm:whoraw

SO

the first execution I get "no such variable", the following I get a result but is "the old" ident, lol


THIS OCCURS:

(fresh restart of the eggdrop)

first time:
!testraw nickONE -> I get "no such variable"

second time:
!testraw nickTWO -> I get identONE

third time:
!testraw nickTHREE -> I get identTWO

and so on...
g
geek
Halfop
Posts: 47
Joined: Fri Oct 24, 2008 6:07 am

Post by geek »

to avoid the "lag" problem, I put the rest of the code in ldm:whoraw instead of ldm:who

but now

when bot enter in a new channel, I think eggdrop performs a global "WHO #channel" command and so it runs my procedure that catch raw 352 too :)


How can solve this problem? with utimer method of willyw? right?
Post Reply