Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
251319e5d7 |
@@ -1,3 +1,18 @@
|
|||||||
|
#!/usr/bin/env perlcritic
|
||||||
|
# Задействованные модули критика:
|
||||||
|
#
|
||||||
|
# Perl::Critic::More
|
||||||
|
# Perl::Critic::Pulp
|
||||||
|
# Perl::Critic::TooMuchCode
|
||||||
|
# Perl::Critic::Lax
|
||||||
|
# Perl::Critic::CognitiveComplexity
|
||||||
|
# Perl::Critic::Policy::CompileTime
|
||||||
|
# Perl::Critic::Policy::ProhibitImplicitImport
|
||||||
|
# Perl::Critic::Policy::Dynamic::NoIndirect
|
||||||
|
# Perl::Critic::StricterSubs
|
||||||
|
# Perl::Critic::Policy::ProhibitImplicitImport
|
||||||
|
# Perl::Critic::Policy::CodeLayout::RequireUseUTF8
|
||||||
|
|
||||||
[-CodeLayout::RequireTidyCode]
|
[-CodeLayout::RequireTidyCode]
|
||||||
[-ValuesAndExpressions::ProhibitMagicNumbers]
|
[-ValuesAndExpressions::ProhibitMagicNumbers]
|
||||||
[-ControlStructures::ProhibitUnlessBlocks]
|
[-ControlStructures::ProhibitUnlessBlocks]
|
||||||
@@ -15,3 +30,13 @@
|
|||||||
[-RegularExpressions::ProhibitEscapedMetacharacters]
|
[-RegularExpressions::ProhibitEscapedMetacharacters]
|
||||||
[-InputOutput::RequireBriefOpen]
|
[-InputOutput::RequireBriefOpen]
|
||||||
[-Modules::ProhibitExcessMainComplexity]
|
[-Modules::ProhibitExcessMainComplexity]
|
||||||
|
[-Editor::RequireEmacsFileVariables]
|
||||||
|
[-TooMuchCode::ProhibitUnnecessaryUTF8Pragma]
|
||||||
|
[-ValuesAndExpressions::RequireConstantOnLeftSideOfEquality]
|
||||||
|
[-Lax::RequireConstantOnLeftSideOfEquality::ExceptEq]
|
||||||
|
[-Lax::ProhibitEmptyQuotes::ExceptAsFallback]
|
||||||
|
[-TooMuchCode::ProhibitDuplicateLiteral]
|
||||||
|
[-CodeLayout::RequireASCII]
|
||||||
|
[-ErrorHandling::RequireUseOfExceptions]
|
||||||
|
[-Miscellanea::ProhibitUnrestrictedNoCritic]
|
||||||
|
[-ValuesAndExpressions::RestrictLongStrings]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
@@ -29,9 +29,10 @@ no Cwd;
|
|||||||
use Cwd::utf8 qw (chdir abs_path);
|
use Cwd::utf8 qw (chdir abs_path);
|
||||||
use File::Basename qw (basename dirname);
|
use File::Basename qw (basename dirname);
|
||||||
use File::Path qw (make_path);
|
use File::Path qw (make_path);
|
||||||
|
use File::Spec ();
|
||||||
use Log::Any qw ($log);
|
use Log::Any qw ($log);
|
||||||
use Log::Any::Adapter;
|
use Log::Any::Adapter ();
|
||||||
use Log::Any::For::Std;
|
use Log::Any::For::Std ();
|
||||||
use POSIX qw (setgid setuid setsid);
|
use POSIX qw (setgid setuid setsid);
|
||||||
|
|
||||||
use Conf qw (LoadConf);
|
use Conf qw (LoadConf);
|
||||||
@@ -70,8 +71,8 @@ if ($UID == 0) {
|
|||||||
make_path (
|
make_path (
|
||||||
$piddir, {
|
$piddir, {
|
||||||
uid => $uid,
|
uid => $uid,
|
||||||
group => $gid
|
group => $gid,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +83,8 @@ if ($UID == 0) {
|
|||||||
make_path (
|
make_path (
|
||||||
$logdir, {
|
$logdir, {
|
||||||
uid => $uid,
|
uid => $uid,
|
||||||
group => $gid
|
group => $gid,
|
||||||
}
|
},
|
||||||
) or die "Unable to create $logdir: $OS_ERROR\n";
|
) or die "Unable to create $logdir: $OS_ERROR\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,14 +104,14 @@ if (defined $logfile) {
|
|||||||
# verbosity paticulary for CHI.
|
# verbosity paticulary for CHI.
|
||||||
Log::Any::Adapter->set (
|
Log::Any::Adapter->set (
|
||||||
{
|
{
|
||||||
category => 'CHI::Driver'
|
category => 'CHI::Driver',
|
||||||
},
|
},
|
||||||
'File',
|
'File',
|
||||||
$logfile,
|
$logfile,
|
||||||
log_level => 'warn'
|
log_level => 'warn',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Log::Any::Adapter->set ('File', '/dev/null');
|
Log::Any::Adapter->set ('File', File::Spec->devnull);
|
||||||
}
|
}
|
||||||
|
|
||||||
# По-умолчанию, демонизируемся, если явно не указано, что этого делать не надо
|
# По-умолчанию, демонизируемся, если явно не указано, что этого делать не надо
|
||||||
@@ -126,7 +127,7 @@ my $apath = abs_path $PROGRAM_NAME;
|
|||||||
unless (defined $apath) {
|
unless (defined $apath) {
|
||||||
$log->fatal ("[FATAL] Unable to get abs_path: $OS_ERROR\n");
|
$log->fatal ("[FATAL] Unable to get abs_path: $OS_ERROR\n");
|
||||||
exit 1;
|
exit 1;
|
||||||
};
|
}
|
||||||
|
|
||||||
my $pidfile = sprintf '%s/%s.pid', $piddir, basename $apath;
|
my $pidfile = sprintf '%s/%s.pid', $piddir, basename $apath;
|
||||||
$log->info ("[INFO] Creating pidfile at $pidfile");
|
$log->info ("[INFO] Creating pidfile at $pidfile");
|
||||||
@@ -152,7 +153,7 @@ $PROGRAM_NAME = abs_path $PROGRAM_NAME; ## no critic (Variables::Re
|
|||||||
# И запустим уже наш сервис
|
# И запустим уже наш сервис
|
||||||
RunGames ();
|
RunGames ();
|
||||||
|
|
||||||
if (-f $pidfile) {
|
if (-e $pidfile) {
|
||||||
unlink $pidfile;
|
unlink $pidfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,11 +161,11 @@ exit 0;
|
|||||||
|
|
||||||
sub daemonize {
|
sub daemonize {
|
||||||
__fork ();
|
__fork ();
|
||||||
POSIX::setsid ();
|
setsid ();
|
||||||
open STDIN, '<', '/dev/null'; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
open STDIN, '<', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
||||||
# we handle STDOUT && STDERR via Log::Any::For::Std, so do not close them explicitly
|
# we handle STDOUT && STDERR via Log::Any::For::Std, so do not close them explicitly
|
||||||
#open STDOUT, '>', '/dev/null'; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
#open STDOUT, '>', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
||||||
#open STDERR, '>', '/dev/null'; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
#open STDERR, '>', File::Spec->devnull; ## no critic (InputOutput::RequireCheckedSyscalls, InputOutput::RequireCheckedOpen)
|
||||||
__fork ();
|
__fork ();
|
||||||
umask 0;
|
umask 0;
|
||||||
return;
|
return;
|
||||||
@@ -188,7 +189,7 @@ sub __fork {
|
|||||||
sub __signal_handler {
|
sub __signal_handler {
|
||||||
$log->info ("[INFO] Caught a signal $OS_ERROR");
|
$log->info ("[INFO] Caught a signal $OS_ERROR");
|
||||||
|
|
||||||
if (-f $pidfile) {
|
if (-e $pidfile) {
|
||||||
unlink $pidfile;
|
unlink $pidfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
|
|||||||
2
cpanfile
2
cpanfile
@@ -1,3 +1,4 @@
|
|||||||
|
## no critic
|
||||||
requires 'Carp', '==1.50';
|
requires 'Carp', '==1.50';
|
||||||
requires 'Clone', '==0.45';
|
requires 'Clone', '==0.45';
|
||||||
requires 'Cwd::utf8', '==0.011';
|
requires 'Cwd::utf8', '==0.011';
|
||||||
@@ -10,6 +11,7 @@ requires 'English', '0';
|
|||||||
requires 'Exporter', '==5.74';
|
requires 'Exporter', '==5.74';
|
||||||
requires 'File::Basename', '0';
|
requires 'File::Basename', '0';
|
||||||
requires 'File::Path', '==2.18';
|
requires 'File::Path', '==2.18';
|
||||||
|
requires 'File::Spec', '==3.75';
|
||||||
requires 'JSON::XS', '==4.03';
|
requires 'JSON::XS', '==4.03';
|
||||||
requires 'Log::Any', '==1.710';
|
requires 'Log::Any', '==1.710';
|
||||||
requires 'Log::Any::Adapter', '==1.710';
|
requires 'Log::Any::Adapter', '==1.710';
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package Conf;
|
package Conf;
|
||||||
# loads config
|
# loads config
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
use open qw (:std :utf8);
|
use open qw (:std :utf8);
|
||||||
use English qw ( -no_match_vars );
|
use English qw ( -no_match_vars );
|
||||||
use Encode qw (encode);
|
use Encode qw (encode);
|
||||||
use JSON::XS;
|
use JSON::XS ();
|
||||||
|
|
||||||
use version; our $VERSION = qw (1.0);
|
use version; our $VERSION = qw (1.0);
|
||||||
use Exporter qw (import);
|
use Exporter qw (import);
|
||||||
|
|||||||
27
lib/Games.pm
27
lib/Games.pm
@@ -1,7 +1,7 @@
|
|||||||
package Games;
|
package Games;
|
||||||
|
|
||||||
# Общие модули - синтаксис, кодировки итд
|
# Общие модули - синтаксис, кодировки итд
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
@@ -9,14 +9,13 @@ use open qw (:std :utf8);
|
|||||||
|
|
||||||
# Модули для работы приложения
|
# Модули для работы приложения
|
||||||
use Clone qw (clone);
|
use Clone qw (clone);
|
||||||
use Data::Dumper;
|
use Data::Dumper qw (Dumper);
|
||||||
use Log::Any qw ($log);
|
use Log::Any qw ($log);
|
||||||
use Math::Random::Secure qw (irand);
|
|
||||||
# Чтобы "уж точно" использовать hiredis-биндинги, загрузим этот модуль перед Mojo::Redis
|
# Чтобы "уж точно" использовать hiredis-биндинги, загрузим этот модуль перед Mojo::Redis
|
||||||
use Protocol::Redis::XS;
|
use Protocol::Redis::XS ();
|
||||||
use Mojo::Redis;
|
use Mojo::Redis ();
|
||||||
use Mojo::IOLoop;
|
use Mojo::IOLoop ();
|
||||||
use Mojo::IOLoop::Signal;
|
use Mojo::IOLoop::Signal ();
|
||||||
|
|
||||||
use Conf qw (LoadConf);
|
use Conf qw (LoadConf);
|
||||||
use Games::Archeologist qw (Dig);
|
use Games::Archeologist qw (Dig);
|
||||||
@@ -99,7 +98,7 @@ my $parse_message = sub {
|
|||||||
|
|
||||||
if (defined $answer->{message}) {
|
if (defined $answer->{message}) {
|
||||||
$self->json ($send_to)->notify (
|
$self->json ($send_to)->notify (
|
||||||
$send_to => $answer
|
$send_to => $answer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ my $__signal_handler = sub {
|
|||||||
my ($self, $name) = @_;
|
my ($self, $name) = @_;
|
||||||
$log->info ("[INFO] Caught a signal $name");
|
$log->info ("[INFO] Caught a signal $name");
|
||||||
|
|
||||||
if (defined $main::pidfile && -f $main::pidfile) {
|
if (defined $main::pidfile && -e $main::pidfile) {
|
||||||
unlink $main::pidfile;
|
unlink $main::pidfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +122,7 @@ sub RunGames {
|
|||||||
$log->info ("[INFO] Connecting to $c->{server}, $c->{port}");
|
$log->info ("[INFO] Connecting to $c->{server}, $c->{port}");
|
||||||
|
|
||||||
my $redis = Mojo::Redis->new (
|
my $redis = Mojo::Redis->new (
|
||||||
sprintf 'redis://%s:%s/1', $c->{server}, $c->{port}
|
sprintf 'redis://%s:%s/1', $c->{server}, $c->{port},
|
||||||
);
|
);
|
||||||
|
|
||||||
$log->info ('[INFO] Registering connection-event callback');
|
$log->info ('[INFO] Registering connection-event callback');
|
||||||
@@ -140,11 +139,11 @@ sub RunGames {
|
|||||||
my ($conn, $error) = @_;
|
my ($conn, $error) = @_;
|
||||||
$log->error ("[ERROR] Redis connection error: $error");
|
$log->error ("[ERROR] Redis connection error: $error");
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
my $pubsub = $redis->pubsub;
|
my $pubsub = $redis->pubsub;
|
||||||
@@ -155,13 +154,13 @@ sub RunGames {
|
|||||||
$log->debug ("[DEBUG] Subscribing to $channel");
|
$log->debug ("[DEBUG] Subscribing to $channel");
|
||||||
|
|
||||||
$sub->{$channel} = $pubsub->json ($channel)->listen (
|
$sub->{$channel} = $pubsub->json ($channel)->listen (
|
||||||
$channel => sub { $parse_message->(@_); }
|
$channel => sub { $parse_message->(@_); },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mojo::IOLoop::Signal->on (
|
Mojo::IOLoop::Signal->on (
|
||||||
TERM => $__signal_handler,
|
TERM => $__signal_handler,
|
||||||
INT => $__signal_handler
|
INT => $__signal_handler,
|
||||||
);
|
);
|
||||||
|
|
||||||
do { Mojo::IOLoop->start } until Mojo::IOLoop->is_running;
|
do { Mojo::IOLoop->start } until Mojo::IOLoop->is_running;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package Games::Archeologist;
|
package Games::Archeologist;
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
use open qw (:std :utf8);
|
use open qw (:std :utf8);
|
||||||
use English qw ( -no_match_vars );
|
use English qw ( -no_match_vars );
|
||||||
use DBI;
|
use DBI ();
|
||||||
use Log::Any qw ($log);
|
use Log::Any qw ($log);
|
||||||
use Math::Random::Secure qw (irand);
|
use Math::Random::Secure qw (irand);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package Games::Fisher;
|
package Games::Fisher;
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
use open qw (:std :utf8);
|
use open qw (:std :utf8);
|
||||||
use English qw ( -no_match_vars );
|
use English qw ( -no_match_vars );
|
||||||
use DBI;
|
use DBI ();
|
||||||
use Log::Any qw ($log);
|
use Log::Any qw ($log);
|
||||||
use Math::Random::Secure qw (irand);
|
use Math::Random::Secure qw (irand);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package Games::Gamestat;
|
package Games::Gamestat;
|
||||||
# Stores and calculates player stats for games
|
# Stores and calculates player stats for games
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
use open qw (:std :utf8);
|
use open qw (:std :utf8);
|
||||||
use DBI;
|
use DBI ();
|
||||||
use English qw ( -no_match_vars );
|
use English qw ( -no_match_vars );
|
||||||
use File::Path qw (make_path);
|
use File::Path qw (make_path);
|
||||||
use Mojo::Util qw (trim);
|
use Mojo::Util qw (trim);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package Util;
|
package Util;
|
||||||
|
|
||||||
use 5.018;
|
use 5.018; ## no critic (ProhibitImplicitImport)
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use utf8;
|
use utf8;
|
||||||
@@ -8,7 +8,7 @@ use open qw (:std :utf8);
|
|||||||
use English qw ( -no_match_vars );
|
use English qw ( -no_match_vars );
|
||||||
|
|
||||||
use Digest::SHA qw (sha1_base64);
|
use Digest::SHA qw (sha1_base64);
|
||||||
use Encode;
|
use Encode qw (encode_utf8);
|
||||||
|
|
||||||
use version; our $VERSION = qw (1.0);
|
use version; our $VERSION = qw (1.0);
|
||||||
use Exporter qw (import);
|
use Exporter qw (import);
|
||||||
|
|||||||
Reference in New Issue
Block a user