mIRC Home    About    Download    Register    News    Help

Print Thread
Version/Update script - help is needed #185500 10/09/07 07:14 AM
Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
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 
  } 
}

Last edited by z4nd; 10/09/07 07:16 AM.
Re: Version/Update script - help is needed [Re: z4nd] #185509 10/09/07 11:57 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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 }
  }
} 


Invision Support
#Invision on irc.irchighway.net
Re: Version/Update script - help is needed [Re: Riamus2] #185527 10/09/07 06:15 PM
Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
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.


Re: Version/Update script - help is needed [Re: z4nd] #185528 10/09/07 06:38 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Version/Update script - help is needed [Re: Lpfix5] #185537 10/09/07 09:35 PM
Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
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 ?

Re: Version/Update script - help is needed [Re: z4nd] #185549 10/09/07 11:36 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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 }
}


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Version/Update script - help is needed [Re: Lpfix5] #185553 11/09/07 12:12 AM
Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
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.

Re: Version/Update script - help is needed [Re: z4nd] #185558 11/09/07 01:21 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
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


Invision Support
#Invision on irc.irchighway.net
Re: Version/Update script - help is needed [Re: z4nd] #185565 11/09/07 02:27 AM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
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! }


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Version/Update script - help is needed [Re: Riamus2] #185606 11/09/07 06:35 PM
Joined: Sep 2007
Posts: 7
Z
z4nd Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
Z
Joined: Sep 2007
Posts: 7
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