SRL Archive - OSR Intermediate Scripting Tutorials

How to Make a Version Checker in SCAR


Naum

2008-10-20 15:23:46

How To Make a Version Checker


Table of Contents

0 - Intoduction
I - What is a version checker?
II - Ways of Making the script check.
III - Making your Website
IV - Implement your version Checker in Scripts!
V - End Notes/Credits.


0 - Intoduction

Hello guys/gals, this tutorial will be teaching you how to make a version checker which looks really 1337 and is very handy in complex scripts. So what is a Version Checker, is it one of those biscuits you can give to your dog?.. well alas, no.


I - What is a version checker?

A version checker is used in programs to check if you have the latest version of that program. Since this is a SCAR Scripting forum I will be talking about scripts. Version Checker are basically implemented in scripts and called before an event to check if that person has the latest offering of your script. If not you can make it stop the script or even make the script download it - else you can let it continue.


II - Ways of Making the script check

There are two main ways of making the script check for updates - One way is to use INI Files. The other is much more easier/harder this involves making the script cross referance with a website. The latter is the one I will focus on.

WARNING - If you bore easily go play runescape. Legit!


III - Making your website

This I will be doing in steps to make it n00b pr00f!

Step:

1 : Go To www.freehostia.com/signup.html

2 : Make an account, make your website name like your script name e.g Guild X Min0r! ->
guildxminer.freehostia.com!

3. Login with your credentials (user + pass)

4. Once your logged in go to File Manager


5. Now Go to your desktop and make a text file named 'version'


6. It should contain your starting version number e.g '0.1'


7. Save it and go Back to file manager.

8. Click on 'browse' in the upload section of the page


9. Then Click On Upload File. Note it would take some time to complete

10. Done!




IV - Impliment your Version checker in Scripts

Okay you've done the juicy part Now take a look at this code.

Const Ver = '0.1';

Procedure CheckVer;
Var Version : String
Begin
Version := GetPage('www.guildminer.freehostia.com\version.txt');
If Version <> Ver Then
WriteLn('get a new version!')
else
WriteLn('good up to date!');
end;

Begin //main loop
CheckVer;
end.

So we have this to begin with:

program new;
begin
end.

Space out the lines and make a const called 'Ver', this constant must be a string

e.g
Const Ver = '0.1';

Now create a new procedure called CheckVer. You should have something like this:

program new;

Const Ver = '0.1';

Procedure CheckVer;
Begin

end;


begin

end.

Now we need to use a Function called GetPage.

Info on this:

[php]function GetPage(URL: string): string;
Return HTTP webpage contents as string.
Example:
s:= GetPage('http://kaitnieks.com');
if(s = '')then
begin
Writeln('Some kind of connection error');
end else
begin
..
end;
[/php]

We need to make a variable called Version this is basically what your GetPage(''); is stored in, so this needs to be a string. Also we need to compare it to see if it is equal to the const 'Ver'.

So we should have something like this:

program new;

Const Ver = '0.1';

Procedure CheckVer;
Var Version : String;
Begin
Version := GetPage('www.{your site name here}.freehostia.com\version.txt');
If Version = Ver Then

end;


begin

end.

So now you need to make it take a specified action so you can say if its outdated or not:
Then you need to call it in your mainloop before everything else

program new;

Const Ver = '0.1';

Procedure CheckVer;
Var Version : String;
Begin
Version := GetPage('www.{your site name here}.freehostia.com\version.txt');
If Version = Ver Then
Begin
WriteLn('continue')
End Else
TerminateScript;
end;


begin
CheckVer;
SetupSRL;
end.

There you go easy. Done and dusted!

V - End Note/Credits

Now you realise that making this stuff isn't that hard. Just for clarification if you want to update the version number then instead of uploading a new file you can edit it by clicking on this:


Easy no?

Credits :

Yakman - From the days when I was noob
TSN
P1nky
EvilChicken
Nielsie95
Sumilion
MastaRaymond
Munk
Santy
thechineseman

Loads of other people!


Edit : I'll move this to jr members once you give your opinions and once freehostia are open for registrations.

Shuttleu

2008-10-20 15:27:55

very good
exactly how i did it in UCB :)
  curentver:= GetPage('http://tsr-forum.mgatesphoto.com/ultracutnbankver.txt');
if curentver <> UCBversion then
begin
writeln('This script is outdated please redownload it from http://www.villavu.com/forum/showthread.php?t=36968');
TerminateScript;
end;

some people could learn from this

~shut

Naum

2008-10-20 15:34:40

It can also be used quite easy with forms aswell. Thanks for the comments.
Btw this is how I use it in GuildXMin0r!

