Skip to content

Commit d655e01

Browse files
authored
Merge branch 'master' into feature/26.1
2 parents f1e779d + 5863712 commit d655e01

15 files changed

Lines changed: 347 additions & 276 deletions

File tree

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ metadata.format.version = "1.1"
33
[versions]
44

55
adventure = "4.25.0"
6-
cloudburstnbt = "3.0.0.Final"
6+
cloudburstnbt = "3.0.4.Final"
77
slf4j = "2.0.9"
88
math = "2.0"
99
fastutil-maps = "8.5.3"

protocol/src/main/java/org/geysermc/mcprotocollib/auth/GameProfile.java

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import org.geysermc.mcprotocollib.auth.texture.Texture;
6+
import org.geysermc.mcprotocollib.auth.texture.TextureType;
57
import org.geysermc.mcprotocollib.auth.util.TextureUrlChecker;
68
import org.geysermc.mcprotocollib.auth.util.UndashedUUIDAdapter;
79

@@ -192,7 +194,7 @@ public Map<TextureType, Texture> getTextures(boolean requireSecure) throws Illeg
192194

193195
if (result != null && result.textures != null) {
194196
if (requireSecure) {
195-
for (GameProfile.Texture texture : result.textures.values()) {
197+
for (Texture texture : result.textures.values()) {
196198
if (TextureUrlChecker.isAllowedTextureDomain(texture.getURL())) {
197199
continue;
198200
}
@@ -357,100 +359,11 @@ public String toString() {
357359
}
358360
}
359361

360-
/**
361-
* The type of a profile texture.
362-
*/
363-
public enum TextureType {
364-
SKIN,
365-
CAPE,
366-
ELYTRA;
367-
}
368-
369-
/**
370-
* The model used for a profile texture.
371-
*/
372-
public enum TextureModel {
373-
WIDE,
374-
SLIM;
375-
}
376-
377-
/**
378-
* A texture contained within a profile.
379-
*/
380-
public static class Texture {
381-
private final String url;
382-
private final Map<String, String> metadata;
383-
384-
/**
385-
* Creates a new Texture instance.
386-
*
387-
* @param url URL of the texture.
388-
* @param metadata Metadata of the texture.
389-
*/
390-
public Texture(String url, Map<String, String> metadata) {
391-
this.url = url;
392-
this.metadata = metadata;
393-
}
394-
395-
/**
396-
* Gets the URL of the texture.
397-
*
398-
* @return The texture's URL.
399-
*/
400-
public String getURL() {
401-
return this.url;
402-
}
403-
404-
/**
405-
* Gets a metadata string from the texture.
406-
*
407-
* @return The metadata value corresponding to the given key.
408-
*/
409-
public String getMetadata(String key) {
410-
if (this.metadata == null) {
411-
return null;
412-
}
413-
414-
return this.metadata.get(key);
415-
}
416-
417-
/**
418-
* Gets the model of the texture.
419-
*
420-
* @return The texture's model.
421-
*/
422-
public TextureModel getModel() {
423-
String model = this.getMetadata("model");
424-
return model != null && model.equals("slim") ? TextureModel.SLIM : TextureModel.WIDE;
425-
}
426-
427-
/**
428-
* Gets the hash of the texture.
429-
*
430-
* @return The texture's hash.
431-
*/
432-
public String getHash() {
433-
String url = this.url.endsWith("/") ? this.url.substring(0, this.url.length() - 1) : this.url;
434-
int slash = url.lastIndexOf("/");
435-
int dot = url.lastIndexOf(".");
436-
if (dot < slash) {
437-
dot = url.length();
438-
}
439-
440-
return url.substring(slash + 1, dot != -1 ? dot : url.length());
441-
}
442-
443-
@Override
444-
public String toString() {
445-
return "Texture{url=" + this.url + ", model=" + this.getModel() + ", hash=" + this.getHash() + "}";
446-
}
447-
}
448-
449362
private static class MinecraftTexturesPayload {
450363
public long timestamp;
451364
public UUID profileId;
452365
public String profileName;
453366
public boolean isPublic;
454-
public Map<GameProfile.TextureType, GameProfile.Texture> textures;
367+
public Map<TextureType, Texture> textures;
455368
}
456369
}

protocol/src/main/java/org/geysermc/mcprotocollib/auth/SessionService.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ public void joinServer(GameProfile profile, String authenticationToken, String s
7272
* @throws IOException If an error occurs while making the request.
7373
*/
7474
public GameProfile getProfileByServer(String name, String serverId) throws IOException {
75-
HasJoinedResponse response = HTTPUtils.makeRequest(this.getProxy(),
76-
URI.create(String.format(HAS_JOINED_ENDPOINT,
77-
URLEncoder.encode(name, StandardCharsets.UTF_8),
78-
URLEncoder.encode(serverId, StandardCharsets.UTF_8))),
79-
null, HasJoinedResponse.class);
75+
URI hasJoinedUri = URI.create(String.format(HAS_JOINED_ENDPOINT, URLEncoder.encode(name, StandardCharsets.UTF_8), URLEncoder.encode(serverId, StandardCharsets.UTF_8)));
76+
HasJoinedResponse response = HTTPUtils.makeRequest(this.getProxy(), hasJoinedUri, null, HasJoinedResponse.class);
8077
if (response != null && response.id != null) {
8178
GameProfile result = new GameProfile(response.id, name);
8279
result.setProperties(response.properties);
@@ -97,7 +94,8 @@ public void fillProfileProperties(GameProfile profile) throws IOException {
9794
return;
9895
}
9996

100-
MinecraftProfileResponse response = HTTPUtils.makeRequest(this.getProxy(), URI.create(String.format(PROFILE_ENDPOINT, UUIDUtils.convertToNoDashes(profile.getId()))), null, MinecraftProfileResponse.class);
97+
URI profileUri = URI.create(String.format(PROFILE_ENDPOINT, UUIDUtils.convertToNoDashes(profile.getId())));
98+
MinecraftProfileResponse response = HTTPUtils.makeRequest(this.getProxy(), profileUri, null, MinecraftProfileResponse.class);
10199
if (response == null) {
102100
throw new IllegalStateException("Couldn't fetch profile properties for " + profile + " as the profile does not exist.");
103101
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.geysermc.mcprotocollib.auth.texture;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* A texture contained within a profile.
7+
*/
8+
public class Texture {
9+
private final String url;
10+
private final Map<String, String> metadata;
11+
12+
/**
13+
* Creates a new Texture instance.
14+
*
15+
* @param url URL of the texture.
16+
* @param metadata Metadata of the texture.
17+
*/
18+
public Texture(String url, Map<String, String> metadata) {
19+
this.url = url;
20+
this.metadata = metadata;
21+
}
22+
23+
/**
24+
* Gets the URL of the texture.
25+
*
26+
* @return The texture's URL.
27+
*/
28+
public String getURL() {
29+
return this.url;
30+
}
31+
32+
/**
33+
* Gets a metadata string from the texture.
34+
*
35+
* @return The metadata value corresponding to the given key.
36+
*/
37+
public String getMetadata(String key) {
38+
if (this.metadata == null) {
39+
return null;
40+
}
41+
42+
return this.metadata.get(key);
43+
}
44+
45+
/**
46+
* Gets the model of the texture.
47+
*
48+
* @return The texture's model.
49+
*/
50+
public TextureModel getModel() {
51+
String model = this.getMetadata("model");
52+
return model != null && model.equals("slim") ? TextureModel.SLIM : TextureModel.WIDE;
53+
}
54+
55+
/**
56+
* Gets the hash of the texture.
57+
*
58+
* @return The texture's hash.
59+
*/
60+
public String getHash() {
61+
String url = this.url.endsWith("/") ? this.url.substring(0, this.url.length() - 1) : this.url;
62+
int slash = url.lastIndexOf("/");
63+
int dot = url.lastIndexOf(".");
64+
if (dot < slash) {
65+
dot = url.length();
66+
}
67+
68+
return url.substring(slash + 1, dot != -1 ? dot : url.length());
69+
}
70+
71+
@Override
72+
public String toString() {
73+
return "Texture{url=" + this.url + ", model=" + this.getModel() + ", hash=" + this.getHash() + "}";
74+
}
75+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.geysermc.mcprotocollib.auth.texture;
2+
3+
/**
4+
* The model used for a profile texture.
5+
*/
6+
public enum TextureModel {
7+
WIDE,
8+
SLIM;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.geysermc.mcprotocollib.auth.texture;
2+
3+
/**
4+
* The type of a profile texture.
5+
*/
6+
public enum TextureType {
7+
SKIN,
8+
CAPE,
9+
ELYTRA;
10+
}

protocol/src/main/java/org/geysermc/mcprotocollib/network/compression/ZlibCompression.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.geysermc.mcprotocollib.network.compression;
22

33
import io.netty.buffer.ByteBuf;
4+
import io.netty.handler.codec.DecoderException;
45

56
import java.nio.ByteBuffer;
67
import java.util.zip.DataFormatException;
@@ -23,26 +24,31 @@ public ZlibCompression(int level) {
2324

2425
@Override
2526
public void inflate(ByteBuf source, ByteBuf destination, int uncompressedSize) throws DataFormatException {
26-
final int originalIndex = source.readerIndex();
27-
inflater.setInput(source.nioBuffer());
27+
ByteBuffer input;
28+
if (source.nioBufferCount() > 0) {
29+
input = source.nioBuffer();
30+
source.skipBytes(source.readableBytes());
31+
} else {
32+
input = ByteBuffer.allocateDirect(source.readableBytes());
33+
source.readBytes(input);
34+
input.flip();
35+
}
36+
inflater.setInput(input);
2837

2938
try {
30-
while (!inflater.finished() && inflater.getBytesWritten() < uncompressedSize) {
31-
if (!destination.isWritable()) {
32-
destination.ensureWritable(ZLIB_BUFFER_SIZE);
33-
}
34-
35-
ByteBuffer destNioBuf = destination.nioBuffer(destination.writerIndex(),
36-
destination.writableBytes());
37-
int produced = inflater.inflate(destNioBuf);
38-
destination.writerIndex(destination.writerIndex() + produced);
39+
ByteBuffer nioBuffer = destination.internalNioBuffer(0, uncompressedSize);
40+
int pos = nioBuffer.position();
41+
inflater.inflate(nioBuffer);
42+
int actualUncompressedSize = nioBuffer.position() - pos;
43+
if (actualUncompressedSize != uncompressedSize) {
44+
throw new DecoderException(
45+
"Badly compressed packet - actual size of uncompressed payload "
46+
+ actualUncompressedSize
47+
+ " does not match declared size "
48+
+ uncompressedSize);
49+
} else {
50+
destination.writerIndex(destination.writerIndex() + actualUncompressedSize);
3951
}
40-
41-
if (!inflater.finished()) {
42-
throw new DataFormatException("Received a deflate stream that was too large, wanted " + uncompressedSize);
43-
}
44-
45-
source.readerIndex(originalIndex + inflater.getTotalIn());
4652
} finally {
4753
inflater.reset();
4854
}

0 commit comments

Comments
 (0)