User:Allen Kerensky/Myriad Lite Dev/Myriad Lite Rumor Server-v0.0.3-20110924.lsl

From OpenSimulator

Jump to: navigation, search

Myriad_Lite_Rumor_Server-v0.0.3-20110924.lsl

Place this script into the Rumor Server prim along with SEED_RUMORS.txt, an Anti-Delay Manager, and one or more Anti-Delay Node scripts.

// Myriad_Lite_Rumor_Server-v0.0.3-20110924.lsl
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG licensed under the Creative Commons Attribution 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
// Myriad Lite software Copyright (c) 2011 by Allen Kerensky (OSG/SL)
// Myriad Lite Module Rumors licensed under the
// Creative Commons Attribution-Share Alike-Non-Commercial 3.0 Unported
// http://creativecommons.org/licenses/by-nc-sa/3.0/

// !!! CODED TO WORK WITH ANTI-DELAY NODE MANAGER AND ONE OR MORE ANTI-DELAY NODE SCRIPTS !!!
// http://wiki.secondlife.com/wiki/AntiDelay_Node

list    ADMINS = [ ]; // list all avatar names of your co-admins here, yourself included - defaults to just owner
integer CHAN_MYRIAD = -999;
integer HAND_MYRIAD;
integer CHAN_SERVER;
integer HAND_SERVER;
float   MENU_TIMEOUT = 20;
integer MENU_HANDLE;
integer MENU_CHANNEL;
string  MENU_TITLE = "Myriad Lite Rumor Server";
list    MENU_BUTTONS = ["RUMOR_LIST","RUMOR_MODERATE","RUMOR_CLOSE","RUMOR_RESET"];
vector  GREEN = <0,1,0>;
vector  BLUE = <0,0,1>;
vector  RED = <1,0,0>;
key     MENU_USER;
list    TOKENS;
string  COMMAND;
string  NAME;
string  RUMOR;
integer RUMOR_TIME = 30; // days
list    PENDING; // [ TIME, NAME of Rumor Start, Rumor text with no commas, [ ... ]]
list    RUMORS; // [ TIME, NAME of Rumor Start, Rumor text with no commas, [ ... ]]
integer TIME;
integer LENGTH;
integer INDEX;
list    TEMP;
list    GETTERS;
integer FLAG_DEBUG;

string  notecardName = "SEED_RUMORS.txt";
integer lineCounter;
key     dataRequestID;


CLEAN_RUMOR_LIST() {
    // reset getters queue
    GETTERS = [];
    // scan rumor queue and timeout
    if ( llGetListLength(RUMORS) < 1 ) {
        return;
    } else {
        LENGTH = llGetListLength(RUMORS);
        for ( INDEX = 0; INDEX < LENGTH; INDEX += 3 ) {
            TIME = llList2Integer(RUMORS,INDEX);
            NAME = llList2String(RUMORS,INDEX + 1);
            RUMOR = llList2String(RUMORS,INDEX + 2);
            if ( TIME > llGetUnixTime() ) TEMP = [ TIME,NAME,RUMOR ] + TEMP;
        }
        RUMORS = [] + TEMP;
        TEMP = [];
    }    
}

DEBUG(string debugmsg) {
    if ( FLAG_DEBUG == TRUE ) llSay(DEBUG_CHANNEL,"DEBUG: "+debugmsg);    
}

SETUP() {
        FLAG_DEBUG = FALSE;
        if ( llGetListLength(ADMINS) < 1 ) { // if there are no admins listed
            ADMINS = [llKey2Name(llGetOwner())]; // add the server owner as an admin minimum
        }        
        if ( HAND_MYRIAD != 0 ) llListenRemove(HAND_MYRIAD);
        HAND_MYRIAD = llListen(CHAN_MYRIAD,"",NULL_KEY,"");
        CHAN_SERVER = (integer)("0x"+llGetSubString((string)llGetKey(),0,6));
        if ( HAND_SERVER != 0 ) llListenRemove(HAND_SERVER);
        HAND_SERVER = llListen(CHAN_SERVER,"",NULL_KEY,"");        
        
        llMessageLinked(LINK_THIS,-123,(string)llGetOwner()+"~~~Restarting Rumor Control and reading seed notecard.","instantmessage");

        lineCounter = 0;
        dataRequestID = llGetNotecardLine(notecardName, lineCounter);
}

