PDA

View Full Version : How to Make a Version Checker in SCAR



Naum
10-20-2008, 07:23 PM
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 (http://www.villavu.com/forum/showthread.php?t=27994?t=30489&highlight=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
http://i33.tinypic.com/309nedz.jpg


5. Now Go to your desktop and make a text file named 'version'
http://i36.tinypic.com/11t63b9.jpg


6. It should contain your starting version number e.g '0.1'
http://i38.tinypic.com/8y5191.jpg


7. Save it and go Back to file manager.

8. Click on 'browse' in the upload section of the page
http://i34.tinypic.com/jgqza0.jpg


9. Then Click On Upload File[s]. Note it would take some time to complete
http://i37.tinypic.com/2it67sw.jpg

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:


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;


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:

http://i35.tinypic.com/mtq8p0.jpg

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
10-20-2008, 07:27 PM
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
10-20-2008, 07:34 PM
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
10-20-2008, 08:18 PM
awsome !!!!
i always wondered how to do this thanks so much dude.

rep.
great explaining/guide.

Timer
10-20-2008, 08:21 PM
I can make update php scripts for people, just pm me, i'll get to it.

noidea
10-20-2008, 09:07 PM
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
10-20-2008, 10:06 PM
Yeah, Timer. Why make a lot while you could explain how to make it?

Timer
10-21-2008, 12:26 AM
Maybe i will xD

Bobarkinator
10-21-2008, 12:42 AM
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
10-21-2008, 03:29 PM
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
10-21-2008, 10:57 PM
<?
$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)
}
?>

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
10-22-2008, 02:06 AM
Oooo I like!
I'ma do this in my Guild Miner :P

Thanks for this GREAT TUT!
Rep++

-Shermanator

Naum
10-22-2008, 06:50 AM
lol :p.

Credit me plz :)

Moved to Jr Members!

Da 0wner
10-22-2008, 11:04 AM
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
10-22-2008, 03:15 PM
No Thanks, Post it in the right place. E.g Procedures/Functions forum.

Da 0wner
10-22-2008, 03:19 PM
i made it especially for this tho. i typed it in this quick reply box.

The_Shermanator
10-23-2008, 02:33 AM
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
10-23-2008, 05:13 AM
lol :p.

Credit me plz :)

Moved to Jr Members!
Dude. Would you really want credit?

Magiic
10-23-2008, 03:45 PM
yeah i mean in every script you make do you credit every tut you've read?

Naum
10-23-2008, 03:48 PM
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
10-23-2008, 10:30 PM
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
10-24-2008, 06:49 AM
Dont use freewebs then, they may have additional HTML coding. Use freehostia :)

vikrant60
10-24-2008, 07:33 AM
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
10-24-2008, 11:22 AM
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
10-29-2008, 12:01 AM
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
10-31-2008, 10:24 AM
Thanks man, I didn't know people would use this :)

Nose Smasher
11-04-2008, 05:42 PM
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
03-24-2009, 05:27 PM
Great tutorial, easy to follow, figured it out in about 2 minutes, got it edited to my needs in 5.

Bad Processor
08-23-2009, 05:42 PM
This is handy, I didn't know SCAR actually returned a string. I thought it returned a file. Nice one!

-- BP