mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Socket help? Please... #139310 13/01/06 07:58 AM
Joined: Jan 2006
Posts: 7
B
brethren Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 7
Code:
alias checkhost sockopen checkhost $+ $ticks $$1 80

on *:sockopen:checkhost*:{

  echo -a $iif($sockerr,$false,$true - $sock($sockname).ip)

  sockclose $sockname

}



Hey I'm tottally lost here.. I'm trying to figure out a way where I can ping the certain ip/port into the channel for everyone to see rather than using echo -a. Does anyone have an idea? I already tried displying it by $chan or $nick. I'd like to make it where it where you can tell which servers are up or down to others by $nick. But by using the on TEXT action instead.

Sorta like this?

;; Message the channel to tell it whether it's true or false....
on 1:Text:*!serverstatus*:*:{ }

Example:

<me>!serverstatus
<bot> msg $nick Servers Servers Currently Up
<bot> .timer 1 3 msg $nick Kastien: IP: 127.0.0.1 Port: 7777
<bot> .timer 1 5 msg $nick Titan: IP: 127.0.0.1 Port: 7777
<bot> .timer 1 5 msg $nick ETC: IP: 127.0.0.1 Port: 7777

Can any of you please help me on this? it would be highly appreciated

Re: Socket help? Please... #139311 13/01/06 08:49 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
unfortunately i dont know anything about sockets
but i can tell you that the *'s you have around server status
arent needed

if i followed you example correctly

was;
echo -a $iif($sockerr,$false,$true - $sock($sockname).ip)

meant to be;
echo -a $iif($sockerr,$true - $sock($sockname).ip,$false)

Quote:
$iif(C,T,F)


or better yet can you give a breakdown of what each line is supposed to accomplish

i'd appreciate it

pardon any ignorance ive displayed

Last edited by NeUtRoN_StaR; 13/01/06 09:11 AM.
Re: Socket help? Please... #139312 13/01/06 09:05 AM
Joined: Jan 2006
Posts: 7
B
brethren Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 7
Well I know they're not needed but I want it to be like that instead of typing "/checkhost google.com". Or atleast write a small script which responds to a typed command in the on text action. I'm trying to see if I can display whatever I checked to another user within the channel if they type something like !serverstatus. So thats why I want to use the on text action. $sockerr determines whether a host to be true or false. So it either displays:
$true IP
or
$flase

after I you type /checkhost google.com.

I'm just trying to find a way where I can display true or false to a user who typed a commands such as !serverstatus.

EDIT:

Assume someone typed !serverstatus and I checked the host from my client. How would I be able to send the $true or $false statement back to them?

Code:
on 1:Text:*!serverstatus*:*:{ 
  /checkhost google.com
}

Last edited by brethren; 13/01/06 09:18 AM.
Re: Socket help? Please... #139313 13/01/06 09:15 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
i edited the last post
i think your $iif might be backwards
and regardless it just echos it
i think you might be looking to send what it returns to the person who called the script but im not sure
just for clarity on your end (should u need it) an echo is seen by only you

what passes the script the addresses or ips to check?
ie does the user specify what the script checks
does it read if from some file

as for getting it to the person who requested it
msg $nick $iif($sockerr,$true - $sock($sockname).ip,$false)
or
notice $nick $iif($sockerr,$true - $sock($sockname).ip,$false)


Last edited by NeUtRoN_StaR; 13/01/06 09:21 AM.
Re: Socket help? Please... #139314 13/01/06 09:18 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
You are confused.

In $iif(c,t,f), the t part means "what you should put if the condition evalutes to "$true" and the f part what you should put when the condition evaluates to "$false"

Let's change it to be an /if and then you will see why what you say makes no sense.

if ($sockerr) {
; an error has occured
echo -a $true - $sock($sockname).ip
}
else {
; connection successful
echo -a $false
}

As you can see, that's exactly the other way round of what we want. We want to echo $false if the condition was $true, with the condition being that there was an error.

if ($sockerr) will be $true if there was an error, thus we want to echo $false in this case.

So the correct /if would be:

if ($sockerr) {
; there was an error
echo -a $false
}
else {
; connection successful
echo -a $true - $sock($sockname).ip
}

For your $iif to be correct you would have to have specified:

$iif(!$sockerr,$true - $sock($sockname).ip,$false)

The $true and $false that we want to echo say something about how the connection with the socket went. If it went successful, then we want to echo $true, if it didn't go sucessful (there was an error that made $sockerr have a value), we want to echo $false.


