Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.38 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
  3. ///////////////////////////////////////////////////////////////////////////
  4. //
  5. // This is an automatic teleporter, sitter and animator for the Corrade
  6. // Second Life / OpenSim bot. You can find more details about the bot
  7. // by following the URL: http://was.fm/secondlife/scripted_agents/corrade
  8. //
  9. // The sit script works together with a "configuration" notecard and an
  10. // animation that must both be placed in the same primitive as this script.
  11. // The purpose of this script is to demonstrate sitting with Corrade and
  12. // you are free to use, change, and commercialize it under the GNU/GPLv3
  13. // license at: http://www.gnu.org/licenses/gpl.html
  14. //
  15. ///////////////////////////////////////////////////////////////////////////
  16.  
  17. ///////////////////////////////////////////////////////////////////////////
  18. // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
  19. ///////////////////////////////////////////////////////////////////////////
  20. string wasKeyValueGet(string k, string data) {
  21. if(llStringLength(data) == 0) return "";
  22. if(llStringLength(k) == 0) return "";
  23. list a = llParseString2List(data, ["&", "="], []);
  24. integer i = llListFindList(a, [ k ]);
  25. if(i != -1) return llList2String(a, i+1);
  26. return "";
  27. }
  28.  
  29. ///////////////////////////////////////////////////////////////////////////
  30. // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
  31. ///////////////////////////////////////////////////////////////////////////
  32. string wasKeyValueEncode(list data) {
  33. list k = llList2ListStrided(data, 0, -1, 2);
  34. list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
  35. data = [];
  36. do {
  37. data += llList2String(k, 0) + "=" + llList2String(v, 0);
  38. k = llDeleteSubList(k, 0, 0);
  39. v = llDeleteSubList(v, 0, 0);
  40. } while(llGetListLength(k) != 0);
  41. return llDumpList2String(data, "&");
  42. }
  43.  
  44. ///////////////////////////////////////////////////////////////////////////
  45. // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
  46. ///////////////////////////////////////////////////////////////////////////
  47. integer wasListCountExclude(list input, list exclude) {
  48. if(llGetListLength(input) == 0) return 0;
  49. if(llListFindList(exclude, (list)llList2String(input, 0)) == -1)
  50. return 1 + wasListCountExclude(llDeleteSubList(input, 0, 0), exclude);
  51. return wasListCountExclude(llDeleteSubList(input, 0, 0), exclude);
  52. }
  53.  
  54. ///////////////////////////////////////////////////////////////////////////
  55. // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
  56. ///////////////////////////////////////////////////////////////////////////
  57. // escapes a string in conformance with RFC1738
  58. string wasURLEscape(string i) {
  59. string o = "";
  60. do {
  61. string c = llGetSubString(i, 0, 0);
  62. i = llDeleteSubString(i, 0, 0);
  63. if(c == "") jump continue;
  64. if(c == " ") {
  65. o += "+";
  66. jump continue;
  67. }
  68. if(c == "\n") {
  69. o += "%0D" + llEscapeURL(c);
  70. jump continue;
  71. }
  72. o += llEscapeURL(c);
  73. @continue;
  74. } while(i != "");
  75. return o;
  76. }
  77.  
  78. ///////////////////////////////////////////////////////////////////////////
  79. // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 //
  80. ///////////////////////////////////////////////////////////////////////////
  81. // unescapes a string in conformance with RFC1738
  82. string wasURLUnescape(string i) {
  83. return llUnescapeURL(
  84. llDumpList2String(
  85. llParseString2List(
  86. llDumpList2String(
  87. llParseString2List(
  88. i,
  89. ["+"],
  90. []
  91. ),
  92. " "
  93. ),
  94. ["%0D%0A"],
  95. []
  96. ),
  97. "\n"
  98. )
  99. );
  100. }
  101.  
  102. // corrade data
  103. string CORRADE = "";
  104. string GROUP = "";
  105. string PASSWORD = "";
  106. string PUNISHMENT = "";
  107. list SPLIT = [];
  108. list ANNOUNCE = [];
  109.  
  110. // for holding the callback URL
  111. string callback = "";
  112.  
  113. // for notecard reading
  114. integer line = 0;
  115.  
  116. // key-value data will be read into this list
  117. list tuples = [];
  118. // blacklisted words will be here
  119. list badwords = [];
  120.  
  121. default {
  122. state_entry() {
  123. if(llGetInventoryType("configuration") != INVENTORY_NOTECARD) {
  124. llOwnerSay("Sorry, could not find a configuration inventory notecard.");
  125. return;
  126. }
  127. // DEBUG
  128. llOwnerSay("Reading configuration file...");
  129. llGetNotecardLine("configuration", line);
  130. }
  131. dataserver(key id, string data) {
  132. if(data == EOF) {
  133. // invariant, length(tuples) % 2 == 0
  134. if(llGetListLength(tuples) % 2 != 0) {
  135. llOwnerSay("Error in configuration notecard.");
  136. return;
  137. }
  138. CORRADE = llList2String(
  139. tuples,
  140. llListFindList(
  141. tuples,
  142. [
  143. "corrade"
  144. ]
  145. )
  146. +1
  147. );
  148. if(CORRADE == "") {
  149. llOwnerSay("Error in configuration notecard: corrade");
  150. return;
  151. }
  152. GROUP = llList2String(
  153. tuples,
  154. llListFindList(
  155. tuples,
  156. [
  157. "group"
  158. ]
  159. )
  160. +1
  161. );
  162. if(GROUP == "") {
  163. llOwnerSay("Error in configuration notecard: group");
  164. return;
  165. }
  166. PASSWORD = llList2String(
  167. tuples,
  168. llListFindList(
  169. tuples,
  170. [
  171. "password"
  172. ]
  173. )
  174. +1
  175. );
  176. if(PASSWORD == "") {
  177. llOwnerSay("Error in configuration notecard: password");
  178. return;
  179. }
  180. PUNISHMENT = llList2String(
  181. tuples,
  182. llListFindList(
  183. tuples,
  184. [
  185. "punishment"
  186. ]
  187. )
  188. +1
  189. );
  190. if(PUNISHMENT == "") {
  191. llOwnerSay("Error in configuration notecard: punishment");
  192. return;
  193. }
  194. string split = llList2String(
  195. tuples,
  196. llListFindList(
  197. tuples,
  198. [
  199. "split"
  200. ]
  201. )
  202. +1
  203. );
  204. do {
  205. SPLIT += llGetSubString(split, 0, 0);
  206. split = llDeleteSubString(split, 0, 0);
  207. } while(llStringLength(split) != 0);
  208. if(SPLIT == []) {
  209. llOwnerSay("Error in configuration notecard: split");
  210. return;
  211. }
  212. ANNOUNCE = llCSV2List(
  213. llList2String(
  214. tuples,
  215. llListFindList(
  216. tuples,
  217. [
  218. "announce"
  219. ]
  220. )
  221. +1
  222. )
  223. );
  224. if(ANNOUNCE == []) {
  225. llOwnerSay("Error in configuration notecard: announce");
  226. return;
  227. }
  228. // DEBUG
  229. llOwnerSay("Read configuration notecard...");
  230. state words;
  231. }
  232. if(data == "") jump continue;
  233. integer i = llSubStringIndex(data, "#");
  234. if(i != -1) data = llDeleteSubString(data, i, -1);
  235. list o = llParseString2List(data, ["="], []);
  236. // get rid of starting and ending quotes
  237. string k = llDumpList2String(
  238. llParseString2List(
  239. llStringTrim(
  240. llList2String(
  241. o,
  242. 0
  243. ),
  244. STRING_TRIM),
  245. ["\""], []
  246. ), "\"");
  247. string v = llDumpList2String(
  248. llParseString2List(
  249. llStringTrim(
  250. llList2String(
  251. o,
  252. 1
  253. ),
  254. STRING_TRIM),
  255. ["\""], []
  256. ), "\"");
  257. if(k == "" || v == "") jump continue;
  258. tuples += k;
  259. tuples += v;
  260. @continue;
  261. llGetNotecardLine("configuration", ++line);
  262. }
  263. on_rez(integer num) {
  264. llResetScript();
  265. }
  266. changed(integer change) {
  267. if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
  268. llResetScript();
  269. }
  270. }
  271. }
  272.  
  273. state words {
  274. state_entry() {
  275. if(llGetInventoryType("badwords") != INVENTORY_NOTECARD) {
  276. llOwnerSay("Sorry, could not find a blacklist inventory notecard.");
  277. return;
  278. }
  279. // DEBUG
  280. llOwnerSay("Reading badwords notecard...");
  281. line = 0;
  282. llGetNotecardLine("badwords", line);
  283. }
  284. dataserver(key id, string data) {
  285. if(data == EOF) {
  286. // DEBUG
  287. llOwnerSay("Read badwords notcard...");
  288. state url;
  289. }
  290. if(data == "") jump continue;
  291. badwords += data;
  292. @continue;
  293. llGetNotecardLine("badwords", ++line);
  294. }
  295. on_rez(integer num) {
  296. llResetScript();
  297. }
  298. changed(integer change) {
  299. if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
  300. llResetScript();
  301. }
  302. }
  303. }
  304.  
  305. state url {
  306. state_entry() {
  307. // DEBUG
  308. llOwnerSay("Requesting URL...");
  309. llRequestURL();
  310. }
  311. http_request(key id, string method, string body) {
  312. if(method != URL_REQUEST_GRANTED) return;
  313. callback = body;
  314. // DEBUG
  315. llOwnerSay("Got URL...");
  316. state detect;
  317. }
  318. on_rez(integer num) {
  319. llResetScript();
  320. }
  321. changed(integer change) {
  322. if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
  323. llResetScript();
  324. }
  325. }
  326. }
  327.  
  328. state detect {
  329. state_entry() {
  330. // DEBUG
  331. llOwnerSay("Detecting if Corrade is online...");
  332. llSetTimerEvent(5);
  333. }
  334. timer() {
  335. llRequestAgentData((key)CORRADE, DATA_ONLINE);
  336. }
  337. dataserver(key id, string data) {
  338. if(data != "1") {
  339. // DEBUG
  340. llOwnerSay("Corrade is not online, sleeping...");
  341. llSetTimerEvent(30);
  342. return;
  343. }
  344. state notify;
  345. }
  346. on_rez(integer num) {
  347. llResetScript();
  348. }
  349. changed(integer change) {
  350. if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
  351. llResetScript();
  352. }
  353. }
  354. }
  355.  
  356. state notify {
  357. state_entry() {
  358. // DEBUG
  359. llOwnerSay("Binding to the group chat notification...");
  360. llInstantMessage(
  361. (key)CORRADE,
  362. wasKeyValueEncode(
  363. [
  364. "command", "notify",
  365. "group", wasURLEscape(GROUP),
  366. "password", wasURLEscape(PASSWORD),
  367. "action", "set",
  368. "type", "group",
  369. "URL", wasURLEscape(callback),
  370. "callback", wasURLEscape(callback)
  371. ]
  372. )
  373. );
  374. }
  375. http_request(key id, string method, string body) {
  376. llHTTPResponse(id, 200, "OK");
  377. if(wasKeyValueGet("command", body) != "notify" ||
  378. wasKeyValueGet("success", body) != "True") {
  379. // DEBUG
  380. llOwnerSay("Failed to bind to the group chat notification: " +
  381. wasURLUnescape(
  382. wasKeyValueGet(
  383. "error",
  384. "body"
  385. )
  386. )
  387. );
  388. state detect;
  389. }
  390. // DEBUG
  391. llOwnerSay("Permission notification installed...");
  392. state main;
  393. }
  394. on_rez(integer num) {
  395. llResetScript();
  396. }
  397. changed(integer change) {
  398. if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
  399. llResetScript();
  400. }
  401. }
  402. }
  403.  
  404. state main {
  405. state_entry() {
  406. // DEBUG
  407. llOwnerSay("Waiting for badwords...");
  408. }
  409. http_request(key id, string method, string body) {
  410. llHTTPResponse(id, 200, "OK");
  411.  
  412. // split the input
  413. list input = llParseString2List(
  414. wasURLUnescape(
  415. wasKeyValueGet(
  416. "message",
  417. body
  418. )
  419. ),
  420. SPLIT, []);
  421.  
  422. // now find badwords
  423. string badword = "";
  424. do {
  425. badword = llList2String(input, 0);
  426. if(llListFindList(badwords, (list)badword) != -1) jump punish;
  427. input = llDeleteSubList(input, 0, 0);
  428. } while(llGetListLength(input) != 0);
  429. return;
  430.  
  431. @punish;
  432.  
  433. string firstname = wasURLUnescape(wasKeyValueGet("firstname", body));
  434. string lastname = wasURLUnescape(wasKeyValueGet("lastname", body));
  435.  
  436. if(PUNISHMENT == "eject") {
  437. llOwnerSay("Ejecting: " + firstname + " " + lastname);
  438. llInstantMessage((key)CORRADE,
  439. wasKeyValueEncode(
  440. [
  441. //"command", "eject",
  442. "command", "ban",
  443. "group", wasURLEscape(GROUP),
  444. "password", wasURLEscape(PASSWORD),
  445. //"action", "ban", //
  446. //"avatars", //
  447. "firstname", wasURLEscape(firstname),
  448. "lastname", wasURLEscape(lastname),
  449. "eject", "True",
  450. "callback", wasURLEscape(callback)
  451. ]
  452. )
  453. );
  454. jump announce;
  455. }
  456.  
  457. llOwnerSay("Muting: " + firstname + " " + lastname);
  458. llInstantMessage((key)CORRADE,
  459. wasKeyValueEncode(
  460. [
  461. "command", "moderate",
  462. "group", wasURLEscape(GROUP),
  463. "password", wasURLEscape(PASSWORD),
  464. "avatars", //
  465. "firstname", wasURLEscape(firstname),
  466. "lastname", wasURLEscape(lastname),
  467. "type", "text",
  468. "silence", "true"
  469. ]
  470. )
  471. );
  472.  
  473. @announce;
  474.  
  475. // Go through the list of avatars to announce and
  476. // tell them who has been ajected and for what word
  477. integer i = llGetListLength(ANNOUNCE)-1;
  478. do {
  479. string full = llList2String(ANNOUNCE, i);
  480. list name = llParseString2List(full, [" "], []);
  481. llInstantMessage((key)CORRADE,
  482. wasKeyValueEncode(
  483. [
  484. "command", "tell",
  485. "group", wasURLEscape(GROUP),
  486. "password", wasURLEscape(PASSWORD),
  487. "entity", "avatar",
  488. "firstname", wasURLEscape(llList2String(name, 0)),
  489. "lastname", wasURLEscape(llList2String(name, 1)),
  490. "message", wasURLEscape(
  491. "The avatar " +
  492. firstname +
  493. " " +
  494. lastname +
  495. " was ejecteded from: " +
  496. GROUP + " for saying: \"" +
  497. badword + "\"."
  498. )
  499. ]
  500. )
  501. );
  502. } while(--i>-1);
  503. }
  504. on_rez(integer num) {
  505. llResetScript();
  506. }
  507. changed(integer change) {
  508. if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
  509. llResetScript();
  510. }
  511. }
  512. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement