Restructure "net" packages
This commit is contained in:
@@ -31,7 +31,7 @@ import net.MaplePacketHandler;
|
||||
import net.PacketProcessor;
|
||||
import net.netty.InvalidPacketHeaderException;
|
||||
import net.packet.logging.LoggingUtil;
|
||||
import net.packet.logging.PacketLogger;
|
||||
import net.packet.logging.MapleLogger;
|
||||
import net.packet.ByteBufOutPacket;
|
||||
import net.packet.InPacket;
|
||||
import net.packet.OutPacket;
|
||||
@@ -189,9 +189,10 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
if (handler != null && handler.validateState(this)) {
|
||||
// TODO: pass InPacket directly to handler once all handlers have been ported,
|
||||
// this is just a temporary workaround
|
||||
GenericSeekableLittleEndianAccessor accessor = new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(packet.getBytes()));
|
||||
final byte[] content = packet.getBytes();
|
||||
GenericSeekableLittleEndianAccessor accessor = new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(content));
|
||||
try {
|
||||
MapleLogger.logRecv(this, opcode, msg);
|
||||
MapleLogger.logRecv(this, opcode, content);
|
||||
handler.handlePacket(accessor, this);
|
||||
} catch (final Throwable t) {
|
||||
FilePrinter.printError(FilePrinter.PACKET_HANDLER + handler.getClass().getName() + ".txt", t, "Error for " + (getPlayer() == null ? "" : "player ; " + getPlayer() + " on map ; " + getPlayer().getMapId() + " - ") + "account ; " + getAccountName() + "\r\n" + accessor);
|
||||
|
||||
@@ -26,7 +26,7 @@ import client.MapleCharacter;
|
||||
import config.YamlConfig;
|
||||
import net.server.Server;
|
||||
import tools.FilePrinter;
|
||||
import tools.MapleLogger;
|
||||
import net.packet.logging.MapleLogger;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.command.Command;
|
||||
import net.server.Server;
|
||||
import tools.MapleLogger;
|
||||
import net.packet.logging.MapleLogger;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
public class IgnoreCommand extends Command {
|
||||
|
||||
@@ -26,7 +26,7 @@ package client.command.commands.gm3;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.command.Command;
|
||||
import tools.MapleLogger;
|
||||
import net.packet.logging.MapleLogger;
|
||||
|
||||
public class IgnoredCommand extends Command {
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.command.Command;
|
||||
import net.server.Server;
|
||||
import tools.MapleLogger;
|
||||
import net.packet.logging.MapleLogger;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
public class MonitorCommand extends Command {
|
||||
|
||||
@@ -26,7 +26,7 @@ package client.command.commands.gm3;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import client.command.Command;
|
||||
import tools.MapleLogger;
|
||||
import net.packet.logging.MapleLogger;
|
||||
|
||||
public class MonitorsCommand extends Command {
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.netty;
|
||||
package net.encryption;
|
||||
|
||||
import constants.net.ServerConstants;
|
||||
import tools.MapleAESOFB;
|
||||
|
||||
public class ClientCyphers {
|
||||
private final MapleAESOFB send;
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.netty;
|
||||
package net.encryption;
|
||||
|
||||
public class InitializationVector {
|
||||
private final byte[] bytes;
|
||||
@@ -19,11 +19,11 @@
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package tools;
|
||||
package net.encryption;
|
||||
|
||||
import net.netty.InitializationVector;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import tools.HexTool;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.netty;
|
||||
package net.encryption;
|
||||
|
||||
import io.netty.channel.CombinedChannelDuplexHandler;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package net.netty;
|
||||
package net.encryption;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ReplayingDecoder;
|
||||
import net.MapleCustomEncryption;
|
||||
import net.netty.InvalidPacketHeaderException;
|
||||
import net.packet.ByteBufInPacket;
|
||||
import tools.MapleAESOFB;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package net.netty;
|
||||
package net.encryption;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import net.MapleCustomEncryption;
|
||||
import net.packet.OutPacket;
|
||||
import tools.MapleAESOFB;
|
||||
|
||||
public class PacketEncoder extends MessageToByteEncoder<OutPacket> {
|
||||
private final MapleAESOFB sendCypher;
|
||||
@@ -9,6 +9,9 @@ import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import net.encryption.ClientCyphers;
|
||||
import net.encryption.InitializationVector;
|
||||
import net.encryption.PacketCodec;
|
||||
import net.packet.logging.InPacketLogger;
|
||||
import net.packet.logging.OutPacketLogger;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
72
src/main/java/net/packet/logging/MapleLogger.java
Normal file
72
src/main/java/net/packet/logging/MapleLogger.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation. You may not use, modify
|
||||
or distribute this program under any other version of the
|
||||
GNU Affero General Public License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.packet.logging;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.opcodes.RecvOpcode;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
import tools.FilePrinter;
|
||||
import tools.HexTool;
|
||||
|
||||
/**
|
||||
* Logs packets to console and file.
|
||||
*
|
||||
* @author Alan (SharpAceX)
|
||||
*/
|
||||
|
||||
public class MapleLogger {
|
||||
public static final Set<Integer> monitored = new HashSet<>();
|
||||
public static final Set<Integer> ignored = new HashSet<>();
|
||||
|
||||
public static void logRecv(MapleClient c, short packetId, byte[] packetContent) {
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
if (chr == null) {
|
||||
return;
|
||||
}
|
||||
if (!monitored.contains(chr.getId())) {
|
||||
return;
|
||||
}
|
||||
RecvOpcode op = getOpcodeFromValue(packetId);
|
||||
if (isRecvBlocked(op)) {
|
||||
return;
|
||||
}
|
||||
String packet = op + "\r\n" + HexTool.toString(packetContent);
|
||||
FilePrinter.printError(FilePrinter.PACKET_LOGS + c.getAccountName() + "-" + chr.getName() + ".txt", packet);
|
||||
}
|
||||
|
||||
private static boolean isRecvBlocked(RecvOpcode op) {
|
||||
return switch (op) {
|
||||
case MOVE_PLAYER, GENERAL_CHAT, TAKE_DAMAGE, MOVE_PET, MOVE_LIFE, NPC_ACTION, FACE_EXPRESSION -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private static RecvOpcode getOpcodeFromValue(int value) {
|
||||
return Arrays.stream(RecvOpcode.values())
|
||||
.filter(opcode -> value == opcode.getValue())
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 ~ 2010 Patrick Huy <patrick.huy@frz.cc>
|
||||
Matthias Butz <matze@odinms.de>
|
||||
Jan Christian Meyer <vimes@odinms.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License version 3
|
||||
as published by the Free Software Foundation. You may not use, modify
|
||||
or distribute this program under any other version of the
|
||||
GNU Affero General Public License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package tools;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.opcodes.RecvOpcode;
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
|
||||
/**
|
||||
* Logs packets to console and file.
|
||||
*
|
||||
* @author Alan (SharpAceX)
|
||||
*/
|
||||
|
||||
public class MapleLogger {
|
||||
|
||||
public static Set<Integer> monitored = new HashSet<>();
|
||||
public static Set<Integer> ignored = new HashSet<>();
|
||||
|
||||
public static void logRecv(MapleClient c, short packetId, Object message) {
|
||||
MapleCharacter chr = c.getPlayer();
|
||||
if (chr == null){
|
||||
return;
|
||||
}
|
||||
if (!monitored.contains(chr.getId())){
|
||||
return;
|
||||
}
|
||||
RecvOpcode op = getOpcodeFromValue(packetId);
|
||||
if (isRecvBlocked(op)){
|
||||
return;
|
||||
}
|
||||
String packet = op.toString() + "\r\n" + HexTool.toString((byte[]) message);
|
||||
FilePrinter.printError(FilePrinter.PACKET_LOGS + c.getAccountName() + "-" + chr.getName() + ".txt", packet);
|
||||
}
|
||||
|
||||
private static final boolean isRecvBlocked(RecvOpcode op){
|
||||
switch(op){
|
||||
case MOVE_PLAYER:
|
||||
case GENERAL_CHAT:
|
||||
case TAKE_DAMAGE:
|
||||
case MOVE_PET:
|
||||
case MOVE_LIFE:
|
||||
case NPC_ACTION:
|
||||
case FACE_EXPRESSION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static final RecvOpcode getOpcodeFromValue(int value){
|
||||
for (RecvOpcode op : RecvOpcode.values()){
|
||||
if (op.getValue() == value){
|
||||
return op;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import constants.inventory.ItemConstants;
|
||||
import constants.skills.Buccaneer;
|
||||
import constants.skills.Corsair;
|
||||
import constants.skills.ThunderBreaker;
|
||||
import net.netty.InitializationVector;
|
||||
import net.encryption.InitializationVector;
|
||||
import net.opcodes.SendOpcode;
|
||||
import net.server.PlayerCoolDownValueHolder;
|
||||
import net.server.Server;
|
||||
|
||||
Reference in New Issue
Block a user