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.

Announce Bot w/ Telnet

Help for those learning Tcl or writing their own scripts.
Post Reply
T
TehSky
Voice
Posts: 4
Joined: Wed May 27, 2009 1:52 am

Announce Bot w/ Telnet

Post by TehSky »

I'm trying to have create an announcebot that gets information through a telnet connection. Using this script.

Code: Select all

set Port "51010"
set Chan "#channel"

listen $Port script listenb

proc listenb {idx} {
control $idx listenb1
}

proc listenb1 {idx args} {

set args [join $args]
set Announce [join [lrange [split $args] 0 end]]

putquick "PRIVMSG $::Chan :$Announce"
}

putlog "Announce Loaded"
My problem is I get this in the DCC chat with my Eggdrop.
Telnet connection: mywebsite.com/43942
Timeout/EOF ident connection
I tried .+host *!*@* and it didnt work, any ideas?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Your web-server doesn't run an identd service, and thus your eggdrop will make a note of that.

To avoid this, you could try using tcl server sockets instead. Using this socket interface is a little more cumbersome though. I believe something like this should do the trick:

Code: Select all

set servsock [socket -server handleConnect 51010]

proc handleConnect {socket clientIP clientPort} {
  fconfigure $socket -blocking 0
  fileevent $socket readable [readSocket $socket]
}

proc readSocket {socket} {
  while {[gets $socket line] >= 0} {
    puthelp "PRIVMSG $::Chan :$line"
  }
  if {[eof $socket]} {
    close $socket
  }
}
Finally, a hint for future coding, stay away from the variable name "args", and you won't have to do all this string<->list juggling you are doing. Eggdrop bindings always call the associated command with a fixed number of arguments for each kind of binding, so you don't need to accept arbitrary number of arguments.
NML_375
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I have posted a similar thread not too long ago, similarly discussing the EOF/Timeout party line event with nml375.

http://forum.egghelp.org/viewtopic.php?t=16877

It does seem likely that the event is caused by failure to respond to an identd request made by the destination bot. I can tell you that the event occurs irrespective of whether you use connect/control or native Tcl sockets (assuming there is no identd daemon to respond). At worst, it simply causes a finite but small delay in connecting.

You can see a screenshot of my script in if you look at the URL I just pasted, it seems to be functioning well. If you are interested, pm me and I will give you an address where you can download it.
I must have had nothing to do
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

arfer, the big difference here, is that we are dealing with server sockets versus listen, not client sockets vs connect. Your case is rather different, as you are required to use listen as you wish the connection to gain access to the dcc partyline, which this case does not require. Hence, the use of server sockets should get rid of those log notices...
NML_375
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Thanks, I wasn't picking that up from the original post.

I did end up using native Tcl sockets. The whole connect/control mechanism seemed sort of 'unfinished' and the documentation erroneous.
I must have had nothing to do
T
TehSky
Voice
Posts: 4
Joined: Wed May 27, 2009 1:52 am

Post by TehSky »

Thank you very much for your help everyone. Unfortunately I am still getting an EOF error with nml375's script. But more was added.
Telnet connection: unknown.mywebsite.com/37874
Timeout/EOF ident connection
Lost telnet connection to telnet@unknown.mywebsite.com/37874
This is what I have on the webserver sending the information.

Code: Select all

#
$ANS = fsockopen('64.85.160.159', 51010);
#
fputs($ANS, $Announce);
#
sleep(8);
#
fclose($ANS);

Long Version: http://txt.srinsr.in/index.php/view/34356603
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

i have some script which i wrote for someone on another forum, this script is sending simple msgs to the eggdrop, you can fix it for yourself:

here is 'eggsend.php' (file name should be the same like in <form> action and in header()):

Code: Select all

<?php
//eggdrop host port
        $egg_port = 1234;
//eggdrop host ip
        $egg_ip = '10.0.1.10';

        if (isset($_POST['message'])) {
                $msg = $_POST['message'];

                $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
                socket_connect($sock, $egg_ip, $egg_port) or die ('can\'t connect!');
                socket_write($sock, $msg);
                socket_close($sock);
                header("Location: ./eggsend.php");
        }

        echo "<form action='eggsend.php' method='POST'>";
                echo "<input type='text' name='message' cols='20'><br>";
                echo "<input type='submit' value='send'>";
        echo "</form>";
