egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Making a socket TCL script work with eggdrop

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
sparc317
Voice


Joined: 23 Jan 2008
Posts: 11

PostPosted: Wed Jan 23, 2008 9:40 am    Post subject: Making a socket TCL script work with eggdrop Reply with quote

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
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Jan 23, 2008 5:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Jan 24, 2008 10:29 am    Post subject: Reply with quote

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
View user's profile Send private message
ultralord
Master


Joined: 06 Nov 2006
Posts: 255

PostPosted: Wed Jul 09, 2008 3:26 pm    Post subject: Reply with quote

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

thx
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber