diff --git a/src/components/Palette.jsx b/src/components/Palette.jsx index e225968..1985200 100644 --- a/src/components/Palette.jsx +++ b/src/components/Palette.jsx @@ -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), diff --git a/src/core/draw.js b/src/core/draw.js index b4b341e..5049a53 100644 --- a/src/core/draw.js +++ b/src/core/draw.js @@ -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 { diff --git a/src/data/User.js b/src/data/User.js index feb6928..c2504fc 100644 --- a/src/data/User.js +++ b/src/data/User.js @@ -172,8 +172,7 @@ class User { return (this.regUser) ? this.regUser.name : null; } - async setWait(wait: number, canvasId: number): Promise { - 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 { const { id } = this; if (!id) return false; - if (this.userlvl === 1) return false; try { await this.regUser.increment( ['totalPixels', 'dailyTotalPixels'],