Check for update
by Skylar Kelty · 11/13/2006 (4:36 pm) · 8 comments
The functions, these can go in any client-side script but lets keep it clean eh? Lets create a new file called versioncheck.cs in client/scripts/ and exec it in initclient.
The put this in that file:
Now, to check for a new version you must call getlatestversion()
For example, you could put it at the end on initClient() which is in client/init.cs
This resource is no good without the online xml file. Create an xml file and upload it to the same directory you specified above (/latestversion.xml and www.-.com would make www.-.com/latestversion.xml).
Put this in the xml file:
1.1
Note: replace the urls and version numbers, etc.
The put this in that file:
function checkversion(%currentversion)
{
// The version of the game/app
%version = 1.0;
if(%currentversion > %version)
{
MessageBoxOK("Old Version", "Your version of - is not the most current version, please download the latest patch from -");
$OutOfDate = true;
}
}
function getlatestversion()
{
new TCPObject(VersionObject);
VersionObject.connect("www.-.com:80");
}
function VersionObject::onConnected(%this)
{
$Version::lineCount = 0;
$Version::requestResults = "";
// Request our RSS.
%this.send("GET " @ "/latestversion.xml" @ " HTTP/1.0\nHost: " @ "www.-.com" @ "\nUser-Agent: " @ "Torque" @ "\n\r\n\r\n");
}
function VersionObject::onLine(%this, %line)
{
$Version::lineCount++;
$Version::requestResults = $Version::requestResults @ %line;
}
function VersionObject::onDisconnect(%this)
{
%version = getxmldata($Version::requestResults, "version", 0);
checkversion(%version);
}
function getxmldata(%string, %tag, %startChar)
{
%startTag = "<" @ %tag @ ">";
%endTag = "</" @ %tag @ ">";
%startTagOffset = strpos(%string, %startTag, %startChar);
%startOffset = %startTagOffset + strlen(%startTag);
%endTagOffset = strpos(%string, %endTag, %startOffset - 1);
if(%endTagOffset < 0)
return "";
%this.lastOffset = %endTagOffset;
%result = getSubStr(%string, %startOffset, %endTagOffset - %startOffset);
%result = strreplace(%result, """, "\"");
%result = strreplace(%result, "&", "&");
return %result;
}Now, to check for a new version you must call getlatestversion()
For example, you could put it at the end on initClient() which is in client/init.cs
This resource is no good without the online xml file. Create an xml file and upload it to the same directory you specified above (/latestversion.xml and www.-.com would make www.-.com/latestversion.xml).
Put this in the xml file:
1.1
Note: replace the urls and version numbers, etc.
About the author
#2
08/01/2007 (6:45 pm)
Looks cool. I will try this as soon as my web server is up and running.
#3
%result = strreplace(%result, """, "\"");
i removed it and it still works.
How can i make it display a message when you have the latest version as well?
08/21/2007 (7:04 pm)
Error on line 53%result = strreplace(%result, """, "\"");
i removed it and it still works.
How can i make it display a message when you have the latest version as well?
#4
08/23/2007 (12:29 am)
%result = strreplace(%result, "\"", "\\\"");
#5
12/09/2007 (10:06 pm)
Does this also make the client download the new files?
#6
12/09/2007 (10:08 pm)
Nope it just tells the person to update.
#7
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10800
12/10/2007 (12:44 pm)
This one does:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10800
#8
08/30/2008 (3:15 pm)
Thanks for this--nice and simple and flexible and works :-) 
Torque 3D Owner CodingChris