<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/19429" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2013-05-28T00:50:46-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/19429</id>

		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2013-05-28T00:50:46-04:00</updated>

		<published>2013-05-28T00:50:46-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101588#p101588</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101588#p101588"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101588#p101588"><![CDATA[
I've read  in a hurry something about PHP and assumed it's fetching something from a web server. But my first suggestion, meaning user's code, should be useful.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Tue May 28, 2013 12:50 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2013-05-27T18:19:53-04:00</updated>

		<published>2013-05-27T18:19:53-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101587#p101587</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101587#p101587"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101587#p101587"><![CDATA[
Too many "gets" in there, but otherwise fine.<br><br>You do need to read the last line (with gets or read) in order for "eof" to return true, but the fileevent will also fire if there is an eof-condition on the channel. Thus, both ways will work well.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Mon May 27, 2013 6:19 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[speechles]]></name></author>
		<updated>2013-05-27T18:04:08-04:00</updated>

		<published>2013-05-27T18:04:08-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101586#p101586</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101586#p101586"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101586#p101586"><![CDATA[
<div class="codebox"><p>Code: </p><pre><code># port for your script you want to listen on (you need to set same port in php script)set botlisten(port) "16384"set botlisten(ip) "127.0.0.1"#Bot listen password. This currently isnt used its only listening to the localhost so no external siglnals can get to it. use only if hosting on a different serverset botlisten(password) ""# channel you want to send output toset botlisten(devchan) "#Admins"if {![info exists serverSocket]} {   set serverSocket [socket -server main -myaddr $botlisten(ip) $botlisten(port)]}proc main { sock host port } {   fconfigure $sock -buffering line   fileevent $sock readable [action $sock $host $port]} proc action { chan host port } {   global botlisten   set soc_data [gets $chan]   if {![eof $chan]} {      outputAction $soc_data $botlisten(devchan)      set soc_data [gets $chan]   } else {      outputAction $soc_data $botlisten(devchan)      close $chan   }}proc outputAction { soc_data chan } {   putlog $soc_data   if {[string length $soc_data]} {      #This Relays what ever the bot is sending to the selected channel, this could also be a user       putquick "PRIVMSG $chan :$soc_data"   }   }</code></pre></div>I always thought you had to [gets] before you could detect eof. So here's my take on what it should look like.. haw <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_wink.gif" width="15" height="15" alt=";)" title="Wink"><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8138">speechles</a> — Mon May 27, 2013 6:04 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2013-05-27T13:24:25-04:00</updated>

		<published>2013-05-27T13:24:25-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101584#p101584</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101584#p101584"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101584#p101584"><![CDATA[
Actually...<br>In this rather trivial example, you might just be better off using eggdrop's own socket handling: listen, and control<br><div class="codebox"><p>Code: </p><pre><code>listen $::botlisten(port) acceptConnectionproc acceptConnection {idx} {  control $idx readLine}proc readLine {idx text} {  if {$text != ""} {    putquick "PRIVMSG $::botlisten(devchan) :$text"  }}</code></pre></div>The downside would be that you can't directly control which IP "listen" will use (you can control it indirectly by using the ::my_ip and/or ::my_hostname variables, though they affect all sockets opened by eggdrop).<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Mon May 27, 2013 1:24 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2013-05-27T13:09:19-04:00</updated>

		<published>2013-05-27T13:09:19-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101583#p101583</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101583#p101583"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101583#p101583"><![CDATA[
