remove flow types - it was inconsistently used and therefore pointless

This commit is contained in:
HF 2022-08-01 17:44:18 +02:00
parent 79b4f55a04
commit d4ef69c2ac
108 changed files with 1208 additions and 1439 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ output.webm
utils/ocean-tiles/ocean utils/ocean-tiles/ocean
utils/osm-tiles/osm utils/osm-tiles/osm
i18n/*.mo i18n/*.mo
test.js
logs logs
*.log *.log

View File

@ -2,8 +2,6 @@ const pkg = require('./package.json');
module.exports = function (api) { module.exports = function (api) {
const plugins = [ const plugins = [
'@babel/plugin-transform-flow-strip-types',
'@babel/plugin-proposal-throw-expressions',
// react-optimize // react-optimize
'@babel/transform-react-constant-elements', '@babel/transform-react-constant-elements',
'@babel/transform-react-inline-elements', '@babel/transform-react-inline-elements',

1938
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,8 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=10.16.0", "node": ">=14"
"npm": ">=6.13.4"
}, },
"description": "Unlimited planet canvas for placing pixels", "description": "Unlimited planet canvas for placing pixels",
"main": "server.js", "main": "server.js",
@ -66,6 +65,7 @@
"three-trackballcontrols": "^0.9.0", "three-trackballcontrols": "^0.9.0",
"ttag": "^1.7.24", "ttag": "^1.7.24",
"url-search-params-polyfill": "^8.1.1", "url-search-params-polyfill": "^8.1.1",
"whoiser": "^1.13.1",
"winston": "^3.8.1", "winston": "^3.8.1",
"winston-daily-rotate-file": "^4.5.5", "winston-daily-rotate-file": "^4.5.5",
"ws": "^8.4.0" "ws": "^8.4.0"
@ -75,8 +75,6 @@
"@babel/core": "^7.18.6", "@babel/core": "^7.18.6",
"@babel/eslint-parser": "^7.16.5", "@babel/eslint-parser": "^7.16.5",
"@babel/node": "^7.18.6", "@babel/node": "^7.18.6",
"@babel/plugin-proposal-throw-expressions": "^7.18.6",
"@babel/plugin-transform-flow-strip-types": "^7.18.6",
"@babel/plugin-transform-react-constant-elements": "^7.18.6", "@babel/plugin-transform-react-constant-elements": "^7.18.6",
"@babel/plugin-transform-react-inline-elements": "^7.18.6", "@babel/plugin-transform-react-inline-elements": "^7.18.6",
"@babel/preset-env": "^7.18.6", "@babel/preset-env": "^7.18.6",

View File

@ -6,7 +6,6 @@
* also: * also:
* echo never > /sys/kernel/mm/transparent_hugepage/enabled * echo never > /sys/kernel/mm/transparent_hugepage/enabled
* *
* @flow
*/ */
/* eslint-disable no-console */ /* eslint-disable no-console */
@ -86,7 +85,7 @@ backupRedis.on('error', () => {
}); });
function runCmd(cmd: string) { function runCmd(cmd) {
const startTime = Date.now(); const startTime = Date.now();
console.log(`Executing ${cmd}`); console.log(`Executing ${cmd}`);
const cmdproc = spawn(cmd); const cmdproc = spawn(cmd);

View File

@ -1,6 +1,5 @@
/* /*
* *
* @flow
*/ */
import React, { useState, useEffect, useCallback } from 'react'; import React, { useState, useEffect, useCallback } from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Change Mail Form * Change Mail Form
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Change Name Form * Change Name Form
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Change Password Form * Change Password Form
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';

View File

@ -1,7 +1,3 @@
/*
*
* @flow
*/
import React from 'react'; import React from 'react';
import { useSelector, useDispatch } from 'react-redux'; import { useSelector, useDispatch } from 'react-redux';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';
@ -11,7 +10,7 @@ import copy from '../utils/clipboard';
import { notify } from '../store/actions'; import { notify } from '../store/actions';
function renderCoordinates(cell): string { function renderCoordinates(cell) {
return `(${cell.join(', ')})`; return `(${cell.join(', ')})`;
} }

View File

@ -1,6 +1,5 @@
/* /*
* Rankings Tabs * Rankings Tabs
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Change Password Form * Change Password Form
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* LogIn Form * LogIn Form
* @flow
*/ */
import React, { import React, {
useState, useCallback, useRef, useState, useCallback, useRef,

View File

@ -5,7 +5,6 @@
* Available languages under window.langSel * Available languages under window.langSel
* [['hz', 'am'], ['de', 'de'], ...] * [['hz', 'am'], ['de', 'de'], ...]
* [languageCode, countryCode (for flag)] * [languageCode, countryCode (for flag)]
* @flow
*/ */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { t } from 'ttag'; import { t } from 'ttag';

View File

@ -1,5 +1,4 @@
/* /*
* @flow
*/ */
import React from 'react'; import React from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';

View File

@ -1,6 +1,5 @@
/* /*
* LogIn Form * LogIn Form
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';

View File

@ -1,7 +1,6 @@
/* /*
* Menu with Buttons on the top left * Menu with Buttons on the top left
* *
* @flow
*/ */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* *
* @flow
* Menu for WASD keys for mobile users * Menu for WASD keys for mobile users
*/ */

View File

@ -2,7 +2,6 @@
* *
* https://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions/35641680#35641680 * https://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions/35641680#35641680
* *
* @flow
*/ */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Modtools * Modtools
* @flow
*/ */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';

View File

@ -1,8 +1,3 @@
/**
*
* @flow
*/
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Rankings Tabs * Rankings Tabs
* @flow
*/ */
/* eslint-disable max-len */ /* eslint-disable max-len */

View File

@ -1,6 +1,5 @@
/* /*
* Change Mail Form * Change Mail Form
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Rankings Tabs * Rankings Tabs
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Menu to change user credentials * Menu to change user credentials
* @flow
*/ */
import React, { useState, useCallback } from 'react'; import React, { useState, useCallback } from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* Messages on top of UserArea * Messages on top of UserArea
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';

View File

@ -1,6 +1,5 @@
/* /*
* draw window * draw window
* @flow
*/ */
import React, { import React, {

View File

@ -1,6 +1,5 @@
/* /*
* draw windows * draw windows
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React, { import React, {
@ -104,7 +103,7 @@ const ChatButton = () => {
>⦿</div> >⦿</div>
)} )}
<MdForum /> <MdForum />
</div>: null </div>
); );
}; };

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,7 +1,6 @@
/* /*
* espand menu / show other menu buttons * espand menu / show other menu buttons
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,7 +1,6 @@
/** /**
* *
* Button to open/close palette * Button to open/close palette
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/* /*
* *
* @flow
*/ */
import React, { useRef, useCallback } from 'react'; import React, { useRef, useCallback } from 'react';

View File

@ -1,7 +1,6 @@
/* /*
* Drop Down menu for Chat Channel selection * Drop Down menu for Chat Channel selection
* *
* @flow
*/ */
import React, { import React, {

View File

@ -1,6 +1,5 @@
/* /*
* *
* @flow
*/ */
import React, { useRef } from 'react'; import React, { useRef } from 'react';

View File

@ -1,7 +1,3 @@
/*
* @flow
*/
/* eslint-disable max-len */ /* eslint-disable max-len */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React, { useCallback } from 'react'; import React, { useCallback } from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React, { import React, {

View File

@ -1,6 +1,5 @@
/* /*
* Form for requesting password-reset mail * Form for requesting password-reset mail
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';

View File

@ -1,6 +1,5 @@
/* /*
* SignUp Form to register new user by mail * SignUp Form to register new user by mail
* @flow
*/ */
import React, { useState } from 'react'; import React, { useState } from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React from 'react'; import React from 'react';

View File

@ -1,6 +1,5 @@
/** /**
* *
* @flow
*/ */
import React, { Suspense } from 'react'; import React, { Suspense } from 'react';

View File

@ -4,7 +4,6 @@
* keycodes: * keycodes:
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
* *
* @flow
*/ */
import { import {
@ -31,7 +30,7 @@ import {
} from '../core/utils'; } from '../core/utils';
class PixelPlainterControls { class PixelPlainterControls {
constructor(renderer, viewport: HTMLCanvasElement, curStore) { constructor(renderer, viewport, curStore) {
this.store = curStore; this.store = curStore;
this.renderer = renderer; this.renderer = renderer;
this.viewport = viewport; this.viewport = viewport;
@ -101,7 +100,7 @@ class PixelPlainterControls {
}, delta * 1000); }, delta * 1000);
} }
onMouseDown(event: MouseEvent) { onMouseDown(event) {
event.preventDefault(); event.preventDefault();
document.activeElement.blur(); document.activeElement.blur();
@ -129,7 +128,7 @@ class PixelPlainterControls {
}, 250); }, 250);
} }
onMouseUp(event: MouseEvent) { onMouseUp(event) {
event.preventDefault(); event.preventDefault();
const { store } = this; const { store } = this;
@ -161,7 +160,7 @@ class PixelPlainterControls {
store.dispatch(onViewFinishChange()); store.dispatch(onViewFinishChange());
} }
static getTouchCenter(event: TouchEvent) { static getTouchCenter(event) {
switch (event.touches.length) { switch (event.touches.length) {
case 1: { case 1: {
const { pageX, pageY } = event.touches[0]; const { pageX, pageY } = event.touches[0];
@ -251,7 +250,7 @@ class PixelPlainterControls {
); );
} }
static getMultiTouchDistance(event: TouchEvent) { static getMultiTouchDistance(event) {
if (event.touches.length < 2) { if (event.touches.length < 2) {
return 1; return 1;
} }
@ -262,7 +261,7 @@ class PixelPlainterControls {
); );
} }
onTouchStart(event: TouchEvent) { onTouchStart(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
document.activeElement.blur(); document.activeElement.blur();
@ -292,7 +291,7 @@ class PixelPlainterControls {
} }
} }
onTouchEnd(event: TouchEvent) { onTouchEnd(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -328,7 +327,7 @@ class PixelPlainterControls {
this.clearTabTimeout(); this.clearTabTimeout();
} }
onTouchMove(event: TouchEvent) { onTouchMove(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -384,7 +383,7 @@ class PixelPlainterControls {
} }
} }
onWheel(event: MouseEvent) { onWheel(event) {
event.preventDefault(); event.preventDefault();
document.activeElement.blur(); document.activeElement.blur();
@ -405,7 +404,7 @@ class PixelPlainterControls {
this.scheduleOnViewFinishChange(); this.scheduleOnViewFinishChange();
} }
onMouseMove(event: MouseEvent) { onMouseMove(event) {
event.preventDefault(); event.preventDefault();
const { clientX, clientY } = event; const { clientX, clientY } = event;
@ -503,7 +502,7 @@ class PixelPlainterControls {
} }
} }
onAuxClick(event: MouseEvent) { onAuxClick(event) {
const { which, clientX, clientY } = event; const { which, clientX, clientY } = event;
// middle mouse button // middle mouse button
if (which !== 2) { if (which !== 2) {
@ -519,7 +518,7 @@ class PixelPlainterControls {
); );
} }
onKeyUp(event: KeyboardEvent) { onKeyUp(event) {
switch (event.key) { switch (event.key) {
case 'Shift': case 'Shift':
case 'CapsLock': case 'CapsLock':
@ -529,7 +528,7 @@ class PixelPlainterControls {
} }
} }
onKeyDown(event: KeyboardEvent) { onKeyDown(event) {
// ignore key presses if modal is open or chat is used // ignore key presses if modal is open or chat is used
if (event.target.nodeName === 'INPUT' if (event.target.nodeName === 'INPUT'
|| event.target.nodeName === 'TEXTAREA' || event.target.nodeName === 'TEXTAREA'

View File

@ -2,7 +2,6 @@
* Buffer for chatMessages for the server * Buffer for chatMessages for the server
* it just buffers the msot recent 200 messages for each channel * it just buffers the msot recent 200 messages for each channel
* *
* @flow
*/ */
import Sequelize from 'sequelize'; import Sequelize from 'sequelize';
import logger from './logger'; import logger from './logger';

View File

@ -492,8 +492,8 @@ export class ChatProvider {
message, message,
channelId, channelId,
id, id,
country: string = 'xx', country = 'xx',
sendapi: boolean = true, sendapi = true,
) { ) {
if (message.length > 250) { if (message.length > 250) {
return; return;

View File

@ -1,74 +0,0 @@
/* @flow */
/**
* Created by http://code.stephenmorley.org/javascript/queues/
*/
class Queue<T> {
array: Array<T>;
offset: number;
constructor() {
this.array = [];
this.offset = 0;
}
/**
*
* @returns {number} the length of the queue.
*/
getLength(): number {
return this.array.length - this.offset;
}
/**
* Returns true if the queue is empty, and false otherwise.
* @returns {boolean}
*/
isEmpty(): boolean {
return this.array.length === 0;
}
/**
* Enqueues the specified item. The parameter is:
* @param item the item to enqueue
*/
enqueue(item: T) {
this.array.push(item);
}
/**
* Dequeues an item and returns it. If the queue is empty, the value
* 'undefined' is returned.
*/
dequeue(): ?T {
// if the queue is empty, return immediately
if (this.isEmpty()) return null;
// store the item at the front of the queue
const item = this.array[this.offset];
// increment the first and remove the free space if necessary
this.offset += 1;
if (this.offset * 2 >= this.array.length) {
this.array = this.array.slice(this.offset);
this.offset = 0;
}
// return the dequeued item
return item;
}
/**
* Returns the item at the front of the queue (without dequeuing it). If the
* queue is empty then undefined is returned.
* @returns {*}
*/
peek(): ?T {
if (this.isEmpty()) return null;
return this.array[this.offset];
}
}
export default Queue;

View File

@ -2,7 +2,6 @@
* This is an even that happens all 2h, * This is an even that happens all 2h,
* if the users complete, they will get rewarded by half the cooldown sitewide * if the users complete, they will get rewarded by half the cooldown sitewide
* *
* @flow
*/ */
import logger from './logger'; import logger from './logger';
@ -66,17 +65,17 @@ function drawCross(centerCell, clr, style, radius) {
class RpgEvent { class RpgEvent {
eventState: number; eventState; // number
eventTimestamp: number; eventTimestamp; // number
eventCenter: Array; eventCenter; // Array
eventCenterC: Array; eventCenterC; // Array
eventArea: Array; eventArea; // Array
// 0 if waiting // 0 if waiting
// 1 if won // 1 if won
// 2 if lost // 2 if lost
success: boolean; success; // boolean
void: Object; void; // Object
chatTimeout: number; chatTimeout; // number
constructor() { constructor() {
this.eventState = -1; this.eventState = -1;

View File

@ -1,4 +1,3 @@
/* @flow */
// general config that is also available from client code can be found in // general config that is also available from client code can be found in
// src/core/constants.js // src/core/constants.js
import path from 'path'; import path from 'path';

View File

@ -1,5 +1,4 @@
/** /**
* @flow
*/ */
// canvas size (width and height) MUST be 256 * 4^n to be able to stick // canvas size (width and height) MUST be 256 * 4^n to be able to stick

View File

@ -1,6 +1,5 @@
/* /*
* *
* @flow
*/ */
function appendNumberText(number) { function appendNumberText(number) {

View File

@ -1,7 +1,3 @@
/**
* @flow
* */
import fetch from '../utils/proxiedFetch'; import fetch from '../utils/proxiedFetch';
import redis from '../data/redis/client'; import redis from '../data/redis/client';
@ -18,7 +14,7 @@ import { USE_PROXYCHECK } from './config';
* @return true if proxy, false if not * @return true if proxy, false if not
*/ */
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
async function getIPIntel(ip: string): Promise<boolean> { async function getIPIntel(ip) {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
const email = `${Math.random().toString(36).substring(8)}-${Math.random().toString(36).substring(4)}@gmail.com`; const email = `${Math.random().toString(36).substring(8)}-${Math.random().toString(36).substring(4)}@gmail.com`;
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
@ -33,8 +29,6 @@ async function getIPIntel(ip: string): Promise<boolean> {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
}, },
}); });
// TODO log response code
logger.debug('PROXYCHECK getipintel? %s', ip);
if (!response.ok) { if (!response.ok) {
const text = await response.text(); const text = await response.text();
throw new Error(`PROXYCHECK getipintel not ok ${response.status}/${text}`); throw new Error(`PROXYCHECK getipintel not ok ${response.status}/${text}`);
@ -52,7 +46,7 @@ async function getIPIntel(ip: string): Promise<boolean> {
* @param ip IP to check * @param ip IP to check
* @return true if proxy, false if not * @return true if proxy, false if not
*/ */
async function getProxyCheck(ip: string): Promise<boolean> { async function getProxyCheck(ip) {
const url = `http://proxycheck.io/v2/${ip}?risk=1&vpn=1&asn=1`; const url = `http://proxycheck.io/v2/${ip}?risk=1&vpn=1&asn=1`;
logger.info('PROXYCHECK fetching proxycheck %s', url); logger.info('PROXYCHECK fetching proxycheck %s', url);
const response = await fetch(url, { const response = await fetch(url, {
@ -70,37 +64,12 @@ async function getProxyCheck(ip: string): Promise<boolean> {
return data.status === 'ok' && data[ip].proxy === 'yes'; return data.status === 'ok' && data[ip].proxy === 'yes';
} }
/*
* check shroomey if IP is proxy
* NOTE: shroomey can not check IPv6
* User random proxies for request, just to be sure
* @param ip IP to check
* @return true if proxy, false if not
*/
async function getShroomey(ip: string): Promise<boolean> {
logger.info('PROXYCHECK fetching shroomey %s', ip);
// eslint-disable-next-line max-len
const response = await fetch(`http://www.shroomery.org/ythan/proxycheck.php?ip=${ip}`, {
headers: {
Accept: '*/*',
'Accept-Language': 'es-ES,es;q=0.8,en;q=0.6',
Referer: 'http://www.shroomery.org/',
// eslint-disable-next-line max-len
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36',
},
});
if (!response.ok) throw new Error('shroomery.org not ok');
const body = await response.text();
logger.info('PROXYCHECK fetch shroomey is proxy? %s %s', ip, body);
return body === 'Y';
}
/* /*
* check MYSQL Blacklist table * check MYSQL Blacklist table
* @param ip IP to check * @param ip IP to check
* @return true if blacklisted * @return true if blacklisted
*/ */
async function isBlacklisted(ip: string): Promise<boolean> { async function isBlacklisted(ip) {
const count = await Blacklist const count = await Blacklist
.count({ .count({
where: { where: {
@ -115,7 +84,7 @@ async function isBlacklisted(ip: string): Promise<boolean> {
* @param ip IP to check * @param ip IP to check
* @return true if whitelisted * @return true if whitelisted
*/ */
async function isWhitelisted(ip: string): Promise<boolean> { async function isWhitelisted(ip) {
const count = await Whitelist const count = await Whitelist
.count({ .count({
where: { where: {
@ -128,7 +97,7 @@ async function isWhitelisted(ip: string): Promise<boolean> {
/* /*
* dummy function to include if you don't want any proxycheck * dummy function to include if you don't want any proxycheck
*/ */
async function dummy(): Promise<boolean> { async function dummy() {
return false; return false;
} }
@ -167,13 +136,8 @@ async function withCache(f, ip) {
const key = `isprox:${ipKey}`; const key = `isprox:${ipKey}`;
const cache = await redis.get(key); const cache = await redis.get(key);
if (cache) { if (cache) {
logger.debug('PROXYCHECK fetch isproxy from cache %s %s %s',
key,
cache,
typeof cache);
return cache === 'y'; return cache === 'y';
} }
logger.debug('PROXYCHECK fetch isproxy not from cache %s', key);
// else make asynchronous ipcheck and assume no proxy in the meantime // else make asynchronous ipcheck and assume no proxy in the meantime
// use lock to just check three at a time // use lock to just check three at a time
@ -201,17 +165,13 @@ async function withCache(f, ip) {
return false; return false;
} }
export function cheapDetector(ip: string): Promise<boolean> { export function cheapDetector(ip) {
if (USE_PROXYCHECK) { if (USE_PROXYCHECK) {
return withCache(getProxyCheck, ip); return withCache(getProxyCheck, ip);
} }
return withCache(dummy, ip); return withCache(dummy, ip);
} }
export function strongDetector(ip: string): Promise<boolean> { export function blacklistDetector(ip) {
return withCache(getShroomey, ip);
}
export function blacklistDetector(ip: string): Promise<boolean> {
return withCache(dummy, ip); return withCache(dummy, ip);
} }

View File

@ -2,7 +2,6 @@
* *
* http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ * http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
* *
* @flow
*/ */
import { createLogger, format, transports } from 'winston'; import { createLogger, format, transports } from 'winston';

View File

@ -3,7 +3,6 @@
* Userdata that gets sent to the client on * Userdata that gets sent to the client on
* various api endpoints. * various api endpoints.
* *
* @flow
*/ */
// eslint-disable-next-line import/no-unresolved // eslint-disable-next-line import/no-unresolved
import { getLocalicedCanvases } from '../canvasesDesc'; import { getLocalicedCanvases } from '../canvasesDesc';

View File

@ -1,7 +1,6 @@
/** /**
* https://scotch.io/tutorials/easy-node-authentication-linking-all-accounts-together#toc-linking-accounts-together * https://scotch.io/tutorials/easy-node-authentication-linking-all-accounts-together#toc-linking-accounts-together
* *
* @flow
*/ */
import passport from 'passport'; import passport from 'passport';

View File

@ -1,6 +1,5 @@
/* /*
* timers and cron for account related actions * timers and cron for account related actions
* @flow
*/ */
import Sequelize from 'sequelize'; import Sequelize from 'sequelize';
@ -13,7 +12,7 @@ import { MINUTE } from './constants';
import { DailyCron } from '../utils/cron'; import { DailyCron } from '../utils/cron';
class Ranks { class Ranks {
ranks: Array; ranks; // Array
constructor() { constructor() {
this.updateRanking = this.updateRanking.bind(this); this.updateRanking = this.updateRanking.bind(this);

View File

@ -1,7 +1,6 @@
/* /*
* Rolls back an area of the canvas to a specific date * Rolls back an area of the canvas to a specific date
* *
* @flow
*/ */
// Tile creation is allowed to be slow // Tile creation is allowed to be slow
@ -21,12 +20,12 @@ import { BACKUP_DIR } from './config';
import canvases from './canvases.json'; import canvases from './canvases.json';
export default async function rollbackToDate( export default async function rollbackToDate(
canvasId: number, canvasId, // number
x: number, x, // number
y: number, y, // number
width: number, width, // number
height: number, height, // number
date: string, date, // string
) { ) {
if (!BACKUP_DIR) { if (!BACKUP_DIR) {
return 0; return 0;

View File

@ -1,6 +1,5 @@
/* /*
* Provide translation serverside * Provide translation serverside
* @flow
*/ */
import { TTag } from 'ttag'; import { TTag } from 'ttag';
import cookie from 'cookie'; import cookie from 'cookie';

View File

@ -173,7 +173,7 @@ export function getPixelFromChunkOffset(
j, j,
offset, offset,
canvasSize, canvasSize,
is3d: boolean = false, is3d = false,
) { ) {
const tileSize = (is3d) ? THREE_TILE_SIZE : TILE_SIZE; const tileSize = (is3d) ? THREE_TILE_SIZE : TILE_SIZE;
const cx = offset % tileSize; const cx = offset % tileSize;
@ -225,7 +225,7 @@ export function worldToScreen(
export function durationToString( export function durationToString(
ms, ms,
smallest: boolean = false, smallest = false,
) { ) {
const seconds = Math.ceil(ms / 1000); const seconds = Math.ceil(ms / 1000);
let timestring; let timestring;
@ -297,7 +297,7 @@ export function colorFromText(str) {
/* /*
* sets a color into bright or dark mode * sets a color into bright or dark mode
*/ */
export function setBrightness(hex, dark: boolean = false) { export function setBrightness(hex, dark = false) {
hex = hex.replace(/^\s*#|\s*$/g, ''); hex = hex.replace(/^\s*#|\s*$/g, '');
if (hex.length === 3) { if (hex.length === 3) {

View File

@ -11,7 +11,6 @@
* Reference: * Reference:
* https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt * https://github.com/ephtracy/voxel-model/blob/master/MagicaVoxel-file-format-vox.txt
* *
* @flow
*/ */
/* /*

View File

@ -4,7 +4,6 @@
* loged in or not. * loged in or not.
* If user is not logged in, id = null * If user is not logged in, id = null
* *
* @flow
* */ * */
import { QueryTypes, Utils } from 'sequelize'; import { QueryTypes, Utils } from 'sequelize';
@ -49,21 +48,21 @@ export const regUserQueryInclude = [{
}]; }];
class User { class User {
id: string; id; // string
ip: string; ip; // string
wait: ?number; wait; // ?number
regUser: Object; regUser; // Object
channels: Object; channels; // Object
blocked: Array; blocked; // Array
/* /*
* 0: nothing * 0: nothing
* 1: Admin * 1: Admin
* 2: Mod * 2: Mod
*/ */
userlvl: number; userlvl; // number
constructor() { constructor() {
// if id = null -> unregistered // if id = 0 -> unregistered
this.id = 0; this.id = 0;
this.regUser = null; this.regUser = null;
this.ip = '127.0.0.1'; this.ip = '127.0.0.1';
@ -185,7 +184,7 @@ class User {
return true; return true;
} }
async getWait(canvasId: number): Promise<?number> { async getWait(canvasId) {
let ttl = await redis.pTTL(`cd:${canvasId}:ip:${this.ipSub}`); let ttl = await redis.pTTL(`cd:${canvasId}:ip:${this.ipSub}`);
if (this.id) { if (this.id) {
const ttlid = await redis.pTTL( const ttlid = await redis.pTTL(
@ -199,7 +198,7 @@ class User {
return wait; return wait;
} }
async incrementPixelcount(amount: number = 1): Promise<boolean> { async incrementPixelcount(amount = 1) {
const { id } = this; const { id } = this;
if (!id) return false; if (!id) return false;
try { try {
@ -213,7 +212,7 @@ class User {
return true; return true;
} }
async getTotalPixels(): Promise<number> { async getTotalPixels() {
const { id } = this; const { id } = this;
if (!id) return 0; if (!id) return 0;
if (this.userlvl === 1) return 100000; if (this.userlvl === 1) return 100000;
@ -244,7 +243,7 @@ class User {
} }
} }
async updateLogInTimestamp(): Promise<boolean> { async updateLogInTimestamp() {
if (!this.regUser) return false; if (!this.regUser) return false;
try { try {
await this.regUser.update({ await this.regUser.update({
@ -256,7 +255,7 @@ class User {
return true; return true;
} }
getUserData(): Object { getUserData() {
const { const {
id, id,
userlvl, userlvl,

View File

@ -43,12 +43,12 @@ const Channel = sequelize.define('Channel', {
updatedAt: false, updatedAt: false,
getterMethods: { getterMethods: {
lastTs(): number { lastTs() {
return new Date(this.lastMessage).valueOf(); return new Date(this.lastMessage).valueOf();
}, },
}, },
setterMethods: { setterMethods: {
lastTs(ts: number) { lastTs(ts) {
this.setDataValue('lastMessage', new Date(ts).toISOString()); this.setDataValue('lastMessage', new Date(ts).toISOString());
}, },
}, },

View File

@ -110,36 +110,36 @@ const RegUser = sequelize.define('User', {
updatedAt: false, updatedAt: false,
getterMethods: { getterMethods: {
mailVerified(): boolean { mailVerified() {
return this.verified & 0x01; return this.verified & 0x01;
}, },
blockDm(): boolean { blockDm() {
return this.blocks & 0x01; return this.blocks & 0x01;
}, },
isMod(): boolean { isMod() {
return this.roles & 0x01; return this.roles & 0x01;
}, },
}, },
setterMethods: { setterMethods: {
mailVerified(num: boolean) { mailVerified(num) {
const val = (num) ? (this.verified | 0x01) : (this.verified & ~0x01); const val = (num) ? (this.verified | 0x01) : (this.verified & ~0x01);
this.setDataValue('verified', val); this.setDataValue('verified', val);
}, },
blockDm(num: boolean) { blockDm(num) {
const val = (num) ? (this.blocks | 0x01) : (this.blocks & ~0x01); const val = (num) ? (this.blocks | 0x01) : (this.blocks & ~0x01);
this.setDataValue('blocks', val); this.setDataValue('blocks', val);
}, },
isMod(num: boolean) { isMod(num) {
const val = (num) ? (this.roles | 0x01) : (this.roles & ~0x01); const val = (num) ? (this.roles | 0x01) : (this.roles & ~0x01);
this.setDataValue('roles', val); this.setDataValue('roles', val);
}, },
password(value: string) { password(value) {
if (value) this.setDataValue('password', generateHash(value)); if (value) this.setDataValue('password', generateHash(value));
}, },
}, },

View File

@ -1,10 +1,7 @@
/* /*
* request password change * request password change
* @flow
*/ */
import type { Request, Response } from 'express';
import mailProvider from '../../../core/mail'; import mailProvider from '../../../core/mail';
import { validatePassword, validateEMail } from '../../../utils/validation'; import { validatePassword, validateEMail } from '../../../utils/validation';
@ -22,7 +19,7 @@ function validate(email, password, gettext) {
return errors; return errors;
} }
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { email, password } = req.body; const { email, password } = req.body;
const { t, gettext } = req.ttag; const { t, gettext } = req.ttag;
const errors = validate(email, password, gettext); const errors = validate(email, password, gettext);

View File

@ -1,11 +1,8 @@
/* /*
* request password change * request password change
* @flow
*/ */
import type { Request, Response } from 'express';
import socketEvents from '../../../socket/SocketEvents'; import socketEvents from '../../../socket/SocketEvents';
import { RegUser } from '../../../data/sql'; import { RegUser } from '../../../data/sql';
import { validateName } from '../../../utils/validation'; import { validateName } from '../../../utils/validation';
@ -22,7 +19,7 @@ async function validate(oldname, name) {
return null; return null;
} }
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { name } = req.body; const { name } = req.body;
const { user } = req; const { user } = req;

View File

@ -1,11 +1,8 @@
/* /*
* request password change * request password change
* @flow
*/ */
import type { Request, Response } from 'express';
import { validatePassword } from '../../../utils/validation'; import { validatePassword } from '../../../utils/validation';
import { compareToHash } from '../../../utils/hash'; import { compareToHash } from '../../../utils/hash';
@ -18,7 +15,7 @@ function validate(newPassword, gettext) {
return errors; return errors;
} }
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { newPassword, password } = req.body; const { newPassword, password } = req.body;
const { t, gettext } = req.ttag; const { t, gettext } = req.ttag;
const errors = validate(newPassword, gettext); const errors = validate(newPassword, gettext);

View File

@ -1,8 +1,3 @@
/**
* @flow
*/
import express from 'express'; import express from 'express';
import logger from '../../../core/logger'; import logger from '../../../core/logger';

View File

@ -1,10 +1,8 @@
/* /*
* logout * logout
* @flow
*/ */
import type { Request, Response } from 'express';
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { user } = req; const { user } = req;
const { t } = req.ttag; const { t } = req.ttag;
if (!user || !user.regUser) { if (!user || !user.regUser) {

View File

@ -1,10 +1,3 @@
/**
*
* @flow
*/
import type { Request, Response } from 'express';
import Sequelize from 'sequelize'; import Sequelize from 'sequelize';
import logger from '../../../core/logger'; import logger from '../../../core/logger';
@ -40,7 +33,7 @@ async function validate(email, name, password, captcha, captchaid, t, gettext) {
return errors; return errors;
} }
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { const {
email, name, password, captcha, captchaid, email, name, password, captcha, captchaid,
} = req.body; } = req.body;

View File

@ -1,15 +1,11 @@
/* /*
* request resend of verification mail * request resend of verification mail
* @flow
*/ */
import type { Request, Response } from 'express';
import mailProvider from '../../../core/mail'; import mailProvider from '../../../core/mail';
import { getHostFromRequest } from '../../../utils/ip'; import { getHostFromRequest } from '../../../utils/ip';
export default async (req: Request, res: Response) => { export default async (req, res) => {
const { user, lang } = req; const { user, lang } = req;
if (!user || !user.regUser) { if (!user || !user.regUser) {
res.status(401); res.status(401);

View File

@ -1,11 +1,8 @@
/* /*
* request passowrd reset mail * request passowrd reset mail
* @flow
*/ */
import type { Request, Response } from 'express';
import mailProvider from '../../../core/mail'; import mailProvider from '../../../core/mail';
import { validateEMail } from '../../../utils/validation'; import { validateEMail } from '../../../utils/validation';
import { getHostFromRequest } from '../../../utils/ip'; import { getHostFromRequest } from '../../../utils/ip';
@ -18,7 +15,7 @@ async function validate(email, gettext) {
return errors; return errors;
} }
export default async (req: Request, res: Response) => { export default async (req, res) => {
const ip = req.trueIp; const ip = req.trueIp;
const { email } = req.body; const { email } = req.body;
const { gettext } = req.ttag; const { gettext } = req.ttag;

View File

@ -2,16 +2,13 @@
* *
* blocks and unblocks a user * blocks and unblocks a user
* *
* @flow
*/ */
import type { Request, Response } from 'express';
import logger from '../../core/logger'; import logger from '../../core/logger';
import socketEvents from '../../socket/SocketEvents'; import socketEvents from '../../socket/SocketEvents';
import { RegUser, UserBlock, Channel } from '../../data/sql'; import { RegUser, UserBlock, Channel } from '../../data/sql';
async function block(req: Request, res: Response) { async function block(req, res) {
let userId = parseInt(req.body.userId, 10); let userId = parseInt(req.body.userId, 10);
let { userName } = req.body; let { userName } = req.body;
const { block: blocking } = req.body; const { block: blocking } = req.body;

View File

@ -2,15 +2,11 @@
* *
* block all private messages * block all private messages
* *
* @flow
*/ */
import type { Request, Response } from 'express';
import logger from '../../core/logger'; import logger from '../../core/logger';
import socketEvents from '../../socket/SocketEvents'; import socketEvents from '../../socket/SocketEvents';
async function blockdm(req: Request, res: Response) { async function blockdm(req, res) {
const { block } = req.body; const { block } = req.body;
const { user } = req; const { user } = req;

View File

@ -2,14 +2,10 @@
* *
* returns chat messages of given channel * returns chat messages of given channel
* *
* @flow
*/ */
import type { Request, Response } from 'express';
import chatProvider from '../../core/ChatProvider'; import chatProvider from '../../core/ChatProvider';
async function chatHistory(req: Request, res: Response) { async function chatHistory(req, res) {
let { cid, limit } = req.query; let { cid, limit } = req.query;
res.set({ res.set({
'Cache-Control': 'no-cache, no-store, must-revalidate', 'Cache-Control': 'no-cache, no-store, must-revalidate',

View File

@ -2,17 +2,13 @@
* *
* starts a DM session * starts a DM session
* *
* @flow
*/ */
import type { Request, Response } from 'express';
import logger from '../../core/logger'; import logger from '../../core/logger';
import { ChatProvider } from '../../core/ChatProvider'; import { ChatProvider } from '../../core/ChatProvider';
import { Channel, RegUser } from '../../data/sql'; import { Channel, RegUser } from '../../data/sql';
import { isUserBlockedBy } from '../../data/sql/UserBlock'; import { isUserBlockedBy } from '../../data/sql/UserBlock';
async function startDm(req: Request, res: Response) { async function startDm(req, res) {
let userId = parseInt(req.body.userId, 10); let userId = parseInt(req.body.userId, 10);
let { userName } = req.body; let { userName } = req.body;
const { user } = req; const { user } = req;

View File

@ -1,14 +1,8 @@
/**
*
* @flow
*/
import fs from 'fs'; import fs from 'fs';
import type { Request, Response } from 'express';
import { BACKUP_DIR } from '../core/config'; import { BACKUP_DIR } from '../core/config';
async function history(req: Request, res: Response) { async function history(req, res) {
const { day, id } = req.query; const { day, id } = req.query;
if (!BACKUP_DIR || !day || !id if (!BACKUP_DIR || !day || !id
|| day.includes('/') || day.includes('\\') || day.length !== 8 || day.includes('/') || day.includes('\\') || day.length !== 8

View File

@ -1,13 +1,10 @@
/** /**
* basic admin api * basic admin api
* *
* @flow
*/ */
import express from 'express'; import express from 'express';
import type { Request, Response } from 'express';
import logger from '../core/logger'; import logger from '../core/logger';
import getPasswordResetHtml from '../ssr/PasswordReset'; import getPasswordResetHtml from '../ssr/PasswordReset';
@ -27,7 +24,7 @@ router.use(express.urlencoded({ extended: true }));
* Check for POST parameters, * Check for POST parameters,
* if invalid password is given, ignore it and go to next * if invalid password is given, ignore it and go to next
*/ */
router.post('/', async (req: Request, res: Response) => { router.post('/', async (req, res) => {
const { pass, passconf, code } = req.body; const { pass, passconf, code } = req.body;
const { lang } = req; const { lang } = req;
const { t } = req.ttag; const { t } = req.ttag;
@ -96,7 +93,7 @@ router.post('/', async (req: Request, res: Response) => {
/* /*
* Check GET parameters for action to execute * Check GET parameters for action to execute
*/ */
router.get('/', async (req: Request, res: Response) => { router.get('/', async (req, res) => {
const { token } = req.query; const { token } = req.query;
const { lang } = req; const { lang } = req;
const { t } = req.ttag; const { t } = req.ttag;

View File

@ -5,8 +5,7 @@
* The minecraft server can set pixels and report user logins * The minecraft server can set pixels and report user logins
* and more. * and more.
* *
* @flow */ */
import WebSocket from 'ws'; import WebSocket from 'ws';
@ -36,7 +35,7 @@ async function verifyClient(info, done) {
class APISocketServer { class APISocketServer {
wss: WebSocket.Server; wss; // WebSocket.Server
initialize() { initialize() {
logger.info('Starting API websocket server'); logger.info('Starting API websocket server');

View File

@ -320,7 +320,7 @@ class SocketServer {
return amount; return amount;
} }
broadcastPixelBuffer(canvasId: number, chunkid, data: Buffer) { broadcastPixelBuffer(canvasId, chunkid, data) {
if (this.CHUNK_CLIENTS.has(chunkid)) { if (this.CHUNK_CLIENTS.has(chunkid)) {
const clients = this.CHUNK_CLIENTS.get(chunkid) const clients = this.CHUNK_CLIENTS.get(chunkid)
// eslint-disable-next-line eqeqeq // eslint-disable-next-line eqeqeq

View File

@ -1,12 +1,10 @@
/* @flow */ # Actions
import type { ColorIndex } from '../core/Palette';
import type { State } from '../reducers';
List of redux actions for reference:
```js
export type Action = export type Action =
{ type: 'LOGGED_OUT' } { type: 'LOGGED_OUT' }
// my actions
| { type: 'ALERT', | { type: 'ALERT',
title: string, title: string,
text: string, text: string,
@ -149,5 +147,5 @@ export type Action =
| { type: 'RELOAD_URL' } | { type: 'RELOAD_URL' }
| { type: 'SET_HISTORICAL_TIME', date: string, time: string } | { type: 'SET_HISTORICAL_TIME', date: string, time: string }
| { type: 'ON_VIEW_FINISH_CHANGE' }; | { type: 'ON_VIEW_FINISH_CHANGE' };
export type PromiseAction = Promise<Action>;
export type GetState = () => State; ```

View File

@ -115,7 +115,7 @@ export function toggleOpenMenu() {
}; };
} }
export function setRequestingPixel(requestingPixel: boolean) { export function setRequestingPixel(requestingPixel) {
return { return {
type: 'SET_REQUESTING_PIXEL', type: 'SET_REQUESTING_PIXEL',
requestingPixel, requestingPixel,
@ -148,14 +148,14 @@ export function unsetHover() {
}; };
} }
export function setWait(wait: ?number) { export function setWait(wait) {
return { return {
type: 'SET_WAIT', type: 'SET_WAIT',
wait, wait,
}; };
} }
export function setMobile(mobile: boolean) { export function setMobile(mobile) {
return { return {
type: 'SET_MOBILE', type: 'SET_MOBILE',
mobile, mobile,
@ -214,8 +214,8 @@ export function receiveChatMessage(
country, country,
channel, channel,
user, user,
isPing: boolean, isPing,
isRead: boolean, isRead,
) { ) {
return { return {
type: 'RECEIVE_CHAT_MESSAGE', type: 'RECEIVE_CHAT_MESSAGE',
@ -334,7 +334,7 @@ export function preLoadedBigChunk(
export function receiveBigChunk( export function receiveBigChunk(
center, center,
chunk: Uint8Array, chunk,
) { ) {
return { return {
type: 'RECEIVE_BIG_CHUNK', type: 'RECEIVE_BIG_CHUNK',
@ -343,7 +343,7 @@ export function receiveBigChunk(
}; };
} }
export function receiveBigChunkFailure(center, error: Error) { export function receiveBigChunkFailure(center, error) {
return { return {
type: 'RECEIVE_BIG_CHUNK_FAILURE', type: 'RECEIVE_BIG_CHUNK_FAILURE',
center, center,
@ -429,7 +429,7 @@ export function setName(
} }
export function setMailreg( export function setMailreg(
mailreg: boolean, mailreg,
) { ) {
return { return {
type: 'SET_MAILREG', type: 'SET_MAILREG',
@ -475,14 +475,14 @@ function receiveChatHistory(
}; };
} }
function setChatFetching(fetching: boolean) { function setChatFetching(fetching) {
return { return {
type: 'SET_CHAT_FETCHING', type: 'SET_CHAT_FETCHING',
fetching, fetching,
}; };
} }
function setApiFetching(fetching: boolean) { function setApiFetching(fetching) {
return { return {
type: 'SET_API_FETCHING', type: 'SET_API_FETCHING',
fetching, fetching,
@ -559,8 +559,8 @@ export function initTimer() {
export function openWindow( export function openWindow(
windowType, windowType,
title, title,
fullscreen: boolean, fullscreen,
cloneable: boolean, cloneable,
args, args,
xPos = null, xPos = null,
yPos = null, yPos = null,
@ -708,7 +708,7 @@ export function unblockUser(userId, userName) {
}; };
} }
export function blockingDm(blockDm: boolean) { export function blockingDm(blockDm) {
return { return {
type: 'SET_BLOCKING_DM', type: 'SET_BLOCKING_DM',
blockDm, blockDm,
@ -838,7 +838,7 @@ export function closeAllWindowTypes(windowType) {
export function hideAllWindowTypes( export function hideAllWindowTypes(
windowType, windowType,
hide: boolean, hide,
) { ) {
return { return {
type: 'HIDE_ALL_WINDOW_TYPE', type: 'HIDE_ALL_WINDOW_TYPE',
@ -896,7 +896,7 @@ export function gotCoolDownDelta(delta) {
export function setUserBlock( export function setUserBlock(
userId, userId,
userName, userName,
block: boolean, block,
) { ) {
return async (dispatch) => { return async (dispatch) => {
dispatch(setApiFetching(true)); dispatch(setApiFetching(true));
@ -918,7 +918,7 @@ export function setUserBlock(
} }
export function setBlockingDm( export function setBlockingDm(
block: boolean, block,
) { ) {
return async (dispatch) => { return async (dispatch) => {
dispatch(setApiFetching(true)); dispatch(setApiFetching(true));

View File

@ -1,7 +1,6 @@
/** /**
* Notifications * Notifications
* *
* @flow
*/ */

View File

@ -1,5 +1,3 @@
/* @flow */
const initialState = { const initialState = {
mute: false, mute: false,
chatNotify: true, chatNotify: true,

View File

@ -15,6 +15,7 @@ import {
TILE_SIZE, TILE_SIZE,
} from '../../core/constants'; } from '../../core/constants';
/*
export type CanvasState = { export type CanvasState = {
canvasId: number, canvasId: number,
canvasIdent: string, canvasIdent: string,
@ -40,13 +41,14 @@ export type CanvasState = {
prevCanvasCoords: Object, prevCanvasCoords: Object,
showHiddenCanvases: boolean, showHiddenCanvases: boolean,
}; };
*/
/* /*
* parse url hash and sets view to coordinates * parse url hash and sets view to coordinates
* @param canvases Object with all canvas informations * @param canvases Object with all canvas informations
* @return view, viewscale and scale for state * @return view, viewscale and scale for state
*/ */
function getViewFromURL(canvases: Object) { function getViewFromURL(canvases) {
const { hash } = window.location; const { hash } = window.location;
try { try {
const almost = hash.substring(1) const almost = hash.substring(1)
@ -143,7 +145,7 @@ const initialState = {
export default function canvasReducer( export default function canvasReducer(
state = initialState, state = initialState,
action, action,
): CanvasState { ) {
switch (action.type) { switch (action.type) {
case 'SET_SCALE': { case 'SET_SCALE': {
let { let {

View File

@ -1,7 +1,6 @@
/* /*
* Loading 3D chunks * Loading 3D chunks
* *
* @flow
*/ */
import { import {
@ -19,9 +18,9 @@ import Chunk from './ChunkRGB3D';
class ChunkLoader { class ChunkLoader {
store = null; store = null;
canvasId: number; canvasId;
palette; palette;
chunks: Map<string, Chunk>; chunks; // Map<string, Chunk>
constructor(store, canvasId, palette, canvasSize) { constructor(store, canvasId, palette, canvasSize) {
this.store = store; this.store = store;
@ -38,7 +37,7 @@ class ChunkLoader {
this.chunks = new Map(); this.chunks = new Map();
} }
getVoxel(x: number, y: number, z: number) { getVoxel(x, y, z) {
const { canvasSize } = this; const { canvasSize } = this;
const [xc, zc] = getChunkOfPixel(canvasSize, x, y, z); const [xc, zc] = getChunkOfPixel(canvasSize, x, y, z);
const offset = getOffsetOfPixel(canvasSize, x, y, z); const offset = getOffsetOfPixel(canvasSize, x, y, z);
@ -56,10 +55,10 @@ class ChunkLoader {
} }
getVoxelUpdate( getVoxelUpdate(
xc: number, xc,
zc: number, zc,
offset: number, offset,
color: number, color,
) { ) {
const key = `${xc}:${zc}`; const key = `${xc}:${zc}`;
const chunk = this.chunks.get(key); const chunk = this.chunks.get(key);
@ -68,7 +67,7 @@ class ChunkLoader {
} }
} }
getChunk(xc, zc, fetch: boolean) { getChunk(xc, zc, fetch) {
const chunkKey = `${xc}:${zc}`; const chunkKey = `${xc}:${zc}`;
// console.log(`Get chunk ${chunkKey}`); // console.log(`Get chunk ${chunkKey}`);
let chunk = this.chunks.get(chunkKey); let chunk = this.chunks.get(chunkKey);
@ -88,7 +87,7 @@ class ChunkLoader {
return null; return null;
} }
async fetchChunk(cx: number, cz: number, chunk) { async fetchChunk(cx, cz, chunk) {
const center = [0, cx, cz]; const center = [0, cx, cz];
this.store.dispatch(requestBigChunk(center)); this.store.dispatch(requestBigChunk(center));
try { try {
@ -114,7 +113,7 @@ class ChunkLoader {
/* /*
// sine environment creation for load tests // sine environment creation for load tests
async fetchChunk(xc: number, zc: number, chunk) { async fetchChunk(xc, zc, chunk) {
const { key } = chunk; const { key } = chunk;
console.log(`Fetch chunk ${key}`); console.log(`Fetch chunk ${key}`);
await chunk.generateSin(); await chunk.generateSin();

View File

@ -1,7 +1,6 @@
/* /*
* 3D Chunk * 3D Chunk
* *
* @flow
*/ */
/* We have to look for performance here not for good looking code */ /* We have to look for performance here not for good looking code */
@ -75,16 +74,16 @@ const material = new THREE.MeshLambertMaterial({
class Chunk { class Chunk {
cell: Array; cell; // Array
key: string; key; // string
ready: boolean = false; ready = false;
palette: Object; palette; // Object
buffer: Uint8Array; buffer; // Uint8Array
mesh: THREE.Mesh = null; mesh = null; // THREE.Mesh
faceCnt: number; faceCnt; // number
lastPixel: number; lastPixel; // number
heightMap: Array; heightMap; // Array
timestamp: number; timestamp; // number
constructor(palette, key, xc, zc) { constructor(palette, key, xc, zc) {
this.cell = [0, xc, zc]; this.cell = [0, xc, zc];
@ -99,7 +98,7 @@ class Chunk {
} }
} }
getVoxel(x: number, y: number, z: number) { getVoxel(x, y, z) {
const { buffer } = this; const { buffer } = this;
if (!buffer) return 0; if (!buffer) return 0;
if (x < 0 || x >= THREE_TILE_SIZE || y >= THREE_CANVAS_HEIGHT if (x < 0 || x >= THREE_TILE_SIZE || y >= THREE_CANVAS_HEIGHT
@ -111,7 +110,7 @@ class Chunk {
return this.buffer[offset]; return this.buffer[offset];
} }
getVoxelByOffset(offset: number) { getVoxelByOffset(offset) {
const { buffer } = this; const { buffer } = this;
if (!buffer) return 0; if (!buffer) return 0;
return buffer[offset]; return buffer[offset];
@ -149,7 +148,7 @@ class Chunk {
} }
*/ */
static calculateMetaData(buffer: Uint8Array) { static calculateMetaData(buffer) {
const rowVolume = THREE_TILE_SIZE ** 2; const rowVolume = THREE_TILE_SIZE ** 2;
const heightMap = new Uint8Array(rowVolume); const heightMap = new Uint8Array(rowVolume);
@ -204,7 +203,7 @@ class Chunk {
return [faceCnt, lastPixel, heightMap]; return [faceCnt, lastPixel, heightMap];
} }
static getOffsetOfVoxel(x: number, y: number, z: number) { static getOffsetOfVoxel(x, y, z) {
return x + z * THREE_TILE_SIZE + y * THREE_TILE_SIZE * THREE_TILE_SIZE; return x + z * THREE_TILE_SIZE + y * THREE_TILE_SIZE * THREE_TILE_SIZE;
} }
@ -216,7 +215,7 @@ class Chunk {
return [x, y, z]; return [x, y, z];
} }
setVoxelByOffset(offset: number, clr: number) { setVoxelByOffset(offset, clr) {
if (offset > this.lastPixel) { if (offset > this.lastPixel) {
this.lastPixel = offset; this.lastPixel = offset;
} }
@ -233,12 +232,12 @@ class Chunk {
this.renderChunk(); this.renderChunk();
} }
setVoxel(x: number, y: number, z: number, clr: number) { setVoxel(x, y, z, clr) {
const offset = Chunk.getOffsetOfVoxel(x, y, z); const offset = Chunk.getOffsetOfVoxel(x, y, z);
this.setVoxelByOffset(offset, clr); this.setVoxelByOffset(offset, clr);
} }
async fromBuffer(chunkBufferInpt: Uint8Array) { async fromBuffer(chunkBufferInpt) {
let chunkBuffer = chunkBufferInpt; let chunkBuffer = chunkBufferInpt;
const neededLength = THREE_TILE_SIZE ** 2 * THREE_CANVAS_HEIGHT; const neededLength = THREE_TILE_SIZE ** 2 * THREE_CANVAS_HEIGHT;
if (chunkBuffer.byteLength < neededLength) { if (chunkBuffer.byteLength < neededLength) {

View File

@ -3,21 +3,18 @@
* Notification when someone places a pixel nearby * Notification when someone places a pixel nearby
* Red increasing circle. * Red increasing circle.
* *
* @flow
*/ */
import type { State } from '../reducers';
import { clamp, worldToScreen } from '../core/utils'; import { clamp, worldToScreen } from '../core/utils';
class PixelNotify { class PixelNotify {
static NOTIFICATION_TIME = 1100; static NOTIFICATION_TIME = 1100;
scale: number; scale; // number
notifcircle: HTMLCanvasElement; notifcircle; // HTMLCanvasElement
notificationRadius: number; notificationRadius; // number
pixelList: Array; pixelList; // Array
constructor() { constructor() {
// initialise notification circle image // initialise notification circle image
@ -39,7 +36,7 @@ class PixelNotify {
} }
addPixel(x: number, y: number) { addPixel(x, y) {
if (this.pixelList.length < 300) { if (this.pixelList.length < 300) {
this.pixelList.unshift([Date.now(), x, y]); this.pixelList.unshift([Date.now(), x, y]);
} }
@ -51,15 +48,15 @@ class PixelNotify {
} }
updateScale(scale: number) { updateScale(scale) {
this.scale = scale; this.scale = scale;
this.notificationRadius = clamp(this.scale * 10, 20, 400); this.notificationRadius = clamp(this.scale * 10, 20, 400);
} }
render( render(
state: State, state,
$viewport: HTMLCanvasElement, $viewport,
) { ) {
const viewportCtx = $viewport.getContext('2d'); const viewportCtx = $viewport.getContext('2d');
if (!viewportCtx) return; if (!viewportCtx) return;

View File

@ -1,5 +1,3 @@
/* @flow */
/* /*
* check if cross-origin request * check if cross-origin request
* see: * see:
@ -33,21 +31,21 @@ export function loadImage(url) {
* loading tiles that get temporarily shown till real tile is loaded * loading tiles that get temporarily shown till real tile is loaded
*/ */
class LoadingTiles { class LoadingTiles {
tiles: Object; tiles; // Object
constructor() { constructor() {
this.tiles = {}; this.tiles = {};
this.loadLoadingTile(0); this.loadLoadingTile(0);
} }
getTile(canvasId: number) { getTile(canvasId) {
if (typeof this.tiles[canvasId] === 'undefined') { if (typeof this.tiles[canvasId] === 'undefined') {
this.loadLoadingTile(canvasId); this.loadLoadingTile(canvasId);
} }
return this.tiles[canvasId] || this.tiles[0] || null; return this.tiles[canvasId] || this.tiles[0] || null;
} }
async loadLoadingTile(canvasId: number) { async loadLoadingTile(canvasId) {
if (this.tiles[canvasId] === null) { if (this.tiles[canvasId] === null) {
return; return;
} }

View File

@ -3,7 +3,6 @@
* Always just one pixelrequest, queue additional requests to send later * Always just one pixelrequest, queue additional requests to send later
* Pixels get predicted on the client and reset if server refused * Pixels get predicted on the client and reset if server refused
* *
* @flow
* */ * */
import { t } from 'ttag'; import { t } from 'ttag';
import { import {

View File

@ -1,19 +1,17 @@
/* /*
* placeholder that shows underneach cursor * placeholder that shows underneach cursor
* *
* @flow
*/ */
import type { State } from '../reducers';
import { screenToWorld, worldToScreen } from '../core/utils'; import { screenToWorld, worldToScreen } from '../core/utils';
const PLACEHOLDER_SIZE = 1.2; const PLACEHOLDER_SIZE = 1.2;
const PLACEHOLDER_BORDER = 1; const PLACEHOLDER_BORDER = 1;
export function renderPlaceholder( export function renderPlaceholder(
state: State, state,
$viewport: HTMLCanvasElement, $viewport,
scale: number, scale,
) { ) {
const viewportCtx = $viewport.getContext('2d'); const viewportCtx = $viewport.getContext('2d');
@ -45,9 +43,9 @@ export function renderPlaceholder(
export function renderPotatoPlaceholder( export function renderPotatoPlaceholder(
state: State, state,
$viewport: HTMLCanvasElement, $viewport,
scale: number, scale,
) { ) {
const viewportCtx = $viewport.getContext('2d'); const viewportCtx = $viewport.getContext('2d');
@ -72,10 +70,10 @@ export function renderPotatoPlaceholder(
export function renderGrid( export function renderGrid(
state: State, state,
$viewport: HTMLCanvasElement, $viewport,
scale: number, scale,
isLightGrid: boolean, isLightGrid,
) { ) {
const { width, height } = $viewport; const { width, height } = $viewport;

Some files were not shown because too many files have changed in this diff Show More