aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/core')
-rw-r--r--server/src/commands/core/emote.js8
-rw-r--r--server/src/commands/core/join.js61
-rw-r--r--server/src/commands/core/move.js45
-rw-r--r--server/src/commands/core/ping.js4
-rw-r--r--server/src/commands/core/session.js13
-rw-r--r--server/src/commands/core/whisper.js3
6 files changed, 113 insertions, 21 deletions
diff --git a/server/src/commands/core/emote.js b/server/src/commands/core/emote.js
index 19a5fbe..21d14d1 100644
--- a/server/src/commands/core/emote.js
+++ b/server/src/commands/core/emote.js
@@ -22,7 +22,7 @@ const parseText = (text) => {
// module main
export async function run(core, server, socket, payload) {
// check user input
- const text = parseText(payload.text);
+ let text = parseText(payload.text);
if (!text) {
// lets not send objects or empty text, yea?
@@ -38,11 +38,15 @@ export async function run(core, server, socket, payload) {
}, socket);
}
+ if (!text.startsWith("'")) {
+ text = ` ${text}`;
+ }
+
const newPayload = {
cmd: 'info',
type: 'emote',
nick: socket.nick,
- text: `@${socket.nick} ${text}`,
+ text: `@${socket.nick}${text}`,
};
if (socket.trip) {
newPayload.trip = socket.trip;
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
index ddbdf6d..b17e1fc 100644
--- a/server/src/commands/core/join.js
+++ b/server/src/commands/core/join.js
@@ -18,7 +18,7 @@ const hash = (password) => {
export function parseNickname(core, data) {
const userInfo = {
nick: '',
- uType: 'user',
+ uType: 'user', /* @legacy */
trip: null,
level: UAC.levels.default,
};
@@ -41,7 +41,7 @@ export function parseNickname(core, data) {
}
if (hash(password + core.config.tripSalt) === core.config.adminTrip) {
- userInfo.uType = 'admin';
+ userInfo.uType = 'admin'; /* @legacy */
userInfo.trip = 'Admin';
userInfo.level = UAC.levels.admin;
} else if (userInfo.nick.toLowerCase() === core.config.adminName.toLowerCase()) {
@@ -55,7 +55,7 @@ export function parseNickname(core, data) {
// for (const mod of core.config.mods) {
core.config.mods.forEach((mod) => {
if (userInfo.trip === mod.trip) {
- userInfo.uType = 'mod';
+ userInfo.uType = 'mod'; /* @legacy */
userInfo.level = UAC.levels.moderator;
}
});
@@ -111,40 +111,73 @@ export async function run(core, server, socket, data) {
}, socket);
}
- userInfo.userHash = server.getSocketHash(socket);
+ userInfo.hash = server.getSocketHash(socket);
+ // 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
// prepare to notify channel peers
const newPeerList = server.findSockets({ channel: data.channel });
- const nicks = [];
+ const nicks = []; /* @legacy */
+ const users = [];
const joinAnnouncement = {
cmd: 'onlineAdd',
nick: userInfo.nick,
trip: userInfo.trip || 'null',
- hash: userInfo.userHash,
+ utype: userInfo.uType, /* @legacy */
+ hash: userInfo.hash,
level: userInfo.level,
+ userid: userInfo.userid,
+ channel: data.channel,
};
// send join announcement and prep online set
for (let i = 0, l = newPeerList.length; i < l; i += 1) {
server.reply(joinAnnouncement, newPeerList[i]);
- nicks.push(newPeerList[i].nick);
+ nicks.push(newPeerList[i].nick); /* @legacy */
+
+ users.push({
+ nick: newPeerList[i].nick,
+ trip: newPeerList[i].trip,
+ utype: newPeerList[i].uType, /* @legacy */
+ hash: newPeerList[i].userHash,
+ level: newPeerList[i].level,
+ userid: newPeerList[i].userid,
+ channel: data.channel,
+ isme: false,
+ });
}
// store user info
- socket.uType = userInfo.uType;
+ socket.uType = userInfo.uType; /* @legacy */
socket.nick = userInfo.nick;
- socket.channel = data.channel;
- socket.hash = userInfo.userHash;
+ socket.trip = userInfo.trip;
+ socket.channel = data.channel; /* @legacy */
+ socket.hash = userInfo.hash;
socket.level = userInfo.level;
- if (userInfo.trip !== null) socket.trip = userInfo.trip;
-
- nicks.push(socket.nick);
+ socket.userid = userInfo.userid;
+
+ nicks.push(socket.nick); /* @legacy */
+ users.push({
+ nick: socket.nick,
+ trip: socket.trip,
+ utype: socket.uType,
+ hash: socket.userHash,
+ level: socket.level,
+ userid: socket.userid,
+ channel: data.channel,
+ isme: true,
+ });
// reply with channel peer list
server.reply({
cmd: 'onlineSet',
- nicks,
+ nicks, /* @legacy */
+ users,
}, socket);
// stats are fun
diff --git a/server/src/commands/core/move.js b/server/src/commands/core/move.js
index 7eda88c..fdafab4 100644
--- a/server/src/commands/core/move.js
+++ b/server/src/commands/core/move.js
@@ -17,6 +17,13 @@ export async function run(core, server, socket, data) {
return true;
}
+ if (data.channel === '') {
+ return server.reply({
+ cmd: 'warn',
+ text: 'Cannot move to an empty channel.',
+ }, socket);
+ }
+
if (data.channel === socket.channel) {
// they are trying to rejoin the channel
return true;
@@ -53,6 +60,7 @@ export async function run(core, server, socket, data) {
}
}
+ // TODO: import function from join module
// broadcast join notice to new peers
const newPeerList = server.findSockets({ channel: data.channel });
const moveAnnouncement = {
@@ -82,10 +90,45 @@ export async function run(core, server, socket, data) {
return true;
}
+// module hook functions
+export function initHooks(server) {
+ server.registerHook('in', 'chat', this.moveCheck.bind(this), 29);
+}
+
+export function moveCheck(core, server, socket, payload) {
+ if (typeof payload.text !== 'string') {
+ return false;
+ }
+
+ if (payload.text.startsWith('/move ')) {
+ const input = payload.text.split(' ');
+
+ // If there is no channel target parameter
+ if (input[1] === undefined) {
+ server.reply({
+ cmd: 'warn',
+ text: 'Refer to `/help move` for instructions on how to use this command.',
+ }, socket);
+
+ return false;
+ }
+
+ this.run(core, server, socket, {
+ cmd: 'move',
+ channel: input[1],
+ });
+
+ return false;
+ }
+
+ return payload;
+}
+
export const requiredData = ['channel'];
export const info = {
name: 'move',
description: 'This will change your current channel to the new one provided',
usage: `
- API: { cmd: 'move', channel: '<target channel>' }`,
+ API: { cmd: 'move', channel: '<target channel>' }
+ Text: /move <new channel>`,
};
diff --git a/server/src/commands/core/ping.js b/server/src/commands/core/ping.js
index 7d8623d..6266f4c 100644
--- a/server/src/commands/core/ping.js
+++ b/server/src/commands/core/ping.js
@@ -3,9 +3,7 @@
*/
// module main
-export async function run() {
-
-}
+export async function run() { }
export const info = {
name: 'ping',
diff --git a/server/src/commands/core/session.js b/server/src/commands/core/session.js
new file mode 100644
index 0000000..677e9a4
--- /dev/null
+++ b/server/src/commands/core/session.js
@@ -0,0 +1,13 @@
+/*
+ Description: Create a new socket session or restore previous session
+*/
+
+// module main
+export async function run() { }
+
+export const info = {
+ name: 'session',
+ description: 'Restore previous state by session id or return new session id (currently unavailable)',
+ usage: `
+ API: { cmd: 'session', id: '<previous session>' }`
+};
diff --git a/server/src/commands/core/whisper.js b/server/src/commands/core/whisper.js
index 0c2e2d3..4424cd2 100644
--- a/server/src/commands/core/whisper.js
+++ b/server/src/commands/core/whisper.js
@@ -88,7 +88,7 @@ export function whisperCheck(core, server, socket, payload) {
return false;
}
- if (payload.text.startsWith('/whisper')) {
+ if (payload.text.startsWith('/whisper') || payload.text.startsWith('/w ')) {
const input = payload.text.split(' ');
// If there is no nickname target parameter
@@ -147,5 +147,6 @@ export const info = {
usage: `
API: { cmd: 'whisper', nick: '<target name>', text: '<text to whisper>' }
Text: /whisper <target name> <text to whisper>
+ Text: /w <target name> <text to whisper>
Alt Text: /r <text to whisper, this will auto reply to the last person who whispered to you>`,
};