corrade-lsl-templates

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 11  →  ?path2? @ 12
/source/eggdrop/wiki.lsl
@@ -176,9 +176,11 @@
// callback URL
string URL = "";
// store message over state.
string path = "";
string data = "";
string path = "";
string jump_state = "";
string action = "";
string statement = "";
string parameters = "";
 
default {
state_entry() {
@@ -189,7 +191,7 @@
if(id != "configuration") return;
llOwnerSay("[Wiki] Got configuration...");
configuration = message;
jump_state = "create_database";
action = "create";
state url;
}
timer() {
@@ -221,87 +223,85 @@
if(method != URL_REQUEST_GRANTED) return;
URL = body;
// DEBUG
llOwnerSay("[Wiki] Got URL...");
if(jump_state == "create_database")
state create_database;
if(jump_state == "get")
state get;
if(jump_state == "set")
state set;
if(jump_state == "dir")
state dir;
if(jump_state == "listen_group")
state listen_group;
llOwnerSay("[Wiki] Got URL.");
// DEBUG
llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
llResetScript();
}
on_rez(integer num) {
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
if(action == "create") {
statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path text unique collate nocase, data text)");
state query;
}
}
}
 
state create_database {
state_entry() {
// DEBUG
llOwnerSay("[Wiki] Creating database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path text unique collate nocase, data text)"),
"callback", wasURLEscape(URL)
]
)
);
llSetTimerEvent(60);
}
http_request(key id, string method, string body) {
llHTTPResponse(id, 200, "OK");
llReleaseURL(URL);
if(wasKeyValueGet("command", body) != "database" ||
wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[Wiki] Unable modify database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
if(action == "get") {
statement = wasURLEscape("SELECT data FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path");
parameters = wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path)
]
)
);
state listen_group;
state query;
}
llOwnerSay("[Wiki] Database created!");
state listen_group;
if(action == "set") {
if(data == "") {
statement = wasURLEscape("DELETE FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path");
parameters = wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path)
]
)
);
state query;
}
statement = wasURLEscape("REPLACE INTO \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path, data) VALUES (:path, :data)");
parameters = wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path),
"data",
wasURLEscape(data)
]
)
);
state query;
}
if(action == "dir") {
if(path == "/") {
path = "";
statement = wasURLEscape("SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + wasKeyValueGet("wiki table", configuration) + "\" WHERE path LIKE '/%'");
state query;
}
statement = wasURLEscape("SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + wasKeyValueGet("wiki table", configuration) + "\" WHERE path LIKE :path");
parameters = wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path + "/" + "%"),
"base",
wasURLEscape("/" + llDumpList2String(llParseString2List(path, ["/"], []), "/") + "/")
]
)
);
state query;
}
// DEBUG
llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
llResetScript();
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
llResetScript();
}
@@ -312,9 +312,6 @@
llResetScript();
}
}
state_exit() {
llSetTimerEvent(0);
}
}
 
state listen_group {
@@ -345,9 +342,9 @@
return;
// Check if the command matches the current module.
list command = llParseString2List(data,
[wasKeyValueGet("command", configuration), " "], ["@"]);
if(llList2String(command, 0) != "wiki")
list command = llParseString2List(data, [" "], []);
if(llList2String(command, 0) !=
wasKeyValueGet("command", configuration) + "wiki")
return;
// Remove command.
@@ -362,7 +359,7 @@
}
// Get the sub-command and store it as a jump state.
jump_state = llList2String(command, 0);
action = llList2String(command, 0);
// Remove sub-command.
command = llDeleteSubList(command, 0, 0);
@@ -415,51 +412,10 @@
}
}
 
state set {
state query {
state_entry() {
if(data == "") {
// DEBUG
llOwnerSay("[Wiki] Removing from database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"SQL", wasURLEscape("DELETE FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path"),
"data", wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape("path")
]
)
),
"callback", wasURLEscape(URL)
]
)
);
llSetTimerEvent(60);
return;
}
// DEBUG
llOwnerSay("[Wiki] Adding to database.");
llOwnerSay("[Wiki] Executing action: " + action);
llInstantMessage(
wasKeyValueGet(
"corrade",
@@ -480,19 +436,8 @@
configuration
)
),
"SQL", wasURLEscape("REPLACE INTO \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path, data) VALUES (:path, :data)"),
"data", wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path),
"data",
wasURLEscape(data)
]
)
),
"SQL", statement,
"data", parameters,
"callback", wasURLEscape(URL)
]
)
@@ -505,7 +450,7 @@
if(wasKeyValueGet("command", body) != "database" ||
wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[Wiki] Unable modify database: " +
llOwnerSay("[Wiki] Unable query database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
@@ -512,242 +457,114 @@
);
state listen_group;
}
if(data == "") {
data = "Deleted from " + path;
// Process actions.
if(action == "set") {
if(data == "") {
data = "Deleted from " + path;
state tell;
}
data = "Stored into " + path;
state tell;
}
data = "Stored into " + path;
state tell;
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
}
state_exit() {
llSetTimerEvent(0);
}
}
 
