corrade-lsl-templates

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 41  →  ?path2? @ 42
/source/eggdrop/motd.lsl
@@ -1,11 +1,11 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 //
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
//
// A MOTD module for Corrade Eggdrop.
//
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
///////////////////////////////////////////////////////////////////////////
@@ -17,9 +17,9 @@
if(i != -1) return llList2String(a, 2*i+1);
return "";
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
// Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
string wasKeyValueEncode(list data) {
list k = llList2ListStrided(data, 0, -1, 2);
@@ -32,9 +32,9 @@
} while(llGetListLength(k) != 0);
return llDumpList2String(data, "&");
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2011 Wizardry and Steamworks - License: CC BY 2.0 //
// Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
// http://was.fm/secondlife/wanderer
vector wasCirclePoint(float radius) {
@@ -44,9 +44,9 @@
return <x, y, 0>;
return wasCirclePoint(radius);
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
// escapes a string in conformance with RFC1738
string wasURLEscape(string i) {
@@ -68,9 +68,9 @@
} while(i != "");
return o;
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
list wasCSVToList(string csv) {
list l = [];
@@ -107,9 +107,9 @@
// postcondition: length(s) = 0
return l + m;
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
string wasListToCSV(list l) {
list v = [];
@@ -117,18 +117,18 @@
string a = llDumpList2String(
llParseStringKeepNulls(
llList2String(
l,
l,
0
),
["\""],
),
["\""],
[]
),
"\"\""
);
if(llParseStringKeepNulls(
a,
a,
[" ", ",", "\n", "\""], []
) !=
) !=
(list) a
) a = "\"" + a + "\"";
v += a;
@@ -136,9 +136,9 @@
} while(l != []);
return llDumpList2String(v, ",");
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
// unescapes a string in conformance with RFC1738
string wasURLUnescape(string i) {
@@ -147,24 +147,22 @@
llParseString2List(
llDumpList2String(
llParseString2List(
i,
["+"],
i,
["+"],
[]
),
),
" "
),
["%0D%0A"],
),
["%0D%0A"],
[]
),
),
"\n"
)
);
}
 
// configuration data
string configuration = "";
// callback URL
string URL = "";
// store message over state.
string firstname = "";
string lastname = "";
@@ -171,7 +169,8 @@
string group = "";
string data = "";
string jump_state = "";
integer membershipFee;
 
default {
state_entry() {
llOwnerSay("[MOTD] Starting module...");
@@ -182,7 +181,7 @@
llOwnerSay("[MOTD] Got configuration...");
configuration = message;
jump_state = "create_database";
state url;
state trampoline;
}
timer() {
llOwnerSay("[MOTD] Requesting configuration...");
@@ -192,8 +191,8 @@
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
@@ -202,18 +201,9 @@
llSetTimerEvent(0);
}
}
state url {
 
state trampoline {
state_entry() {
// DEBUG
llOwnerSay("[MOTD] Requesting URL...");
llRequestURL();
}
http_request(key id, string method, string body) {
if(method != URL_REQUEST_GRANTED) return;
URL = body;
// DEBUG
llOwnerSay("[MOTD] Got URL...");
if(jump_state == "create_database")
state create_database;
if(jump_state == "greet")
@@ -222,9 +212,13 @@
state get;
if(jump_state == "set")
state set;
if(jump_state == "fee")
state fee;
if(jump_state == "pay")
state pay;
if(jump_state == "listen_group")
state listen_group;
 
// DEBUG
llOwnerSay("[MOTD] Jump table corrupted, please contact creator...");
llResetScript();
@@ -233,14 +227,14 @@
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
}
}
 
state create_database {
state_entry() {
// DEBUG
@@ -247,48 +241,54 @@
llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration));
llInstantMessage(
wasKeyValueGet(
"corrade",
"corrade",
configuration
),
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
"password",
configuration
)
),
"SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
wasKeyValueGet("motd table", configuration) +
"SQL", wasURLEscape("CREATE TABLE IF NOT EXISTS \"" +
wasKeyValueGet("motd table", configuration) +
"\" (name text unique collate nocase, data text)"),
"callback", wasURLEscape(URL)
"callback", wasURLEscape(
wasKeyValueGet(
"URL",
configuration
)
)
]
)
);
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") {
link_message(integer sender, integer num, string body, key id) {
// Only process callbacks for the database command.
if(id != "callback" || wasKeyValueGet("command", body) != "database")
return;
 
if(wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[MOTD] Unable modify database: " +
llOwnerSay("[MOTD] Unable modify database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
) +
" " +
) +
" " +
wasURLUnescape(
wasKeyValueGet("data", body)
)
 
);
llResetScript();
}
@@ -296,7 +296,6 @@
state listen_group;
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
@@ -303,8 +302,8 @@
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
@@ -313,8 +312,8 @@
llSetTimerEvent(0);
}
}
 
 
state listen_group {
state_entry() {
// DEBUG
@@ -324,7 +323,7 @@
// We only care about notifications now.
if(id != "notification")
return;
 
// Get the group.
group = wasURLUnescape(
wasKeyValueGet(
@@ -332,7 +331,15 @@
message
)
);
 
// This script only processes group and membership notifications.
// Esnure that the notification is meant for the configured group.
if((wasKeyValueGet("type", message) != "membership" && wasKeyValueGet("type", message) != "group") ||
((wasKeyValueGet("type", message) == "membership" || wasKeyValueGet("type", message) == "group") &&
wasURLUnescape(wasKeyValueGet("group", message)) !=
wasKeyValueGet("group", configuration)))
return;
 
// Retrieve the membership notification.
if(wasKeyValueGet("type", message) == "membership" &&
wasKeyValueGet("action", message) == "joined") {
@@ -348,86 +355,92 @@
message
)
);
jump_state = "greet";
state url;
 
if(wasKeyValueGet("pay back", configuration) != "true") {
jump_state = "greet";
state trampoline;
}
 
jump_state = "fee";
state trampoline;
}
// This script only processes group notifications.
if(wasKeyValueGet("type", message) != "group")
return;
 
