From 71492a73b6f57ac92feb52b5b19763c861d1b741 Mon Sep 17 00:00:00 2001 From: Conor Date: Thu, 28 Dec 2023 15:12:11 -0500 Subject: [PATCH] * add info log when poll completes --- server/src/state/gameState.ts | 6 +++--- server/src/state/pollService.ts | 15 ++++++++++----- server/src/state/rooms.ts | 10 +++++----- server/src/types/result.ts | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/server/src/state/gameState.ts b/server/src/state/gameState.ts index 3fd8a48..60dae24 100644 --- a/server/src/state/gameState.ts +++ b/server/src/state/gameState.ts @@ -3,7 +3,7 @@ import { getCorrections, stringMatch } from './matchUtils'; import { PollName, PollService } from './pollService'; import logger from '../logger/logger'; import { Player as RoomPlayer, Room } from './rooms'; -import { Err, Info, Ok, Result, Success, VoidResult, Warning } from '../types/result'; +import { Err, Info, Ok, Result, Success, VoidResult, Warn } from '../types/result'; import { ConfigurableOptions, defaultOptions, getConfigurableOptionsSchema, Options } from './options'; import { Match, MidgameConnectData, Responses, SelectionType, Stage } from '../types/stateTypes'; @@ -165,11 +165,11 @@ export class GameState { acceptPromptResponse(id: string, response: string): Result<{ response: string }> { if (!response) { - return Warning('emptyResponse'); + return Warn('emptyResponse'); } response = response.trim().normalize().trim(); if (!response) { - return Warning('emptyResponse'); + return Warn('emptyResponse'); } if (this.stage === Stage.Response) { const playerState = this.players.find((player) => player.id === id); diff --git a/server/src/state/pollService.ts b/server/src/state/pollService.ts index 6c5fc38..94a8bd5 100644 --- a/server/src/state/pollService.ts +++ b/server/src/state/pollService.ts @@ -1,6 +1,7 @@ import { GameState } from './gameState'; -import { Err, Ok, Result } from '../types/result'; +import { Err, Ok, Result, Warn } from '../types/result'; import { Stage } from '../types/stateTypes'; +import logger from '../logger/logger'; export enum PollName { SkipPrompt = 'skipPrompt', @@ -48,7 +49,7 @@ export class PollService { acceptVote(pollName: PollName, id: string, stage: Stage): Result<{ count: number; next: boolean }> { const poll = this.polls.get(pollName); if (!poll) { - return Err(`noPoll${pollName}`); + return Warn(`noPoll${pollName}`); } if (poll.stage && stage !== poll.stage) { return Err('invalidStage'); @@ -86,7 +87,7 @@ export class PollService { } _cbIfComplete(poll: Poll, pollName: PollName): boolean { - if (this._complete(poll)) { + if (this._complete(poll, pollName)) { this.clearPoll(pollName); poll!.completeCb(); return true; @@ -94,9 +95,13 @@ export class PollService { return false; } - _complete(poll: Poll) { + _complete(poll: Poll, pollName: PollName) { const threshold = Math.ceil(this.gameState.numVoters(poll.exclude) * poll.majorityPercent); - return this._countVotes(poll) >= threshold; + if (this._countVotes(poll) >= threshold) { + logger.info(`(pollService) ${pollName} completed`); + return true; + } + return false; } _nextComplete(poll: Poll) { diff --git a/server/src/state/rooms.ts b/server/src/state/rooms.ts index b145780..69a2d3c 100644 --- a/server/src/state/rooms.ts +++ b/server/src/state/rooms.ts @@ -1,7 +1,7 @@ import { GameState } from './gameState'; import parameterize from 'parameterize'; import locale from 'locale'; -import { Info, isErr, Ok, Result, Success, VoidResult, Warning } from '../types/result'; +import { Info, isErr, Ok, Result, Success, VoidResult, Warn } from '../types/result'; export type Player = { id: string; @@ -27,14 +27,14 @@ const playerRoom: Record = {}; const rooms: { [key: string]: Room } = {}; function isValidName(name: string): VoidResult { - if (name.length < 2) return Warning('shortName'); - if (name.length > 20) return Warning('longName'); + if (name.length < 2) return Warn('shortName'); + if (name.length > 20) return Warn('longName'); return Success(); } function isValidRoomName(name: string): VoidResult { - if (name.length < 2) return Warning('shortRoomName'); - if (name.length > 15) return Warning('longRoomName'); + if (name.length < 2) return Warn('shortRoomName'); + if (name.length > 15) return Warn('longRoomName'); if (rooms[name]) return Info('roomTaken'); return Success(); } diff --git a/server/src/types/result.ts b/server/src/types/result.ts index c567c41..48add44 100644 --- a/server/src/types/result.ts +++ b/server/src/types/result.ts @@ -38,7 +38,7 @@ class ResultErr { } // Construct ResultErr with given log level -export function Warning(message: string): ResultErr { +export function Warn(message: string): ResultErr { return new ResultErr(message, 'warning'); }