I'm posting the code here. I want to say I don't own the code, worked on code or know HOW to code but the code there was full perm.
If anybody can help I'd appreciate
Thanks
Rylee
// todo:
// notecard config
// text color
// help
string URL = "http://w-hat.com/name2key"; // name2key url
integer DefaultChan = 1;
float ScanTimer = 10.0;
string Name;
key HttpReqId; // http request id
integer Chan;
integer Index;
list Names;
list Keys;
list CardNames;
key QueryId;
string Text;
vector Color; // for floating text
// Static parameters for reading card config %%%
integer ConfigRequired = FALSE; // whether to fail if no config cards
string ConfigNotecardSuffix = ".cfg"; // string identifying config notecards
float ConfigTimeout = 60.0; // seconds per card to wait for slow server
// Globals for reading card config
integer ConfigLineIndex;
key ConfigRequestID;
list ConfigCards; // list of names of config cards
string ConfigCardName; // name of card being read
integer ConfigCardIndex; // index of next card to read
integer Debug; // Whether to print debug text
config_init()
{
Chan = DefaultChan;
// remove any card-configured items from the main lists
integer cx; // index into card-configured names
integer ix; // index into runtime lists
for (; cx < llGetListLength(CardNames); ++cx) {
string name = llList2String(CardNames, cx);
ix = llListFindList(Names, (list)name);
if (ix != -1) {
debug("removing " + name);
Names = llDeleteSubList(Names, ix, ix);
Keys = llDeleteSubList(Keys, ix, ix);
}
}
CardNames = [];
Debug = 0;
}
// print the configuration -- primarily for debugging.
config_dump()
{
say("Configured Names: " + llList2CSV(CardNames));
}
// Example notecard line parser.
//
// Comments lines begin with a slash
// Each line begins with a command followed by optional arguments
// Equals-sign ("="
separates command and arguments (and args from each other)// Unrecognized commands are ignored -- good for forwards-backwards notecard compatibility
// cardName and lineNum are in case you want to print error messages.
config_parse(string str, string cardName, integer lineNum)
{
str = llStringTrim(str, STRING_TRIM_HEAD); // delete leading spaces
// lines beginning with slash are comments -- ignore them
if (llGetSubString(str,0,0) == "/"
{return;
}
list ldata = llParseString2List(str, ["="], [""]);
string cmd = llList2String(ldata,0);
string arg1 = llList2String(ldata,1);
string arg2 = llList2String(ldata,2);
// Example commands -- replace this code with meaningful stuff! %%%
if (cmd == "av"
{CardNames = (CardNames=[]) + CardNames + llStringTrim(arg1, STRING_TRIM);
} else if (cmd == "channel"
{Chan = (integer) arg1;
} else if (cmd == "color"
{Color = (vector) arg1;
} else if (cmd == "timer"
{ScanTimer = (float) arg1;
}
// this one is a good one to keep
else if (cmd == "debug"
{Debug = (integer) arg1;
}
}
// Post-process any config, if necessary
config_done() {
if (Debug) {
config_dump();
}
say("Config done"
;}
// ==== Utilities ====
// Say something, to owner (%%% modify to whisper or whatever)
say(string str)
{
llOwnerSay(str);
}
debug(string str)
{
if (Debug) {
llWhisper(0, llGetScriptName() + ": " + str);
}
}
// return TRUE if there is a config card
integer next_card()
{
if (ConfigCardIndex >= llGetListLength(ConfigCards)) {
return (FALSE);
}
ConfigLineIndex = 0;
ConfigCardName = llList2String(ConfigCards, ConfigCardIndex);
ConfigCardIndex++;
ConfigRequestID = llGetNotecardLine(ConfigCardName, ConfigLineIndex);
say("Reading " + ConfigCardName);
return (TRUE);
}
// return TRUE if done
integer cardNameKeyQuery() {
++Index;
if (Index >= llGetListLength(CardNames)) {
return TRUE;
}
Name = llList2String(CardNames, Index);
debug("cnq " + (string)Index + ": " + Name);
HttpReqId = llHTTPRequest(URL + "?terse=1&name=" + llEscapeURL(Name), [], "" );
llSetTimerEvent(120.0);
return FALSE;
}
httpResponse(integer status, string body) {
if ( status == 499 )
llOwnerSay("name2key request timed out"
;else if ( status != 200 )
llOwnerSay("the internet exploded!!"
;else if ((key)body == NULL_KEY)
llOwnerSay("No key found for " + Name);
else {
integer ix = llListFindList(Names, (list)Name);
if (ix == -1) {
Names = llListSort(Names + (list)Name, 1, 1);
ix = llListFindList(Names, (list)Name);
Keys = llListInsertList(Keys, (list)body, ix);
} else {
Keys = llListReplaceList(Keys, (list)body, ix, ix);
}
llOwnerSay(Name + " added. Free memory: " + (string)llGetFreeMemory());
Name = "";
}
}
onlineQuery() {
llSetTimerEvent(0.0);
integer count = llGetListLength(Names);
if (count == 0) {
llSetText("", Color, 1.0);
return;
}
++Index;
if (Index >= count) {
llSetText(Text, Color, 1.0);
Text = "";
Index = -1;
llSetTimerEvent(ScanTimer);
return;
}
string id = llList2Key(Keys, Index);
// llSay(0, "query for " + llList2String(Names, Index));
QueryId = llRequestAgentData(id, DATA_ONLINE);
}
// ========== STATES =============
// Default state can do any init you need that doesn't require configuration.
default
{
state_entry() {
Names = [];
Keys = [];
state s_config;
}
}
// This state is only used to get into s_config, because going from
// s_config to s_config won't redo it's state_entry. But we might
// not want to redo anything we might have put in default state entry.
state s_reconfig
{
state_entry() {
state s_config;
}
}
// Read card config
// Multiple notecard version - read all cards with the given extension
state s_config
{
state_entry() {
config_init();
string item;
ConfigCards = [];
integer n = llGetInventoryNumber(INVENTORY_NOTECARD);
while (n-- > 0) {
item = llGetInventoryName(INVENTORY_NOTECARD, n);
if (llSubStringIndex(item, ConfigNotecardSuffix) != -1) {
ConfigCards += [item];
}
}
ConfigCardIndex = 0;
if (next_card()) {
llSetTimerEvent(ConfigTimeout);
} else if (ConfigRequired) {
say("Configuration notecard missing."
; state s_configRetry;
} else {
state s_configDone;
}
}
dataserver(key query_id, string data) {
if (query_id == ConfigRequestID) {
if (data == EOF) {
if (next_card()) {
llSetTimerEvent(ConfigTimeout);
} else {
config_done();
state s_configDone;
}
} else {
config_parse(data, ConfigCardName, ConfigLineIndex);
ConfigRequestID = llGetNotecardLine(ConfigCardName, ++ConfigLineIndex);
}
}
}
timer() {
say("Dataserver time out: touch to retry"
;state s_configRetry;
}
on_rez(integer num) { state s_reconfig; }
changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_reconfig; }
}
state_exit() {
llSetTimerEvent(0);
llOwnerSay("Channel " + (string)Chan);
}
}
state s_configRetry
{
touch_start(integer tot) {
if (llDetectedKey(0) == llGetOwner()) {
state s_config;
}
}
changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_config; }
}
}
state s_configDone {
state_entry() {
Index = -1;
if (cardNameKeyQuery()) {
state s_active;
}
}
http_response(key id, integer status, list meta, string body) {
if (id != HttpReqId) {
return;
}
httpResponse(status, body);
if (cardNameKeyQuery()) {
state s_active;
}
}
changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_config; }
}
state_exit() {
llSetTimerEvent(0.0);
}
}
state s_active {
state_entry() {
llListen(Chan, "", llGetOwner(), ""
;Index = -1;
Text = "";
llSetText(Text, Color, 1.0);
onlineQuery();
}
listen(integer chan, string name, key id, string msg) {
list ldata = llParseString2List(msg, [" "], []);
string cmd = llList2String(ldata, 0);
if (cmd == "add"
{Name = llList2String(ldata, 1) + " " + llList2String(ldata, 2);
HttpReqId = llHTTPRequest(URL + "?terse=1&name=" + llEscapeURL(Name), [], "" );
state s_w_hat;
return;
}
if (cmd == "delete"
{string name = llList2String(ldata, 1) + " " + llList2String(ldata, 2);
integer ix = llListFindList(Names, (list)name);
if (ix == -1) {
llOwnerSay(name + " is not being tracked"
;return;
}
Names = llDeleteSubList(Names, ix, ix);
Keys = llDeleteSubList(Keys, ix, ix);
llOwnerSay(name + " removed"
;if (llListFindList(CardNames, (list)name) != -1) {
llOwnerSay("Note: " + name + " is card-configured. "
+ "You must delete them from the card for this to be permanent"
;}
Index = -1;
onlineQuery();
return;
}
if (cmd == "list"
{llOwnerSay("All avs: " + llList2CSV(Names));
return;
}
if (cmd == "reset"
{llOwnerSay("resetting"
;llResetScript();
}
}
dataserver(key queryid, string data) {
if (queryid != QueryId) {
return;
}
integer online = (integer) data;
if (online) {
Text += "\n" + llList2String(Names, Index);
}
onlineQuery();
}
touch_end(integer count) {
if (llDetectedKey(0) != llGetOwner()) {
return;
}
llOwnerSay("Edit config card or chat on channel " + (string) Chan);
llOwnerSay("Commands:"
;llOwnerSay(" /" + (string)Chan + " add John Smith"
;llOwnerSay(" /" + (string)Chan + " delete John Smith"
;llOwnerSay(" /" + (string)Chan + " list"
;llOwnerSay(" /" + (string)Chan + " reset"
;llOwnerSay("To edit config card, right-click, edit, "
+ "click 'More>>' if you see it, Content, and "
+ "double-click the notecard ending in '.cfg'."
;}
timer() {
onlineQuery();
}
changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_reconfig; }
}
state_exit() {
llSetTimerEvent(0.0);
}
}
state s_w_hat {
state_entry() {
llSetTimerEvent(120.0);
}
http_response(key id, integer status, list meta, string body) {
if (id != HttpReqId) {
state s_active;
return;
}
httpResponse(status, body);
state s_active;
}
timer() {
state s_active;
}
changed(integer change) {
if (change & CHANGED_OWNER) { llResetScript(); }
if (change & CHANGED_INVENTORY) { state s_reconfig; }
}
state_exit() {
llSetTimerEvent(0.0);
}
}
