LoginHandler.ts 446 Bytes
import { Connection } from "../../connection/Connection";
import { User } from "../../user/User";
import { LoginMessage } from "../types";
import { MessageHandler } from "./MessageHandler";

export class LoginHandler implements MessageHandler<LoginMessage> {
  public handle(connection: Connection, message: LoginMessage): void {
    connection.user = new User(message.username);
    console.log(`User ${message.username} has logged in!`);
  }
}