Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Should be the final version before the batch...
Browse files Browse the repository at this point in the history
mode is functional.
  • Loading branch information
PoneyClairDeLune committed Mar 27, 2023
1 parent 4f17382 commit d022af7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dist/web.js.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/core/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ let sortDist = function (a, b) {
return a[1] - b[1];
};

let humanizedTime = function (inSeconds) {
let humanizedTime = function (inSeconds = 0) {
let ms = `${Math.floor(inSeconds % 1 * 100)}`.padStart(2, "0");
let sec = `${Math.floor(inSeconds % 60)}`.padStart(2, "0");
let min = `${Math.floor(inSeconds / 60) % 60}`.padStart(2, "0");
let hr = `${Math.floor(inSeconds / 3600) % 24}`.padStart(2, "0");
let day = `${Math.floor(inSeconds / 86400)}`;
return `${day}d ${hr}:${min}:${sec}.${ms}`;
};
let humanizedPercentage = function (floatv) {
let humanizedPercentage = function (floatv = 0) {
floatv = Math.round(floatv * 10000) / 100;
let intv = `${Math.floor(floatv)}`;
let fracv = `${Math.floor(floatv * 100 % 100)}`.padStart(2, "0");
Expand Down
77 changes: 68 additions & 9 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"use strict";

import {BuildInfo, humanizedTime} from "./common.js";
import {BuildInfo, humanizedTime, dim2Dist} from "./common.js";
import {IPInfo} from "../core/ipinfo.js";
import {FetchContext} from "./fetchContext.js";
import {RedditAuth} from "./redditAuth.js";
Expand All @@ -14,13 +14,15 @@ import webUiCss from "../web/index.css";
import picoCss from "../../libs/picocss/pico.css";
import webUiJs from "../../dist/web.js.txt";

import KdTreeSrc from "../../libs/kd-tree/kd-tree.js";
let {kdTree, BinaryHeap} = KdTreeSrc;
import {pako} from "../../libs/pako/bridge.min.js";
self.pako = pako;
import {UPNG} from "../../libs/upng/upng.min.js";

const svc = {
cnc: "",
tpl: "https://github.com/ltgcgo/painted-palette/raw/main/conf/service/rdnsptr.json"
tpl: "https://github.com/ltgcgo/painted-palette/raw/main/conf/service/pointer.json"
};

let logoutEverywhere = async function (browserContext, redditAuth) {
Expand Down Expand Up @@ -64,6 +66,29 @@ let waitForProxy = async function () {
};
};
};
let hasTmplEtagChanged = async function (fc, paintGuideObj) {
let statusCode = 0;
try {
let pointer = await (await fc.fetch(svc.tpl)).json();
for (let i = 0; i < pointer?.bot?.length; i ++) {
let url = pointer?.bot[i];
if (statusCode != 200) {
let options = await fc.fetch(url, {
"method": "HEAD"
});
statusCode = options.status;
let etag = options.headers.get("etag");
if (etag != paintGuideObj.etag) {
paintGuideObj.etag = etag;
return true;
};
};
};
return false;
} catch (err) {
console.info(`ETag fetch failed: ${err}`);
};
};
let refreshTemplate = async function (fc, paintGuideObj) {
try {
let pointer = await (await fc.fetch(svc.tpl)).json();
Expand All @@ -87,15 +112,36 @@ let refreshTemplate = async function (fc, paintGuideObj) {
if (maskData && botImageData) {
paintGuideObj.x = pointer.offX || 0;
paintGuideObj.y = pointer.offY || 0;
if (paintGuideObj.data) {
delete paintGuideObj.data;
};
let pointCloud = new kdTree([], dim2Dist, [0, 1]);
let maskArr = UPNG.toRGBA8(maskData)[0];
let botData = UPNG.toRGBA8(botImageData)[0];
let maskView = new DataView(maskArr);
let botView = new DataView(botData);
let width = maskData.width;
let pixels = 0;
let prio = 0, r = 0, g = 0, b = 0;
for (let i = 0; i < maskArr.byteLength; i += 4) {
let prio = maskData.getUint8();
prio = maskView.getUint8(i);
if (prio > 0) {
r = botView.getUint8(i);
g = botView.getUint8(i + 1);
b = botView.getUint8(i + 2);
pointCloud.insert(new Uint8Array([i % width, Math.floor(i / width), prio, r, g, b]));
pixels ++;
};
};
paintGuideObj.pixels = pixels;
paintGuideObj.data = pointCloud;
//console.info(pixels);
//console.info(paintGuideObj.data.balanceFactor());
maskArr = undefined; // Drop it as soon as possible
delete maskView.buffer;
maskView = undefined;
delete botView.buffer;
botView = undefined;
delete maskData.data;
delete maskData.frames;
delete maskData.tabs;
Expand All @@ -106,7 +152,7 @@ let refreshTemplate = async function (fc, paintGuideObj) {
delete botImageData.tabs;
botImageData = undefined; // Drop!
botData = undefined; // Again, drop as soon as possible
console.info(paintGuideObj);
//console.info(paintGuideObj);
if (paintGuideObj.onbuild) {
paintGuideObj.onbuild(paintGuideObj);
};
Expand All @@ -116,6 +162,9 @@ let refreshTemplate = async function (fc, paintGuideObj) {
};
};
let rebuildDamageCloud = async function (paintGuideObj) {};
let getPower = function (paintGuideObj, sensitivity) {
return Math.max(0, Math.min(1, sensitivity * (1 - (0 / paintGuideObj.pixels))));
};
/*
Paint Guide Object
{
Expand Down Expand Up @@ -151,7 +200,7 @@ let main = async function (args) {
};
let paintAnalytics = new Analytics('https://analytics.place.equestria.dev');
// If the painter starts
let botSensitivity = 1, botPower, botMagazine = 2, botPlaced = 0;
let botSensitivity = 1, botMagazine = 2, botPlaced = 0;
switch (args[0]) {
case "help": {
// Show help
Expand Down Expand Up @@ -209,9 +258,11 @@ let main = async function (args) {
let browserContext = new FetchContext('https://place.equestria.dev');
let paintGuide = {};
let templateRefresher = async () => {
await refreshTemplate(browserContext, paintGuide);
if (await hasTmplEtagChanged(browserContext, paintGuide)) {
await refreshTemplate(browserContext, paintGuide);
};
},
templateThread = setInterval(templateRefresher, 180000);
templateThread = setInterval(templateRefresher, 30000);
templateRefresher();
await browserContext.fetch('https://place.equestria.dev/');
// Begin the test server auth flow
Expand Down Expand Up @@ -257,12 +308,15 @@ let main = async function (args) {
let systemBrowser = new FetchContext('https://place.equestria.dev');
let paintGuide = {};
let templateRefresher = async () => {
await refreshTemplate(systemBrowser, paintGuide);
if (await hasTmplEtagChanged(systemBrowser, paintGuide)) {
await refreshTemplate(systemBrowser, paintGuide);
};
},
templateThread = setInterval(templateRefresher, 180000);
templateThread = setInterval(templateRefresher, 30000);
templateRefresher();
let confFile = parseInt(acct) || 14514;
let managedUsers = {};
let managedClients = [];
console.info(`Reading configuration data from "${confFile}.json".`);
let ipInfo = new IPInfo();
ipInfo.start();
Expand Down Expand Up @@ -327,8 +381,13 @@ let main = async function (args) {
uptime: Date.now() - runSince,
bot: {
sen: botSensitivity,
pow: getPower(paintGuide, botSensitivity),
mag: botMagazine,
px: botPlaced
},
art: {
px: paintGuide.pixels,
ok: 0
}
}), {
"headers": {
Expand Down
2 changes: 1 addition & 1 deletion src/web/index.htm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>Painted Palette Web UI</title><link rel="stylesheet" href="./pico.css"><link rel="stylesheet" href="./index.css"><script defer src="./index.js"></script></head><body><div class="container" x-data="{tab:0,showIp:false}"><nav><ul><li><b>Painted Palette Dashboard</b></li></ul><ul><li><a href="javascript:void(0)" @mouseup="tab=0">Accounts</a></li><li><a href="javascript:void(0)" @mouseup="tab=1">Info</a></li><li><a href="javascript:void(0)" @mouseup="tab=2">About</a></li></ul></nav><div id="tab-containers"><div id="tab-a" class="tab-on container-fluid" x-show="tab==0"><div class="grid"><button id="btn-gon" data-tooltip="Enable all managed accounts.">All On</button><button id="btn-goff" data-tooltip="Disable all managed accounts.">All Off</button><button id="btn-full" data-tooltip="Set power to 1 (bots run at full force).">P=1</button><button id="btn-half" data-tooltip="Set power to 0.5 (bots run at half power).">P=0.5</button><button id="btn-empty" data-tooltip="Set power to 0 (bots rest).">P=0</button><button id="btn-grem" data-tooltip="Reset power value to be provided by damage.">P Reset</button><button id="btn-fr" data-tooltip="Force random redistribution of focal points.">Refocus</button></div><div class="grid"><input id="in-acct" placeholder="Account"></input><input id="in-pass" type="password" placeholder="Password"></input><input id="in-otp" placeholder="2FA OTP (Optional)"></input><button id="btn-add" data-tooltip="Add the account for management and attempt login.">Login</button></div><table><thead><tr><th>Account</th><th>Next in</th><th>Active</th><th>Placed</th><th data-tooltip="Where the account is currently at.">Focus</th><th>Actions</th></tr></thead><tbody><template x-for="user in $store.userdata"><tr><td x-text="user?.name||'N/A'"></td><td x-text="user?.stateText||'N/A'"></td><td x-text="user?.active?'Yes':'No'"></td><td><span class="b-palette" :style="{background:user?.lastColour||'transparent'}" data-tooltip="Colour of the last placed pixel."></span> <span x-text="user?.pixelCount||0" data-tooltip="How many pixels have been placed."></span></td><td><span x-text="user?.focusX||0"></span>, <span x-text="user?.focusY||0"></span></td><td><a href="javascript:void(0)" :data-tooltip="['Activate this account.','Deactivate this account.'][+(user?.active||0)]" x-text="user?.active?'Disable':'Enable'">Toggle</a> <a href="javascript:void(0)" data-tooltip="Remove this account.">Remove</a></td></tr></template></tbody></table></div><div x-show="tab==1"><div><big><b>IP info</b></big> <a href="javascript:void(0)" @mouseup="showIp=!showIp" x-text="['Show','Hide'][+showIp]" :data-tooltip="['Click to reveal IP information.','Click to hide IP information.'][+showIp]"></a></div><table class="text-center"><thead><tr><th data-tooltip="Type of the current proxy.">Proxy</th><th data-tooltip="Your current IP address.">IP</th><th data-tooltip="The country your IP is in.">Country</th><th data-tooltip="The AS number of your IP.">ASN</th><th data-tooltip="Name of AS of your IP.">AS Name</th></tr></thead><tbody><tr><td x-text="$store.info?.proxy||'N/A'" :data-tooltip="{'No Proxy':'No proxy is connected.','System':'Proxy set in env var.','Standalone':'Auto-managed proxy.','Tor':'Over Tor.'}[$store.info?.proxy]||'Not known.'"></td><td x-text="showIp?($store.info?.ip||'0.0.0.0'):'Hidden'">IP</td><td x-text="showIp?($store.info?.cc||'XX'):'Hidden'">Country</td><td x-text="showIp?($store.info?.asn||0):'Hidden'">ASN</td><td x-text="showIp?($store.info?.as||'Unknown AS'):'Hidden'">AS Name</td></tr></tbody></table><div><big><b>Managed Stats</b></big></div><table class="text-center"><tbody><tr><th data-tooltip="Information about the canvas.">Canvas</th><td><span data-tooltip="Dimension of the whole canvas."><span x-text="$store.info?.ctw||0"></span>x<span x-text="$store.info?.cth||0"></span></span>, <span data-tooltip="Dimension of the seperate canvases."><span x-text="$store.info?.cuw||0"></span>x<span x-text="$store.info?.cuh||0"></span></span> (<span x-text="$store.info?.cus||0" data-tooltip="How many canvases are there."></span>)</td></tr><tr><th data-tooltip="How much have we finished.">Finished</th><td x-text="$store.info?.finish||0"></td></tr><tr><th data-tooltip="How sensitive to damage the accounts are.">Sensitivity</th><td x-text="$store.info?.sensitivity||0"></td></tr><tr><th data-tooltip="Possibility of pixel placement.">Power</th><td x-text="$store.info?.power||0"></td></tr><tr><th data-tooltip="How many accounts are managed.">Accounts</th><td x-text="$store.info?.acct||0">0</td></tr><tr><th data-tooltip="How many active accounts.">Active</th><td x-text="$store.info?.active||0"></td></tr><tr><th data-tooltip="Max allowed active acounts.">Magazine</th><td x-text="$store.info?.maxOn||0"></td></tr><tr><th data-tooltip="How many accounts were banned.">Banned</th><td x-text="$store.info?.banned||0">0</td></tr><tr><th data-tooltip="How many accounts are still fresh.">Fresh</th><td x-text="$store.info?.fresh||0">0</td></tr><tr><th data-tooltip="How many pixels have been placed.">Placed Pixels</th><td x-text="$store.info?.pixels||0">0</td></tr><tr><th data-tooltip="How long has this instance been running.">Uptime</th><td x-text="$store.sessionUptime">0d 00:00:00</td></tr></tbody></table></div><div x-show="tab==2"><h4>About</h4><table><tbody><tr><th colspan="2" class="text-center" x-text="$store.buildInfo?.name||'Unknown'"></th></tr><tr><th>Version</th><td x-text="$store.buildInfo?.ver||'Unknown'"></td></tr><tr><th>Runtime</th><td x-text="$store.info?.var||'Loading...'"></td></tr><tr><th>OS</th><td x-text="$store.info?.os||'Loading...'"></td></tr><tr><th>Developed by</th><td>Lumière Élevé</td></tr><tr><th>Tested by</th><td>Lumière Élevé<br/>Fauli1221<br/>Starshine</td></tr><tr><th>Produced by</th><td><a href="https://ltgc.cc/" target="_blank">Lightingale Community</a></td></tr></tbody></table></div></div></div></body></html>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>Painted Palette Web UI</title><link rel="stylesheet" href="./pico.css"><link rel="stylesheet" href="./index.css"><script defer src="./index.js"></script></head><body><div class="container" x-data="{tab:0,showIp:false}"><nav><ul><li><b>Painted Palette Dashboard</b></li></ul><ul><li><a href="javascript:void(0)" @mouseup="tab=0">Accounts</a></li><li><a href="javascript:void(0)" @mouseup="tab=1">Info</a></li><li><a href="javascript:void(0)" @mouseup="tab=2">About</a></li></ul></nav><div id="tab-containers"><div id="tab-a" class="tab-on container-fluid" x-show="tab==0"><div class="grid"><button id="btn-gon" data-tooltip="Enable all managed accounts.">All On</button><button id="btn-goff" data-tooltip="Disable all managed accounts.">All Off</button><button id="btn-full" data-tooltip="Set power to 1 (bots run at full force).">P=1</button><button id="btn-half" data-tooltip="Set power to 0.5 (bots run at half power).">P=0.5</button><button id="btn-empty" data-tooltip="Set power to 0 (bots rest).">P=0</button><button id="btn-grem" data-tooltip="Reset power value to be provided by damage.">P Reset</button><button id="btn-fr" data-tooltip="Force random redistribution of focal points.">Refocus</button></div><div class="grid"><input id="in-acct" placeholder="Account"></input><input id="in-pass" type="password" placeholder="Password"></input><input id="in-otp" placeholder="2FA OTP (Optional)"></input><button id="btn-add" data-tooltip="Add the account for management and attempt login.">Login</button></div><table><thead><tr><th>Account</th><th>Next in</th><th>Active</th><th>Placed</th><th data-tooltip="Where the account is currently at.">Focus</th><th>Actions</th></tr></thead><tbody><template x-for="user in $store.userdata"><tr><td x-text="user?.name||'N/A'"></td><td x-text="user?.stateText||'N/A'"></td><td x-text="user?.active?'Yes':'No'"></td><td><span class="b-palette" :style="{background:user?.lastColour||'transparent'}" data-tooltip="Colour of the last placed pixel."></span> <span x-text="user?.pixelCount||0" data-tooltip="How many pixels have been placed."></span></td><td><span x-text="user?.focusX||0"></span>, <span x-text="user?.focusY||0"></span></td><td><a href="javascript:void(0)" :data-tooltip="['Activate this account.','Deactivate this account.'][+(user?.active||0)]" x-text="user?.active?'Disable':'Enable'">Toggle</a> <a href="javascript:void(0)" data-tooltip="Remove this account.">Remove</a></td></tr></template></tbody></table></div><div x-show="tab==1"><div><big><b>IP info</b></big> <a href="javascript:void(0)" @mouseup="showIp=!showIp" x-text="['Show','Hide'][+showIp]" :data-tooltip="['Click to reveal IP information.','Click to hide IP information.'][+showIp]"></a></div><table class="text-center"><thead><tr><th data-tooltip="Type of the current proxy.">Proxy</th><th data-tooltip="Your current IP address.">IP</th><th data-tooltip="The country your IP is in.">Country</th><th data-tooltip="The AS number of your IP.">ASN</th><th data-tooltip="Name of AS of your IP.">AS Name</th></tr></thead><tbody><tr><td x-text="$store.info?.proxy||'N/A'" :data-tooltip="{'No Proxy':'No proxy is connected.','System':'Proxy set in env var.','Standalone':'Auto-managed proxy.','Tor':'Over Tor.'}[$store.info?.proxy]||'Not known.'"></td><td x-text="showIp?($store.info?.ip||'0.0.0.0'):'Hidden'">IP</td><td x-text="showIp?($store.info?.cc||'XX'):'Hidden'">Country</td><td x-text="showIp?($store.info?.asn||0):'Hidden'">ASN</td><td x-text="showIp?($store.info?.as||'Unknown AS'):'Hidden'">AS Name</td></tr></tbody></table><div><big><b>Managed Stats</b></big></div><table class="text-center"><tbody><tr><th data-tooltip="Information about the canvas.">Canvas</th><td><span data-tooltip="Dimensions of the whole canvas."><span x-text="$store.info?.ctw||0"></span>x<span x-text="$store.info?.cth||0"></span></span>, <span data-tooltip="Dimensions of the seperate canvases."><span x-text="$store.info?.cuw||0"></span>x<span x-text="$store.info?.cuh||0"></span></span> (<span x-text="$store.info?.cus||0" data-tooltip="How many canvases are there."></span>)</td></tr><tr><th data-tooltip="How much have we finished.">Finished</th><td><span x-text="$store.info?.pxOk||0" data-tooltip="Correct pixels."></span>/<span x-text="$store.info?.pxAll||0" data-tooltip="Total pixels."></span> (<span x-text="$store.info?.pxRate||0" data-tooltip="Finished ratio."></span>)</td></tr><tr><th data-tooltip="How sensitive to damage the accounts are.">Sensitivity</th><td x-text="$store.info?.sensitivity||0"></td></tr><tr><th data-tooltip="Possibility of pixel placement.">Power</th><td x-text="$store.info?.power||0"></td></tr><tr><th data-tooltip="How many accounts are managed.">Accounts</th><td x-text="$store.info?.acct||0">0</td></tr><tr><th data-tooltip="How many active accounts.">Active</th><td x-text="$store.info?.active||0"></td></tr><tr><th data-tooltip="Max allowed active acounts.">Magazine</th><td x-text="$store.info?.maxOn||0"></td></tr><tr><th data-tooltip="How many accounts were banned.">Banned</th><td x-text="$store.info?.banned||0">0</td></tr><tr><th data-tooltip="How many accounts are still fresh.">Fresh</th><td x-text="$store.info?.fresh||0">0</td></tr><tr><th data-tooltip="How many pixels have been placed.">Placed Pixels</th><td x-text="$store.info?.pixels||0">0</td></tr><tr><th data-tooltip="How long has this instance been running.">Uptime</th><td x-text="$store.sessionUptime">0d 00:00:00</td></tr></tbody></table></div><div x-show="tab==2"><h4>About</h4><table><tbody><tr><th colspan="2" class="text-center" x-text="$store.buildInfo?.name||'Unknown'"></th></tr><tr><th>Version</th><td x-text="$store.buildInfo?.ver||'Unknown'"></td></tr><tr><th>Runtime</th><td x-text="$store.info?.var||'Loading...'"></td></tr><tr><th>OS</th><td x-text="$store.info?.os||'Loading...'"></td></tr><tr><th>Developed by</th><td>Lumière Élevé</td></tr><tr><th>Tested by</th><td>Lumière Élevé<br/>Fauli1221<br/>Starshine</td></tr><tr><th>Produced by</th><td><a href="https://ltgc.cc/" target="_blank">Lightingale Community</a></td></tr></tbody></table></div></div></div></body></html>
14 changes: 9 additions & 5 deletions src/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ document.addEventListener("alpine:init", () => {
sensitivity: humanizedPercentage(data.bot.sen),
maxOn: data.bot.mag,
pixels: data.bot.px,
ctw: data.ct.w,
cth: data.ct.h,
cuw: data.cu.w,
cuh: data.cu.h,
cus: data.cu.s
power: humanizedPercentage(data.bot.pow),
ctw: data.ct?.w,
cth: data.ct?.h,
cuw: data.cu?.w,
cuh: data.cu?.h,
cus: data.cu?.s,
pxOk: data.art.ok,
pxAll: data.art.px,
pxRate: humanizedPercentage(data.art.ok / data.art.px)
});
}, 5000);
subSecondTask = setInterval(async () => {
Expand Down

0 comments on commit d022af7

Please sign in to comment.