pixelplanet/utils/redisUnprotect.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-01-30 23:18:26 +00:00
/* @flow */
//this script removes protection from all pixels on main canas
2020-01-30 23:18:26 +00:00
import redis from 'redis';
//ATTENTION Make suer to set the rdis URLs right!!!
const urlo = "redis://localhost:6379";
const url = "redis://localhost:6380";
const rediso = redis.createClient(urlo, { return_buffers: true });
const redisc = redis.createClient(url, { return_buffers: true });
2020-01-30 23:18:26 +00:00
const CANVAS_SIZE = 256 * 256;
const TILE_SIZE = 256;
const CHUNKS_XY = CANVAS_SIZE / TILE_SIZE;
async function moveProtection() {
for (let x = 0; x < CHUNKS_XY; x++) {
for (let y = 0; y < CHUNKS_XY; y++) {
const key = `ch:0:${x}:${y}`;
2022-04-05 19:37:33 +00:00
const chunk = await redisc.get(key);
2020-01-30 23:18:26 +00:00
if (chunk) {
const buffer = new Uint8Array(chunk);
let changed = false;
for (let u = 0; u < buffer.length; ++u) {
const bit = buffer[u];
if (bit & 0x80) {
buffer[u] = bit & 0x1F;
2020-01-30 23:18:26 +00:00
changed = true;
}
}
if (changed) {
2022-04-05 19:37:33 +00:00
await rediso.set(key, Buffer.from(buffer.buffer));
2020-01-30 23:18:26 +00:00
console.log("Changed Chunk ", key);
}
}
}
}
console.log("done");
2020-01-30 23:18:26 +00:00
}
moveProtection();