prevent sending or logging of empty chats

This commit is contained in:
ari melody 2024-08-30 12:33:40 +01:00
parent 5c936df3f6
commit cdaa7c678d
Signed by: ari
GPG key ID: CF99829C92678188
2 changed files with 2 additions and 1 deletions

View file

@ -315,6 +315,7 @@ composeBox.addEventListener("keypress", event => {
}); });
function sendChat(msg) { function sendChat(msg) {
if (msg === "") return;
setTimeout(() => { setTimeout(() => {
if (!ws) return; if (!ws) return;
ws.send(JSON.stringify({ ws.send(JSON.stringify({

View file

@ -131,12 +131,12 @@ export function init(http_server) {
case "chat": case "chat":
if (data.msg === undefined) if (data.msg === undefined)
throw new Error("Attempted chat with no message"); throw new Error("Attempted chat with no message");
Log.info('<' + socket.player.name + '> ' + data.msg)
data.msg = data.msg.replaceAll("<", "&lt;") data.msg = data.msg.replaceAll("<", "&lt;")
data.msg = data.msg.replaceAll(">", "&gt;") data.msg = data.msg.replaceAll(">", "&gt;")
data.msg = data.msg.replaceAll("\n", ""); data.msg = data.msg.replaceAll("\n", "");
data.msg = data.msg.trim(); data.msg = data.msg.trim();
if (data.msg == "") return; if (data.msg == "") return;
Log.info('<' + socket.player.name + '> ' + data.msg)
clients.forEach(client => { clients.forEach(client => {
client.send(JSON.stringify({ client.send(JSON.stringify({
type: "chat", type: "chat",