Fixing redis bug.

This commit is contained in:
Sergiotarxz 2023-06-23 01:48:22 +02:00
parent 305c5316b3
commit 15c9d2f6fd
2 changed files with 20 additions and 16 deletions

View File

@ -49,7 +49,6 @@ sub handle ( $self, $ws, $session, $data ) {
my @friends = grep { $pj->uuid ne $_->uuid } @team_members;
my $team_pjs = [ map { $_->hash } ( $pj, @friends ) ];
my $location = $team->location;
my $connected_places = $self->_get_connected_places($pj);
$pj->append_log_line(
[
@ -77,6 +76,7 @@ sub handle ( $self, $ws, $session, $data ) {
my $info_packet_to_send =
LasTres::Controller::Websocket::OutputPacket::Info->new(
set_log => [ $pj->last_50_log ],
$self->_location_data($pj),
team_pjs => $team_pjs,
clear => $JSON::true,
);
@ -90,8 +90,23 @@ sub handle ( $self, $ws, $session, $data ) {
}
);
$session->{redis} = $redis;
$redis->publish( $redis->pj_subscription($pj),
to_json( { command => 'update-location' } ) );
}
sub _location_data($self, $pj) {
my $connected_places = $self->_get_connected_places($pj);
my $team = $pj->team;
my $location = $team->location;
return (
location_data => {
current => $location->hash,
(
( $team->is_moving )
? ( moving_to => LasTres::Location::get(@{from_json( $team->moving_to )})->hash )
: ()
),
connected_places => $connected_places,
},
);
}
sub _on_redis_event ( $self, $ws, $session, $message, $topic, $topics ) {
@ -106,20 +121,9 @@ sub _on_redis_event ( $self, $ws, $session, $message, $topic, $topics ) {
return;
}
if ( $data->{command} eq 'update-location' ) {
my $team = $pj->team;
my $location = $team->location;
my $connected_places = $self->_get_connected_places($pj);
my $info_packet_to_send =
LasTres::Controller::Websocket::OutputPacket::Info->new(
location_data => {
current => $location->hash,
(
( $team->is_moving )
? ( moving_to => LasTres::Location::get(@{from_json( $team->moving_to )})->hash )
: ()
),
connected_places => $connected_places,
},
$self->_location_data($pj)
);
$info_packet_to_send->send($ws);

View File

@ -27,7 +27,7 @@ sub get_auto_discover($self) {
}
sub frames_to_move {
return 1;
return 0;
}
sub identifier {