|
@@ -28,7 +28,6 @@ import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
|
import com.l2jserver.gameserver.network.SystemMessageId;
|
|
|
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Format : chdb
|
|
|
* c (id) 0xD0
|
|
@@ -42,109 +41,121 @@ public final class RequestExSetPledgeCrestLarge extends L2GameClientPacket
|
|
|
{
|
|
|
private static final String _C__D0_11_REQUESTEXSETPLEDGECRESTLARGE = "[C] D0:11 RequestExSetPledgeCrestLarge";
|
|
|
static Logger _log = Logger.getLogger(RequestExSetPledgeCrestLarge.class.getName());
|
|
|
- private int _size;
|
|
|
+
|
|
|
+ private int _length;
|
|
|
private byte[] _data;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
protected void readImpl()
|
|
|
{
|
|
|
- _size = readD();
|
|
|
- if(_size > 2176)
|
|
|
+ _length = readD();
|
|
|
+ if (_length > 2176)
|
|
|
return;
|
|
|
- if(_size > 0) // client CAN send a RequestExSetPledgeCrestLarge with the size set to 0 then format is just chd
|
|
|
- {
|
|
|
- _data = new byte[_size];
|
|
|
- readB(_data);
|
|
|
- }
|
|
|
+
|
|
|
+ _data = new byte[_length];
|
|
|
+ readB(_data);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/* (non-Javadoc)
|
|
|
* @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#runImpl()
|
|
|
*/
|
|
|
@Override
|
|
|
- protected
|
|
|
- void runImpl()
|
|
|
+ protected void runImpl()
|
|
|
{
|
|
|
L2PcInstance activeChar = getClient().getActiveChar();
|
|
|
- if (activeChar == null) return;
|
|
|
-
|
|
|
+ if (activeChar == null)
|
|
|
+ return;
|
|
|
+
|
|
|
L2Clan clan = activeChar.getClan();
|
|
|
- if (clan == null) return;
|
|
|
-
|
|
|
- if (_data == null)
|
|
|
+ if (clan == null)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (_length < 0)
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("File transfer error.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (_length > 2176)
|
|
|
+ {
|
|
|
+ activeChar.sendMessage("The insignia file size is greater than 2176 bytes.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean updated = false;
|
|
|
+ int crestLargeId = -1;
|
|
|
+ if (_length == 0 || _data == null)
|
|
|
{
|
|
|
CrestCache.getInstance().removePledgeCrestLarge(clan.getCrestLargeId());
|
|
|
- clan.setCrestLargeId(0);
|
|
|
- clan.setHasCrestLarge(false);
|
|
|
-
|
|
|
- activeChar.sendMessage("The insignia has been removed.");
|
|
|
-
|
|
|
- for (L2PcInstance member : clan.getOnlineMembers(0))
|
|
|
- member.broadcastUserInfo();
|
|
|
-
|
|
|
- return;
|
|
|
+ clan.setCrestLargeId(crestLargeId = 0);
|
|
|
+ clan.setHasCrestLarge(false);
|
|
|
+
|
|
|
+ activeChar.sendMessage("The insignia has been removed.");
|
|
|
+
|
|
|
+ updated = true;
|
|
|
}
|
|
|
-
|
|
|
- if (_size > 2176)
|
|
|
- {
|
|
|
- activeChar.sendMessage("The insignia file size is greater than 2176 bytes.");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_REGISTER_CREST) == L2Clan.CP_CL_REGISTER_CREST)
|
|
|
{
|
|
|
- if(clan.getHasCastle() == 0 && clan.getHasHideout() == 0)
|
|
|
+ if (clan.getHasCastle() == 0 && clan.getHasHideout() == 0)
|
|
|
{
|
|
|
activeChar.sendMessage("Only a clan that owns a clan hall or a castle can get their emblem displayed on clan related items"); //there is a system message for that but didnt found the id
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
CrestCache crestCache = CrestCache.getInstance();
|
|
|
-
|
|
|
+
|
|
|
int newId = IdFactory.getInstance().getNextId();
|
|
|
-
|
|
|
- if (clan.hasCrestLarge())
|
|
|
- {
|
|
|
- crestCache.removePledgeCrestLarge(clan.getCrestLargeId());
|
|
|
- }
|
|
|
-
|
|
|
- if (!crestCache.savePledgeCrestLarge(newId,_data))
|
|
|
- {
|
|
|
- _log.log(Level.INFO, "Error loading large crest of clan:" + clan.getName());
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- Connection con = null;
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
- PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?");
|
|
|
- statement.setInt(1, newId);
|
|
|
- statement.setInt(2, clan.getClanId());
|
|
|
- statement.executeUpdate();
|
|
|
- statement.close();
|
|
|
- }
|
|
|
- catch (SQLException e)
|
|
|
- {
|
|
|
- _log.warning("could not update the large crest id:"+e.getMessage());
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- try { con.close(); } catch (Exception e) {}
|
|
|
- }
|
|
|
-
|
|
|
- clan.setCrestLargeId(newId);
|
|
|
- clan.setHasCrestLarge(true);
|
|
|
-
|
|
|
- activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_EMBLEM_WAS_SUCCESSFULLY_REGISTERED));
|
|
|
-
|
|
|
- for (L2PcInstance member : clan.getOnlineMembers(0))
|
|
|
- member.broadcastUserInfo();
|
|
|
-
|
|
|
+
|
|
|
+ if (clan.hasCrestLarge())
|
|
|
+ crestCache.removePledgeCrestLarge(clan.getCrestLargeId());
|
|
|
+
|
|
|
+ if (!crestCache.savePledgeCrestLarge(newId, _data))
|
|
|
+ {
|
|
|
+ _log.log(Level.INFO, "Error saving large crest for clan " + clan.getName() + " [" + clan.getClanId() + "]");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ clan.setCrestLargeId(newId);
|
|
|
+ clan.setHasCrestLarge(true);
|
|
|
+
|
|
|
+ activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_EMBLEM_WAS_SUCCESSFULLY_REGISTERED));
|
|
|
+
|
|
|
+ updated = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (updated && crestLargeId != -1)
|
|
|
+ {
|
|
|
+ Connection con = null;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ con = L2DatabaseFactory.getInstance().getConnection();
|
|
|
+ PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?");
|
|
|
+ statement.setInt(1, crestLargeId);
|
|
|
+ statement.setInt(2, clan.getClanId());
|
|
|
+ statement.executeUpdate();
|
|
|
+ statement.close();
|
|
|
+ }
|
|
|
+ catch (SQLException e)
|
|
|
+ {
|
|
|
+ _log.warning("Could not update large crest for clan " + clan.getName() + " [" + clan.getClanId() + "] : " + e.getMessage());
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ con.close();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (L2PcInstance member : clan.getOnlineMembers(0))
|
|
|
+ member.broadcastUserInfo();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/* (non-Javadoc)
|
|
|
* @see com.l2jserver.gameserver.BasePacket#getType()
|
|
|
*/
|
|
@@ -153,5 +164,5 @@ public final class RequestExSetPledgeCrestLarge extends L2GameClientPacket
|
|
|
{
|
|
|
return _C__D0_11_REQUESTEXSETPLEDGECRESTLARGE;
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
+
|
|
|
+}
|