1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00

inital v2 commit

This commit is contained in:
marzavec 2020-09-07 23:51:47 -05:00
parent 6824073300
commit 6266b1432d
23 changed files with 608 additions and 597 deletions

696
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,8 @@
"license": "WTFPL",
"dependencies": {
"esm": "^3.2.25",
"http-server": "^0.12.1",
"pm2": "^4.2.3"
"http-server": "^0.12.3",
"pm2": "^4.4.1",
"react-icons": "^3.11.0"
}
}

View File

@ -1,6 +1,6 @@
{
"name": "hack.chat-v2",
"version": "2.1.9",
"version": "2.1.93",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -18,11 +18,6 @@
"color-convert": "^2.0.1"
}
},
"ascii-captcha": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/ascii-captcha/-/ascii-captcha-0.0.3.tgz",
"integrity": "sha1-NAtO1oVYOHEHsJVzBC/kc4v0mPk="
},
"async": {
"version": "0.9.2",
"resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
@ -202,16 +197,16 @@
}
},
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"version": "0.5.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"requires": {
"minimist": "0.0.8"
"minimist": "^1.2.5"
}
},
"mute-stream": {

View File

@ -14,7 +14,7 @@ export async function run(core, server, socket) {
// attempt save, notify of failure
if (!core.configManager.save()) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Failed to save config, check logs.',
}, socket);
}

View File

@ -8,7 +8,7 @@ import * as UAC from '../utility/UAC/_info';
export async function run(core, server, socket, data) {
if (server.police.frisk(socket.address, 6)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are changing nicknames too fast. Wait a moment before trying again.',
}, socket);
}
@ -24,7 +24,7 @@ export async function run(core, server, socket, data) {
const newNick = data.nick.trim();
if (!UAC.verifyNickname(newNick)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Nickname must consist of up to 24 letters, numbers, and underscores',
}, socket);
}
@ -35,14 +35,14 @@ export async function run(core, server, socket, data) {
server.police.frisk(socket.address, 4);
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are not the admin, liar!',
}, socket);
}
if (newNick == previousNick) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You already have that name',
}, socket);
}
@ -59,7 +59,7 @@ export async function run(core, server, socket, data) {
if (userExists.length > 0) {
// That nickname is already in that channel
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Nickname taken',
}, socket);
}
@ -112,7 +112,7 @@ export function nickCheck(core, server, socket, payload) {
// If there is no nickname target parameter
if (input[1] === undefined) {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Refer to `/help nick` for instructions on how to use this command.',
}, socket);

View File

@ -35,7 +35,7 @@ export async function run(core, server, socket, data) {
const score = text.length / 83 / 4;
if (server.police.frisk(socket.address, score)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
}, socket);
}
@ -43,7 +43,9 @@ export async function run(core, server, socket, data) {
// build chat payload
const payload = {
cmd: 'chat',
nick: socket.nick,
nick: socket.nick, /* @legacy */
userid: socket.userid,
channel: socket.channel,
text,
level: socket.level,
};
@ -55,7 +57,7 @@ export async function run(core, server, socket, data) {
}
if (socket.trip) {
payload.trip = socket.trip;
payload.trip = socket.trip; /* @legacy */
}
// broadcast to channel peers
@ -107,7 +109,7 @@ export function finalCmdCheck(core, server, socket, payload) {
}
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: `Unknown command: ${payload.text}`,
}, socket);

View File

@ -33,7 +33,7 @@ export async function run(core, server, socket, payload) {
const score = text.length / 83 / 4;
if (server.police.frisk(socket.address, score)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
}, socket);
}
@ -42,6 +42,7 @@ export async function run(core, server, socket, payload) {
text = ` ${text}`;
}
// @todo Change `cmd` from `info` to it's own `emote` event
const newPayload = {
cmd: 'info',
type: 'emote',
@ -75,7 +76,7 @@ export function emoteCheck(core, server, socket, payload) {
// If there is no emote target parameter
if (input[1] === undefined) {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Refer to `/help emote` for instructions on how to use this command.',
}, socket);

View File

@ -7,7 +7,7 @@ export async function run(core, server, socket, payload) {
// check for spam
if (server.police.frisk(socket.address, 2)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
}, socket);
}

View File

