/
SubProtocol.java
143 lines (117 loc) · 6.23 KB
/
SubProtocol.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package net.ME1312.SubServers.Client.Bukkit.Network;
import net.ME1312.Galaxi.Library.Callback.Callback;
import net.ME1312.Galaxi.Library.Version.Version;
import net.ME1312.SubData.Client.SubDataClient;
import net.ME1312.SubData.Client.SubDataProtocol;
import net.ME1312.SubServers.Client.Bukkit.Event.SubNetworkDisconnectEvent;
import net.ME1312.SubServers.Client.Bukkit.Network.Packet.*;
import net.ME1312.SubServers.Client.Bukkit.SubAPI;
import net.ME1312.SubServers.Client.Bukkit.SubPlugin;
import org.bukkit.Bukkit;
import java.io.IOException;
import java.net.InetAddress;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class SubProtocol extends SubDataProtocol {
private static SubProtocol instance;
private static Logger log;
private SubProtocol() {}
@SuppressWarnings("deprecation")
public static SubProtocol get() {
if (instance == null) {
log = Logger.getAnonymousLogger();
log.setUseParentHandlers(false);
log.addHandler(new Handler() {
private boolean open = true;
@Override
public void publish(LogRecord record) {
if (open)
Bukkit.getLogger().log(record.getLevel(), "SubData > " + record.getMessage(), record.getParameters());
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
open = false;
}
});
instance = new SubProtocol();
SubPlugin plugin = SubAPI.getInstance().getInternals();
instance.setName("SubServers 2");
instance.addVersion(new Version("2.14a+"));
// 00-09: Object Link Packets
instance.registerPacket(0x0002, PacketLinkServer.class);
instance.registerPacket(0x0002, new PacketLinkServer(plugin));
// 10-29: Download Packets
instance.registerPacket(0x0010, PacketDownloadLang.class);
instance.registerPacket(0x0011, PacketDownloadPlatformInfo.class);
instance.registerPacket(0x0012, PacketDownloadProxyInfo.class);
instance.registerPacket(0x0013, PacketDownloadHostInfo.class);
instance.registerPacket(0x0014, PacketDownloadGroupInfo.class);
instance.registerPacket(0x0015, PacketDownloadServerInfo.class);
instance.registerPacket(0x0016, PacketDownloadPlayerList.class);
instance.registerPacket(0x0010, new PacketDownloadLang(plugin));
instance.registerPacket(0x0011, new PacketDownloadPlatformInfo());
instance.registerPacket(0x0012, new PacketDownloadProxyInfo());
instance.registerPacket(0x0013, new PacketDownloadHostInfo());
instance.registerPacket(0x0014, new PacketDownloadGroupInfo());
instance.registerPacket(0x0015, new PacketDownloadServerInfo());
instance.registerPacket(0x0016, new PacketDownloadPlayerList());
// 30-49: Control Packets
//instance.registerPacket(0x0030, PacketOutReload.class); TODO
instance.registerPacket(0x0031, PacketCreateServer.class);
//instance.registerPacket(0x0032, PacketAddServer.class); TODO
instance.registerPacket(0x0033, PacketStartServer.class);
//instance.registerPacket(0x0034, PacketEditServer.class); TODO
instance.registerPacket(0x0035, PacketRestartServer.class);
instance.registerPacket(0x0036, PacketCommandServer.class);
instance.registerPacket(0x0037, PacketStopServer.class);
//instance.registerPacket(0x0038, PacketRemoveServer.class); TODO
//instance.registerPacket(0x0039, PacketDeleteServer.class); TODO
//instance.registerPacket(0x0030 new PacketOutReload()); TODO
instance.registerPacket(0x0031, new PacketCreateServer());
//instance.registerPacket(0x0032, new PacketAddServer()); TODO
instance.registerPacket(0x0033, new PacketStartServer());
//instance.registerPacket(0x0034, new PacketEditServer()); TODO
instance.registerPacket(0x0035, new PacketRestartServer());
instance.registerPacket(0x0036, new PacketCommandServer());
instance.registerPacket(0x0037, new PacketStopServer());
//instance.registerPacket(0x0038, new PacketRemoveServer()); TODO
//instance.registerPacket(0x0039, new PacketDeleteServer()); TODO
// 70-79: External Misc Packets
//instance.registerPacket(0x0070, PacketInExRunEvent.class);
//instance.registerPacket(0x0071, PacketInExReset.class);
//instance.registerPacket(0x0072, PacketInExReload.class);
instance.registerPacket(0x0070, new PacketInExRunEvent(plugin));
instance.registerPacket(0x0071, new PacketInExReset());
instance.registerPacket(0x0072, new PacketInExReload(plugin));
}
return instance;
}
@SuppressWarnings("deprecation")
@Override
public SubDataClient open(Callback<Runnable> scheduler, Logger logger, InetAddress address, int port) throws IOException {
SubDataClient subdata = super.open(scheduler, logger, address, port);
SubPlugin plugin = SubAPI.getInstance().getInternals();
subdata.on.ready(client -> ((SubDataClient) client).sendPacket(new PacketLinkServer(plugin)));
subdata.on.closed(client -> {
SubNetworkDisconnectEvent event = new SubNetworkDisconnectEvent(client.get(), client.name());
if (plugin.isEnabled()) Bukkit.getPluginManager().callEvent(event);
});
return subdata;
}
@SuppressWarnings("deprecation")
@Override
public SubDataClient open(Logger logger, InetAddress address, int port) throws IOException {
SubPlugin plugin = SubAPI.getInstance().getInternals();
return open(event -> {
if (plugin.isEnabled()) Bukkit.getScheduler().runTask(plugin, event);
else event.run();
}, logger, address, port);
}
public SubDataClient open(InetAddress address, int port) throws IOException {
return open(log, address, port);
}
}