Gone.
Re: Socket help? Please... #139315 13/01/06 09:24 AM
Joined: Jan 2006
Posts: 7
B
brethren Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 7
This was taken from the mIRC help file:
Code:
$iif(C,T,F)
Returns T or F depending on whether the evaluation of the Conditional C is true or false.

$iif(1 == 2, yes, no)  returns "no"

$iif() returns F if the conditional returns zero, $false, or $null. For any other value $iif() returns T.

If you don't specify the F parameter, $iif returns a T value if the condition is true, and returns nothing if it's false.

$iif(1 == 2, yes)  returns nothing

You can find out more about conditionals in the if-then-else section.


- $iif determines the host to be either true or false.
- $sockerr opens a connection on a existing ip/port and if the host doesn't have that port open it responds to being false from $iif.

Last edited by brethren; 13/01/06 09:27 AM.
Re: Socket help? Please... #139316 13/01/06 09:28 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
just not thinking in socket terms
so what he needs if i have this straight

either
msg $nick $iif($sockerr,$false,$true - $sock($sockname).ip)

or

notice $nick $iif($sockerr,$false,$true - $sock($sockname).ip)

right?
i had some mental kneejerk reaction to associate an error with false
i understand now though

as always your taking the time to straighten me out is appreciated

Re: Socket help? Please... #139317 13/01/06 09:30 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
Quote:

$sockerr
$sockerr is set to a value after each socket command/event and must be checked after each socket command and before processing an event to see if an error occurred.

close but no cigar

Re: Socket help? Please... #139318 13/01/06 09:30 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
You can't use $nick or $chan etc. in a socket event, because those identifiers aren't filled.

He needs to either sockmark his socket like:

sockmark <socket> <nick or channel>

and in the sockopen event, he can then do: msg $sock($sockname).mark <message>

Or he could of course just set some variables before initiating the socket, like %chan or %nick or whatever, and then reference these in the sockopen event.


Gone.
Re: Socket help? Please... #139319 13/01/06 09:33 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
its a on text event deiter
or it should be
hes looking for it to do all the socket business on a text event

Last edited by NeUtRoN_StaR; 13/01/06 09:34 AM.
Re: Socket help? Please... #139320 13/01/06 09:34 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
No it isn't.

The determination of the socket being successful (checking $sockerr) or not is done in the sockopen event, which has no connection to a channel.

From which location you initiate this, whether it be from a channel, pm, or just a status window is irrelevant, as the checking of the status isn't done there.


Gone.
Re: Socket help? Please... #139321 13/01/06 09:35 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
der your right
this is why around 330am i should keep my mouth shut

ok so
let me focus my chakras ;p

im so confused its ridiculous

he wants the opening trigger to be a text event which fires the alias that does the connection
which triggers a event that sees if the connection was succesful

sooo.......
how about the name is stored in a global variable that
is unset after all the msging

Last edited by NeUtRoN_StaR; 13/01/06 09:39 AM.
Re: Socket help? Please... #139322 13/01/06 09:44 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Anyway...

Code:
on *:text:!serverstatus &amp;:#: checkhost $2

alias checkhost {
  var %sock = $+(checkhost,$ticks,$r(1111,9999))
  sockopen %sock $$1 80
  sockmark %sock $chan $1 -&gt;
}
on *:sockopen:checkhost*:{ 
  var %sock = $sockname
  msg $sock(%sock).mark $iif($sockerr,$false,$true - $sock(%sock).ip) 
  sockclose %sock
}


Gone.
Re: Socket help? Please... #139323 13/01/06 09:47 AM
Joined: Jan 2006
Posts: 7
B
brethren Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 7
I'm oblivious here, how hould I manage adding to the channel by sockmark. I'm sorry I only understand this all too an extenet, I've only been scripting for atleast a day or two O_o.

Last edited by brethren; 13/01/06 09:48 AM.
Re: Socket help? Please... #139324 13/01/06 09:51 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
The code I gave you already does this.

Anyway, for further queries others will have to help you, I've done my part, hopefully you can figure out the rest. There could be some more changes to the code to build some sort of flood protection, so that no one can go crazy and ask for 10 url's in 1 second etc, and various little tweaks to make it more fullproof (check if you are still on the channel before messaging it, check if you are still connected to a server before messaging $nick etc. etc.), but others can do that if they want.

Btw you could check $sock($sockname).wserr for a more accurate error code, but for your purposes $sockerr will suffice.


