stuff
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Session } from "../session.js";
|
||||
import * as msg from "../../utils/messages.js";
|
||||
import * as security from "../../utils/security.js";
|
||||
import { JustLoggedInState } from "./justLoggedIn.js";
|
||||
import { CreatePlayerState } from "./createPlayer.js";
|
||||
import { JustLoggedInState } from "./justLoggedIn.js";
|
||||
import { Session } from "../session.js";
|
||||
|
||||
const STATE_EXPECT_USERNAME = "promptUsername";
|
||||
const STATE_EXPECT_PASSWORD = "promptPassword";
|
||||
@@ -43,7 +43,7 @@ export class AuthState {
|
||||
}
|
||||
|
||||
if (this.subState === STATE_EXPECT_PASSWORD) {
|
||||
this.receivePassword(message)
|
||||
this.receivePassword(message);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,11 +81,7 @@ export class AuthState {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.session.game.players.size === 0) {
|
||||
console.error("there are no players registered");
|
||||
}
|
||||
|
||||
const player = this.session.game.players.get(message.username);
|
||||
const player = this.session.game.getPlayer(message.username);
|
||||
|
||||
//
|
||||
// handle invalid username
|
||||
@@ -142,9 +138,13 @@ export class AuthState {
|
||||
if (!security.verifyPassword(message.password, this.session.player.passwordHash)) {
|
||||
this.session.sendError("Incorrect password!");
|
||||
this.session.sendPrompt("password", PASSWORD_PROMPT);
|
||||
this.session.player.failedPasswordsSinceLastLogin++;
|
||||
return;
|
||||
}
|
||||
|
||||
this.session.player.lastSucessfulLoginAt = new Date();
|
||||
this.session.player.failedPasswordsSinceLastLogin = 0;
|
||||
|
||||
//
|
||||
// Password correct, check if player is an admin
|
||||
if (this.session.player.isAdmin) {
|
||||
|
||||
0
server/models/states/awaitCommands.js
Normal file → Executable file
0
server/models/states/awaitCommands.js
Normal file → Executable file
@@ -1,7 +1,5 @@
|
||||
import figlet from "figlet";
|
||||
import { Session } from "../session.js";
|
||||
import WebSocket from "ws";
|
||||
import { AuthState } from "./auth.js";
|
||||
import { ClientMessage } from "../../utils/messages.js";
|
||||
import { PARTY_MAX_SIZE } from "../../config.js";
|
||||
import { frameText } from "../../utils/tui.js";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import WebSocket from "ws";
|
||||
import { Session } from "../session.js";
|
||||
import * as msg from "../../utils/messages.js";
|
||||
import * as security from "../../utils/security.js";
|
||||
@@ -79,11 +78,11 @@ export class CreatePlayerState {
|
||||
return;
|
||||
}
|
||||
|
||||
const taken = this.session.game.players.has(message.username);
|
||||
const player = this.session.game.createPlayer(message.username);
|
||||
|
||||
//
|
||||
// handle taken/occupied username
|
||||
if (taken) {
|
||||
if (player === false) {
|
||||
// Telling the user right away that the username is taken can
|
||||
// lead to data leeching. But fukkit.
|
||||
|
||||
@@ -92,18 +91,9 @@ export class CreatePlayerState {
|
||||
return;
|
||||
}
|
||||
|
||||
this._player = new Player(message.username, undefined);
|
||||
this._player = player;
|
||||
|
||||
// _____ _
|
||||
// | ___(_)_ ___ __ ___ ___
|
||||
// | |_ | \ \/ / '_ ` _ \ / _ \
|
||||
// | _| | |> <| | | | | | __/
|
||||
// |_| |_/_/\_\_| |_| |_|\___|
|
||||
//
|
||||
// 1. Add mutex on the players table to avoid race conditions
|
||||
// 2. Prune "dead" players (players with 0 logins) after a short while
|
||||
this.session.game.players.set(message.username, this._player);
|
||||
this.session.sendMessage("Username available");
|
||||
this.session.sendMessage("Username available 👌");
|
||||
this.session.sendMessage(`Username _*${message.username}*_ is available, and I've reserved it for you :)`);
|
||||
this.session.sendPrompt("password", PASSWORD_PROMPT);
|
||||
this.setMessageHandler(this.receivePassword);
|
||||
|
||||
Reference in New Issue
Block a user