Button3 : Begin
Lol := Getpage('http://guildxminer.freehostia.com/version.txt');
If Lol <> Ver Then
begin
Memo1.Lines.Add('Not Up To DATE!!, Update please - by Visiting The Site');
Memo1.Lines.Add('On the Other Hand - you may be online whilst Im testing a new version, so keep tuned!');
TerminateScript;
end else
Memo1.Lines.Add('Up To date! Using Version '+lol);
Memo1.Lines.Add('Continuing....');
end;

P1nky

2008-10-20 16:18:33

awsome !!!!
i always wondered how to do this thanks so much dude.

rep.
great explaining/guide.

Timer

2008-10-20 16:21:14

I can make update php scripts for people, just pm me, i'll get to it.

noidea

2008-10-20 17:07:37

Hey, can you explainon how to get it to download the current script from the website if the version they have is outdated thanks.

Esteban

2008-10-20 18:06:38

Yeah, Timer. Why make a lot while you could explain how to make it?

Timer

2008-10-20 20:26:02

Maybe i will xD

Bobarkinator

2008-10-20 20:42:01

In the tutorial, you upload verstion.txt, but yet you are just GetPaging the root of your website, guildxminor.freehostia.com. You need to change that to version.txt or change version.txt to index.html

Naum

2008-10-21 11:29:41

Oh yes thanks for that fix bob :).
And for downloading that is pretty easy, just use a between function to find the beginning and the end of a scripte.g

script :

~ {Fight Caver 0.9!!!}
Program new;
Begin
dostuff
end;
#

So you can do :

Procedure GetScript
Var S : String;
Begin
S := Between('~', '#', GetPage('script123.freehostia.com/script.txt'));
WriteFileString({filenum}, S);
LoadFromFile({stuff});
WriteLn('Downloaded Script!!!');
end;

Fixed the tutorial a bit, THX BOB!

MylesMadness

2008-10-21 18:57:59

[php]<?
$Username = $_POST['username'];
$Password = $_POST['password'];
if($Username = 'username' and $Password = 'password'){
$handle= fopen("script.txt", "r")
echo fread($handle, filesize(script.txt))
fclose($handle)
}
?>[/php]

Procedure UpdateAuth;
var
FileNum:Integer;
Ver2:extended;
Site: Integer;
S: string;
begin
Writeln('Alow this to do verison check')
Ver2:=StrToFloat(GetPage(''))//A url that has the newest verison in it
If Ver2 > Ver then //in float form Ex: 1.1
begin
Site:= InitializeHTTPClient(False, False);
ClearPostData(Site);
AddPostVariable(Site, 'username', 'username');
AddPostVariable(Site, 'password', 'password');
S:= PostHTTPPageEx(Site, '');//A site with the php script that is above
if(S <> '')then
begin
FileNum := RewriteFile(ScriptPath+'script Ver '+FloatToStr(Ver2)+'.scar', True);
WriteFileString(FileNum, S);
CloseFile(FileNum);
Writeln('Their was a new version out, so I downloaded it for you')
Writeln('Please open the new one and start again')
TerminateScript;
end else
begin
Writeln('Wrong pass. Stoping script')
TerminateScript;
end;
end;
end;

I like password so incase I ever want to make the script members I can change the pass and BAM, no one's script will work unless they can script.

The_Shermanator

2008-10-21 22:06:18

Oooo I like!
I'ma do this in my Guild Miner :P

Thanks for this GREAT TUT!
Rep++

-Shermanator

Naum

2008-10-22 02:50:55

lol :p.

Credit me plz :)

Moved to Jr Members!

Da 0wner

2008-10-22 07:04:09

Here is a template procedure for checking versions

If you don't know what a float/extended is, it's basically a decimal.


function HasLatestVersion(ScriptVersionURL, ScriptURL, ExactFileName : string; UsedVersion : extended) : boolean;
var
FileNum : integer;
begin
result := StrToFloat(GetPage(ScriptVersionURL)) = UsedVersion;
if result = false then
begin
case GetApplication.Messagebox('Version' + GetPage(ScriptVersionURL) + chr(13) + 'Download?' , 'Download Latest Version', 4) of
6 : begin
FileNum := ReWriteFile(ScriptPath + ExactFileName, true);
WriteFileString(FileNum, GetPage(ScriptURL));
CloseFile(FileNum);
GetApplication.MessageBox('The current version of ' + ExactFileName + ' has been successfully downloaded.' + chr(13) + 'Please reopen this script.', 'Please Reopen the Script', 0);
TerminateScript;
end;
end;
end;
end;

Usage:


The required variables are