@ -2,24 +2,7 @@
Description: Generates a semi-unique channel name then broadcasts it to each client
*/
import * as UAC from '../utility/UAC/_info';
// module support functions
/**
* Returns a message for if it's a valid nickname to invite. Returns null if there was no error.
* @param {any} nick
* @return {(string|null)}
*/
export function checkNickname (nick, inviterNick) {
if (typeof nick !== 'string' || !UAC.verifyNickname(nick)) {
return "Nickname was invalid.";
} else if (nick === inviterNick) {
return "Why would you invite yourself?";
}
return null;
}
/**
* Returns the channel that should be invited to.
* @param {any} channel
@ -33,90 +16,56 @@ export function getChannel (channel=undefined) {
}
}
/**
* Creates the payload that a user who is being invited would receive.
* @param {string} inviter The user who is inviting them.
* @param {string} channel The channel they are being invited to.
* @return {Object}
*/
export function createRecipientPayload (inviter, channel) {
return {
cmd: 'info',
type: 'invite',
from: inviter,
text: `${inviter} invited you to ?${channel}`,
};
}
/**
* Creates the payload that a user who invited users (and succeeded) would receive.
* @param {string} nick The user who was invited.
* @param {string} channel The channel they were invited to.
*/
export function createSuccessPayload (nick, channel) {
return {
cmd: 'info',
type: 'invite',
invite: channel,
text: `You invited ${nick} to ?${channel}`,
};
}
/**
* Sends the invites to the recipients.
* @param {MainServer} server The server. Required to broadcast the messages.
* @param {string} recipientNick The user who is being invited.
* @param {string} inviterNick The user who is doing the inviting.
* @param {string} originalChannel The channel they have in common, and where the invite is sent in.
* @param {string} inviteChannel The channel they are being invited to.
*/
export function sendInvite (server, recipientNick, inviterNick, originalChannel, inviteChannel) {
return server.broadcast(createRecipientPayload(inviterNick, inviteChannel), {
channel: originalChannel,
nick: recipientNick,
});
}
// module main
export async function run(core, server, socket, data) {
// check for spam
if (server.police.frisk(socket.address, 2)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are sending invites too fast. Wait a moment before trying again.',
}, socket);
}
// verify user input
const nickValid = checkNickname(data.nick, socket.nick);
if (nickValid !== null) {
server.reply({
cmd: 'warn',
text: nickValid,
}, socket);
if (typeof data.userid !== 'number' || typeof data.channel !== 'string') {
return true;
}
const channel = getChannel(data.to);
// why would you invite yourself?
if (data.userid === socket.userid) {
return true;
}
// build and send invite
const payload = createRecipientPayload(socket.nick, channel);
// @todo Verify this socket is part of data.channel - multichannel patch
// find target user
let targetClient = server.findSockets({ channel: data.channel, userid: data.userid });
const inviteSent = server.broadcast(payload, {
channel: socket.channel,
nick: data.nick,
});
// server indicates the user was not found
if (!inviteSent) {
if (targetClient.length === 0) {
return server.reply({
cmd: 'warn',
text: 'Could not find user in channel',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Could not find user in that channel',
}, socket);
}
// reply with common channel
server.reply(createSuccessPayload(data.nick, channel), socket);
[targetClient] = targetClient;
// generate common channel
const channel = getChannel(data.to);
// build invite
const payload = {
cmd: 'invite',
channel: socket.channel,
from: socket.userid,
to: data.userid,
inviteChannel: channel,
};
// send invite notice to target client
server.reply(payload, targetClient);
// send invite notice to this client
server.reply(payload, socket);
// stats are fun
core.stats.increment('invites-sent');
@ -124,7 +73,7 @@ export async function run(core, server, socket, data) {
return true;
}
export const requiredData = ['nick'];
export const requiredData = [];//['nick'];
export const info = {
name: 'invite',
description: 'Sends an invite to the target client with the provided channel, or a random channel.',

View File

@ -17,28 +17,19 @@ const hash = (password) => {
// returns object containing user info or string if error
export function parseNickname(core, data) {
const userInfo = {
nick: '',
nick: data.nick,
uType: 'user', /* @legacy */
trip: null,
level: UAC.levels.default,
};
// seperate nick from password
const nickArray = data.nick.split('#', 2);
userInfo.nick = nickArray[0].trim();
if (!UAC.verifyNickname(userInfo.nick)) {
// return error as string
// @todo Remove english and change to numeric id
return 'Nickname must consist of up to 24 letters, numbers, and underscores';
}
let password = undefined;
// prioritize hash in nick for password over password field
if (typeof nickArray[1] === 'string') {
password = nickArray[1];
} else if (typeof data.password === 'string') {
password = data.password;
}
let password = data.pass || false;
if (hash(password + core.config.tripSalt) === core.config.adminTrip) {
userInfo.uType = 'admin'; /* @legacy */
@ -46,6 +37,7 @@ export function parseNickname(core, data) {
userInfo.level = UAC.levels.admin;
} else if (userInfo.nick.toLowerCase() === core.config.adminName.toLowerCase()) {
// they've got the main-admin name while not being an admin
// @todo Remove english and change to numeric id
return 'You are not the admin, liar!';
} else if (password) {
userInfo.trip = hash(password + core.config.tripSalt);
@ -68,14 +60,18 @@ export async function run(core, server, socket, data) {
// check for spam
if (server.police.frisk(socket.address, 3)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are joining channels too fast. Wait a moment and try again.',
}, socket);
}
// calling socket already in a channel
// @todo Multichannel update
if (typeof socket.channel !== 'undefined') {
return true;
return server.reply({
cmd: 'warn', // @todo Remove this
text: 'Joining more than one channel is not currently supported',
}, socket);
}
// check user input
@ -92,7 +88,7 @@ export async function run(core, server, socket, data) {
const userInfo = this.parseNickname(core, data);
if (typeof userInfo === 'string') {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: userInfo,
}, socket);
}
@ -106,19 +102,17 @@ export async function run(core, server, socket, data) {
if (userExists.length > 0) {
// that nickname is already in that channel
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Nickname taken',
}, socket);
}
// populate final userinfo fields
// @TODO: this could be move into parseNickname, changing the function name to match
userInfo.hash = server.getSocketHash(socket);
userInfo.userid = socket.userid;
// assign "unique" socket ID
if (typeof socket.userid === 'undefined') {
userInfo.userid = Math.floor(Math.random() * 9999999999999);
}
// TODO: place this within it's own function allowing import
// @TODO: place this within it's own function allowing import
// prepare to notify channel peers
const newPeerList = server.findSockets({ channel: data.channel });
const nicks = []; /* @legacy */
@ -159,7 +153,6 @@ export async function run(core, server, socket, data) {
socket.channel = data.channel; /* @legacy */
socket.hash = userInfo.hash;
socket.level = userInfo.level;
socket.userid = userInfo.userid;
nicks.push(socket.nick); /* @legacy */
users.push({
@ -191,5 +184,5 @@ export const info = {
name: 'join',
description: 'Place calling socket into target channel with target nick & broadcast event to channel',
usage: `
API: { cmd: 'join', nick: '<your nickname>', password: '<optional password>', channel: '<target channel>' }`,
API: { cmd: 'join', nick: '<your nickname>', pass: '<optional password>', channel: '<target channel>' }`,
};

View File

@ -7,7 +7,7 @@ export async function run(core, server, socket, data) {
// check for spam
if (server.police.frisk(socket.address, 6)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are changing channels too fast. Wait a moment before trying again.',
}, socket);
}
@ -19,7 +19,7 @@ export async function run(core, server, socket, data) {
if (data.channel === '') {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Cannot move to an empty channel.',
}, socket);
}
@ -106,7 +106,7 @@ export function moveCheck(core, server, socket, payload) {
// If there is no channel target parameter
if (input[1] === undefined) {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Refer to `/help move` for instructions on how to use this command.',
}, socket);

View File

@ -2,8 +2,66 @@
Description: Create a new socket session or restore previous session
*/
// module support functions
const createSessionID = () => {
let sessionID = '';
for( let i = 0, j = 32; i < j; i++) {
sessionID += Math.random().toString(36).substr(2, 9);
}
return sessionID;
}
// module main
export async function run() { }
export async function run(core, server, socket) {
// gather connection and channel count
let ips = {};
let channels = {};
// todo: use public channel flag
let publicChanCounts = {
lounge: 0,
meta: 0,
math: 0,
physics: 0,
chemistry: 0,
technology: 0,
programming: 0,
games: 0,
banana: 0,
chinese: 0,
};
// todo: code resuage between here and `morestats`, export function
server.clients.forEach((client) => {
if (client.channel) {
channels[client.channel] = true;
ips[client.address] = true;
if (typeof publicChanCounts[client.channel] !== 'undefined') {
publicChanCounts[client.channel]++;
}
}
});
const uniqueClientCount = Object.keys(ips).length;
const uniqueChannels = Object.keys(channels).length;
ips = null;
channels = null;
// @todo: restore session
socket.sessionID = createSessionID();
socket.hcProtocol = 2;
socket.userid = Math.floor(Math.random() * 9999999999999);
// dispatch info
server.reply({
cmd: 'session',
users: uniqueClientCount,
chans: uniqueChannels,
public: publicChanCounts,
sessionID: socket.sessionID,
restored: false,
}, socket);
}
export const info = {
name: 'session',

View File

@ -1,5 +1,7 @@
/*
Description: Display text on targets screen that only they can see
@todo This should be changed to it's own event type, instead of `info`
and accept a `userid` rather than `nick`
*/
import * as UAC from '../utility/UAC/_info';
@ -36,7 +38,7 @@ export async function run(core, server, socket, payload) {
const score = text.length / 83 / 4;
if (server.police.frisk(socket.address, score)) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
}, socket);
}
@ -51,7 +53,7 @@ export async function run(core, server, socket, payload) {
if (targetClient.length === 0) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Could not find user in channel',
}, socket);
}
@ -94,7 +96,7 @@ export function whisperCheck(core, server, socket, payload) {
// If there is no nickname target parameter
if (input[1] === undefined) {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Refer to `/help whisper` for instructions on how to use this command.',
}, socket);
@ -117,7 +119,7 @@ export function whisperCheck(core, server, socket, payload) {
if (payload.text.startsWith('/r ')) {
if (typeof socket.whisperReply === 'undefined') {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Cannot reply to nobody',
}, socket);

View File

@ -14,7 +14,8 @@ export async function run(core, server, socket, data) {
if (socket.channel) {
server.broadcast({
cmd: 'onlineRemove',
nick: socket.nick,
userid: socket.userid,
nick: socket.nick, /* @legacy */
}, { channel: socket.channel });
}

View File

@ -1,18 +1,161 @@
/*
Description: This module adjusts outgoing data, making it compatible with legacy clients
Dear god this module is horrifying
*/
// import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
/**
* @todo
*/
return server.police.frisk(socket.address, 20);
}
// module hook functions
export function initHooks(server) {
// module is only a placeholder
// server.registerHook('out', '', this.);
server.registerHook('in', 'join', this.joinCheck.bind(this), 10);
server.registerHook('in', 'invite', this.inviteInCheck.bind(this), 10);
server.registerHook('out', 'invite', this.inviteOutCheck.bind(this), 10);
server.registerHook('in', 'ban', this.banCheck.bind(this), 10);
server.registerHook('in', 'dumb', this.dumbCheck.bind(this), 10);
server.registerHook('in', 'kick', this.kickCheck.bind(this), 10);
}
// hook incoming join events, if session was not invoked, default proto to 1
export function joinCheck(core, server, socket, payload) {
if (typeof socket.hcProtocol === 'undefined') {
socket.hcProtocol = 1;
const nickArray = payload.nick.split('#', 2);
payload.nick = nickArray[0].trim();
if (nickArray[1] && typeof payload.pass === 'undefined') {
payload.pass = nickArray[1];
}
// dunno how this happened on the legacy version
if (typeof payload.password !== 'undefined') {
payload.pass = payload.password;
}
if (typeof socket.userid === 'undefined') {
socket.userid = Math.floor(Math.random() * 9999999999999);
}
}
return payload;
}
// if legacy client sent an invite, downgrade request
export function inviteInCheck(core, server, socket, payload) {
if (socket.hcProtocol === 1) {
let targetClient = server.findSockets({ channel: socket.channel, nick: data.nick });
if (targetClient.length === 0) {
server.reply({
cmd: 'warn',
text: 'Could not find user in that channel',
}, socket);
return false;
}
[targetClient] = targetClient;
payload.userid = targetClient.userid;
payload.channel = socket.channel;
}
return payload;
}
//
export function inviteOutCheck(core, server, socket, payload) {
if (socket.hcProtocol === 1) {
payload.cmd = 'info';
if (socket.userid === payload.from) {
let toClient = server.findSockets({ channel: socket.channel, userid: payload.from });
[toClient] = toClient;
payload.type = 'invite';
payload.from = toClient.nick;
payload.text = `You invited ${toClient.nick} to ?${payload.inviteChannel}`;
} else if (socket.userid === payload.to) {
let fromClient = server.findSockets({ channel: socket.channel, userid: payload.from });
[fromClient] = fromClient;
payload.type = 'invite';
payload.from = fromClient.nick;
payload.text = `${fromClient.nick} invited you to ?${payload.inviteChannel}`;
}
}
return payload;
}
export function banCheck(core, server, socket, payload) {
if (socket.hcProtocol === 1) {
let targetClient = server.findSockets({ channel: socket.channel, nick: data.nick });
if (targetClient.length === 0) {
server.reply({
cmd: 'warn',
text: 'Could not find user in that channel',
}, socket);
return false;
}
[targetClient] = targetClient;
payload.userid = targetClient.userid;
payload.channel = socket.channel;
}
return payload;
}
export function dumbCheck(core, server, socket, payload) {
if (socket.hcProtocol === 1) {
let targetClient = server.findSockets({ channel: socket.channel, nick: data.nick });
if (targetClient.length === 0) {
server.reply({
cmd: 'warn',
text: 'Could not find user in that channel',
}, socket);
return false;
}
[targetClient] = targetClient;
payload.userid = targetClient.userid;
payload.channel = socket.channel;
}
return payload;
}
export function kickCheck(core, server, socket, payload) {
if (socket.hcProtocol === 1) {
if (typeof payload.nick !== 'number') {
if (typeof payload.nick !== 'object' && !Array.isArray(data.nick)) {
return true;
}
}
let targetClient = server.findSockets({ channel: socket.channel, nick: data.nick });
if (targetClient.length === 0) {
return false;
}
payload.userid = [];
for (let i = 0, j = targetClient.length; i < j; i += 1) {
payload.userid.push(targetClient[i].userid);
}
payload.channel = socket.channel;
}
return payload;
}
export const info = {

View File

@ -10,7 +10,10 @@ export async function run(core, server, socket, data) {
}
// send warning to target socket
server.reply({ cmd: 'warn', text: data.text }, socket);
server.reply({
cmd: 'warn', // @todo Remove english and change to numeric id
text: data.text
}, socket);
return true;
}

View File

@ -12,27 +12,27 @@ export async function run(core, server, socket, data) {
}
// check user input
if (typeof data.nick !== 'string') {
if (typeof data.userid !== 'number') {
return true;
}
// find target user
const targetNick = data.nick;
let badClient = server.findSockets({ channel: socket.channel, nick: targetNick });
let badClient = server.findSockets({ channel: socket.channel, userid: data.userid });
if (badClient.length === 0) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Could not find user in channel',
}, socket);
}
[badClient] = badClient;
const targetNick = badClient.nick;
// i guess banning mods or admins isn't the best idea?
if (badClient.level >= socket.level) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Cannot ban other users of the same level, how rude',
}, socket);
}
@ -52,8 +52,8 @@ export async function run(core, server, socket, data) {
// notify mods
server.broadcast({
cmd: 'info',
text: `${socket.nick}#${socket.trip} banned ${targetNick} in ${socket.channel}, userhash: ${badClient.hash}`,
channel: socket.channel,
text: `${socket.nick}#${socket.trip} banned ${targetNick} in ${data.channel}, userhash: ${badClient.hash}`,
channel: data.channel,
user: UAC.getUserDetails(badClient),
banner: UAC.getUserDetails(socket),
}, { level: UAC.isModerator });
@ -67,7 +67,7 @@ export async function run(core, server, socket, data) {
return true;
}
export const requiredData = ['nick'];
//export const requiredData = ['nick'];
export const info = {
name: 'ban',
description: 'Disconnects the target nickname in the same channel as calling socket & adds to ratelimiter',

View File

@ -4,7 +4,6 @@
*/
import * as UAC from '../utility/UAC/_info';
import * as Invite from '../core/invite';
// module constructor
export function init(core) {
@ -21,16 +20,16 @@ export async function run(core, server, socket, data) {
}
// check user input
if (typeof data.nick !== 'string') {
if (typeof data.userid !== 'number') {
return true;
}
// find target user
let badClient = server.findSockets({ channel: socket.channel, nick: data.nick });
let badClient = server.findSockets({ channel: data.channel, userid: data.userid });
if (badClient.length === 0) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Could not find user in channel',
}, socket);
}
@ -40,7 +39,7 @@ export async function run(core, server, socket, data) {
// likely dont need this, muting mods and admins is fine
if (badClient.level >= socket.level) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'This trick wont work on users of the same level',
}, socket);
}
@ -58,7 +57,7 @@ export async function run(core, server, socket, data) {
// notify mods
server.broadcast({
cmd: 'info',
text: `${socket.nick}#${socket.trip} muzzled ${data.nick} in ${socket.channel}, userhash: ${badClient.hash}`,
text: `${socket.nick}#${socket.trip} muzzled ${badClient.nick} in ${data.channel}, userhash: ${badClient.hash}`,
}, { level: UAC.isModerator });
return true;
@ -119,10 +118,11 @@ export function chatCheck(core, server, socket, payload) {
// shadow-prevent all invites from muzzled users
export function inviteCheck(core, server, socket, payload) {
if (core.muzzledHashes[socket.hash]) {
const nickValid = Invite.checkNickname(payload.nick);
// @todo convert to protocol 2
/*const nickValid = Invite.checkNickname(payload.nick);
if (nickValid !== null) {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: nickValid,
}, socket);
return false;
@ -132,7 +132,7 @@ export function inviteCheck(core, server, socket, payload) {
const channel = Invite.getChannel();
// send fake reply
server.reply(Invite.createSuccessPayload(payload.nick, channel), socket);
server.reply(Invite.createSuccessPayload(payload.nick, channel), socket);*/
return false;
}
@ -168,7 +168,7 @@ export function whisperCheck(core, server, socket, payload) {
return payload;
}
export const requiredData = ['nick'];
// export const requiredData = ['nick'];
export const info = {
name: 'dumb',
description: 'Globally shadow mute a connection. Optional allies array will see muted messages.',

View File

@ -12,8 +12,9 @@ export async function run(core, server, socket, data) {
}
// check user input
if (typeof data.nick !== 'string') {
if (typeof data.nick !== 'object' && !Array.isArray(data.nick)) {
if (typeof data.userid !== 'number') {
// @todo create multi-ban ui
if (typeof data.userid !== 'object' && !Array.isArray(data.userid)) {
return true;
}
}
@ -26,11 +27,11 @@ export async function run(core, server, socket, data) {
}
// find target user(s)
const badClients = server.findSockets({ channel: socket.channel, nick: data.nick });
const badClients = server.findSockets({ channel: data.channel, userid: data.userid });
if (badClients.length === 0) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Could not find user(s) in channel',
}, socket);
}
@ -40,7 +41,7 @@ export async function run(core, server, socket, data) {
for (let i = 0, j = badClients.length; i < j; i += 1) {
if (badClients[i].level >= socket.level) {
server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Cannot kick other users with the same level, how rude',
}, socket);
} else {
@ -96,7 +97,7 @@ export async function run(core, server, socket, data) {
return true;
}
export const requiredData = ['nick'];
// export const requiredData = ['nick'];
export const info = {
name: 'kick',
description: 'Silently forces target client(s) into another channel. `nick` may be string or array of strings',

View File

@ -25,7 +25,7 @@ export async function run(core, server, socket, data) {
if (badClients.length === 0) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Could not find user in channel',
}, socket);
}
@ -34,7 +34,7 @@ export async function run(core, server, socket, data) {
if (badClient.level >= socket.level) {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: 'Cannot move other users of the same level, how rude',
}, socket);
}

View File

@ -22,7 +22,7 @@ export async function run(core, server, socket, data) {
// check user input
if (typeof data.ip !== 'string' && typeof data.hash !== 'string') {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: "hash:'targethash' or ip:'1.2.3.4' is required",
}, socket);
}

View File

@ -14,7 +14,7 @@ export async function run(core, server, socket, data) {
// check user input
if (typeof data.ip !== 'string' && typeof data.hash !== 'string') {
return server.reply({
cmd: 'warn',
cmd: 'warn', // @todo Remove english and change to numeric id
text: "hash:'targethash' or ip:'1.2.3.4' is required",
}, socket);
}

View File

@ -197,7 +197,7 @@ class MainServer extends WsServer {
return;
}
if (typeof socket.channel === 'undefined' && (payload.cmd !== 'join' && payload.cmd !== 'chat')) {
if (typeof socket.channel === 'undefined' && (payload.cmd !== 'join' && payload.cmd !== 'session' && payload.cmd !== 'chat')) {
return;
}