Skip to content

Commit

Permalink
Fix maps with negative IDs causing out of bounds errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Jul 6, 2020
1 parent ba73657 commit c454e44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ public class BedrockMapInfoRequestTranslator extends PacketTranslator<MapInfoReq
@Override
public void translate(MapInfoRequestPacket packet, GeyserSession session) {
long mapID = packet.getUniqueMapId();
if (mapID <= -1l) {
mapID = 0l;
}

if (session.getStoredMaps().containsKey(mapID)) {
// Delay the packet 100ms to prevent the client from ignoring the packet
long finalMapID = mapID;
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
session.sendUpstreamPacket(session.getStoredMaps().get(mapID));
session.getStoredMaps().remove(mapID);
session.sendUpstreamPacket(session.getStoredMaps().get(finalMapID));
session.getStoredMaps().remove(finalMapID);
}, 100, TimeUnit.MILLISECONDS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public void translate(ServerMapDataPacket packet, GeyserSession session) {

// Store the map to send when the client requests it, as bedrock expects the data after a MapInfoRequestPacket
if (shouldStore) {
session.getStoredMaps().put(mapItemDataPacket.getUniqueMapId(), mapItemDataPacket);
long uniqueMapId = mapItemDataPacket.getUniqueMapId();
if (uniqueMapId <= -1l) {
uniqueMapId = 0l;
}
session.getStoredMaps().put(uniqueMapId, mapItemDataPacket);
}

// Send anyway just in case
Expand Down

0 comments on commit c454e44

Please sign in to comment.