User:Allen Kerensky/Myriad Lite/Myriad Lite Rumor Server-Preview6.lsl

From OpenSimulator

< User:Allen Kerensky | Myriad Lite
Revision as of 09:25, 12 August 2012 by Allen Kerensky (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Myriad_Lite_Rumor_Server-Preview6.lsl

// Myriad_Lite_Rumor_Server-Preview6.lsl
// Copyright (c) 2012 by Allen Kerensky (OSG/SL) All Rights Reserved.
// This work is dual-licensed under
// Creative Commons Attribution (CC BY) 3.0 Unported
// http://creativecommons.org/licenses/by/3.0/
// - or -
// Modified BSD License (3-clause)
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, 
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
// * Neither the name of Myriad Lite nor the names of its contributors may be
//   used to endorse or promote products derived from this software without
//   specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
// NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The Myriad RPG System was designed, written, and illustrated by Ashok Desai
// Myriad RPG System licensed under:
// Creative Commons Attribution (CC BY) 2.0 UK: England and Wales
// http://creativecommons.org/licenses/by/2.0/uk/
 
string  VERSION = "0.0.5"; // version number
string  VERDATE = "20120704"; // version date
 
// !!! 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;
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;
integer FLAG_RESTART;
 
string  notecardName = "Myriad_Lite_Seed_Rumors-Preview6.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,"("+llKey2Name(llGetOwner())+") RUMOR SERVER: "+debugmsg);
}
 
SETUP() {
    FLAG_DEBUG = TRUE;
    FLAG_RESTART = 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();
    }
 
    changed(integer changes) {
        if ( changes & CHANGED_INVENTORY ) { // someone changed rumor notecard, restart?
            if ( FLAG_RESTART == TRUE ) {
                RESET();
            }
        }
    }
 
    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 == queryid) {
            //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
                    list tokens = llParseString2List(data,[","],[]);
                    integer time = (llGetUnixTime() + (RUMOR_TIME * 86400));
                    string rumormonger = llList2String(tokens,0);
                    string rumor = llList2String(tokens,1);
                    if ( llStringLength(rumormonger) > 4 && llStringLength(rumor) > 4 ) { // ignore blank rumor lines in notecard
                        RUMORS = [ time, rumormonger, rumor ] + RUMORS;
                        DEBUG("notecard: time=["+(string)time+"] rumormonger=["+rumormonger+"] rumor=["+rumor+"]");
                    }
                }
                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
                integer objchan = (integer)("0x"+llGetSubString((string)id,0,6));
                llRegionSay(objchan,"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);
                // need a way for quests to add pre-approved rumors - if object adding rumor is owned by admin, pre-approve
                if ( llListFindList(ADMINS,[llKey2Name(llList2Key(llGetObjectDetails(id,[OBJECT_OWNER]),0))]) != -1 ) {
                    RUMORS = [ (llGetUnixTime() + (RUMOR_TIME * 86400)), NAME, RUMOR ] + RUMORS;
                    llMessageLinked(LINK_THIS,-123,(string)llGetOwner()+"~~~RUMOR ADDED FOR "+NAME+": "+RUMOR,"instantmessage");
                } else {
                        //llOwnerSay("RUMORS: "+NAME+" WAITING FOR YOU TO APPROVE RUMOR: "+RUMOR);
                        PENDING = [ (llGetUnixTime() + (RUMOR_TIME * 86400)),NAME,RUMOR ] + PENDING;
                    llMessageLinked(LINK_THIS,-123,(string)llGetOwner()+"~~~RUMORS: "+NAME+" WAITING FOR YOU TO APPROVE RUMOR: "+RUMOR,"instantmessage");
                    llMessageLinked(LINK_THIS,-123,(string)who+"~~~Your rumor is pending approval.","instantmessage");
                }
            }
        }
    }
 
    timer() {
        CLEAN_RUMOR_LIST();
    }
}
Personal tools
General
About This Wiki