Add a pause before further execution in mIRC - sockets

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.

Related

Voicing Script Bug

I'm working on an auto voice/devoice script snippet for an mIRC bot when a nick is lower case it'll voice the nick. Then when the nick is changed and it's upper it should devoice people or if there's an upper nick to lower case nick it voices them. My issue is it won't recognize nick changes to voice or devoice a user.
#lowercheck on
alias -l _c return #
alias startwithlower {
if ( $1 ) {
return $islower($left($regsubex($$1,/\W+/g,$null),1))
}
else return $false
}
on #*:JOIN:#Tristram_Halls:{
if ( $startwithlower($nick) == $true ) {
mode $_c +v $nick
}
}
on #*:NICK:{
if ( ( $startwithlower($newnick) == $false ) && ( $newnick !isvoice $_c ) ) {
mode $_c -v $newnick
}
elseif ( ( $startwithlower($newnick) == $true ) && ( $newnick isvoice $_c ) ) {
mode $_c +v $newnick
}
}
ON NICK is action that happens on nick and execute for every channel, than if your bot should handle many channels it should change how you voice the user in every channel you want to grant him a voice.
If the bot only has OP+ control in 1 channel than the following will fix you issue (you switched between isvoice for both cases):
on #*:NICK:{
if ( ( $startwithlower($newnick) == $false ) && ( $newnick isvoice $_c ) ) {
mode $_c -v $newnick
}
elseif ( ( $startwithlower($newnick) == $true ) && ( $newnick !isvoice $_c ) ) {
mode $_c +v $newnick
}
}
A nicer implementation will be:
#lowercheck on
alias -l _c return #
alias startwithlower {
return $1 && $islower($left($regsubex($$1,/\W+/g,$null),1))
}
on #*:JOIN:#Tristram_Halls:{
if ($startwithlower($nick)) {
mode $_c +v $nick
}
}
on #*:NICK:{
if ($startwithlower($newnick)) {
if ($newnick !isvoice $_c) {
mode $_c +v $newnick
}
}
else
{
if ($newnick isvoice $_c) {
mode $_c -v $newnick
}
}
}

mIRC socket read text from url

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

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++;
}
}
}

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.