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();
if(action == "create") {
statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path text unique collate nocase, data text)");
state query;
}
on_rez(integer num) {
llResetScript();
if(action == "get") {
statement = wasURLEscape("SELECT data FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path");
parameters = wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path)
]
)
);
state query;
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
}
}
 
state create_database {
state_entry() {
// DEBUG
llOwnerSay("[Wiki] Creating database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
if(action == "set") {
if(data == "") {
statement = wasURLEscape("DELETE FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path");
parameters = wasURLEscape(
wasListToCSV(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
"path",
wasURLEscape(path)
]
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
);
state query;
}
statement = wasURLEscape("REPLACE INTO \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path text unique collate nocase, data text)"),
"callback", wasURLEscape(URL)
"\" (path, data) VALUES (:path, :data)");
parameters = wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path),
"data",
wasURLEscape(data)
]
)
);
llSetTimerEvent(60);
state query;
}
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 == "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 listen_group;
state query;
}
llOwnerSay("[Wiki] Database created!");
state listen_group;
// DEBUG
llOwnerSay("[Wiki] Jump table corrupted, please contact creator...");
llResetScript();
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
llResetScript();
}
@@ -312,10 +312,7 @@
llResetScript();
}
}
state_exit() {
llSetTimerEvent(0);
}
}
 
state listen_group {
state_entry() {
@@ -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,11 +412,10 @@
}
}
 
state set {
state query {
state_entry() {
if(data == "") {
// DEBUG
llOwnerSay("[Wiki] Removing from database.");
llOwnerSay("[Wiki] Executing action: " + action);
llInstantMessage(
wasKeyValueGet(
"corrade",
@@ -440,65 +436,14 @@
configuration
)
),
"SQL", wasURLEscape("DELETE FROM \"" +
wasKeyValueGet("wiki table", configuration) +
"\" WHERE path=:path"),
"data", wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape("path")
]
)
),
"SQL", statement,
"data", parameters,
"callback", wasURLEscape(URL)
]
)
);
llSetTimerEvent(60);
return;
}
// DEBUG
llOwnerSay("[Wiki] Adding to database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"SQL", wasURLEscape("REPLACE INTO \"" +
wasKeyValueGet("wiki table", configuration) +
"\" (path, data) VALUES (:path, :data)"),
"data", wasURLEscape(
wasListToCSV(
[
"path",
wasURLEscape(path),
"data",
wasURLEscape(data)
]
)
),
"callback", wasURLEscape(URL)
]
)
);
llSetTimerEvent(60);
}
http_request(key id, string method, string body) {
llHTTPResponse(id, 200, "OK");
llReleaseURL(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,6 +457,10 @@
);
state listen_group;
}
// Process actions.
if(action == "set") {
if(data == "") {
data = "Deleted from " + path;
state tell;
@@ -519,80 +468,8 @@
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
)
),
"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)
)
);
state listen_group;
}
if(action == "get") {
data = llDumpList2String(
llDeleteSubList(
wasCSVToList(
@@ -614,80 +491,11 @@
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
)
),
"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;
}
if(action == "dir") {
llOwnerSay(wasURLUnescape(
wasKeyValueGet("data", body)
));
list paths = llList2ListStrided(
llDeleteSubList(
wasCSVToList(
@@ -734,12 +542,12 @@
integer i = llSubStringIndex(child, "/");
if(i == -1) {
sibling += path + "/" + child;
jump continue;
jump continue_dir;
}
child = path + "/" + llDeleteSubString(child, i, -1) + "/";
if(llListFindList(sibling, (list)child) == -1)
sibling += child;
@continue;
@continue_dir;
paths = llDeleteSubList(paths, 0, 0);
} while(llGetListLength(paths) != 0);
@@ -749,6 +557,15 @@
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);
state listen_group;