<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TCL - Devhour</title>
	<atom:link href="https://www.devhour.net/category/tcl/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.devhour.net</link>
	<description>Taking time to write about development</description>
	<lastBuildDate>Tue, 12 Mar 2024 10:00:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.2</generator>

<image>
	<url>https://www.devhour.net/wp-content/uploads/2024/03/cropped-devhourlogo-32x32.png</url>
	<title>TCL - Devhour</title>
	<link>https://www.devhour.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Sending messages to an Eggdrop via PHP</title>
		<link>https://www.devhour.net/sending-messages-to-an-eggdrop-via-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sending-messages-to-an-eggdrop-via-php</link>
					<comments>https://www.devhour.net/sending-messages-to-an-eggdrop-via-php/#respond</comments>
		
		<dc:creator><![CDATA[Jamie]]></dc:creator>
		<pubDate>Thu, 23 May 2013 12:19:00 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[TCL]]></category>
		<category><![CDATA[Dev Hour]]></category>
		<category><![CDATA[Sockets]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://www.devhour.net/?p=22</guid>

					<description><![CDATA[<p>So if you frequent IRC often like I do, you may notice some eggdrop bots displaying messages which come from a website. The most common times you will see this sort of script in action is when they are hooked into forum posts or torrent listings. You will more than likely have seen messages saying [&#8230;]</p>
<p>The post <a href="https://www.devhour.net/sending-messages-to-an-eggdrop-via-php/">Sending messages to an Eggdrop via PHP</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>So if you frequent IRC often like I do, you may notice some eggdrop bots displaying messages which come from a website. The most common times you will see this sort of script in action is when they are hooked into forum posts or torrent listings. You will more than likely have seen messages saying “New forum topic…X Y by Z” or “[PRE] such.and.such.movie.torrent”.&nbsp;Today I’m going to show you how to do that by sending messages to an eggdrop via PHP.</p>



<p>It’s actually relatively easy (as you are about to see) and really only requires a few lines of PHP code on the web end and the same again in TCL on the eggdrop. The general idea is that the eggdrop will open up a socket and sit listening waiting for data to come through before displaying the message. For the PHP end it is as simple as connecting to said socket and sending through some data.</p>



<p>First things first, the TCL script sock-listen.tcl:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="set output_chan &quot;#chan&quot;
# eggdrop port to bindset 
port 7878
# eggdrop ip to bind
set host xxx.xxx.xxx.xxx
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 != &quot;&quot;} {
      putquick &quot;PRIVMSG $output_chan :$host | $port $soc_data&quot;
    }
  } { close $chan }
}
putlog &quot;sock-listen.tcl loaded&quot;" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">set</span><span style="color: #575279"> output_chan </span><span style="color: #EA9D34">&quot;#chan&quot;</span></span>
<span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> eggdrop port to bindset </span></span>
<span class="line"><span style="color: #575279">port </span><span style="color: #D7827E">7878</span></span>
<span class="line"><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> eggdrop ip to bind</span></span>
<span class="line"><span style="color: #286983">set</span><span style="color: #575279"> host xxx.xxx.xxx.xxx</span></span>
<span class="line"><span style="color: #286983">set</span><span style="color: #575279"> serverSocket [</span><span style="color: #286983">socket</span><span style="color: #575279"> -server main -myaddr </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">host</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">port</span><span style="color: #575279">]</span></span>
<span class="line"><span style="color: #286983">proc</span><span style="color: #575279"> </span><span style="color: #D7827E">main</span><span style="color: #575279"> { sock host port } {</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">fconfigure</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">sock</span><span style="color: #575279"> -buffering line</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">fileevent</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">sock</span><span style="color: #575279"> readable [action </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">sock</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">host</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">port</span><span style="color: #575279">]</span></span>
<span class="line"><span style="color: #575279">}</span></span>
<span class="line"><span style="color: #286983">proc</span><span style="color: #575279"> </span><span style="color: #D7827E">action</span><span style="color: #575279"> { chan host port } {</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">global</span><span style="color: #575279"> output_chan</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">if</span><span style="color: #575279"> {![</span><span style="color: #286983">eof</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #575279">]} {</span></span>
<span class="line"><span style="color: #575279">    </span><span style="color: #286983">set</span><span style="color: #575279"> soc_data [</span><span style="color: #286983">gets</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #575279">]</span></span>
<span class="line"><span style="color: #575279">    </span><span style="color: #286983">if</span><span style="color: #575279"> {</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">soc_data</span><span style="color: #575279"> != </span><span style="color: #EA9D34">&quot;&quot;</span><span style="color: #575279">} {</span></span>
<span class="line"><span style="color: #575279">      putquick </span><span style="color: #EA9D34">&quot;PRIVMSG </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">output_chan</span><span style="color: #EA9D34"> :</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">host</span><span style="color: #EA9D34"> | </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">port</span><span style="color: #EA9D34"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">soc_data</span><span style="color: #EA9D34">&quot;</span></span>
<span class="line"><span style="color: #575279">    }</span></span>
<span class="line"><span style="color: #575279">  } { </span><span style="color: #286983">close</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #575279"> }</span></span>
<span class="line"><span style="color: #575279">}</span></span>
<span class="line"><span style="color: #575279">putlog </span><span style="color: #EA9D34">&quot;sock-listen.tcl loaded&quot;</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">TCL</span></div>



<p>That’s it! Simple enough. Create a socket which will sit and listen waiting for something to connect and send through data. Once a connection is made call the ‘action’ function which will &nbsp;send a message to the channel with the host, port and socket data.</p>



<p>To get that up and running just copy sock-listen.tcl into the scripts folder of your eggdrop and include it in your config file. Don’t forget to change the channel, IP address and port. Once you rehash or reconnect the bot the socket will automatically start listening.</p>



<p>Now to send messages from PHP is very straight forward, just open up a socket and connect to the IP/port specified in the TCL script. Send through a message and watch it come out the other end (IRC channel).</p>



<p>To do this we create a php file called send.php and place the following code:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="&lt;?php
//eggdrop port
$egg_port = 7878;
//eggdrop ip
$egg_ip = 'xxx.xxx.xxx.xxx';
// message to send
$msg = 'Sent from a PHP page';
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_connect($sock, $egg_ip, $egg_port) or die ('failed to connect!');
socket_write($sock, $msg);
socket_close($sock);
?&gt;" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">&lt;?php</span></span>
<span class="line"><span style="color: #797593; font-style: italic">//</span><span style="color: #9893A5; font-style: italic">eggdrop port</span></span>
<span class="line"><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_port </span><span style="color: #286983">= 7878</span><span style="color: #797593">;</span></span>
<span class="line"><span style="color: #797593; font-style: italic">//</span><span style="color: #9893A5; font-style: italic">eggdrop ip</span></span>
<span class="line"><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_ip </span><span style="color: #286983">= </span><span style="color: #EA9D34">&#39;xxx.xxx.xxx.xxx&#39;</span><span style="color: #797593">;</span></span>
<span class="line"><span style="color: #797593; font-style: italic">//</span><span style="color: #9893A5; font-style: italic"> message to send</span></span>
<span class="line"><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">msg </span><span style="color: #286983">= </span><span style="color: #EA9D34">&#39;Sent from a PHP page&#39;</span><span style="color: #797593">;</span></span>
<span class="line"><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock </span><span style="color: #286983">=</span><span style="color: #D7827E"> socket_create</span><span style="color: #797593">(</span><span style="color: #286983">AF_INET</span><span style="color: #797593">,</span><span style="color: #286983"> SOCK_STREAM</span><span style="color: #797593">,</span><span style="color: #286983"> SOL_TCP</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #B4637A; font-style: italic">socket_connect</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock</span><span style="color: #797593">,</span><span style="color: #286983"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_ip</span><span style="color: #797593">,</span><span style="color: #286983"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_port</span><span style="color: #797593">)</span><span style="color: #D7827E"> or die </span><span style="color: #797593">(</span><span style="color: #EA9D34">&#39;failed to connect!&#39;</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #B4637A; font-style: italic">socket_write</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock</span><span style="color: #797593">,</span><span style="color: #286983"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">msg</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #B4637A; font-style: italic">socket_close</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #286983">?&gt;</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">PHP</span></div>



<p>Again, easy enough. Make sure you set the correct IP address and port and then upload the file. Point your browser to it and watch the magic happen. You should see the following message appear on the IRC channel:</p>



<p><strong>xxx.xxx.xxx.xxx | 7878 | Sent from a PHP page</strong></p>



<p>To make it easier I’ve added a small form which will allow you to customize the message to your liking. Again send.php:</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="&lt;?php
//eggdrop port$egg_port = 7878;
//eggdrop ip
$egg_ip = 'xxx.xxx.xxx.xxx';

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 ('failed to connect!');
  socket_write($sock, $msg);
  socket_close($sock);
  header(&quot;Location: send.php&quot;);
}
?&gt;
&lt;form action='send.php' method='POST'&gt;
&lt;input type='text' name='message' cols='20'&gt;&lt;br&gt;
&lt;input type='submit' value='send'&gt;
&lt;/form&gt;" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">&lt;?php</span></span>
<span class="line"><span style="color: #797593; font-style: italic">//</span><span style="color: #9893A5; font-style: italic">eggdrop port$egg_port = 7878;</span></span>
<span class="line"><span style="color: #797593; font-style: italic">//</span><span style="color: #9893A5; font-style: italic">eggdrop ip</span></span>
<span class="line"><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_ip </span><span style="color: #286983">= </span><span style="color: #EA9D34">&#39;xxx.xxx.xxx.xxx&#39;</span><span style="color: #797593">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #286983">if </span><span style="color: #797593">(</span><span style="color: #B4637A; font-style: italic">isset</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">_POST</span><span style="color: #797593">[</span><span style="color: #EA9D34">&#39;message&#39;</span><span style="color: #797593">]))</span><span style="color: #286983"> </span><span style="color: #797593">{</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">msg </span><span style="color: #286983">= </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">_POST</span><span style="color: #797593">[</span><span style="color: #EA9D34">&#39;message&#39;</span><span style="color: #797593">];</span><span style="color: #286983">   </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock </span><span style="color: #286983">=</span><span style="color: #D7827E"> socket_create</span><span style="color: #797593">(</span><span style="color: #286983">AF_INET</span><span style="color: #797593">,</span><span style="color: #286983"> SOCK_STREAM</span><span style="color: #797593">,</span><span style="color: #286983"> SOL_TCP</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #B4637A; font-style: italic">socket_connect</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock</span><span style="color: #797593">,</span><span style="color: #286983"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_ip</span><span style="color: #797593">,</span><span style="color: #286983"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">egg_port</span><span style="color: #797593">)</span><span style="color: #D7827E"> or die </span><span style="color: #797593">(</span><span style="color: #EA9D34">&#39;failed to connect!&#39;</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #B4637A; font-style: italic">socket_write</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock</span><span style="color: #797593">,</span><span style="color: #286983"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">msg</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #B4637A; font-style: italic">socket_close</span><span style="color: #797593">(</span><span style="color: #797593; font-style: italic">$</span><span style="color: #575279; font-style: italic">sock</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #B4637A; font-style: italic">header</span><span style="color: #797593">(</span><span style="color: #EA9D34">&quot;Location: send.php&quot;</span><span style="color: #797593">);</span></span>
<span class="line"><span style="color: #797593">}</span></span>
<span class="line"><span style="color: #286983">?&gt;</span></span>
<span class="line"><span style="color: #286983">&lt;form action=</span><span style="color: #EA9D34">&#39;send.php&#39;</span><span style="color: #286983"> method=</span><span style="color: #EA9D34">&#39;POST&#39;</span><span style="color: #286983">&gt;</span></span>
<span class="line"><span style="color: #286983">&lt;input type=</span><span style="color: #EA9D34">&#39;text&#39;</span><span style="color: #286983"> name=</span><span style="color: #EA9D34">&#39;message&#39;</span><span style="color: #286983"> cols=</span><span style="color: #EA9D34">&#39;20&#39;</span><span style="color: #286983">&gt;&lt;</span><span style="color: #D7827E">br</span><span style="color: #286983">&gt;</span></span>
<span class="line"><span style="color: #286983">&lt;input type=</span><span style="color: #EA9D34">&#39;submit&#39;</span><span style="color: #286983"> value=</span><span style="color: #EA9D34">&#39;send&#39;</span><span style="color: #286983">&gt;</span></span>
<span class="line"><span style="color: #286983">&lt;/form&gt;</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">PHP</span></div>



<p>It isn’t all that secure but gives you a general idea of what you can do.&nbsp;To implement it into the examples I posted at the start all you really need to do is edit the submit/post PHP files and place the socket code above with a customized message in.</p>



<p>This isn’t limited to just PHP. Something similar could easily be set up in a number or any other languages as well. Simply by opening the socket and sending the data.</p>



<p>Something simple for &nbsp;the day. Have a play around and let me know if you make any improvements. Feel free to ask any questions, I’ll do my best to answer them&nbsp;<img decoding="async" src="https://web.archive.org/web/20150313032438im_/https://www.devhour.net/wp-includes/images/smilies/icon_smile.gif" alt=":)"></p>



<p>Also feel free to follow me on twitter: <a href="https://twitter.com/JAGracie">@JAGracie</a></p><p>The post <a href="https://www.devhour.net/sending-messages-to-an-eggdrop-via-php/">Sending messages to an Eggdrop via PHP</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.devhour.net/sending-messages-to-an-eggdrop-via-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Shoutcast TCL script for eggdrops</title>
		<link>https://www.devhour.net/shoutcast-tcl-script-for-eggdrops/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shoutcast-tcl-script-for-eggdrops</link>
					<comments>https://www.devhour.net/shoutcast-tcl-script-for-eggdrops/#respond</comments>
		
		<dc:creator><![CDATA[Jamie]]></dc:creator>
		<pubDate>Wed, 17 Apr 2013 12:04:00 +0000</pubDate>
				<category><![CDATA[TCL]]></category>
		<category><![CDATA[EFNet]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[Radio]]></category>
		<category><![CDATA[Shoutcast]]></category>
		<guid isPermaLink="false">https://www.devhour.net/?p=13</guid>

					<description><![CDATA[<p>Update (14/02/2014):Some folks over at http://www.247drumandbass.com are now utilizing this script on their IRC channel. You should check it out on Quakenet #247drumandbass. Shoutcast TCL Script I was recently approached by a friend to help out with a TCL script for his  Shoutcast radio station. He has an eggdrop running on the EFNet IRC server which acts as an announcer for [&#8230;]</p>
<p>The post <a href="https://www.devhour.net/shoutcast-tcl-script-for-eggdrops/">Shoutcast TCL script for eggdrops</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></description>
										<content:encoded><![CDATA[<p><strong>Update (14/02/2014):<br></strong>Some folks over at <a href="http://www.247drumandbass.com/" target="_blank" rel="noreferrer noopener">http://www.247drumandbass.com</a> are now utilizing this script on their IRC channel. You should check it out on <a href="https://www.quakenet.org/" target="_blank" rel="noreferrer noopener">Quakenet</a> #247drumandbass.</p>



<p><strong>Shoutcast TCL Script</strong></p>



<p>I was recently approached by a friend to help out with a TCL script for his  Shoutcast radio station. He has an <a href="https://www.egghelp.org/">eggdrop</a> running on the EFNet IRC server which acts as an announcer for the radio station. It gives users the ability to call commands such as what song is currently playing, what is playing next and  general advertising of the station.</p>



<p>Shoutcast have recently had a big upgrade to their software and in particular the admin interface.&nbsp;While this is always a welcome edition due to new features and bug fixes one of the downsides is that scripts that use the old software tend to be made null and void. In particular changes to the XML and the inclusion of stream IDs broke most of the old TCL scripts.</p>



<p>I wouldn’t say I am particularly skilled in the TCL language but I’m always willing to give something a go and by looking at the old scripts and the newer admin interface I did manage to make a fairly feature rich Shoutcast announcement script.</p>



<p>The below code block outlines how I made the basic commands by using an http connection to browse to the admin xml webpage and then using an exceptional TCL package called <a href="https://tdom.github.io/">tDom</a> to extract particular XML nodes and their inline text. This text is then displayed to an IRC channel.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="package require http
package require tdom

bind pub -|- !song currsong

proc currplaying {nick uhost hand chan arg} { 
  global siteurl djchan radiochan adminpass  
  # Create an HTTP request to the admin xml page :
  :http::config -useragent &quot;Mozilla/5.0; Shoutinfo&quot; 
  set http_req [::http::geturl http://$siteurl:8000/admin.cgi?pass=$adminpass&amp;sid=1&amp;mode=viewxml&amp;page=0 -timeout 2000]
  if {[::http::status $http_req] != &quot;ok&quot;} { 
    putnow &quot;PRIVMSG $chan :Stream is unavailable&quot;; 
  } 
  set data [::http::data $http_req] ::http::cleanup $http_req  
  # Create dom document 
  set doc [dom parse $data] set xmlNodes [$doc documentElement]  
  # Grab Stream status from XML to check if the station is currently online or not 
  if {[[$xmlNodes selectNodes /SHOUTCASTSERVER/STREAMSTATUS/text()] data] == &quot;1&quot;} {  
    # If it is online display a message to the channel the current playing song 
    putnow &quot;PRIVMSG $chan :\002Current Song\002: [[$xmlNodes selectNodes /SHOUTCASTSERVER/SONGTITLE/text()] data]&quot; 
  } else {    
    # Otherwise let the user kmow the server is offline 
    if {$chan != $djchan} { 
      putnow &quot;PRIVMSG $chan :Server status is offline...&quot; 
    } else { 
      putnow &quot;NOTICE $nick :Server status is offline...&quot; 
    }
  }
}" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">package</span><span style="color: #575279"> require http</span></span>
<span class="line"><span style="color: #286983">package</span><span style="color: #575279"> require tdom</span></span>
<span class="line"></span>
<span class="line"><span style="color: #575279">bind pub -|- !song currsong</span></span>
<span class="line"></span>
<span class="line"><span style="color: #286983">proc</span><span style="color: #575279"> </span><span style="color: #D7827E">currplaying</span><span style="color: #575279"> {nick uhost hand chan arg} { </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">global</span><span style="color: #575279"> siteurl djchan radiochan adminpass  </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Create an HTTP request to the admin xml page :</span></span>
<span class="line"><span style="color: #575279">  :http::config -useragent </span><span style="color: #EA9D34">&quot;Mozilla/5.0; Shoutinfo&quot;</span><span style="color: #575279"> </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">set</span><span style="color: #575279"> http_req [::http::geturl http://</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">siteurl</span><span style="color: #575279">:</span><span style="color: #D7827E">8000</span><span style="color: #575279">/admin.cgi?pass=</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">adminpass</span><span style="color: #575279">&amp;sid=</span><span style="color: #D7827E">1</span><span style="color: #575279">&amp;mode=viewxml&amp;page=</span><span style="color: #D7827E">0</span><span style="color: #575279"> -timeout </span><span style="color: #D7827E">2000</span><span style="color: #575279">]</span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">if</span><span style="color: #575279"> {[::http::status </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">http_req</span><span style="color: #575279">] </span><span style="color: #286983">!=</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;ok&quot;</span><span style="color: #575279">} { </span></span>
<span class="line"><span style="color: #575279">    putnow </span><span style="color: #EA9D34">&quot;PRIVMSG </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #EA9D34"> :Stream is unavailable&quot;</span><span style="color: #575279">; </span></span>
<span class="line"><span style="color: #575279">  } </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">set</span><span style="color: #575279"> data [::http::data </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">http_req</span><span style="color: #575279">] ::http::cleanup </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">http_req</span><span style="color: #575279">  </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Create dom document </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">set</span><span style="color: #575279"> doc [dom parse </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">data</span><span style="color: #575279">] set xmlNodes [</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">doc</span><span style="color: #575279"> documentElement]  </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Grab Stream status from XML to check if the station is currently online or not </span></span>
<span class="line"><span style="color: #575279">  </span><span style="color: #286983">if</span><span style="color: #575279"> {[[</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">xmlNodes</span><span style="color: #575279"> selectNodes /SHOUTCASTSERVER/STREAMSTATUS/text()] data] </span><span style="color: #286983">==</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;1&quot;</span><span style="color: #575279">} {  </span></span>
<span class="line"><span style="color: #575279">    </span><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> If it is online display a message to the channel the current playing song </span></span>
<span class="line"><span style="color: #575279">    putnow </span><span style="color: #EA9D34">&quot;PRIVMSG </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #EA9D34"> :</span><span style="color: #286983">\002</span><span style="color: #EA9D34">Current Song</span><span style="color: #286983">\002</span><span style="color: #EA9D34">: </span><span style="color: #797593">[</span><span style="color: #EA9D34">[</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">xmlNodes</span><span style="color: #EA9D34"> selectNodes /SHOUTCASTSERVER/SONGTITLE/text()</span><span style="color: #797593">]</span><span style="color: #EA9D34"> data]&quot;</span><span style="color: #575279"> </span></span>
<span class="line"><span style="color: #575279">  } </span><span style="color: #286983">else</span><span style="color: #575279"> {    </span></span>
<span class="line"><span style="color: #575279">    </span><span style="color: #797593; font-style: italic">#</span><span style="color: #9893A5; font-style: italic"> Otherwise let the user kmow the server is offline </span></span>
<span class="line"><span style="color: #575279">    </span><span style="color: #286983">if</span><span style="color: #575279"> {</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #575279"> </span><span style="color: #286983">!=</span><span style="color: #575279"> </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">djchan</span><span style="color: #575279">} { </span></span>
<span class="line"><span style="color: #575279">      putnow </span><span style="color: #EA9D34">&quot;PRIVMSG </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #EA9D34"> :Server status is offline...&quot;</span><span style="color: #575279"> </span></span>
<span class="line"><span style="color: #575279">    } </span><span style="color: #286983">else</span><span style="color: #575279"> { </span></span>
<span class="line"><span style="color: #575279">      putnow </span><span style="color: #EA9D34">&quot;NOTICE </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">nick</span><span style="color: #EA9D34"> :Server status is offline...&quot;</span><span style="color: #575279"> </span></span>
<span class="line"><span style="color: #575279">    }</span></span>
<span class="line"><span style="color: #575279">  }</span></span>
<span class="line"><span style="color: #575279">}</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">TCL</span></div>



<p>I won’t go through it line by line as most of it is standard TCL code but I will point out the bits important to this post. Firstly you can see I include two packages. HTTP and tDom. As mentioned previously this allows me to make http calls and then extract and use the XML nodes.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="package require http
package requite tdom" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">package</span><span style="color: #575279"> require http</span></span>
<span class="line"><span style="color: #286983">package</span><span style="color: #575279"> requite tdom</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">TCL</span></div>



<p>Next up  I make an http call to the servers admin interface passing through the $siteurl and $adminpass variables. These are set at the top of the script as global variables. As you can see in the url I am also calling &amp;mode=viewxml to display the output in XML.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="::http::config -useragent &quot;Mozilla/5.0; Shoutinfo&quot; 
set http_req [::http::geturl http://$siteurl:8000/admin.cgi?pass=$adminpass&amp;sid=1&amp;mode=viewxml&amp;page=0 -timeout 2000] 
if {[::http::status $http_req] != &quot;ok&quot;} { 
  putnow &quot;PRIVMSG $chan :Stream is unavailable&quot;; 
} 
set data [::http::data $http_req] ::http::cleanup $http_req" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #575279">::http::config -useragent </span><span style="color: #EA9D34">&quot;Mozilla/5.0; Shoutinfo&quot;</span><span style="color: #575279"> </span></span>
<span class="line"><span style="color: #286983">set</span><span style="color: #575279"> http_req [::http::geturl http://</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">siteurl</span><span style="color: #575279">:</span><span style="color: #D7827E">8000</span><span style="color: #575279">/admin.cgi?pass=</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">adminpass</span><span style="color: #575279">&amp;sid=</span><span style="color: #D7827E">1</span><span style="color: #575279">&amp;mode=viewxml&amp;page=</span><span style="color: #D7827E">0</span><span style="color: #575279"> -timeout </span><span style="color: #D7827E">2000</span><span style="color: #575279">] </span></span>
<span class="line"><span style="color: #286983">if</span><span style="color: #575279"> {[::http::status </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">http_req</span><span style="color: #575279">] </span><span style="color: #286983">!=</span><span style="color: #575279"> </span><span style="color: #EA9D34">&quot;ok&quot;</span><span style="color: #575279">} { </span></span>
<span class="line"><span style="color: #575279">  putnow </span><span style="color: #EA9D34">&quot;PRIVMSG </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #EA9D34"> :Stream is unavailable&quot;</span><span style="color: #575279">; </span></span>
<span class="line"><span style="color: #575279">} </span></span>
<span class="line"><span style="color: #286983">set</span><span style="color: #575279"> data [::http::data </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">http_req</span><span style="color: #575279">] ::http::cleanup </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">http_req</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">TCL</span></div>



<p>Finally I create a Dom document from the returned http data and use that to extract particular nodes.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-bottom-disabled cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#575279;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#faf4ed"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="set doc [dom parse $data]
set xmlNodes [$doc documentElement]
putnow &quot;PRIVMSG $chan :\002Current Song\002: [[$xmlNodes selectNodes /SHOUTCASTSERVER/SONGTITLE/text()] data]&quot;" style="color:#575279;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki rose-pine-dawn" style="background-color: #faf4ed" tabindex="0"><code><span class="line"><span style="color: #286983">set</span><span style="color: #575279"> doc [dom parse </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">data</span><span style="color: #575279">]</span></span>
<span class="line"><span style="color: #286983">set</span><span style="color: #575279"> xmlNodes [</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">doc</span><span style="color: #575279"> documentElement]</span></span>
<span class="line"><span style="color: #575279">putnow </span><span style="color: #EA9D34">&quot;PRIVMSG </span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">chan</span><span style="color: #EA9D34"> :</span><span style="color: #286983">\002</span><span style="color: #EA9D34">Current Song</span><span style="color: #286983">\002</span><span style="color: #EA9D34">: </span><span style="color: #797593">[</span><span style="color: #EA9D34">[</span><span style="color: #797593; font-style: italic">$</span><span style="color: #B4637A; font-style: italic">xmlNodes</span><span style="color: #EA9D34"> selectNodes /SHOUTCASTSERVER/SONGTITLE/text()</span><span style="color: #797593">]</span><span style="color: #EA9D34"> data]&quot;</span></span></code></pre><span style="display:flex;align-items:flex-end;padding:10px;width:100%;justify-content:flex-end;background-color:#faf4ed;color:#625c88;font-size:12px;line-height:1;position:relative">TCL</span></div>



<p>This similar technique is also used to display the next song, current bitrate, current listeners which are all grabbed from the XML output. Other features of the script include:</p>



<ul>
<li>Topic changes for when the radio station comes online/goes offline</li>



<li>A periodic timer to check and show song changes</li>



<li>A timer to check if the peak listeners changes</li>



<li>Commands to show current song, next song, server status, radio url and radio url</li>



<li>Ability for operators to disconnect current dj</li>



<li>Ability for users to request songs (which are displayed to a separate dj channel)</li>



<li>List the 10 previous songs</li>



<li>Display the current and peak listeners</li>
</ul>



<p>I add the script to my github page soon, so feel free to check it out and replace any old scripts you may have. I’m always up for a challenge so if you have any ideas for new features drop a comment or tweet and I’ll be happy to discuss it.</p>



<p>If you want to see it in action jump on EFNet and join the #android-radio channel.</p><p>The post <a href="https://www.devhour.net/shoutcast-tcl-script-for-eggdrops/">Shoutcast TCL script for eggdrops</a> first appeared on <a href="https://www.devhour.net">Devhour</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.devhour.net/shoutcast-tcl-script-for-eggdrops/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
