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.game.chat.channel; |
21
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.game.chat.ChannelType; |
23
|
|
|
import fr.quatrevieux.araknemu.game.chat.ChatException; |
24
|
|
|
import fr.quatrevieux.araknemu.game.chat.event.ConcealedMessage; |
25
|
|
|
import fr.quatrevieux.araknemu.game.player.GamePlayer; |
26
|
|
|
import fr.quatrevieux.araknemu.game.player.PlayerService; |
27
|
|
|
import fr.quatrevieux.araknemu.network.game.in.chat.Message; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Channel for private messages |
31
|
|
|
*/ |
32
|
|
|
public final class PrivateChannel implements Channel { |
33
|
|
|
private final PlayerService service; |
34
|
|
|
|
35
|
1 |
|
public PrivateChannel(PlayerService service) { |
36
|
1 |
|
this.service = service; |
37
|
1 |
|
} |
38
|
|
|
|
39
|
|
|
@Override |
40
|
|
|
public ChannelType type() { |
41
|
1 |
|
return ChannelType.PRIVATE; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
@Override |
45
|
|
|
public boolean authorized(GamePlayer from) { |
46
|
1 |
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
@Override |
50
|
|
|
public void send(GamePlayer from, Message message) throws ChatException { |
51
|
1 |
|
if (message.target() == null || !service.isOnline(message.target())) { |
52
|
1 |
|
throw new ChatException(ChatException.Error.USER_NOT_CONNECTED); |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
final GamePlayer to = service.get(message.target()); |
56
|
1 |
|
final ConcealedMessage event = new ConcealedMessage( |
57
|
|
|
from, |
58
|
|
|
to, |
59
|
1 |
|
message.message(), |
60
|
1 |
|
message.items() |
61
|
|
|
); |
62
|
|
|
|
63
|
1 |
|
from.dispatch(event); |
64
|
1 |
|
to.dispatch(event); |
65
|
1 |
|
} |
66
|
|
|
} |
67
|
|
|
|