This commit is contained in:
Kim Ravn Hansen
2025-09-15 10:44:24 +02:00
parent 232a771980
commit 58c48fdc4b
17 changed files with 848 additions and 57 deletions

View File

@@ -2,12 +2,12 @@ import { PasswordPrompt } from "./passwordPrompt.js";
import { Player } from "../../models/player.js";
import { Scene } from "../scene.js";
import { UsernamePrompt } from "./usernamePrompt.js";
import { CreateUsernamePrompt } from "../playerCreation/createUsernamePrompt.js";
import { PlayerCreationScene } from "../playerCreation/playerCreationSene.js";
/** @property {Session} session */
export class AuthenticationScene extends Scene {
introText = [
"= Welcome", //
"= Welcome!", //
];
/** @type {Player} */
@@ -21,6 +21,7 @@ export class AuthenticationScene extends Scene {
/** @param {Player} player */
usernameAccepted(player) {
this.player = player;
this.session.sendSystemMessage("salt", player.salt);
this.show(PasswordPrompt);
}
@@ -28,6 +29,9 @@ export class AuthenticationScene extends Scene {
this.player.loggedIn = true;
this.session.player = this.player;
this.session.sendText(["= Success!", "((but I don't know what to do now...))"]);
return;
if (this.player.admin) {
this.session.setScene("new AdminJustLoggedInScene");
} else {
@@ -35,7 +39,12 @@ export class AuthenticationScene extends Scene {
}
}
createPlayer() {
scene.session.setScene(new PlayerCreationScene(this.scene));
/**
* User typed `:create`
*
* Create new player
*/
onColon__create() {
this.session.setScene(new PlayerCreationScene(this.session));
}
}

View File

@@ -1,6 +1,7 @@
import { Prompt } from "../prompt.js";
import * as security from "../../utils/security.js";
import { Config } from "../../config.js";
import { AuthenticationScene } from "./authenticationScene.js";
export class PasswordPrompt extends Prompt {
//
@@ -15,6 +16,11 @@ export class PasswordPrompt extends Prompt {
return this.scene.player;
}
/** @returns {AuthenticationScene} */
get scene() {
return this._scene;
}
onReply(text) {
//
// Check of the password is sane. This is both bad from a security point
@@ -70,10 +76,8 @@ export class PasswordPrompt extends Prompt {
return;
}
this.scene.passwordAccepted();
//
// Password was correct, go to main game
this.session.setState(new JustLoggedInState(this.session));
// this.scene.passwordAccepted();
this.scene.passwordAccepted();
}
}

View File

@@ -2,7 +2,6 @@ import { Player } from "../../models/player.js";
import { Prompt } from "../prompt.js";
import * as security from "../../utils/security.js";
import { gGame } from "../../models/globals.js";
import { PlayerCreationScene } from "../playerCreation/playerCreationSene.js";
import { Config } from "../../config.js";
import { AuthenticationScene } from "./authenticationScene.js";

View File

@@ -1,6 +1,4 @@
import { Session } from "../models/session.js";
import { PartyCreationState } from "./partyCreationState.js";
import { AwaitCommandsState } from "./awaitCommands.js";
const castle = `

View File

@@ -8,7 +8,7 @@ export class CreateUsernamePrompt extends Prompt {
//
promptText = [
"Enter your username", //
"((type *:help* for more info))" //
"((type *:help* for more info))", //
];
//
@@ -25,27 +25,31 @@ export class CreateUsernamePrompt extends Prompt {
// Let the client know that we're asking for a username
promptOptions = { username: true };
onReply(text) {
/**
* @returns {PlayerCreationScene}
*/
get scene() {
return this._scene;
}
onReply(username) {
//
// do basic syntax checks on usernames
if (!security.isUsernameSane(text)) {
console.info("Someone entered insane username: '%s'", text);
this.sendError(
"Incorrect username, try again.",
);
if (!security.isUsernameSane(username)) {
console.info("Someone entered insane username: '%s'", username);
this.sendError("Incorrect username, try again.");
this.execute();
return;
}
//
// try and fetch the player object from the game
const player = gGame.getPlayer(text);
const player = gGame.getPlayer(username);
//
// handle invalid username
if (player) {
console.info("Someone tried to create a user with an occupied username: '%s'", text);
console.info("Someone tried to create a user with an occupied username: '%s'", username);
this.sendError("Occupied, try something else");
this.execute();
return;
@@ -53,6 +57,6 @@ export class CreateUsernamePrompt extends Prompt {
//
// Tell daddy that we're done
this.scene.onUsernameAccepted(player);
this.scene.usernameAccepted(username);
}
}

View File

@@ -33,7 +33,9 @@ export class PlayerCreationScene extends Scene {
this.session.sendSystemMessage("salt", player.salt);
this.session.sendText(`Username _*${username}*_ is available, and I've reserved it for you :)`);
this.showPrompt("new passwordprompt");
//
this.session.sendError("TODO: create a createPasswordPrompt and display it.");
}
/**
@@ -47,10 +49,4 @@ export class PlayerCreationScene extends Scene {
this.session.sendText("*_Success_* ✅ You will now be asked to log in again, sorry for that ;)");
this.player.setPasswordHash(security.generateHash(this.password));
}
//
// User entered ":create"
onColon__create() {
this.scene.createPlayer();
}
}

View File

@@ -79,7 +79,7 @@ export class Scene {
//
// Default: we have no handler for the Foo command
if (property === undefined) {
this.session.sendError(`You cannot ${command.toUpperCase()} right now`, { verbatim: true }); // :foo ==> you cannot FOO right now
this.session.sendError(`You cannot ${command.toUpperCase()} right now`); // :foo ==> you cannot FOO right now
return;
}