Myriad Lite Region Settings Server
Myriad_Lite_Region_Settings_Server-v0.0.1-20111114.lsl
// Myriad_Lite_Region_Settings_Server-v0.0.1-20111114.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 licensed under the
// Creative Commons Attribution-Share Alike-Non-Commercial 3.0 Unported
// http://creativecommons.org/licenses/by-nc-sa/3.0/
// CONSTANTS - DO NOT CHANGE DURING RUN
string VERSION = "0.0.1"; // Allen Kerensky's script version
string VERSIONDATE = "20111114"; // Allen Kerensky's script yyyymmdd
integer CHAN_MYRIAD = -999; // regionwide channel for Myriad events
string CARD = "Myriad_Lite_Region_Settings-v0.0.0-20111114.txt"; // notecard data table
// RUNTIME GLOBALS - CAN CHANGE DURING RUN
integer HAND_MYRIAD;
list REGION_SETTINGS; // list of setting categories
list REGION_GENERATORS; // character generation methods
list REGION_POINT_POOLS; // campaign power levels and point pool basis
list REGION_STATISTICS; // list of statistics for characters in this region
list REGION_RESILIENCES; // list of healths for various combats used
list REGION_SKILLS; // list of available skills
list REGION_GENRES; // list of available skill and item genres to allow
list REGION_BOONS; // list of available boons
list REGION_FLAWS; // list of available flaws
list REGION_MORTAL_EFFECTS; // list of available mortal combat special effects
list REGION_SOCIAL_EFFECTS; // list of available social combat special effects
list REGION_MAGIC_EFFECTS; // list of available magical special effects
list REGION_VEHICLE_EFFECTS; // list of available vehicle special effects
list REGION_SPECIES; // list of available species templates
list REGION_BACKGROUNDS; // list of available background templates
list REGION_CAREERS; // list of available career templates
list REGION_EQUIPMENT; // list of available starting items
integer LINE = 0; // reading line number
key QUERY = NULL_KEY; // track notecard queries
// DEBUG - show debug messages
DEBUG(string dmessage) {
llOwnerSay("DEBUG: "+dmessage);
}
// SETUP - begin
SETUP() {
llSetText("Server: Region",<1,1,1>,1);
if ( HAND_MYRIAD != 0 ) llListenRemove(HAND_MYRIAD); // is there already a listener? clear it
HAND_MYRIAD = llListen(CHAN_MYRIAD,"",NULL_KEY,""); // start region channel listener
DEBUG("Region setting server "+VERSION+" "+VERSIONDATE+" loading region configuration. Please wait..."); // tell player we're waiting for data server
QUERY = llGetNotecardLine(CARD,LINE++); // ask for line from notecard and advance to next line
}
// RESET - reload
RESET() {
llResetScript(); // now reset
}
LIST_REGION_SETTINGS(key id) {
integer replyto = (integer)("0x"+llGetSubString((string)id,0,6)); // calculate requestor-specific chat channel to reply to
llRegionSay(replyto,"REGION_SETTINGS|SETTINGS="+llList2CSV(REGION_SETTINGS)); // send list of settings categories
integer numsettings = llGetListLength(REGION_SETTINGS); // how long is list of categories
integer count; // temporary place to store our count of lists we've sent
for ( count = 0; count < numsettings; count++) { // step through all settings lists
string index = llList2String(REGION_SETTINGS,count); // find position of current category to send in list
string reply = "REGION_SETTING|"+llToUpper(index)+"="; // start our output string
if ( index == "GENERATORS" ) { reply += llList2CSV(REGION_GENERATORS); } // if sending generators, add the generator methods
if ( index == "POINT_POOLS" ) { reply += llList2CSV(REGION_POINT_POOLS); } // if sending point pools, add the pool configuration
if ( index == "STATISTICS" ) { reply += llList2CSV(REGION_STATISTICS); } // if sending stats, add the statistics list
if ( index == "RESILIENCES" ) { reply += llList2CSV(REGION_RESILIENCES); } // if sending resiliences, add the resilience list
if ( index == "SKILLS" ) { reply += llList2CSV(REGION_SKILLS); } // if sending skills, add the skill list
if ( index == "GENRES" ) { reply += llList2CSV(REGION_GENRES); } // if sending genres, add the genre list
if ( index == "BOONS" ) { reply += llList2CSV(REGION_BOONS); } // if sending boons, add the boon list
if ( index == "FLAWS" ) { reply += llList2CSV(REGION_FLAWS); } // if sending flaws, add the flaw list
if ( index == "MORTAL_EFFECTS" ) { reply += llList2CSV(REGION_MORTAL_EFFECTS); } // if sending mortal sfx, add the sfx list
if ( index == "SOCIAL_EFFECTS" ) { reply += llList2CSV(REGION_SOCIAL_EFFECTS); } // if sending social sfx, add the sfx list
if ( index == "MAGIC_EFFECTS" ) { reply += llList2CSV(REGION_MAGIC_EFFECTS); } // if sending magic sfx, add the sfx list
if ( index == "VEHICLE_EFFECTS" ) { reply += llList2CSV(REGION_VEHICLE_EFFECTS); } // if sending vehicle sfx, add the sfx list
if ( index == "SPECIES" ) { reply += llList2CSV(REGION_SPECIES); } // if sending species templates, add the template list
if ( index == "BACKGROUNDS" ) { reply += llList2CSV(REGION_BACKGROUNDS); } // if sending background templates, add the template list
if ( index == "CAREERS" ) { reply += llList2CSV(REGION_CAREERS); } // if sending career templates, add the template list
if ( index == "EQUIPMENT" ) { reply += llList2CSV(REGION_EQUIPMENT);} // if sending equipment, add the equipment list
llRegionSay(replyto,reply); // send current setting and list FIXME what if output > 1016 characters?
}
llRegionSay(replyto,"REGION_SETTING|LIST_COMPLETE"); // send a final marker to tell character creator all config has been sent
}
GET_REGION_SETTING(key id,string msg) {
integer replyto = (integer)("0x"+llGetSubString((string)id,0,6)); // calculate requestor-specific chat channel to reply to
list tokens = llParseString2List(msg,["|"],[]); // split msg into list around pipe symbols
string index = llList2String(tokens,1); // the name of the item to get
integer regionindex = llListFindList(REGION_SETTINGS,[index]); // get the position of that item in the list
if ( regionindex != -1 ) { // was item name in the list?
string reply = "REGION_SETTING|"+llToUpper(index)+"="; // start output item data NO PLURAL here - we're sending 1 setting list
if ( index == "SETTINGS" ) { reply += llList2CSV(REGION_SETTINGS); } // if settings requested, add settings list to output
if ( index == "GENERATORS" ) { reply += llList2CSV(REGION_GENERATORS); } // if generators requested, add generator to output
if ( index == "POINT_POOLS" ) { reply += llList2CSV(REGION_POINT_POOLS); } // if point pools requested, add point pools to output
if ( index == "STATISTICS" ) { reply += llList2CSV(REGION_STATISTICS); } // if statistics requested, add statistics to output
if ( index == "RESILIENCES" ) { reply += llList2CSV(REGION_RESILIENCES); } // if resiliences requested, add resiliences to output
if ( index == "SKILLS" ) { reply += llList2CSV(REGION_SKILLS); } // if skills requested, add skills to output
if ( index == "GENRES" ) { reply += llList2CSV(REGION_GENRES); } // if genres requested, add genres to output
if ( index == "BOONS" ) { reply += llList2CSV(REGION_BOONS); } // if boons requested, add boons to output
if ( index == "FLAWS" ) { reply += llList2CSV(REGION_FLAWS); } // if flaws requested, add flaws to output
if ( index == "MORTAL_EFFECTS" ) { reply += llList2CSV(REGION_MORTAL_EFFECTS); } // if mortal sfx requested, add sfx to output
if ( index == "SOCIAL_EFFECTS" ) { reply += llList2CSV(REGION_SOCIAL_EFFECTS); } // if social sfx requested, add sfx to output
if ( index == "MAGIC_EFFECTS" ) { reply += llList2CSV(REGION_MAGIC_EFFECTS); } // if magic sfx requested, add sfx to output
if ( index == "VEHICLE_EFFECTS" ) { reply += llList2CSV(REGION_VEHICLE_EFFECTS); } // if vehicle sfx requested, add sfx to output
if ( index == "SPECIES" ) { reply += llList2CSV(REGION_SPECIES); } // if species templates requested, add templates to output
if ( index == "BACKGROUNDS" ) { reply += llList2CSV(REGION_BACKGROUNDS); } // if background templates requested, add templates to output
if ( index == "CAREERS" ) { reply += llList2CSV(REGION_CAREERS); } // if career templates requested, add templates to output
if ( index == "EQUIPMENT" ) { reply += llList2CSV(REGION_EQUIPMENT); } // if equipment requested, add equipment to output
llRegionSay(replyto,reply); // send current output line FIXME what if output line > 1016 characters?
} else {
llRegionSay(replyto,"REGION_SETTING|ERROR=Requested Region Setting ("+index+") not found"); // item requested does not exist, return an error
}
}
SET_REGION_SETTING() {
// FIXME - do we need this?
}
// DEFAULT STATE
default {
// STATE ENTRY - called on Reset
state_entry() {
SETUP(); // show credits and start character sheet load
}
// on_rez - when rezzed to ground or from inventory as attachment during login
on_rez(integer params) {
params = 0; // LSLINT
RESET(); // force to go through state entry
}
// attach - when attached or detached from inventory or during login
attach(key id) {
id = NULL_KEY; // LSLINT
RESET(); // force to go through state entry
}
// dataserver called for each line of notecard requested
dataserver(key queryid,string data) {
if ( queryid == QUERY ) { // ataserver gave us line we asked for?
if ( data != EOF ) { // we're not at end of notecard file?
if ( llGetSubString(data,0,0) == "#" ) { // does this line start with comment mark?
QUERY = llGetNotecardLine(CARD,LINE++); // ignore comment and ask for the next line
return;
}
// Parse non-comment lines in keyword = value[,value,...] format
list FIELDS = llParseString2List(data,["="],[]); // break line of text into = delimited fields
string CMD = llStringTrim(llList2String(FIELDS,0),STRING_TRIM); // field zero is the "command"
string DATA = llStringTrim(llList2String(FIELDS,1),STRING_TRIM); // field one is the data
// we're appending to lists to handle long lists that use multiple config lines per keyword see EQUIPMENT for example
if ( CMD == "SETTINGS" ) { REGION_SETTINGS = REGION_SETTINGS + llCSV2List(DATA);} // add setting list to memory
if ( CMD == "GENERATORS" ) { REGION_GENERATORS = REGION_GENERATORS + llCSV2List(DATA); } // add generator list to memory
if ( CMD == "POINT_POOLS") { REGION_POINT_POOLS = REGION_POINT_POOLS + llCSV2List(DATA);} // add point pool list to memory
if ( CMD == "STATISTICS") { REGION_STATISTICS = REGION_STATISTICS + llCSV2List(DATA); } // add stat list to memory
if ( CMD == "RESILIENCES" ) { REGION_RESILIENCES = REGION_RESILIENCES + llCSV2List(DATA); } // add health list to memory
if ( CMD == "SKILLS" ) { REGION_SKILLS = REGION_SKILLS + llCSV2List(DATA); } // add skill list to memory
if ( CMD == "GENRES" ) { REGION_GENRES = REGION_GENRES + llCSV2List(DATA); } // add genre list to memory
if ( CMD == "BOONS" ) { REGION_BOONS = REGION_BOONS + llCSV2List(DATA); } // add boon list to memory
if ( CMD == "FLAWS" ) { REGION_FLAWS = REGION_FLAWS + llCSV2List(DATA); } // add flaw list to memory
if ( CMD == "MORTAL_EFFECTS" ) { REGION_MORTAL_EFFECTS = REGION_MORTAL_EFFECTS + llCSV2List(DATA); } // add sfx list to memory
if ( CMD == "SOCIAL_EFFECTS" ) { REGION_SOCIAL_EFFECTS = REGION_SOCIAL_EFFECTS + llCSV2List(DATA); } // add sfx list to memory
if ( CMD == "MAGIC_EFFECTS" ) { REGION_MAGIC_EFFECTS = REGION_MAGIC_EFFECTS + llCSV2List(DATA); } // add sfx list to memory
if ( CMD == "VEHICLE_EFFECTS" ) { REGION_VEHICLE_EFFECTS = REGION_VEHICLE_EFFECTS + llCSV2List(DATA);} // add sfx list to memory
if ( CMD == "SPECIES" ) { REGION_SPECIES = REGION_SPECIES + llCSV2List(DATA); } // add template list to memory
if ( CMD == "BACKGROUNDS" ) { REGION_BACKGROUNDS = REGION_BACKGROUNDS + llCSV2List(DATA); } // add template list to memory
if ( CMD == "CAREERS" ) { REGION_CAREERS = REGION_CAREERS + llCSV2List(DATA); } // add career list to memory
if ( CMD == "EQUIPMENT" ) { REGION_EQUIPMENT = REGION_EQUIPMENT + llCSV2List(DATA); } // add equipment list to memory
QUERY = llGetNotecardLine(CARD,LINE++); // finished with known keywords, get next line
} else { // end of notecard
DEBUG("Region settings loaded. Server ready. Free Memory: "+(string)llGetFreeMemory()); // done, ready to serve
} // end if data not equal eof
} // end if query id equal
} // end if data server event
listen(integer channel,string name,key id,string msg) {
channel = 0; // LSLINT
name = ""; // LSLINT
list tokens = llParseString2List(msg,["|"],[ ]); // split msg into list around pipe symbols
string command = llList2String(tokens,0); // first field is some sort of command
if ( command == "LIST_REGION_SETTINGS" ) { // is this a list all region settings request?
LIST_REGION_SETTINGS(id); // call it
return; // return early instead of processing more
}
if ( command == "GET_REGION_SETTING" ) { // GET_REGION_SETTING|string settingname
GET_REGION_SETTING(id,msg); // call it
return; // return early instead of processing more
}
if ( command == "SET_REGION_SETTING" ) { // is this a set-region-setting request?
SET_REGION_SETTING(); // call it
return; // return early in case we add more later
}
}
} // end default state