RESET() {
    llResetScript();
}
default {
    state_entry() {
        SETUP();
    }
    
    dataserver(key queryid, string data) {
        //Check to make sure this is the request we are making.
        //Remember that when data comes back from the dataserver, 
        //it goes to *all* scripts in your prim.
        //So you have to make sure this is the data you want, and
        //not data coming from some other script.
        if (dataRequestID) {
            //If we haven't reached the end of the file
            //Display the incoming data, then request the next line #
            if (data != EOF) { 
                if ( llGetSubString(data,0,0) != "#" ) { // skip comment lines
                    RUMORS = [(llGetUnixTime() + (RUMOR_TIME * 86400))]+ llCSV2List(data) + RUMORS;
                }
                dataRequestID = llGetNotecardLine(notecardName, ++lineCounter);
            } else {
                llSetColor(GREEN,ALL_SIDES);
                llMessageLinked(LINK_THIS,-123,(string)llGetOwner()+"~~~Restart complete. Now serving rumors.","instantmessage");                
            }
        }
    }

    listen(integer channel,string name,key id,string msg) {
        DEBUG("listen: channel=["+(string)channel+"] name=["+name+"] id=["+(string)id+"] message=["+msg+"]");

        integer replychan = (integer)("0x"+llGetSubString((string)llList2String(llGetObjectDetails(id,[OBJECT_OWNER]),0),0,6));
        
        //----------------------------------------------------------------
        // Watch the region-wide channel for a HUD looking for the rumor server
        //----------------------------------------------------------------
        if ( channel == CHAN_MYRIAD ) {
            if ( msg == "RUMOR_SERVER_FIND" ) { // got a request to locate rumor server
                llRegionSay(replychan,"RUMOR_SERVER_FOUND"); // reply that we're found to give requester our UUID for calculating a dynamic channel
                return;
            }
        }
                
        //----------------------------------------------------------------
        // Handle messages sent specifically to the rumor server
        //----------------------------------------------------------------
        if ( channel == CHAN_SERVER ) {
            TOKENS = llParseString2List(msg,["|"],[]); // split on | pipe symbols
            COMMAND = llList2String(TOKENS,0); // first field is the command
            key who = llList2Key(llGetObjectDetails(id,[OBJECT_OWNER]),0); // who is interacting?
            string whoname = llKey2Name(who);
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_MAIN" ) {
                //llDialog(MENU_USER,MENU_TITLE,MENU_BUTTONS,MENU_CHANNEL);
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                llMessageLinked(LINK_THIS,-123,(string)who+"~~~"+MENU_TITLE+"~~~"+llList2CSV(MENU_BUTTONS)+"~~~"+(string)CHAN_SERVER,"dialog");
                return;
            }
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_RESET" ) {
                //llDialog(id,"ERASE EVERYTHING?\nARE YOU SURE?",["YES","NO","MAIN"],MENU_CHANNEL);
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                llMessageLinked(LINK_THIS,-123,(string)who+"~~~ERASE EVERYTHING?\nARE YOU SURE?~~~RUMOR_YES,RUMOR_NO,RUMOR_MAIN~~~"+(string)CHAN_SERVER,"dialog");
                return;
            }
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_YES" ) {
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                RESET();
                return;
            }
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_LIST" ) {
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                if ( llGetListLength(RUMORS) < 1 ) {
                    //llInstantMessage(id,"No pending rumors. Start some.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~No active rumors. Start some.","instantmessage");                    
                } else {
                    LENGTH = llGetListLength(RUMORS);
                    for ( INDEX = 0; INDEX < LENGTH; INDEX += 3 ) {
                        // llInstantMessage(id,llList2String(RUMORS,INDEX + 1)+": "+llList2String(RUMORS, INDEX + 2));
                        llMessageLinked(LINK_THIS,-123,(string)who+"~~~"+llList2String(RUMORS,INDEX + 1)+": "+llList2String(RUMORS, INDEX + 2),"instantmessage");
                    }
                }
                return;
            }        
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_MODERATE" ) {
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                if ( llGetListLength(PENDING) < 1 ) {
                    //llOwnerSay("No pending rumors. Start some.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~No pending rumors. Start some.","instantmessage");
                } else {
                    TIME = llList2Integer(PENDING,0);
                    NAME = llList2String(PENDING,1);
                    RUMOR = llList2String(PENDING,2);
                    //llDialog(id,"Author: "+NAME+"\nRumor: "+RUMOR+"\nApprove Rumor?",["APPROVE","DENY","MAIN"],MENU_CHANNEL);
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~Author: "+NAME+"\nRumor: "+RUMOR+"\nApprove Rumor?~~~RUMOR_APPROVE,RUMOR_DENY,RUMOR_MAIN~~~"+(string)CHAN_SERVER,"dialog");
               }
               return;
            }
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_APPROVE" ) {
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                RUMORS = [ TIME,NAME,RUMOR ] + RUMORS;
                PENDING = llDeleteSubList(PENDING,0,2);
                //llInstantMessage(id,"APPROVED: "+NAME+", "+RUMOR);
                llMessageLinked(LINK_THIS,-123,(string)who+"~~~APPROVED: "+NAME+", "+RUMOR,"instantmessage");
                if ( llGetListLength(PENDING) < 1 ) {
                    llOwnerSay("No more rumors. Start some.");
                } else {
                    TIME = llList2Integer(PENDING,0);
                    NAME = llList2String(PENDING,1);
                    RUMOR = llList2String(PENDING,2);
                    //llDialog(id,"Author: "+NAME+"\nRumor: "+RUMOR+"\nApproved Rumor?",["APPROVE","DENY","MAIN"],MENU_CHANNEL);            
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~Author: "+NAME+"\nRumor: "+RUMOR+"\nApprove Rumor?~~~RUMOR_APPROVE,RUMOR_DENY,RUMOR_MAIN~~~"+(string)CHAN_SERVER,"dialog");
                }
                return;
            }
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( msg == "RUMOR_DENY" ) {
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                PENDING = llDeleteSubList(PENDING,0,2);
                //llInstantMessage(id,"DELETED Rumor.");
                llMessageLinked(LINK_THIS,-123,(string)who+"~~~DELETED Rumor.","instantmessage");
                if ( llGetListLength(PENDING) < 1 ) {
                    //llOwnerSay("No more rumors. Start some.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~No more rumors. Start some.","instantmessage");
                } else {
                    TIME = llList2Integer(PENDING,0);
                    NAME = llList2String(PENDING,1);
                    RUMOR = llList2String(PENDING,2);
                    //llDialog(id,"Author: "+NAME+"\nRumor: "+RUMOR+"\nApprove Rumor?",["APPROVE","DENY","MAIN"],MENU_CHANNEL);
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~Author: "+NAME+"\nRumor: "+RUMOR+"\nApprove Rumor?~~~RUMOR_APPROVE,RUMOR_DENY,RUMOR_MAIN~~~"+(string)CHAN_SERVER,"dialog");            
                }
                return;
            }

            //----------------------------------------------------------------
            //----------------------------------------------------------------                    
            if ( msg == "RUMOR_CLOSE" ) {
                //llWhisper(PUBLIC_CHANNEL,"Closing menu and resetting.");
                if ( llListFindList(ADMINS,[whoname]) < 0 ) {
                    //llInstantMessage(MENU_USER,"You are not an Al Raqis Admin.");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~You are not a Region Admin.","instantmessage");
                    MENU_USER = NULL_KEY;
                    return;
                }
                llMessageLinked(LINK_THIS,-123,(string)who+"~~~Closing menu and resetting.","instantmessage");
                return;
            }

            //----------------------------------------------------------------
            //----------------------------------------------------------------                                    
            if ( COMMAND == "RUMOR_GET" ) {
                 if ( llGetListLength(RUMORS) < 1 ) {
                    //llInstantMessage(llList2Key(TOKENS,1),"No rumors are circulating. Time to start some!");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~No rumors are circulating. Time to start some!","instantmessage");
                    return;
                }
                if ( llListFindList(GETTERS,[who]) < 0 ) {
                    if ( llGetFreeMemory() < 256 ) GETTERS = [];                
                    GETTERS = [who,llGetUnixTime()] + GETTERS;
                } else {
                    if ( llListFindList(ADMINS,[whoname]) < 0 ) {// not an admin
                        integer time = llList2Integer(GETTERS,llListFindList(GETTERS,[who])+1);
                        if ( ( llGetUnixTime() - time ) <= 600 ) {
                            //llInstantMessage(who,"Please allow some time to pass before checking for more rumors.");
                            llMessageLinked(LINK_THIS,-123,(string)who+"~~~Please allow some time to pass before checking for more rumors.","instantmessage");
                            return;
                        }
                    }
                }
                INDEX = (integer)llFrand( (llGetListLength(RUMORS) / 3 ) );
                //llInstantMessage(who,llList2String(RUMORS,INDEX + 2));
                llMessageLinked(LINK_THIS,-123,(string)who+"~~~"+llList2String(RUMORS,(INDEX * 3) + 2),"instantmessage");
                return;
            }
            
            //----------------------------------------------------------------
            //----------------------------------------------------------------
            if ( COMMAND == "RUMOR_PUT" ) {
                NAME = llList2String(TOKENS,1);
                RUMOR = llList2String(TOKENS,2);
                PENDING = [ (llGetUnixTime() + (RUMOR_TIME * 86400)),NAME,RUMOR ] + PENDING;
                //llOwnerSay("AL RAQIS RUMORS: "+NAME+" WAITING FOR YOU TO APPROVE RUMOR: "+RUMOR);
                llMessageLinked(LINK_THIS,-123,(string)llGetOwner()+"~~~RUMORS: "+NAME+" WAITING FOR YOU TO APPROVE RUMOR: "+RUMOR,"instantmessage");
            }
        }        
    }
    
    timer() {
        CLEAN_RUMOR_LIST();
    }
}

Personal tools
General
About This Wiki