// Get the sent message.
data = wasURLUnescape(
wasKeyValueGet(
"message",
"message",
message
)
);
 
// Check if this is an eggdrop command.
if(llGetSubString(data, 0, 0) !=
if(llGetSubString(data, 0, 0) !=
wasKeyValueGet("command", configuration))
return;
 
// Check if the command matches the current module.
list command = llParseString2List(data, [" "], []);
if(llList2String(command, 0) !=
if(llList2String(command, 0) !=
wasKeyValueGet("command", configuration) + "motd")
return;
 
// Remove command.
command = llDeleteSubList(command, 0, 0);
 
// Dump the rest of the message.
data = llDumpList2String(command, " ");
 
// DEBUG
//llOwnerSay("Remaining data: " + data);
 
// Get the sent message.
if(data == "") {
jump_state = "get";
state url;
state trampoline;
}
 
data = wasURLEscape(data);
jump_state = "set";
state url;
state trampoline;
}
on_rez(integer num) {
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
}
}
 
state greet {
state_entry() {
// DEBUG
llOwnerSay("[MOTD] Member joined, retrieving MOTD...");
llOwnerSay("[MOTD] Retrieving MOTD...");
llInstantMessage(
wasKeyValueGet(
"corrade",
"corrade",
configuration
),
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
"password",
configuration
)
),
"SQL", wasURLEscape("SELECT data FROM \"" +
wasKeyValueGet("motd table", configuration) +
wasKeyValueGet("motd table", configuration) +
"\" WHERE name=:group"),
"data", wasURLEscape(
wasListToCSV(
@@ -437,19 +450,25 @@
]
)
),
"callback", wasURLEscape(URL)
"callback", wasURLEscape(
wasKeyValueGet(
"URL",
configuration
)
)
]
)
);
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") {
link_message(integer sender, integer num, string body, key id) {
// Only process callbacks for the database command.
if(id != "callback" || wasKeyValueGet("command", body) != "database")
return;
 
if(wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[MOTD] Unable retrieve from database: " +
llOwnerSay("[MOTD] Unable retrieve from database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
@@ -456,7 +475,7 @@
);
state listen_group;
}
 
data = llDumpList2String(
llDeleteSubList(
wasCSVToList(
@@ -469,15 +488,14 @@
),
""
);
 
if(data == "")
state listen_group;
 
data = "Hello " + firstname + " " + lastname + "!" + " " + data;
state tell;
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
@@ -484,8 +502,8 @@
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
@@ -494,7 +512,7 @@
llSetTimerEvent(0);
}
}
 
state get {
state_entry() {
// DEBUG
@@ -501,26 +519,26 @@
llOwnerSay("[MOTD] Retrieving from database.");
llInstantMessage(
wasKeyValueGet(
"corrade",
"corrade",
configuration
),
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
"password",
configuration
)
),
"SQL", wasURLEscape("SELECT data FROM \"" +
wasKeyValueGet("motd table", configuration) +
wasKeyValueGet("motd table", configuration) +
"\" WHERE name=:group"),
"data", wasURLEscape(
wasListToCSV(
@@ -528,7 +546,7 @@
"group",
wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
)
@@ -535,19 +553,25 @@
]
)
),
"callback", wasURLEscape(URL)
"callback", wasURLEscape(
wasKeyValueGet(
"URL",
configuration
)
)
]
)
);
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") {
link_message(integer sender, integer num, string body, key id) {
// Only process callbacks for the database command.
if(id != "callback" || wasKeyValueGet("command", body) != "database")
return;
 
if(wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[MOTD] Unable retrieve from database: " +
llOwnerSay("[MOTD] Unable retrieve from database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
@@ -554,7 +578,7 @@
);
state listen_group;
}
 
data = llDumpList2String(
llDeleteSubList(
wasCSVToList(
@@ -567,16 +591,15 @@
),
""
);
 
if(data == "") {
data = "Sorry, no MOTD is currently set.";
state tell;
}
 
state tell;
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
@@ -583,8 +606,8 @@
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
@@ -593,62 +616,241 @@
llSetTimerEvent(0);
}
}
 
