|
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.game.admin; |
|
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.core.di.ContainerConfigurator; |
|
26
|
|
|
import fr.quatrevieux.araknemu.core.di.ContainerModule; |
|
27
|
|
|
import fr.quatrevieux.araknemu.data.living.repository.account.AccountRepository; |
|
28
|
|
|
import fr.quatrevieux.araknemu.data.world.repository.environment.MapTemplateRepository; |
|
29
|
|
|
import fr.quatrevieux.araknemu.game.GameService; |
|
30
|
|
|
import fr.quatrevieux.araknemu.game.ShutdownService; |
|
31
|
|
|
import fr.quatrevieux.araknemu.game.account.AccountService; |
|
32
|
|
|
import fr.quatrevieux.araknemu.game.admin.account.AccountContext; |
|
33
|
|
|
import fr.quatrevieux.araknemu.game.admin.account.AccountContextResolver; |
|
34
|
|
|
import fr.quatrevieux.araknemu.game.admin.account.Ban; |
|
35
|
|
|
import fr.quatrevieux.araknemu.game.admin.account.Info; |
|
36
|
|
|
import fr.quatrevieux.araknemu.game.admin.context.AbstractContextConfigurator; |
|
37
|
|
|
import fr.quatrevieux.araknemu.game.admin.context.SelfContextResolver; |
|
38
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.Area; |
|
39
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.DebugContext; |
|
40
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.DebugContextResolver; |
|
41
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.FightPos; |
|
42
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.LineOfSight; |
|
43
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.MapStats; |
|
44
|
|
|
import fr.quatrevieux.araknemu.game.admin.debug.Movement; |
|
45
|
|
|
import fr.quatrevieux.araknemu.game.admin.exception.ExceptionHandler; |
|
46
|
|
|
import fr.quatrevieux.araknemu.game.admin.executor.CommandExecutor; |
|
47
|
|
|
import fr.quatrevieux.araknemu.game.admin.executor.DefaultCommandExecutor; |
|
48
|
|
|
import fr.quatrevieux.araknemu.game.admin.executor.argument.ArgumentsHydrator; |
|
49
|
|
|
import fr.quatrevieux.araknemu.game.admin.executor.argument.HydratorsAggregate; |
|
50
|
|
|
import fr.quatrevieux.araknemu.game.admin.global.GlobalContext; |
|
51
|
|
|
import fr.quatrevieux.araknemu.game.admin.global.Help; |
|
52
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.GetItem; |
|
53
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.PlayerContext; |
|
54
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.PlayerContextResolver; |
|
55
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.teleport.CellResolver; |
|
56
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.teleport.Goto; |
|
57
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.teleport.LocationResolver; |
|
58
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.teleport.MapResolver; |
|
59
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.teleport.PlayerResolver; |
|
60
|
|
|
import fr.quatrevieux.araknemu.game.admin.player.teleport.PositionResolver; |
|
61
|
|
|
import fr.quatrevieux.araknemu.game.admin.server.Banip; |
|
62
|
|
|
import fr.quatrevieux.araknemu.game.admin.server.Online; |
|
63
|
|
|
import fr.quatrevieux.araknemu.game.admin.server.ServerContext; |
|
64
|
|
|
import fr.quatrevieux.araknemu.game.admin.server.ServerContextResolver; |
|
65
|
|
|
import fr.quatrevieux.araknemu.game.admin.server.Shutdown; |
|
66
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.ExplorationMapService; |
|
67
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.GeolocationService; |
|
68
|
|
|
import fr.quatrevieux.araknemu.game.fight.FightService; |
|
69
|
|
|
import fr.quatrevieux.araknemu.game.item.ItemService; |
|
70
|
|
|
import fr.quatrevieux.araknemu.game.player.PlayerService; |
|
71
|
|
|
import fr.quatrevieux.araknemu.game.spell.effect.SpellEffectService; |
|
72
|
|
|
import org.apache.logging.log4j.LogManager; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Register the admin service and console commands |
|
76
|
|
|
* |
|
77
|
|
|
* Note: Only commands which needs dependencies from the container should be defined here. "simple" commands may be defined directly on the context |
|
78
|
|
|
*/ |
|
79
|
|
|
public final class AdminModule implements ContainerModule { |
|
80
|
|
|
private final Araknemu app; |
|
81
|
|
|
|
|
82
|
1 |
|
public AdminModule(Araknemu app) { |
|
83
|
1 |
|
this.app = app; |
|
84
|
1 |
|
} |
|
85
|
|
|
|
|
86
|
|
|
@Override |
|
87
|
|
|
public void configure(ContainerConfigurator configurator) { |
|
88
|
1 |
|
configureService(configurator); |
|
89
|
1 |
|
configureResolvers(configurator); |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
private void configureService(ContainerConfigurator configurator) { |
|
93
|
1 |
|
configurator.factory(Araknemu.class, container -> app); |
|
94
|
|
|
|
|
95
|
1 |
|
configurator.persist( |
|
96
|
|
|
AdminSessionService.class, |
|
97
|
1 |
|
container -> new AdminSessionService( |
|
98
|
1 |
|
container.get(AdminUser.Factory.class) |
|
99
|
|
|
) |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
1 |
|
configurator.persist( |
|
103
|
|
|
AdminUser.Factory.class, |
|
104
|
1 |
|
container -> ((player) -> new AdminUser( |
|
105
|
|
|
player, |
|
106
|
1 |
|
container.get(CommandExecutor.class), |
|
107
|
1 |
|
container.get(CommandParser.class), |
|
108
|
1 |
|
container.get(PlayerContextResolver.class).resolve(player), |
|
109
|
1 |
|
container.get(ExceptionHandler.class), |
|
110
|
1 |
|
LogManager.getLogger(AdminModule.class) |
|
111
|
|
|
)) |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
1 |
|
configurator.persist( |
|
115
|
|
|
GlobalContext.class, |
|
116
|
1 |
|
container -> new GlobalContext().register(new AbstractContextConfigurator<GlobalContext>() { |
|
117
|
|
|
@Override |
|
118
|
|
|
public void configure(GlobalContext context) { |
|
119
|
1 |
|
add(new Help(container.get(ArgumentsHydrator.class))); |
|
120
|
1 |
|
} |
|
121
|
|
|
}) |
|
122
|
|
|
); |
|
123
|
|
|
|
|
124
|
1 |
|
configurator.persist(SelfContextResolver.class, container -> new SelfContextResolver()); |
|
125
|
|
|
|
|
126
|
1 |
|
configurator.persist( |
|
127
|
|
|
CommandExecutor.class, |
|
128
|
1 |
|
container -> new DefaultCommandExecutor(container.get(ArgumentsHydrator.class)) |
|
129
|
|
|
); |
|
130
|
|
|
|
|
131
|
1 |
|
configurator.persist( |
|
132
|
|
|
ArgumentsHydrator.class, |
|
133
|
1 |
|
container -> new HydratorsAggregate() |
|
134
|
|
|
); |
|
135
|
|
|
|
|
136
|
1 |
|
configurator.persist( |
|
137
|
|
|
CommandParser.class, |
|
138
|
1 |
|
container -> new ContextCommandParser( |
|
139
|
1 |
|
container.get(PlayerContextResolver.class), |
|
140
|
1 |
|
container.get(AccountContextResolver.class), |
|
141
|
1 |
|
container.get(DebugContextResolver.class), |
|
142
|
1 |
|
container.get(ServerContextResolver.class), |
|
143
|
1 |
|
container.get(SelfContextResolver.class) |
|
144
|
|
|
) |
|
145
|
|
|
); |
|
146
|
|
|
|
|
147
|
1 |
|
configurator.persist(ExceptionHandler.class, container -> new ExceptionHandler()); |
|
148
|
1 |
|
} |
|
149
|
|
|
|
|
150
|
|
|
private void configureResolvers(ContainerConfigurator configurator) { |
|
151
|
1 |
|
configurator.factory( |
|
152
|
|
|
PlayerContextResolver.class, |
|
153
|
1 |
|
container -> new PlayerContextResolver(container.get(PlayerService.class), container.get(AccountContextResolver.class)) |
|
154
|
1 |
|
.register(new AbstractContextConfigurator<PlayerContext>() { |
|
155
|
|
|
@Override |
|
156
|
|
|
public void configure(PlayerContext context) { |
|
157
|
1 |
|
add(new GetItem(context.player(), container.get(ItemService.class))); |
|
158
|
1 |
|
add(new Goto(context.player(), container.get(ExplorationMapService.class), new LocationResolver[] { |
|
159
|
1 |
|
new MapResolver(container.get(ExplorationMapService.class)), |
|
160
|
1 |
|
new PositionResolver(context.player(), container.get(GeolocationService.class)), |
|
161
|
1 |
|
new PlayerResolver(container.get(PlayerService.class), container.get(ExplorationMapService.class)), |
|
162
|
|
|
new CellResolver(), |
|
163
|
|
|
})); |
|
164
|
1 |
|
} |
|
165
|
|
|
}) |
|
166
|
|
|
); |
|
167
|
|
|
|
|
168
|
1 |
|
configurator.persist( |
|
169
|
|
|
AccountContextResolver.class, |
|
170
|
1 |
|
container -> new AccountContextResolver(container.get(AccountService.class), container.get(GlobalContext.class)) |
|
171
|
1 |
|
.register(new AbstractContextConfigurator<AccountContext>() { |
|
172
|
|
|
@Override |
|
173
|
|
|
public void configure(AccountContext context) { |
|
174
|
1 |
|
add(new Info(context.account(), container.get(AccountRepository.class))); |
|
175
|
1 |
|
add(new Ban(context.account(), container.get(BanishmentService.class))); |
|
176
|
1 |
|
} |
|
177
|
|
|
}) |
|
178
|
|
|
); |
|
179
|
|
|
|
|
180
|
1 |
|
configurator.persist( |
|
181
|
|
|
DebugContextResolver.class, |
|
182
|
1 |
|
container -> new DebugContextResolver(container.get(GlobalContext.class)) |
|
183
|
1 |
|
.register(new AbstractContextConfigurator<DebugContext>() { |
|
184
|
|
|
@Override |
|
185
|
|
|
public void configure(DebugContext context) { |
|
186
|
1 |
|
add(new FightPos()); |
|
187
|
1 |
|
add(new Movement(container.get(MapTemplateRepository.class))); |
|
188
|
1 |
|
add(new MapStats(container.get(MapTemplateRepository.class))); |
|
189
|
1 |
|
add(new Area(container.get(SpellEffectService.class))); |
|
190
|
1 |
|
add(new LineOfSight(container.get(MapTemplateRepository.class))); |
|
191
|
1 |
|
} |
|
192
|
|
|
}) |
|
193
|
|
|
); |
|
194
|
|
|
|
|
195
|
1 |
|
configurator.persist( |
|
196
|
|
|
ServerContextResolver.class, |
|
197
|
1 |
|
container -> new ServerContextResolver(container.get(GlobalContext.class)) |
|
198
|
1 |
|
.register(new AbstractContextConfigurator<ServerContext>() { |
|
199
|
|
|
@Override |
|
200
|
|
|
public void configure(ServerContext context) { |
|
201
|
1 |
|
add(new Online( |
|
202
|
1 |
|
container.get(PlayerService.class), |
|
203
|
1 |
|
container.get(ExplorationMapService.class), |
|
204
|
1 |
|
container.get(GameService.class) |
|
205
|
|
|
)); |
|
206
|
1 |
|
add(new Shutdown(container.get(ShutdownService.class))); |
|
207
|
1 |
|
add(new Banip(container.get(BanIpService.class))); |
|
208
|
1 |
|
add(new fr.quatrevieux.araknemu.game.admin.server.Info( |
|
209
|
1 |
|
container.get(Araknemu.class), |
|
210
|
1 |
|
container.get(PlayerService.class), |
|
211
|
1 |
|
container.get(GameService.class), |
|
212
|
1 |
|
container.get(FightService.class) |
|
213
|
|
|
)); |
|
214
|
1 |
|
} |
|
215
|
|
|
}) |
|
216
|
|
|
); |
|
217
|
1 |
|
} |
|
218
|
|
|
} |
|
219
|
|
|
|