It does seem a little scary sending unauthenticated data directly to the irc server:<div class="codebox"><p>Code: </p><pre><code>putquick "$soc_data"</code></pre></div>Although you are listening to the loopback interface, anyone using that machine would still be able to connect to that port. If this is a private server (not VPS), where you are in full control of how accesses the server, I guess it would'nt be that horrible - yet still worth mentioning...<br><br>As for the opening of the listen-socket, it should remain open for the duration of the tcl interpreter, so there should be no need to re-open it on a .rehash (hence the error you get). I don't quite recall if it'll persist through .restart, though I do know that the ::serveSocket variable will not.<br><br>If dirty's suggestion works for you, go with it. Looks proper enough..<br><br>As for the catch command, it's use is not so difficult;<br>First argument is a command string (be aware of "double evaluations" though).<br>The second (optional) argument is the name of a variable holding either the error code (if TCL_ERROR), or the result of the command (if TCL_OK);<div class="codebox"><p>Code: </p><pre><code>catch {socket -server main -myaddr $botlisten(ip) $botlisten(port)} serverSocket</code></pre></div>If you'd like to test whether the command was successful, add an if-block;<div class="codebox"><p>Code: </p><pre><code>if {[catch {socket -server main -myaddr $botlisten(ip) $botlisten(port)} serverSocket]} {  putlog "Unable to open listening port: $serverSocket"}</code></pre></div>As for ceasar's suggestion, the http-package will not work, as you obviously are not fetching web pages...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Mon May 27, 2013 1:09 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[caesar]]></name></author>
		<updated>2013-05-27T05:43:52-04:00</updated>

		<published>2013-05-27T05:43:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101581#p101581</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101581#p101581"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101581#p101581"><![CDATA[
Or how about checking <strong class="text-strong"><a href="http://forum.egghelp.org/profile.php?mode=viewprofile&amp;u=2878" class="postlink">user</a></strong>'s <a href="http://forum.egghelp.org/viewtopic.php?p=82212" class="postlink">socket api - nonblocking tcp made easy</a>?<br><br>But, if you are fetching some info off a web page, why don't you just use http package instead?<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=187">caesar</a> — Mon May 27, 2013 5:43 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[dirty]]></name></author>
		<updated>2013-05-26T16:06:33-04:00</updated>

		<published>2013-05-26T16:06:33-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101579#p101579</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101579#p101579"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101579#p101579"><![CDATA[
Try this:<br><div class="codebox"><p>Code: </p><pre><code>if {![info exists serverSocket]} {        set serverSocket [socket -server main -myaddr $botlisten(ip) $botlisten(port)]}</code></pre></div>Instead of this:<br><div class="codebox"><p>Code: </p><pre><code>set serverSocket [socket -server main -myaddr $botlisten(ip) $botlisten(port)]</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12189">dirty</a> — Sun May 26, 2013 4:06 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[tintin]]></name></author>
		<updated>2013-05-26T08:04:03-04:00</updated>

		<published>2013-05-26T08:04:03-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=101577#p101577</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=101577#p101577"/>
		<title type="html"><![CDATA[Sockets and rehashing]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=101577#p101577"><![CDATA[
So once again I'm having some issues, going somewhat out of my depth with coding, but hey thats how we learn.<br><br>I wrote/borrowed parts to this script that announces data to channels of posts reports so on and so forth from the forums, there is no real problem with that part. Where the issue lies is when the bot is rehashed or restarted it can't reopen the port because its already open. <br><br>So the part that is out of my depth is getting the script not to kill the bot just because it can't open the port again and either closing or just start listening again whichever better.<br><br>Here is all the relevant code to the script. <br><div class="codebox"><p>Code: </p><pre><code># port for your script you want to listen on (you need to set same port in php script)set botlisten(port) "16384"set botlisten(ip) "127.0.0.1"#Bot listen password. This currently isnt used its only listening to the localhost so no external siglnals can get to it. use only if hosting on a different serverset botlisten(password) ""# channel you want to send output toset botlisten(devchan) "#Admins"set serverSocket [socket -server main -myaddr $botlisten(ip) $botlisten(port)]proc main { sock host port } {fconfigure $sock -buffering linefileevent $sock readable [action $sock $host $port]}proc action { chan host port } {global botlistenif {![eof $chan]} {                set soc_data [gets $chan] putlog $soc_data                if {$soc_data != ""} {                         #This Relays what ever the bot is sending to the selected channel, this could also be a userputquick "PRIVMSG $botlisten(devchan) :$soc_data" putquick "$soc_data"                }         } {                 close $chan         } } </code></pre></div>I'm guessing I have to use the catch command but I can't quite get my head around it. However I am open to any different ways you guys might suggest. <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>Thanks for the help, its always appreciated<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=12187">tintin</a> — Sun May 26, 2013 8:04 am</p><hr />
]]></content>
	</entry>
	</feed>
