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.

Making a socket TCL script work with eggdrop

Help for those learning Tcl or writing their own scripts.
Post Reply
s
sparc317
Voice
Posts: 11
Joined: Wed Jan 23, 2008 9:34 am

Making a socket TCL script work with eggdrop

Post by sparc317 »

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: Select all

# 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]
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
User avatar
ultralord
Master
Posts: 255
Joined: Mon Nov 06, 2006 6:52 pm

Post by ultralord »

good idea about this script.. if you fix it plz release it.. if you want.. will be great

thx
Post Reply