2023-06-01 08:45:43 +02:00
|
|
|
package LasTres;
|
|
|
|
|
2023-06-20 01:48:55 +02:00
|
|
|
use v5.36.0;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2023-06-01 08:45:43 +02:00
|
|
|
use Mojo::Base 'Mojolicious', -signatures;
|
|
|
|
|
|
|
|
# This method will run once at server start
|
|
|
|
sub startup ($self) {
|
|
|
|
|
|
|
|
# Load configuration from config file
|
|
|
|
my $config = $self->plugin('NotYAMLConfig');
|
|
|
|
|
|
|
|
# Configure the application
|
|
|
|
$self->secrets( $config->{secrets} );
|
|
|
|
|
|
|
|
# Router
|
|
|
|
my $r = $self->routes;
|
|
|
|
|
|
|
|
$self->helper(user => sub($self) {
|
|
|
|
require LasTres::DAO::Players;
|
|
|
|
my $result_set_players = LasTres::DAO::Players->ResultSet;
|
|
|
|
my $uuid = $self->session->{uuid};
|
|
|
|
if (!defined $uuid) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
my @players = $result_set_players->search({
|
|
|
|
uuid => $uuid,
|
|
|
|
});
|
|
|
|
my $player = $players[0];
|
|
|
|
if (!defined $player) {
|
|
|
|
delete $self->session->{uuid};
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $player;
|
|
|
|
});
|
|
|
|
|
|
|
|
my $sessions = Mojolicious::Sessions->new;
|
|
|
|
$sessions->cookie_name('LasTres');
|
2023-06-08 09:02:32 +02:00
|
|
|
$sessions->default_expiration(0);
|
2023-06-01 08:45:43 +02:00
|
|
|
|
|
|
|
# Normal route to controller
|
|
|
|
$r->get('/')->to('Root#index');
|
2023-06-05 02:06:18 +02:00
|
|
|
$r->get('/races/playable')->to('Race#playable');
|
2023-06-08 09:02:32 +02:00
|
|
|
$r->get('/my/pjs')->to('PJ#list_my_pjs');
|
2023-06-05 02:06:18 +02:00
|
|
|
|
2023-06-01 08:45:43 +02:00
|
|
|
$r->post('/player/register')->to('Player#register');
|
|
|
|
$r->post('/player/login')->to('Player#login');
|
|
|
|
$r->post('/player/check_login')->to('Player#check_login');
|
|
|
|
$r->post('/pj/create')->to('PJ#create');;
|
|
|
|
$r->websocket('/ws')->to('Websocket#ws');
|
2023-06-20 01:48:55 +02:00
|
|
|
$self->hook(before_server_start => sub ($server, $self) {
|
|
|
|
require LasTres::EventLoop;
|
|
|
|
LasTres::EventLoop->new->loop;
|
|
|
|
});
|
2023-06-01 08:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|