|
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.common.account.banishment.AbstractBanIpSynchronizer; |
|
23
|
|
|
import fr.quatrevieux.araknemu.common.account.banishment.BanIpService; |
|
24
|
|
|
import fr.quatrevieux.araknemu.core.InitializableService; |
|
25
|
|
|
import fr.quatrevieux.araknemu.core.event.EventsSubscriber; |
|
26
|
|
|
import fr.quatrevieux.araknemu.core.event.Listener; |
|
27
|
|
|
import fr.quatrevieux.araknemu.core.network.session.Session; |
|
28
|
|
|
import fr.quatrevieux.araknemu.realm.authentication.AuthenticationAccount; |
|
29
|
|
|
import fr.quatrevieux.araknemu.realm.event.AuthStopped; |
|
30
|
|
|
import org.apache.logging.log4j.Logger; |
|
31
|
|
|
|
|
32
|
|
|
import java.time.Duration; |
|
33
|
|
|
import java.util.Collection; |
|
34
|
|
|
import java.util.function.Supplier; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Synchronize ban ip table for authentication service |
|
38
|
|
|
*/ |
|
39
|
|
|
public final class AuthBanIpSynchronizer extends AbstractBanIpSynchronizer implements EventsSubscriber, InitializableService { |
|
40
|
|
|
public AuthBanIpSynchronizer(BanIpService<AuthenticationAccount> service, Supplier<Collection<? extends Session>> sessionsSupplier, Logger logger, Duration refreshDelay) { |
|
41
|
1 |
|
super(service, sessionsSupplier, logger, refreshDelay); |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
@Override |
|
45
|
|
|
public void init(Logger logger) { |
|
46
|
|
|
startPulling(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
@Override |
|
50
|
|
|
public Listener[] listeners() { |
|
51
|
|
|
return new Listener[] { |
|
52
|
|
|
new Listener<AuthStopped>() { |
|
53
|
|
|
@Override |
|
54
|
|
|
public void on(AuthStopped event) { |
|
55
|
|
|
stopPulling(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
@Override |
|
59
|
|
|
public Class<AuthStopped> event() { |
|
60
|
|
|
return AuthStopped.class; |
|
61
|
|
|
} |
|
62
|
|
|
}, |
|
63
|
|
|
ipBannedListener(), |
|
64
|
|
|
}; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|