state fee {
state_entry() {
// DEBUG
llOwnerSay("[MOTD] Member joined, getting group membership fee...");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "getgroupdata",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"data", "MembershipFee",
"callback", wasURLEscape(
wasKeyValueGet(
"URL",
configuration
)
)
]
)
);
llSetTimerEvent(60);
}
link_message(integer sender, integer num, string body, key id) {
// Only process callbacks for the database command.
if(id != "callback" || wasKeyValueGet("command", body) != "getgroupdata")
return;
 
if(wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[MOTD] Unable to get group data: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
);
state listen_group;
}
 
list membership = wasCSVToList(
wasURLUnescape(
wasKeyValueGet(
"data",
body
)
)
);
 
membershipFee = llList2Integer(
membership,
llListFindList(
membership,
[ "MembershipFee" ]
) + 1
);
 
if(membershipFee <= 0) {
// DEBUG
llOwnerSay("The configured group does not have a membership fee!");
state listen_group;
}
 
jump_state = "pay";
state trampoline;
}
timer() {
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 pay {
state_entry() {
// DEBUG
llOwnerSay("[MOTD] Paying back the entrance fee...");
llInstantMessage(
wasKeyValueGet(
"corrade",
configuration
),
wasKeyValueEncode(
[
"command", "pay",
"group", wasURLEscape(
wasKeyValueGet(
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
configuration
)
),
"amount", membershipFee,
"entity", "avatar",
"firstname", wasURLEscape(firstname),
"lastname", wasURLEscape(lastname),
"callback", wasURLEscape(
wasKeyValueGet(
"URL",
configuration
)
)
]
)
);
llSetTimerEvent(60);
}
link_message(integer sender, integer num, string body, key id) {
// Only process callbacks for the database command.
if(id != "callback" || wasKeyValueGet("command", body) != "pay")
return;
 
if(wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[MOTD] Unable to pay the entrance fee: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
);
state listen_group;
}
 
// DEBUG
llOwnerSay("[MOTD] Paid back the entrance fee.");
 
jump_state = "greet";
state trampoline;
}
timer() {
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 set {
state_entry() {
// DEBUG
llOwnerSay("[MOTD] Adding to database.");
llOwnerSay("[MOTD] Adding to database...");
llInstantMessage(
wasKeyValueGet(
"corrade",
"corrade",
configuration
),
),
wasKeyValueEncode(
[
"command", "database",
"group", wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
"password",
configuration
)
),
"SQL", wasURLEscape("REPLACE INTO \"" +
wasKeyValueGet("motd table", configuration) +
"\" (name, data) VALUES (:name, :data)"),
wasKeyValueGet("motd table", configuration) +
"\" (name, data) VALUES (:group, :message)"),
"data", wasURLEscape(
wasListToCSV(
[
"name",
"group",
wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
),
"data",
wasURLEscape(data)
"message",
data
]
)
),
"callback", wasURLEscape(URL)
"callback", wasURLEscape(
wasKeyValueGet(
"URL",
configuration
)
)
]
)
);
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") {
link_message(integer sender, integer num, string body, key id) {
// Only process callbacks for the database command.
if(id != "callback" || wasKeyValueGet("command", body) != "database")
return;
 
if(wasKeyValueGet("success", body) != "True") {
// DEBUG
llOwnerSay("[MOTD] Unable modify database: " +
llOwnerSay("[MOTD] Unable modify database: " +
wasURLUnescape(
wasKeyValueGet("error", body)
)
@@ -659,7 +861,6 @@
state tell;
}
timer() {
llReleaseURL(URL);
state listen_group;
}
on_rez(integer num) {
@@ -666,8 +867,8 @@
llResetScript();
}
changed(integer change) {
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
if((change & CHANGED_INVENTORY) ||
(change & CHANGED_REGION_START) ||
(change & CHANGED_OWNER)) {
llResetScript();
}
@@ -676,7 +877,7 @@
llSetTimerEvent(0);
}
}
 
state tell {
state_entry() {
// DEBUG
@@ -683,21 +884,21 @@
llOwnerSay("[MOTD] Sending to group.");
llInstantMessage(
wasKeyValueGet(
"corrade",
"corrade",
configuration
),
),
wasKeyValueEncode(
[
"command", "tell",
"group", wasURLEscape(
wasKeyValueGet(
"group",
"group",
configuration
)
),
"password", wasURLEscape(
wasKeyValueGet(
"password",
"password",
configuration
)
),