make moderators be able to place unset pixels without cooldown
This commit is contained in:
parent
3540f19978
commit
b5f9e59549
|
@ -118,7 +118,7 @@ const Palette = () => {
|
||||||
if (!paletteOpen) setRender(false);
|
if (!paletteOpen) setRender(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const clrHide = (userlvl === 1) ? 0 : clrIgnore;
|
const clrHide = (userlvl === 0) ? clrIgnore : 0;
|
||||||
|
|
||||||
const [paletteStyle, spanStyle] = getStylesByWindowSize(
|
const [paletteStyle, spanStyle] = getStylesByWindowSize(
|
||||||
(render && paletteOpen),
|
(render && paletteOpen),
|
||||||
|
|
|
@ -109,6 +109,12 @@ export async function drawByOffsets(
|
||||||
throw new Error(3);
|
throw new Error(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* userlvl:
|
||||||
|
* 0: nothing
|
||||||
|
* 1: admin
|
||||||
|
* 2: mod
|
||||||
|
*/
|
||||||
const isAdmin = (user.userlvl === 1);
|
const isAdmin = (user.userlvl === 1);
|
||||||
|
|
||||||
if (canvas.req !== undefined && !isAdmin) {
|
if (canvas.req !== undefined && !isAdmin) {
|
||||||
|
@ -155,8 +161,13 @@ export async function drawByOffsets(
|
||||||
// z out of bounds or weird stuff
|
// z out of bounds or weird stuff
|
||||||
throw new Error(4);
|
throw new Error(4);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* admins and mods can place unset pixels
|
||||||
|
*/
|
||||||
if (color >= canvas.colors.length
|
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
|
// color out of bounds
|
||||||
throw new Error(5);
|
throw new Error(5);
|
||||||
|
@ -175,11 +186,17 @@ export async function drawByOffsets(
|
||||||
|
|
||||||
coolDown = ((setColor & 0x3F) >= clrIgnore && canvas.pcd)
|
coolDown = ((setColor & 0x3F) >= clrIgnore && canvas.pcd)
|
||||||
? canvas.pcd : canvas.bcd;
|
? 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;
|
coolDown = 0.0;
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
|
* cooldown changes like from event
|
||||||
|
*/
|
||||||
coolDown *= coolDownFactor;
|
coolDown *= coolDownFactor;
|
||||||
// temporary lowered cooldown
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wait += coolDown;
|
wait += coolDown;
|
||||||
|
@ -193,9 +210,12 @@ export async function drawByOffsets(
|
||||||
setPixelByOffset(canvasId, color, i, j, offset);
|
setPixelByOffset(canvasId, color, i, j, offset);
|
||||||
|
|
||||||
pxlCnt += 1;
|
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
|
// eslint-disable-next-line eqeqeq
|
||||||
if (canvas.ranked && (canvasId != 0 || y < 14450)) {
|
if (canvas.ranked && (canvasId != 0 || y < 14450) && coolDown) {
|
||||||
rankedPxlCnt += 1;
|
rankedPxlCnt += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,15 +234,15 @@ export async function drawByOffsets(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retCode !== 13) {
|
if (pxlCnt && wait) {
|
||||||
curReqIPs.delete(ip);
|
await user.setWait(wait, canvasId);
|
||||||
|
if (rankedPxlCnt) {
|
||||||
|
await user.incrementPixelcount(rankedPxlCnt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pxlCnt) {
|
if (retCode !== 13) {
|
||||||
user.setWait(wait, canvasId);
|
curReqIPs.delete(ip);
|
||||||
if (rankedPxlCnt) {
|
|
||||||
user.incrementPixelcount(rankedPxlCnt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -172,8 +172,7 @@ class User {
|
||||||
return (this.regUser) ? this.regUser.name : null;
|
return (this.regUser) ? this.regUser.name : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setWait(wait: number, canvasId: number): Promise<boolean> {
|
async setWait(wait, canvasId) {
|
||||||
if (!wait) return false;
|
|
||||||
// PX is milliseconds expire
|
// PX is milliseconds expire
|
||||||
await redis.set(`cd:${canvasId}:ip:${this.ipSub}`, '', {
|
await redis.set(`cd:${canvasId}:ip:${this.ipSub}`, '', {
|
||||||
PX: wait,
|
PX: wait,
|
||||||
|
@ -203,7 +202,6 @@ class User {
|
||||||
async incrementPixelcount(amount: number = 1): Promise<boolean> {
|
async incrementPixelcount(amount: number = 1): Promise<boolean> {
|
||||||
const { id } = this;
|
const { id } = this;
|
||||||
if (!id) return false;
|
if (!id) return false;
|
||||||
if (this.userlvl === 1) return false;
|
|
||||||
try {
|
try {
|
||||||
await this.regUser.increment(
|
await this.regUser.increment(
|
||||||
['totalPixels', 'dailyTotalPixels'],
|
['totalPixels', 'dailyTotalPixels'],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user