| View previous topic :: View next topic |
| Author |
Message |
sparc317 Voice
Joined: 23 Jan 2008 Posts: 11
|
Posted: Wed Jan 23, 2008 9:40 am Post subject: Making a socket TCL script work with eggdrop |
|
|
Hi All,
I would be very grateful if someone could point me in the right direction with something I'm a bit stuck on.
I'll admit I'm a beginner TCL programmer, but have coded in various other languages before.
Basically I have a TCL script that works fine if I run it outside of Eggdrop, however when loading it in Eggdrop I'm hitting some issues.
What my script does is connect to a TCP port on a gameserver, login and monitor chat taking place on the server. It then simply prints any chat messages it finds.
I believe the problem to be because I'm using "vwait eventLoop". This causes the bot to hang while loading, and I'm a bit unsure of how I should rewrite this to be eggrop friendly.
My script is below and I would be very grateful for any help I can get in getting this to work with eggdrop.
Thanks!!
| Code: |
# Set server connection details
set gsname "xxxx"
set gsip "xxxx"
set gsadmport xxxx
set gspass "xxxx"
set gsnick "xxx"
# Handle output from the server and print chat messages to channel
proc read_sock {sock} {
set l [gets $sock]
if {[string match *Chat* $l]} {
puthelp "PRIVMSG #gsadmins :Server #02 - $l"
}
}
# Setup the connection
set gsSock [socket $gsip $gsadmport]
# Monitor the socket
fileevent $gsSock readable [list read_sock $gsSock]
# Line buffer the socket
fconfigure $gsSock -buffering line
# Send admin password
puts $gsSock "$gspass"
# Identify us!
puts $gsSock "/nick $gsnick"
# Wait and handle events
vwait eventLoop
|
[/code] |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Wed Jan 23, 2008 5:24 pm Post subject: |
|
|
| I've never seen or figured out how vwait is supposed to be used. But in your case, you'd probably be better off using a 'while' loop, while not EOF, gets $gsSock, something along those lines. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Jan 24, 2008 10:29 am Post subject: |
|
|
You really don't need vwait, or rather, should not use vwait in eggdrop, as this will block eggdrop's own event-engine (different than tcl's engine). Also, eggdrop calls the Tcl_DoOneEvent within the main-loop stepping tcl's event-engine.
Drop the vwait, and your script should work pretty ok. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
ultralord Master

Joined: 06 Nov 2006 Posts: 255
|
Posted: Wed Jul 09, 2008 3:26 pm Post subject: |
|
|
good idea about this script.. if you fix it plz release it.. if you want.. will be great
thx |
|
| Back to top |
|
 |
|