make info and event messages belong to actual user
This commit is contained in:
parent
2038e56d4f
commit
9f0a78f1ea
|
@ -47,9 +47,9 @@ export default function getPasswordResetHtml(name, code, message = null) {
|
||||||
: <PasswordReset name={name} code={code} />;
|
: <PasswordReset name={name} code={code} />;
|
||||||
const index = `<!doctype html>${
|
const index = `<!doctype html>${
|
||||||
ReactDOM.renderToStaticMarkup(<Html
|
ReactDOM.renderToStaticMarkup(<Html
|
||||||
title={title}
|
title={title}
|
||||||
description={description}
|
description={description}
|
||||||
body={body}
|
body={body}
|
||||||
/>)}`;
|
/>)}`;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,6 +181,7 @@ class PixelPlainterControls {
|
||||||
|
|
||||||
onTouchStart(event: TouchEvent) {
|
onTouchStart(event: TouchEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
|
|
||||||
this.clickTabStartTime = Date.now();
|
this.clickTabStartTime = Date.now();
|
||||||
|
@ -212,6 +213,7 @@ class PixelPlainterControls {
|
||||||
|
|
||||||
onTouchEnd(event: TouchEvent) {
|
onTouchEnd(event: TouchEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
this.clearTabTimeout();
|
this.clearTabTimeout();
|
||||||
|
|
||||||
if (event.changedTouches.length < 2) {
|
if (event.changedTouches.length < 2) {
|
||||||
|
@ -240,6 +242,7 @@ class PixelPlainterControls {
|
||||||
|
|
||||||
onTouchMove(event: TouchEvent) {
|
onTouchMove(event: TouchEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const multiTouch = (event.touches.length > 1);
|
const multiTouch = (event.touches.length > 1);
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,19 @@ import logger from './logger';
|
||||||
import redis from '../data/redis';
|
import redis from '../data/redis';
|
||||||
import User from '../data/models/User';
|
import User from '../data/models/User';
|
||||||
import webSockets from '../socket/websockets';
|
import webSockets from '../socket/websockets';
|
||||||
import { Channel } from '../data/models';
|
import { Channel, RegUser } from '../data/models';
|
||||||
import ChatMessageBuffer from './ChatMessageBuffer';
|
import ChatMessageBuffer from './ChatMessageBuffer';
|
||||||
|
|
||||||
import { CHAT_CHANNELS } from './constants';
|
import { CHAT_CHANNELS, EVENT_USER_NAME, INFO_USER_NAME } from './constants';
|
||||||
|
|
||||||
export class ChatProvider {
|
export class ChatProvider {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.defaultChannels = [];
|
this.defaultChannels = [];
|
||||||
this.defaultChannelIds = [];
|
this.defaultChannelIds = [];
|
||||||
|
this.enChannelId = 0;
|
||||||
this.intChannelId = 0;
|
this.intChannelId = 0;
|
||||||
|
this.infoUserId = 1;
|
||||||
|
this.eventUserId = 1;
|
||||||
this.caseCheck = /^[A-Z !.]*$/;
|
this.caseCheck = /^[A-Z !.]*$/;
|
||||||
this.cyrillic = new RegExp('[\u0436-\u043B]');
|
this.cyrillic = new RegExp('[\u0436-\u043B]');
|
||||||
this.filters = [
|
this.filters = [
|
||||||
|
@ -68,12 +71,44 @@ export class ChatProvider {
|
||||||
if (name === 'int') {
|
if (name === 'int') {
|
||||||
this.intChannelId = id;
|
this.intChannelId = id;
|
||||||
}
|
}
|
||||||
|
if (name === 'en') {
|
||||||
|
this.enChannelId = id;
|
||||||
|
}
|
||||||
this.defaultChannels.push([
|
this.defaultChannels.push([
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
]);
|
]);
|
||||||
this.defaultChannelIds.push(id);
|
this.defaultChannelIds.push(id);
|
||||||
}
|
}
|
||||||
|
// find or create default users
|
||||||
|
let name = INFO_USER_NAME;
|
||||||
|
const infoUser = await RegUser.findOrCreate({
|
||||||
|
attributes: [
|
||||||
|
'id',
|
||||||
|
],
|
||||||
|
where: { name },
|
||||||
|
defaults: {
|
||||||
|
name,
|
||||||
|
verified: 3,
|
||||||
|
email: 'info@example.com',
|
||||||
|
},
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
[this.infoUserId] = infoUser;
|
||||||
|
name = EVENT_USER_NAME;
|
||||||
|
const eventUser = await RegUser.findOrCreate({
|
||||||
|
attributes: [
|
||||||
|
'id',
|
||||||
|
],
|
||||||
|
where: { name },
|
||||||
|
defaults: {
|
||||||
|
name,
|
||||||
|
verified: 3,
|
||||||
|
email: 'event@example.com',
|
||||||
|
},
|
||||||
|
raw: true,
|
||||||
|
});
|
||||||
|
[this.eventUserId] = eventUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
userHasChannelAccess(user, cid, write = false) {
|
userHasChannelAccess(user, cid, write = false) {
|
||||||
|
@ -181,6 +216,7 @@ export class ChatProvider {
|
||||||
'info',
|
'info',
|
||||||
`Country ${cc} has been muted`,
|
`Country ${cc} has been muted`,
|
||||||
channelId,
|
channelId,
|
||||||
|
this.infoUserId,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
} if (cmd === 'unmutec' && args[0]) {
|
} if (cmd === 'unmutec' && args[0]) {
|
||||||
|
@ -193,6 +229,7 @@ export class ChatProvider {
|
||||||
'info',
|
'info',
|
||||||
`Country ${cc} has been unmuted`,
|
`Country ${cc} has been unmuted`,
|
||||||
channelId,
|
channelId,
|
||||||
|
this.infoUserId,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -226,8 +263,8 @@ export class ChatProvider {
|
||||||
broadcastChatMessage(
|
broadcastChatMessage(
|
||||||
name,
|
name,
|
||||||
message,
|
message,
|
||||||
channelId: number = 1,
|
channelId,
|
||||||
id = 1,
|
id,
|
||||||
country: string = 'xx',
|
country: string = 'xx',
|
||||||
sendapi: boolean = true,
|
sendapi: boolean = true,
|
||||||
) {
|
) {
|
||||||
|
@ -251,12 +288,13 @@ export class ChatProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static automute(name, channelId = 1) {
|
static automute(name, channelId) {
|
||||||
ChatProvider.mute(name, channelId, 60);
|
ChatProvider.mute(name, channelId, 60);
|
||||||
webSockets.broadcastChatMessage(
|
webSockets.broadcastChatMessage(
|
||||||
'info',
|
'info',
|
||||||
`${name} has been muted for spam for 60min`,
|
`${name} has been muted for spam for 60min`,
|
||||||
channelId,
|
channelId,
|
||||||
|
this.infoUserId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +304,7 @@ export class ChatProvider {
|
||||||
return ttl;
|
return ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async mute(plainName, channelId = 1, timeMin = null) {
|
static async mute(plainName, channelId, timeMin = null) {
|
||||||
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
|
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
|
||||||
const id = await User.name2Id(name);
|
const id = await User.name2Id(name);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
@ -281,6 +319,7 @@ export class ChatProvider {
|
||||||
'info',
|
'info',
|
||||||
`${name} has been muted for ${timeMin}min`,
|
`${name} has been muted for ${timeMin}min`,
|
||||||
channelId,
|
channelId,
|
||||||
|
this.infoUserId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -289,13 +328,14 @@ export class ChatProvider {
|
||||||
'info',
|
'info',
|
||||||
`${name} has been muted forever`,
|
`${name} has been muted forever`,
|
||||||
channelId,
|
channelId,
|
||||||
|
this.infoUserId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
logger.info(`Muted user ${id}`);
|
logger.info(`Muted user ${id}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async unmute(plainName, channelId = 1) {
|
static async unmute(plainName, channelId) {
|
||||||
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
|
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
|
||||||
const id = await User.name2Id(name);
|
const id = await User.name2Id(name);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
@ -310,6 +350,7 @@ export class ChatProvider {
|
||||||
'info',
|
'info',
|
||||||
`${name} has been unmuted`,
|
`${name} has been unmuted`,
|
||||||
channelId,
|
channelId,
|
||||||
|
this.infoUserId,
|
||||||
);
|
);
|
||||||
logger.info(`Unmuted user ${id}`);
|
logger.info(`Unmuted user ${id}`);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -90,6 +90,8 @@ export const DAY = 24 * HOUR;
|
||||||
export const MONTH = 30 * DAY;
|
export const MONTH = 30 * DAY;
|
||||||
|
|
||||||
// available public Chat Channels
|
// available public Chat Channels
|
||||||
|
// at least 'en' and 'int' have to be present,
|
||||||
|
// as they get used in core/ChatProvider
|
||||||
export const CHAT_CHANNELS = [
|
export const CHAT_CHANNELS = [
|
||||||
{
|
{
|
||||||
name: 'en',
|
name: 'en',
|
||||||
|
@ -99,3 +101,6 @@ export const CHAT_CHANNELS = [
|
||||||
];
|
];
|
||||||
|
|
||||||
export const MAX_CHAT_MESSAGES = 100;
|
export const MAX_CHAT_MESSAGES = 100;
|
||||||
|
|
||||||
|
export const EVENT_USER_NAME = 'event';
|
||||||
|
export const INFO_USER_NAME = 'info';
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {
|
||||||
import Void from './Void';
|
import Void from './Void';
|
||||||
import { protectCanvasArea } from './Image';
|
import { protectCanvasArea } from './Image';
|
||||||
import { setPixelByOffset } from './setPixel';
|
import { setPixelByOffset } from './setPixel';
|
||||||
import { TILE_SIZE } from './constants';
|
import { TILE_SIZE, EVENT_USER_NAME } from './constants';
|
||||||
import chatProvider from './ChatProvider';
|
import chatProvider from './ChatProvider';
|
||||||
import { HOURLY_EVENT } from './config';
|
import { HOURLY_EVENT } from './config';
|
||||||
// eslint-disable-next-line import/no-unresolved
|
// eslint-disable-next-line import/no-unresolved
|
||||||
|
@ -147,8 +147,7 @@ class Event {
|
||||||
const timestamp = await nextEvent();
|
const timestamp = await nextEvent();
|
||||||
const x = i * TILE_SIZE - canvasSize / 2;
|
const x = i * TILE_SIZE - canvasSize / 2;
|
||||||
const y = j * TILE_SIZE - canvasSize / 2;
|
const y = j * TILE_SIZE - canvasSize / 2;
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
`Suspicious activity spotted in ${Event.getDirection(x, y)}`,
|
`Suspicious activity spotted in ${Event.getDirection(x, y)}`,
|
||||||
);
|
);
|
||||||
drawCross([i, j], 19, 0, 13);
|
drawCross([i, j], 19, 0, 13);
|
||||||
|
@ -156,6 +155,15 @@ class Event {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static broadcastChatMessage(message) {
|
||||||
|
chatProvider.broadcastChatMessage(
|
||||||
|
EVENT_USER_NAME,
|
||||||
|
message,
|
||||||
|
chatProvider.enChannelId,
|
||||||
|
chatProvider.eventUserId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async runEventLoop() {
|
async runEventLoop() {
|
||||||
const {
|
const {
|
||||||
eventState,
|
eventState,
|
||||||
|
@ -181,8 +189,7 @@ class Event {
|
||||||
if (eventState !== 3 && eventState !== 4) {
|
if (eventState !== 3 && eventState !== 4) {
|
||||||
this.eventState = 3;
|
this.eventState = 3;
|
||||||
const [x, y] = this.eventArea;
|
const [x, y] = this.eventArea;
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
`Unstable area at ${Event.getDirection(x, y)} at concerning level`,
|
`Unstable area at ${Event.getDirection(x, y)} at concerning level`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -215,8 +222,7 @@ class Event {
|
||||||
const rand = Math.random() * 3000 - 500;
|
const rand = Math.random() * 3000 - 500;
|
||||||
return Math.floor(z + TILE_SIZE * 1.5 + rand);
|
return Math.floor(z + TILE_SIZE * 1.5 + rand);
|
||||||
});
|
});
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
`Alert! Threat is rising in 2min near #d,${xNear},${yNear},30`,
|
`Alert! Threat is rising in 2min near #d,${xNear},${yNear},30`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -232,8 +238,7 @@ class Event {
|
||||||
// 1min till Event: blinking solid cross red small fase
|
// 1min till Event: blinking solid cross red small fase
|
||||||
if (eventState !== 9 && eventState !== 10) {
|
if (eventState !== 9 && eventState !== 10) {
|
||||||
this.eventState = 9;
|
this.eventState = 9;
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
'Alert! Danger!',
|
'Alert! Danger!',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -251,8 +256,7 @@ class Event {
|
||||||
const [x, y, w, h] = this.eventArea;
|
const [x, y, w, h] = this.eventArea;
|
||||||
await protectCanvasArea(CANVAS_ID, x, y, w, h, false);
|
await protectCanvasArea(CANVAS_ID, x, y, w, h, false);
|
||||||
logger.info(`Starting Event at ${x},${y} now`);
|
logger.info(`Starting Event at ${x},${y} now`);
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
'Fight starting!',
|
'Fight starting!',
|
||||||
);
|
);
|
||||||
this.void = new Void(this.eventCenterC);
|
this.void = new Void(this.eventCenterC);
|
||||||
|
@ -262,8 +266,7 @@ class Event {
|
||||||
if (percent === 100) {
|
if (percent === 100) {
|
||||||
// event lost
|
// event lost
|
||||||
logger.info(`Event got lost after ${Math.abs(eventMinutes)} min`);
|
logger.info(`Event got lost after ${Math.abs(eventMinutes)} min`);
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
'Threat couldn\'t be contained, abandon area',
|
'Threat couldn\'t be contained, abandon area',
|
||||||
);
|
);
|
||||||
this.success = 2;
|
this.success = 2;
|
||||||
|
@ -274,8 +277,7 @@ class Event {
|
||||||
} else {
|
} else {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now > this.chatTimeout) {
|
if (now > this.chatTimeout) {
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
`Clown Void reached ${percent}% of its max size`,
|
`Clown Void reached ${percent}% of its max size`,
|
||||||
);
|
);
|
||||||
this.chatTimeout = now + 40000;
|
this.chatTimeout = now + 40000;
|
||||||
|
@ -292,8 +294,7 @@ class Event {
|
||||||
if (this.void.checkStatus() !== 100) {
|
if (this.void.checkStatus() !== 100) {
|
||||||
// event won
|
// event won
|
||||||
logger.info('Event got won! Cooldown sitewide now half.');
|
logger.info('Event got won! Cooldown sitewide now half.');
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
'Threat successfully defeated. Good work!',
|
'Threat successfully defeated. Good work!',
|
||||||
);
|
);
|
||||||
this.success = 1;
|
this.success = 1;
|
||||||
|
@ -312,8 +313,7 @@ class Event {
|
||||||
// 5min after last Event
|
// 5min after last Event
|
||||||
// end debuff if lost
|
// end debuff if lost
|
||||||
if (this.success === 2) {
|
if (this.success === 2) {
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
'Void seems to leave again.',
|
'Void seems to leave again.',
|
||||||
);
|
);
|
||||||
this.success = 0;
|
this.success = 0;
|
||||||
|
@ -330,8 +330,7 @@ class Event {
|
||||||
logger.info('Restoring old event area');
|
logger.info('Restoring old event area');
|
||||||
await clearOldEvent();
|
await clearOldEvent();
|
||||||
if (this.success === 1) {
|
if (this.success === 1) {
|
||||||
chatProvider.broadcastChatMessage(
|
Event.broadcastChatMessage(
|
||||||
'event',
|
|
||||||
'Celebration time over, get back to work.',
|
'Celebration time over, get back to work.',
|
||||||
);
|
);
|
||||||
this.success = 0;
|
this.success = 0;
|
||||||
|
|
|
@ -253,16 +253,16 @@ class APISocketServer extends WebSocketEvents {
|
||||||
chatProvider.broadcastChatMessage(
|
chatProvider.broadcastChatMessage(
|
||||||
chatname,
|
chatname,
|
||||||
msg,
|
msg,
|
||||||
1,
|
chatProvider.enChannelId,
|
||||||
1,
|
chatProvider.infoUserId,
|
||||||
'xx',
|
'xx',
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
this.broadcastChatMessage(
|
this.broadcastChatMessage(
|
||||||
chatname,
|
chatname,
|
||||||
msg,
|
msg,
|
||||||
1,
|
chatProvider.enChannelId,
|
||||||
1,
|
chatProvider.infoUserId,
|
||||||
'xx',
|
'xx',
|
||||||
true,
|
true,
|
||||||
ws,
|
ws,
|
||||||
|
@ -275,7 +275,7 @@ class APISocketServer extends WebSocketEvents {
|
||||||
name,
|
name,
|
||||||
msg,
|
msg,
|
||||||
channelId,
|
channelId,
|
||||||
1,
|
chatProvider.infoUserId,
|
||||||
country,
|
country,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
@ -283,7 +283,7 @@ class APISocketServer extends WebSocketEvents {
|
||||||
name,
|
name,
|
||||||
msg,
|
msg,
|
||||||
channelId,
|
channelId,
|
||||||
1,
|
chatProvider.infoUserId,
|
||||||
country,
|
country,
|
||||||
true,
|
true,
|
||||||
ws,
|
ws,
|
||||||
|
|
|
@ -14,8 +14,12 @@ class WebSocketEvents {
|
||||||
broadcastPixelBuffer(canvasId: number, chunkid: number, buffer: Buffer) {
|
broadcastPixelBuffer(canvasId: number, chunkid: number, buffer: Buffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcastChatMessage(name: string, message: string, channelId: number) {
|
broadcastChatMessage(
|
||||||
}
|
name: string,
|
||||||
|
message: string,
|
||||||
|
channelId: number,
|
||||||
|
userId: number,
|
||||||
|
) {}
|
||||||
|
|
||||||
broadcastMinecraftLink(name: string, minecraftid: string, accepted: boolean) {
|
broadcastMinecraftLink(name: string, minecraftid: string, accepted: boolean) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,8 @@ class WebSockets {
|
||||||
broadcastChatMessage(
|
broadcastChatMessage(
|
||||||
name: string,
|
name: string,
|
||||||
message: string,
|
message: string,
|
||||||
channelId: number = 1,
|
channelId: number,
|
||||||
id: number = 1,
|
id: number,
|
||||||
country: string = 'xx',
|
country: string = 'xx',
|
||||||
sendapi: boolean = true,
|
sendapi: boolean = true,
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user