- UID
- 137702
- 閱讀權限
- 20
- 主題
- 32
- 帖子
- 64
- 精華
- 1
- A幣
- 338
- 在線時間
- 111 小時
- 最後登錄
- 2024-11-12
初窺門道
- 主題
- 32
- 帖子
- 64
- 精華
- 1
- 綜合社群主題發文量
- 0
- 電玩社群主題發文量
- 0
- 娛樂社群主題發文量
- 0
- 技術社群主題發文量
- 32
- 閱讀權限
- 20
- 註冊時間
- 2021-11-15
TA的每日心情 | 奮鬥 2024-1-28 13:17 |
---|
簽到天數: 1 天 連續簽到: 1 天 [LV.1]初來乍到
|
很感謝你的幫助!我現在嘗試替換了源碼的內容
未修改之前:
public class MaplePacketEncoder implements ProtocolEncoder {
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
if (client != null) {
final MapleAESOFB send_crypto = client.getSendCrypto();
final byte[] inputInitialPacket = ((byte[]) message);
final byte[] unencrypted = new byte[inputInitialPacket.length];
System.arraycopy(inputInitialPacket, 0, unencrypted, 0, inputInitialPacket.length); // Copy the input > "unencrypted"
final byte[] ret = new byte[unencrypted.length + 4]; // Create new bytes with length = "unencrypted" + 4
final Lock mutex = client.getLock();
mutex.lock();
try {
final byte[] header = send_crypto.getPacketHeader(unencrypted.length);
MapleCustomEncryption.encryptData(unencrypted); // Encrypting Data
send_crypto.crypt(unencrypted); // Crypt it with IV
System.arraycopy(header, 0, ret, 0, 4); // Copy the header > "Ret", first 4 bytes
} finally {
mutex.unlock();
}
System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length); // Copy the unencrypted > "ret"
out.write(IoBuffer.wrap(ret));
} else { // no client object created yet, send unencrypted (hello)
out.write(IoBuffer.wrap(((byte[]) message)));
}
}
修改后:
public class MaplePacketEncoder implements ProtocolEncoder {
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
if (client != null) {
final MapleAESOFB send_crypto = client.getSendCrypto();
final byte[] inputInitialPacket = ((byte[]) message);
final byte[] unencrypted = new byte[inputInitialPacket.length];
System.arraycopy(inputInitialPacket, 0, unencrypted, 0, inputInitialPacket.length); // Copy the input > "unencrypted"
final byte[] ret = new byte[unencrypted.length + 4]; // Create new bytes with length = "unencrypted" + 4
final Lock mutex = client.getLock();
mutex.lock();
try {
final byte[] header = send_crypto.getPacketHeader(unencrypted.length);
MapleCustomEncryption.encryptData(unencrypted); // Encrypting Data
send_crypto.crypt(unencrypted); // Crypt it with IV
System.arraycopy(header, 0, ret, 0, 4); // Copy the header > "Ret", first 4 bytes
System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length); // Copy the unencrypted > "ret"
session.write(IoBuffer.wrap(ret));//除了第一次的封包發送, 其餘使用 IoSession 而不是 ProtocolEncoderOutput
} finally {
mutex.unlock();
}
} else { // no client object created yet, send unencrypted (hello)
out.write(IoBuffer.wrap(((byte[]) message)));
}
}
不知道這樣修改對不對,我有雙開上線測試打怪了一小時左右,沒有出現斷開連接的情況了!很感謝你的幫助!!! |
|