Commit b1d7b272 authored by tricid's avatar tricid

Just some comment cleaning/formatting.

Some of my comments were outdated and misleading
parent 170e136e
......@@ -17,10 +17,6 @@
* http://www.gnu.org/copyleft/gpl.html
*/
/*
* (Tricid) This is the first class in the pipeline that handles new connections. Right now I'm only
* using it to send the first packet that the client expects.
*/
package l1j.server.server.network;
import java.io.IOException;
......@@ -39,6 +35,10 @@ import l1j.server.server.datatables.IpTable;
import l1j.server.server.encryptions.ClientIdExistsException;
import l1j.server.server.encryptions.L1JEncryption;
/*
* (Tricid) This is the first class in the pipeline that handles new connections. Right now I'm only
* using it to send the first packet that the client expects.
*/
public class ChannelInit extends ChannelInitializer<Channel> {
private static Logger _log = LoggerFactory.getLogger(ChannelInit.class);
......@@ -63,34 +63,41 @@ public class ChannelInit extends ChannelInitializer<Channel> {
}
}
@Override
protected void initChannel(Channel channel) throws Exception {
String ip = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress().toString();
//check if banned, close and return if yes
// check if banned, close and return if yes
if (IpTable.getInstance().isBannedIp(ip)) {
channel.close();
return;
}
//check if connections from this IP exceed limits
// check if connections from this IP exceed limits
int ipcount = Collections.frequency(NetworkServer.getInstance().getIps(), ip);
if (ipcount >= Config.CONNECTIONS_PER_IP) {
channel.close();
return;
} else {
NetworkServer.getInstance().getIps().add(ip);
}
// prepare first packet buffer
final ByteBuf first = channel.alloc().buffer(FIRST_PACKET.length + 7);
// Prepare a new Client, replaces ClientThread
Client client = null;
try {
client = new Client(channel);
} catch (IOException e) {
// TODO Auto-generated catch block
_log.error("",e);
_log.error("", e);
}
// collections for connections in case we need to find it later
NetworkServer.getInstance().getClients().put(channel.id(), client);
long seed = 0x7C98BDFA; // 3.0 English Packet Seed
......@@ -109,9 +116,9 @@ public class ChannelInit extends ChannelInitializer<Channel> {
try {
client.set_clkey(L1JEncryption.initKeys(channel.id(), seed));
} catch (ClientIdExistsException e) {
_log.error("",e);
_log.error("", e);
}
channel.pipeline().addLast(new PacketDecoder(),new PacketDecrypter());
channel.pipeline().addLast(new PacketDecoder(), new PacketDecrypter());
}
......
......@@ -17,11 +17,6 @@
* http://www.gnu.org/copyleft/gpl.html
*/
/*
* (Tricid) New network server using netty. Rather than needing one thread per client we will now use a proper
* nio library and a producer/consumer model. On start up this results in a few more threads but in exchange requires no
* thread per client. So in theory 1 player of 1000 players the thread count stays the same and performance is better for it.
*/
package l1j.server.server.network;
import java.util.ArrayList;
......@@ -44,12 +39,18 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import l1j.server.Config;
/*
* (Tricid) New network server using netty. Rather than needing one thread per client we will now use a proper
* nio library and a producer/consumer model. On start up this results in a few more threads but in exchange requires no
* thread per client. So in theory 1 player or 1000 players the thread count stays the same and performance is better for it.
*/
public class NetworkServer implements Runnable {
Logger _log = LoggerFactory.getLogger(NetworkServer.class);
private static final NetworkServer instance = new NetworkServer();
private ArrayBlockingQueue<Client> clientQueue;
private ArrayList<String> ips = new ArrayList<String>();
private NetworkServer() {
}
......@@ -77,9 +78,8 @@ public class NetworkServer implements Runnable {
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
// Takes input data and once a complete packet is formed
// passes it along
// takes complete packets from above and decrypts them
// Only add the pipeline that sends the first packet
// It'll add the other pipelines when it's ready
ch.pipeline().addLast(new ChannelInit());
}
......
......@@ -17,6 +17,8 @@
* http://www.gnu.org/copyleft/gpl.html
*/
package l1j.server.server.network;
/*
* (Tricid) These are the packet consumers for the new network model. They try to pull from a queue that contains
* clients (not packets), blocking on the queue when it's empty. Once they get a client it runs a client method that
......@@ -27,11 +29,8 @@
* I might tweak how that works.
*
* Additionally, if I ever get motivated in the future to implement my speed hack fix I've done on other servers, this is
* the model it relies on.
* the model it relies on. It'll make sense when/if I implement it for l1j
*/
package l1j.server.server.network;
public class PacketConsumer implements Runnable {
String name;
......
......@@ -17,11 +17,6 @@
* http://www.gnu.org/copyleft/gpl.html
*/
/*
* (Tricid) This is the second class in the pipeline that handles packets (after ChannelInit).
* All this is doing is continually reading bytes until a proper packet is formed. Afterwards, it passes it
* to the next in the pipeline (the decrypter).
*/
package l1j.server.server.network;
import java.util.List;
......@@ -33,16 +28,15 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
/*
* (Tricid) This is the second class in the pipeline that handles packets (after ChannelInit).
* All this is doing is continually reading bytes until a proper packet is formed. Afterwards, it passes it
* to the next in the pipeline (the decrypter).
*/
public class PacketDecoder extends ByteToMessageDecoder {
Logger _log = LoggerFactory.getLogger(PacketDecoder.class);
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
// TODO Auto-generated method stub
}
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
// its likely already closed at this point
......@@ -71,16 +65,11 @@ public class PacketDecoder extends ByteToMessageDecoder {
_log.error("", e);
}
}
NetworkServer.getInstance().getIps().remove(client.getIp());
NetworkServer.getInstance().getClients().remove(ctx.channel().id());
}
@Override
public void channelActive(final ChannelHandlerContext ctx) {
}
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
int dataLength = 0;
if (in.readableBytes() >= 2) {
......
......@@ -17,10 +17,6 @@
* http://www.gnu.org/copyleft/gpl.html
*/
/*
* (Tricid) The last step in the pipeline. This class should receive only complete packets/frames to decrypt then pass along
* to the queue to be processed.
*/
package l1j.server.server.network;
import org.slf4j.Logger;
......@@ -31,6 +27,10 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
import l1j.server.server.encryptions.L1JEncryption;
import l1j.server.server.encryptions.NoEncryptionKeysSelectedException;
/*
* (Tricid) The last step in the pipeline. This class should receive only complete packets/frames to decrypt then pass along
* to the queue to be processed.
*/
public class PacketDecrypter extends ChannelInboundHandlerAdapter {
private static Logger _log = LoggerFactory.getLogger(PacketDecrypter.class);
......@@ -49,11 +49,11 @@ public class PacketDecrypter extends ChannelInboundHandlerAdapter {
NetworkServer.getInstance().getClientQueue().offer(client);
} catch (NoEncryptionKeysSelectedException e) {
// TODO Auto-generated catch block
_log.error("",e);
_log.error("", e);
}
}
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
// its likely already closed at this point
......
......@@ -205,35 +205,35 @@ import l1j.server.server.serverpackets.S_SystemMessage;
// Referenced classes of package l1j.server.server:
// Opcodes, LoginController, Client, Logins
public class PacketHandler {
private static Logger _log =LoggerFactory .getLogger(PacketHandler.class.getName());
private static Logger _log = LoggerFactory.getLogger(PacketHandler.class.getName());
private final Client _client;
public PacketHandler(Client client) {
_client = client;
}
public void handlePacket(byte abyte0[], L1PcInstance object)
throws Exception {
public void handlePacket(byte abyte0[], L1PcInstance object) throws Exception {
int i = abyte0[0] & 0xff;
if (Config.LOGGING_INCOMING_PACKETS) {
_log.info("Packet sent from client: " + i);
if (_client.getActiveChar() != null) {
if (_client.getActiveChar().isGm()) {
_client.getActiveChar().sendPackets(
new S_SystemMessage("Sent from client: " + i));
_client.getActiveChar().sendPackets(new S_SystemMessage("Sent from client: " + i));
}
}
}
_client.setLastClientPacket(i);
// String packet = IntArrayUtil.toCsv(ByteArrayUtil.convertToInt(abyte0));
if(object != null && object.isLoggingPackets()) {
//LogPacketsTable.storeLogPacket(object.getId(), object.getName(), object.getTempCharGfx(), i, packet, "report", System.currentTimeMillis());
if (object != null && object.isLoggingPackets()) {
// LogPacketsTable.storeLogPacket(object.getId(), object.getName(),
// object.getTempCharGfx(), i, packet, "report", System.currentTimeMillis());
} else {
//_client.addToClientPacketLog(i, packet); // only add to the historical log if we aren't logging to the database
// _client.addToClientPacketLog(i, packet); // only add to the historical log if
// we aren't logging to the database
}
switch (i) {
case C_OPCODE_EXCLUDE:
new C_Exclude(abyte0, _client);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment