stuffAndThings
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
export const ENV = process.env.NODE_ENV || "prod";
|
||||
export const DEV = ENV === "dev";
|
||||
export const PROD =!DEV;
|
||||
export const PORT = process.env.PORT || 3000;
|
||||
@@ -122,7 +122,7 @@ export class ClientMessage {
|
||||
|
||||
/** Does this message contain a username-response from the client? */
|
||||
isUsernameResponse() {
|
||||
return this._attr.length === 3
|
||||
return this._attr.length === 4
|
||||
&& this._attr[0] === REPLY
|
||||
&& this._attr[1] === "username"
|
||||
&& typeof this._attr[2] === "string";
|
||||
@@ -130,7 +130,7 @@ export class ClientMessage {
|
||||
|
||||
/** Does this message contain a password-response from the client? */
|
||||
isPasswordResponse() {
|
||||
return this._attr.length === 3
|
||||
return this._attr.length === 4
|
||||
&& this._attr[0] === REPLY
|
||||
&& this._attr[1] === "password"
|
||||
&& typeof this._attr[2] === "string";
|
||||
@@ -147,11 +147,11 @@ export class ClientMessage {
|
||||
|
||||
/** @returns {boolean} is this a debug message? */
|
||||
isDebug() {
|
||||
return this._attr.length == 2 && this._attr[0] === DEBUG;
|
||||
return this._attr.length === 2 && this._attr[0] === DEBUG;
|
||||
}
|
||||
|
||||
isIntegerResponse() {
|
||||
return this._attr.length === 3
|
||||
return this._attr.length === 4
|
||||
&& this._attr[0] === REPLY
|
||||
&& this._attr[1] === "integer"
|
||||
&& (typeof this._attr[2] === "string" || typeof this._attr[2] === "number")
|
||||
@@ -167,10 +167,6 @@ export class ClientMessage {
|
||||
return Number.parseInt(this._attr[2]);
|
||||
}
|
||||
|
||||
get debugInfo() {
|
||||
return this.isDebug() ? this._attr[1] : undefined;
|
||||
}
|
||||
|
||||
/** @returns {string|false} Get the username stored in this message */
|
||||
get username() {
|
||||
return this.isUsernameResponse() ? this._attr[2] : false;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { randomBytes, pbkdf2Sync } from "node:crypto";
|
||||
import { DEV } from "./config.js";
|
||||
import { Config } from "../config.js";
|
||||
|
||||
|
||||
// Settings (tune as needed)
|
||||
const ITERATIONS = 1000;
|
||||
const KEYLEN = 32; // 32-bit hash
|
||||
const DIGEST = "sha256";
|
||||
const DEV = process.env.NODE_ENV === "dev";
|
||||
|
||||
/**
|
||||
* Generate a hash from a plaintext password.
|
||||
@@ -28,14 +30,14 @@ export function verifyPassword(password_candidate, stored_password_hash) {
|
||||
const [iterations, salt, hash] = stored_password_hash.split(":");
|
||||
const derived = pbkdf2Sync(password_candidate, salt, Number(iterations), KEYLEN, DIGEST).toString("hex");
|
||||
const success = hash === derived;
|
||||
if (DEV) {
|
||||
if (Config.dev || true) {
|
||||
console.debug(
|
||||
"Verifying password:\n" +
|
||||
" Input : %s\n" +
|
||||
" Stored : %s\n" +
|
||||
" Given : %s\n" +
|
||||
" Derived : %s\n" +
|
||||
" Success : %s",
|
||||
" Input : %s (the password as it was sent to us by the client)\n" +
|
||||
" Given : %s (the input password hashed by us (not necessary for validation))\n" +
|
||||
" Stored : %s (the password hash we have on file for the player)\n" +
|
||||
" Derived : %s (the hashed version of the input password)\n" +
|
||||
" Verified : %s (was the password valid)",
|
||||
password_candidate,
|
||||
generateHash(password_candidate),
|
||||
stored_password_hash,
|
||||
|
||||
@@ -182,7 +182,7 @@ export function frameText(text, options) {
|
||||
+ options.hMargin * 2;
|
||||
|
||||
// get the frame characters from the frameType.
|
||||
const [
|
||||
let [
|
||||
fNorth, // horizontal frame top lines
|
||||
fSouth, // horizontal frame bottom lines
|
||||
fWest, // vertical frame lines on the left side
|
||||
@@ -192,6 +192,14 @@ export function frameText(text, options) {
|
||||
fSouthWest, // lower left frame corner
|
||||
fSouthEast, // lower right frame corner
|
||||
] = options.frameChars.split("");
|
||||
if (fNorth === "§") { fNorth = ""; }
|
||||
if (fSouth === "§") { fSouth = ""; }
|
||||
if (fEast === "§") { fEast = ""; }
|
||||
if (fWest === "§") { fWest = ""; }
|
||||
if (fNorthEast === "§") { fNorthEast = ""; }
|
||||
if (fSouthEast === "§") { fSouthEast = ""; }
|
||||
if (fNorthWest === "§") { fNorthWest = ""; }
|
||||
if (fSouthWest === "§") { fSouthWest = ""; }
|
||||
|
||||
let output = "";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user