line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hoppy::Service::Login; |
2
|
5
|
|
|
5
|
|
30
|
use strict; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
227
|
|
3
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
192
|
|
4
|
5
|
|
|
5
|
|
5372
|
use Data::GUID; |
|
5
|
|
|
|
|
125118
|
|
|
5
|
|
|
|
|
38
|
|
5
|
5
|
|
|
5
|
|
1040
|
use base qw( Hoppy::Service::Base ); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
13764
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub work { |
8
|
1
|
|
|
1
|
1
|
93
|
my $self = shift; |
9
|
1
|
|
|
|
|
2
|
my $args = shift; |
10
|
1
|
|
|
|
|
3
|
my $in_data = $args->{in_data}; |
11
|
1
|
|
|
|
|
2
|
my $poe = $args->{poe}; |
12
|
1
|
|
|
|
|
5
|
my $session_id = $poe->session->ID; |
13
|
|
|
|
|
|
|
## It can generate and distribute ID automatically |
14
|
1
|
50
|
|
|
|
18
|
if ( $in_data->{params}->{auto} ) { |
15
|
0
|
|
|
|
|
0
|
$args->{user_id} = Data::GUID->new->as_string; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
else { |
18
|
1
|
|
|
|
|
5
|
$args->{user_id} = $in_data->{params}->{user_id}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
## login |
21
|
1
|
|
|
|
|
12
|
my $c = $self->context; |
22
|
1
|
|
|
|
|
19
|
my $result = $c->room->login( |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
user_id => $args->{user_id}, |
25
|
|
|
|
|
|
|
password => $in_data->{params}->{password}, |
26
|
|
|
|
|
|
|
room_id => $in_data->{params}->{room_id}, |
27
|
|
|
|
|
|
|
session_id => $session_id, |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
$poe |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
## response |
32
|
1
|
50
|
|
|
|
10
|
if ( $in_data->{id} ) { |
33
|
|
|
|
|
|
|
## set out_data |
34
|
1
|
|
|
|
|
2
|
my $out_data = {}; |
35
|
1
|
50
|
|
|
|
4
|
if ($result) { |
36
|
1
|
|
|
|
|
24
|
$out_data = { |
37
|
|
|
|
|
|
|
result => { |
38
|
|
|
|
|
|
|
login_id => $args->{user_id}, |
39
|
|
|
|
|
|
|
login_time => time() |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
error => "" |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
0
|
|
|
|
|
0
|
$out_data = { result => "", error => "login failed" }; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
4
|
$out_data->{id} = $in_data->{id}; |
48
|
|
|
|
|
|
|
## respond it |
49
|
1
|
|
|
|
|
4
|
my $serialized = $c->formatter->serialize($out_data); |
50
|
1
|
|
|
|
|
9
|
$c->unicast( |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
session_id => $session_id, |
53
|
|
|
|
|
|
|
user_id => $args->{user_id}, |
54
|
|
|
|
|
|
|
message => $serialized |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
1
|
50
|
|
|
|
133
|
if ( my $hook = $c->hook->{login} ) { |
59
|
0
|
|
|
|
|
|
$hook->work($args); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
1; |
63
|
|
|
|
|
|
|
__END__ |