mIRC socket read text from url - chat

I have been trying to use mIRC to read a short line of text from a url and echo/ write it in to chat when someone types !test.
The socket host is XXXXXXXXXXXX because it is running on wamp on my PC.
The data on the page is not long, Here is the page.
SnOwEfLaKe's Battlefield 4(pc) Stats | Rank: 140 | Kills: 66393 | K/D:
2 | W/L: 1.38 | Score: 60646533 | Time Played: 53.27 days | Accuracy:
14.17%
alias demo {
var %user = $$1, %chan = $2, %sockname = demo. $+ $ticks
hfree -w %sockname | hmake %sockname
hadd %sockname user %user
hadd %sockname chan %chan
hadd %sockname host XXXXXXXXX
hadd %sockname port 80
hadd %sockname request /nb/bf4stats.php
sockopen -e %sockname $hget(%sockname,host) $hget(%sockname,port)
}
on *:text:!test:#:{
demo #
}
on *:sockopen:demo.*: {
var %<< = sockwrite -nt $sockname
%<< GET $hget($sockname,request) HTTP/1.0
%<< Host: $sock($sockname).addr
%<< $crlf
}
on *:sockread:demo.*: {
var %header, %content
if (!$hget($sockname,header.complete)) {
sockread %header
while (%header != $null) {
if (HTTP/* 2?? * iswm %header) { hadd $sockname following $true }
elseif (HTTP/* 4?? * iswm %header) { hadd $sockname following $false }
;echo -ag %header
sockread %header
}
if ($sockbr) hadd $sockname header.complete $true
}
if ($hget($sockname,header.complete)) {
while ($sockbr) {
sockread -f %content
;if (%content != $null) echo -ag %content
}
}
}
on *:sockclose:demo.*:{
if ($hget($sockname,following)) { var %msg = Following }
else { var %msg = Not following }
if ($hget($sockname,chan)) { msg $v1 %msg }
else { echo -ag %msg }
hfree $sockname
}
I am not having any luck

I figured out how to do it.
on *:TEXT:*:#blood_wolf89:{
if ($strip($1) === !bf4stats) {
var %user = $iif($2, $strip($2), Blood_Wolff89)
var %urlSafeUser = $regsubex(%user, /[^a-z\d_-]/gi, % $+ $base($asc(\t), 10, 16, 2))
var %url = http://api.bf4stats.com/api/playerInfo?plat=pc&name= $+ %urlSafeuser
JSONOpen -ud bf4stat %url
var %name = $JSON(bf4stat, player, name)
var %rank = $JSON(bf4stat, player, rank, nr)
var %score = $JSON(bf4stat, player, score)
var %kills = $JSON(bf4stat, stats, kills)
var %deaths = $JSON(bf4stat, stats, deaths)
var %kdRatio = $round($calc(%kills / %deaths), 2)
var %wins = $JSON(bf4stat, stats, numWins)
var %losses = $JSON(bf4stat, stats, numLosses)
var %wlRatio = $round($calc(%wins / %losses), 2)
var %played = $duration($JSON(bf4stat, stats, timePlayed))
var %hits = $JSON(bf4stat, stats, shotsHit)
var %misses = $JSON(bf4stat, stats, shotsFired)
var %accuracy = $round($calc(%hits / %misses * 100),2) $+ %
if ((%user == %name) || (%urlSafeuser == %name)) { msg # [BF4Stats]: %name $+ 's Battlefield 4(PC) Stats $(|,0) Rank: %rank $(|,0) Kills: %kills $(|,0) K/D: %kdRatio $(|,0) W/L: %wlRatio $(|,0) Score: %score $(|,0) Time Played: %played $(|,0) Accuracy: %accuracy }
if ((%urlSafeuser !== %name)) { msg # [BF4Stats]: Invalid Battlefield 4 Name. }
}
}
And after that I have a JSON Parser that I have gotten from here: http://hawkee.com/snippet/10194

Related

Add a pause before further execution in mIRC

So I've been thinking for like over an hour but did not arrive any conclusion with this script. I basically am trying to add a "status check" for 3 IRC servers via mIRC sockets. The problem I'm facing is that the execution jumps over to the next step without the socket connection being completed hence it returns a false value i.e Offline.
I tried using timer before goto commands but that returns ' not found'
Code:
on *:text:!stats:#: {
sockopen IRCAurora aurora.irchound.tk 6667
sockopen IRCKepler kepler.irchound.tk 6667
sockopen IRCJupiter jupiter.irchound.tk 6667
sockpause IRCAurora
sockpause IRCKepler
sockpause IRCJupiter
:true
msg $chan ----STATUS----
goto check1
halt
:check1
if ($sock(IRCAurora,pause) == 1) {
msg $chan 1Aurora - 9Online
}
else {
msg $chan 1Aurora - 4Offline
}
goto check2
halt
:check2
if ($sock(IRCJupiter,pause) == 1) {
msg $chan 1Jupiter - 9Online
}
else {
msg $chan 1Jupiter - 4Offline
}
goto check3
halt
:check3
if ($sock(IRCKepler,pause) == 1) {
msg $chan 1Kepler - 9Online
}
else {
msg $chan 1Kepler - 4Offline
}
halt
}
I know one solution is simply set up a php bot, but I want it on mIRC.
Any help would be appreciated. Thanks in advance.
Never mind .. I've already found the solution for the problem. Simple needed to add an alias function (that replies if socket pause if true / false) with a timer.
Solved code:
on *:text,loaddservers:#: {
if (%admin. [ $+ [ $nick ] ] = 1) {
msg $chan All default servers are now being loaded.
set %server1 aurora.irchound.tk
set %server2 jupiter.irchound.tk
set %server3 kepler.irchound.tk
}
else {
msg $chan Access denied.
}
}
;Create socket connection to servers on trigure.
on *:text:,status*:#: {
if ($2 = all) {
sockopen IRCAurora %server1 6667
sockopen IRCKepler %server2 6667
sockopen IRCJupiter %server3 6667
set %chan $chan
msg $chan Connecting to servers...
msg $chan >>>Status of all servers<<<
timer2 1 5 checkall
}
if ($2 = aurora) {
sockopen IRCAurora %server1 6667
set %chan $chan
msg $chan Connecting to server $2 $+ ...
timerAURORA 1 5 checkaurora
}
if ($2 = kepler) {
sockopen IRCKepler %server2 6667
set %chan $chan
msg $chan Connecting to server $2 $+ ...
timerKEPLER 1 5 checkkepler
}
if ($2 = jupiter) {
sockopen IRCJupiter %server3 6667
set %chan $chan
msg $chan Connecting to server $2 $+ ...
timerJUPITER 1 5 checkjupiter
}
}
;Aliases for each server status response.
alias checkaurora {
if ($sock(IRCAurora,pause) == 1) {
msg %chan 1Aurora - 9Online
}
else {
msg %chan 1Aurora - 4Offline
}
halt
}
alias checkjupiter {
if ($sock(IRCJupiter,pause) == 1) {
msg %chan 1Jupiter - 9Online
}
else {
msg %chan 1Jupiter - 4Offline
}
halt
}
alias checkkepler {
if ($sock(IRCKepler,pause) == 1) {
msg %chan 1Kepler - 9Online
}
else {
msg %chan 1Kepler- 4Offline
}
halt
}
alias checkall {
if ($sock(IRCAurora,pause) == 1) {
msg %chan 1Aurora - 9Online
}
else {
msg %chan 1Aurora - 4Offline
}
goto check2
halt
:check2
if ($sock(IRCJupiter,pause) == 1) {
msg %chan 1Jupiter - 9Online
}
else {
msg %chan 1Jupiter - 4Offline
}
goto check3
halt
:check3
if ($sock(IRCKepler,pause) == 1) {
msg %chan 1Kepler - 9Online
}
else {
msg %chan 1Kepler - 4Offline
}
}
NOTE: I've excluded some part of the script that's not related to the question.. so you may find some undefined variables.

socket_select method in php

could any one help me to understand the following example about handling multiple connection in PHP socket programming.
I need just to explain for me these steps
if(socket_select($read , $write , $except , null) === false)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not listen on socket : [$errorcode] $errormsg \n");
}
//if ready contains the master socket, then a new connection has come in
if (in_array($sock, $read))
{
}
really I cant understand what happen in those steps.
this is the full example :
error_reporting(~E_NOTICE);
set_time_limit (0);
$address = "0.0.0.0";
$port = 6000;
$max_clients = 10;
if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
// Bind the source address
if( !socket_bind($sock, $address , 5000) )
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg \n");
}
echo "Socket bind OK \n";
if(!socket_listen ($sock , 10))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not listen on socket : [$errorcode] $errormsg \n");
}
echo "Socket listen OK \n";
echo "Waiting for incoming connections... \n";
//array of client sockets
$client_socks = array();
//array of sockets to read
$read = array();
//start loop to listen for incoming connections and process existing connections
while (true)
{
//prepare array of readable client sockets
$read = array();
//first socket is the master socket
$read[0] = $sock;
//now add the existing client sockets
for ($i = 0; $i < $max_clients; $i++)
{
if($client_socks[$i] != null)
{
$read[$i+1] = $client_socks[$i];
}
}
//now call select - blocking call
if(socket_select($read , $write , $except , null) === false)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not listen on socket : [$errorcode] $errormsg \n");
}
//if ready contains the master socket, then a new connection has come in
if (in_array($sock, $read))
{
for ($i = 0; $i < $max_clients; $i++)
{
if ($client_socks[$i] == null)
{
$client_socks[$i] = socket_accept($sock);
//display information about the client who is connected
if(socket_getpeername($client_socks[$i], $address, $port))
{
echo "Client $address : $port is now connected to us. \n";
}
//Send Welcome message to client
$message = "Welcome to php socket server version 1.0 \n";
$message .= "Enter a message and press enter, and i shall reply back \n";
socket_write($client_socks[$i] , $message);
break;
}
}
}
//check each client if they send any data
for ($i = 0; $i < $max_clients; $i++)
{
if (in_array($client_socks[$i] , $read))
{
$input = socket_read($client_socks[$i] , 1024);
if ($input == null)
{
//zero length string meaning disconnected, remove and close the socket
unset($client_socks[$i]);
socket_close($client_socks[$i]);
}
$n = trim($input);
$output = "OK ... $input";
echo "Sending output to client \n";
//send response to client
socket_write($client_socks[$i] , $output." welcome any time");
}
}
}

multiple socket_read with multi clients in php

i have a problem with socket connections
i need multiple socket read with several clients but i can connect several clients but only can one socket_read for client, if i add second socket_read, the program doesnt work
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
$socket_bind($sock, $address , $port);
$socket_listen ($sock , 10)
while (true){
$read = array();
//first socket is the master socket
$read[0] = $sock;
//now add the existing client sockets
for ($i = 0; $i < $max_clients; $i++)
{
if($client_socks[$i] != null)
{
$read[$i+1] = $client_socks[$i];
}
}
//now call select - blocking call
if(socket_select($read , $write , $except , null) === false)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not listen on socket : [$errorcode] $errormsg \n");
}
//if ready contains the master socket, then a new connection has come in
if (in_array($sock, $read))
{
for ($i = 0; $i < $max_clients; $i++)
{
if ($client_socks[$i] == null)
{
$client_socks[$i] = socket_accept($sock);
//display information about the client who is connected
if(socket_getsockname($client_socks[$i], $address, $port))
{
echo "Client $i : $port . \n";
}
//Send Welcome message to client
$msg = "Bienvenido cliente {$key[0]} \n\r";
$msg .= "1.-Crear Paleta\n\r";
$msg .= "2.-Ubicar Paleta\n\r";
$msg .= "exz.-Salir\n\r";
socket_write($client_socks[$i] , $msg);
break;
}
}
}
//check each client if they send any data
for ($i = 0; $i < $max_clients; $i++)
{
if (in_array($client_socks[$i] , $read))
{
if (false === ($input = socket_read($client_socks[$i],PHP_NORMA))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
break 2;
}
echo "client $i : ";
echo "$input";
//send response to client
socket_write ($client_socks[$i], "client $i : ");
socket_write ($client_socks[$i], $input);
socket_write ($client_socks[$i], "\r");
$y++;
}
}
}

Modify code to auto complete on taxonomies instead of title

I've been trying for hours to modify this plugin to work with custom taxonomies instead of post titles and/or post content
http://wordpress.org/extend/plugins/kau-boys-autocompleter/
Added the code / part of the plugin where I think the modification should be done. I could post some stuff I tried but I think it would just confuse people, I don't think I ever came close. Normally I can modify code perfectly but just can't seem to find it. I've tried this method posted here.
http://wordpress.org/support/topic/autocomplete-taxonomy-in-stead-of-title-or-content
But it doesn't work. I've tried searching for possible solutions around his suggestion but I'm starting to think his suggestion isn't even close to fixing it.
if(WP_DEBUG){
error_reporting(E_ALL);
} else {
error_reporting(0);
}
header('Content-Type: text/html; charset=utf-8');
// remove the filter functions from relevanssi
if(function_exists('relevanssi_kill')) remove_filter('posts_where', 'relevanssi_kill');
if(function_exists('relevanssi_query')) remove_filter('the_posts', 'relevanssi_query');
if(function_exists('relevanssi_kill')) remove_filter('post_limits', 'relevanssi_getLimit');
$choices = get_option('kau-boys_autocompleter_choices');
$framework = get_option('kau-boys_autocompleter_framework');
$encoding = get_option('kau-boys_autocompleter_encoding');
$searchfields = get_option('kau-boys_autocompleter_searchfields');
$resultfields = get_option('kau-boys_autocompleter_resultfields');
$titlelength = get_option('kau-boys_autocompleter_titlelength');
$contentlength = get_option('kau-boys_autocompleter_contentlength');
if(empty($choices)) $choices = 10;
if(empty($framework)) $framework = 'jQuery';
if(empty($encoding)) $encoding = 'UTF-8';
if(empty($searchfields)) $searchfields = 'both';
if(empty($resultfields)) $resultfields = 'both';
if(empty($titlelength)) $titlelength = 50;
if(empty($contentlength)) $contentlength = 120;
mb_internal_encoding($encoding);
mb_regex_encoding($encoding);
$words = '%'.$_REQUEST['q'].'%';
switch($searchfields){
case 'post_title' :
$where = 'post_title LIKE "'.$words.'"';
break;
case 'post_content' :
$where = 'post_content LIKE "'.$words.'"';
default :
$where = 'post_title LIKE "'.$words.'" OR post_content LIKE "'.$words.'"';
}
$wp_query = new WP_Query();
$wp_query->query(array(
's' => $_REQUEST['q'],
'showposts' => $choices,
'post_status' => 'publish'
));
$posts = $wp_query->posts;
$results = array();
foreach ($posts as $key => $post){
setup_postdata($post);
$title = strip_tags(html_entity_decode(get_the_title($post->ID), ENT_NOQUOTES, 'UTF-8'));
$content = strip_tags(strip_shortcodes(html_entity_decode(get_the_content($post->ID), ENT_NOQUOTES, 'UTF-8')));
if(mb_strpos(mb_strtolower(($searchfields == 'post_title')? $title : (($searchfields == 'post_content')? $content : $title.$content)), mb_strtolower($_REQUEST['q'])) !== false){
$results[] = array(
'url' => get_permalink($post->ID),
'title' => highlightSearchString(strtruncate($title, $titlelength, true), $_REQUEST['q']),
'content' => (($resultfields == 'both')? highlightSearchString(strtruncate($content, $contentlength, false, '[...]', $_REQUEST['q']), $_REQUEST['q']) : '')
);
}
}
printResults($results, $framework);
function highlightSearchString($value, $searchString){
if((version_compare(phpversion(), '5.0') < 0) && (strtolower(mb_internal_encoding()) == 'utf-8')){
$value = utf8_encode(html_entity_decode(utf8_decode($value)));
}
$regex_chars = '\.+?(){}[]^$';
for ($i=0; $i<mb_strlen($regex_chars); $i++) {
$char = mb_substr($regex_chars, $i, 1);
$searchString = str_replace($char, '\\'.$char, $searchString);
}
$searchString = '(.*)('.$searchString.')(.*)';
return mb_eregi_replace($searchString, '\1<span class="ac_match">\2</span>\3', $value);
}
function strtruncate($str, $length = 50, $cutWord = false, $suffix = '...', $needle = ''){
$str = trim($str);
if((version_compare(phpversion(), '5.0') < 0) && (strtolower(mb_internal_encoding()) == 'utf-8')){
$str = utf8_encode(html_entity_decode(utf8_decode($str)));
}else{
$str = html_entity_decode($str, ENT_NOQUOTES, mb_internal_encoding());
}
if(mb_strlen($str)>$length){
if(!empty($needle) && mb_strpos(mb_strtolower($str), mb_strtolower($needle)) > 0){
$pos = mb_strpos(mb_strtolower($str), mb_strtolower($needle)) + (mb_strlen($needle) / 2);
$startToShort = ($pos - ($length / 2)) < 0;
$endToShort = ($pos + ($length / 2)) > mb_strlen($str);
// build the prefix and suffix
$prefix = $suffix;
if($startToShort){
$prefix = '';
}
if($endToShort){
$suffix = '';
}
// set maximum length
$length = $length - mb_strlen($prefix) - mb_strlen($suffix);
// get the start
if($startToShort){
$start = 0;
} elseif($endToShort){
$start = mb_strlen($str) - $length;
} else {
$start = $pos - ($length / 2);
}
// shorten the string
$string = mb_substr($str, $start, $length);
if($cutWord){
return $prefix.$string.$suffix;
} else {
$firstWhitespace = ($startToShort)? 0 : mb_strpos($string, ' ');
$lastWhitespace =($endToShort)? mb_strlen($string) : mb_strrpos($string, ' ');
return $prefix.' '.(!empty($lastWhitespace)? mb_substr($string, $firstWhitespace, ($lastWhitespace - $firstWhitespace)) : $string).' '.$suffix;
}
} else {
$string = mb_substr($str, 0, $length - mb_strlen($suffix));
return (($cutWord) ? $string : mb_substr($string, 0, mb_strrpos($string, ' ')).' ').$suffix;
}
} else {
return $str;
}
}
function printResults($results, $framework){
if($framework == 'scriptaculous'){
echo '<ul>';
foreach($results as $result){
echo ' <li>
<a href="'.$result['url'].'">
<span class="title">'.$result['title'].'</span>
<span style="display: block;">'.$result['content'].'</span>
</a>
</li>';
}
echo '</ul>';
} else {
foreach($results as $result){
echo str_replace(array("\n", "\r", '|'), array(' ',' ', '|'), '<span class="title">'.$result['title'].'</span><p>'.$result['content'].'</p>')
.'|'
.str_replace(array("\n", "\r", '|'), array(' ',' ', '|'), $result['url'])
."\n";
}
}
}

mIRC Script snippet misfirigin

Whenever somebody just types ! point the snippet runs through all of its commands for some reason I'm trying to find what causes this to happen, so far I cannot find the issue in the code
alias -l sd { return " $+ $scriptdir $+ $$1 $+ " }
on $*:text:/^!(monday|tuesday|wednesday|thursday|friday|saturday|sunday|website|food|touchy|sakura|Bass|bacon|snickers|bot|quiz|quizrules|NYE|NYD|stop|dance|Leta|back|sways|ladies|enters|choice|lounge|hiphop|fault|country|piano|rocks|diva|diva1|hello|sassy|hips|bounces|woot|kiss|pops|wiggle|greets|gotit|phone|next|cheeky|dj|xmas|here|guitar|twist|dj1|facebook|cheeky1|jig|birthday|thanks|chacha|moves|fleshies|aerial|drinks|heifer|dances|tap|chacha1|jam|hairbrush|hairbrush1|hairbrush2|reggae|lmfao|accept|hairbrush3|touch|no|music|tinbot|buffering|fleshie1|brat|2step|twirls|vote|whistle|hohey|scripted|botgurl|shows|phone1|laughs|me|crazy|shares|rani|takes|hour|mj|elvis|profiles|song|sweet|brightie|fire|passenger|lr|)$/Si:#:{
if (!%f) { inc -u6 %f
if ($isfile($sd(timetable.txt))) { .play $+(-t,$regml(1)) # $sd(timetable.txt) 50 }
else { msg # Either timetable.txt doesn't exist or the txt file name doesn't match! }
}
}
menu * {
Ping-Pong:$iif(%pp,pingpongoff,pingpongon)
Anti-Idle:$iif(%antiidle,antioff,antion)
}
on 1:ping: { $iif(%pp,raw pong $1 wannaplaypingpong,) }
on 1:pong: { $iif(%pp,raw ping $1 wannaplaypingpong,) }
alias pingpongoff { unset %pp | echo -a Ping-Pong has been disabled. }
alias pingpongon { set %pp on | echo -a Ping-Pong has been enabled. }
alias antioff { timeridle off | unset %antiidle | echo -a Anti-Idle has been disabled. }
alias antion { .timeridle 0 120 scid -atM1 antiidle | set %antiidle on | echo -a Anti-Idle has been enabled. }
alias antiidle { .msg $status $me }
raw 401:*: {
if (connected isin $1-) && (%antiidle) { echo -s ***** SassIRC Anti-Idle | halt }
}
}
}
You have an error at the end of your regex.
...fire|passenger|lr|)$..
Which contain redundant last pipe |, remove it from the end and it will solve the problem.