Use byte buffer for packets to avoid copying#46
Use byte buffer for packets to avoid copying#46jon-zu wants to merge 4 commits intodoriyan13:masterfrom
Conversation
doriyan13
left a comment
There was a problem hiding this comment.
Sorry for all the comments, tho i'm rlly excited about this changes! :D
rlly nice job Joo! <3
| } | ||
|
|
||
| static void decryptData(ByteBuf buf, | ||
| int offset, |
There was a problem hiding this comment.
the offset is always 0, please inline it. no need for it to be a param.
| private static Cipher initCipher() { | ||
| try { | ||
| cipher = Cipher.getInstance("AES"); | ||
| Cipher cipher = Cipher.getInstance("AES"); |
There was a problem hiding this comment.
this is the old algo, please update to the new one.
i don't remember if i pushed it to master but it's in dev for sure
| // Init connection for the client - | ||
| logger.serverNotice(String.format("[CHAT] Opened session with %s in Acceptor", c.getIP())); | ||
| c.write(CLogin.sendConnect(siv,riv)); | ||
| c.write(CLogin.sendConnect(siv.getBytes(), riv.getBytes())); |
There was a problem hiding this comment.
your Initialization vector save int and start convert to bytes each time you call getBytes, it's redundant and expensive thus i've removed it and kept it as byte array
| logger.notice(String.format("Channel %d-%d listening on port %d", channel.getWorldId(), channel.getChannelId(), channel.getPort())); | ||
| if (channel != null) { | ||
| logger.notice(String.format("Channel %d-%d listening on port %d", channel.getWorldId(), | ||
| channel.getChannelId(), channel.getPort())); |
|
|
||
| import com.dori.SpringStory.connection.packet.OutPacket; | ||
|
|
||
| public class BroadcastSet<T extends NettyClient> { |
There was a problem hiding this comment.
after thinking on what you said yesterday -
we can just keep the lock as static rather then instance base and each time you get to the encoder - call this util class that will lock, get list of clients and then do the same business logic
| @Override | ||
| public String toString() { | ||
| return MapleUtils.readableByteArray(Arrays.copyOfRange(getData(), getData().length - getUnreadAmount(), getData().length)); // Substring after copy of range xd | ||
| return super.toString(); |
There was a problem hiding this comment.
i use the toString to log all the packets, please make sure this logic still being printed as intend
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[Pck] | " + this.buf.toString(); |
There was a problem hiding this comment.
yeh this is not good, please use my handling for toString or just remove the prefix of [Pck]
| // If it's true will auto login as admin - | ||
| if (AUTO_LOGIN) { | ||
| OutPacket outPacket = new OutPacket(); | ||
| OutPacket outPacket = new OutPacket(0); |
There was a problem hiding this comment.
yeh it's bad practice, default 0 should be internal and not be passed into constructor in java
| private long creationTime; | ||
| private long deprecationStartTime; | ||
| private List<PositionData> mobsSpawnPoints = new ArrayList<>(); | ||
| private BroadcastSet<MapleClient> tx = new BroadcastSet<>(); |
There was a problem hiding this comment.
will require double maintaining which i think is redundant
| this.needSkillForFly = mapData.isNeedSkillForFly(); | ||
| this.fixedMobCapacity = mapData.getFixedMobCapacity() != 0 ? mapData.getFixedMobCapacity() : DEFAULT_FIELD_MOB_CAPACITY; | ||
| this.fixedMobCapacity = mapData.getFixedMobCapacity() != 0 ? mapData.getFixedMobCapacity() | ||
| : DEFAULT_FIELD_MOB_CAPACITY; |
There was a problem hiding this comment.
in java it's suppose to be inline
Groundwork to use netty byte bufs for packets properly. Not done yet(!)
ByteBufin packet