This script requests a file via http to a remote service and compares the returning content to a string to check weather it matches. It comes with a commad to allow disabling this check without removing the script.
// Copyright © 2023 Reiikz
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
key http_request_id;
key avatar_key;
integer COMMAND_CHANNEL = 998;
string version_string = "1.0.0";
integer check_requested = FALSE;
integer AUTOCHECK_NOT_SET = 0;
integer AUTOCHECK_ENABLED = 1;
integer AUTOCHECK_DISABLED = 2;
integer autocheck = TRUE;
string Location = "";
string Redelivery = "https://your-site.com/link-that-gets-shown-to-the-user.txt";
saveautocheck(){
llLinksetDataWrite("AUTOCHECK", (string)autocheck);
}
integer checkIsMe(key _key){
return _key == avatar_key;
}
default
{
on_rez(integer start_param)
{ //when the object is rezzed, reset the script.
llResetScript();
}
changed(integer change)
{
if (change & CHANGED_OWNER)//if owner changes, reset the script.
{
// ready = FALSE;
llResetScript();
}
///////////////////NOTECARD
if(change & CHANGED_INVENTORY)
{ //The object's inventory just changed - the notecard could have been modified!
// ready = FALSE;
llResetScript();
}
}
state_entry()
{
avatar_key = llGetOwner();
llListenRemove(COMMAND_CHANNEL);
llListen(COMMAND_CHANNEL, "", llGetOwner(), "");
autocheck = (integer)llLinksetDataRead("AUTOCHECK");
if(autocheck == AUTOCHECK_NOT_SET){
autocheck = AUTOCHECK_ENABLED;
}
if(autocheck == AUTOCHECK_ENABLED) http_request_id = llHTTPRequest(Location, [], "");
check_requested = FALSE;
}
link_message(integer sender_num, integer num, string msg, key id)
{
if(msg == "check_update"){
// llOwnerSay("Reloading configuration");
check_requested = TRUE;
http_request_id = llHTTPRequest(Location, [], "");
}
// the owner of object LSLWiki will hear
// LSLWiki:_lslwiki
}
http_response(key request_id, integer status, list metadata, string body)
{
if (request_id != http_request_id) return;// exit if unknown
if(status != 200){
if (check_requested) llOwnerSay("Can't check version please try again later. Status: " + (string)status);
return;
}
if(body != version_string){
llOwnerSay("There is a new version of this item available, consider redelivering it via the following link: " + Redelivery);
if(!check_requested) llOwnerSay("To disable auto update check use /" + (string)COMMAND_CHANNEL + "disable_auto_check, to enable /" + (string)COMMAND_CHANNEL + "enable_auto_check");
}else if(check_requested){
llOwnerSay("The item is up to date");
}
check_requested = FALSE;
}
listen(integer channel, string name, key id, string message)
{
// we make sure only the owner can call the owner functions.
if(checkIsMe(id)){
if(message == "help"){
llOwnerSay(
"\n/" + (string)COMMAND_CHANNEL + "check_update check for updates\n\
/" + (string)COMMAND_CHANNEL + "disable_auto_check disables checking version upon the script initiating, alternatively remove the script from the prim\n\
/" + (string)COMMAND_CHANNEL + "enable_auto_check enable automatic version checking, it'll notify when there's a new update"
);
}
if(message == "check_update"){
check_requested = TRUE;
http_request_id = llHTTPRequest(Location, [], "");
return;
}
if(message == "disable_auto_check"){
llOwnerSay("Automatic update check disabled");
autocheck = AUTOCHECK_DISABLED;
saveautocheck();
return;
}
if(message == "enable_auto_check"){
llOwnerSay("Automatic update check enabled");
autocheck = AUTOCHECK_ENABLED;
saveautocheck();
return;
}
}
}
}