make info and event messages belong to actual user

This commit is contained in:
HF 2020-11-06 21:00:47 +01:00
parent 2038e56d4f
commit 9f0a78f1ea
8 changed files with 93 additions and 41 deletions

View File

@ -47,9 +47,9 @@ export default function getPasswordResetHtml(name, code, message = null) {
: <PasswordReset name={name} code={code} />;
const index = `<!doctype html>${
ReactDOM.renderToStaticMarkup(<Html
title={title}
description={description}
body={body}
title={title}
description={description}
body={body}
/>)}`;
return index;
}

View File

@ -181,6 +181,7 @@ class PixelPlainterControls {
onTouchStart(event: TouchEvent) {
event.preventDefault();
event.stopPropagation();
document.activeElement.blur();
this.clickTabStartTime = Date.now();
@ -212,6 +213,7 @@ class PixelPlainterControls {
onTouchEnd(event: TouchEvent) {
event.preventDefault();
event.stopPropagation();
this.clearTabTimeout();
if (event.changedTouches.length < 2) {
@ -240,6 +242,7 @@ class PixelPlainterControls {
onTouchMove(event: TouchEvent) {
event.preventDefault();
event.stopPropagation();
const multiTouch = (event.touches.length > 1);

View File

@ -5,16 +5,19 @@ import logger from './logger';
import redis from '../data/redis';
import User from '../data/models/User';
import webSockets from '../socket/websockets';
import { Channel } from '../data/models';
import { Channel, RegUser } from '../data/models';
import ChatMessageBuffer from './ChatMessageBuffer';
import { CHAT_CHANNELS } from './constants';
import { CHAT_CHANNELS, EVENT_USER_NAME, INFO_USER_NAME } from './constants';
export class ChatProvider {
constructor() {
this.defaultChannels = [];
this.defaultChannelIds = [];
this.enChannelId = 0;
this.intChannelId = 0;
this.infoUserId = 1;
this.eventUserId = 1;
this.caseCheck = /^[A-Z !.]*$/;
this.cyrillic = new RegExp('[\u0436-\u043B]');
this.filters = [
@ -68,12 +71,44 @@ export class ChatProvider {
if (name === 'int') {
this.intChannelId = id;
}
if (name === 'en') {
this.enChannelId = id;
}
this.defaultChannels.push([
id,
name,
]);
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) {
@ -181,6 +216,7 @@ export class ChatProvider {
'info',
`Country ${cc} has been muted`,
channelId,
this.infoUserId,
);
return null;
} if (cmd === 'unmutec' && args[0]) {
@ -193,6 +229,7 @@ export class ChatProvider {
'info',
`Country ${cc} has been unmuted`,
channelId,
this.infoUserId,
);
return null;
}
@ -226,8 +263,8 @@ export class ChatProvider {
broadcastChatMessage(
name,
message,
channelId: number = 1,
id = 1,
channelId,
id,
country: string = 'xx',
sendapi: boolean = true,
) {
@ -251,12 +288,13 @@ export class ChatProvider {
);
}
static automute(name, channelId = 1) {
static automute(name, channelId) {
ChatProvider.mute(name, channelId, 60);
webSockets.broadcastChatMessage(
'info',
`${name} has been muted for spam for 60min`,
channelId,
this.infoUserId,
);
}
@ -266,7 +304,7 @@ export class ChatProvider {
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 id = await User.name2Id(name);
if (!id) {
@ -281,6 +319,7 @@ export class ChatProvider {
'info',
`${name} has been muted for ${timeMin}min`,
channelId,
this.infoUserId,
);
}
} else {
@ -289,13 +328,14 @@ export class ChatProvider {
'info',
`${name} has been muted forever`,
channelId,
this.infoUserId,
);
}
logger.info(`Muted user ${id}`);
return null;
}
static async unmute(plainName, channelId = 1) {
static async unmute(plainName, channelId) {
const name = (plainName.startsWith('@')) ? plainName.substr(1) : plainName;
const id = await User.name2Id(name);
if (!id) {
@ -310,6 +350,7 @@ export class ChatProvider {
'info',
`${name} has been unmuted`,
channelId,
this.infoUserId,
);
logger.info(`Unmuted user ${id}`);
return null;

View File

@ -90,6 +90,8 @@ export const DAY = 24 * HOUR;
export const MONTH = 30 * DAY;
// available public Chat Channels
// at least 'en' and 'int' have to be present,
// as they get used in core/ChatProvider
export const CHAT_CHANNELS = [
{
name: 'en',
@ -99,3 +101,6 @@ export const CHAT_CHANNELS = [
];
export const MAX_CHAT_MESSAGES = 100;
export const EVENT_USER_NAME = 'event';
export const INFO_USER_NAME = 'info';

View File

@ -18,7 +18,7 @@ import {
import Void from './Void';
import { protectCanvasArea } from './Image';
import { setPixelByOffset } from './setPixel';
import { TILE_SIZE } from './constants';
import { TILE_SIZE, EVENT_USER_NAME } from './constants';
import chatProvider from './ChatProvider';
import { HOURLY_EVENT } from './config';
// eslint-disable-next-line import/no-unresolved
@ -147,8 +147,7 @@ class Event {
const timestamp = await nextEvent();
const x = i * TILE_SIZE - canvasSize / 2;
const y = j * TILE_SIZE - canvasSize / 2;
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
`Suspicious activity spotted in ${Event.getDirection(x, y)}`,
);
drawCross([i, j], 19, 0, 13);
@ -156,6 +155,15 @@ class Event {
return timestamp;
}
static broadcastChatMessage(message) {
chatProvider.broadcastChatMessage(
EVENT_USER_NAME,
message,
chatProvider.enChannelId,
chatProvider.eventUserId,
);
}
async runEventLoop() {
const {
eventState,
@ -181,8 +189,7 @@ class Event {
if (eventState !== 3 && eventState !== 4) {
this.eventState = 3;
const [x, y] = this.eventArea;
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
`Unstable area at ${Event.getDirection(x, y)} at concerning level`,
);
}
@ -215,8 +222,7 @@ class Event {
const rand = Math.random() * 3000 - 500;
return Math.floor(z + TILE_SIZE * 1.5 + rand);
});
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
`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
if (eventState !== 9 && eventState !== 10) {
this.eventState = 9;
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
'Alert! Danger!',
);
}
@ -251,8 +256,7 @@ class Event {
const [x, y, w, h] = this.eventArea;
await protectCanvasArea(CANVAS_ID, x, y, w, h, false);
logger.info(`Starting Event at ${x},${y} now`);
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
'Fight starting!',
);
this.void = new Void(this.eventCenterC);
@ -262,8 +266,7 @@ class Event {
if (percent === 100) {
// event lost
logger.info(`Event got lost after ${Math.abs(eventMinutes)} min`);
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
'Threat couldn\'t be contained, abandon area',
);
this.success = 2;
@ -274,8 +277,7 @@ class Event {
} else {
const now = Date.now();
if (now > this.chatTimeout) {
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
`Clown Void reached ${percent}% of its max size`,
);
this.chatTimeout = now + 40000;
@ -292,8 +294,7 @@ class Event {
if (this.void.checkStatus() !== 100) {
// event won
logger.info('Event got won! Cooldown sitewide now half.');
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
'Threat successfully defeated. Good work!',
);
this.success = 1;
@ -312,8 +313,7 @@ class Event {
// 5min after last Event
// end debuff if lost
if (this.success === 2) {
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
'Void seems to leave again.',
);
this.success = 0;
@ -330,8 +330,7 @@ class Event {
logger.info('Restoring old event area');
await clearOldEvent();
if (this.success === 1) {
chatProvider.broadcastChatMessage(
'event',
Event.broadcastChatMessage(
'Celebration time over, get back to work.',
);
this.success = 0;

View File

@ -253,16 +253,16 @@ class APISocketServer extends WebSocketEvents {
chatProvider.broadcastChatMessage(
chatname,
msg,
1,
1,
chatProvider.enChannelId,
chatProvider.infoUserId,
'xx',
false,
);
this.broadcastChatMessage(
chatname,
msg,
1,
1,
chatProvider.enChannelId,
chatProvider.infoUserId,
'xx',
true,
ws,
@ -275,7 +275,7 @@ class APISocketServer extends WebSocketEvents {
name,
msg,
channelId,
1,
chatProvider.infoUserId,
country,
false,
);
@ -283,7 +283,7 @@ class APISocketServer extends WebSocketEvents {
name,
msg,
channelId,
1,
chatProvider.infoUserId,
country,
true,
ws,

View File

@ -14,8 +14,12 @@ class WebSocketEvents {
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) {
}

View File

@ -71,8 +71,8 @@ class WebSockets {
broadcastChatMessage(
name: string,
message: string,
channelId: number = 1,
id: number = 1,
channelId: number,
id: number,
country: string = 'xx',
sendapi: boolean = true,
) {