mIRC Homepage
Posted By: z4nd Version/Update script - help is needed - 10/09/07 07:14 AM
I've got this socket script, that should check version.txt and compare it with a current version number and echo if it's newer or not.
But it seems to echo there is a newer version 15 times with a line in between that says it's the newest version.
It would be nice to have the current version as a global variable, to be used in the rest of the script, if it's possible.
Current version: 1.5, newest version 1.6
Code:
on *:sockopen:vercheck:{ 
  if $sockerr { echo -ac info * error retrieving data from siradio | return } 
  set %sockwrite /siradio/version.txt $+ %variable
  sockwrite -n $sockname GET %sockwrite HTTP/1.1
  sockwrite -n $sockname Host: z4nd.net $+ $str($crlf,2) 
} 

on *:sockread:vercheck:{ 
  if $sockerr { return } 
  var %b 1.5
  var %a  
  sockread %a
  if (%a > %b) { echo There is a new version available at http://z4nd.net/siradio }
  else { echo You have the newest version }
} 

on *:sockclose:vercheck: { 

} 
alias verchecks { 
set %variable 1.5
  if ($sock(vercheck)) { 
    sockclose vercheck
    sockopen vercheck z4nd.net 80  
  } 
  else { 
    sockopen vercheck z4nd.net 80 
  } 
}
Posted By: Riamus2 Re: Version/Update script - help is needed - 10/09/07 11:57 AM
When reading a website through sockets, you're not just reading the actual page data. You are reading the header information, which is why you're getting extra outputs. Change your version.txt file so it says:

Version 1.6

Then, you can do this:
Code:
on *:sockread:vercheck:{ 
  if $sockerr { return } 
  var %b 1.5
  var %a  
  sockread %a
  if (Version* iswm %a) {
    if ($gettok(%a,2,32) > %b) { echo There is a new version available at http://z4nd.net/siradio }
    else { echo You have the newest version }
  }
} 
Posted By: z4nd Re: Version/Update script - help is needed - 10/09/07 06:15 PM
Thanks for the reply

But, with the change, it doesn't even want to check anything now.

When i do /siupdate (i've changed the alias and sockets to siupdate) it wont reply with anything, not if it's a newer version or the same version.

Posted By: Lpfix5 Re: Version/Update script - help is needed - 10/09/07 06:38 PM
A) Write your webpage code like this. Don't read from .txt over web.

Code:
split Infinity Radio mIRC Add-On
.zip:<br>
<a href="siradio.zip">siradio.zip</a>: Version 1.5 
.rar:<br>
<a href="siradio.rar">siradio.rar</a>: Version 1.5 



B) Here's the script to go with it

Code:
alias siupdate /sockopen siupdate z4nd.net 80

on 1:sockopen:siupdate:{
  .sockwrite -n siupdate GET /siradio/ HTTP/1.1
  .sockwrite -n siupdate HOST: z4nd.net
  .sockwrite -n siupdate $crlf
}

on 1:sockread:siupdate:{
  if ($sockerr > 0) return
  var %x | sockread %x
  if ($sockbr == 0) return
  if (!%X) { return - }
  if ($gettok(%x,$calc($findtok(%x,Version,32)+1),32) > YOURVERSIONHEREOFSCRIPT) { echo -a There is a new version available at http://z4nd.net/siradio }
}


Btw, the part of my script that says YOURVERSIONHEREOFSCRIPT should be where you add the variable which contains your version number like 1.0 1.1 1.2 1.3 1.4 etc... that way it will check on the web if it's larger then the original script
Posted By: z4nd Re: Version/Update script - help is needed - 10/09/07 09:35 PM
I like your remade script there, but still got a problem:

When i do /siupdate i get this:
Code:
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio


And i have if ($gettok(%x,$calc($findtok(%x,Version,32)+1),32) > 1.5) So, it shouldn't say anything ? or does it still count the same version as a newer ? and why do it echo it 11 times ?
Posted By: Lpfix5 Re: Version/Update script - help is needed - 10/09/07 11:36 PM
Originally Posted By: z4nd
I like your remade script there, but still got a problem:

When i do /siupdate i get this:
Code:
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio
There is a new version available at http://z4nd.net/siradio


And i have if ($gettok(%x,$calc($findtok(%x,Version,32)+1),32) > 1.5) So, it shouldn't say anything ? or does it still count the same version as a newer ? and why do it echo it 11 times ?


My appoligies dude I should of checked for if version was in X then use bitwise to calc that but heres a faster alternative way if your gonna keep the format of the HTML always the same like

whatever.zip: Version 1.5 what i do is take the last 3 chars and compare them if larger meaning if you ever changed it to version 1.5a you would need to change the script itself to $right(%x,+4) instead well so you see since there's 2 identical data's in the sockread "Version 1.5" it became tricky to use $gettok or $wildtok etc... thus why the $right stuff... well it works for now If you want it better ill try harder but here it is

NOTE: Maybe someone could help me seems that $gettok,$wildtok events somehow interfere with the return data because I can make the command perfectly get the data but when it comes time to compare it always acts that the value @ $v2 is larger then $v1 im thinking that because he is using . $chr(46) it somehow evaluates or something. Giving me no option whatsoever to compare if larger then. $gettok(%x,$calc($findtok(%x,Version,32)+1),32) is same as $right(%x,+3) its returning the same data but the gettok dont work but the $right does.

Code:
on 1:sockread:siupdate:{
  if ($sockerr > 0) return
  var %x | sockread %x
  if ($sockbr == 0) return
  if (%x == $null) { return }
  if (Version isin %x) && ($right(%x,+3) > 1.4) { echo -a There is a new version available at http://z4nd.net/siradio | haltdef }
}
Posted By: z4nd Re: Version/Update script - help is needed - 11/09/07 12:12 AM
It works perfectly!

Thank you for your time for doing this, now i can finally release the next version of the script.

I will try and read through it and learn more about sockets from this, because i think this is a good example of doing somthing relative simple as checking for a version (the simple way)

On a side note: I guess i can just do
Code:
if (Version isin %x) && ($right(%x,+3) == 1.4) { echo -a You have the neweset version! | haltdef }

After the last if.
Posted By: Riamus2 Re: Version/Update script - help is needed - 11/09/07 01:21 AM
Originally Posted By: z4nd
Thanks for the reply

But, with the change, it doesn't even want to check anything now.

When i do /siupdate (i've changed the alias and sockets to siupdate) it wont reply with anything, not if it's a newer version or the same version.



Two reasons why my code wouldn't work for you...

1) You didn't include the rest of the script. I only displayed the part that was changed. You still needed everything else.

2) You didn't change your version file to what I said. It would not have replied with anything if your text file didn't have the line:

Version 1.6

The number can change, but "Version" has to start the line for it to work. Note that you don't need to deal with the HTML stuff. The text file would work correctly if the 2 items above were done correctly. smile
Posted By: Lpfix5 Re: Version/Update script - help is needed - 11/09/07 02:27 AM
Originally Posted By: z4nd
It works perfectly!

Thank you for your time for doing this, now i can finally release the next version of the script.

I will try and read through it and learn more about sockets from this, because i think this is a good example of doing somthing relative simple as checking for a version (the simple way)

On a side note: I guess i can just do
Code:
if (Version isin %x) && ($right(%x,+3) == 1.4) { echo -a You have the neweset version! | haltdef }

After the last if.


Actually after the last if (Version statement make a new line just below it and put else { echo -a You have the newest version! }
Posted By: z4nd Re: Version/Update script - help is needed - 11/09/07 06:35 PM
1) Yes, i did use other parts of the code with your changes

2) I did change the version to what you said.

But that doesn't matter now, i like other code better, it's more clean and simpler
© mIRC Discussion Forums