/
tofu
/
l2interlude
Обзор
Документация
Войти
/
tofu
/
l2interlude
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/main/java/com/l2jserver/gameserver/network/clientpackets/L2GameClientPacket.java
133 строки
4 KB
Zoey76
Copyright Update
01 янв 2025, 07:57
01 янв 2025, 07:57
16130a5
Код
Авторство
О чём код?
/* * Copyright © 2004-2025 L2J Server * * This file is part of L2J Server. * * L2J Server 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. * * L2J Server 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 com.l2jserver.gameserver.network.clientpackets; import static com.l2jserver.gameserver.config.Configuration.character; import static com.l2jserver.gameserver.config.Configuration.general; import java.nio.BufferUnderflowException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.network.L2GameClient; import com.l2jserver.gameserver.network.SystemMessageId; import com.l2jserver.gameserver.network.serverpackets.ActionFailed; import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket; import com.l2jserver.gameserver.network.serverpackets.SystemMessage; import com.l2jserver.mmocore.ReceivablePacket; /** * Packets received by the game server from clients * @author KenM */ public abstract class L2GameClientPacket extends ReceivablePacket<L2GameClient> { private static final Logger LOG = LoggerFactory.getLogger(L2GameClientPacket.class); static final int MAX_ITEM_IN_PACKET = Math.max(character().getMaximumSlotsForNoDwarf(), // Math.max(character().getMaximumSlotsForDwarf(), // character().getMaximumSlotsForGMPlayer())); @Override public boolean read() { try { readImpl(); return true; } catch (Exception e) { LOG.error("Client: {} - Failed reading: {} ; {}", getClient().toString(), getType(), e.getMessage(), e); if (e instanceof BufferUnderflowException) { getClient().onBufferUnderflow(); } } return false; } protected abstract void readImpl(); @Override public void run() { try { runImpl(); /* * Removes onspawn protection - player has faster computer than average Since GE: True for all packets except RequestItemList and UseItem (in case the item is a Scroll of Escape (736) */ if (triggersOnActionRequest()) { final L2PcInstance actor = getClient().getActiveChar(); if ((actor != null) && (actor.isSpawnProtected() || actor.isInvul())) { actor.onActionRequest(); if (general().debug()) { LOG.info("Spawn protection for player {} removed by packet: {}", actor.getName(), getType()); } } } } catch (Throwable t) { LOG.error("Client: {} - Failed running: {} ; {}", getClient().toString(), getType(), t.getMessage(), t); // in case of EnterWorld error kick player from game if (this instanceof EnterWorld) { getClient().closeNow(); } } } protected abstract void runImpl(); /** * Sends a game server packet to the client. * @param gsp the game server packet */ protected final void sendPacket(L2GameServerPacket gsp) { getClient().sendPacket(gsp); } /** * Sends a system message to the client. * @param id the system message id */ public void sendPacket(SystemMessageId id) { sendPacket(SystemMessage.getSystemMessage(id)); } /** * @return A String with this packet name for debugging purposes */ public abstract String getType(); /** * Overridden with true value on some packets that should disable spawn protection (RequestItemList and UseItem only) */ protected boolean triggersOnActionRequest() { return true; } /** * @return the active player if it exists, otherwise null. */ protected final L2PcInstance getActiveChar() { return getClient().getActiveChar(); } protected final void sendActionFailed() { if (getClient() != null) { getClient().sendPacket(ActionFailed.STATIC_PACKET); } } }