Binato/server/packets/PrivateMessage.ts

23 lines
849 B
TypeScript
Raw Normal View History

2023-09-10 12:59:22 +01:00
import MessageData from "../interfaces/MessageData";
import Shared from "../objects/Shared";
import PrivateChannel from "../objects/PrivateChannel";
import User from "../objects/User";
2023-08-20 13:03:01 +01:00
2023-09-10 12:59:22 +01:00
export default function PrivateMessage(user:User, message:MessageData) {
2023-08-20 13:03:01 +01:00
const shared:Shared = user.shared;
const sendingTo = shared.users.getByUsername(message.target);
if (!(sendingTo instanceof User)) {
return;
}
let channel = shared.privateChatManager.GetChannelByName(`${user.username}${sendingTo.username}`);
if (!(channel instanceof PrivateChannel)) {
// Try it the other way around
channel = shared.privateChatManager.GetChannelByName(`${sendingTo.username}${user.username}`);
}
if (!(channel instanceof PrivateChannel)) {
channel = shared.privateChatManager.AddChannel(user, sendingTo);
}
channel.SendMessage(user, message.message);
}