?>
~
here is script for eggdrop:

Code: Select all

set output_chan "#channel"

# eggdrop port to bind
set port 1234
# eggdrop ip to bind
set host 10.0.1.10

set serverSocket [socket -server main -myaddr $host $port]

proc main { sock host port } {
        fconfigure $sock -buffering line
        fileevent $sock readable [action $sock $host $port]
}

proc action { chan host port } {
        global output_chan

        if {![eof $chan]} {
                set soc_data [gets $chan]

                if {$soc_data != ""} {
                        putquick "PRIVMSG $output_chan :$host | $port | $soc_data"
                }
        } {
                close $chan
        }
}

putlog "sock-server.tcl"
i sent: "lala" through page

bot on chan:
19:54:54 < botty> lala
about your problem, maybe bot is getting timeout cause your php script is holding connection to long?

in those scripts, you are sending information just once, i mean : connect -> send one line -> disconnect, there is no holding of connection

don't know how many data your php script is sending at one time, maybe fix it or something and make it like this "send" script, connect -> announce -> disconnect, and after another connect -> announce -> disconnect

/edit/

just try to load my tcl script to your eggdrop, set up proper ip and port and after change in your php script:

Code: Select all

$ANS = fsockopen('64.85.160.159', 51010);
fputs($ANS, $Announce);
sleep(8);
fclose($ANS);
to:

Code: Select all

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($sock, '64.85.160.159', 51010) or die ('can\'t connect!');
socket_write($sock, $msg);
socket_close($sock);
and check it, use this php script in proper way :)
bot should write announce to the chan,
for tests, you can try to use short message: socket_write($sock, "test me");
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Did you remember to do a complete restart of your eggdrop, in order to remove the old code? A simple .rehash would not suffice in this case.
NML_375
T
TehSky
Voice
Posts: 4
Joined: Wed May 27, 2009 1:52 am

Post by TehSky »

[18:39] couldn't open socket: address already in use
while executing
"socket -server main -myaddr $host $port"
invoked from within
"set serverSocket [socket -server main -myaddr $host $port]"
(file "scripts/announce.tcl" line 8)
invoked from within
"source scripts/announce.tcl"
(file "eggdrop.conf" line 1337)
[18:39] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
From the SSH when trying to load eggdrop with your script. Announce .tcl = The Script. @tomekk
nml375 wrote:Did you remember to do a complete restart of your eggdrop, in order to remove the old code? A simple .rehash would not suffice in this case.
Yes I did. But after using tomekk's changes to the php, I got a Lost Connection while resolving hostname.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Then you did either not fully restart your eggdrop, or you are loading several of these scripts at once. If you do see that ident/EOF error, that means you've still got that "listen ¤Port script listenb" line lying around somewhere.

"Couldn't open socket: address already in use" means just that, there is already some process listening on that ip:port. As such, you cannot create a new server socket with that very same address. This again suggests you did not remove that old "listen-based" script.

Considering the orientation of your php-script, I'm not sure how much further help can be given at this forum.
NML_375
T
TehSky
Voice
Posts: 4
Joined: Wed May 27, 2009 1:52 am

Post by TehSky »

Yep, figures. Anyways, there is no listenb sitting anywhere and there is only one script.

Thanks for the help you gave I guess.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Change the port.
Have you ever read "The Manual"?
p
putyn
Voice
Posts: 2
Joined: Mon Feb 07, 2011 6:39 pm

Post by putyn »

hey i know that this is an old topic but i really hope someone could help me
what i want to do is similar to this send data from php to the eggdrop but after that i need eggdrop to send some data back back to the php script

any idea would be appreciated
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

user had posted some interesting stuff in "socket api - nonblocking tcp made easy", worth reading. You should open your own topic and refer to this topic to give it as an example.
Once the game is over, the king and the pawn go back in the same box.
Post Reply