-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix VoxelMap support: special case for zero-length packet prefix
- Loading branch information
Showing
6 changed files
with
247 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
common/src/main/java/com/turikhay/mc/mapmodcompanion/worldid/WorldIdRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.turikhay.mc.mapmodcompanion.worldid; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.DataInputStream; | ||
import java.io.IOException; | ||
|
||
import static com.turikhay.mc.mapmodcompanion.worldid.WorldId.MAGIC_MARKER; | ||
|
||
public class WorldIdRequest { | ||
|
||
private final int prefixLength; | ||
|
||
public WorldIdRequest(int prefixLength) { | ||
this.prefixLength = prefixLength; | ||
} | ||
|
||
public int getPrefixLength() { | ||
return prefixLength; | ||
} | ||
|
||
public static WorldIdRequest parse(byte[] message) throws IOException { | ||
int prefixLength = 0; | ||
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(message))) { | ||
if (in.readByte() != 0) { | ||
throw new IOException("unexpected first byte"); | ||
} | ||
int c; | ||
do { | ||
prefixLength++; | ||
c = in.readByte(); | ||
} while(c == 0); | ||
if (c != MAGIC_MARKER) { | ||
throw new IOException("first byte prefix is not a magic number"); | ||
} | ||
} | ||
switch (prefixLength) { | ||
case 1: | ||
// Normal request | ||
break; | ||
case 3: | ||
// VoxelMap fix | ||
prefixLength = 0; | ||
break; | ||
default: | ||
throw new IOException("unexpected prefix length"); | ||
} | ||
return new WorldIdRequest(prefixLength); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.