ronancpl / HeavenMS

An improved server based on MapleSolaxia (v83 MapleStory private server)
GNU Affero General Public License v3.0
1.03k stars 742 forks source link

New USE_DEBUG_SHOW_PACKET #435

Closed Atoot closed 5 years ago

Atoot commented 5 years ago

\src\constants\ServerConstants.java Add: public static boolean USE_DEBUG_SHOW_PACKET = true;

\src\tools\HexTool.java

Add: public static final String toStringFromAscii(final byte[] bytes) { byte[] ret = new byte[bytes.length]; for (int x = 0; x < bytes.length; x++) { if (bytes[x] < 32 && bytes[x] >= 0) { ret[x] = '.'; } else { int chr = ((short) bytes[x]) & 0xFF; ret[x] = (byte) chr; } } String encode = "GBK"; try { String str = new String(ret, encode); return str; } catch (Exception e) { } return ""; }

\src\net\mina\MaplePacketDecoder.java search: out.write(decryptedPacket);

Modified to: out.write(decryptedPacket); if(ServerConstants.USE_DEBUG_SHOW_PACKET){ int packetLen = decryptedPacket.length; int pHeader = readFirstShort(decryptedPacket); String pHeaderStr = Integer.toHexString(pHeader).toUpperCase(); String op = lookupSend(pHeader); String Send = "ClientSend:" + op + " [" + pHeaderStr + "] (" + packetLen + ")\r\n"; if (packetLen <= 3000) { String SendTo = Send + HexTool.toString(decryptedPacket) + "\r\n" + HexTool.toStringFromAscii(decryptedPacket); System.out.println(SendTo); if (op.equals("UNKNOWN")) { System.out.println("UnknownPacket:" + SendTo); } } else { log.info(HexTool.toString(new byte[]{decryptedPacket[0], decryptedPacket[1]}) + "..."); } }

Add: private String lookupSend(int val) { for (RecvOpcode op : RecvOpcode.values()) { if (op.getValue() == val) { return op.name(); } } return "UNKNOWN"; }

private int readFirstShort(byte[] arr) { return new GenericLittleEndianAccessor(new ByteArrayByteStream(arr)).readShort(); }

\src\net\mina\MaplePacketEncoder.java search: final byte[] input = (byte[]) message; Modified to: final byte[] input = (byte[]) message; if(ServerConstants.USE_DEBUG_SHOW_PACKET){ int packetLen = input.length; int pHeader = readFirstShort(input); String pHeaderStr = Integer.toHexString(pHeader).toUpperCase(); String op = lookupRecv(pHeader); String Recv = "ServerSend:" + op + " [" + pHeaderStr + "] (" + packetLen + ")\r\n"; if (packetLen <= 50000) { String RecvTo = Recv + HexTool.toString(input) + "\r\n" + HexTool.toStringFromAscii(input); System.out.println(RecvTo); if (op.equals("UNKNOWN")) { System.out.println("UnknownPacket:" + RecvTo); } } else { log.info(HexTool.toString(new byte[]{input[0], input[1]}) + " ..."); } }

add: private String lookupRecv(int val) { for (SendOpcode op : SendOpcode.values()) { if (op.getValue() == val) { return op.name(); } } return "UNKNOWN"; }

private int readFirstShort(byte[] arr) { return new GenericLittleEndianAccessor(new ByteArrayByteStream(arr)).readShort(); }

ronancpl commented 5 years ago

Duplicate issue from #423.