ScriptVersionURL : string = The URL of the current version.
ScriptURL : string = The URL of the actual up to date script.
ExactFileName : string = The exact filename of the name of the script you are using. The filename the not the title!
UsedVersion : extended = The version of the script that is currently being used.

Procedure Example:

begin
HasLatestVersion('http://mysubdomain.freehosta.com/MyVersion.txt', 'http://mysubdomain.freehostia.com/MyScript.txt', 'TheScriptFilenameispwnz0r.scar', 0.9);
end.

Put in your tutorial please?

Naum

2008-10-22 11:15:50

No Thanks, Post it in the right place. E.g Procedures/Functions forum.

Da 0wner

2008-10-22 11:19:10

i made it especially for this tho. i typed it in this quick reply box.

The_Shermanator

2008-10-22 22:33:46

This doesn't work for me, anybody know why?
Procedure VersionCheck;
Var
Version, Ver: String;

Begin
Ver := '1.3';
Version := GetPage('http://www.freewebs.com/guildminer/VersionCheck.txt');
If Version <> Ver Then
Begin
WriteLN('Wrong Version!');
WriteLN('Please Download From...');
WriteLN('http://www.villavu.com/forum/showthread.php?t=35975');
TerminateScript;
end else
WriteLn('Your Using Correct Version!');
end;

Daniel

2008-10-23 01:13:07

From: NaumanAkhlaQ
lol :p.

Credit me plz :)

Moved to Jr Members!

Dude. Would you really want credit?

Magiic

2008-10-23 11:45:43

yeah i mean in every script you make do you credit every tut you've read?

Naum

2008-10-23 11:48:57

Nop, I just said I would like credit. The 'plz :)' part…

EDIT: Here sherman you use '=' much easier :)

Procedure VersionCheck;
Var
Version, Ver: String;

Begin
Ver := '1.3';
Version := GetPage('http://freewebs.com/guildminer/VersionCheck.txt');
If Version = Ver Then
Begin
WriteLN('Wrong Version!');
WriteLN('Please Download From...');
WriteLN('http://www.villavu.com/forum/showthread.php?t=35975');
TerminateScript;
end else
WriteLn('Your Using Correct Version!');
end;

Lol it works like that??? I recommend leave it since it works perfectly?

MylesMadness

2008-10-23 18:30:47

Um, not it doesn't work right… They way you did it it would say old ones are indate and indate ones are not

Naum

2008-10-24 02:49:12

Dont use freewebs then, they may have additional HTML coding. Use freehostia :)

vikrant60

2008-10-24 03:33:11

Already know how make make one but what i didn't know is that you could make it detect a connection problem :P thanks man ^.^

t35.com works.

110mb.com works.

Timer

2008-10-24 07:22:53

From: NaumanAkhlaQ
Nop, I just said I would like credit. The 'plz :)' part…

EDIT: Here sherman you use '=' much easier :)

Procedure VersionCheck;
Var
Version, Ver: String;

Begin
Ver := '1.3';
Version := GetPage('http://freewebs.com/guildminer/VersionCheck.txt');
If Version = Ver Then
Begin
WriteLN('Wrong Version!');
WriteLN('Please Download From...');
WriteLN('http://www.villavu.com/forum/showthread.php?t=35975');
TerminateScript;
end else
WriteLn('Your Using Correct Version!');
end;

Lol it works like that??? I recommend leave it since it works perfectly?

Ver := '1.3';
Version := GetPage('http://freewebs.com/guildminer/VersionCheck.txt');
If Version = Ver Then
Begin
WriteLN('Wrong Version!');
if the version is the version on the site… Wrong version..?
You forget Nots much Nauman?

noidea

2008-10-28 20:01:14

Socket Error # 10061
Connection refused.

I'm getting this error, and yes, I clicked 'allow all'.

Edit: Never mind, I figured it out :)

Edit, Edit: Yay! IT worked!!! Another rep for nauM!!!!!!!!!!!!

Naum

2008-10-31 06:24:17

Thanks man, I didn't know people would use this :)

Nose Smasher

2008-11-04 12:42:41

From: noidea
Socket Error # 10061
Connection refused.

I'm getting this error, and yes, I clicked 'allow all'.

Edit: Never mind, I figured it out :)

Edit, Edit: Yay! IT worked!!! Another rep for nauM!!!!!!!!!!!!


I get this error :redface: How'd you fix??

XRaye

2009-03-24 13:27:14

Great tutorial, easy to follow, figured it out in about 2 minutes, got it edited to my needs in 5.

Bad Processor

2009-08-23 13:42:04

This is handy, I didn't know SCAR actually returned a string. I thought it returned a file. Nice one!

– BP