Clean up Apache Mina, goodbye!
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -46,11 +46,6 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Networking -->
|
||||
<dependency>
|
||||
<groupId>org.apache.mina</groupId>
|
||||
<artifactId>mina-core</artifactId>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport</artifactId>
|
||||
|
||||
@@ -52,7 +52,6 @@ import net.server.services.task.world.CharacterSaveService;
|
||||
import net.server.services.type.ChannelServices;
|
||||
import net.server.services.type.WorldServices;
|
||||
import net.server.world.*;
|
||||
import org.apache.mina.util.ConcurrentHashSet;
|
||||
import scripting.AbstractPlayerInteraction;
|
||||
import scripting.event.EventInstanceManager;
|
||||
import scripting.item.ItemScriptManager;
|
||||
@@ -85,6 +84,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
@@ -177,7 +177,7 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
|
||||
private final Map<Short, MapleQuestStatus> quests;
|
||||
private Set<MapleMonster> controlled = new LinkedHashSet<>();
|
||||
private Map<Integer, String> entered = new LinkedHashMap<>();
|
||||
private Set<MapleMapObject> visibleMapObjects = new ConcurrentHashSet<>();
|
||||
private Set<MapleMapObject> visibleMapObjects = Collections.newSetFromMap(new ConcurrentHashMap<>());
|
||||
private Map<Skill, SkillEntry> skills = new LinkedHashMap<>();
|
||||
private Map<Integer, Integer> activeCoupons = new LinkedHashMap<>();
|
||||
private Map<Integer, Integer> activeCouponRates = new LinkedHashMap<>();
|
||||
|
||||
@@ -45,7 +45,6 @@ import net.server.coordinator.session.MapleSessionCoordinator.AntiMulticlientRes
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.world.*;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import scripting.AbstractPlayerInteraction;
|
||||
@@ -86,10 +85,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
public static final int LOGIN_NOTLOGGEDIN = 0;
|
||||
public static final int LOGIN_SERVER_TRANSITION = 1;
|
||||
public static final int LOGIN_LOGGEDIN = 2;
|
||||
public static final String CLIENT_KEY = "CLIENT";
|
||||
public static final String CLIENT_HWID = "HWID";
|
||||
public static final String CLIENT_NIBBLEHWID = "HWID2";
|
||||
public static final String CLIENT_REMOTE_ADDRESS = "REMOTE_IP";
|
||||
|
||||
private final Type type;
|
||||
|
||||
@@ -98,9 +93,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
private String remoteAddress;
|
||||
private volatile boolean inTransition;
|
||||
|
||||
private MapleAESOFB send;
|
||||
private MapleAESOFB receive;
|
||||
|
||||
private io.netty.channel.Channel ioChannel;
|
||||
private PacketProcessor packetProcessor;
|
||||
private MapleCharacter player;
|
||||
@@ -158,12 +150,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public MapleClient(MapleAESOFB send, MapleAESOFB receive, IoSession session) {
|
||||
this.type = null;
|
||||
this.send = send;
|
||||
this.receive = receive;
|
||||
}
|
||||
|
||||
public static MapleClient createMock() {
|
||||
return new MapleClient(null, null, -123, -123);
|
||||
}
|
||||
@@ -275,14 +261,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
ioChannel.disconnect();
|
||||
}
|
||||
|
||||
public MapleAESOFB getReceiveCrypto() {
|
||||
return receive;
|
||||
}
|
||||
|
||||
public MapleAESOFB getSendCrypto() {
|
||||
return send;
|
||||
}
|
||||
|
||||
public Hwid getHwid() {
|
||||
return hwid;
|
||||
}
|
||||
@@ -1097,9 +1075,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
this.birthday = null;
|
||||
this.engines = null;
|
||||
this.player = null;
|
||||
this.receive = null;
|
||||
this.send = null;
|
||||
//this.session = null;
|
||||
}
|
||||
|
||||
public void setCharacterOnSessionTransitionState(int cid) {
|
||||
@@ -1171,11 +1146,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
lastPong = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void testPing(long timeThen) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void checkIfIdle(final IdleStateEvent event) {
|
||||
final long pingedAt = System.currentTimeMillis();
|
||||
announce(MaplePacketCreator.getPing());
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
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.mina;
|
||||
package net;
|
||||
|
||||
public class MapleCustomEncryption {
|
||||
private static byte rollLeft(byte in, int count) {
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 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 as
|
||||
published by the Free Software Foundation 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.mina;
|
||||
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import org.apache.mina.filter.codec.ProtocolCodecFactory;
|
||||
import org.apache.mina.filter.codec.ProtocolDecoder;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoder;
|
||||
|
||||
public class MapleCodecFactory implements ProtocolCodecFactory {
|
||||
private final ProtocolEncoder encoder;
|
||||
private final ProtocolDecoder decoder;
|
||||
|
||||
public MapleCodecFactory() {
|
||||
encoder = new MaplePacketEncoder();
|
||||
decoder = new MaplePacketDecoder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolEncoder getEncoder(IoSession session) throws Exception {
|
||||
return encoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolDecoder getDecoder(IoSession session) throws Exception {
|
||||
return decoder;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 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 as
|
||||
published by the Free Software Foundation 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.mina;
|
||||
|
||||
import client.MapleClient;
|
||||
import config.YamlConfig;
|
||||
import constants.net.OpcodeConstants;
|
||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
|
||||
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
|
||||
import tools.FilePrinter;
|
||||
import tools.HexTool;
|
||||
import tools.MapleAESOFB;
|
||||
import tools.data.input.ByteArrayByteStream;
|
||||
import tools.data.input.GenericLittleEndianAccessor;
|
||||
|
||||
public class MaplePacketDecoder extends CumulativeProtocolDecoder {
|
||||
private static final String DECODER_STATE_KEY = MaplePacketDecoder.class.getName() + ".STATE";
|
||||
|
||||
private static class DecoderState {
|
||||
public int packetlength = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
|
||||
final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
|
||||
if(client == null) {
|
||||
MapleSessionCoordinator.getInstance().closeSession(MapleClient.getPlaceholder(), true);
|
||||
return false;
|
||||
}
|
||||
|
||||
DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);
|
||||
if (decoderState == null) {
|
||||
decoderState = new DecoderState();
|
||||
session.setAttribute(DECODER_STATE_KEY, decoderState);
|
||||
}
|
||||
|
||||
MapleAESOFB rcvdCrypto = client.getReceiveCrypto();
|
||||
if (in.remaining() >= 4 && decoderState.packetlength == -1) {
|
||||
int packetHeader = in.getInt();
|
||||
if (!rcvdCrypto.isValidHeader(packetHeader)) {
|
||||
MapleSessionCoordinator.getInstance().closeSession(MapleClient.getPlaceholder(), true);
|
||||
return false;
|
||||
}
|
||||
decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
|
||||
} else if (in.remaining() < 4 && decoderState.packetlength == -1) {
|
||||
return false;
|
||||
}
|
||||
if (in.remaining() >= decoderState.packetlength) {
|
||||
byte[] decryptedPacket = new byte[decoderState.packetlength];
|
||||
in.get(decryptedPacket, 0, decoderState.packetlength);
|
||||
decoderState.packetlength = -1;
|
||||
rcvdCrypto.crypt(decryptedPacket);
|
||||
MapleCustomEncryption.decryptData(decryptedPacket);
|
||||
out.write(decryptedPacket);
|
||||
if (YamlConfig.config.server.USE_DEBUG_SHOW_PACKET){ // Atoot's idea: packet traffic log, applied using auto-identation thanks to lrenex
|
||||
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 == null) {
|
||||
System.out.println("UnknownPacket:" + SendTo);
|
||||
}
|
||||
} else {
|
||||
FilePrinter.print(FilePrinter.PACKET_STREAM + ".txt", HexTool.toString(new byte[]{decryptedPacket[0], decryptedPacket[1]}) + "...");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String lookupSend(int val) {
|
||||
return OpcodeConstants.recvOpcodeNames.get(val);
|
||||
}
|
||||
|
||||
private int readFirstShort(byte[] arr) {
|
||||
return new GenericLittleEndianAccessor(new ByteArrayByteStream(arr)).readShort();
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
This file is part of the OdinMS Maple Story Server
|
||||
Copyright (C) 2008 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 as
|
||||
published by the Free Software Foundation 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.mina;
|
||||
|
||||
import client.MapleClient;
|
||||
import config.YamlConfig;
|
||||
import constants.net.OpcodeConstants;
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
import org.apache.mina.core.session.IoSession;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoder;
|
||||
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
|
||||
import tools.FilePrinter;
|
||||
import tools.HexTool;
|
||||
import tools.MapleAESOFB;
|
||||
import tools.data.input.ByteArrayByteStream;
|
||||
import tools.data.input.GenericLittleEndianAccessor;
|
||||
|
||||
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);
|
||||
|
||||
try {
|
||||
if (client.tryacquireEncoder()) {
|
||||
try {
|
||||
final MapleAESOFB send_crypto = client.getSendCrypto();
|
||||
final byte[] input = (byte[]) message;
|
||||
if (YamlConfig.config.server.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 == null) {
|
||||
System.out.println("UnknownPacket:" + RecvTo);
|
||||
}
|
||||
} else {
|
||||
FilePrinter.print(FilePrinter.PACKET_STREAM + ".txt", HexTool.toString(new byte[]{input[0], input[1]}) + " ...");
|
||||
}
|
||||
}
|
||||
|
||||
final byte[] unencrypted = new byte[input.length];
|
||||
System.arraycopy(input, 0, unencrypted, 0, input.length);
|
||||
final byte[] ret = new byte[unencrypted.length + 4];
|
||||
final byte[] header = send_crypto.getPacketHeader(unencrypted.length);
|
||||
MapleCustomEncryption.encryptData(unencrypted);
|
||||
|
||||
send_crypto.crypt(unencrypted);
|
||||
System.arraycopy(header, 0, ret, 0, 4);
|
||||
System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);
|
||||
|
||||
out.write(IoBuffer.wrap(ret));
|
||||
} finally {
|
||||
client.unlockEncoder();
|
||||
}
|
||||
}
|
||||
// System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);
|
||||
// out.write(ByteBuffer.wrap(ret));
|
||||
} catch (NullPointerException npe) {
|
||||
out.write(IoBuffer.wrap(((byte[]) message)));
|
||||
}
|
||||
}
|
||||
|
||||
private String lookupRecv(int val) {
|
||||
return OpcodeConstants.sendOpcodeNames.get(val);
|
||||
}
|
||||
|
||||
private int readFirstShort(byte[] arr) {
|
||||
return new GenericLittleEndianAccessor(new ByteArrayByteStream(arr)).readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(IoSession session) throws Exception {}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ReplayingDecoder;
|
||||
import net.mina.MapleCustomEncryption;
|
||||
import net.MapleCustomEncryption;
|
||||
import net.packet.ByteBufInPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import net.mina.MapleCustomEncryption;
|
||||
import net.MapleCustomEncryption;
|
||||
import net.packet.ByteBufInPacket;
|
||||
import net.packet.OutPacket;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
Reference in New Issue
Block a user