Gone.
Re: Socket help? Please... #139325 13/01/06 09:51 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
sockmark stores the data for later reference by
$sock().mark

i did sorta the same thing using global variables
if you want it to msg the nick
[code]
alias checkhost {
sockopen checkhost $+ $ticks $$1 80
}
on *:text:!serverstatus &:*:{
set %target $nick
checkhost $$2
}
on *:sockopen:checkhost*:{
msg %target $iif($sockerr,$false,$true - $sock($sockname).ip)
sockclose $sockname
unset %target
}

if you want it to msg the channel just substitute the red $nick
with $chan

and lastly use fibers code im betting theres something horribly wrong with mine

Last edited by NeUtRoN_StaR; 13/01/06 10:03 AM.
Re: Socket help? Please... #139326 13/01/06 09:59 AM
Joined: Jan 2006
Posts: 7
B
brethren Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 7
I appreciate both or your guys help! Thanks, time for me to put on a thinking cap and see what else I can do with sockets. I found a good tutorial here if your ever a little flakely on the commands, it's great:
http://mircscripts.org/showdoc.php?type=tutorial&id=1128

Last edited by brethren; 13/01/06 10:01 AM.
Re: Socket help? Please... #139327 13/01/06 10:03 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
The problem with your code is that you are using a variable that is too generic, and not uniquely identifiying the specific request.

Let's illustrate this:

Ricky does !serverstatus, which makes %target be Ricky.
Right after that, FOP does !serverstatus, which makes %target be FOP.

The sockopen event is triggered in an undefined number of seconds, depending on how long it takes mIRC (Windows actually) to make a connection to the host (if at all.)

Now the sockopen event is triggered, and it is uncertain who the %target will be. It is very possible that the query that Ricky did will end up being messaged to FOP, if Ricky's query took 5 seconds, and FOP did a query only 3 seconds after Ricky did. On top of that, if this occurs, FOP won't even get his original request, because %target is unset, which results in an error on the person hosting this script as there are insufficient parameters.

That's the reason I use a unique socket name ($ticks + $r(1111,9999)) and sockmark this name with the target, so that there could never be any such issue.

In other words, your current version does not accomodate simultaneous lookups.


Gone.
Re: Socket help? Please... #139328 13/01/06 10:07 AM
Joined: Mar 2005
Posts: 212
N
NeUtRoN_StaR Offline
Fjord artisan
Offline
Fjord artisan
N
Joined: Mar 2005
Posts: 212
thats what turns me on about you..
your attention to detail wink

Re: Socket help? Please... #139329 13/01/06 11:38 AM
Joined: Jan 2006
Posts: 7
B
brethren Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
B
Joined: Jan 2006
Posts: 7
Thanks fiber you really saved me a headache. I managed to find a simple way of preventing others typing !serverstatus without being the channel owner:

First I loaded the script that you gave me onto one mIRC client and set the user as a channel operator "@FMP-Bot":
Code:
/*
Script made by FiberOPtics @
http://forums.mirc.com/showflat.php?Cat=0&amp;Number=146657&amp;page=0&amp;vc=1#Post146657
*/
on *:text:!serverstatus &amp;:#: checkhost $2

alias checkhost {
  var %sock = $+(checkhost,$ticks,$r(1111,9999))
  sockopen %sock $$1 80
  sockmark %sock $chan $1 -&gt;
}
on *:sockopen:checkhost*:{ 
  var %sock = $sockname
  msg $sock(%sock).mark $iif($sockerr,$false,$true - $sock(%sock).ip) 
  sockclose %sock
}


Then on the channel owner I used the following:
Code:
on 1:Text:*!host*:#:{
  .timer 1 2 msg $chan 4Checking to see if Titan is up...
  .timer 1 10 msg $chan !serverstatus web.com
}
on 1:Text:*$true*:#:{
  .timer 1 5 msg $chan 3Servers Up!  Stop complaining about it now!
}
on 1:Text:*$false*:#:{
  .timer 1 5 msg $chan 5Servers Down!
}
on 1:Text:*!serverstatus*:#:{
  kick $chan $nick Only a channel owner is allowed to type that command!
}


I kept it limited to where, only a user can type a certain command and it will use !serverstatus on a specified address. Hopefully this will keep the channel owner only capiable of typing various addresses. Other than that, I still need to write the part where users can only type the command "!host" within a certain amount of time.

Last edited by brethren; 13/01/06 11:41 AM.
Page 1 of 2 1 2