// Dragon Land - part of the Dragon Library for a Dragon AI Connect agent (Mind plan and up). // Put it next to dragon_api.lsl. The Library is a set of small scripts, one per kind of ability, each with // its own 64 KB: add only the ones you want. No logic and no secrets: the server decides. // Guide: https://dragonaiconnect.com/docs/runtime/toolkit // // Land security, like a security orb: eject, teleport home, ban / unban, the access (pass) list, push, and // return someone's objects on the parcel. It only works when this object and the land have the same owner // (or the object is deeded to the land's group). It never acts on its owner, checks the person is really on // your land, and can warn first: "you have 15 seconds to leave", then act only if they're still there. // // 9110 <- API {"do":"land","op":eject|home|ban|unban|pass_add|pass_remove|push|return,"t":key, // "hours":0 (0 = permanent),"power":1-10,"warn":seconds,"text":warning} // 9118 -> API {"type":"hello","part":"land","rights":"yes"|"no"}; {"type":"land","op","t","result"} // result: done | not_on_land | owner | no_rights | left | asked_permission // 9113 <- API "announce yourself" / "status" // 9110 <- API {"do":"parcel_map","id"} -> 9117 the parcel's real edges, middle and standing (yes | group | no) list gWait; // strided [avatar, op, due (unix), hours, power]: warned, acting when the time is up list gReturn; // avatars whose objects to return once the owner grants permission key gMapId; // the last parcel mapped, and its edges (mapping takes a few seconds: once per parcel) string gMap; integer rights() { key landOwner = llList2Key(llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_OWNER]), 0); return landOwner == llGetOwner(); // a deeded object's owner is the group, which then owns the land } string standing() // yes: same owner (or deeded); group: rented or shared through our group (build, not police) { if (rights()) return "yes"; list d = llGetParcelDetails(llGetPos(), [PARCEL_DETAILS_GROUP]); key grp = llList2Key(d, 0); if (grp != NULL_KEY) { if (grp == llList2Key(llGetObjectDetails(llGetKey(), [OBJECT_GROUP]), 0)) return "group"; } return "no"; } hello() { llMessageLinked(LINK_THIS, 9118, llList2Json(JSON_OBJECT, ["type", "hello", "part", "land", "rights", standing()]), NULL_KEY); } report(string op, key t, string result) { llMessageLinked(LINK_THIS, 9118, llList2Json(JSON_OBJECT, ["type", "land", "op", op, "t", t, "result", result]), NULL_KEY); } act(key t, string op, float hours, float power) { if (t == llGetOwner()) { report(op, t, "owner"); return; } if (!rights()) { report(op, t, "no_rights"); return; } if (op == "ban") { llAddToLandBanList(t, hours); report(op, t, "done"); return; } if (op == "unban") { llRemoveFromLandBanList(t); report(op, t, "done"); return; } if (op == "pass_add") { llAddToLandPassList(t, hours); report(op, t, "done"); return; } if (op == "pass_remove") { llRemoveFromLandPassList(t); report(op, t, "done"); return; } if (op == "return") { if (llGetPermissions() & PERMISSION_RETURN_OBJECTS) { llReturnObjectsByOwner(t, OBJECT_RETURN_PARCEL); report(op, t, "done"); } else { gReturn = llList2List(gReturn + [t], -10, -1); llRequestPermissions(llGetOwner(), PERMISSION_RETURN_OBJECTS); // the owner gets a one-time window report(op, t, "asked_permission"); } return; } if (!llOverMyLand(t)) { report(op, t, "not_on_land"); return; } if (op == "eject") llEjectFromLand(t); else if (op == "home") llTeleportAgentHome(t); else if (op == "push") { vector them = llList2Vector(llGetObjectDetails(t, [OBJECT_POS]), 0); vector dir = them - llGetPos(); dir.z = 0; if (llVecMag(dir) < 0.1) dir = <1, 0, 0>; if (power < 1) power = 3; llPushObject(t, (llVecNorm(dir) + <0, 0, 0.5>) * power * 30.0, ZERO_VECTOR, FALSE); } report(op, t, "done"); } string edges(vector here) // a parcel's real edges and middle: Second Life gives scripts no outline, so ask which { // parcel each 4 m square of the region is in (parcels are made of 4 m squares) key id = llList2Key(llGetParcelDetails(here, [PARCEL_DETAILS_ID]), 0); if (id == gMapId) return gMap; integer x; integer y; integer n; float sx; float sy; float x0 = 256; float y0 = 256; float x1 = 0; float y1 = 0; for (x = 2; x < 256; x += 4) { for (y = 2; y < 256; y += 4) { if (llList2Key(llGetParcelDetails(, [PARCEL_DETAILS_ID]), 0) == id) { ++n; sx += x; sy += y; if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y; } } } if (!n) return "{}"; vector mid = ; integer whole = ((x1 - x0 + 4) * (y1 - y0 + 4) == n * 16); // a plain rectangle if (llList2Key(llGetParcelDetails(mid, [PARCEL_DETAILS_ID]), 0) != id) { float best = 9999; vector in = mid; // an L-shaped parcel's middle can be outside it: for (x = 2; x < 256; x += 4) { // the nearest square that's inside instead for (y = 2; y < 256; y += 4) { vector c = ; if (llVecDist(c, mid) < best) { if (llList2Key(llGetParcelDetails(c, [PARCEL_DETAILS_ID]), 0) == id) { best = llVecDist(c, mid); in = c; } } } } mid = in; } gMapId = id; gMap = llList2Json(JSON_OBJECT, ["from", (string), "to", (string), "size_m", (string)((integer)(x1 - x0 + 4)) + " x " + (string)((integer)(y1 - y0 + 4)), "middle", (string)mid, "rectangle", llList2String(["no (an irregular shape)", "yes"], whole)]); return gMap; } perform(string a) { if (llJsonGetValue(a, ["do"]) == "parcel_map") { // the parcel here: real edges, middle, and whose it is string m = edges(llGetPos()); llMessageLinked(LINK_THIS, 9117, llJsonSetValue(llList2Json(JSON_OBJECT, ["id", llJsonGetValue(a, ["id"])]), ["result"], llJsonSetValue(m, ["standing"], standing())), NULL_KEY); return; } if (llJsonGetValue(a, ["do"]) != "land") return; string op = llJsonGetValue(a, ["op"]); key t = (key)llJsonGetValue(a, ["t"]); if (t) ; else return; // no valid avatar key (LSL can't apply ! to a key) float hours = (float)llJsonGetValue(a, ["hours"]); float power = (float)llJsonGetValue(a, ["power"]); integer warn = (integer)llJsonGetValue(a, ["warn"]); if (warn > 0) { if (t == llGetOwner()) { report(op, t, "owner"); return; } string text = llJsonGetValue(a, ["text"]); if (text == JSON_INVALID || text == "") text = "Please leave this land within " + (string)warn + " seconds."; llRegionSayTo(t, 0, text); gWait = llList2List(gWait + [t, op, llGetUnixTime() + warn, hours, power], -50, -1); llSetTimerEvent(1.0); return; } act(t, op, hours, power); } default { state_entry() { hello(); } on_rez(integer p) { llResetScript(); } changed(integer c) { if (c & (CHANGED_OWNER | CHANGED_REGION)) llResetScript(); } timer() { integer now = llGetUnixTime(); integer i; for (i = 0; i < llGetListLength(gWait); i += 5) { if (llList2Integer(gWait, i + 2) <= now) { key t = llList2Key(gWait, i); string op = llList2String(gWait, i + 1); float hours = llList2Float(gWait, i + 3); float power = llList2Float(gWait, i + 4); gWait = llDeleteSubList(gWait, i, i + 4); i -= 5; if (op == "ban") act(t, op, hours, power); // a ban applies whether they left or not else if (llOverMyLand(t)) act(t, op, hours, power); else report(op, t, "left"); } } if (gWait == []) llSetTimerEvent(0); } run_time_permissions(integer perm) { if (!(perm & PERMISSION_RETURN_OBJECTS)) { gReturn = []; return; } integer i; for (i = 0; i < llGetListLength(gReturn); ++i) { llReturnObjectsByOwner(llList2Key(gReturn, i), OBJECT_RETURN_PARCEL); report("return", llList2Key(gReturn, i), "done"); } gReturn = []; } link_message(integer sender, integer num, string str, key id) { if (num == 9113) { if (str == "status") { llOwnerSay("dragon-land, " + (string)(llGetFreeMemory() / 1024) + " KB free, land rights: " + llList2String(["no (this object and the land need the same owner)", "yes"], rights())); return; } hello(); return; } if (num != 9110) return; integer i; string a = llJsonGetValue(str, [0]); while (a != JSON_INVALID && i < 8) { perform(a); a = llJsonGetValue(str, [++i]); } } }