fix bug of void failing or being too fast
fix eslint errors
This commit is contained in:
parent
d444b3498b
commit
2f2b114ec9
|
@ -362,14 +362,14 @@ export function receiveCoolDown(
|
||||||
* draw pixel on canvas
|
* draw pixel on canvas
|
||||||
* @param i, j, offset Chunk and offset in chunk
|
* @param i, j, offset Chunk and offset in chunk
|
||||||
* @param color integer Color Index
|
* @param color integer Color Index
|
||||||
* @param notify Bool if pixel notification appears (false when my own pixel)
|
* @param notifyPxl Bool if pixel notification appears (false when my own pixel)
|
||||||
*/
|
*/
|
||||||
export function updatePixel(
|
export function updatePixel(
|
||||||
i,
|
i,
|
||||||
j,
|
j,
|
||||||
offset,
|
offset,
|
||||||
color,
|
color,
|
||||||
notify = true,
|
notifyPxl = true,
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'UPDATE_PIXEL',
|
type: 'UPDATE_PIXEL',
|
||||||
|
@ -377,7 +377,7 @@ export function updatePixel(
|
||||||
j,
|
j,
|
||||||
offset,
|
offset,
|
||||||
color,
|
color,
|
||||||
notify,
|
notify: notifyPxl,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,10 @@ const CanvasItem = ({
|
||||||
{t`Stacking till`}:
|
{t`Stacking till`}:
|
||||||
<span className="modalinfo"> {canvas.cds / 1000}s</span><br />
|
<span className="modalinfo"> {canvas.cds / 1000}s</span><br />
|
||||||
{t`Ranked`}:
|
{t`Ranked`}:
|
||||||
<span className="modalinfo">{(canvas.ranked) ? t`Yes` : t`No`}</span><br />
|
<span className="modalinfo">{
|
||||||
|
(canvas.ranked) ? t`Yes` : t`No`
|
||||||
|
}
|
||||||
|
</span><br />
|
||||||
{(canvas.req !== -1) ? <span>{t`Requirements`}:<br /></span> : null}
|
{(canvas.req !== -1) ? <span>{t`Requirements`}:<br /></span> : null}
|
||||||
<span className="modalinfo">
|
<span className="modalinfo">
|
||||||
{(canvas.req !== -1) ? <span>{t`User Account`} </span> : null}
|
{(canvas.req !== -1) ? <span>{t`User Account`} </span> : null}
|
||||||
|
|
|
@ -28,8 +28,6 @@ const OnlineBox = () => {
|
||||||
], shallowEqual);
|
], shallowEqual);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const onlineUsers = (onlineCanvas) ? online[canvasId] : online.total;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="onlinebox"
|
className="onlinebox"
|
||||||
|
@ -51,15 +49,14 @@ const OnlineBox = () => {
|
||||||
>
|
>
|
||||||
{online.total}<FaUser />
|
{online.total}<FaUser />
|
||||||
</span>
|
</span>
|
||||||
)
|
)}
|
||||||
}
|
|
||||||
|
|
||||||
{(name != null)
|
{(name != null)
|
||||||
&& (
|
&& (
|
||||||
<span title={t`Pixels placed`}>
|
<span title={t`Pixels placed`}>
|
||||||
{numberToString(totalPixels)} <FaPaintBrush />
|
{numberToString(totalPixels)} <FaPaintBrush />
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
* users fight it with background pixels
|
* users fight it with background pixels
|
||||||
* if it reaches the TARGET_RADIUS size, the event is lost
|
* if it reaches the TARGET_RADIUS size, the event is lost
|
||||||
*
|
*
|
||||||
* @flow
|
|
||||||
*/
|
*/
|
||||||
import socketEvents from '../socket/SocketEvents';
|
import socketEvents from '../socket/SocketEvents';
|
||||||
import PixelUpdate from '../socket/packets/PixelUpdateServer';
|
import PixelUpdate from '../socket/packets/PixelUpdateServer';
|
||||||
|
@ -19,17 +18,24 @@ const EVENT_DURATION_MIN = 10;
|
||||||
// const EVENT_DURATION_MIN = 1;
|
// const EVENT_DURATION_MIN = 1;
|
||||||
|
|
||||||
class Void {
|
class Void {
|
||||||
i: number;
|
// chunk coords
|
||||||
j: number;
|
i;
|
||||||
maxClr: number;
|
j;
|
||||||
msTimeout: number;
|
// number highest possible colorIndex
|
||||||
pixelStack: Array;
|
maxClr;
|
||||||
area: Object;
|
// timeout between pixels in ms
|
||||||
userArea: Object;
|
msTimeout;
|
||||||
curRadius: number;
|
// array of pixels that we place before continue building (instant-defense)
|
||||||
curAngle: number;
|
pixelStack;
|
||||||
curAngleDelta: number;
|
// Uint8Array to log pixels in area
|
||||||
ended: boolean;
|
area;
|
||||||
|
userArea;
|
||||||
|
// current numberical data
|
||||||
|
curRadius;
|
||||||
|
curAngle;
|
||||||
|
curAngleDelta;
|
||||||
|
// boolean if ended
|
||||||
|
ended;
|
||||||
|
|
||||||
constructor(centerCell) {
|
constructor(centerCell) {
|
||||||
// chunk coordinates
|
// chunk coordinates
|
||||||
|
@ -39,16 +45,13 @@ class Void {
|
||||||
this.ended = false;
|
this.ended = false;
|
||||||
this.maxClr = canvases[CANVAS_ID].colors.length;
|
this.maxClr = canvases[CANVAS_ID].colors.length;
|
||||||
const area = TARGET_RADIUS ** 2 * Math.PI;
|
const area = TARGET_RADIUS ** 2 * Math.PI;
|
||||||
const online = socketEvents.onlineCounter;
|
const online = socketEvents.onlineCounter.total || 0;
|
||||||
// require an average of 0.25 px / min / user
|
// require an average of 0.25 px / min / user
|
||||||
const requiredSpeed = Math.floor(online / 1.8);
|
const requiredSpeed = Math.floor(online / 1.8);
|
||||||
const ppm = Math.ceil(area / EVENT_DURATION_MIN + requiredSpeed);
|
const ppm = Math.ceil(area / EVENT_DURATION_MIN + requiredSpeed);
|
||||||
// timeout between pixels
|
|
||||||
this.msTimeout = 60 * 1000 / ppm;
|
this.msTimeout = 60 * 1000 / ppm;
|
||||||
// area where we log placed pixels
|
|
||||||
this.area = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3);
|
this.area = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3);
|
||||||
this.userArea = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3);
|
this.userArea = new Uint8Array(TILE_SIZE * 3 * TILE_SIZE * 3);
|
||||||
// array of pixels that we place before continue building (instant-defense)
|
|
||||||
this.pixelStack = [];
|
this.pixelStack = [];
|
||||||
this.curRadius = 0;
|
this.curRadius = 0;
|
||||||
this.curAngle = 0;
|
this.curAngle = 0;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
/* @flow
|
/*
|
||||||
*
|
|
||||||
* Events for WebSockets
|
* Events for WebSockets
|
||||||
*/
|
*/
|
||||||
import EventEmitter from 'events';
|
import EventEmitter from 'events';
|
||||||
|
@ -13,31 +12,34 @@ class SocketEvents extends EventEmitter {
|
||||||
super();
|
super();
|
||||||
/*
|
/*
|
||||||
* {
|
* {
|
||||||
|
* total: totalUsersOnline,
|
||||||
* canvasId: onlineUsers,
|
* canvasId: onlineUsers,
|
||||||
* ...
|
* ...
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
this.onlineCounter = {};
|
this.onlineCounter = {
|
||||||
|
total: 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* broadcast message via websocket
|
* broadcast message via websocket
|
||||||
* @param message Message to send
|
* @param message Buffer Message to send
|
||||||
*/
|
*/
|
||||||
broadcast(message: Buffer) {
|
broadcast(message) {
|
||||||
this.emit('broadcast', message);
|
this.emit('broadcast', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* broadcast pixel message via websocket
|
* broadcast pixel message via websocket
|
||||||
* @param canvasId ident of canvas
|
* @param canvasId number ident of canvas
|
||||||
* @param chunkid id consisting of i,j chunk coordinates
|
* @param chunkid number id consisting of i,j chunk coordinates
|
||||||
* @param pxls buffer with offset and color of one or more pixels
|
* @param pxls buffer with offset and color of one or more pixels
|
||||||
*/
|
*/
|
||||||
broadcastPixels(
|
broadcastPixels(
|
||||||
canvasId: number,
|
canvasId,
|
||||||
chunkId: number,
|
chunkId,
|
||||||
pixels: Buffer,
|
pixels,
|
||||||
) {
|
) {
|
||||||
const buffer = PixelUpdate.dehydrate(chunkId, pixels);
|
const buffer = PixelUpdate.dehydrate(chunkId, pixels);
|
||||||
this.emit('pixelUpdate', canvasId, chunkId, buffer);
|
this.emit('pixelUpdate', canvasId, chunkId, buffer);
|
||||||
|
@ -50,9 +52,9 @@ class SocketEvents extends EventEmitter {
|
||||||
* @param channelId numerical channel id
|
* @param channelId numerical channel id
|
||||||
*/
|
*/
|
||||||
recvChatMessage(
|
recvChatMessage(
|
||||||
user: Object,
|
user,
|
||||||
message: string,
|
message,
|
||||||
channelId: number,
|
channelId,
|
||||||
) {
|
) {
|
||||||
this.emit('recvChatMessage', user, message, channelId);
|
this.emit('recvChatMessage', user, message, channelId);
|
||||||
}
|
}
|
||||||
|
@ -65,12 +67,12 @@ class SocketEvents extends EventEmitter {
|
||||||
* (usefull if the api is supposed to not answer to its own messages)
|
* (usefull if the api is supposed to not answer to its own messages)
|
||||||
*/
|
*/
|
||||||
broadcastChatMessage(
|
broadcastChatMessage(
|
||||||
name: string,
|
name,
|
||||||
message: string,
|
message,
|
||||||
channelId: number,
|
channelId,
|
||||||
id: number,
|
id,
|
||||||
country: string = 'xx',
|
country = 'xx',
|
||||||
sendapi: boolean = true,
|
sendapi = true,
|
||||||
) {
|
) {
|
||||||
this.emit(
|
this.emit(
|
||||||
'chatMessage',
|
'chatMessage',
|
||||||
|
@ -87,12 +89,12 @@ class SocketEvents extends EventEmitter {
|
||||||
* send chat message to a single user in channel
|
* send chat message to a single user in channel
|
||||||
*/
|
*/
|
||||||
broadcastSUChatMessage(
|
broadcastSUChatMessage(
|
||||||
targetUserId: number,
|
targetUserId,
|
||||||
name: string,
|
name,
|
||||||
message: string,
|
message,
|
||||||
channelId: number,
|
channelId,
|
||||||
id: number,
|
id,
|
||||||
country: string = 'xx',
|
country = 'xx',
|
||||||
) {
|
) {
|
||||||
this.emit(
|
this.emit(
|
||||||
'suChatMessage',
|
'suChatMessage',
|
||||||
|
@ -112,9 +114,9 @@ class SocketEvents extends EventEmitter {
|
||||||
* @param channelArray array with channel info [name, type, lastTs]
|
* @param channelArray array with channel info [name, type, lastTs]
|
||||||
*/
|
*/
|
||||||
broadcastAddChatChannel(
|
broadcastAddChatChannel(
|
||||||
userId: number,
|
userId,
|
||||||
channelId: number,
|
channelId,
|
||||||
channelArray: Array,
|
channelArray,
|
||||||
) {
|
) {
|
||||||
this.emit(
|
this.emit(
|
||||||
'addChatChannel',
|
'addChatChannel',
|
||||||
|
@ -131,8 +133,8 @@ class SocketEvents extends EventEmitter {
|
||||||
* (i.e. false if the user already gets it via api response)
|
* (i.e. false if the user already gets it via api response)
|
||||||
*/
|
*/
|
||||||
broadcastRemoveChatChannel(
|
broadcastRemoveChatChannel(
|
||||||
userId: number,
|
userId,
|
||||||
channelId: number,
|
channelId,
|
||||||
) {
|
) {
|
||||||
this.emit('remChatChannel', userId, channelId);
|
this.emit('remChatChannel', userId, channelId);
|
||||||
}
|
}
|
||||||
|
@ -140,15 +142,16 @@ class SocketEvents extends EventEmitter {
|
||||||
/*
|
/*
|
||||||
* reload user on websocket to get changes
|
* reload user on websocket to get changes
|
||||||
*/
|
*/
|
||||||
reloadUser(name: string) {
|
reloadUser(name) {
|
||||||
this.emit('reloadUser', name);
|
this.emit('reloadUser', name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* broadcast online counter
|
* broadcast online counter
|
||||||
* @param online Number of users online
|
* @param online Object of total and canvas online users
|
||||||
|
* (see this.onlineCounter)
|
||||||
*/
|
*/
|
||||||
broadcastOnlineCounter(online: number) {
|
broadcastOnlineCounter(online) {
|
||||||
this.onlineCounter = online;
|
this.onlineCounter = online;
|
||||||
const buffer = OnlineCounter.dehydrate(online);
|
const buffer = OnlineCounter.dehydrate(online);
|
||||||
this.emit('broadcast', buffer);
|
this.emit('broadcast', buffer);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
|
|
||||||
import logger from '../core/logger';
|
import logger from '../core/logger';
|
||||||
|
// eslint-disable-next-line import/no-unresolved
|
||||||
import canvases from './canvases.json';
|
import canvases from './canvases.json';
|
||||||
import Counter from '../utils/Counter';
|
import Counter from '../utils/Counter';
|
||||||
import { getIPFromRequest } from '../utils/ip';
|
import { getIPFromRequest } from '../utils/ip';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user