Updated README, fixed a couple bugs

This commit is contained in:
2021-03-18 04:38:44 +11:00
parent e60535c525
commit 7333fa4211
2 changed files with 20 additions and 12 deletions
+12 -12
View File
@@ -8,23 +8,23 @@ TODO: document the chat server setup
# API # API
TODO: document the chat server api This server uses socket.io for communication. Be aware that every chat message requires a valid JWT. See the [auth-server](https://github.com/krgamestudios/auth-server) for details.
socket.io
The event types are as follows:
``` ```
on connection -> wait for "create user" event Server:
on 'connection' -> Server waits for "open chat" event to continue
on 'error' -> Server emits and logs an error
on 'open chat' -> Preps the server for your messages, places you in the room 'general'
on 'message' -> Server broadcasts to all other users in your room
on 'disconnect' -> Server will no longer accept your messages
on create user -> join #general as @username; socket.roomName = 'general'; socket.username = 'username'; accept only JWTs, send "backlog" message
on message -> socket.to(socket.roomName).emit('message'); //scan for commands via middleware Chat Commands:
/room name -> Move to the room "name"
on disconnect -> cleanup etc. /mute username minutes [reason] -> Mutes a specified user for X minutes; only available to admins or mods
/unmute username - Unmutes the previously muted user; only available to admins or mods
regular user API:
/join #room -> room is set to #room, join and leave commands are issued (this can also "create" new rooms)
/whisper @username -> disallow if roomName is different between two users
``` ```
+8
View File
@@ -229,6 +229,11 @@ const executeCommand = (io, socket, command) => {
} }
case '/unmute': { case '/unmute': {
if (socket.user.privilege != 'administrator' && socket.user.privilege != 'moderator') {
socket.emit('message', { emphasis: true, text: '/unmute is only available to admins and mods' });
break;
}
const arr = command.split(' '); const arr = command.split(' ');
arr.shift(); // /mute arr.shift(); // /mute
const username = arr.shift(); const username = arr.shift();
@@ -237,6 +242,9 @@ const executeCommand = (io, socket, command) => {
where: { where: {
username: { username: {
[Op.eq]: username [Op.eq]: username
},
until: {
[Op.gt]: new Date(Date.now())
} }
} }
}); });