make moderators be able to place unset pixels without cooldown

This commit is contained in:
HF 2022-07-11 01:46:07 +02:00
parent 3540f19978
commit b5f9e59549
3 changed files with 34 additions and 16 deletions

View File

@ -118,7 +118,7 @@ const Palette = () => {
if (!paletteOpen) setRender(false);
};
const clrHide = (userlvl === 1) ? 0 : clrIgnore;
const clrHide = (userlvl === 0) ? clrIgnore : 0;
const [paletteStyle, spanStyle] = getStylesByWindowSize(
(render && paletteOpen),

View File

@ -109,6 +109,12 @@ export async function drawByOffsets(
throw new Error(3);
}
/*
* userlvl:
* 0: nothing
* 1: admin
* 2: mod
*/
const isAdmin = (user.userlvl === 1);
if (canvas.req !== undefined && !isAdmin) {
@ -155,8 +161,13 @@ export async function drawByOffsets(
// z out of bounds or weird stuff
throw new Error(4);
}
/*
* admins and mods can place unset pixels
*/
if (color >= canvas.colors.length
|| (color < clrIgnore && !isAdmin && !(canvas.v && color === 0))
|| (color < clrIgnore
&& user.userlvl === 0
&& !(canvas.v && color === 0))
) {
// color out of bounds
throw new Error(5);
@ -175,11 +186,17 @@ export async function drawByOffsets(
coolDown = ((setColor & 0x3F) >= clrIgnore && canvas.pcd)
? canvas.pcd : canvas.bcd;
if (isAdmin) {
/*
* admins have no cooldown
* mods have no cooldown when placing unset pixels
*/
if (isAdmin || (user.userlvl > 0 && color < clrIgnore)) {
coolDown = 0.0;
} else {
/*
* cooldown changes like from event
*/
coolDown *= coolDownFactor;
// temporary lowered cooldown
}
wait += coolDown;
@ -193,9 +210,12 @@ export async function drawByOffsets(
setPixelByOffset(canvasId, color, i, j, offset);
pxlCnt += 1;
/* hardcode to not count pixels in antarctica */
/*
* hardcode to not count pixels in antarctica
* do not count 0cd pixels
*/
// eslint-disable-next-line eqeqeq
if (canvas.ranked && (canvasId != 0 || y < 14450)) {
if (canvas.ranked && (canvasId != 0 || y < 14450) && coolDown) {
rankedPxlCnt += 1;
}
@ -214,15 +234,15 @@ export async function drawByOffsets(
}
}
if (retCode !== 13) {
curReqIPs.delete(ip);
if (pxlCnt && wait) {
await user.setWait(wait, canvasId);
if (rankedPxlCnt) {
await user.incrementPixelcount(rankedPxlCnt);
}
}
if (pxlCnt) {
user.setWait(wait, canvasId);
if (rankedPxlCnt) {
user.incrementPixelcount(rankedPxlCnt);
}
if (retCode !== 13) {
curReqIPs.delete(ip);
}
return {

View File

@ -172,8 +172,7 @@ class User {
return (this.regUser) ? this.regUser.name : null;
}
async setWait(wait: number, canvasId: number): Promise<boolean> {
if (!wait) return false;
async setWait(wait, canvasId) {
// PX is milliseconds expire
await redis.set(`cd:${canvasId}:ip:${this.ipSub}`, '', {
PX: wait,
@ -203,7 +202,6 @@ class User {
async incrementPixelcount(amount: number = 1): Promise<boolean> {
const { id } = this;
if (!id) return false;
if (this.userlvl === 1) return false;
try {
await this.regUser.increment(
['totalPixels', 'dailyTotalPixels'],