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