euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit b5a81c738a18016bb70f823467c6c028dd8dde45 (patch)
parent f207c95c231a36c2ffdbcaee17e044b90dd8d164
Author: Alex Karle <alex@karle.co>
Date:   Thu, 23 Apr 2020 22:01:31 -0400

Euchre::Dealer: Add uptime and lifetime stats to /stats

Just for funsies :)

Diffstat:
Mlib/Euchre/Dealer.pm | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm @@ -68,6 +68,11 @@ our @EXPORT = qw( our %GAMES; our %PLAYERS; +# Stats +our $TOTAL_PLAYERS = 0; +our $TOTAL_GAMES = 0; +our $START_TIME = localtime(time); + # On ws connection, we add the player to %PLAYERS so that all # future handle_msg's know how to send messages back to the # player. No name or game_id known (yet). Player in lobby @@ -76,6 +81,8 @@ sub register_player { my $id = ''.$tx; $PLAYERS{$id} = { id => $id, ws => $tx, active => 1, joined => time }; print "Player $id has joined the server\n"; + + $TOTAL_PLAYERS++; } # finish handler to cleanup state @@ -181,6 +188,7 @@ sub join_game { phase => 'lobby', start_time => time, }; + $TOTAL_GAMES++; } my $game = $GAMES{$id}; @@ -646,6 +654,14 @@ sub stats { $msg .= "-----------------------------------------------------------\n"; $msg .= "$num_games\tGames\n"; + $msg .= "\n\nServer Stats\n"; + $msg .= "===========================================================\n"; + $msg .= "Server Start: $START_TIME\n"; + $msg .= "Lifetime Games: $TOTAL_GAMES\n"; + $msg .= "Lifetime Players: $TOTAL_PLAYERS\n"; + $msg .= "-----------------------------------------------------------\n"; + $msg .= "\n\nUptime: " . `uptime`; + return $msg; }