From 327ed17b1d66f89a2165d626775698edbc2c0e9d Mon Sep 17 00:00:00 2001
From: Holden Rohrer
Date: Thu, 16 Jul 2020 17:13:47 -0400
Subject: added nword protector using an add'l id func to Queue
This should be added to sched.Queue so (even if it requires a somewhat
convoluted workflow), any write may be tracked.
---
examples/nword.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
create mode 100644 examples/nword.js
(limited to 'examples')
diff --git a/examples/nword.js b/examples/nword.js
new file mode 100644
index 0000000..fe09a0b
--- /dev/null
+++ b/examples/nword.js
@@ -0,0 +1,50 @@
+// Replaces the n-word with "n-word"
+const Socket = require('../socket');
+const Space = require('../space');
+const Search = require('../tools/search');
+const Queue = require('../tools/queue');
+const maketiles = require('../utils/maketiles');
+const vec = require('../utils/vec');
+const wwrap = require('../utils/writewrap');
+
+var main = new Socket();
+wwrap.call(main);
+var search = new Search();
+var ids = [];
+var idcall = [];
+var wq = new Queue(1000, 200, (w,max) =>{
+ let globid = main.write(w);
+ let id;
+ while (id = ids.shift()) {
+ if (id > max) break;
+ main.on(globid, idcall.shift());
+ }
+});
+
+main.on('open',()=>{wq.enable(); console.log('here');});
+
+var expire = {};
+main.on('tileUpdate', (send, source, tiles)=>{
+ let tiledata = maketiles(tiles);
+ for (loc of tiledata.locs) {
+ let spc = tiledata.tilespaces[loc];
+ if (search.has(loc)){
+ clearTimeout(expire[loc]);
+ search.del(loc);
+ }
+ search.add(loc, spc);
+ expire[loc] = setTimeout(() => {search.del(loc); delete expire[loc];},
+ 30000);
+ }
+});
+
+search.match(new Space().adhoc('nigger'), clean);
+search.match(new Space().adhoc('Nigger'), clean);
+search.match(new Space().adhoc('NIGGER'), clean);
+
+let response = new Space().adhoc(' I am a racist ');
+function clean(coord, send){
+ response.loc = vec.add(coord,[0,-6]);
+ ids.push(wq.enqueue(response.towrite()));
+ idcall.push(() => {search.update(response);});
+}
--
cgit