|
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-2020 Vincent Quatrevieux |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
package fr.quatrevieux.araknemu.realm; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.Araknemu; |
|
23
|
|
|
import fr.quatrevieux.araknemu.common.account.banishment.BanIpService; |
|
24
|
|
|
import fr.quatrevieux.araknemu.common.account.banishment.BanishmentService; |
|
25
|
|
|
import fr.quatrevieux.araknemu.common.account.banishment.network.BanIpCheck; |
|
26
|
|
|
import fr.quatrevieux.araknemu.common.session.SessionLogService; |
|
27
|
|
|
import fr.quatrevieux.araknemu.core.di.ContainerConfigurator; |
|
28
|
|
|
import fr.quatrevieux.araknemu.core.di.ContainerModule; |
|
29
|
|
|
import fr.quatrevieux.araknemu.core.event.DefaultListenerAggregate; |
|
30
|
|
|
import fr.quatrevieux.araknemu.core.event.ListenerAggregate; |
|
31
|
|
|
import fr.quatrevieux.araknemu.core.network.Server; |
|
32
|
|
|
import fr.quatrevieux.araknemu.core.network.netty.NettyServer; |
|
33
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.AggregatePacketParser; |
|
34
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.AggregateParserLoader; |
|
35
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.DefaultDispatcher; |
|
36
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.Dispatcher; |
|
37
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.PacketHandler; |
|
38
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.PacketParser; |
|
39
|
|
|
import fr.quatrevieux.araknemu.core.network.parser.ParserLoader; |
|
40
|
|
|
import fr.quatrevieux.araknemu.core.network.session.SessionConfigurator; |
|
41
|
|
|
import fr.quatrevieux.araknemu.core.network.session.SessionFactory; |
|
42
|
|
|
import fr.quatrevieux.araknemu.core.network.session.extension.RateLimiter; |
|
43
|
|
|
import fr.quatrevieux.araknemu.core.network.session.extension.SessionLogger; |
|
44
|
|
|
import fr.quatrevieux.araknemu.data.living.repository.BanIpRepository; |
|
45
|
|
|
import fr.quatrevieux.araknemu.data.living.repository.account.AccountRepository; |
|
46
|
|
|
import fr.quatrevieux.araknemu.data.living.repository.account.BanishmentRepository; |
|
47
|
|
|
import fr.quatrevieux.araknemu.data.living.repository.account.ConnectionLogRepository; |
|
48
|
|
|
import fr.quatrevieux.araknemu.data.living.repository.player.PlayerRepository; |
|
49
|
|
|
import fr.quatrevieux.araknemu.network.in.CommonParserLoader; |
|
50
|
|
|
import fr.quatrevieux.araknemu.network.realm.RealmSession; |
|
51
|
|
|
import fr.quatrevieux.araknemu.network.realm.RealmSessionConfigurator; |
|
52
|
|
|
import fr.quatrevieux.araknemu.network.realm.in.Credentials; |
|
53
|
|
|
import fr.quatrevieux.araknemu.network.realm.in.DofusVersion; |
|
54
|
|
|
import fr.quatrevieux.araknemu.network.realm.in.RealmParserLoader; |
|
55
|
|
|
import fr.quatrevieux.araknemu.realm.authentication.AuthenticationService; |
|
56
|
|
|
import fr.quatrevieux.araknemu.realm.authentication.password.Argon2Hash; |
|
57
|
|
|
import fr.quatrevieux.araknemu.realm.authentication.password.PasswordManager; |
|
58
|
|
|
import fr.quatrevieux.araknemu.realm.authentication.password.PlainTextHash; |
|
59
|
|
|
import fr.quatrevieux.araknemu.realm.handler.CheckDofusVersion; |
|
60
|
|
|
import fr.quatrevieux.araknemu.realm.handler.CheckQueuePosition; |
|
61
|
|
|
import fr.quatrevieux.araknemu.realm.handler.CloseInactiveSession; |
|
62
|
|
|
import fr.quatrevieux.araknemu.realm.handler.PongResponse; |
|
63
|
|
|
import fr.quatrevieux.araknemu.realm.handler.StartSession; |
|
64
|
|
|
import fr.quatrevieux.araknemu.realm.handler.StopSession; |
|
65
|
|
|
import fr.quatrevieux.araknemu.realm.handler.account.Authenticate; |
|
66
|
|
|
import fr.quatrevieux.araknemu.realm.handler.account.ConnectGame; |
|
67
|
|
|
import fr.quatrevieux.araknemu.realm.handler.account.ListServers; |
|
68
|
|
|
import fr.quatrevieux.araknemu.realm.handler.account.SearchFriend; |
|
69
|
|
|
import fr.quatrevieux.araknemu.realm.host.HostService; |
|
70
|
|
|
import org.apache.logging.log4j.LogManager; |
|
71
|
|
|
import org.apache.logging.log4j.Logger; |
|
72
|
|
|
|
|
73
|
|
|
import java.util.Arrays; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* DI module for RealmService |
|
77
|
|
|
*/ |
|
78
|
|
|
public final class RealmModule implements ContainerModule { |
|
79
|
|
|
private final Araknemu app; |
|
80
|
|
|
|
|
81
|
1 |
|
public RealmModule(Araknemu app) { |
|
82
|
1 |
|
this.app = app; |
|
83
|
1 |
|
} |
|
84
|
|
|
|
|
85
|
|
|
@Override |
|
86
|
|
|
public void configure(ContainerConfigurator configurator) { |
|
87
|
1 |
|
configurator.factory( |
|
88
|
|
|
Logger.class, |
|
89
|
1 |
|
container -> LogManager.getLogger(RealmService.class) |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
1 |
|
configurator.persist( |
|
93
|
|
|
RealmService.class, |
|
94
|
1 |
|
container -> new RealmService( |
|
95
|
1 |
|
container.get(RealmConfiguration.class), |
|
96
|
1 |
|
container.get(Server.class), |
|
97
|
1 |
|
container.get(Logger.class), |
|
98
|
1 |
|
container.get(ListenerAggregate.class), |
|
99
|
1 |
|
Arrays.asList( |
|
100
|
1 |
|
container.get(AuthBanIpSynchronizer.class) |
|
101
|
|
|
), |
|
102
|
1 |
|
Arrays.asList( |
|
103
|
1 |
|
container.get(AuthBanIpSynchronizer.class), |
|
104
|
1 |
|
container.get(AuthenticationService.class) |
|
105
|
|
|
) |
|
106
|
|
|
) |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
1 |
|
configurator.persist(ListenerAggregate.class, container -> new DefaultListenerAggregate(container.get(Logger.class))); |
|
110
|
1 |
|
configurator.factory(fr.quatrevieux.araknemu.core.event.Dispatcher.class, container -> container.get(ListenerAggregate.class)); |
|
111
|
|
|
|
|
112
|
1 |
|
configurator.factory( |
|
113
|
|
|
RealmConfiguration.class, |
|
114
|
1 |
|
container -> app.configuration().module(RealmConfiguration.MODULE) |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
1 |
|
configurator.factory( |
|
118
|
|
|
Server.class, |
|
119
|
1 |
|
container -> new NettyServer( |
|
120
|
1 |
|
container.get(SessionFactory.class), |
|
121
|
1 |
|
container.get(RealmConfiguration.class).port(), |
|
122
|
1 |
|
container.get(RealmConfiguration.class).inactivityTime() |
|
123
|
|
|
) |
|
124
|
|
|
); |
|
125
|
|
|
|
|
126
|
1 |
|
configurator.factory( |
|
127
|
|
|
SessionFactory.class, |
|
128
|
1 |
|
container -> new SessionConfigurator<>(RealmSession::new) |
|
129
|
1 |
|
.add(new BanIpCheck<>(container.get(BanIpService.class))) |
|
130
|
1 |
|
.add(new RateLimiter.Configurator<>(container.get(RealmConfiguration.class).packetRateLimit())) |
|
131
|
1 |
|
.add(new SessionLogger.Configurator<>(container.get(Logger.class))) |
|
132
|
1 |
|
.add(new RealmSessionConfigurator( |
|
133
|
1 |
|
container.get(Dispatcher.class), |
|
134
|
1 |
|
new PacketParser[] {DofusVersion.parser(), Credentials.parser()}, |
|
135
|
1 |
|
container.get(PacketParser.class), |
|
136
|
1 |
|
container.get(Logger.class) |
|
137
|
|
|
)) |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
1 |
|
configurator.factory( |
|
141
|
|
|
Dispatcher.class, |
|
142
|
1 |
|
container -> new DefaultDispatcher<RealmSession>( |
|
143
|
|
|
new PacketHandler[] { |
|
144
|
|
|
new StartSession(), |
|
145
|
1 |
|
new StopSession(container.get(AuthenticationService.class)), |
|
146
|
|
|
new CloseInactiveSession(), |
|
147
|
1 |
|
new CheckDofusVersion(container.get(RealmConfiguration.class)), |
|
148
|
|
|
new Authenticate( |
|
149
|
1 |
|
container.get(AuthenticationService.class), |
|
150
|
1 |
|
container.get(HostService.class), |
|
151
|
1 |
|
container.get(SessionLogService.class) |
|
152
|
|
|
), |
|
153
|
|
|
new CheckQueuePosition(), |
|
154
|
|
|
new ListServers( |
|
155
|
1 |
|
container.get(HostService.class) |
|
156
|
|
|
), |
|
157
|
|
|
new PongResponse(), |
|
158
|
|
|
new ConnectGame( |
|
159
|
1 |
|
container.get(HostService.class) |
|
160
|
|
|
), |
|
161
|
1 |
|
new SearchFriend(container.get(HostService.class)), |
|
162
|
|
|
} |
|
163
|
|
|
) |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
1 |
|
configurator.factory( |
|
167
|
|
|
PacketParser.class, |
|
168
|
1 |
|
container -> new AggregatePacketParser( |
|
169
|
|
|
new AggregateParserLoader( |
|
170
|
|
|
new ParserLoader[]{ |
|
171
|
|
|
new CommonParserLoader(), |
|
172
|
|
|
new RealmParserLoader(), |
|
173
|
|
|
} |
|
174
|
1 |
|
).load() |
|
175
|
|
|
) |
|
176
|
|
|
); |
|
177
|
|
|
|
|
178
|
1 |
|
configurator.persist( |
|
179
|
|
|
AuthenticationService.class, |
|
180
|
1 |
|
container -> new AuthenticationService( |
|
181
|
1 |
|
container.get(AccountRepository.class), |
|
182
|
1 |
|
container.get(HostService.class), |
|
183
|
1 |
|
container.get(PasswordManager.class), |
|
184
|
1 |
|
container.get(BanishmentService.class) |
|
185
|
|
|
) |
|
186
|
|
|
); |
|
187
|
|
|
|
|
188
|
1 |
|
configurator.persist( |
|
189
|
|
|
HostService.class, |
|
190
|
1 |
|
container -> new HostService( |
|
191
|
1 |
|
container.get(PlayerRepository.class), |
|
192
|
1 |
|
container.get(fr.quatrevieux.araknemu.core.event.Dispatcher.class) |
|
193
|
|
|
) |
|
194
|
|
|
); |
|
195
|
|
|
|
|
196
|
1 |
|
configurator.persist(SessionLogService.class, container -> new SessionLogService( |
|
197
|
1 |
|
container.get(ConnectionLogRepository.class) |
|
198
|
|
|
)); |
|
199
|
|
|
|
|
200
|
1 |
|
configurator.persist( |
|
201
|
|
|
PasswordManager.class, |
|
202
|
1 |
|
container -> new PasswordManager( |
|
203
|
1 |
|
Arrays.asList(container.get(RealmConfiguration.class).passwordHashAlgorithms()), |
|
204
|
1 |
|
container.get(Argon2Hash.class), |
|
205
|
1 |
|
container.get(PlainTextHash.class) |
|
206
|
|
|
) |
|
207
|
|
|
); |
|
208
|
|
|
|
|
209
|
1 |
|
configurator.persist( |
|
210
|
|
|
BanishmentService.class, |
|
211
|
1 |
|
container -> new BanishmentService(container.get(BanishmentRepository.class), container.get(fr.quatrevieux.araknemu.core.event.Dispatcher.class)) |
|
212
|
|
|
); |
|
213
|
|
|
|
|
214
|
1 |
|
configurator.persist( |
|
215
|
|
|
BanIpService.class, |
|
216
|
1 |
|
container -> new BanIpService(container.get(BanIpRepository.class), container.get(fr.quatrevieux.araknemu.core.event.Dispatcher.class)) |
|
217
|
|
|
); |
|
218
|
|
|
|
|
219
|
1 |
|
configurator.persist( |
|
220
|
|
|
AuthBanIpSynchronizer.class, |
|
221
|
1 |
|
container -> new AuthBanIpSynchronizer( |
|
222
|
1 |
|
container.get(BanIpService.class), |
|
223
|
|
|
() -> container.get(RealmService.class).sessions(), |
|
224
|
1 |
|
container.get(Logger.class), |
|
225
|
1 |
|
container.get(RealmConfiguration.class).banIpRefresh() |
|
226
|
|
|
) |
|
227
|
|
|
); |
|
228
|
|
|
|
|
229
|
1 |
|
configurator.factory( |
|
230
|
|
|
Argon2Hash.class, |
|
231
|
|
|
container -> { |
|
232
|
1 |
|
final RealmConfiguration.Argon2 config = container.get(RealmConfiguration.class).argon2(); |
|
233
|
|
|
|
|
234
|
1 |
|
return new Argon2Hash() |
|
235
|
1 |
|
.setIterations(config.iterations()) |
|
236
|
1 |
|
.setMemory(config.memory()) |
|
237
|
1 |
|
.setParallelism(config.parallelism()) |
|
238
|
1 |
|
.setType(config.type()) |
|
239
|
|
|
; |
|
240
|
|
|
} |
|
241
|
|
|
); |
|
242
|
|
|
|
|
243
|
1 |
|
configurator.factory(PlainTextHash.class, container -> new PlainTextHash()); |
|
244
|
1 |
|
} |
|
245
|
|
|
} |
|
246
|
|
|
|