fixed byte-overflow in UpdateStackHeightComposer

This commit is contained in:
skeletor 2020-01-21 06:26:44 -05:00 committed by Harmonic
parent 395cba2a5f
commit 3fb3b200d2
3 changed files with 15 additions and 8 deletions

View File

@ -547,7 +547,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
tile.setState(this.calculateTileState(tile));
}
this.sendComposer(new UpdateStackHeightComposer(tiles).compose());
this.sendComposer(new UpdateStackHeightComposer(this, tiles).compose());
}
private RoomTileState calculateTileState(RoomTile tile) {
@ -655,7 +655,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
}
}
this.sendComposer(new UpdateStackHeightComposer(updatedTiles).compose());
this.sendComposer(new UpdateStackHeightComposer(this, updatedTiles).compose());
this.updateTiles(updatedTiles);
for (RoomTile tile : updatedTiles) {
this.updateHabbosAt(tile.x, tile.y);

View File

@ -51,7 +51,7 @@ public class SetStackHelperHeightEvent extends MessageHandler {
item.needsUpdate(true);
this.client.getHabbo().getHabboInfo().getCurrentRoom().updateItem(item);
this.client.getHabbo().getHabboInfo().getCurrentRoom().updateTiles(tiles);
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightComposer(tiles).compose());
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightComposer(room, tiles).compose());
this.client.getHabbo().getHabboInfo().getCurrentRoom().sendComposer(new UpdateStackHeightTileHeightComposer(item, (int) ((height) * 100)).compose());
}
}

View File

@ -1,5 +1,6 @@
package com.eu.habbo.messages.outgoing.rooms;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
@ -12,6 +13,7 @@ public class UpdateStackHeightComposer extends MessageComposer {
private double height;
private THashSet<RoomTile> updateTiles;
private Room room;
public UpdateStackHeightComposer(int x, int y, double height) {
this.x = x;
@ -19,24 +21,29 @@ public class UpdateStackHeightComposer extends MessageComposer {
this.height = height;
}
public UpdateStackHeightComposer(THashSet<RoomTile> updateTiles) {
public UpdateStackHeightComposer(Room room, THashSet<RoomTile> updateTiles) {
this.updateTiles = updateTiles;
this.room = room;
}
@Override
public ServerMessage compose() {
//TODO: THIS IS A TEMP FIX. THERE IS AN ISSUE WITH BAD PACKET STRUCTURE HERE CAUSING ISSUES WITH MOVING LARGE FURNITURE
//TODO: maybe do this another way? doesn't seem to be very clean but gets the job done
this.response.init(Outgoing.UpdateStackHeightComposer);
if (this.updateTiles != null) {
if(this.updateTiles.size() > 4) {
// prevent overflow. Byte max value is 127
if(this.updateTiles.size() > 127) {
RoomTile[] tiles = this.updateTiles.toArray(new RoomTile[updateTiles.size()]);
this.response.appendByte(4);
for(int i = 0; i < 4; i++) {
this.response.appendByte(127);
for(int i = 0; i < 127; i++) {
RoomTile t = tiles[i];
updateTiles.remove(t); // remove it from the set
this.response.appendByte((int) t.x);
this.response.appendByte((int) t.y);
this.response.appendShort(t.relativeHeight());
}
//send the remaining tiles in a new message
this.room.sendComposer(new UpdateStackHeightComposer(this.room, updateTiles).compose());
return this.response;
}