User:Cow Taurog/Update server

From Second Life Wiki
Jump to navigation Jump to search

This script comes in two seperate pieces, one for the server object, and one that goes in the object that checks to see if there is an updated version of itself. The server object will use the name of the last item dropped into it as the object to send out as an update. The checker object will send the name of the object it is in as an email to the server. Place the server object into a prim, and take note of the object's email address. Put the checker script into the object to distribute, and enter the server's email address into the settings. Drop the object to distribute as an update inside. The checker script will send an email with the object's name as the subject, and the owner's key as the message. The server will then compare that name to the name stored as the most current version, and send out the object inside the server that has the same name as the most current version of the object if the names don't match. If they both match, it will send the user an IM telling them they have the latest version. Once the server is in place, it is important that the UUID doesn't change, so don't delete it, re-rez it, or put it somewhere that will return it. To move it from one place to another, wear it on your avatar (but don't detach it), go to wherever, and then drop it (drop, not detach). Resetting the server script won't break it. If the UUID of the server does change, you'll have to change each object that uses it by hand, or issue a new update through a group notice or some other method that looks bad, and tells everyone you screwed up.

Server

// will keep track of objects, and always send out the latest one dropped in as an update
// email is the object's name as the subject, and the owner's key as the message
list glInv;
integer i;
string gsLatest;
integer DEBUG=0;
default{
    state_entry(){
        llOwnerSay("Update server online, "+(string)llGetKey()+"@lsl.secondlife.com");
        llSetTimerEvent(20);
        llGetNextEmail("","");
        if(DEBUG==2){llOwnerSay("Inv num: "+(string)llGetInventoryNumber(INVENTORY_OBJECT));}
        for(i=0;i<llGetInventoryNumber(INVENTORY_OBJECT);i++){
            if(DEBUG==2){llOwnerSay("Inv name: "+llGetInventoryName(INVENTORY_OBJECT,i));}
            glInv=glInv+[llGetInventoryName(INVENTORY_OBJECT,i)];
            if(DEBUG==2){llOwnerSay(llList2CSV(glInv));}
        }
        gsLatest=llList2String(glInv,llGetListLength(glInv)-1);
        if(DEBUG==2){llOwnerSay("Latest: "+gsLatest);}
    }
    touch_start(integer num){if(llDetectedKey(num-1)==llGetOwner()){
        glInv=[];
        for(i=0;i<llGetInventoryNumber(INVENTORY_OBJECT);i++){
            if(DEBUG==2){llOwnerSay("Inv name: "+llGetInventoryName(INVENTORY_OBJECT,i));}
            glInv=glInv+[llGetInventoryName(INVENTORY_OBJECT,i)];
            if(DEBUG==2){llOwnerSay(llList2CSV(glInv));}
        }
        gsLatest=llList2String(glInv,llGetListLength(glInv)-1);
        if(DEBUG==2){llOwnerSay("Latest: "+gsLatest);}
        llGetNextEmail("","");
    }}
    timer(){
        llGetNextEmail("","");
    }
    changed(integer change){if(change&CHANGED_INVENTORY){
        glInv=[];
        for(i=0;i<llGetInventoryNumber(INVENTORY_OBJECT);i++){
            if(DEBUG==2){llOwnerSay("Inv name: "+llGetInventoryName(INVENTORY_OBJECT,i));}
            glInv=glInv+[llGetInventoryName(INVENTORY_OBJECT,i)];
            if(DEBUG==2){llOwnerSay(llList2CSV(glInv));}
        }
        gsLatest=llList2String(glInv,llGetListLength(glInv)-1);
        if(DEBUG==2){llOwnerSay("Latest: "+gsLatest);}
    }}
    email(string time,string address,string subject,string message,integer numleft){
        if(llGetSubString(address,-19,-1)=="@lsl.secondlife.com")
        message=llDeleteSubString(message,0,llSubStringIndex(message,"\n\n")+1);
        if(DEBUG==2){llOwnerSay(subject+", "+message);}
        if(subject!=gsLatest){
            llInstantMessage((key)message,"There is a new update, "+gsLatest+" is now available. Sending it now...");
            llGiveInventory((key)message,gsLatest);
        }
        else{llInstantMessage((key)message,"There are no new updates. Please check again later.");}
        llGetNextEmail("","");
    }
}

Prim

// will check for an update if "update" is heard over linkmessage num 100
// match the email address to the server's email address
string gsServer="";
integer giComm=100;
default{
    link_message(integer sender,integer num,string mess,key id){if(num==giComm){if(mess=="update"){
        llOwnerSay("Checking for update...");llEmail(gsServer,llGetObjectName(),llGetOwner());
    }}}
}