fr.quatrevieux.araknemu.realm.handler.account.ConnectGame   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 31
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle(RealmSession,ChooseServer) 0 17 2
A packet() 0 3 1
A ConnectGame(HostService) 0 2 1
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.handler.account;
21
22
import fr.quatrevieux.araknemu.core.network.parser.PacketHandler;
23
import fr.quatrevieux.araknemu.network.realm.RealmSession;
24
import fr.quatrevieux.araknemu.network.realm.in.ChooseServer;
25
import fr.quatrevieux.araknemu.network.realm.out.SelectServerError;
26
import fr.quatrevieux.araknemu.network.realm.out.SelectServerPlain;
27
import fr.quatrevieux.araknemu.realm.host.GameHost;
28
import fr.quatrevieux.araknemu.realm.host.HostService;
29
import org.checkerframework.checker.nullness.util.NullnessUtil;
30
31
/**
32
 * Connect the client to choose game server
33
 *
34
 * @todo Do not use SelectServerPlain
0 ignored issues
show
introduced by
Comment matches to-do format '(TODO:)|(@todo )'.
Loading history...
35
 */
36
public final class ConnectGame implements PacketHandler<RealmSession, ChooseServer> {
37
    private final HostService service;
38
39 1
    public ConnectGame(HostService service) {
40 1
        this.service = service;
41 1
    }
42
43
    @Override
44
    public void handle(RealmSession session, ChooseServer packet) {
45 1
        if (!service.isAvailable(packet.id())) {
46 1
            session.send(
47
                new SelectServerError(SelectServerError.Error.CANT_SELECT)
48
            );
49
50 1
            return;
51
        }
52
53 1
        final GameHost host = service.get(packet.id());
54
55 1
        host.connector().token(
56 1
            NullnessUtil.castNonNull(session.account()),
57
            token -> {
58 1
                session.send(new SelectServerPlain(host.ip(), host.port(), token));
59 1
                session.close();
60 1
            }
61
        );
62 1
    }
63
64
    @Override
65
    public Class<ChooseServer> packet() {
66 1
        return ChooseServer.class;
67
    }
68
}
69