What are some of the latest things you have added to the server?
|
I'm getting a weird error, well not so much weird, but it's strange that I get it since the packet sizes are fine and I don't see anything wrong with the Player updating procedure.
Packet sizes.
PacketBuilder class.Code:public static final int[] PACKET_SIZES = { 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 6, 2, 2, 0, 0, 2, 0, 6, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 4, 0, 0, 2, 2, 6, 0, 6, 0, -1, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0, 8, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 2, 2, 8, 6, 0, -1, 0, 6, 0, 0, 0, 0, 0, 1, 4, 6, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, -1, 0, 0, 13, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 1, 0, 6, 0, 0, 0, -1, 0, 2, 6, 0, 4, 6, 8, 0, 6, 0, 0, 0, 2, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 6, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 3, 0, 2, 0, 0, 8, 1, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 0, 0, 7, 8, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, -1, 0, 6, 0, 1, 0, 0, 0, 6, 0, 6, 8, 1, 0, 0, 4, 0, 0, 0, 0, -1, 0, -1, 4, 0, 0, 6, 6, 0, 0, 0 };
What could be wrong?Code:package com.emulation.net.packet; import com.emulation.net.packet.Packet.Type; public class PacketBuilder { private static int[] BIT_MASK_OUT = new int[32]; private int opcode; private Type type; private int bitPosition; private int position; private byte[] buffer = new byte[16]; static { for (int i = 0; i < PacketBuilder.BIT_MASK_OUT.length; i++) { PacketBuilder.BIT_MASK_OUT[i] = (1 << i) - 1; } } public byte[] getBuffer() { return this.buffer; } public int getPosition() { return this.position; } public PacketBuilder setPosition(int position) { this.position = position; return this; } public Type getType() { return this.type; } public int getOpcode() { return this.opcode; } public PacketBuilder setOpcode(int opcode) { this.opcode = opcode; this.type = Type.FIXED; return this; } public PacketBuilder setOpcodeType(int opcode, Type type) { this.opcode = opcode; this.type = type; return this; } public PacketBuilder() { this(-1); } public PacketBuilder(int opcode) { this(opcode, Type.FIXED); } public PacketBuilder(int opcode, Type type) { this.opcode = opcode; this.type = type; } public Packet toPacket() { byte[] packetBuffer = new byte[this.position]; System.arraycopy(this.buffer, 0, packetBuffer, 0, this.position); return new Packet(this.opcode, this.type, packetBuffer); } public PacketBuilder putByte(byte b) { this.setCapacity(this.position + 1); this.buffer[this.position++] = b; return this; } public PacketBuilder putBytes(byte[] b) { this.setCapacity(this.position + b.length); System.arraycopy(b, 0, this.buffer, this.position, b.length); this.position += b.length; return this; } public PacketBuilder putByteA(int b) { this.setCapacity(this.position + 1); this.buffer[this.position++] = (byte) (b + 128); return this; } public PacketBuilder putBytesA(byte[] data, int length) { this.setCapacity(this.position + data.length); for (int i = 0; i < length; i ++) { this.buffer[this.position++] = (byte) (data[i] + 128); } return this; } public PacketBuilder putByteC(int i) { this.setCapacity(this.position + 1); this.buffer[this.position++] = (byte) -i; return this; } public PacketBuilder putByteS(int i) { this.setCapacity(this.position + 1); this.buffer[this.position++] = (byte) (128 - i); return this; } public PacketBuilder putBytes(byte[] b, int position, int length) { this.setCapacity(position + (length - position)); System.arraycopy(b, position, this.buffer, this.position, length); this.position += length - position; return this; } public PacketBuilder putShort(int s) { this.setCapacity(this.position + 2); this.buffer[this.position++] = (byte) (s >> 8); this.buffer[this.position++] = (byte) s; return this; } public PacketBuilder putLEShort(int s) { this.setCapacity(this.position + 2); this.buffer[this.position++] = (byte) s; this.buffer[this.position++] = (byte) (s >> 8); return this; } public PacketBuilder putShortA(int s) { this.setCapacity(this.position + 2); this.buffer[this.position++] = (byte) (s >> 8); this.buffer[this.position++] = (byte) (s + 128); return this; } public PacketBuilder putLEShortA(int b) { this.setCapacity(this.position + 2); this.buffer[this.position++] = (byte) (b + 128); this.buffer[this.position++] = (byte) (b >> 8); return this; } public PacketBuilder putInt(int i) { this.setCapacity(this.position + 4); this.buffer[this.position++] = (byte) (i >> 24); this.buffer[this.position++] = (byte) (i >> 16); this.buffer[this.position++] = (byte) (i >> 8); this.buffer[this.position++] = (byte) i; return this; } public PacketBuilder putInt1(int i) { this.setCapacity(this.position + 4); this.buffer[this.position++] = ((byte) (i >> 8)); this.buffer[this.position++] = ((byte) i); this.buffer[this.position++] = ((byte) (i >> 24)); this.buffer[this.position++] = ((byte) (i >> 16)); return this; } public PacketBuilder putInt2(int i) { this.setCapacity(this.position + 4); this.buffer[this.position++] = ((byte) (i >> 16)); this.buffer[this.position++] = ((byte) (i >> 24)); this.buffer[this.position++] = ((byte) i); this.buffer[this.position++] = ((byte) (i >> 8)); return this; } public PacketBuilder putLEInt(int i) { this.setCapacity(this.position + 4); this.buffer[this.position++] = (byte) (i); this.buffer[this.position++] = (byte) (i >> 8); this.buffer[this.position++] = (byte) (i >> 16); this.buffer[this.position++] = (byte) (i >> 24); return this; } public PacketBuilder putLong(long l) { this.setCapacity(this.position + 8); this.buffer[this.position++] = (byte) (l >> 56); this.buffer[this.position++] = (byte) (l >> 48); this.buffer[this.position++] = (byte) (l >> 40); this.buffer[this.position++] = (byte) (l >> 32); this.buffer[this.position++] = (byte) (l >> 24); this.buffer[this.position++] = (byte) (l >> 16); this.buffer[this.position++] = (byte) (l >> 8); this.buffer[this.position++] = (byte) l; return this; } @SuppressWarnings("deprecation") public PacketBuilder putString(String s) { s.getBytes(0, s.length(), this.buffer, this.position); this.position += s.length(); this.buffer[this.position++] = 10; return this; } public PacketBuilder putSmart(int i) { if (i < 128) { return this.putByte((byte) i); } return this.putShort((short) i); } public boolean isEmpty() { return this.buffer.length == 0; } public PacketBuilder startBitAccess() { this.bitPosition = this.position * 8; return this; } public PacketBuilder finishBitAccess() { this.position = (this.bitPosition + 7) / 8; return this; } public PacketBuilder putBits(int numBits, int value) { int bytePos = this.bitPosition >> 3; int bitOffset = 8 - (this.bitPosition & 7); this.bitPosition += numBits; for (; numBits > bitOffset; bitOffset = 8) { this.buffer[bytePos] &= ~ PacketBuilder.BIT_MASK_OUT[bitOffset]; this.buffer[bytePos++] |= (value >> (numBits - bitOffset)) & PacketBuilder.BIT_MASK_OUT[bitOffset]; numBits -= bitOffset; } if (numBits == bitOffset) { this.buffer[bytePos] &= ~ PacketBuilder.BIT_MASK_OUT[bitOffset]; this.buffer[bytePos] |= value & PacketBuilder.BIT_MASK_OUT[bitOffset]; } else { this.buffer[bytePos] &= ~ (PacketBuilder.BIT_MASK_OUT[numBits] << (bitOffset - numBits)); this.buffer[bytePos] |= (value & PacketBuilder.BIT_MASK_OUT[numBits]) << (bitOffset - numBits); } return this; } public PacketBuilder setCapacity(int newCapacity) { if (newCapacity >= this.buffer.length) { byte[] newBuffer = new byte[newCapacity + 100]; System.arraycopy(this.buffer, 0, newBuffer, 0, this.position); this.buffer = newBuffer; } return this; } }
What are some of the latest things you have added to the server?
Nothing. I finally got maps to show and then this error shows. Here's my PlayerUpdate class.
Code:package com.emulation.net.update; import java.util.Iterator; import com.emulation.model.player.Appearance; import com.emulation.model.player.Player; import com.emulation.model.player.Talk; import com.emulation.net.packet.Packet; import com.emulation.net.packet.Packet.Type; import com.emulation.net.packet.PacketBuilder; import com.emulation.util.NameUtility; import com.emulation.world.World; public class PlayerUpdate implements Runnable { private EntityUpdate entityUpdate; private Player player; public PlayerUpdate(EntityUpdate entityUpdate, Player player) { this.entityUpdate = entityUpdate; this.player = player; } @Override public void run() { try { PacketBuilder updateBlock = new PacketBuilder(); PacketBuilder packet = new PacketBuilder(); this.updateThisPlayerMovement(packet); this.updatePlayer(updateBlock, this.player); packet.putBits(8, this.player.getPlayerList().size()); for (Iterator<Player> it$ = this.player.getPlayerList().iterator(); it$.hasNext();) { Player player = it$.next(); if (!player.isTeleporting() && player.getLocation() .isWithinDistance(this.player.getLocation())) { this.updatePlayerMovement(packet, player); if (player.getUpdateFlags().isUpdateRequired()) { this.updatePlayer(updateBlock, player); } } else { it$.remove(); packet.putBits(1, 1); packet.putBits(2, 3); } } for (Player player : World.getWorld().getRegionManager().getLocalPlayers( this.player)) { if (this.player.getPlayerList().size() == 255) { break; } if ((player == this.player) || this.player.getPlayerList().contains( player)) { continue; } this.player.getPlayerList().add(player); int yPos = player.getLocation().getY() - this.player.getLocation() .getY(); int xPos = player.getLocation().getX() - this.player.getLocation() .getX(); packet.putBits(11, player.getID()); packet.putBits(1, 1); this.updatePlayer(updateBlock, player); packet.putBits(1, 1); packet.putBits(5, yPos); packet.putBits(5, xPos); } if (updateBlock.getPosition() > 0) { packet.putBits(11, 2047); packet.finishBitAccess(); packet.putBytes(updateBlock.toPacket().getBuffer(), updateBlock .toPacket().getPosition(), 0); } else { packet.finishBitAccess(); } this.player.write(packet.toPacket()); } catch (Exception ex) { ex.printStackTrace(); } finally { this.entityUpdate.getLatch().countDown(); } } private void updatePlayer(PacketBuilder packet, Player player) { if (!player.getUpdateFlags().isUpdateRequired()) { return; } synchronized (player) { if (player.isPacket() && (player != this.player)) { return; } PacketBuilder blockBuilder = new PacketBuilder(); int mask = 0; if (player.getUpdateFlags().isChatUpdateRequired()) { mask |= 0x80; } if (player.getUpdateFlags().isAppearanceUpdateRequired()) { mask |= 0x10; } if (mask >= 0x100) { mask |= 0x40; blockBuilder.putByte((byte) (mask & 0xFF)); blockBuilder.putByte((byte) (mask >> 8)); } else { blockBuilder.putByte((byte) (mask)); } if (player.getUpdateFlags().isChatUpdateRequired()) { this.updateChat(blockBuilder, player); } if (player.getUpdateFlags().isAppearanceUpdateRequired()) { this.updateAppearance(blockBuilder, player); } Packet blockPacket = blockBuilder.toPacket(); if ((player != this.player)) { player.setPacket(blockPacket); } packet.putBytes(blockPacket.getBuffer()); } } private void updateChat(PacketBuilder packet, Player player) { Talk talk = player.getTalking(); byte[] talkingBytes = talk.getData(); packet.putLEShort(((talk.getColor() & 0xFF) << 8) + (talk.getEffects() & 0xFF)); packet.putByte(player.getRight().getValue()); packet.putByteC(talkingBytes.length); for (int i = talkingBytes.length - 1; i >= 0; i--) { packet.putByte(talkingBytes[i]); } } private void updateAppearance(PacketBuilder packet, Player player) { Appearance appearance = player.getAppearance(); PacketBuilder playerProps = new PacketBuilder(); playerProps.putByte((byte) appearance.getGender()); for (int i = 0; i < 5; i++) { playerProps.putByte((byte) 0); } playerProps.putShort(0x100 + appearance.getChest()); playerProps.putByte((byte) 0); playerProps.putShort(0x100 + appearance.getArms()); playerProps.putShort(0x100 + appearance.getLegs()); playerProps.putShort(0x100 + appearance.getHead()); playerProps.putShort(0x100 + appearance.getHands()); playerProps.putShort(0x100 + appearance.getFeet()); playerProps.putShort(0x100 + appearance.getBeard()); playerProps.putByte((byte) appearance.getHairColor()); playerProps.putByte((byte) appearance.getTorsoColor()); playerProps.putByte((byte) appearance.getLegColor()); playerProps.putByte((byte) appearance.getFeetColor()); playerProps.putByte((byte) appearance.getSkinColor()); playerProps.putShort(0x328); playerProps.putShort(0x337); playerProps.putShort(0x333); playerProps.putShort(0x334); playerProps.putShort(0x335); playerProps.putShort(0x336); playerProps.putShort(0x338); playerProps.putLong(NameUtility.nameToLong(player.getName())); playerProps.putByte((byte) 3); playerProps.putShort(0); Packet playerPacket = playerProps.toPacket(); packet.putByteC(playerPacket.getLength()); packet.putBytes(playerPacket.getBuffer()); } private void updateThisPlayerMovement(PacketBuilder packet) { if (this.player.isMapChanging()) { this.player.getPacketSender().mapRegion(); } if (this.player.isTeleporting()) { packet.setOpcodeType(81, Type.VARIABLE_SHORT); packet.startBitAccess(); packet.putBits(1, 1); packet.putBits(2, 3); packet.putBits(2, this.player.getLocation().getZ()); packet.putBits(1, 1); packet.putBits(1, this.player.getUpdateFlags().isUpdateRequired() ? 1 : 0); packet.putBits(7, this.player.getLocation().getLocalY(this.player .getLastLocation())); packet.putBits(7, this.player.getLocation().getLocalX(this.player .getLastLocation())); } if (this.player.getWalkingDirection() == -1) { packet.setOpcodeType(81, Type.VARIABLE_SHORT); packet.startBitAccess(); if (this.player.getUpdateFlags().isUpdateRequired()) { packet.putBits(1, 1); packet.putBits(2, 0); } else { packet.putBits(1, 0); } } else { packet.setOpcodeType(81, Type.VARIABLE_SHORT); packet.startBitAccess(); packet.putBits(1, 1); if (this.player.getRunningDirection() == -1) { packet.putBits(2, 1); packet.putBits(3, this.player.getWalkingDirection()); packet.putBits(1, this.player.getUpdateFlags().isUpdateRequired() ? 1 : 0); } else { packet.putBits(2, 2); packet.putBits(3, this.player.getWalkingDirection()); packet.putBits(3, this.player.getRunningDirection()); packet.putBits(1, this.player.getUpdateFlags().isUpdateRequired() ? 1 : 0); } } } private void updatePlayerMovement(PacketBuilder packet, Player player) { if (player.getWalkingDirection() == -1) { if (this.player.getUpdateFlags().isUpdateRequired()) { packet.putBits(1, 1); packet.putBits(2, 0); } else { packet.putBits(1, 0); } } else if (player.getRunningDirection() == -1) { packet.putBits(1, 1); packet.putBits(2, 1); packet.putBits(3, player.getWalkingDirection()); packet.putBits(1, (player.getUpdateFlags().isUpdateRequired() ? 1 : 0)); } else { packet.putBits(1, 1); packet.putBits(2, 2); packet.putBits(3, player.getWalkingDirection()); packet.putBits(3, player.getRunningDirection()); packet.putBits(1, (this.player.getUpdateFlags().isUpdateRequired() ? 1 : 0)); } } }
Well, I fixed that error but now I get too many players when I'm the only one on..
That's only a portion of that method and I assume that server sided, this would match up with the above for the 8 part:Code:private void method134(Stream stream) { int j = stream.readBits(8); if (j < playerCount) { for (int k = j; k < playerCount; k++) { anIntArray840[anInt839++] = playerIndices[k]; } } if (j > playerCount) { signlink.reporterror(myUsername + " Too many players : " + j + " Expected : " + playerCount); throw new RuntimeException("eek"); } playerCount = 0; for (int l = 0; l < j; l++) { int i1 = playerIndices[l]; Player player = playerArray[i1]; int j1 = stream.readBits(1); if (j1 == 0) { playerIndices[playerCount++] = i1; player.anInt1537 = loopCycle; } else { int k1 = stream.readBits(2); if (k1 == 0) { playerIndices[playerCount++] = i1; player.anInt1537 = loopCycle; anIntArray894[anInt893++] = i1; } else if (k1 == 1) { playerIndices[playerCount++] = i1; player.anInt1537 = loopCycle; int l1 = stream.readBits(3); player.moveInDir(false, l1); int j2 = stream.readBits(1); if (j2 == 1) { anIntArray894[anInt893++] = i1; } else if (k1 == 2) { playerIndices[playerCount++] = i1; player.anInt1537 = loopCycle; int i2 = stream.readBits(3); player.moveInDir(true, i2); int k2 = stream.readBits(3); player.moveInDir(true, k2); int l2 = stream.readBits(1); if (l2 == 1) { anIntArray894[anInt893++] = i1; } } else if (k1 == 3) { anIntArray840[anInt839++] = i1; } } } }
I checked the size for that list, but it always returns 0 so I don't see how it could be 128.. Unless there's something wrong with the putBits method in the PacketBuilder class? The full part for it would be the following:Code:packet.putBits(8, this.player.getPlayerList().size());
Any help?Code:@Override public void run() { try { PacketBuilder updateBlock = new PacketBuilder(); PacketBuilder packet = new PacketBuilder(81, Type.VARIABLE_SHORT); packet.startBitAccess(); this.updateThisPlayerMovement(packet); this.updatePlayer(updateBlock, this.player); packet.putBits(8, this.player.getPlayerList().size()); for (Iterator<Player> playerIterate = this.player.getPlayerList().iterator(); playerIterate.hasNext();) { Player player = playerIterate.next(); if (!player.isTeleporting() && player.getLocation().isWithinDistance(this.player.getLocation())) { this.updatePlayerMovement(packet, player); if (player.getUpdateFlags().isUpdateRequired()) { this.updatePlayer(updateBlock, player); } } else { packet.putBits(1, 1); packet.putBits(2, 3); playerIterate.remove(); } } for (Iterator<Player> playerIterate = this.player.getPlayerList().iterator(); playerIterate.hasNext();) { Player player = playerIterate.next(); if ((player == this.player) || (player == null)) { continue; } packet.putBits(11, player.getID()); packet.putBits(1, 1); packet.putBits(1, 1); int y = player.getLocation().getY() - this.player.getLocation().getY(); int x = player.getLocation().getX()- this.player.getLocation().getX(); packet.putBits(5, y); packet.putBits(5, x); this.updatePlayer(updateBlock, player); } if (updateBlock.getPosition() > 0) { packet.putBits(11, 2047); packet.finishBitAccess(); packet.putBytes(updateBlock.toPacket().getBuffer()); } else { packet.finishBitAccess(); } this.player.write(packet.toPacket()); } catch (Exception ex) { ex.printStackTrace(); } finally { this.entityUpdate.getLatch().countDown(); } }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |