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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
From 8d6e8268b01132a6276f0ee6fd88b1196b14ed66 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sat, 12 Apr 2014 15:11:15 +1000
Subject: [PATCH] Old / New Version Support.
This adds support for newer / older Minecraft versions.
At present it supports protocol versions 4 and 5 (1.7.2-1.7.8).
diff --git a/src/main/java/net/minecraft/server/HandshakeListener.java b/src/main/java/net/minecraft/server/HandshakeListener.java
index ee24038..09fdb88 100644
--- a/src/main/java/net/minecraft/server/HandshakeListener.java
+++ b/src/main/java/net/minecraft/server/HandshakeListener.java
@@ -26,6 +26,12 @@ public class HandshakeListener implements PacketHandshakingInListener {
}
public void a(PacketHandshakingInSetProtocol packethandshakinginsetprotocol) {
+ // Spigot start
+ if ( NetworkManager.SUPPORTED_VERSIONS.contains( packethandshakinginsetprotocol.d() ) )
+ {
+ NetworkManager.a( this.b ).attr( NetworkManager.protocolVersion ).set( packethandshakinginsetprotocol.d() );
+ }
+ // Spigot end
switch (ProtocolOrdinalWrapper.a[packethandshakinginsetprotocol.c().ordinal()]) {
case 1:
this.b.a(EnumProtocol.LOGIN);
@@ -70,7 +76,7 @@ public class HandshakeListener implements PacketHandshakingInListener {
chatcomponenttext = new ChatComponentText( org.spigotmc.SpigotConfig.outdatedServerMessage ); // Spigot
this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
this.b.close(chatcomponenttext);
- } else if (packethandshakinginsetprotocol.d() < 5) {
+ } else if (packethandshakinginsetprotocol.d() < 4) {
chatcomponenttext = new ChatComponentText( org.spigotmc.SpigotConfig.outdatedClientMessage ); // Spigot
this.b.handle(new PacketLoginOutDisconnect(chatcomponenttext), new GenericFutureListener[0]);
this.b.close(chatcomponenttext);
diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java
index 31d6008..04af15c 100644
--- a/src/main/java/net/minecraft/server/NetworkManager.java
+++ b/src/main/java/net/minecraft/server/NetworkManager.java
@@ -22,6 +22,9 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
+// Spigot start
+import com.google.common.collect.ImmutableSet;
+// Spigot end
public class NetworkManager extends SimpleChannelInboundHandler {
@@ -47,6 +50,20 @@ public class NetworkManager extends SimpleChannelInboundHandler {
private EnumProtocol p;
private IChatBaseComponent q;
private boolean r;
+ // Spigot Start
+ public static final AttributeKey<Integer> protocolVersion = new AttributeKey<Integer>("protocol_version");
+ public static final ImmutableSet<Integer> SUPPORTED_VERSIONS = ImmutableSet.of(4, 5);
+ public static final int CURRENT_VERSION = 5;
+ public static int getVersion(Channel attr)
+ {
+ Integer ver = attr.attr( protocolVersion ).get();
+ return ( ver != null ) ? ver : CURRENT_VERSION;
+ }
+ public int getVersion()
+ {
+ return getVersion( this.m );
+ }
+ // Spigot End
public NetworkManager(boolean flag) {
this.j = flag;
diff --git a/src/main/java/net/minecraft/server/PacketDataSerializer.java b/src/main/java/net/minecraft/server/PacketDataSerializer.java
index 8d3cf1f..a5be533 100644
--- a/src/main/java/net/minecraft/server/PacketDataSerializer.java
+++ b/src/main/java/net/minecraft/server/PacketDataSerializer.java
@@ -19,10 +19,19 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack; // CraftBukkit
public class PacketDataSerializer extends ByteBuf {
private final ByteBuf a;
+ // Spigot Start
+ public final int version;
- public PacketDataSerializer(ByteBuf bytebuf) {
+ public PacketDataSerializer(ByteBuf bytebuf)
+ {
+ this( bytebuf, NetworkManager.CURRENT_VERSION );
+ }
+
+ public PacketDataSerializer(ByteBuf bytebuf, int version) {
this.a = bytebuf;
+ this.version = version;
}
+ // Spigot End
public static int a(int i) {
return (i & -128) == 0 ? 1 : ((i & -16384) == 0 ? 2 : ((i & -2097152) == 0 ? 3 : ((i & -268435456) == 0 ? 4 : 5)));
diff --git a/src/main/java/net/minecraft/server/PacketEncoder.java b/src/main/java/net/minecraft/server/PacketEncoder.java
new file mode 100644
index 0000000..7994daa
--- /dev/null
+++ b/src/main/java/net/minecraft/server/PacketEncoder.java
@@ -0,0 +1,45 @@
+package net.minecraft.server;
+
+import java.io.IOException;
+
+import net.minecraft.util.com.google.common.collect.BiMap;
+import net.minecraft.util.io.netty.buffer.ByteBuf;
+import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
+import net.minecraft.util.io.netty.handler.codec.MessageToByteEncoder;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+
+public class PacketEncoder extends MessageToByteEncoder {
+
+ private static final Logger a = LogManager.getLogger();
+ private static final Marker b = MarkerManager.getMarker("PACKET_SENT", NetworkManager.b);
+ private final NetworkStatistics c;
+
+ public PacketEncoder(NetworkStatistics networkstatistics) {
+ this.c = networkstatistics;
+ }
+
+ protected void a(ChannelHandlerContext channelhandlercontext, Packet packet, ByteBuf bytebuf) throws IOException {
+ Integer integer = (Integer) ((BiMap) channelhandlercontext.channel().attr(NetworkManager.f).get()).inverse().get(packet.getClass());
+
+ if (a.isDebugEnabled()) {
+ a.debug(b, "OUT: [{}:{}] {}[{}]", new Object[] { channelhandlercontext.channel().attr(NetworkManager.d).get(), integer, packet.getClass().getName(), packet.b()});
+ }
+
+ if (integer == null) {
+ throw new IOException("Can\'t serialize unregistered packet");
+ } else {
+ PacketDataSerializer packetdataserializer = new PacketDataSerializer(bytebuf, NetworkManager.getVersion(channelhandlercontext.channel())); // Spigot
+
+ packetdataserializer.b(integer.intValue());
+ packet.b(packetdataserializer);
+ this.c.b(integer.intValue(), (long) packetdataserializer.readableBytes());
+ }
+ }
+
+ protected void encode(ChannelHandlerContext channelhandlercontext, Object object, ByteBuf bytebuf) throws IOException {
+ this.a(channelhandlercontext, (Packet) object, bytebuf);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/PacketLoginOutSuccess.java b/src/main/java/net/minecraft/server/PacketLoginOutSuccess.java
new file mode 100644
index 0000000..a244f00
--- /dev/null
+++ b/src/main/java/net/minecraft/server/PacketLoginOutSuccess.java
@@ -0,0 +1,44 @@
+package net.minecraft.server;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import net.minecraft.util.com.mojang.authlib.GameProfile;
+
+public class PacketLoginOutSuccess extends Packet {
+
+ private GameProfile a;
+
+ public PacketLoginOutSuccess() {}
+
+ public PacketLoginOutSuccess(GameProfile gameprofile) {
+ this.a = gameprofile;
+ }
+
+ public void a(PacketDataSerializer packetdataserializer) throws IOException {
+ String s = packetdataserializer.c(36);
+ String s1 = packetdataserializer.c(16);
+ UUID uuid = UUID.fromString(s);
+
+ this.a = new GameProfile(uuid, s1);
+ }
+
+ public void b(PacketDataSerializer packetdataserializer) throws IOException {
+ UUID uuid = this.a.getId();
+
+ packetdataserializer.a(uuid == null ? "" : ( ( packetdataserializer.version >= 5 ) ? uuid.toString() : uuid.toString().replaceAll( "-", "" ) ) );
+ packetdataserializer.a(this.a.getName());
+ }
+
+ public void a(PacketLoginOutListener packetloginoutlistener) {
+ packetloginoutlistener.a(this);
+ }
+
+ public boolean a() {
+ return true;
+ }
+
+ public void handle(PacketListener packetlistener) {
+ this.a((PacketLoginOutListener) packetlistener);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/PacketPlayOutNamedEntitySpawn.java b/src/main/java/net/minecraft/server/PacketPlayOutNamedEntitySpawn.java
index 0023f18..ccd4cec 100644
--- a/src/main/java/net/minecraft/server/PacketPlayOutNamedEntitySpawn.java
+++ b/src/main/java/net/minecraft/server/PacketPlayOutNamedEntitySpawn.java
@@ -66,8 +66,9 @@ public class PacketPlayOutNamedEntitySpawn extends Packet {
packetdataserializer.b(this.a);
UUID uuid = this.b.getId();
- packetdataserializer.a(uuid == null ? "" : uuid.toString());
+ packetdataserializer.a( uuid == null ? "" : ( ( packetdataserializer.version >= 5 ) ? uuid.toString() : uuid.toString().replaceAll( "-", "" ) ) ); // Spigot
packetdataserializer.a(this.b.getName().length() > 16 ? this.b.getName().substring(0, 16) : this.b.getName()); // CraftBukkit - Limit name length to 16 characters
+ if (packetdataserializer.version >= 5 ) { // Spigot
packetdataserializer.b(this.b.getProperties().size());
Iterator iterator = this.b.getProperties().values().iterator();
@@ -78,6 +79,7 @@ public class PacketPlayOutNamedEntitySpawn extends Packet {
packetdataserializer.a(property.getValue());
packetdataserializer.a(property.getSignature());
}
+ } // Spigot
packetdataserializer.writeInt(this.c);
packetdataserializer.writeInt(this.d);
diff --git a/src/main/java/net/minecraft/server/PacketStatusListener.java b/src/main/java/net/minecraft/server/PacketStatusListener.java
index 6423aec..f1571f1 100644
--- a/src/main/java/net/minecraft/server/PacketStatusListener.java
+++ b/src/main/java/net/minecraft/server/PacketStatusListener.java
@@ -123,7 +123,7 @@ public class PacketStatusListener implements PacketStatusInListener {
ping.setFavicon(event.icon.value);
ping.setMOTD(new ChatComponentText(event.getMotd()));
ping.setPlayerSample(playerSample);
- ping.setServerInfo(new ServerPingServerData(minecraftServer.getServerModName() + " " + minecraftServer.getVersion(), 5)); // TODO: Update when protocol changes
+ ping.setServerInfo(new ServerPingServerData(minecraftServer.getServerModName() + " " + minecraftServer.getVersion(), networkManager.getVersion())); // TODO: Update when protocol changes
this.networkManager.handle(new PacketStatusOutServerInfo(ping), new GenericFutureListener[0]);
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/TileEntitySkull.java b/src/main/java/net/minecraft/server/TileEntitySkull.java
index 7c3757f..2a50db9 100644
--- a/src/main/java/net/minecraft/server/TileEntitySkull.java
+++ b/src/main/java/net/minecraft/server/TileEntitySkull.java
@@ -23,6 +23,7 @@ public class TileEntitySkull extends TileEntity {
GameProfileSerializer.serialize(nbttagcompound1, this.j);
nbttagcompound.set("Owner", nbttagcompound1);
+ nbttagcompound.setString("ExtraType", nbttagcompound1.getString("Name")); // Spigot
}
}
--
1.9.1
|