/
InitPacketVerifyState.java
54 lines (46 loc) · 2.16 KB
/
InitPacketVerifyState.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package net.ME1312.SubData.Server.Protocol.Initial;
import net.ME1312.Galaxi.Library.Map.ObjectMap;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.SubData.Server.Library.ConnectionState;
import net.ME1312.SubData.Server.Protocol.PacketObjectIn;
import net.ME1312.SubData.Server.Protocol.PacketObjectOut;
import net.ME1312.SubData.Server.Protocol.PacketOut;
import net.ME1312.SubData.Server.SubDataClient;
import java.util.HashMap;
import java.util.LinkedList;
import static net.ME1312.SubData.Server.Library.ConnectionState.POST_INITIALIZATION;
/**
* Initial Packet for Verifying States Class
*/
public final class InitPacketVerifyState implements InitialProtocol.Packet, PacketObjectIn<Integer>, PacketObjectOut<Integer> {
@Override
public ObjectMap<Integer> send(SubDataClient client) throws Throwable {
ObjectMap<Integer> data = new ObjectMap<Integer>();
if (Util.reflect(SubDataClient.class.getDeclaredField("state"), client) == POST_INITIALIZATION) {
data.set(0x0000, Util.<HashMap<ConnectionState, LinkedList<PacketOut>>>reflect(SubDataClient.class.getDeclaredField("statequeue"), client).keySet().contains(POST_INITIALIZATION));
}
return data;
}
@Override
public void receive(SubDataClient client, ObjectMap<Integer> data) throws Throwable {
if (Util.reflect(SubDataClient.class.getDeclaredField("state"), client) == POST_INITIALIZATION) {
if (data.getBoolean(0x0000)) {
HashMap<ConnectionState, LinkedList<PacketOut>> queue = Util.reflect(SubDataClient.class.getDeclaredField("statequeue"), client);
if (data.getBoolean(0x0001)) {
if (queue.size() > 0) {
Util.reflect(SubDataClient.class.getDeclaredField("queue"), client, queue.get(POST_INITIALIZATION));
Util.reflect(SubDataClient.class.getDeclaredMethod("write"), client);
}
} else {
setReady(client, true);
}
} else {
client.sendPacket(this);
}
}
}
@Override
public int version() {
return 0x0001;
}
}