|
1
|
|
|
/* |
|
2
|
|
|
* This file is part of Araknemu. |
|
3
|
|
|
* |
|
4
|
|
|
* Araknemu is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* Araknemu is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU Lesser General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with Araknemu. If not, see <https://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* Copyright (c) 2017-2019 Vincent Quatrevieux |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.realm.authentication; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.common.account.AbstractLivingAccount; |
|
23
|
|
|
import fr.quatrevieux.araknemu.data.living.entity.account.Account; |
|
24
|
|
|
import fr.quatrevieux.araknemu.game.world.util.Sender; |
|
25
|
|
|
import fr.quatrevieux.araknemu.network.realm.RealmSession; |
|
26
|
|
|
import fr.quatrevieux.araknemu.realm.authentication.password.Password; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* AuthenticationAccount entity for realm |
|
30
|
|
|
*/ |
|
31
|
|
|
public final class AuthenticationAccount extends AbstractLivingAccount<RealmSession> implements Sender { |
|
32
|
|
|
private final AuthenticationService service; |
|
33
|
|
|
private Password password; |
|
34
|
|
|
|
|
35
|
|
|
public AuthenticationAccount(Account account, Password password, AuthenticationService service) { |
|
36
|
1 |
|
super(account); |
|
37
|
|
|
|
|
38
|
1 |
|
this.password = password; |
|
39
|
1 |
|
this.service = service; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the password of the account |
|
44
|
|
|
*/ |
|
45
|
|
|
public Password password() { |
|
46
|
1 |
|
return password; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Update the account password |
|
51
|
|
|
* |
|
52
|
|
|
* @param newPassword new password |
|
53
|
|
|
*/ |
|
54
|
|
|
public void updatePassword(Password newPassword) { |
|
55
|
1 |
|
password = newPassword; |
|
56
|
1 |
|
account.setPassword(newPassword.toString()); |
|
57
|
1 |
|
service.savePassword(account); |
|
58
|
1 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Attach account to a session |
|
62
|
|
|
*/ |
|
63
|
|
|
@Override |
|
64
|
|
|
public void attach(RealmSession session) { |
|
65
|
1 |
|
session.attach(this); |
|
66
|
1 |
|
service.login(this); |
|
67
|
|
|
|
|
68
|
1 |
|
super.attach(session); |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Detach account from session |
|
73
|
|
|
*/ |
|
74
|
|
|
@Override |
|
75
|
|
|
public void detach() { |
|
76
|
1 |
|
session.detach(); |
|
77
|
1 |
|
service.logout(this); |
|
78
|
|
|
|
|
79
|
1 |
|
super.detach(); |
|
80
|
1 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get the secret question |
|
84
|
|
|
*/ |
|
85
|
|
|
public String question() { |
|
86
|
1 |
|
return account.question(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
@Override |
|
90
|
|
|
public void send(Object packet) { |
|
91
|
1 |
|
if (session != null) { |
|
92
|
1 |
|
session.send(packet); |
|
93
|
|
|
} |
|
94
|
1 |
|
} |
|
95
|
|
|
|
|
96
|
|
|
@Override |
|
97
|
|
|
public boolean equals(Object o) { |
|
98
|
1 |
|
if (this == o) { |
|
99
|
1 |
|
return true; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
if (o == null || getClass() != o.getClass()) { |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
final AuthenticationAccount that = (AuthenticationAccount) o; |
|
107
|
|
|
|
|
108
|
|
|
return account.id() == that.account.id(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
@Override |
|
112
|
|
|
public int hashCode() { |
|
113
|
1 |
|
return 23 * account.id(); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|