New networking.
This commit is contained in:
parent
6217f0ded2
commit
837f21af8d
@ -6,11 +6,6 @@
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="dist/libs/mariadb-java-client-2.7.5.jar" sourcepath="dist/libs/mariadb-java-client-2.7.5-sources.jar"/>
|
||||
<classpathentry kind="lib" path="dist/libs/netty-buffer-4.1.75.Final.jar" sourcepath="dist/libs/netty-buffer-4.1.75.Final-sources.jar"/>
|
||||
<classpathentry kind="lib" path="dist/libs/netty-codec-4.1.75.Final.jar" sourcepath="dist/libs/netty-codec-4.1.75.Final-sources.jar"/>
|
||||
<classpathentry kind="lib" path="dist/libs/netty-common-4.1.75.Final.jar" sourcepath="dist/libs/netty-common-4.1.75.Final-sources.jar"/>
|
||||
<classpathentry kind="lib" path="dist/libs/netty-handler-4.1.75.Final.jar" sourcepath="dist/libs/netty-handler-4.1.75.Final-sources.jar"/>
|
||||
<classpathentry kind="lib" path="dist/libs/netty-transport-4.1.75.Final.jar" sourcepath="dist/libs/netty-transport-4.1.75.Final-sources.jar"/>
|
||||
<classpathentry including="**/*.java" kind="src" path="dist/game/data/scripts"/>
|
||||
<classpathentry kind="src" path="java"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
|
@ -31,6 +31,49 @@ GameserverHostname = 0.0.0.0
|
||||
# Default: 7777
|
||||
GameserverPort = 7777
|
||||
|
||||
# Client pool size for reading client packets.
|
||||
# Each pool is executed on a separate thread.
|
||||
# Default: 100
|
||||
ClientReadPoolSize = 100
|
||||
|
||||
# Client pool size for executing client packets.
|
||||
# Each pool is executed on a separate thread.
|
||||
# Default: 50
|
||||
ClientExecutePoolSize = 50
|
||||
|
||||
# Expected client packet count queued by the server.
|
||||
# Default: 80
|
||||
PacketQueueLimit = 80
|
||||
|
||||
# Disconnect client when queue has reached the queue packet limit.
|
||||
# Default: False
|
||||
PacketFloodDisconnect = False
|
||||
|
||||
# Drop packets when queue has reached the queue packet limit.
|
||||
# Default: False
|
||||
PacketFloodDrop = False
|
||||
|
||||
# Log message when queue has reached the queue packet limit.
|
||||
# Default: True
|
||||
PacketFloodLogged = True
|
||||
|
||||
# Nagle's algorithm tries to conserve bandwidth by minimizing the number of segments that are sent.
|
||||
# When applications wish to decrease network latency, they can disable Nagle's algorithm (by enabling TcpNoDelay).
|
||||
# Data will be sent earlier, at the cost of an increase in bandwidth consumption.
|
||||
# Default: True (disabled)
|
||||
TcpNoDelay = True
|
||||
|
||||
# Connection timeout in milliseconds.
|
||||
# Default 800
|
||||
ConnectionTimeout = 800
|
||||
|
||||
# Packet encryption.
|
||||
# By default packets sent or received are encrypted using the Blowfish algorithm.
|
||||
# Disabling this reduces the resources needed to process any packets transfered,
|
||||
# also broadcasted packets do not need to be re-encrypted for each client sent.
|
||||
# Retail: True
|
||||
PacketEncryption = False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Database
|
||||
@ -130,8 +173,11 @@ InstantThreadPoolCount = -1
|
||||
# Specifies how many threads will be in a single instant pool.
|
||||
ThreadsPerInstantThreadPool = 2
|
||||
|
||||
# Urgent packet thread core size.
|
||||
UrgentPacketThreadCoreSize = -1
|
||||
# Use threads to run client packets individually.
|
||||
# Less lag when using threads, but more CPU consumption.
|
||||
# Can try disabling it when server is highly populated and CPU is high.
|
||||
# Default: True
|
||||
ThreadsForClientPackets = True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
@ -1,35 +0,0 @@
|
||||
#=========================#
|
||||
# Telnet Properties #
|
||||
#=========================#
|
||||
# ----------------------------------------------------------------------------------------------------------------------------------
|
||||
# The defaults are set to be retail-like.
|
||||
# If you modify any of these settings your server will deviate from being retail-like.
|
||||
# Warning:
|
||||
# Please take extreme caution when changing anything.
|
||||
# Also please understand what you are changing before you do so on a live server.
|
||||
# ---------------------------------------------------------------------------------------------------------------------------------
|
||||
# Allows text based monitoring and administration of L2J GS/LS
|
||||
# by using a telnet client. Communication protocol is insecure
|
||||
# and you should use SSL tunnels, VPN, etc. if you plan to connect
|
||||
# over non-trusted channels.
|
||||
# Default: False
|
||||
EnableTelnet = False
|
||||
|
||||
# This is the port L2J should listen to for incoming telnet
|
||||
# requests.
|
||||
# Default: 12345
|
||||
StatusPort = 12345
|
||||
|
||||
# If the following is not set, a random password is generated on server startup.
|
||||
# Usage: StatusPW = somePass
|
||||
|
||||
# This list can contain IPs or Hosts of clients you wish to allow. Hostnames must be resolvable to an IP.
|
||||
# Example: 0.0.0.0,host,0.0.0.1,host2,host3,host4,0.0.0.3
|
||||
# Make sure that the link between the address / hosts no spaces
|
||||
ListOfHosts = 127.0.0.1,localhost
|
||||
|
||||
# On / off the generation of complex passwords
|
||||
SuperPass = False
|
||||
|
||||
# Size-generated password
|
||||
LengthPass = 10
|
@ -44,8 +44,8 @@ import org.l2jmobius.gameserver.model.quest.Quest;
|
||||
import org.l2jmobius.gameserver.model.spawn.Spawn;
|
||||
import org.l2jmobius.gameserver.model.zone.type.BossZone;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.Earthquake;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PlaySound;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SpecialCamera;
|
||||
|
||||
/**
|
||||
@ -522,7 +522,7 @@ public class Antharas extends Quest
|
||||
}
|
||||
}
|
||||
|
||||
protected void broadcastPacket(IClientOutgoingPacket mov)
|
||||
protected void broadcastPacket(ServerPacket packet)
|
||||
{
|
||||
if (_zone != null)
|
||||
{
|
||||
@ -530,7 +530,7 @@ public class Antharas extends Quest
|
||||
{
|
||||
if (creatures instanceof Player)
|
||||
{
|
||||
creatures.sendPacket(mov);
|
||||
creatures.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
L2J_Mobius_C6_Interlude/dist/game/java.cfg
vendored
2
L2J_Mobius_C6_Interlude/dist/game/java.cfg
vendored
@ -1 +1 @@
|
||||
-server -Dfile.encoding=UTF-8 -Djava.util.logging.manager=org.l2jmobius.log.ServerLogManager -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Xmx4g -Xms2g
|
||||
-server -Dfile.encoding=UTF-8 -Djava.util.logging.manager=org.l2jmobius.log.ServerLogManager -Xmx4g -Xms2g
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,35 +0,0 @@
|
||||
#=========================#
|
||||
# Telnet Properties #
|
||||
#=========================#
|
||||
# ----------------------------------------------------------------------------------------------------------------------------------
|
||||
# The defaults are set to be retail-like.
|
||||
# If you modify any of these settings your server will deviate from being retail-like.
|
||||
# Warning:
|
||||
# Please take extreme caution when changing anything.
|
||||
# Also please understand what you are changing before you do so on a live server.
|
||||
# ---------------------------------------------------------------------------------------------------------------------------------
|
||||
# Allows text based monitoring and administration of L2J GS/LS
|
||||
# by using a telnet client. Communication protocol is insecure
|
||||
# and you should use SSL tunnels, VPN, etc. if you plan to connect
|
||||
# over non-trusted channels.
|
||||
# Default: False
|
||||
EnableTelnet = False
|
||||
|
||||
# This is the port L2J should listen to for incoming telnet
|
||||
# requests.
|
||||
# Default: 12345
|
||||
StatusPort = 12345
|
||||
|
||||
# If the following is not set, a random password is generated on server startup.
|
||||
# Usage: StatusPW = somePass
|
||||
|
||||
# This list can contain IPs or Hosts of clients you wish to allow. Hostnames must be resolvable to an IP.
|
||||
# Example: 0.0.0.0,host,0.0.0.1,host2,host3,host4,0.0.0.3
|
||||
# Make sure that the link between the address / hosts no spaces
|
||||
ListOfHosts = 127.0.0.1,localhost
|
||||
|
||||
# On / off the generation of complex passwords
|
||||
SuperPass = False
|
||||
|
||||
# Size-generated password
|
||||
LengthPass = 10
|
2
L2J_Mobius_C6_Interlude/dist/login/java.cfg
vendored
2
L2J_Mobius_C6_Interlude/dist/login/java.cfg
vendored
@ -1 +1 @@
|
||||
-server -Dfile.encoding=UTF-8 -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Xms128m -Xmx256m
|
||||
-server -Dfile.encoding=UTF-8 -Xms128m -Xmx256m
|
@ -93,7 +93,6 @@ public class Config
|
||||
private static final String SERVER_CONFIG_FILE = "./config/Server.ini";
|
||||
private static final String SEVENSIGNS_CONFIG_FILE = "./config/SevenSigns.ini";
|
||||
public static final String SIEGE_CONFIG_FILE = "./config/Siege.ini";
|
||||
public static final String TELNET_CONFIG_FILE = "./config/Telnet.ini";
|
||||
// custom
|
||||
private static final String BANK_CONFIG_FILE = "./config/custom/Bank.ini";
|
||||
private static final String BOSS_ANNOUNCEMENTS_CONFIG_FILE = "./config/custom/BossAnnouncements.ini";
|
||||
@ -227,8 +226,6 @@ public class Config
|
||||
public static int BACKUP_DAYS;
|
||||
public static boolean RESERVE_HOST_ON_LOGIN = false;
|
||||
|
||||
public static boolean IS_TELNET_ENABLED;
|
||||
|
||||
public static boolean JAIL_IS_PVP;
|
||||
public static boolean JAIL_DISABLE_CHAT;
|
||||
public static int WYVERN_SPEED;
|
||||
@ -1088,6 +1085,15 @@ public class Config
|
||||
public static String GAME_SERVER_LOGIN_HOST;
|
||||
public static List<String> GAME_SERVER_SUBNETS;
|
||||
public static List<String> GAME_SERVER_HOSTS;
|
||||
public static int CLIENT_READ_POOL_SIZE;
|
||||
public static int CLIENT_EXECUTE_POOL_SIZE;
|
||||
public static int PACKET_QUEUE_LIMIT;
|
||||
public static boolean PACKET_FLOOD_DISCONNECT;
|
||||
public static boolean PACKET_FLOOD_DROP;
|
||||
public static boolean PACKET_FLOOD_LOGGED;
|
||||
public static boolean TCP_NO_DELAY;
|
||||
public static int CONNECTION_TIMEOUT;
|
||||
public static boolean PACKET_ENCRYPTION;
|
||||
public static int REQUEST_ID;
|
||||
public static boolean ACCEPT_ALTERNATE_ID;
|
||||
public static File DATAPACK_ROOT;
|
||||
@ -1101,7 +1107,7 @@ public class Config
|
||||
public static int THREADS_PER_SCHEDULED_THREAD_POOL;
|
||||
public static int INSTANT_THREAD_POOL_COUNT;
|
||||
public static int THREADS_PER_INSTANT_THREAD_POOL;
|
||||
public static int IO_PACKET_THREAD_CORE_SIZE;
|
||||
public static boolean THREADS_FOR_CLIENT_PACKETS;
|
||||
public static boolean DEADLOCK_DETECTOR;
|
||||
public static int DEADLOCK_CHECK_INTERVAL;
|
||||
public static boolean RESTART_ON_DEADLOCK;
|
||||
@ -1158,7 +1164,15 @@ public class Config
|
||||
PORT_GAME = serverConfig.getInt("GameserverPort", 7777);
|
||||
GAME_SERVER_LOGIN_PORT = serverConfig.getInt("LoginPort", 9014);
|
||||
GAME_SERVER_LOGIN_HOST = serverConfig.getString("LoginHost", "127.0.0.1");
|
||||
|
||||
CLIENT_READ_POOL_SIZE = serverConfig.getInt("ClientReadPoolSize", 100);
|
||||
CLIENT_EXECUTE_POOL_SIZE = serverConfig.getInt("ClientExecutePoolSize", 50);
|
||||
PACKET_QUEUE_LIMIT = serverConfig.getInt("PacketQueueLimit", 80);
|
||||
PACKET_FLOOD_DISCONNECT = serverConfig.getBoolean("PacketFloodDisconnect", false);
|
||||
PACKET_FLOOD_DROP = serverConfig.getBoolean("PacketFloodDrop", false);
|
||||
PACKET_FLOOD_LOGGED = serverConfig.getBoolean("PacketFloodLogged", true);
|
||||
TCP_NO_DELAY = serverConfig.getBoolean("TcpNoDelay", true);
|
||||
CONNECTION_TIMEOUT = serverConfig.getInt("ConnectionTimeout", 800);
|
||||
PACKET_ENCRYPTION = serverConfig.getBoolean("PacketEncryption", false);
|
||||
DATABASE_DRIVER = serverConfig.getString("Driver", "org.mariadb.jdbc.Driver");
|
||||
DATABASE_URL = serverConfig.getString("URL", "jdbc:mariadb://localhost/");
|
||||
DATABASE_LOGIN = serverConfig.getString("Login", "root");
|
||||
@ -1200,11 +1214,7 @@ public class Config
|
||||
INSTANT_THREAD_POOL_COUNT = Runtime.getRuntime().availableProcessors();
|
||||
}
|
||||
THREADS_PER_INSTANT_THREAD_POOL = serverConfig.getInt("ThreadsPerInstantThreadPool", 2);
|
||||
IO_PACKET_THREAD_CORE_SIZE = serverConfig.getInt("UrgentPacketThreadCoreSize", -1);
|
||||
if (IO_PACKET_THREAD_CORE_SIZE == -1)
|
||||
{
|
||||
IO_PACKET_THREAD_CORE_SIZE = Runtime.getRuntime().availableProcessors();
|
||||
}
|
||||
THREADS_FOR_CLIENT_PACKETS = serverConfig.getBoolean("ThreadsForClientPackets", true);
|
||||
DEADLOCK_DETECTOR = serverConfig.getBoolean("DeadLockDetector", true);
|
||||
DEADLOCK_CHECK_INTERVAL = serverConfig.getInt("DeadLockCheckInterval", 20);
|
||||
RESTART_ON_DEADLOCK = serverConfig.getBoolean("RestartOnDeadlock", false);
|
||||
@ -1232,12 +1242,6 @@ public class Config
|
||||
PRECAUTIONARY_RESTART_DELAY = serverConfig.getInt("PrecautionaryRestartDelay", 60) * 1000;
|
||||
}
|
||||
|
||||
public static void loadTelnetConfig()
|
||||
{
|
||||
final PropertiesParser telnetConfig = new PropertiesParser(TELNET_CONFIG_FILE);
|
||||
IS_TELNET_ENABLED = telnetConfig.getBoolean("EnableTelnet", false);
|
||||
}
|
||||
|
||||
public static void loadRatesConfig()
|
||||
{
|
||||
final PropertiesParser ratesConfig = new PropertiesParser(RATES_CONFIG_FILE);
|
||||
@ -3025,14 +3029,10 @@ public class Config
|
||||
final IPConfigData ipcd = new IPConfigData();
|
||||
GAME_SERVER_SUBNETS = ipcd.getSubnets();
|
||||
GAME_SERVER_HOSTS = ipcd.getHosts();
|
||||
|
||||
loadTelnetConfig();
|
||||
}
|
||||
else if (SERVER_MODE == ServerMode.LOGIN)
|
||||
{
|
||||
loadLoginStartConfig();
|
||||
|
||||
loadTelnetConfig();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -15,7 +15,7 @@
|
||||
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.l2jmobius.commons.util.crypt;
|
||||
package org.l2jmobius.commons.crypt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -14,7 +14,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.util.crypt;
|
||||
package org.l2jmobius.commons.crypt;
|
||||
|
||||
/**
|
||||
* Class to use a blowfish cipher with ECB processing.<br>
|
||||
@ -153,7 +153,7 @@ public class NewCrypt
|
||||
* @param size Length of the data to be encrypted
|
||||
* @param key The 4 bytes (int) XOR key
|
||||
*/
|
||||
static void encXORPass(byte[] raw, int offset, int size, int key)
|
||||
public static void encXORPass(byte[] raw, int offset, int size, int key)
|
||||
{
|
||||
final int stop = size - 8;
|
||||
int pos = 4 + offset;
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.2.4.1 $ $Date: 2005/03/27 15:30:12 $
|
||||
*/
|
||||
public abstract class BaseRecievePacket
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(BaseRecievePacket.class.getName());
|
||||
|
||||
private final byte[] _decrypt;
|
||||
private int _off;
|
||||
|
||||
public BaseRecievePacket(byte[] decrypt)
|
||||
{
|
||||
_decrypt = decrypt;
|
||||
_off = 1; // skip packet type id
|
||||
}
|
||||
|
||||
public int readD()
|
||||
{
|
||||
int result = _decrypt[_off++] & 0xff;
|
||||
result |= (_decrypt[_off++] << 8) & 0xff00;
|
||||
result |= (_decrypt[_off++] << 0x10) & 0xff0000;
|
||||
result |= (_decrypt[_off++] << 0x18) & 0xff000000;
|
||||
return result;
|
||||
}
|
||||
|
||||
public int readC()
|
||||
{
|
||||
return _decrypt[_off++] & 0xff;
|
||||
}
|
||||
|
||||
public int readH()
|
||||
{
|
||||
return (_decrypt[_off++] & 0xff) | ((_decrypt[_off++] << 8) & 0xff00);
|
||||
}
|
||||
|
||||
public double readF()
|
||||
{
|
||||
long result = _decrypt[_off++] & 0xff;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 8L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 16L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 24L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 32L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 40L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 48L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 56L;
|
||||
return Double.longBitsToDouble(result);
|
||||
}
|
||||
|
||||
public String readS()
|
||||
{
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
result = new String(_decrypt, _off, _decrypt.length - _off, StandardCharsets.UTF_16LE);
|
||||
result = result.substring(0, result.indexOf(0));
|
||||
_off += (result.length() * 2) + 2;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] readB(int length)
|
||||
{
|
||||
final byte[] result = new byte[length];
|
||||
System.arraycopy(_decrypt, _off, result, 0, length);
|
||||
_off += length;
|
||||
return result;
|
||||
}
|
||||
|
||||
public long readQ()
|
||||
{
|
||||
long result = _decrypt[_off++] & 0xff;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 8L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 16L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 24L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 32L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 40L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 48L;
|
||||
result |= (_decrypt[_off++] & 0xffL) << 56L;
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @version $Revision: 1.2.4.1 $ $Date: 2005/03/27 15:30:11 $
|
||||
*/
|
||||
public abstract class BaseSendablePacket
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(BaseSendablePacket.class.getName());
|
||||
|
||||
private final ByteArrayOutputStream _bao;
|
||||
|
||||
protected BaseSendablePacket()
|
||||
{
|
||||
_bao = new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
protected void writeD(int value)
|
||||
{
|
||||
_bao.write(value & 0xff);
|
||||
_bao.write((value >> 8) & 0xff);
|
||||
_bao.write((value >> 16) & 0xff);
|
||||
_bao.write((value >> 24) & 0xff);
|
||||
}
|
||||
|
||||
protected void writeH(int value)
|
||||
{
|
||||
_bao.write(value & 0xff);
|
||||
_bao.write((value >> 8) & 0xff);
|
||||
}
|
||||
|
||||
protected void writeC(int value)
|
||||
{
|
||||
_bao.write(value & 0xff);
|
||||
}
|
||||
|
||||
protected void writeF(double org)
|
||||
{
|
||||
final long value = Double.doubleToRawLongBits(org);
|
||||
_bao.write((int) (value & 0xff));
|
||||
_bao.write((int) ((value >> 8) & 0xff));
|
||||
_bao.write((int) ((value >> 16) & 0xff));
|
||||
_bao.write((int) ((value >> 24) & 0xff));
|
||||
_bao.write((int) ((value >> 32) & 0xff));
|
||||
_bao.write((int) ((value >> 40) & 0xff));
|
||||
_bao.write((int) ((value >> 48) & 0xff));
|
||||
_bao.write((int) ((value >> 56) & 0xff));
|
||||
}
|
||||
|
||||
protected void writeS(String text)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (text != null)
|
||||
{
|
||||
_bao.write(text.getBytes(StandardCharsets.UTF_16LE));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
_bao.write(0);
|
||||
_bao.write(0);
|
||||
}
|
||||
|
||||
protected void writeB(byte[] array)
|
||||
{
|
||||
try
|
||||
{
|
||||
_bao.write(array);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeQ(long value)
|
||||
{
|
||||
_bao.write((int) (value & 0xff));
|
||||
_bao.write((int) ((value >> 8) & 0xff));
|
||||
_bao.write((int) ((value >> 16) & 0xff));
|
||||
_bao.write((int) ((value >> 24) & 0xff));
|
||||
_bao.write((int) ((value >> 32) & 0xff));
|
||||
_bao.write((int) ((value >> 40) & 0xff));
|
||||
_bao.write((int) ((value >> 48) & 0xff));
|
||||
_bao.write((int) ((value >> 56) & 0xff));
|
||||
}
|
||||
|
||||
public int getLength()
|
||||
{
|
||||
return _bao.size() + 2;
|
||||
}
|
||||
|
||||
public byte[] getBytes()
|
||||
{
|
||||
// if (this instanceof Init)
|
||||
// writeD(0); // reserve for XOR initial key
|
||||
|
||||
writeD(0); // reserve for checksum
|
||||
|
||||
final int padding = _bao.size() % 8;
|
||||
if (padding != 0)
|
||||
{
|
||||
for (int i = padding; i < 8; i++)
|
||||
{
|
||||
writeC(0);
|
||||
}
|
||||
}
|
||||
|
||||
return _bao.toByteArray();
|
||||
}
|
||||
|
||||
public abstract byte[] getContent() throws IOException;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class ChannelInboundHandler<T extends ChannelInboundHandler<?>>extends SimpleChannelInboundHandler<IIncomingPacket<T>>
|
||||
{
|
||||
private Channel _channel;
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
{
|
||||
_channel = ctx.channel();
|
||||
}
|
||||
|
||||
public void setConnectionState(IConnectionState connectionState)
|
||||
{
|
||||
_channel.attr(IConnectionState.ATTRIBUTE_KEY).set(connectionState);
|
||||
}
|
||||
|
||||
public IConnectionState getConnectionState()
|
||||
{
|
||||
return _channel != null ? _channel.attr(IConnectionState.ATTRIBUTE_KEY).get() : null;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since October 4th 2022
|
||||
*/
|
||||
public interface EncryptionInterface
|
||||
{
|
||||
default void encrypt(byte[] data, int offset, int size)
|
||||
{
|
||||
}
|
||||
|
||||
default void decrypt(byte[] data, int offset, int size)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.commons.util.CommonUtil;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since September 7th 2020
|
||||
* @param <E> extends NetClient
|
||||
*/
|
||||
public class ExecuteThread<E extends NetClient> implements Runnable
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(ExecuteThread.class.getName());
|
||||
|
||||
private final Set<E> _pool;
|
||||
private final PacketHandlerInterface<E> _packetHandler;
|
||||
|
||||
public ExecuteThread(Set<E> pool, PacketHandlerInterface<E> packetHandler)
|
||||
{
|
||||
_pool = pool;
|
||||
_packetHandler = packetHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
long executionStart;
|
||||
long currentTime;
|
||||
while (true)
|
||||
{
|
||||
executionStart = System.currentTimeMillis();
|
||||
|
||||
// No need to iterate when pool is empty.
|
||||
if (!_pool.isEmpty())
|
||||
{
|
||||
// Iterate client pool.
|
||||
ITERATE: for (E client : _pool)
|
||||
{
|
||||
if (client.getChannel() == null)
|
||||
{
|
||||
_pool.remove(client);
|
||||
continue ITERATE;
|
||||
}
|
||||
|
||||
final byte[] data = client.getPacketData().poll();
|
||||
if (data == null)
|
||||
{
|
||||
continue ITERATE;
|
||||
}
|
||||
|
||||
if (client.getEncryption() != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
client.getEncryption().decrypt(data, 0, data.length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning("ExecuteThread: Problem with " + client + " data decryption.");
|
||||
LOGGER.warning(CommonUtil.getStackTrace(e));
|
||||
client.disconnect();
|
||||
continue ITERATE;
|
||||
}
|
||||
}
|
||||
_packetHandler.handle(client, new ReadablePacket(data));
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent high CPU caused by repeatedly looping.
|
||||
currentTime = System.currentTimeMillis();
|
||||
if ((currentTime - executionStart) < 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import io.netty.util.AttributeKey;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public interface IConnectionState
|
||||
{
|
||||
AttributeKey<IConnectionState> ATTRIBUTE_KEY = AttributeKey.valueOf(IConnectionState.class, "");
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public interface ICrypt
|
||||
{
|
||||
void encrypt(ByteBuf buf);
|
||||
|
||||
void decrypt(ByteBuf buf);
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
* @param <T>
|
||||
*/
|
||||
public interface IIncomingPacket<T>
|
||||
{
|
||||
/**
|
||||
* Reads a packet.
|
||||
* @param client the client
|
||||
* @param packet the packet reader
|
||||
* @return {@code true} if packet was read successfully, {@code false} otherwise.
|
||||
*/
|
||||
boolean read(T client, PacketReader packet);
|
||||
|
||||
void run(T client) throws Exception;
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
* @param <T>
|
||||
*/
|
||||
public interface IIncomingPackets<T>extends IConnectionState
|
||||
{
|
||||
int getPacketId();
|
||||
|
||||
IIncomingPacket<T> newIncomingPacket();
|
||||
|
||||
Set<IConnectionState> getConnectionStates();
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public interface IOutgoingPacket
|
||||
{
|
||||
/**
|
||||
* @param packet the packet writer
|
||||
* @return {@code true} if packet was writen successfully, {@code false} otherwise.
|
||||
*/
|
||||
boolean write(PacketWriter packet);
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since September 7th 2020
|
||||
*/
|
||||
public class NetClient
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(NetClient.class.getName());
|
||||
|
||||
private String _ip;
|
||||
private SocketChannel _channel;
|
||||
private NetConfig _netConfig;
|
||||
private Queue<byte[]> _pendingPacketData;
|
||||
|
||||
/**
|
||||
* Initialize the client.
|
||||
* @param channel
|
||||
* @param netConfig
|
||||
*/
|
||||
public void init(SocketChannel channel, NetConfig netConfig)
|
||||
{
|
||||
_channel = channel;
|
||||
_netConfig = netConfig;
|
||||
_pendingPacketData = new ConcurrentLinkedQueue<>();
|
||||
|
||||
try
|
||||
{
|
||||
_ip = _channel.getRemoteAddress().toString();
|
||||
_ip = _ip.substring(1, _ip.lastIndexOf(':')); // Trim out /127.0.0.1:12345
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
|
||||
// Client is ready for communication.
|
||||
onConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when client is connected.
|
||||
*/
|
||||
public void onConnection()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when client is disconnected.
|
||||
*/
|
||||
public void onDisconnection()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect the client.
|
||||
*/
|
||||
public void disconnect()
|
||||
{
|
||||
if (_channel != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_channel.close();
|
||||
_channel = null;
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
_pendingPacketData.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add packet data to the queue.
|
||||
* @param data
|
||||
*/
|
||||
public void addPacketData(byte[] data)
|
||||
{
|
||||
// Check packet flooding.
|
||||
final int size = _pendingPacketData.size();
|
||||
if (size >= _netConfig.getPacketQueueLimit())
|
||||
{
|
||||
if (_netConfig.isPacketFloodDisconnect())
|
||||
{
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_netConfig.isPacketFloodDrop())
|
||||
{
|
||||
if (_netConfig.isPacketFloodLogged() && ((size % _netConfig.getPacketQueueLimit()) == 0))
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(this);
|
||||
sb.append(" packet queue size(");
|
||||
sb.append(size);
|
||||
sb.append(") exceeded limit(");
|
||||
sb.append(_netConfig.getPacketQueueLimit());
|
||||
sb.append(").");
|
||||
LOGGER.warning(sb.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to queue.
|
||||
_pendingPacketData.add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pending packet data.
|
||||
*/
|
||||
public Queue<byte[]> getPacketData()
|
||||
{
|
||||
return _pendingPacketData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Encryption of this client.
|
||||
*/
|
||||
public EncryptionInterface getEncryption()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the SocketChannel of this client.
|
||||
*/
|
||||
public SocketChannel getChannel()
|
||||
{
|
||||
return _channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the IP address of this client.
|
||||
*/
|
||||
public String getIp()
|
||||
{
|
||||
return _ip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" - IP: ");
|
||||
sb.append(_ip);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since October 4th 2022
|
||||
*/
|
||||
public class NetConfig
|
||||
{
|
||||
private int _readPoolSize = 100;
|
||||
private int _executePoolSize = 50;
|
||||
private int _connectionTimeout = 800;
|
||||
private int _packetQueueLimit = 80;
|
||||
private boolean _packetFloodDisconnect = false;
|
||||
private boolean _packetFloodDrop = false;
|
||||
private boolean _packetFloodLogged = true;
|
||||
private boolean _tcpNoDelay = true;
|
||||
|
||||
/**
|
||||
* @return the NetClient pool size for reading client packets.
|
||||
*/
|
||||
public int getReadPoolSize()
|
||||
{
|
||||
return _readPoolSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NetClient pool size for reading client packets.
|
||||
* @param clientPoolSize
|
||||
*/
|
||||
public void setReadPoolSize(int clientPoolSize)
|
||||
{
|
||||
_readPoolSize = clientPoolSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the NetClient pool size for executing client packets.
|
||||
*/
|
||||
public int getExecutePoolSize()
|
||||
{
|
||||
return _executePoolSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NetClient pool size for executing client packets.
|
||||
* @param executePoolSize
|
||||
*/
|
||||
public void setExecutePoolSize(int executePoolSize)
|
||||
{
|
||||
_executePoolSize = executePoolSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timeout until a connection is established.
|
||||
*/
|
||||
public int getConnectionTimeout()
|
||||
{
|
||||
return _connectionTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout until a connection is established.
|
||||
* @param connectionTimeout
|
||||
*/
|
||||
public void setConnectionTimeout(int connectionTimeout)
|
||||
{
|
||||
_connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the packet queue limit of receivable packets.
|
||||
*/
|
||||
public int getPacketQueueLimit()
|
||||
{
|
||||
return _packetQueueLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the packet queue limit of receivable packets.
|
||||
* @param packetQueueLimit
|
||||
*/
|
||||
public void setPacketQueueLimit(int packetQueueLimit)
|
||||
{
|
||||
_packetQueueLimit = packetQueueLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if disconnect when packets that exceed the packet queue limit.
|
||||
*/
|
||||
public boolean isPacketFloodDisconnect()
|
||||
{
|
||||
return _packetFloodDisconnect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets to disconnect when the packet queue limit is exceeded.
|
||||
* @param packetFloodDisconnect
|
||||
*/
|
||||
public void setPacketFloodDisconnect(boolean packetFloodDisconnect)
|
||||
{
|
||||
_packetFloodDisconnect = packetFloodDisconnect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if packets that exceed the packet queue limit are dropped.
|
||||
*/
|
||||
public boolean isPacketFloodDrop()
|
||||
{
|
||||
return _packetFloodDrop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if packets that exceed the packet queue limit are dropped.
|
||||
* @param packetQueueDrop
|
||||
*/
|
||||
public void setPacketFloodDrop(boolean packetQueueDrop)
|
||||
{
|
||||
_packetFloodDrop = packetQueueDrop;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if dropped packets are logged.
|
||||
*/
|
||||
public boolean isPacketFloodLogged()
|
||||
{
|
||||
return _packetFloodLogged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if dropped packets are logged.
|
||||
* @param packetFloodLogged
|
||||
*/
|
||||
public void setPacketFloodLogged(boolean packetFloodLogged)
|
||||
{
|
||||
_packetFloodLogged = packetFloodLogged;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if TCP_NODELAY (Nagle's Algorithm) is used.
|
||||
*/
|
||||
public boolean isTcpNoDelay()
|
||||
{
|
||||
return _tcpNoDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if TCP_NODELAY (Nagle's Algorithm) is used.
|
||||
* @param tcpNoDelay
|
||||
*/
|
||||
public void setTcpNoDelay(boolean tcpNoDelay)
|
||||
{
|
||||
_tcpNoDelay = tcpNoDelay;
|
||||
}
|
||||
}
|
@ -0,0 +1,206 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since September 7th 2020
|
||||
* @param <E> extends NetClient
|
||||
*/
|
||||
public class NetServer<E extends NetClient>
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(NetServer.class.getName());
|
||||
|
||||
protected final List<Set<E>> _clientReadPools = new LinkedList<>();
|
||||
protected final List<Set<E>> _clientExecutePools = new LinkedList<>();
|
||||
protected final NetConfig _netConfig = new NetConfig();
|
||||
protected final String _hostname;
|
||||
protected final int _port;
|
||||
protected final Supplier<E> _clientSupplier;
|
||||
protected final PacketHandlerInterface<E> _packetHandler;
|
||||
protected String _name = getClass().getSimpleName();
|
||||
|
||||
/**
|
||||
* Creates a new NetServer.
|
||||
* @param port that the server will listen for incoming connections.
|
||||
* @param packetHandler that will be used to handle incoming data.
|
||||
* @param clientSupplier that will be used to create new client objects.
|
||||
*/
|
||||
public NetServer(int port, PacketHandlerInterface<E> packetHandler, Supplier<E> clientSupplier)
|
||||
{
|
||||
this("0.0.0.0", port, packetHandler, clientSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new NetServer.
|
||||
* @param hostname of the server, use 0.0.0.0 to bind on all available IPs.
|
||||
* @param port that the server will listen for incoming connections.
|
||||
* @param packetHandler that will be used to handle incoming data.
|
||||
* @param clientSupplier that will be used to create new client objects.
|
||||
*/
|
||||
public NetServer(String hostname, int port, PacketHandlerInterface<E> packetHandler, Supplier<E> clientSupplier)
|
||||
{
|
||||
_hostname = hostname;
|
||||
_port = port;
|
||||
_packetHandler = packetHandler;
|
||||
_clientSupplier = clientSupplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use alternative name for this NetServer object.
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the network configurations of this server.
|
||||
*/
|
||||
public NetConfig getNetConfig()
|
||||
{
|
||||
return _netConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start listening for clients.
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
if (_clientSupplier == null)
|
||||
{
|
||||
LOGGER.warning(_name + ": Could not start because client Supplier was not set.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_packetHandler == null)
|
||||
{
|
||||
LOGGER.warning(_name + ": Could not start because PacketHandler was not set.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Runs on a separate thread.
|
||||
final Thread thread = new Thread(new NetworkListenerThread(), _name + ": Network listener thread");
|
||||
thread.setPriority(Thread.MAX_PRIORITY);
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private class NetworkListenerThread implements Runnable
|
||||
{
|
||||
public NetworkListenerThread()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Create server and bind port.
|
||||
try (ServerSocketChannel server = ServerSocketChannel.open())
|
||||
{
|
||||
server.bind(new InetSocketAddress(_hostname, _port));
|
||||
server.configureBlocking(false); // Non-blocking I/O.
|
||||
|
||||
// Listen for new connections.
|
||||
LOGGER.info(_name + ": Listening on port " + _port + " for incoming connections.");
|
||||
long executionStart;
|
||||
long currentTime;
|
||||
while (true)
|
||||
{
|
||||
executionStart = System.currentTimeMillis();
|
||||
|
||||
final SocketChannel channel = server.accept();
|
||||
if (channel != null)
|
||||
{
|
||||
// Configure channel.
|
||||
channel.socket().setTcpNoDelay(_netConfig.isTcpNoDelay());
|
||||
channel.socket().setSoTimeout(_netConfig.getConnectionTimeout());
|
||||
channel.configureBlocking(false); // Non-blocking I/O.
|
||||
|
||||
// Create client.
|
||||
final E client = _clientSupplier.get();
|
||||
client.init(channel, _netConfig);
|
||||
|
||||
// Add to read pool.
|
||||
|
||||
// Find a pool that is not full.
|
||||
boolean readPoolFound = false;
|
||||
READ_POOLS: for (Set<E> pool : _clientReadPools)
|
||||
{
|
||||
if (pool.size() < _netConfig.getReadPoolSize())
|
||||
{
|
||||
pool.add(client);
|
||||
readPoolFound = true;
|
||||
break READ_POOLS;
|
||||
}
|
||||
}
|
||||
|
||||
// All pools are full.
|
||||
if (!readPoolFound)
|
||||
{
|
||||
// Create a new client pool.
|
||||
final Set<E> newReadPool = ConcurrentHashMap.newKeySet(_netConfig.getReadPoolSize());
|
||||
newReadPool.add(client);
|
||||
// Create a new task for the new pool.
|
||||
final Thread readThread = new Thread(new ReadThread<>(newReadPool), _name + ": Packet read thread " + _clientReadPools.size());
|
||||
readThread.setPriority(Thread.MAX_PRIORITY);
|
||||
readThread.setDaemon(true);
|
||||
readThread.start();
|
||||
// Add the new pool to the pool list.
|
||||
_clientReadPools.add(newReadPool);
|
||||
}
|
||||
|
||||
// Add to execute pool.
|
||||
|
||||
// Find a pool that is not full.
|
||||
boolean executePoolFound = false;
|
||||
EXECUTE_POOLS: for (Set<E> pool : _clientExecutePools)
|
||||
{
|
||||
if (pool.size() < _netConfig.getExecutePoolSize())
|
||||
{
|
||||
pool.add(client);
|
||||
executePoolFound = true;
|
||||
break EXECUTE_POOLS;
|
||||
}
|
||||
}
|
||||
|
||||
// All pools are full.
|
||||
if (!executePoolFound)
|
||||
{
|
||||
// Create a new client pool.
|
||||
final Set<E> newExecutePool = ConcurrentHashMap.newKeySet(_netConfig.getExecutePoolSize());
|
||||
newExecutePool.add(client);
|
||||
// Create a new task for the new pool.
|
||||
final Thread executeThread = new Thread(new ExecuteThread<>(newExecutePool, _packetHandler), _name + ": Packet execute thread " + _clientExecutePools.size());
|
||||
executeThread.setPriority(Thread.MAX_PRIORITY);
|
||||
executeThread.setDaemon(true);
|
||||
executeThread.start();
|
||||
// Add the new pool to the pool list.
|
||||
_clientExecutePools.add(newExecutePool);
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent high CPU caused by repeatedly polling the channel.
|
||||
currentTime = System.currentTimeMillis();
|
||||
if ((currentTime - executionStart) < 1)
|
||||
{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning(_name + ": Problem initializing. " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.PooledByteBufAllocator;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class NetworkManager
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(NetworkManager.class.getName());
|
||||
|
||||
private final ServerBootstrap _serverBootstrap;
|
||||
private final String _host;
|
||||
private final int _port;
|
||||
|
||||
private ChannelFuture _channelFuture;
|
||||
|
||||
public NetworkManager(EventLoopGroup bossGroup, EventLoopGroup workerGroup, ChannelInitializer<SocketChannel> clientInitializer, String host, int port)
|
||||
{
|
||||
// @formatter:off
|
||||
_serverBootstrap = new ServerBootstrap()
|
||||
.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.childHandler(clientInitializer)
|
||||
.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||
// @formatter:on
|
||||
_host = host;
|
||||
_port = port;
|
||||
}
|
||||
|
||||
public ChannelFuture getChannelFuture()
|
||||
{
|
||||
return _channelFuture;
|
||||
}
|
||||
|
||||
public void start() throws InterruptedException
|
||||
{
|
||||
if ((_channelFuture != null) && !_channelFuture.isDone())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_channelFuture = _serverBootstrap.bind(_host, _port).sync();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Listening on " + _host + ":" + _port);
|
||||
}
|
||||
|
||||
public void stop() throws InterruptedException
|
||||
{
|
||||
_channelFuture.channel().close().sync();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since October 4th 2022
|
||||
* @param <E> extends NetClient
|
||||
*/
|
||||
public interface PacketHandlerInterface<E extends NetClient>
|
||||
{
|
||||
default void handle(E client, ReadablePacket packet)
|
||||
{
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class PacketReader
|
||||
{
|
||||
private final ByteBuf _buf;
|
||||
|
||||
public PacketReader(ByteBuf buf)
|
||||
{
|
||||
_buf = buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the readable bytes.
|
||||
* @return the readable bytes
|
||||
*/
|
||||
public int getReadableBytes()
|
||||
{
|
||||
return _buf.readableBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned byte.
|
||||
* @return the unsigned byte
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 1}
|
||||
*/
|
||||
public short readC()
|
||||
{
|
||||
return _buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an unsigned short.
|
||||
* @return the unsigned short
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 2}
|
||||
*/
|
||||
public int readH()
|
||||
{
|
||||
return _buf.readUnsignedShortLE();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an integer.
|
||||
* @return the integer
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 4}
|
||||
*/
|
||||
public int readD()
|
||||
{
|
||||
return _buf.readIntLE();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a long.
|
||||
* @return the long
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 8}
|
||||
*/
|
||||
public long readQ()
|
||||
{
|
||||
return _buf.readLongLE();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a float.
|
||||
* @return the float
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 4}
|
||||
*/
|
||||
public float readE()
|
||||
{
|
||||
return Float.intBitsToFloat(_buf.readIntLE());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a double.
|
||||
* @return the double
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 8}
|
||||
*/
|
||||
public double readF()
|
||||
{
|
||||
return Double.longBitsToDouble(_buf.readLongLE());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a string.
|
||||
* @return the string
|
||||
* @throws IndexOutOfBoundsException if string {@code null} terminator is not found within {@code readableBytes}
|
||||
*/
|
||||
public String readS()
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
char chr;
|
||||
while ((chr = Character.reverseBytes(_buf.readChar())) != 0)
|
||||
{
|
||||
sb.append(chr);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a fixed length string.
|
||||
* @return the string
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code 2 + String.length * 2}
|
||||
*/
|
||||
public String readString()
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final int stringLength = _buf.readShortLE();
|
||||
if ((stringLength * 2) > _buf.readableBytes())
|
||||
{
|
||||
throw new IndexOutOfBoundsException("readerIndex(" + _buf.readerIndex() + ") + length(" + (stringLength * 2) + ") exceeds writerIndex(" + _buf.writerIndex() + "): " + _buf);
|
||||
}
|
||||
|
||||
for (int i = 0; i < stringLength; i++)
|
||||
{
|
||||
sb.append(Character.reverseBytes(_buf.readChar()));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a byte array.
|
||||
* @param length the length
|
||||
* @return the byte array
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code length}
|
||||
*/
|
||||
public byte[] readB(int length)
|
||||
{
|
||||
final byte[] result = new byte[length];
|
||||
_buf.readBytes(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a byte array.
|
||||
* @param dst the destination
|
||||
* @param dstIndex the destination index to start writing the bytes from
|
||||
* @param length the length
|
||||
* @throws IndexOutOfBoundsException if {@code readableBytes} is less than {@code length}, if the specified dstIndex is less than 0 or if {@code dstIndex + length} is greater than {@code dst.length}
|
||||
*/
|
||||
public void readB(byte[] dst, int dstIndex, int length)
|
||||
{
|
||||
_buf.readBytes(dst, dstIndex, length);
|
||||
}
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class PacketWriter
|
||||
{
|
||||
private final ByteBuf _buf;
|
||||
|
||||
public PacketWriter(ByteBuf buf)
|
||||
{
|
||||
_buf = buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the writable bytes.
|
||||
* @return the writable bytes
|
||||
*/
|
||||
public int getWritableBytes()
|
||||
{
|
||||
return _buf.writableBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a byte.
|
||||
* @param value the byte (The 24 high-order bits are ignored)
|
||||
*/
|
||||
public void writeC(int value)
|
||||
{
|
||||
_buf.writeByte(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a short.
|
||||
* @param value the short (The 16 high-order bits are ignored)
|
||||
*/
|
||||
public void writeH(int value)
|
||||
{
|
||||
_buf.writeShortLE(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an integer.
|
||||
* @param value the integer
|
||||
*/
|
||||
public void writeD(int value)
|
||||
{
|
||||
_buf.writeIntLE(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a long.
|
||||
* @param value the long
|
||||
*/
|
||||
public void writeQ(long value)
|
||||
{
|
||||
_buf.writeLongLE(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a float.
|
||||
* @param value the float
|
||||
*/
|
||||
public void writeE(float value)
|
||||
{
|
||||
_buf.writeIntLE(Float.floatToIntBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a double.
|
||||
* @param value the double
|
||||
*/
|
||||
public void writeF(double value)
|
||||
{
|
||||
_buf.writeLongLE(Double.doubleToLongBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string.
|
||||
* @param value the string
|
||||
*/
|
||||
public void writeS(String value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
for (int i = 0; i < value.length(); i++)
|
||||
{
|
||||
_buf.writeChar(Character.reverseBytes(value.charAt(i)));
|
||||
}
|
||||
}
|
||||
|
||||
_buf.writeChar(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string with fixed length specified as [short length, char[length] data].
|
||||
* @param value the string
|
||||
*/
|
||||
public void writeString(String value)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
_buf.writeShortLE(value.length());
|
||||
for (int i = 0; i < value.length(); i++)
|
||||
{
|
||||
_buf.writeChar(Character.reverseBytes(value.charAt(i)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_buf.writeShort(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a byte array.
|
||||
* @param bytes the byte array
|
||||
*/
|
||||
public void writeB(byte[] bytes)
|
||||
{
|
||||
_buf.writeBytes(bytes);
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since September 7th 2020
|
||||
* @param <E> extends NetClient
|
||||
*/
|
||||
public class ReadThread<E extends NetClient> implements Runnable
|
||||
{
|
||||
private final ByteBuffer _sizeBuffer = ByteBuffer.allocate(2); // Reusable size buffer.
|
||||
private final Set<E> _pool;
|
||||
|
||||
public ReadThread(Set<E> pool)
|
||||
{
|
||||
_pool = pool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
long executionStart;
|
||||
long currentTime;
|
||||
while (true)
|
||||
{
|
||||
executionStart = System.currentTimeMillis();
|
||||
|
||||
// No need to iterate when pool is empty.
|
||||
if (!_pool.isEmpty())
|
||||
{
|
||||
// Iterate client pool.
|
||||
ITERATE: for (E client : _pool)
|
||||
{
|
||||
try
|
||||
{
|
||||
final SocketChannel channel = client.getChannel();
|
||||
if (channel == null) // Unexpected disconnection?
|
||||
{
|
||||
// Null SocketChannel: client
|
||||
onDisconnection(client);
|
||||
continue ITERATE;
|
||||
}
|
||||
|
||||
// Read incoming packet size (short).
|
||||
_sizeBuffer.clear();
|
||||
switch (channel.read(_sizeBuffer))
|
||||
{
|
||||
// Disconnected.
|
||||
case -1:
|
||||
{
|
||||
onDisconnection(client);
|
||||
continue ITERATE;
|
||||
}
|
||||
// Nothing read.
|
||||
case 0:
|
||||
{
|
||||
continue ITERATE;
|
||||
}
|
||||
// Read actual packet bytes.
|
||||
default:
|
||||
{
|
||||
// Allocate a new ByteBuffer based on packet size read.
|
||||
final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize());
|
||||
switch (channel.read(packetByteBuffer))
|
||||
{
|
||||
// Disconnected.
|
||||
case -1:
|
||||
{
|
||||
onDisconnection(client);
|
||||
continue ITERATE;
|
||||
}
|
||||
// Nothing read.
|
||||
case 0:
|
||||
{
|
||||
continue ITERATE;
|
||||
}
|
||||
// Send data read to the client packet queue.
|
||||
default:
|
||||
{
|
||||
client.addPacketData(packetByteBuffer.array());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SocketTimeoutException e)
|
||||
{
|
||||
onDisconnection(client);
|
||||
}
|
||||
catch (Exception e) // Unexpected disconnection?
|
||||
{
|
||||
onDisconnection(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent high CPU caused by repeatedly looping.
|
||||
currentTime = System.currentTimeMillis();
|
||||
if ((currentTime - executionStart) < 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep(1);
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int calculatePacketSize()
|
||||
{
|
||||
_sizeBuffer.rewind();
|
||||
return ((_sizeBuffer.get() & 0xff) | ((_sizeBuffer.get() << 8) & 0xffff)) - 2;
|
||||
}
|
||||
|
||||
private void onDisconnection(E client)
|
||||
{
|
||||
_pool.remove(client);
|
||||
client.onDisconnection();
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
/**
|
||||
* @author Pantelis Andrianakis
|
||||
* @since October 29th 2020
|
||||
*/
|
||||
public class ReadablePacket
|
||||
{
|
||||
private final byte[] _bytes;
|
||||
private int _position = 0;
|
||||
|
||||
public ReadablePacket(byte[] bytes)
|
||||
{
|
||||
_bytes = bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>boolean</b> from the packet data.<br>
|
||||
* 8bit integer (00) or (01)
|
||||
* @return
|
||||
*/
|
||||
public boolean readBoolean()
|
||||
{
|
||||
return readByte() != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>String</b> from the packet data.
|
||||
* @return
|
||||
*/
|
||||
public String readString()
|
||||
{
|
||||
final StringBuilder result = new StringBuilder();
|
||||
try
|
||||
{
|
||||
int charId;
|
||||
while ((charId = readShort() & 0x00ff) != 0)
|
||||
{
|
||||
result.append((char) charId);
|
||||
}
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>byte[]</b> from the packet data.<br>
|
||||
* 8bit integer array (00...)
|
||||
* @param length of the array.
|
||||
* @return
|
||||
*/
|
||||
public byte[] readBytes(int length)
|
||||
{
|
||||
final byte[] result = new byte[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
result[i] = _bytes[_position++];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>byte[]</b> from the packet data.<br>
|
||||
* 8bit integer array (00...)
|
||||
* @param array used to store data.
|
||||
* @return
|
||||
*/
|
||||
public byte[] readBytes(byte[] array)
|
||||
{
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
array[i] = _bytes[_position++];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>byte</b> from the packet data.<br>
|
||||
* 8bit integer (00)
|
||||
* @return
|
||||
*/
|
||||
public int readByte()
|
||||
{
|
||||
return _bytes[_position++] & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>short</b> from the packet data.<br>
|
||||
* 16bit integer (00 00)
|
||||
* @return
|
||||
*/
|
||||
public int readShort()
|
||||
{
|
||||
return (_bytes[_position++] & 0xff) //
|
||||
| ((_bytes[_position++] << 8) & 0xff00);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>int</b> from the packet data.<br>
|
||||
* 32bit integer (00 00 00 00)
|
||||
* @return
|
||||
*/
|
||||
public int readInt()
|
||||
{
|
||||
return (_bytes[_position++] & 0xff) //
|
||||
| ((_bytes[_position++] << 8) & 0xff00) //
|
||||
| ((_bytes[_position++] << 16) & 0xff0000) //
|
||||
| ((_bytes[_position++] << 24) & 0xff000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>long</b> from the packet data.<br>
|
||||
* 64bit integer (00 00 00 00 00 00 00 00)
|
||||
* @return
|
||||
*/
|
||||
public long readLong()
|
||||
{
|
||||
return (_bytes[_position++] & 0xff) //
|
||||
| ((_bytes[_position++] << 8) & 0xff00) //
|
||||
| ((_bytes[_position++] << 16) & 0xff0000) //
|
||||
| ((_bytes[_position++] << 24) & 0xff000000) //
|
||||
| (((long) _bytes[_position++] << 32) & 0xff00000000L) //
|
||||
| (((long) _bytes[_position++] << 40) & 0xff0000000000L) //
|
||||
| (((long) _bytes[_position++] << 48) & 0xff000000000000L) //
|
||||
| (((long) _bytes[_position++] << 56) & 0xff00000000000000L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>float</b> from the packet data.<br>
|
||||
* 32bit single precision float (00 00 00 00)
|
||||
* @return
|
||||
*/
|
||||
public float readFloat()
|
||||
{
|
||||
return Float.intBitsToFloat(readInt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads <b>double</b> from the packet data.<br>
|
||||
* 64bit double precision float (00 00 00 00 00 00 00 00)
|
||||
* @return
|
||||
*/
|
||||
public double readDouble()
|
||||
{
|
||||
return Double.longBitsToDouble(readLong());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of unread bytes.
|
||||
*/
|
||||
public int getRemainingLength()
|
||||
{
|
||||
return _bytes.length - _position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the byte size.
|
||||
*/
|
||||
public int getLength()
|
||||
{
|
||||
return _bytes.length;
|
||||
}
|
||||
}
|
@ -0,0 +1,300 @@
|
||||
package org.l2jmobius.commons.network;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Writable packet backed up by a byte array, with a maximum raw data size of 65533 bytes.
|
||||
* @author Pantelis Andrianakis
|
||||
* @since October 29th 2020
|
||||
*/
|
||||
public abstract class WritablePacket
|
||||
{
|
||||
private byte[] _data;
|
||||
private byte[] _sendableBytes;
|
||||
private ByteBuffer _byteBuffer;
|
||||
private int _position = 2; // Allocate space for size (max length 65535 - size header).
|
||||
|
||||
/**
|
||||
* Construct a WritablePacket with an initial data size of 32 bytes.
|
||||
*/
|
||||
protected WritablePacket()
|
||||
{
|
||||
this(32);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a WritablePacket with a given initial data size.
|
||||
* @param initialSize
|
||||
*/
|
||||
protected WritablePacket(int initialSize)
|
||||
{
|
||||
_data = new byte[initialSize];
|
||||
}
|
||||
|
||||
public void write(byte value)
|
||||
{
|
||||
// Check current size.
|
||||
if (_position < 65535)
|
||||
{
|
||||
// Check capacity.
|
||||
if (_position == _data.length)
|
||||
{
|
||||
_data = Arrays.copyOf(_data, _data.length * 2); // Double the capacity.
|
||||
}
|
||||
|
||||
// Set value.
|
||||
_data[_position++] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IndexOutOfBoundsException("Packet data exceeded the raw data size limit of 65533!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>boolean</b> to the packet data.<br>
|
||||
* 8bit integer (00) or (01)
|
||||
* @param value
|
||||
*/
|
||||
public void writeBoolean(boolean value)
|
||||
{
|
||||
writeByte(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>String</b> to the packet data.
|
||||
* @param text
|
||||
*/
|
||||
public void writeString(String text)
|
||||
{
|
||||
if (text != null)
|
||||
{
|
||||
final byte[] bytes = text.getBytes(StandardCharsets.UTF_16LE);
|
||||
for (int i = 0; i < bytes.length; i++)
|
||||
{
|
||||
writeByte(bytes[i]);
|
||||
}
|
||||
}
|
||||
writeShort(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>byte[]</b> to the packet data.<br>
|
||||
* 8bit integer array (00...)
|
||||
* @param array
|
||||
*/
|
||||
public void writeBytes(byte[] array)
|
||||
{
|
||||
for (int i = 0; i < array.length; i++)
|
||||
{
|
||||
write(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>byte</b> to the packet data.<br>
|
||||
* 8bit integer (00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeByte(int value)
|
||||
{
|
||||
write((byte) (value & 0xff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>boolean</b> to the packet data.<br>
|
||||
* 8bit integer (00) or (01)
|
||||
* @param value
|
||||
*/
|
||||
public void writeByte(boolean value)
|
||||
{
|
||||
writeByte(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>short</b> to the packet data.<br>
|
||||
* 16bit integer (00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeShort(int value)
|
||||
{
|
||||
write((byte) (value & 0xff));
|
||||
write((byte) ((value >> 8) & 0xff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>boolean</b> to the packet data.<br>
|
||||
* 16bit integer (00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeShort(boolean value)
|
||||
{
|
||||
writeShort(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>int</b> to the packet data.<br>
|
||||
* 32bit integer (00 00 00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeInt(int value)
|
||||
{
|
||||
write((byte) (value & 0xff));
|
||||
write((byte) ((value >> 8) & 0xff));
|
||||
write((byte) ((value >> 16) & 0xff));
|
||||
write((byte) ((value >> 24) & 0xff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>boolean</b> to the packet data.<br>
|
||||
* 32bit integer (00 00 00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeInt(boolean value)
|
||||
{
|
||||
writeInt(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>long</b> to the packet data.<br>
|
||||
* 64bit integer (00 00 00 00 00 00 00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeLong(long value)
|
||||
{
|
||||
write((byte) (value & 0xff));
|
||||
write((byte) ((value >> 8) & 0xff));
|
||||
write((byte) ((value >> 16) & 0xff));
|
||||
write((byte) ((value >> 24) & 0xff));
|
||||
write((byte) ((value >> 32) & 0xff));
|
||||
write((byte) ((value >> 40) & 0xff));
|
||||
write((byte) ((value >> 48) & 0xff));
|
||||
write((byte) ((value >> 56) & 0xff));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>boolean</b> to the packet data.<br>
|
||||
* 64bit integer (00 00 00 00 00 00 00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeLong(boolean value)
|
||||
{
|
||||
writeLong(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>float</b> to the packet data.<br>
|
||||
* 32bit single precision float (00 00 00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeFloat(float value)
|
||||
{
|
||||
writeInt(Float.floatToRawIntBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write <b>double</b> to the packet data.<br>
|
||||
* 64bit double precision float (00 00 00 00 00 00 00 00)
|
||||
* @param value
|
||||
*/
|
||||
public void writeDouble(double value)
|
||||
{
|
||||
writeLong(Double.doubleToRawLongBits(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be overridden to write data after packet has initialized.<br>
|
||||
* Called when getSendableBytes generates data, ensures that the data are processed only once.
|
||||
*/
|
||||
public void write()
|
||||
{
|
||||
// Overridden by server implementation.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <b>byte[]</b> of the sendable packet data, including a size header.
|
||||
*/
|
||||
public byte[] getSendableBytes()
|
||||
{
|
||||
return getSendableBytes(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param encryption if EncryptionInterface is used.
|
||||
* @return <b>byte[]</b> of the sendable packet data, including a size header.
|
||||
*/
|
||||
public synchronized byte[] getSendableBytes(EncryptionInterface encryption)
|
||||
{
|
||||
// Generate sendable byte array.
|
||||
if ((_sendableBytes == null /* Not processed */) || (encryption != null /* Encryption can change */))
|
||||
{
|
||||
// Write packet implementation (only once).
|
||||
if (_position == 2)
|
||||
{
|
||||
write();
|
||||
}
|
||||
|
||||
// Check if data was written.
|
||||
if (_position > 2)
|
||||
{
|
||||
// Trim array of data.
|
||||
_sendableBytes = Arrays.copyOf(_data, _position);
|
||||
|
||||
// Add size info at start (unsigned short - max size 65535).
|
||||
_sendableBytes[0] = (byte) (_position & 0xff);
|
||||
_sendableBytes[1] = (byte) ((_position >> 8) & 0xffff);
|
||||
|
||||
// Encrypt data.
|
||||
if (encryption != null)
|
||||
{
|
||||
encryption.encrypt(_sendableBytes, 2, _position - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the data.
|
||||
return _sendableBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ByteBuffer of the sendable packet data, including a size header.
|
||||
*/
|
||||
public ByteBuffer getSendableByteBuffer()
|
||||
{
|
||||
return getSendableByteBuffer(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param encryption if EncryptionInterface is used.
|
||||
* @return ByteBuffer of the sendable packet data, including a size header.
|
||||
*/
|
||||
public synchronized ByteBuffer getSendableByteBuffer(EncryptionInterface encryption)
|
||||
{
|
||||
// Generate sendable ByteBuffer.
|
||||
if ((_byteBuffer == null /* Not processed */) || (encryption != null /* Encryption can change */))
|
||||
{
|
||||
final byte[] bytes = getSendableBytes(encryption);
|
||||
if (bytes != null) // Data was actually written.
|
||||
{
|
||||
_byteBuffer = ByteBuffer.wrap(bytes);
|
||||
}
|
||||
}
|
||||
else // Rewind the buffer.
|
||||
{
|
||||
_byteBuffer.rewind();
|
||||
}
|
||||
|
||||
// Return the buffer.
|
||||
return _byteBuffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take in consideration that data must be written first.
|
||||
* @return The length of the data (includes size header).
|
||||
*/
|
||||
public int getLength()
|
||||
{
|
||||
return _position;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network.codecs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageCodec;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class CryptCodec extends ByteToMessageCodec<ByteBuf>
|
||||
{
|
||||
private final ICrypt _crypt;
|
||||
|
||||
public CryptCodec(ICrypt crypt)
|
||||
{
|
||||
super();
|
||||
_crypt = crypt;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see io.netty.handler.codec.ByteToMessageCodec#encode(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.buffer.ByteBuf)
|
||||
*/
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out)
|
||||
{
|
||||
// Check if there are any data to encrypt.
|
||||
if (!msg.isReadable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
msg.resetReaderIndex();
|
||||
_crypt.encrypt(msg);
|
||||
msg.resetReaderIndex();
|
||||
out.writeBytes(msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see io.netty.handler.codec.ByteToMessageCodec#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
|
||||
{
|
||||
in.resetReaderIndex();
|
||||
_crypt.decrypt(in);
|
||||
in.readerIndex(in.writerIndex());
|
||||
out.add(in.copy(0, in.writerIndex()));
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network.codecs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageEncoder;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
@Sharable
|
||||
public class LengthFieldBasedFrameEncoder extends MessageToMessageEncoder<ByteBuf>
|
||||
{
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
|
||||
{
|
||||
final ByteBuf buf = ctx.alloc().buffer(2);
|
||||
final short length = (short) (msg.readableBytes() + 2);
|
||||
buf.writeShortLE(length);
|
||||
out.add(buf);
|
||||
out.add(msg.retain());
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network.codecs;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.commons.network.IConnectionState;
|
||||
import org.l2jmobius.commons.network.IIncomingPacket;
|
||||
import org.l2jmobius.commons.network.IIncomingPackets;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
* @param <T>
|
||||
*/
|
||||
public class PacketDecoder<T>extends ByteToMessageDecoder
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(PacketDecoder.class.getName());
|
||||
|
||||
private final IIncomingPackets<T>[] _incomingPackets;
|
||||
private final T _client;
|
||||
|
||||
public PacketDecoder(IIncomingPackets<T>[] incomingPackets, T client)
|
||||
{
|
||||
_incomingPackets = incomingPackets;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
|
||||
{
|
||||
if ((in == null) || !in.isReadable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
final short packetId = in.readUnsignedByte();
|
||||
if (packetId >= _incomingPackets.length)
|
||||
{
|
||||
LOGGER.finer("Unknown packet: " + Integer.toHexString(packetId));
|
||||
return;
|
||||
}
|
||||
|
||||
final IIncomingPackets<T> incomingPacket = _incomingPackets[packetId];
|
||||
if (incomingPacket == null)
|
||||
{
|
||||
LOGGER.finer("Unknown packet: " + Integer.toHexString(packetId));
|
||||
return;
|
||||
}
|
||||
|
||||
final IConnectionState connectionState = ctx.channel().attr(IConnectionState.ATTRIBUTE_KEY).get();
|
||||
if ((connectionState == null) || !incomingPacket.getConnectionStates().contains(connectionState))
|
||||
{
|
||||
// LOGGER.warning(incomingPacket + ": Connection at invalid state: " + connectionState + " Required States: " + incomingPacket.getConnectionStates());
|
||||
return;
|
||||
}
|
||||
|
||||
final IIncomingPacket<T> packet = incomingPacket.newIncomingPacket();
|
||||
if ((packet != null) && packet.read(_client, new PacketReader(in)))
|
||||
{
|
||||
out.add(packet);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// We always consider that we read whole packet.
|
||||
in.readerIndex(in.writerIndex());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.network.codecs;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.commons.network.IOutgoingPacket;
|
||||
import org.l2jmobius.commons.network.PacketWriter;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
@Sharable
|
||||
public class PacketEncoder extends MessageToByteEncoder<IOutgoingPacket>
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(PacketEncoder.class.getName());
|
||||
|
||||
private final int _maxPacketSize;
|
||||
|
||||
public PacketEncoder(int maxPacketSize)
|
||||
{
|
||||
super();
|
||||
_maxPacketSize = maxPacketSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, IOutgoingPacket packet, ByteBuf out)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (packet.write(new PacketWriter(out)))
|
||||
{
|
||||
if (out.writerIndex() > _maxPacketSize)
|
||||
{
|
||||
throw new IllegalStateException("Packet (" + packet + ") size (" + out.writerIndex() + ") is bigger than the expected client limit (" + _maxPacketSize + ")");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Avoid sending the packet
|
||||
out.clear();
|
||||
}
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Failed sending Packet(" + packet + ")", e);
|
||||
// Avoid sending the packet if some exception happened
|
||||
out.clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.commons.util.crypt;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/**
|
||||
* @author NosBit
|
||||
*/
|
||||
public class LoginCrypt implements ICrypt
|
||||
{
|
||||
private static final byte[] STATIC_BLOWFISH_KEY =
|
||||
{
|
||||
(byte) 0x6b,
|
||||
(byte) 0x60,
|
||||
(byte) 0xcb,
|
||||
(byte) 0x5b,
|
||||
(byte) 0x82,
|
||||
(byte) 0xce,
|
||||
(byte) 0x90,
|
||||
(byte) 0xb1,
|
||||
(byte) 0xcc,
|
||||
(byte) 0x2b,
|
||||
(byte) 0x6c,
|
||||
(byte) 0x55,
|
||||
(byte) 0x6c,
|
||||
(byte) 0x6c,
|
||||
(byte) 0x6c,
|
||||
(byte) 0x6c
|
||||
};
|
||||
|
||||
private static final BlowfishEngine STATIC_BLOWFISH_ENGINE = new BlowfishEngine();
|
||||
static
|
||||
{
|
||||
STATIC_BLOWFISH_ENGINE.init(STATIC_BLOWFISH_KEY);
|
||||
}
|
||||
|
||||
private final BlowfishEngine _blowfishEngine = new BlowfishEngine();
|
||||
private boolean _static = true;
|
||||
|
||||
public LoginCrypt(SecretKey blowfishKey)
|
||||
{
|
||||
_blowfishEngine.init(blowfishKey.getEncoded());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.l2jmobius.commons.network.ICrypt#encrypt(io.netty.buffer.ByteBuf)
|
||||
*/
|
||||
@Override
|
||||
public void encrypt(ByteBuf buf)
|
||||
{
|
||||
// Checksum & XOR Key or Checksum only
|
||||
buf.writeZero(_static ? 16 : 12);
|
||||
|
||||
// Padding
|
||||
buf.writeZero(8 - (buf.readableBytes() % 8));
|
||||
|
||||
if (_static)
|
||||
{
|
||||
_static = false;
|
||||
|
||||
int key = Rnd.nextInt();
|
||||
buf.skipBytes(4); // The first 4 bytes are ignored
|
||||
while (buf.readerIndex() < (buf.writerIndex() - 8))
|
||||
{
|
||||
int data = buf.readIntLE();
|
||||
key += data;
|
||||
data ^= key;
|
||||
buf.setIntLE(buf.readerIndex() - 4, data);
|
||||
}
|
||||
buf.setIntLE(buf.readerIndex(), key);
|
||||
|
||||
buf.resetReaderIndex();
|
||||
|
||||
final byte[] block = new byte[8];
|
||||
while (buf.isReadable(8))
|
||||
{
|
||||
buf.readBytes(block);
|
||||
STATIC_BLOWFISH_ENGINE.encryptBlock(block, 0);
|
||||
buf.setBytes(buf.readerIndex() - block.length, block);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int checksum = 0;
|
||||
while (buf.isReadable(8))
|
||||
{
|
||||
checksum ^= buf.readIntLE();
|
||||
}
|
||||
buf.setIntLE(buf.readerIndex(), checksum);
|
||||
|
||||
buf.resetReaderIndex();
|
||||
|
||||
final byte[] block = new byte[8];
|
||||
while (buf.isReadable(8))
|
||||
{
|
||||
buf.readBytes(block);
|
||||
_blowfishEngine.encryptBlock(block, 0);
|
||||
buf.setBytes(buf.readerIndex() - block.length, block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.l2jmobius.commons.network.ICrypt#decrypt(io.netty.buffer.ByteBuf)
|
||||
*/
|
||||
@Override
|
||||
public void decrypt(ByteBuf buf)
|
||||
{
|
||||
// Packet size must be multiple of 8
|
||||
if ((buf.readableBytes() % 8) != 0)
|
||||
{
|
||||
buf.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
final byte[] block = new byte[8];
|
||||
while (buf.isReadable(8))
|
||||
{
|
||||
buf.readBytes(block);
|
||||
_blowfishEngine.decryptBlock(block, 0);
|
||||
buf.setBytes(buf.readerIndex() - block.length, block);
|
||||
}
|
||||
|
||||
// TODO: verify checksum also dont forget!
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import java.util.logging.Logger;
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.commons.enums.ServerMode;
|
||||
import org.l2jmobius.commons.network.NetServer;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.util.DeadLockDetector;
|
||||
import org.l2jmobius.commons.util.PropertiesParser;
|
||||
@ -119,19 +120,18 @@ import org.l2jmobius.gameserver.model.siege.clanhalls.BanditStrongholdSiege;
|
||||
import org.l2jmobius.gameserver.model.siege.clanhalls.DevastatedCastle;
|
||||
import org.l2jmobius.gameserver.model.siege.clanhalls.FortressOfResistance;
|
||||
import org.l2jmobius.gameserver.model.spawn.AutoSpawnHandler;
|
||||
import org.l2jmobius.gameserver.network.ClientNetworkManager;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.PacketHandler;
|
||||
import org.l2jmobius.gameserver.scripting.ScriptEngineManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.ItemsAutoDestroyTaskManager;
|
||||
import org.l2jmobius.gameserver.taskmanager.TaskManager;
|
||||
import org.l2jmobius.gameserver.ui.Gui;
|
||||
import org.l2jmobius.telnet.TelnetStatusThread;
|
||||
|
||||
public class GameServer
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(GameServer.class.getName());
|
||||
|
||||
private static TelnetStatusThread _statusServer;
|
||||
private static GameServer INSTANCE;
|
||||
public static final Calendar dateTimeServerStarted = Calendar.getInstance();
|
||||
|
||||
@ -463,20 +463,23 @@ public class GameServer
|
||||
}
|
||||
|
||||
printSection("Status");
|
||||
|
||||
if (Config.IS_TELNET_ENABLED)
|
||||
{
|
||||
_statusServer = new TelnetStatusThread();
|
||||
_statusServer.start();
|
||||
}
|
||||
|
||||
System.gc();
|
||||
final long totalMem = Runtime.getRuntime().maxMemory() / 1048576;
|
||||
LOGGER.info(getClass().getSimpleName() + ": Started, using " + getUsedMemoryMB() + " of " + totalMem + " MB total memory.");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Maximum number of connected players is " + Config.MAXIMUM_ONLINE_USERS + ".");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Server loaded in " + ((System.currentTimeMillis() - serverLoadStart) / 1000) + " seconds.");
|
||||
|
||||
ClientNetworkManager.getInstance().start();
|
||||
final NetServer<GameClient> server = new NetServer<>(Config.GAMESERVER_HOSTNAME, Config.PORT_GAME, new PacketHandler(), GameClient::new);
|
||||
server.setName(getClass().getSimpleName());
|
||||
server.getNetConfig().setReadPoolSize(Config.CLIENT_READ_POOL_SIZE);
|
||||
server.getNetConfig().setExecutePoolSize(Config.CLIENT_EXECUTE_POOL_SIZE);
|
||||
server.getNetConfig().setPacketQueueLimit(Config.PACKET_QUEUE_LIMIT);
|
||||
server.getNetConfig().setPacketFloodDisconnect(Config.PACKET_FLOOD_DISCONNECT);
|
||||
server.getNetConfig().setPacketFloodDrop(Config.PACKET_FLOOD_DROP);
|
||||
server.getNetConfig().setPacketFloodLogged(Config.PACKET_FLOOD_LOGGED);
|
||||
server.getNetConfig().setTcpNoDelay(Config.TCP_NO_DELAY);
|
||||
server.getNetConfig().setConnectionTimeout(Config.CONNECTION_TIMEOUT);
|
||||
server.start();
|
||||
|
||||
LoginServerThread.getInstance().start();
|
||||
|
||||
|
@ -38,9 +38,9 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.BaseSendablePacket;
|
||||
import org.l2jmobius.commons.crypt.NewCrypt;
|
||||
import org.l2jmobius.commons.network.WritablePacket;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.commons.util.crypt.NewCrypt;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.ConnectionState;
|
||||
@ -279,6 +279,7 @@ public class LoginServerThread extends Thread
|
||||
if (wc.account.equals(account))
|
||||
{
|
||||
wcToRemove = wc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -320,7 +321,7 @@ public class LoginServerThread extends Thread
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": LoginServer not avaible, trying to reconnect...");
|
||||
LOGGER.warning(getClass().getSimpleName() + ": LoginServer not available, trying to reconnect...");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@ -355,25 +356,26 @@ public class LoginServerThread extends Thread
|
||||
|
||||
/**
|
||||
* Adds the waiting client and send request.
|
||||
* @param acc the account
|
||||
* @param accountName the account
|
||||
* @param client the game client
|
||||
* @param key the session key
|
||||
*/
|
||||
public void addWaitingClientAndSendRequest(String acc, GameClient client, SessionKey key)
|
||||
public void addWaitingClientAndSendRequest(String accountName, GameClient client, SessionKey key)
|
||||
{
|
||||
final WaitingClient wc = new WaitingClient(acc, client, key);
|
||||
final WaitingClient wc = new WaitingClient(accountName, client, key);
|
||||
synchronized (_waitingClients)
|
||||
{
|
||||
_waitingClients.add(wc);
|
||||
}
|
||||
final PlayerAuthRequest par = new PlayerAuthRequest(acc, key);
|
||||
|
||||
final PlayerAuthRequest par = new PlayerAuthRequest(accountName, key);
|
||||
try
|
||||
{
|
||||
sendPacket(par);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while sending player auth request");
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while sending player auth request.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,6 +393,7 @@ public class LoginServerThread extends Thread
|
||||
if (c.gameClient == client)
|
||||
{
|
||||
toRemove = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toRemove != null)
|
||||
@ -417,7 +420,7 @@ public class LoginServerThread extends Thread
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while sending logout packet to login");
|
||||
LOGGER.warning(getClass().getSimpleName() + ": Error while sending logout packet to login.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -495,25 +498,38 @@ public class LoginServerThread extends Thread
|
||||
|
||||
/**
|
||||
* Send packet.
|
||||
* @param sl the sendable packet
|
||||
* @param packet the sendable packet
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
private void sendPacket(BaseSendablePacket sl) throws IOException
|
||||
private void sendPacket(WritablePacket packet) throws IOException
|
||||
{
|
||||
if (_blowfish == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final byte[] data = sl.getContent();
|
||||
NewCrypt.appendChecksum(data);
|
||||
_blowfish.crypt(data, 0, data.length);
|
||||
|
||||
final int len = data.length + 2;
|
||||
synchronized (_out) // avoids tow threads writing in the mean time
|
||||
packet.write(); // write initial data
|
||||
packet.writeInt(0); // reserved for checksum
|
||||
int size = packet.getLength() - 2; // size without header
|
||||
final int padding = size % 8; // padding of 8 bytes
|
||||
if (padding != 0)
|
||||
{
|
||||
for (int i = padding; i < 8; i++)
|
||||
{
|
||||
packet.writeByte(0);
|
||||
}
|
||||
}
|
||||
|
||||
// size header + encrypted[data + checksum (int) + padding]
|
||||
final byte[] data = packet.getSendableBytes();
|
||||
|
||||
// encrypt
|
||||
size = data.length - 2; // data size without header
|
||||
NewCrypt.appendChecksum(data, 2, size);
|
||||
_blowfish.crypt(data, 2, size);
|
||||
|
||||
synchronized (_out)
|
||||
{
|
||||
_out.write(len & 0xff);
|
||||
_out.write((len >> 8) & 0xff);
|
||||
_out.write(data);
|
||||
_out.flush();
|
||||
}
|
||||
|
@ -41,8 +41,6 @@ import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.olympiad.Olympiad;
|
||||
import org.l2jmobius.gameserver.model.sevensigns.SevenSigns;
|
||||
import org.l2jmobius.gameserver.model.sevensigns.SevenSignsFestival;
|
||||
import org.l2jmobius.gameserver.network.ClientNetworkManager;
|
||||
import org.l2jmobius.gameserver.network.EventLoopGroupManager;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
||||
@ -307,18 +305,6 @@ public class Shutdown extends Thread
|
||||
// ignore
|
||||
}
|
||||
|
||||
// saveData sends messages to exit players, so shutdown selector after it
|
||||
try
|
||||
{
|
||||
ClientNetworkManager.getInstance().stop();
|
||||
EventLoopGroupManager.getInstance().shutdown();
|
||||
LOGGER.info("Game Server: Selector thread has been shutdown.");
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
// stop all threadpolls
|
||||
try
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ import org.l2jmobius.gameserver.model.AccessLevel;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
@ -302,7 +302,7 @@ public class AdminData implements IXmlReader
|
||||
}
|
||||
}
|
||||
|
||||
public static void broadcastToGMs(IClientOutgoingPacket packet)
|
||||
public static void broadcastToGMs(ServerPacket packet)
|
||||
{
|
||||
for (Player gm : getInstance().getAllGms(true))
|
||||
{
|
||||
|
@ -71,8 +71,7 @@ public class AdminDisconnect implements IAdminCommandHandler
|
||||
BuilderUtil.sendSysMessage(activeChar, "Character " + player.getName() + " disconnected from server.");
|
||||
|
||||
// Logout Character
|
||||
player.sendPacket(LeaveWorld.STATIC_PACKET);
|
||||
player.closeNetConnection();
|
||||
player.getClient().close(LeaveWorld.STATIC_PACKET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -967,7 +967,7 @@ public class AdminEditChar implements IAdminCommandHandler
|
||||
if (player.getClient() != null)
|
||||
{
|
||||
account = player.getClient().getAccountName();
|
||||
ip = player.getClient().getIpAddress();
|
||||
ip = player.getClient().getIp();
|
||||
}
|
||||
|
||||
final NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
|
||||
@ -1195,12 +1195,12 @@ public class AdminEditChar implements IAdminCommandHandler
|
||||
final Map<String, Integer> dualboxIPs = new HashMap<>();
|
||||
for (Player player : players)
|
||||
{
|
||||
if ((player.getClient() == null) || (player.getClient().getConnectionAddress() == null) || (player.getClient().getConnectionAddress() == null) || (player.getClient().getConnectionAddress().getHostAddress() == null))
|
||||
if ((player.getClient() == null) || (player.getClient().getIp() == null))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ip = player.getClient().getConnectionAddress().getHostAddress();
|
||||
ip = player.getClient().getIp();
|
||||
if (ipMap.get(ip) == null)
|
||||
{
|
||||
ipMap.put(ip, new ArrayList<Player>());
|
||||
@ -1260,12 +1260,12 @@ public class AdminEditChar implements IAdminCommandHandler
|
||||
|
||||
for (Player player : players)
|
||||
{
|
||||
if ((player.getClient() == null) || (player.getClient().getConnectionAddress() == null) || (player.getClient().getConnectionAddress() == null) || (player.getClient().getConnectionAddress().getHostAddress() == null))
|
||||
if ((player.getClient() == null) || (player.getClient().getIp() == null))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ip = player.getClient().getConnectionAddress().getHostAddress();
|
||||
ip = player.getClient().getIp();
|
||||
if (ip.equals(ipAdress))
|
||||
{
|
||||
name = player.getName();
|
||||
|
@ -30,9 +30,9 @@ import org.l2jmobius.gameserver.model.actor.instance.Chest;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.Earthquake;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExRedSky;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PlaySound;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SignsSky;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SocialAction;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.StopMove;
|
||||
@ -687,7 +687,7 @@ public class AdminEffects implements IAdminCommandHandler
|
||||
*/
|
||||
private void adminAtmosphere(String type, String state, Player activeChar)
|
||||
{
|
||||
IClientOutgoingPacket packet = null;
|
||||
ServerPacket packet = null;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ public class AdminOnline implements IAdminCommandHandler
|
||||
{
|
||||
if (player.getClient() != null)
|
||||
{
|
||||
final String ip = player.getClient().getIpAddress();
|
||||
final String ip = player.getClient().getIp();
|
||||
if ((ip != null) && !ips.contains(ip))
|
||||
{
|
||||
ips.add(ip);
|
||||
|
@ -150,7 +150,7 @@ public class AdminServerInfo implements IAdminCommandHandler
|
||||
{
|
||||
if ((onlinePlayer != null) && (onlinePlayer.getClient() != null) && !onlinePlayer.getClient().isDetached())
|
||||
{
|
||||
realPlayers.add(onlinePlayer.getClient().getIpAddress());
|
||||
realPlayers.add(onlinePlayer.getClient().getIp());
|
||||
}
|
||||
}
|
||||
return realPlayers.size();
|
||||
|
@ -23,7 +23,7 @@ import java.util.logging.Logger;
|
||||
import org.l2jmobius.gameserver.model.Duel;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.effects.Effect;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
|
||||
public class DuelManager
|
||||
{
|
||||
@ -189,7 +189,7 @@ public class DuelManager
|
||||
* @param player
|
||||
* @param packet
|
||||
*/
|
||||
public void broadcastToOppositTeam(Player player, IClientOutgoingPacket packet)
|
||||
public void broadcastToOppositTeam(Player player, ServerPacket packet)
|
||||
{
|
||||
if ((player == null) || !player.isInDuel())
|
||||
{
|
||||
|
@ -30,8 +30,8 @@ import org.l2jmobius.gameserver.enums.ChatType;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
@ -178,7 +178,7 @@ public class PetitionManager
|
||||
return _type.toString().replace("_", " ");
|
||||
}
|
||||
|
||||
public void sendPetitionerPacket(IClientOutgoingPacket responsePacket)
|
||||
public void sendPetitionerPacket(ServerPacket responsePacket)
|
||||
{
|
||||
if ((_petitioner == null) || !_petitioner.isOnline())
|
||||
{
|
||||
@ -188,7 +188,7 @@ public class PetitionManager
|
||||
_petitioner.sendPacket(responsePacket);
|
||||
}
|
||||
|
||||
public void sendResponderPacket(IClientOutgoingPacket responsePacket)
|
||||
public void sendResponderPacket(ServerPacket responsePacket)
|
||||
{
|
||||
if ((_responder == null) || !_responder.isOnline())
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExCloseMPCC;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExOpenMPCC;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
@ -145,9 +145,9 @@ public class CommandChannel
|
||||
|
||||
/**
|
||||
* Broadcast packet to every channel member
|
||||
* @param gsp
|
||||
* @param packet
|
||||
*/
|
||||
public void broadcastToChannelMembers(IClientOutgoingPacket gsp)
|
||||
public void broadcastToChannelMembers(ServerPacket packet)
|
||||
{
|
||||
if ((_parties != null) && !_parties.isEmpty())
|
||||
{
|
||||
@ -155,7 +155,7 @@ public class CommandChannel
|
||||
{
|
||||
if (party != null)
|
||||
{
|
||||
party.broadcastToPartyMembers(gsp);
|
||||
party.broadcastToPartyMembers(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ import org.l2jmobius.gameserver.network.serverpackets.ExDuelEnd;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExDuelReady;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExDuelStart;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExDuelUpdateUserInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PlaySound;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SocialAction;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
@ -664,7 +664,7 @@ public class Duel
|
||||
* Broadcast a packet to the challanger team.
|
||||
* @param packet the packet
|
||||
*/
|
||||
public void broadcastToTeam1(IClientOutgoingPacket packet)
|
||||
public void broadcastToTeam1(ServerPacket packet)
|
||||
{
|
||||
if (_playerA == null)
|
||||
{
|
||||
@ -688,7 +688,7 @@ public class Duel
|
||||
* Broadcast a packet to the challenged team.
|
||||
* @param packet the packet
|
||||
*/
|
||||
public void broadcastToTeam2(IClientOutgoingPacket packet)
|
||||
public void broadcastToTeam2(ServerPacket packet)
|
||||
{
|
||||
if (_playerB == null)
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ public class MacroList
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.info("Player: " + _owner.getName() + " IP:" + _owner.getClient().getConnectionAddress().getHostAddress() + " trird to use bug with macros.");
|
||||
LOGGER.info("Player: " + _owner.getName() + " IP:" + _owner.getClient().getIp() + " trird to use bug with macros.");
|
||||
LOGGER.warning("could not store macro: " + e);
|
||||
}
|
||||
}
|
||||
|
@ -42,12 +42,12 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExCloseMPCC;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExOpenMPCC;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartyMemberPosition;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowAdd;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowAll;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowDelete;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartySmallWindowDeleteAll;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.taskmanager.GameTimeTaskManager;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
@ -281,15 +281,15 @@ public class Party
|
||||
|
||||
/**
|
||||
* Broadcasts packet to every party member
|
||||
* @param msg
|
||||
* @param packet
|
||||
*/
|
||||
public void broadcastToPartyMembers(IClientOutgoingPacket msg)
|
||||
public void broadcastToPartyMembers(ServerPacket packet)
|
||||
{
|
||||
for (Player member : _members)
|
||||
{
|
||||
if (member != null)
|
||||
{
|
||||
member.sendPacket(msg);
|
||||
member.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,15 +327,15 @@ public class Party
|
||||
/**
|
||||
* Send a Server->Client packet to all other Player of the Party.
|
||||
* @param player
|
||||
* @param msg
|
||||
* @param packet
|
||||
*/
|
||||
public void broadcastToPartyMembers(Player player, IClientOutgoingPacket msg)
|
||||
public void broadcastToPartyMembers(Player player, ServerPacket packet)
|
||||
{
|
||||
for (Player member : _members)
|
||||
{
|
||||
if ((member != null) && !member.equals(player))
|
||||
{
|
||||
member.sendPacket(msg);
|
||||
member.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package org.l2jmobius.gameserver.model;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
/**
|
||||
@ -34,7 +34,7 @@ public class Request
|
||||
protected Player _partner;
|
||||
protected boolean _isRequestor;
|
||||
protected boolean _isAnswerer;
|
||||
protected IClientIncomingPacket _requestPacket;
|
||||
protected ClientPacket _requestPacket;
|
||||
|
||||
public Request(Player player)
|
||||
{
|
||||
@ -70,7 +70,7 @@ public class Request
|
||||
* Set the packet incomed from requester.
|
||||
* @param packet
|
||||
*/
|
||||
private synchronized void setRequestPacket(IClientIncomingPacket packet)
|
||||
private synchronized void setRequestPacket(ClientPacket packet)
|
||||
{
|
||||
_requestPacket = packet;
|
||||
}
|
||||
@ -78,7 +78,7 @@ public class Request
|
||||
/**
|
||||
* @return the packet originally incomed from requester.
|
||||
*/
|
||||
public IClientIncomingPacket getRequestPacket()
|
||||
public ClientPacket getRequestPacket()
|
||||
{
|
||||
return _requestPacket;
|
||||
}
|
||||
@ -89,7 +89,7 @@ public class Request
|
||||
* @param packet
|
||||
* @return
|
||||
*/
|
||||
public synchronized boolean setRequest(Player partner, IClientIncomingPacket packet)
|
||||
public synchronized boolean setRequest(Player partner, ClientPacket packet)
|
||||
{
|
||||
if (partner == null)
|
||||
{
|
||||
|
@ -29,6 +29,7 @@ import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.Pet;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
||||
|
||||
public class World
|
||||
{
|
||||
@ -333,8 +334,8 @@ public class World
|
||||
{
|
||||
// This can happen when offline system is enabled.
|
||||
// LOGGER.warning("Teleporting: Duplicate character!? Closing both characters (" + player.getName() + ")");
|
||||
player.closeNetConnection();
|
||||
tmp.closeNetConnection();
|
||||
player.getClient().close(LeaveWorld.STATIC_PACKET);
|
||||
tmp.getClient().close(LeaveWorld.STATIC_PACKET);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,6 @@ import org.l2jmobius.gameserver.network.serverpackets.Attack;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ChangeMoveType;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ChangeWaitType;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExOlympiadSpelledInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MagicEffectIcons;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillCanceld;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillLaunched;
|
||||
@ -117,6 +116,7 @@ import org.l2jmobius.gameserver.network.serverpackets.NpcInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartySpelled;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PetInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.Revive;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SetupGauge;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SocialAction;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.StatusUpdate;
|
||||
@ -387,15 +387,15 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
getAttackByList().add(creature);
|
||||
}
|
||||
|
||||
public void broadcastPacket(IClientOutgoingPacket mov)
|
||||
public void broadcastPacket(ServerPacket packet)
|
||||
{
|
||||
for (Player player : getKnownList().getKnownPlayers().values())
|
||||
{
|
||||
player.sendPacket(mov);
|
||||
player.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastPacket(IClientOutgoingPacket mov, int radius)
|
||||
public void broadcastPacket(ServerPacket packet, int radius)
|
||||
{
|
||||
for (Player player : getKnownList().getKnownPlayers().values())
|
||||
{
|
||||
@ -404,7 +404,7 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
continue;
|
||||
}
|
||||
|
||||
player.sendPacket(mov);
|
||||
player.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -526,9 +526,9 @@ public abstract class Creature extends WorldObject implements ISkillsHolder
|
||||
* <br>
|
||||
* <b><u>Overridden in</u>:</b><br>
|
||||
* <li>Player</li><br>
|
||||
* @param mov the mov
|
||||
* @param packet the packet
|
||||
*/
|
||||
public void sendPacket(IClientOutgoingPacket mov)
|
||||
public void sendPacket(ServerPacket packet)
|
||||
{
|
||||
// default implementation
|
||||
}
|
||||
|
@ -191,7 +191,6 @@ import org.l2jmobius.gameserver.network.serverpackets.ExPCCafePointInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ExSetCompassZoneCode;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.FriendList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.HennaInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ItemList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
||||
@ -213,6 +212,7 @@ import org.l2jmobius.gameserver.network.serverpackets.RecipeShopSellList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.RelationChanged;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.Ride;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SendTradeDone;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SetupGauge;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ShortBuffStatusUpdate;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ShortCutInit;
|
||||
@ -1141,7 +1141,7 @@ public class Player extends Playable
|
||||
public void logout(boolean kicked)
|
||||
{
|
||||
_kicked = kicked;
|
||||
closeNetConnection();
|
||||
_client.close(LeaveWorld.STATIC_PACKET);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4242,18 +4242,6 @@ public class Player extends Playable
|
||||
_client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the active connection with the client.
|
||||
*/
|
||||
public void closeNetConnection()
|
||||
{
|
||||
if (_client != null)
|
||||
{
|
||||
_client.close(new LeaveWorld());
|
||||
setClient(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage actions when a player click on this Player.<br>
|
||||
* <br>
|
||||
@ -4781,12 +4769,12 @@ public class Player extends Playable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastPacket(IClientOutgoingPacket mov)
|
||||
public void broadcastPacket(ServerPacket packet)
|
||||
{
|
||||
final boolean isCharInfo = mov instanceof CharInfo;
|
||||
final boolean isCharInfo = packet instanceof CharInfo;
|
||||
if (!isCharInfo)
|
||||
{
|
||||
sendPacket(mov);
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
for (Player player : getKnownList().getKnownPlayers().values())
|
||||
@ -4796,7 +4784,7 @@ public class Player extends Playable
|
||||
continue;
|
||||
}
|
||||
|
||||
player.sendPacket(mov);
|
||||
player.sendPacket(packet);
|
||||
|
||||
if (isCharInfo)
|
||||
{
|
||||
@ -4810,12 +4798,12 @@ public class Player extends Playable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastPacket(IClientOutgoingPacket mov, int radius)
|
||||
public void broadcastPacket(ServerPacket packet, int radius)
|
||||
{
|
||||
final boolean isCharInfo = mov instanceof CharInfo;
|
||||
final boolean isCharInfo = packet instanceof CharInfo;
|
||||
if (!isCharInfo)
|
||||
{
|
||||
sendPacket(mov);
|
||||
sendPacket(packet);
|
||||
}
|
||||
|
||||
for (Player player : getKnownList().getKnownPlayers().values())
|
||||
@ -4830,7 +4818,7 @@ public class Player extends Playable
|
||||
continue;
|
||||
}
|
||||
|
||||
player.sendPacket(mov);
|
||||
player.sendPacket(packet);
|
||||
|
||||
if (isCharInfo)
|
||||
{
|
||||
@ -5991,8 +5979,8 @@ public class Player extends Playable
|
||||
// Anti FARM same IP
|
||||
if (Config.ANTI_FARM_IP_ENABLED && (_client != null) && (targetPlayer.getClient() != null))
|
||||
{
|
||||
final String ip1 = _client.getConnectionAddress().getHostAddress();
|
||||
final String ip2 = targetPlayer.getClient().getConnectionAddress().getHostAddress();
|
||||
final String ip1 = _client.getIp();
|
||||
final String ip2 = targetPlayer.getClient().getIp();
|
||||
if (ip1.equals(ip2))
|
||||
{
|
||||
sendMessage("Farm is punishable with Ban! GM informed.");
|
||||
@ -6012,9 +6000,9 @@ public class Player extends Playable
|
||||
private void addItemReward(Player targetPlayer)
|
||||
{
|
||||
// IP check
|
||||
if ((targetPlayer.getClient() != null) && (targetPlayer.getClient().getConnectionAddress() != null))
|
||||
if ((targetPlayer.getClient() != null) && (targetPlayer.getClient().getIp() != null))
|
||||
{
|
||||
if (targetPlayer.getClient().getConnectionAddress() != _client.getConnectionAddress())
|
||||
if (targetPlayer.getClient().getIp() != _client.getIp())
|
||||
{
|
||||
if ((targetPlayer.getKarma() > 0) || (targetPlayer.getPvpFlag() > 0)) // killing target pk or in pvp
|
||||
{
|
||||
@ -10809,7 +10797,7 @@ public class Player extends Playable
|
||||
* Send a Server->Client packet StatusUpdate to the Player.
|
||||
*/
|
||||
@Override
|
||||
public void sendPacket(IClientOutgoingPacket packet)
|
||||
public void sendPacket(ServerPacket packet)
|
||||
{
|
||||
if (_client != null)
|
||||
{
|
||||
@ -13372,7 +13360,10 @@ public class Player extends Playable
|
||||
}
|
||||
|
||||
// Close the connection with the client
|
||||
closeNetConnection();
|
||||
if (_client != null)
|
||||
{
|
||||
_client.close(LeaveWorld.STATIC_PACKET);
|
||||
}
|
||||
|
||||
if (getClanId() > 0)
|
||||
{
|
||||
@ -14670,12 +14661,12 @@ public class Player extends Playable
|
||||
boolean canMultiBox = true;
|
||||
int boxCount = 1;
|
||||
final List<String> activeBoxes = new ArrayList<>();
|
||||
if ((_client != null) && (_client.getConnectionAddress() != null) && !_client.isDetached() && (_client.getConnectionAddress() != null))
|
||||
if ((_client != null) && (_client.getIp() != null) && !_client.isDetached() && (_client.getIp() != null))
|
||||
{
|
||||
final String playerIP = _client.getConnectionAddress().getHostAddress();
|
||||
final String playerIP = _client.getIp();
|
||||
for (Player player : World.getInstance().getAllPlayers())
|
||||
{
|
||||
if ((player != null) && (player != this) && player.isOnline() && (player.getClient() != null) && (player.getClient().getConnectionAddress() != null) && !player.getClient().isDetached() && (player.getClient().getConnectionAddress() != null) && playerIP.equals(player.getClient().getConnectionAddress().getHostAddress()))
|
||||
if ((player != null) && (player != this) && player.isOnline() && (player.getClient() != null) && (player.getClient().getIp() != null) && !player.getClient().isDetached() && playerIP.equals(player.getClient().getIp()))
|
||||
{
|
||||
boxCount++;
|
||||
activeBoxes.add(player.getName());
|
||||
@ -14707,12 +14698,12 @@ public class Player extends Playable
|
||||
*/
|
||||
public void refreshOtherBoxes()
|
||||
{
|
||||
if ((_client != null) && (_client.getConnectionAddress() != null) && !_client.isDetached() && (_client.getConnectionAddress() != null))
|
||||
if ((_client != null) && (_client.getIp() != null) && !_client.isDetached())
|
||||
{
|
||||
final String playerIP = _client.getConnectionAddress().getHostAddress();
|
||||
final String playerIP = _client.getIp();
|
||||
for (Player player : World.getInstance().getAllPlayers())
|
||||
{
|
||||
if ((player != null) && (player != this) && player.isOnline() && (player.getClient() != null) && (player.getClient().getConnectionAddress() != null) && !player.getClient().isDetached() && !player.getName().equals(getName()) && playerIP.equals(player.getClient().getConnectionAddress().getHostAddress()))
|
||||
if ((player != null) && (player != this) && player.isOnline() && (player.getClient() != null) && (player.getClient().getIp() != null) && !player.getClient().isDetached() && !player.getName().equals(getName()) && playerIP.equals(player.getClient().getIp()))
|
||||
{
|
||||
player._activeBoxes = _activeBoxes;
|
||||
player._activeBoxCharacters = _activeBoxCharacters;
|
||||
|
@ -21,6 +21,7 @@ import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
|
||||
import org.l2jmobius.gameserver.model.clan.Clan;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.WareHouseDepositList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.WareHouseWithdrawalList;
|
||||
@ -133,7 +134,7 @@ public class CastleWarehouse extends Folk
|
||||
if ((player.getActiveEnchantItem() != null) || (player.getActiveTradeList() != null))
|
||||
{
|
||||
LOGGER.info(player + " trying to use enchant exploit, ban this player!");
|
||||
player.closeNetConnection();
|
||||
player.getClient().close(LeaveWorld.STATIC_PACKET);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,6 @@ import org.l2jmobius.gameserver.model.itemcontainer.ItemContainer;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ItemList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PledgeReceiveSubPledgeCreated;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PledgeShowInfoUpdate;
|
||||
@ -55,6 +54,7 @@ import org.l2jmobius.gameserver.network.serverpackets.PledgeShowMemberListAll;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PledgeShowMemberListDeleteAll;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PledgeShowMemberListUpdate;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PledgeSkillListAdd;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.StatusUpdate;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
@ -1139,7 +1139,7 @@ public class Clan
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastToOnlineAllyMembers(IClientOutgoingPacket packet)
|
||||
public void broadcastToOnlineAllyMembers(ServerPacket packet)
|
||||
{
|
||||
if (_allyId == 0)
|
||||
{
|
||||
@ -1155,7 +1155,7 @@ public class Clan
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastToOnlineMembers(IClientOutgoingPacket packet)
|
||||
public void broadcastToOnlineMembers(ServerPacket packet)
|
||||
{
|
||||
for (ClanMember member : _members.values())
|
||||
{
|
||||
@ -1173,7 +1173,7 @@ public class Clan
|
||||
}
|
||||
}
|
||||
|
||||
public void broadcastToOtherOnlineMembers(IClientOutgoingPacket packet, Player player)
|
||||
public void broadcastToOtherOnlineMembers(ServerPacket packet, Player player)
|
||||
{
|
||||
for (ClanMember member : _members.values())
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
|
||||
/**
|
||||
* Abstract base class for any zone type Handles basic operations
|
||||
@ -331,7 +331,7 @@ public abstract class ZoneType
|
||||
* Broadcasts packet to all players inside the zone
|
||||
* @param packet
|
||||
*/
|
||||
public void broadcastPacket(IClientOutgoingPacket packet)
|
||||
public void broadcastPacket(ServerPacket packet)
|
||||
{
|
||||
if (_characterList.isEmpty())
|
||||
{
|
||||
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
import org.l2jmobius.commons.network.codecs.CryptCodec;
|
||||
import org.l2jmobius.commons.network.codecs.LengthFieldBasedFrameEncoder;
|
||||
import org.l2jmobius.commons.network.codecs.PacketDecoder;
|
||||
import org.l2jmobius.commons.network.codecs.PacketEncoder;
|
||||
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class ClientInitializer extends ChannelInitializer<SocketChannel>
|
||||
{
|
||||
private static final LengthFieldBasedFrameEncoder LENGTH_ENCODER = new LengthFieldBasedFrameEncoder();
|
||||
private static final PacketEncoder PACKET_ENCODER = new PacketEncoder(0x8000 - 2);
|
||||
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch)
|
||||
{
|
||||
final GameClient client = new GameClient();
|
||||
ch.pipeline().addLast("length-decoder", new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 0x8000 - 2, 0, 2, -2, 2, false));
|
||||
ch.pipeline().addLast("length-encoder", LENGTH_ENCODER);
|
||||
ch.pipeline().addLast("crypt-codec", new CryptCodec(client.getCrypt()));
|
||||
// ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
|
||||
ch.pipeline().addLast("packet-decoder", new PacketDecoder<>(IncomingPackets.PACKET_ARRAY, client));
|
||||
ch.pipeline().addLast("packet-encoder", PACKET_ENCODER);
|
||||
ch.pipeline().addLast(client);
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.NetworkManager;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class ClientNetworkManager extends NetworkManager
|
||||
{
|
||||
protected ClientNetworkManager()
|
||||
{
|
||||
super(EventLoopGroupManager.getInstance().getBossGroup(), EventLoopGroupManager.getInstance().getWorkerGroup(), new ClientInitializer(), Config.GAMESERVER_HOSTNAME, Config.PORT_GAME);
|
||||
}
|
||||
|
||||
public static ClientNetworkManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final ClientNetworkManager INSTANCE = new ClientNetworkManager();
|
||||
}
|
||||
}
|
@ -22,15 +22,12 @@ import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.IConnectionState;
|
||||
import org.l2jmobius.commons.network.IIncomingPacket;
|
||||
import org.l2jmobius.commons.network.IIncomingPackets;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.*;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public enum IncomingPackets implements IIncomingPackets<GameClient>
|
||||
public enum ClientPackets
|
||||
{
|
||||
PROTOCOL_VERSION(0x00, ProtocolVersion::new, ConnectionState.CONNECTED),
|
||||
AUTH_LOGIN(0x08, AuthLogin::new, ConnectionState.CONNECTED),
|
||||
@ -193,44 +190,42 @@ public enum IncomingPackets implements IIncomingPackets<GameClient>
|
||||
REQUEST_RECORD_INFO(0xCF, RequestRecordInfo::new, ConnectionState.IN_GAME),
|
||||
EX_PACKET(0xD0, ExPacket::new, ConnectionState.values()); // This packet has its own connection state checking so we allow all of them
|
||||
|
||||
public static final IncomingPackets[] PACKET_ARRAY;
|
||||
public static final ClientPackets[] PACKET_ARRAY;
|
||||
static
|
||||
{
|
||||
final short maxPacketId = (short) Arrays.stream(values()).mapToInt(IIncomingPackets::getPacketId).max().orElse(0);
|
||||
PACKET_ARRAY = new IncomingPackets[maxPacketId + 1];
|
||||
for (IncomingPackets incomingPacket : values())
|
||||
final int maxPacketId = Arrays.stream(values()).mapToInt(ClientPackets::getPacketId).max().orElse(0);
|
||||
PACKET_ARRAY = new ClientPackets[maxPacketId + 1];
|
||||
for (ClientPackets packet : values())
|
||||
{
|
||||
PACKET_ARRAY[incomingPacket.getPacketId()] = incomingPacket;
|
||||
PACKET_ARRAY[packet.getPacketId()] = packet;
|
||||
}
|
||||
}
|
||||
|
||||
private short _packetId;
|
||||
private Supplier<IIncomingPacket<GameClient>> _incomingPacketFactory;
|
||||
private Set<IConnectionState> _connectionStates;
|
||||
private int _packetId;
|
||||
private Supplier<ClientPacket> _packetSupplier;
|
||||
private Set<ConnectionState> _connectionStates;
|
||||
|
||||
IncomingPackets(int packetId, Supplier<IIncomingPacket<GameClient>> incomingPacketFactory, IConnectionState... connectionStates)
|
||||
ClientPackets(int packetId, Supplier<ClientPacket> packetSupplier, ConnectionState... connectionStates)
|
||||
{
|
||||
// packetId is an unsigned byte
|
||||
// Packet id is an unsigned byte.
|
||||
if (packetId > 0xFF)
|
||||
{
|
||||
throw new IllegalArgumentException("packetId must not be bigger than 0xFF");
|
||||
throw new IllegalArgumentException("Packet id must not be bigger than 0xFF");
|
||||
}
|
||||
|
||||
_packetId = (short) packetId;
|
||||
_incomingPacketFactory = incomingPacketFactory != null ? incomingPacketFactory : () -> null;
|
||||
_packetId = packetId;
|
||||
_packetSupplier = packetSupplier != null ? packetSupplier : () -> null;
|
||||
_connectionStates = new HashSet<>(Arrays.asList(connectionStates));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPacketId()
|
||||
{
|
||||
return _packetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIncomingPacket<GameClient> newIncomingPacket()
|
||||
public ClientPacket newPacket()
|
||||
{
|
||||
final IIncomingPacket<GameClient> packet = _incomingPacketFactory.get();
|
||||
final ClientPacket packet = _packetSupplier.get();
|
||||
if (Config.DEBUG_INCOMING_PACKETS)
|
||||
{
|
||||
if (packet != null)
|
||||
@ -249,8 +244,7 @@ public enum IncomingPackets implements IIncomingPackets<GameClient>
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IConnectionState> getConnectionStates()
|
||||
public Set<ConnectionState> getConnectionStates()
|
||||
{
|
||||
return _connectionStates;
|
||||
}
|
@ -16,12 +16,10 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.IConnectionState;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public enum ConnectionState implements IConnectionState
|
||||
public enum ConnectionState
|
||||
{
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
|
@ -16,14 +16,12 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.l2jmobius.commons.network.EncryptionInterface;
|
||||
|
||||
/**
|
||||
* @author KenM
|
||||
*/
|
||||
public class Crypt implements ICrypt
|
||||
public class Encryption implements EncryptionInterface
|
||||
{
|
||||
private final byte[] _inKey = new byte[16];
|
||||
private final byte[] _outKey = new byte[16];
|
||||
@ -36,35 +34,7 @@ public class Crypt implements ICrypt
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrypt(ByteBuf buf)
|
||||
{
|
||||
if (!_isEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
final int b = buf.readByte() & 0xff;
|
||||
buf.setByte(buf.readerIndex() - 1, b ^ _inKey[(buf.readerIndex() - 1) & 15] ^ a);
|
||||
a = b;
|
||||
}
|
||||
|
||||
// Shift key.
|
||||
int old = _inKey[8] & 0xff;
|
||||
old |= (_inKey[9] << 8) & 0xff00;
|
||||
old |= (_inKey[10] << 16) & 0xff0000;
|
||||
old |= (_inKey[11] << 24) & 0xff000000;
|
||||
old += buf.writerIndex();
|
||||
_inKey[8] = (byte) (old & 0xff);
|
||||
_inKey[9] = (byte) ((old >> 8) & 0xff);
|
||||
_inKey[10] = (byte) ((old >> 16) & 0xff);
|
||||
_inKey[11] = (byte) ((old >> 24) & 0xff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encrypt(ByteBuf buf)
|
||||
public void encrypt(byte[] data, int offset, int size)
|
||||
{
|
||||
if (!_isEnabled)
|
||||
{
|
||||
@ -73,11 +43,11 @@ public class Crypt implements ICrypt
|
||||
}
|
||||
|
||||
int a = 0;
|
||||
while (buf.isReadable())
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
final int b = buf.readByte() & 0xff;
|
||||
a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
|
||||
buf.setByte(buf.readerIndex() - 1, a);
|
||||
final int b = data[offset + i] & 0xff;
|
||||
a = b ^ _outKey[i & 15] ^ a;
|
||||
data[offset + i] = (byte) a;
|
||||
}
|
||||
|
||||
// Shift key.
|
||||
@ -85,10 +55,38 @@ public class Crypt implements ICrypt
|
||||
old |= (_outKey[9] << 8) & 0xff00;
|
||||
old |= (_outKey[10] << 16) & 0xff0000;
|
||||
old |= (_outKey[11] << 24) & 0xff000000;
|
||||
old += buf.writerIndex();
|
||||
old += size;
|
||||
_outKey[8] = (byte) (old & 0xff);
|
||||
_outKey[9] = (byte) ((old >> 8) & 0xff);
|
||||
_outKey[10] = (byte) ((old >> 16) & 0xff);
|
||||
_outKey[11] = (byte) ((old >> 24) & 0xff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrypt(byte[] data, int offset, int size)
|
||||
{
|
||||
if (!_isEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int a = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
final int b = data[offset + i] & 0xff;
|
||||
data[offset + i] = (byte) (b ^ _inKey[i & 15] ^ a);
|
||||
a = b;
|
||||
}
|
||||
|
||||
// Shift key.
|
||||
int old = _inKey[8] & 0xff;
|
||||
old |= (_inKey[9] << 8) & 0xff00;
|
||||
old |= (_inKey[10] << 16) & 0xff0000;
|
||||
old |= (_inKey[11] << 24) & 0xff000000;
|
||||
old += size;
|
||||
_inKey[8] = (byte) (old & 0xff);
|
||||
_inKey[9] = (byte) ((old >> 8) & 0xff);
|
||||
_inKey[10] = (byte) ((old >> 16) & 0xff);
|
||||
_inKey[11] = (byte) ((old >> 24) & 0xff);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class EventLoopGroupManager
|
||||
{
|
||||
private final NioEventLoopGroup _bossGroup = new NioEventLoopGroup(1);
|
||||
private final NioEventLoopGroup _workerGroup = new NioEventLoopGroup(Config.IO_PACKET_THREAD_CORE_SIZE);
|
||||
|
||||
public NioEventLoopGroup getBossGroup()
|
||||
{
|
||||
return _bossGroup;
|
||||
}
|
||||
|
||||
public NioEventLoopGroup getWorkerGroup()
|
||||
{
|
||||
return _workerGroup;
|
||||
}
|
||||
|
||||
public void shutdown()
|
||||
{
|
||||
_bossGroup.shutdownGracefully();
|
||||
_workerGroup.shutdownGracefully();
|
||||
}
|
||||
|
||||
public static EventLoopGroupManager getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final EventLoopGroupManager INSTANCE = new EventLoopGroupManager();
|
||||
}
|
||||
}
|
@ -22,10 +22,8 @@ import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.IConnectionState;
|
||||
import org.l2jmobius.commons.network.IIncomingPacket;
|
||||
import org.l2jmobius.commons.network.IIncomingPackets;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.AnswerJoinPartyRoom;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.RequestAskJoinPartyRoom;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.RequestAutoSoulShot;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.RequestChangePartyLeader;
|
||||
@ -75,7 +73,7 @@ import org.l2jmobius.gameserver.network.clientpackets.RequestWriteHeroWords;
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public enum ExIncomingPackets implements IIncomingPackets<GameClient>
|
||||
public enum ExClientPackets
|
||||
{
|
||||
REQUEST_OUST_FROM_PARTY_ROOM(0x01, RequestOustFromPartyRoom::new, ConnectionState.IN_GAME),
|
||||
REQUEST_DISMISS_PARTY_ROOM(0x02, RequestDismissPartyRoom::new, ConnectionState.IN_GAME),
|
||||
@ -124,43 +122,42 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
|
||||
REQUEST_EX_MAGIC_SKILL_USE_GROUND(0x2F, RequestExMagicSkillUseGround::new, ConnectionState.IN_GAME),
|
||||
REQUEST_DUEL_SURRENDER(0x30, RequestDuelSurrender::new, ConnectionState.IN_GAME);
|
||||
|
||||
public static final ExIncomingPackets[] PACKET_ARRAY;
|
||||
public static final ExClientPackets[] PACKET_ARRAY;
|
||||
static
|
||||
{
|
||||
final short maxPacketId = (short) Arrays.stream(values()).mapToInt(IIncomingPackets::getPacketId).max().orElse(0);
|
||||
PACKET_ARRAY = new ExIncomingPackets[maxPacketId + 1];
|
||||
for (ExIncomingPackets incomingPacket : values())
|
||||
final int maxPacketId = Arrays.stream(values()).mapToInt(ExClientPackets::getPacketId).max().orElse(0);
|
||||
PACKET_ARRAY = new ExClientPackets[maxPacketId + 1];
|
||||
for (ExClientPackets packet : values())
|
||||
{
|
||||
PACKET_ARRAY[incomingPacket.getPacketId()] = incomingPacket;
|
||||
PACKET_ARRAY[packet.getPacketId()] = packet;
|
||||
}
|
||||
}
|
||||
|
||||
private int _packetId;
|
||||
private Supplier<IIncomingPacket<GameClient>> _incomingPacketFactory;
|
||||
private Set<IConnectionState> _connectionStates;
|
||||
private Supplier<ClientPacket> _packetSupplier;
|
||||
private Set<ConnectionState> _connectionStates;
|
||||
|
||||
ExIncomingPackets(int packetId, Supplier<IIncomingPacket<GameClient>> incomingPacketFactory, IConnectionState... connectionStates)
|
||||
ExClientPackets(int packetId, Supplier<ClientPacket> packetSupplier, ConnectionState... connectionStates)
|
||||
{
|
||||
// packetId is an unsigned short
|
||||
// Packet id is an unsigned short.
|
||||
if (packetId > 0xFFFF)
|
||||
{
|
||||
throw new IllegalArgumentException("packetId must not be bigger than 0xFFFF");
|
||||
throw new IllegalArgumentException("Packet id must not be bigger than 0xFFFF");
|
||||
}
|
||||
|
||||
_packetId = packetId;
|
||||
_incomingPacketFactory = incomingPacketFactory != null ? incomingPacketFactory : () -> null;
|
||||
_packetSupplier = packetSupplier != null ? packetSupplier : () -> null;
|
||||
_connectionStates = new HashSet<>(Arrays.asList(connectionStates));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPacketId()
|
||||
{
|
||||
return _packetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIncomingPacket<GameClient> newIncomingPacket()
|
||||
public ClientPacket newPacket()
|
||||
{
|
||||
final IIncomingPacket<GameClient> packet = _incomingPacketFactory.get();
|
||||
final ClientPacket packet = _packetSupplier.get();
|
||||
if (Config.DEBUG_EX_INCOMING_PACKETS)
|
||||
{
|
||||
if (packet != null)
|
||||
@ -179,8 +176,7 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<IConnectionState> getConnectionStates()
|
||||
public Set<ConnectionState> getConnectionStates()
|
||||
{
|
||||
return _connectionStates;
|
||||
}
|
@ -16,25 +16,21 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||
import org.l2jmobius.commons.network.ChannelInboundHandler;
|
||||
import org.l2jmobius.commons.network.ICrypt;
|
||||
import org.l2jmobius.commons.network.IIncomingPacket;
|
||||
import org.l2jmobius.commons.network.EncryptionInterface;
|
||||
import org.l2jmobius.commons.network.NetClient;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.gameserver.LoginServerThread;
|
||||
import org.l2jmobius.gameserver.LoginServerThread.SessionKey;
|
||||
@ -47,30 +43,26 @@ import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.clan.Clan;
|
||||
import org.l2jmobius.gameserver.model.olympiad.Olympiad;
|
||||
import org.l2jmobius.gameserver.model.zone.ZoneId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
import org.l2jmobius.gameserver.util.FloodProtectors;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
* Represents a client connected on Game Server.
|
||||
* Represents a client connected on GameServer.
|
||||
* @author KenM
|
||||
*/
|
||||
public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
public class GameClient extends NetClient
|
||||
{
|
||||
protected static final Logger LOGGER = Logger.getLogger(GameClient.class.getName());
|
||||
protected static final Logger LOGGER_ACCOUNTING = Logger.getLogger("accounting");
|
||||
|
||||
protected Player _player;
|
||||
private final FloodProtectors _floodProtectors = new FloodProtectors(this);
|
||||
private final ReentrantLock _playerLock = new ReentrantLock();
|
||||
private final Crypt _crypt = new Crypt();
|
||||
private InetAddress _addr;
|
||||
private Channel _channel;
|
||||
private ConnectionState _connectionState = ConnectionState.CONNECTED;
|
||||
private Encryption _encryption = null;
|
||||
private String _accountName;
|
||||
private SessionKey _sessionId;
|
||||
private SessionKey _sessionKey;
|
||||
private Player _player;
|
||||
private final List<Integer> _charSlotMapping = new ArrayList<>();
|
||||
private volatile boolean _isDetached = false;
|
||||
private boolean _isAuthedGG;
|
||||
@ -78,61 +70,22 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
private ScheduledFuture<?> _cleanupTask = null;
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx)
|
||||
public void onConnection()
|
||||
{
|
||||
super.channelActive(ctx);
|
||||
|
||||
setConnectionState(ConnectionState.CONNECTED);
|
||||
final InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress();
|
||||
_addr = address.getAddress();
|
||||
_channel = ctx.channel();
|
||||
LOGGER_ACCOUNTING.finer("Client Connected: " + ctx.channel());
|
||||
LOGGER_ACCOUNTING.finer("Client connected: " + getIp());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx)
|
||||
{
|
||||
LOGGER_ACCOUNTING.finer("Client Disconnected: " + ctx.channel());
|
||||
LoginServerThread.getInstance().sendLogout(getAccountName());
|
||||
|
||||
if ((_player == null) || !_player.isInOfflineMode())
|
||||
{
|
||||
// no long running tasks here, do it async
|
||||
try
|
||||
{
|
||||
ThreadPool.execute(new DisconnectTask());
|
||||
}
|
||||
catch (RejectedExecutionException e)
|
||||
{
|
||||
// server is closing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, IIncomingPacket<GameClient> packet)
|
||||
{
|
||||
try
|
||||
{
|
||||
packet.run(this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Exception for: " + toString() + " on packet.run: " + packet.getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
|
||||
public void onDisconnection()
|
||||
{
|
||||
LOGGER_ACCOUNTING.finer("Client disconnected: " + this);
|
||||
LoginServerThread.getInstance().sendLogout(_accountName);
|
||||
_connectionState = ConnectionState.DISCONNECTED;
|
||||
}
|
||||
|
||||
public void closeNow()
|
||||
{
|
||||
if (_channel != null)
|
||||
{
|
||||
_channel.close();
|
||||
}
|
||||
disconnect();
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
@ -144,33 +97,23 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
}
|
||||
}
|
||||
|
||||
public void close(IClientOutgoingPacket packet)
|
||||
public void close(ServerPacket packet)
|
||||
{
|
||||
sendPacket(packet);
|
||||
closeNow();
|
||||
}
|
||||
|
||||
public Channel getChannel()
|
||||
{
|
||||
return _channel;
|
||||
}
|
||||
|
||||
public byte[] enableCrypt()
|
||||
{
|
||||
final byte[] key = BlowFishKeygen.getRandomKey();
|
||||
_crypt.setKey(key);
|
||||
if (Config.PACKET_ENCRYPTION)
|
||||
{
|
||||
_encryption = new Encryption();
|
||||
_encryption.setKey(key);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* For loaded offline traders returns localhost address.
|
||||
* @return cached connection IP address, for checking detached clients.
|
||||
*/
|
||||
public InetAddress getConnectionAddress()
|
||||
{
|
||||
return _addr;
|
||||
}
|
||||
|
||||
public Player getPlayer()
|
||||
{
|
||||
return _player;
|
||||
@ -190,6 +133,11 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
return _playerLock;
|
||||
}
|
||||
|
||||
public FloodProtectors getFloodProtectors()
|
||||
{
|
||||
return _floodProtectors;
|
||||
}
|
||||
|
||||
public void setGameGuardOk(boolean value)
|
||||
{
|
||||
_isAuthedGG = value;
|
||||
@ -200,9 +148,9 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
return _isAuthedGG;
|
||||
}
|
||||
|
||||
public void setAccountName(String pAccountName)
|
||||
public void setAccountName(String accountName)
|
||||
{
|
||||
_accountName = pAccountName;
|
||||
_accountName = accountName;
|
||||
}
|
||||
|
||||
public String getAccountName()
|
||||
@ -210,36 +158,46 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
return _accountName;
|
||||
}
|
||||
|
||||
public void setSessionId(SessionKey sk)
|
||||
public void setSessionId(SessionKey sessionKey)
|
||||
{
|
||||
_sessionId = sk;
|
||||
_sessionKey = sessionKey;
|
||||
}
|
||||
|
||||
public SessionKey getSessionId()
|
||||
{
|
||||
return _sessionId;
|
||||
return _sessionKey;
|
||||
}
|
||||
|
||||
public void sendPacket(IClientOutgoingPacket packet)
|
||||
public void sendPacket(ServerPacket packet)
|
||||
{
|
||||
if (_isDetached || (packet == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Write into the channel.
|
||||
_channel.writeAndFlush(packet);
|
||||
try
|
||||
{
|
||||
if ((getChannel() != null) && getChannel().isConnected())
|
||||
{
|
||||
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
|
||||
if (byteBuffer != null)
|
||||
{
|
||||
// Send the packet data.
|
||||
getChannel().write(byteBuffer);
|
||||
|
||||
// Run packet implementation.
|
||||
packet.runImpl(_player);
|
||||
// Run packet implementation.
|
||||
packet.run(_player);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param smId
|
||||
*/
|
||||
public void sendPacket(SystemMessageId smId)
|
||||
public void sendPacket(SystemMessageId systemMessageId)
|
||||
{
|
||||
sendPacket(new SystemMessage(smId));
|
||||
sendPacket(new SystemMessage(systemMessageId));
|
||||
}
|
||||
|
||||
public boolean isDetached()
|
||||
@ -511,58 +469,6 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
return objectId.intValue();
|
||||
}
|
||||
|
||||
public String getIpAddress()
|
||||
{
|
||||
final InetAddress address = _addr;
|
||||
String ip;
|
||||
if (address == null)
|
||||
{
|
||||
ip = "N/A";
|
||||
}
|
||||
else
|
||||
{
|
||||
ip = address.getHostAddress();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the best possible string representation of this client.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
try
|
||||
{
|
||||
final InetAddress address = _addr;
|
||||
final ConnectionState state = (ConnectionState) getConnectionState();
|
||||
switch (state)
|
||||
{
|
||||
case CONNECTED:
|
||||
{
|
||||
return "[IP: " + (address == null ? "disconnected" : address.getHostAddress()) + "]";
|
||||
}
|
||||
case AUTHENTICATED:
|
||||
{
|
||||
return "[Account: " + _accountName + " - IP: " + (address == null ? "disconnected" : address.getHostAddress()) + "]";
|
||||
}
|
||||
case ENTERING:
|
||||
case IN_GAME:
|
||||
{
|
||||
return "[Character: " + (_player == null ? "disconnected" : _player.getName() + "[" + _player.getObjectId() + "]") + " - Account: " + _accountName + " - IP: " + (address == null ? "disconnected" : address.getHostAddress()) + "]";
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new IllegalStateException("Missing state on switch");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
return "[Character read failed due to disconnect]";
|
||||
}
|
||||
}
|
||||
|
||||
protected class CleanupTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
@ -605,6 +511,7 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
// prevent closing again
|
||||
player.deleteMe();
|
||||
player.store(true);
|
||||
player.setClient(null);
|
||||
}
|
||||
|
||||
setPlayer(null);
|
||||
@ -710,11 +617,6 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
}
|
||||
}
|
||||
|
||||
public FloodProtectors getFloodProtectors()
|
||||
{
|
||||
return _floodProtectors;
|
||||
}
|
||||
|
||||
private boolean cancelCleanup()
|
||||
{
|
||||
final Future<?> task = _cleanupTask;
|
||||
@ -736,8 +638,64 @@ public class GameClient extends ChannelInboundHandler<GameClient>
|
||||
return _protocolVersion;
|
||||
}
|
||||
|
||||
public ICrypt getCrypt()
|
||||
public void setConnectionState(ConnectionState connectionState)
|
||||
{
|
||||
return _crypt;
|
||||
_connectionState = connectionState;
|
||||
}
|
||||
|
||||
public ConnectionState getConnectionState()
|
||||
{
|
||||
return _connectionState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncryptionInterface getEncryption()
|
||||
{
|
||||
return _encryption;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces the best possible string representation of this client.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
try
|
||||
{
|
||||
final String ip = getIp();
|
||||
final ConnectionState state = getConnectionState();
|
||||
switch (state)
|
||||
{
|
||||
case DISCONNECTED:
|
||||
{
|
||||
if (_accountName != null)
|
||||
{
|
||||
return "[Account: " + _accountName + " - IP: " + (ip == null ? "disconnected" : ip) + "]";
|
||||
}
|
||||
return "[IP: " + (ip == null ? "disconnected" : ip) + "]";
|
||||
}
|
||||
case CONNECTED:
|
||||
{
|
||||
return "[IP: " + (ip == null ? "disconnected" : ip) + "]";
|
||||
}
|
||||
case AUTHENTICATED:
|
||||
{
|
||||
return "[Account: " + _accountName + " - IP: " + (ip == null ? "disconnected" : ip) + "]";
|
||||
}
|
||||
case ENTERING:
|
||||
case IN_GAME:
|
||||
{
|
||||
return "[Character: " + (_player == null ? "disconnected" : _player.getName() + "[" + _player.getObjectId() + "]") + " - Account: " + _accountName + " - IP: " + (ip == null ? "disconnected" : ip) + "]";
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new IllegalStateException("Missing state on switch.");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
return "[Character read failed due to disconnect]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketHandlerInterface;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.commons.threads.ThreadPool;
|
||||
import org.l2jmobius.commons.util.CommonUtil;
|
||||
import org.l2jmobius.gameserver.network.clientpackets.ClientPacket;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class PacketHandler implements PacketHandlerInterface<GameClient>
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(PacketHandler.class.getName());
|
||||
|
||||
@Override
|
||||
public void handle(GameClient client, ReadablePacket packet)
|
||||
{
|
||||
// Read packet id.
|
||||
final int packetId;
|
||||
try
|
||||
{
|
||||
packetId = packet.readByte();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning("PacketHandler: Problem receiving packet id from " + client);
|
||||
LOGGER.warning(CommonUtil.getStackTrace(e));
|
||||
client.disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if packet id is within valid range.
|
||||
if ((packetId < 0) || (packetId >= ClientPackets.PACKET_ARRAY.length))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Find packet enum.
|
||||
final ClientPackets packetEnum = ClientPackets.PACKET_ARRAY[packetId];
|
||||
if (packetEnum == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check connection state.
|
||||
if (!packetEnum.getConnectionStates().contains(client.getConnectionState()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new ClientPacket.
|
||||
final ClientPacket newPacket = packetEnum.newPacket();
|
||||
if (newPacket == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Continue on another thread.
|
||||
if (Config.THREADS_FOR_CLIENT_PACKETS)
|
||||
{
|
||||
ThreadPool.execute(new ExecuteTask(client, packet, newPacket, packetId));
|
||||
}
|
||||
else // Wait for execution.
|
||||
{
|
||||
try
|
||||
{
|
||||
newPacket.read(packet);
|
||||
newPacket.run(client);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning("PacketHandler: Problem with " + client + " [Packet: 0x" + Integer.toHexString(packetId).toUpperCase() + "]");
|
||||
LOGGER.warning(CommonUtil.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ExecuteTask implements Runnable
|
||||
{
|
||||
private final GameClient _client;
|
||||
private final ReadablePacket _packet;
|
||||
private final ClientPacket _newPacket;
|
||||
private final int _packetId;
|
||||
|
||||
public ExecuteTask(GameClient client, ReadablePacket packet, ClientPacket newPacket, int packetId)
|
||||
{
|
||||
_client = client;
|
||||
_packet = packet;
|
||||
_newPacket = newPacket;
|
||||
_packetId = packetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
_newPacket.read(_packet);
|
||||
_newPacket.run(_client);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.warning("PacketHandler->ExecuteTask: Problem with " + _client + " [Packet: 0x" + Integer.toHexString(_packetId).toUpperCase() + "]");
|
||||
LOGGER.warning(CommonUtil.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,14 +17,13 @@
|
||||
package org.l2jmobius.gameserver.network;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketWriter;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ServerPacket;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public enum OutgoingPackets
|
||||
public enum ServerPackets
|
||||
{
|
||||
// Packets
|
||||
KEY_PACKET(0x00),
|
||||
CHAR_MOVE_TO_LOCATION(0x01),
|
||||
CHAR_INFO(0x03),
|
||||
@ -288,28 +287,18 @@ public enum OutgoingPackets
|
||||
private final int _id1;
|
||||
private final int _id2;
|
||||
|
||||
OutgoingPackets(int id1)
|
||||
ServerPackets(int id1)
|
||||
{
|
||||
this(id1, -1);
|
||||
}
|
||||
|
||||
OutgoingPackets(int id1, int id2)
|
||||
ServerPackets(int id1, int id2)
|
||||
{
|
||||
_id1 = id1;
|
||||
_id2 = id2;
|
||||
}
|
||||
|
||||
public int getId1()
|
||||
{
|
||||
return _id1;
|
||||
}
|
||||
|
||||
public int getId2()
|
||||
{
|
||||
return _id2;
|
||||
}
|
||||
|
||||
public void writeId(PacketWriter packet)
|
||||
public void writeId(ServerPacket packet)
|
||||
{
|
||||
if (Config.DEBUG_OUTGOING_PACKETS)
|
||||
{
|
||||
@ -320,22 +309,10 @@ public enum OutgoingPackets
|
||||
}
|
||||
}
|
||||
|
||||
packet.writeC(_id1);
|
||||
packet.writeByte(_id1);
|
||||
if (_id2 > 0)
|
||||
{
|
||||
packet.writeH(_id2);
|
||||
packet.writeShort(_id2);
|
||||
}
|
||||
}
|
||||
|
||||
public static OutgoingPackets getPacket(int id1, int id2)
|
||||
{
|
||||
for (OutgoingPackets packet : values())
|
||||
{
|
||||
if ((packet.getId1() == id1) && (packet.getId2() == id2))
|
||||
{
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
@ -26,7 +26,7 @@ import org.l2jmobius.gameserver.network.PacketLogger;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
|
||||
public class Action implements IClientIncomingPacket
|
||||
public class Action implements ClientPacket
|
||||
{
|
||||
private int _objectId;
|
||||
@SuppressWarnings("unused")
|
||||
@ -38,14 +38,13 @@ public class Action implements IClientIncomingPacket
|
||||
private int _actionId;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_objectId = packet.readD(); // Target object Identifier
|
||||
_originX = packet.readD();
|
||||
_originY = packet.readD();
|
||||
_originZ = packet.readD();
|
||||
_actionId = packet.readC(); // Action identifier : 0-Simple click, 1-Shift click
|
||||
return true;
|
||||
_objectId = packet.readInt(); // Target object Identifier
|
||||
_originX = packet.readInt();
|
||||
_originY = packet.readInt();
|
||||
_originZ = packet.readInt();
|
||||
_actionId = packet.readByte(); // Action identifier : 0-Simple click, 1-Shift click
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.TradeList;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
@ -28,19 +28,18 @@ import org.l2jmobius.gameserver.network.serverpackets.TradeOtherAdd;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.TradeOwnAdd;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.TradeUpdate;
|
||||
|
||||
public class AddTradeItem implements IClientIncomingPacket
|
||||
public class AddTradeItem implements ClientPacket
|
||||
{
|
||||
private int _tradeId;
|
||||
private int _objectId;
|
||||
private int _count;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_tradeId = packet.readD();
|
||||
_objectId = packet.readD();
|
||||
_count = packet.readD();
|
||||
return true;
|
||||
_tradeId = packet.readInt();
|
||||
_objectId = packet.readInt();
|
||||
_count = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,22 +17,21 @@
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.data.sql.ClanTable;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.clan.Clan;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
|
||||
public class AllyDismiss implements IClientIncomingPacket
|
||||
public class AllyDismiss implements ClientPacket
|
||||
{
|
||||
private String _clanName;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_clanName = packet.readS();
|
||||
return true;
|
||||
_clanName = packet.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,20 +17,13 @@
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.clan.Clan;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
|
||||
public class AllyLeave implements IClientIncomingPacket
|
||||
public class AllyLeave implements ClientPacket
|
||||
{
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GameClient client)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.partymatching.PartyMatchRoom;
|
||||
@ -29,15 +29,14 @@ import org.l2jmobius.gameserver.network.serverpackets.ExPartyRoomMember;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PartyMatchDetail;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
public class AnswerJoinPartyRoom implements IClientIncomingPacket
|
||||
public class AnswerJoinPartyRoom implements ClientPacket
|
||||
{
|
||||
private int _answer; // 1 or 0
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_answer = packet.readD();
|
||||
return true;
|
||||
_answer = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
@ -25,15 +25,14 @@ import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SendTradeDone;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||
|
||||
public class AnswerTradeRequest implements IClientIncomingPacket
|
||||
public class AnswerTradeRequest implements ClientPacket
|
||||
{
|
||||
private int _response;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_response = packet.readD();
|
||||
return true;
|
||||
_response = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
@ -25,14 +24,8 @@ import org.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
/**
|
||||
* Appearing Packet Handler
|
||||
*/
|
||||
public class Appearing implements IClientIncomingPacket
|
||||
public class Appearing implements ClientPacket
|
||||
{
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GameClient client)
|
||||
{
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
@ -24,7 +24,7 @@ import org.l2jmobius.gameserver.model.actor.instance.Servitor;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
|
||||
public class AttackRequest implements IClientIncomingPacket
|
||||
public class AttackRequest implements ClientPacket
|
||||
{
|
||||
private int _objectId;
|
||||
@SuppressWarnings("unused")
|
||||
@ -37,14 +37,13 @@ public class AttackRequest implements IClientIncomingPacket
|
||||
private int _attackId;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_objectId = packet.readD();
|
||||
_originX = packet.readD();
|
||||
_originY = packet.readD();
|
||||
_originZ = packet.readD();
|
||||
_attackId = packet.readC(); // 0 for simple click 1 for shift-click
|
||||
return true;
|
||||
_objectId = packet.readInt();
|
||||
_originX = packet.readInt();
|
||||
_originY = packet.readInt();
|
||||
_originZ = packet.readInt();
|
||||
_attackId = packet.readByte(); // 0 for simple click 1 for shift-click
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,12 +16,12 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.LoginServerThread;
|
||||
import org.l2jmobius.gameserver.LoginServerThread.SessionKey;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
public class AuthLogin implements IClientIncomingPacket
|
||||
public class AuthLogin implements ClientPacket
|
||||
{
|
||||
// loginName + keys must match what the loginserver used.
|
||||
private String _loginName;
|
||||
@ -31,14 +31,13 @@ public class AuthLogin implements IClientIncomingPacket
|
||||
private int _loginKey2;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_loginName = packet.readS().toLowerCase();
|
||||
_playKey2 = packet.readD();
|
||||
_playKey1 = packet.readD();
|
||||
_loginKey1 = packet.readD();
|
||||
_loginKey2 = packet.readD();
|
||||
return true;
|
||||
_loginName = packet.readString().toLowerCase();
|
||||
_playKey2 = packet.readInt();
|
||||
_playKey1 = packet.readInt();
|
||||
_loginKey1 = packet.readInt();
|
||||
_loginKey2 = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,11 +45,10 @@ public class AuthLogin implements IClientIncomingPacket
|
||||
{
|
||||
final SessionKey key = new SessionKey(_loginKey1, _loginKey2, _playKey1, _playKey2);
|
||||
|
||||
// avoid potential exploits
|
||||
// Avoid potential exploits.
|
||||
if (client.getAccountName() == null)
|
||||
{
|
||||
// Preventing duplicate login in case client login server socket was
|
||||
// disconnected or this packet was not sent yet
|
||||
// Preventing duplicate login in case client login server socket was disconnected or this packet was not sent yet.
|
||||
if (LoginServerThread.getInstance().addGameServerLogin(_loginName, client))
|
||||
{
|
||||
client.setAccountName(_loginName);
|
||||
|
@ -16,13 +16,13 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.ai.CtrlEvent;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
public class CannotMoveAnymore implements IClientIncomingPacket
|
||||
public class CannotMoveAnymore implements ClientPacket
|
||||
{
|
||||
private int _x;
|
||||
private int _y;
|
||||
@ -30,13 +30,12 @@ public class CannotMoveAnymore implements IClientIncomingPacket
|
||||
private int _heading;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_x = packet.readD();
|
||||
_y = packet.readD();
|
||||
_z = packet.readD();
|
||||
_heading = packet.readD();
|
||||
return true;
|
||||
_x = packet.readInt();
|
||||
_y = packet.readInt();
|
||||
_z = packet.readInt();
|
||||
_heading = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
@ -25,7 +25,7 @@ import org.l2jmobius.gameserver.network.serverpackets.StopMoveInVehicle;
|
||||
/**
|
||||
* @author Maktakien
|
||||
*/
|
||||
public class CannotMoveAnymoreInVehicle implements IClientIncomingPacket
|
||||
public class CannotMoveAnymoreInVehicle implements ClientPacket
|
||||
{
|
||||
private int _x;
|
||||
private int _y;
|
||||
@ -34,14 +34,13 @@ public class CannotMoveAnymoreInVehicle implements IClientIncomingPacket
|
||||
private int _boatId;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_boatId = packet.readD();
|
||||
_x = packet.readD();
|
||||
_y = packet.readD();
|
||||
_z = packet.readD();
|
||||
_heading = packet.readD();
|
||||
return true;
|
||||
_boatId = packet.readInt();
|
||||
_x = packet.readInt();
|
||||
_y = packet.readInt();
|
||||
_z = packet.readInt();
|
||||
_heading = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,19 +16,18 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
public class ChangeMoveType2 implements IClientIncomingPacket
|
||||
public class ChangeMoveType2 implements ClientPacket
|
||||
{
|
||||
private boolean _typeRun;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_typeRun = packet.readD() == 1;
|
||||
return true;
|
||||
_typeRun = packet.readInt() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.instancemanager.CastleManager;
|
||||
import org.l2jmobius.gameserver.model.WorldObject;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
@ -25,15 +25,14 @@ import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ChairSit;
|
||||
|
||||
public class ChangeWaitType2 implements IClientIncomingPacket
|
||||
public class ChangeWaitType2 implements ClientPacket
|
||||
{
|
||||
private boolean _typeStand;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_typeStand = packet.readD() == 1;
|
||||
return true;
|
||||
_typeStand = packet.readInt() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.data.ItemTable;
|
||||
import org.l2jmobius.gameserver.data.SkillTable;
|
||||
import org.l2jmobius.gameserver.data.sql.CharNameTable;
|
||||
@ -47,7 +47,7 @@ import org.l2jmobius.gameserver.network.serverpackets.CharCreateOk;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
|
||||
import org.l2jmobius.gameserver.util.Util;
|
||||
|
||||
public class CharacterCreate implements IClientIncomingPacket
|
||||
public class CharacterCreate implements ClientPacket
|
||||
{
|
||||
private String _name;
|
||||
private byte _sex;
|
||||
@ -71,22 +71,21 @@ public class CharacterCreate implements IClientIncomingPacket
|
||||
private int _wit;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_name = packet.readS();
|
||||
_race = packet.readD();
|
||||
_sex = (byte) packet.readD();
|
||||
_classId = packet.readD();
|
||||
_int = packet.readD();
|
||||
_str = packet.readD();
|
||||
_con = packet.readD();
|
||||
_men = packet.readD();
|
||||
_dex = packet.readD();
|
||||
_wit = packet.readD();
|
||||
_hairStyle = (byte) packet.readD();
|
||||
_hairColor = (byte) packet.readD();
|
||||
_face = (byte) packet.readD();
|
||||
return true;
|
||||
_name = packet.readString();
|
||||
_race = packet.readInt();
|
||||
_sex = (byte) packet.readInt();
|
||||
_classId = packet.readInt();
|
||||
_int = packet.readInt();
|
||||
_str = packet.readInt();
|
||||
_con = packet.readInt();
|
||||
_men = packet.readInt();
|
||||
_dex = packet.readInt();
|
||||
_wit = packet.readInt();
|
||||
_hairStyle = (byte) packet.readInt();
|
||||
_hairColor = (byte) packet.readInt();
|
||||
_face = (byte) packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.PacketLogger;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CharDeleteFail;
|
||||
@ -26,15 +26,14 @@ import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
|
||||
/**
|
||||
* @author eX1steam
|
||||
*/
|
||||
public class CharacterDelete implements IClientIncomingPacket
|
||||
public class CharacterDelete implements ClientPacket
|
||||
{
|
||||
private int _charSlot;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_charSlot = packet.readD();
|
||||
return true;
|
||||
_charSlot = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,19 +16,18 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CharSelectInfo;
|
||||
|
||||
public class CharacterRestore implements IClientIncomingPacket
|
||||
public class CharacterRestore implements ClientPacket
|
||||
{
|
||||
private int _charSlot;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_charSlot = packet.readD();
|
||||
return true;
|
||||
_charSlot = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +17,7 @@
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.World;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.ConnectionState;
|
||||
@ -28,7 +28,7 @@ import org.l2jmobius.gameserver.network.serverpackets.CharSelected;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class CharacterSelected implements IClientIncomingPacket
|
||||
public class CharacterSelected implements ClientPacket
|
||||
{
|
||||
private int _charSlot;
|
||||
private int _unk1; // new in C4
|
||||
@ -37,14 +37,13 @@ public class CharacterSelected implements IClientIncomingPacket
|
||||
private int _unk4;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_charSlot = packet.readD();
|
||||
_unk1 = packet.readH();
|
||||
_unk2 = packet.readD();
|
||||
_unk3 = packet.readD();
|
||||
_unk4 = packet.readD();
|
||||
return true;
|
||||
_charSlot = packet.readInt();
|
||||
_unk1 = packet.readShort();
|
||||
_unk2 = packet.readInt();
|
||||
_unk3 = packet.readInt();
|
||||
_unk4 = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,13 +16,19 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.IIncomingPacket;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* Packets received by the game server from clients
|
||||
* @author KenM
|
||||
* @author Mobius
|
||||
*/
|
||||
public interface IClientIncomingPacket extends IIncomingPacket<GameClient>
|
||||
public abstract interface ClientPacket
|
||||
{
|
||||
default void read(ReadablePacket packet)
|
||||
{
|
||||
}
|
||||
|
||||
default void run(GameClient client)
|
||||
{
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
@ -25,19 +25,18 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||
/**
|
||||
* @author Dezmond_snz - Packet Format: cddd
|
||||
*/
|
||||
public class DlgAnswer implements IClientIncomingPacket
|
||||
public class DlgAnswer implements ClientPacket
|
||||
{
|
||||
private int _messageId;
|
||||
private int _answer;
|
||||
private int _requesterId;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_messageId = packet.readD();
|
||||
_answer = packet.readD();
|
||||
_requesterId = packet.readD();
|
||||
return true;
|
||||
_messageId = packet.readInt();
|
||||
_answer = packet.readInt();
|
||||
_requesterId = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,6 @@ import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.communitybbs.Manager.MailBBSManager;
|
||||
import org.l2jmobius.gameserver.data.SkillTable;
|
||||
import org.l2jmobius.gameserver.data.sql.AnnouncementsTable;
|
||||
@ -76,6 +75,7 @@ import org.l2jmobius.gameserver.network.serverpackets.ExStorageMaxCount;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.FriendList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.HennaInfo;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.ItemList;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.LeaveWorld;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.PlaySound;
|
||||
@ -95,17 +95,11 @@ import org.l2jmobius.gameserver.util.Util;
|
||||
/**
|
||||
* Enter World Packet Handler
|
||||
*/
|
||||
public class EnterWorld implements IClientIncomingPacket
|
||||
public class EnterWorld implements ClientPacket
|
||||
{
|
||||
private final SimpleDateFormat fmt = new SimpleDateFormat("H:mm.");
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd MM yyyy");
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GameClient client)
|
||||
{
|
||||
@ -113,7 +107,7 @@ public class EnterWorld implements IClientIncomingPacket
|
||||
if (player == null)
|
||||
{
|
||||
PacketLogger.warning("EnterWorld failed! player is null...");
|
||||
client.closeNow();
|
||||
client.close(LeaveWorld.STATIC_PACKET);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -127,7 +121,7 @@ public class EnterWorld implements IClientIncomingPacket
|
||||
if (!player.isGM() && !player.isDonator() && Config.CHECK_NAME_ON_LOGIN && ((player.getName().length() < 3) || (player.getName().length() > 16) || !Util.isAlphaNumeric(player.getName()) || !isValidName(player.getName())))
|
||||
{
|
||||
PacketLogger.warning("Charname: " + player.getName() + " is invalid. EnterWorld failed.");
|
||||
client.closeNow();
|
||||
client.close(LeaveWorld.STATIC_PACKET);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -16,47 +16,55 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.IIncomingPacket;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.network.ExIncomingPackets;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.network.ExClientPackets;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author Nos
|
||||
*/
|
||||
public class ExPacket implements IClientIncomingPacket
|
||||
public class ExPacket implements ClientPacket
|
||||
{
|
||||
private ExIncomingPackets _exIncomingPacket;
|
||||
private IIncomingPacket<GameClient> _exPacket;
|
||||
private ExClientPackets _packetEnum;
|
||||
private ClientPacket _newPacket;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
final int exPacketId = packet.readH() & 0xFFFF;
|
||||
if ((exPacketId < 0) || (exPacketId >= ExIncomingPackets.PACKET_ARRAY.length))
|
||||
final int exPacketId = packet.readShort() & 0xFFFF;
|
||||
if ((exPacketId < 0) || (exPacketId >= ExClientPackets.PACKET_ARRAY.length))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_exIncomingPacket = ExIncomingPackets.PACKET_ARRAY[exPacketId];
|
||||
if (_exIncomingPacket == null)
|
||||
{
|
||||
// LOGGER.finer(getClass().getSimpleName() + ": Unknown packet: " + Integer.toHexString(exPacketId));
|
||||
return false;
|
||||
}
|
||||
|
||||
_exPacket = _exIncomingPacket.newIncomingPacket();
|
||||
return (_exPacket != null) && _exPacket.read(client, packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GameClient client) throws Exception
|
||||
{
|
||||
if (!_exIncomingPacket.getConnectionStates().contains(client.getConnectionState()))
|
||||
{
|
||||
// LOGGER.finer(_exIncomingPacket + ": Connection at invalid state: " + client.getConnectionState() + " Required State: " + _exIncomingPacket.getConnectionStates());
|
||||
return;
|
||||
}
|
||||
_exPacket.run(client);
|
||||
|
||||
_packetEnum = ExClientPackets.PACKET_ARRAY[exPacketId];
|
||||
if (_packetEnum == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_newPacket = _packetEnum.newPacket();
|
||||
if (_newPacket == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_newPacket.read(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(GameClient client)
|
||||
{
|
||||
if (_newPacket == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_packetEnum.getConnectionStates().contains(client.getConnectionState()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_newPacket.run(client);
|
||||
}
|
||||
}
|
||||
|
@ -17,21 +17,20 @@
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.StopRotation;
|
||||
|
||||
public class FinishRotating implements IClientIncomingPacket
|
||||
public class FinishRotating implements ClientPacket
|
||||
{
|
||||
private int _degree;
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_degree = packet.readD();
|
||||
packet.readD(); // Unknown.
|
||||
return true;
|
||||
_degree = packet.readInt();
|
||||
packet.readInt(); // Unknown.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,24 +16,23 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.commons.network.ReadablePacket;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
|
||||
/**
|
||||
* @author zabbix Lets drink to code! Unknown Packet: ca 0000: 45 00 01 00 1e 37 a2 f5 00 00 00 00 00 00 00 00 E....7..........
|
||||
*/
|
||||
public class GameGuardReply implements IClientIncomingPacket
|
||||
public class GameGuardReply implements ClientPacket
|
||||
{
|
||||
private final int[] _reply = new int[4];
|
||||
|
||||
@Override
|
||||
public boolean read(GameClient client, PacketReader packet)
|
||||
public void read(ReadablePacket packet)
|
||||
{
|
||||
_reply[0] = packet.readD();
|
||||
_reply[1] = packet.readD();
|
||||
_reply[2] = packet.readD();
|
||||
_reply[3] = packet.readD();
|
||||
return true;
|
||||
_reply[0] = packet.readInt();
|
||||
_reply[1] = packet.readInt();
|
||||
_reply[2] = packet.readInt();
|
||||
_reply[3] = packet.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user