Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:

- Added the required column `muted` to the `private_chat` table without a default value. This is not possible if the table is not empty.
- Added the required column `muted` to the `public_chat` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE `private_chat` ADD COLUMN `muted` BOOLEAN NOT NULL;

-- AlterTable
ALTER TABLE `public_chat` ADD COLUMN `muted` BOOLEAN NOT NULL;
2 changes: 2 additions & 0 deletions prisma/multiworld/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ model public_chat {
timestamp DateTime
coord Int
message String
muted Boolean
}

model private_chat {
Expand All @@ -219,6 +220,7 @@ model private_chat {
coord Int
to_account_id Int
message String
muted Boolean
}

model report {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Warnings:

- Added the required column `muted` to the `private_chat` table without a default value. This is not possible if the table is not empty.
- Added the required column `muted` to the `public_chat` table without a default value. This is not possible if the table is not empty.

*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_private_chat" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"account_id" INTEGER NOT NULL,
"profile" TEXT NOT NULL,
"timestamp" DATETIME NOT NULL,
"coord" INTEGER NOT NULL,
"to_account_id" INTEGER NOT NULL,
"message" TEXT NOT NULL,
"muted" BOOLEAN NOT NULL
);
INSERT INTO "new_private_chat" ("account_id", "coord", "id", "message", "profile", "timestamp", "to_account_id") SELECT "account_id", "coord", "id", "message", "profile", "timestamp", "to_account_id" FROM "private_chat";
DROP TABLE "private_chat";
ALTER TABLE "new_private_chat" RENAME TO "private_chat";
CREATE TABLE "new_public_chat" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"account_id" INTEGER NOT NULL,
"profile" TEXT NOT NULL,
"world" INTEGER NOT NULL,
"timestamp" DATETIME NOT NULL,
"coord" INTEGER NOT NULL,
"message" TEXT NOT NULL,
"muted" BOOLEAN NOT NULL
);
INSERT INTO "new_public_chat" ("account_id", "coord", "id", "message", "profile", "timestamp", "world") SELECT "account_id", "coord", "id", "message", "profile", "timestamp", "world" FROM "public_chat";
DROP TABLE "public_chat";
ALTER TABLE "new_public_chat" RENAME TO "public_chat";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
2 changes: 2 additions & 0 deletions prisma/singleworld/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ model public_chat {
timestamp DateTime
coord Int
message String
muted Boolean
}

model private_chat {
Expand All @@ -220,6 +221,7 @@ model private_chat {
coord Int
to_account_id Int
message String
muted Boolean
}

model report {
Expand Down
2 changes: 2 additions & 0 deletions src/db/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export type private_chat = {
coord: number;
to_account_id: number;
message: string;
muted: number;
};
export type public_chat = {
id: Generated<number>;
Expand All @@ -170,6 +171,7 @@ export type public_chat = {
timestamp: string;
coord: number;
message: string;
muted: number;
};
export type report = {
id: Generated<number>;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/World.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ class World {
}
}

sendPrivateMessage(player: Player, targetUsername37: bigint, message: string): void {
attemptPrivateMessage(player: Player, targetUsername37: bigint, message: string): void {
//printDebug(`[World] sendPrivateMessage => player: ${player.username}, target: ${targetUsername37} (${fromBase37(targetUsername37)}), message: '${message}'`);

this.friendThread.postMessage({
Expand Down
11 changes: 5 additions & 6 deletions src/network/game/client/handler/MessagePrivateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export default class MessagePrivateHandler extends MessageHandler<MessagePrivate
return false;
}

if (player.muted_until !== null && player.muted_until > new Date()) {
// todo: do we still log their attempt to chat?
return false;
}

if (fromBase37(username) === 'invalid_name') {
World.notifyPlayerBan('automated', player.username, Date.now() + 172800000);
return false;
Expand All @@ -28,10 +23,14 @@ export default class MessagePrivateHandler extends MessageHandler<MessagePrivate
const buf: Packet = Packet.alloc(0);
buf.pdata(input, 0, input.length);
buf.pos = 0;
World.sendPrivateMessage(player, username, WordPack.unpack(buf, input.length));
World.attemptPrivateMessage(player, username, WordPack.unpack(buf, input.length));
buf.release();

player.socialProtect = true;

if (player.muted_until !== null && player.muted_until > new Date()) {
return false;
}
return true;
}
}
11 changes: 6 additions & 5 deletions src/network/game/client/handler/MessagePublicHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Packet from '#/io/Packet.js';
import MessageHandler from '#/network/game/client/handler/MessageHandler.js';
import MessagePublic from '#/network/game/client/model/MessagePublic.js';
import WordPack from '#/wordenc/WordPack.js';
import World from '#/engine/World.js';


export default class MessagePublicHandler extends MessageHandler<MessagePublic> {
Expand All @@ -16,17 +17,17 @@ export default class MessagePublicHandler extends MessageHandler<MessagePublic>
return false;
}

if (player.muted_until !== null && player.muted_until > new Date()) {
// todo: do we still log their attempt to chat?
return false;
}

const buf: Packet = Packet.alloc(0);
buf.pdata(input, 0, input.length);
buf.pos = 0;
const unpack: string = WordPack.unpack(buf, input.length);
buf.release();

if (player.muted_until !== null && player.muted_until > new Date()) {
World.logPublicChat(player, unpack);
return false;
}

player.messageColor = color;
player.messageEffect = effect;
player.messageType = Math.min(player.staffModLevel, 2);
Expand Down
12 changes: 9 additions & 3 deletions src/server/friend/FriendServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export class FriendServer {

const from = await db.selectFrom('account').selectAll().where('username', '=', fromBase37(username37)).executeTakeFirstOrThrow();
const to = await db.selectFrom('account').selectAll().where('username', '=', fromBase37(targetUsername37)).executeTakeFirstOrThrow();
const muted = from.muted_until !== null && new Date(from.muted_until) > new Date() ? 1 : 0;

await db
.insertInto('private_chat')
Expand All @@ -283,15 +284,19 @@ export class FriendServer {
to_account_id: to.id,
timestamp: toDbDate(Date.now()),
coord: message.coord,
message: chat
message: chat,
muted
})
.execute();

await this.sendPrivateMessage(profile, username37, staffLvl, pmId, targetUsername37, chat);
if (!muted) {
await this.sendPrivateMessage(profile, username37, staffLvl, pmId, targetUsername37, chat);
}
} else if (type === FriendsClientOpcodes.PUBLIC_CHAT_LOG) {
const { nodeId, nodeTime, profile, username, coord, chat } = message;

const from = await db.selectFrom('account').selectAll().where('username', '=', username).executeTakeFirstOrThrow();
const muted = from.muted_until !== null && new Date(from.muted_until) > new Date() ? 1 : 0;

await db
.insertInto('public_chat')
Expand All @@ -302,7 +307,8 @@ export class FriendServer {

timestamp: toDbDate(nodeTime),
coord,
message: chat
message: chat,
muted
})
.execute();
} else if (type === FriendsClientOpcodes.RELAY_MUTE) {
Expand Down