state get {
state_entry() {
// DEBUG
llOwnerSay("[Wiki] Retrieving from database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
if(action == "get") {
data = llDumpList2String(
llDeleteSubList(
wasCSVToList(
wasURLUnescape(
wasKeyValueGet("data", body)
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"SQL", wasURLEscape("SELECT data FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path"),
"data", wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path)
]
)
),
"callback", wasURLEscape(URL)
]
)
);
llSetTimerEvent(60);
}
http_request(key id, string method, string body) {
llHTTPResponse(id, 200, "OK");
llReleaseURL(URL);
if(wasKeyValueGet("command", body) != "database" ||
wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[Wiki] Unable retrieve from database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
0,
0
),
""
);
state listen_group;
}
data = llDumpList2String(
llDeleteSubList(
wasCSVToList(
wasURLUnescape(
wasKeyValueGet("data", body)
)
),
0,
0
),
""
);
if(data == "") {
data = "Sorry, that path contains no data.";
state tell;
}
if(data == "") {
data = "Sorry, that path contains no data.";
data = path + ": " + data;
state tell;
}
data = path + ": " + data;
state tell;
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
}
state_exit() {
llSetTimerEvent(0);
}
}
 
state dir {
state_entry() {
// DEBUG
llOwnerSay("[Wiki] Listing paths from database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
if(action == "dir") {
llOwnerSay(wasURLUnescape(
wasKeyValueGet("data", body)
));
list paths = llList2ListStrided(
llDeleteSubList(
wasCSVToList(
wasURLUnescape(
wasKeyValueGet("data", body)
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"SQL", wasURLEscape("SELECT path FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path like :path"),
"data", wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path + "%")
]
)
),
"callback", wasURLEscape(URL)
]
)
);
llSetTimerEvent(60);
}
http_request(key id, string method, string body) {
llHTTPResponse(id, 200, "OK");
llReleaseURL(URL);
if(wasKeyValueGet("command", body) != "database" ||
wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[Wiki] Unable retrieve from database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
);
state listen_group;
}
list paths = llList2ListStrided(
llDeleteSubList(
wasCSVToList(
wasURLUnescape(
wasKeyValueGet("data", body)
)
0,
0
),
0,
0
),
0,
-1,
2
);
-1,
2
);
if(llGetListLength(paths) == 0) {
data = "Sorry, that path contains no sub-paths.";
state tell;
}
if(llGetListLength(paths) == 0) {
data = "Sorry, that path contains no sub-paths.";
state tell;
}
// Eliminate path component.
if(path == "/")
path = "";
// Eliminate path component.
if(path == "/")
path = "";
list sibling = [];
do {
// Get the path part.
string part = llList2String(paths, 0);
list sibling = [];
do {
// Get the path part.
string part = llList2String(paths, 0);
// Remove the path component.
string child = llStringTrim(
llDumpList2String(
llParseString2List(
part,
[path, "/"],
[]
// Remove the path component.
string child = llStringTrim(
llDumpList2String(
llParseString2List(
part,
[path, "/"],
[]
),
"/"
),
"/"
),
STRING_TRIM
STRING_TRIM
);
);
integer i = llSubStringIndex(child, "/");
if(i == -1) {
sibling += path + "/" + child;
jump continue;
}
child = path + "/" + llDeleteSubString(child, i, -1) + "/";
if(llListFindList(sibling, (list)child) == -1)
sibling += child;
@continue;
paths = llDeleteSubList(paths, 0, 0);
} while(llGetListLength(paths) != 0);
integer i = llSubStringIndex(child, "/");
if(i == -1) {
sibling += path + "/" + child;
jump continue_dir;
}
child = path + "/" + llDeleteSubString(child, i, -1) + "/";
if(llListFindList(sibling, (list)child) == -1)
sibling += child;
@continue_dir;
paths = llDeleteSubList(paths, 0, 0);
} while(llGetListLength(paths) != 0);
data = llList2CSV(sibling);
// GC
sibling = [];
data = llList2CSV(sibling);
// GC
sibling = [];
state tell;
state tell;
}
// Don't announce creating table.
if(action == "create")
state listen_group;
// DEBUG
llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
state listen_group;
}
timer() {
llReleaseURL(URL);