From 22db860d42432ffb1ce0a35675419a732c372fb6 Mon Sep 17 00:00:00 2001
From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com>
Date: Sat, 29 May 2021 01:04:55 +0000
Subject: [PATCH] Moved crest data to SQL.
---
.../dist/db_installer/sql/game/crests.sql | 6 +
.../dist/game/config/AdminCommands.xml | 5 +-
.../dist/game/data/html/admin/server_menu.htm | 4 +-
.../org/l2jmobius/gameserver/GameServer.java | 6 +-
.../gameserver/cache/CrestCache.java | 380 ------------------
.../gameserver/data/sql/CrestTable.java | 219 ++++++++++
.../admincommandhandlers/AdminCache.java | 14 +-
.../org/l2jmobius/gameserver/model/Crest.java | 120 ++++++
.../model/actor/instance/PlayerInstance.java | 4 +-
.../l2jmobius/gameserver/model/clan/Clan.java | 186 ++++++---
.../model/interfaces/IIdentifiable.java | 26 ++
.../gameserver/network/OutgoingPackets.java | 4 +-
.../network/clientpackets/AllyDismiss.java | 2 +-
.../network/clientpackets/AllyLeave.java | 2 +-
.../clientpackets/RequestAnswerJoinAlly.java | 6 +-
.../RequestExPledgeCrestLarge.java | 9 +-
.../RequestExSetPledgeCrestLarge.java | 104 ++---
.../clientpackets/RequestSetAllyCrest.java | 84 ++--
.../clientpackets/RequestSetPledgeCrest.java | 107 ++---
.../network/serverpackets/AllyCrest.java | 25 +-
...dgeCrestLarge.java => ExPledgeEmblem.java} | 31 +-
.../network/serverpackets/PledgeCrest.java | 17 +-
.../dist/db_installer/sql/game/crests.sql | 6 +
.../dist/game/config/AdminCommands.xml | 5 +-
.../dist/game/data/html/admin/server_menu.htm | 4 +-
.../org/l2jmobius/gameserver/GameServer.java | 6 +-
.../gameserver/cache/CrestCache.java | 380 ------------------
.../gameserver/data/sql/CrestTable.java | 219 ++++++++++
.../admincommandhandlers/AdminCache.java | 14 +-
.../org/l2jmobius/gameserver/model/Crest.java | 120 ++++++
.../model/actor/instance/PlayerInstance.java | 4 +-
.../l2jmobius/gameserver/model/clan/Clan.java | 186 ++++++---
.../model/interfaces/IIdentifiable.java | 26 ++
.../gameserver/network/OutgoingPackets.java | 4 +-
.../network/clientpackets/AllyDismiss.java | 2 +-
.../network/clientpackets/AllyLeave.java | 2 +-
.../clientpackets/RequestAnswerJoinAlly.java | 6 +-
.../RequestExPledgeCrestLarge.java | 9 +-
.../RequestExSetPledgeCrestLarge.java | 104 ++---
.../clientpackets/RequestSetAllyCrest.java | 84 ++--
.../clientpackets/RequestSetPledgeCrest.java | 107 ++---
.../network/serverpackets/AllyCrest.java | 25 +-
...dgeCrestLarge.java => ExPledgeEmblem.java} | 31 +-
.../network/serverpackets/PledgeCrest.java | 17 +-
44 files changed, 1322 insertions(+), 1400 deletions(-)
create mode 100644 L2J_Mobius_C4_ScionsOfDestiny/dist/db_installer/sql/game/crests.sql
delete mode 100644 L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/cache/CrestCache.java
create mode 100644 L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/data/sql/CrestTable.java
create mode 100644 L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/Crest.java
create mode 100644 L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java
rename L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/{ExPledgeCrestLarge.java => ExPledgeEmblem.java} (63%)
create mode 100644 L2J_Mobius_C6_Interlude/dist/db_installer/sql/game/crests.sql
delete mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/cache/CrestCache.java
create mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/data/sql/CrestTable.java
create mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/Crest.java
create mode 100644 L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java
rename L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/{ExPledgeCrestLarge.java => ExPledgeEmblem.java} (63%)
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/dist/db_installer/sql/game/crests.sql b/L2J_Mobius_C4_ScionsOfDestiny/dist/db_installer/sql/game/crests.sql
new file mode 100644
index 0000000000..b3e6dd8b67
--- /dev/null
+++ b/L2J_Mobius_C4_ScionsOfDestiny/dist/db_installer/sql/game/crests.sql
@@ -0,0 +1,6 @@
+CREATE TABLE IF NOT EXISTS `crests` (
+ `crest_id` INT,
+ `data` VARBINARY(2176) NOT NULL,
+ `type` TINYINT NOT NULL,
+ PRIMARY KEY(`crest_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
\ No newline at end of file
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/dist/game/config/AdminCommands.xml b/L2J_Mobius_C4_ScionsOfDestiny/dist/game/config/AdminCommands.xml
index e4a85384aa..ab28ff9240 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/dist/game/config/AdminCommands.xml
+++ b/L2J_Mobius_C4_ScionsOfDestiny/dist/game/config/AdminCommands.xml
@@ -51,9 +51,8 @@
-
-
-
+
+
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/dist/game/data/html/admin/server_menu.htm b/L2J_Mobius_C4_ScionsOfDestiny/dist/game/data/html/admin/server_menu.htm
index 93eb0ac74a..48c285aeb2 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/dist/game/data/html/admin/server_menu.htm
+++ b/L2J_Mobius_C4_ScionsOfDestiny/dist/game/data/html/admin/server_menu.htm
@@ -19,12 +19,12 @@
|
|
|
- |
-
|
+
|
|
|
+ |
Geodata
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameServer.java
index 9290d72372..9d27e12fd0 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameServer.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/GameServer.java
@@ -33,7 +33,6 @@ import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.commons.util.PropertiesParser;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
import org.l2jmobius.gameserver.data.ItemTable;
@@ -42,6 +41,7 @@ import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.data.sql.AnnouncementsTable;
import org.l2jmobius.gameserver.data.sql.CharNameTable;
import org.l2jmobius.gameserver.data.sql.ClanTable;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
import org.l2jmobius.gameserver.data.sql.HelperBuffTable;
import org.l2jmobius.gameserver.data.sql.NpcTable;
import org.l2jmobius.gameserver.data.sql.OfflineTraderTable;
@@ -181,12 +181,10 @@ public class GameServer
throw new Exception("Could not initialize the ID factory!");
}
- new File(Config.DATAPACK_ROOT, "data/clans").mkdirs();
- new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
new File(Config.DATAPACK_ROOT, "data/geodata").mkdirs();
HtmCache.getInstance();
- CrestCache.getInstance();
+ CrestTable.getInstance();
ScriptEngineManager.getInstance();
printSection("World");
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/cache/CrestCache.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/cache/CrestCache.java
deleted file mode 100644
index 8c086a3458..0000000000
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/cache/CrestCache.java
+++ /dev/null
@@ -1,380 +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 .
- */
-package org.l2jmobius.gameserver.cache;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import org.l2jmobius.Config;
-import org.l2jmobius.commons.database.DatabaseFactory;
-import org.l2jmobius.gameserver.data.sql.ClanTable;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
-import org.l2jmobius.gameserver.model.clan.Clan;
-
-/**
- * @author Layane
- */
-public class CrestCache
-{
- private static final Logger LOGGER = Logger.getLogger(CrestCache.class.getName());
-
- private final Map _cachePledge = new HashMap<>();
- private final Map _cachePledgeLarge = new HashMap<>();
- private final Map _cacheAlly = new HashMap<>();
- private int _loadedFiles;
- private long _bytesBuffLen;
-
- protected CrestCache()
- {
- convertOldPedgeFiles();
- reload();
- }
-
- public void reload()
- {
- final FileFilter filter = new BmpFilter();
- final File dir = new File(Config.DATAPACK_ROOT, "data/crests/");
- final File[] files = dir.listFiles(filter);
- byte[] content;
- synchronized (this)
- {
- _loadedFiles = 0;
- _bytesBuffLen = 0;
- _cachePledge.clear();
- _cachePledgeLarge.clear();
- _cacheAlly.clear();
- }
-
- for (File file : files)
- {
- RandomAccessFile f = null;
- synchronized (this)
- {
- try
- {
- f = new RandomAccessFile(file, "r");
- content = new byte[(int) f.length()];
- f.readFully(content);
-
- if (file.getName().startsWith("Crest_Large_"))
- {
- _cachePledgeLarge.put(Integer.parseInt(file.getName().substring(12, file.getName().length() - 4)), content);
- }
- else if (file.getName().startsWith("Crest_"))
- {
- _cachePledge.put(Integer.parseInt(file.getName().substring(6, file.getName().length() - 4)), content);
- }
- else if (file.getName().startsWith("AllyCrest_"))
- {
- _cacheAlly.put(Integer.parseInt(file.getName().substring(10, file.getName().length() - 4)), content);
- }
-
- _loadedFiles++;
- _bytesBuffLen += content.length;
- }
- catch (Exception e)
- {
- LOGGER.warning("problem with crest bmp file " + e);
- }
- finally
- {
- if (f != null)
- {
- try
- {
- f.close();
- }
- catch (Exception e1)
- {
- LOGGER.warning("Problem with CrestCache: " + e1.getMessage());
- }
- }
- }
- }
- }
-
- LOGGER.info("Cache[Crest]: " + String.format("%.3f", getMemoryUsage()) + "MB on " + _loadedFiles + " files loaded.");
- }
-
- public void convertOldPedgeFiles()
- {
- final File dir = new File(Config.DATAPACK_ROOT, "data/crests/");
- final File[] files = dir.listFiles(new OldPledgeFilter());
- if (files == null)
- {
- LOGGER.info("No old crest files found in \"data/crests/\"!!! May be you deleted them?");
- return;
- }
-
- for (File file : files)
- {
- final int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4));
-
- LOGGER.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId);
-
- final int newId = IdManager.getInstance().getNextId();
- final Clan clan = ClanTable.getInstance().getClan(clanId);
- if (clan != null)
- {
- removeOldPledgeCrest(clan.getCrestId());
-
- file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp"));
- LOGGER.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp");
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, newId);
- statement.setInt(2, clan.getClanId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("could not update the crest id:" + e.getMessage());
- }
-
- clan.setCrestId(newId);
- clan.setHasCrest(true);
- }
- else
- {
- LOGGER.info("Clan Id: " + clanId + " does not exist in table.. deleting.");
- file.delete();
- }
- }
- }
-
- public float getMemoryUsage()
- {
- return (float) _bytesBuffLen / 1048576;
- }
-
- public int getLoadedFiles()
- {
- return _loadedFiles;
- }
-
- public byte[] getPledgeCrest(int id)
- {
- return _cachePledge.get(id);
- }
-
- public byte[] getPledgeCrestLarge(int id)
- {
- return _cachePledgeLarge.get(id);
- }
-
- public byte[] getAllyCrest(int id)
- {
- return _cacheAlly.get(id);
- }
-
- public void removePledgeCrest(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + id + ".bmp");
- _cachePledge.remove(id);
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public void removePledgeCrestLarge(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_Large_" + id + ".bmp");
- _cachePledgeLarge.remove(id);
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public void removeOldPledgeCrest(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Pledge_" + id + ".bmp");
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public void removeAllyCrest(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/AllyCrest_" + id + ".bmp");
- _cacheAlly.remove(id);
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public boolean savePledgeCrest(int newId, byte[] data)
- {
- boolean output = false;
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp");
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(crestFile);
- out.write(data);
- _cachePledge.put(newId, data);
-
- output = true;
- }
- catch (IOException e)
- {
- LOGGER.warning("Error saving pledge crest" + crestFile + " " + e);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- LOGGER.warning("Problem with CrestCache: " + e.getMessage());
- }
- }
- }
- return output;
- }
-
- public boolean savePledgeCrestLarge(int newId, byte[] data)
- {
- boolean output = false;
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_Large_" + newId + ".bmp");
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(crestFile);
- out.write(data);
- _cachePledgeLarge.put(newId, data);
-
- output = true;
- }
- catch (IOException e)
- {
- LOGGER.warning("Error saving Large pledge crest" + crestFile + " " + e);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- LOGGER.warning("Problem with CrestCache: " + e.getMessage());
- }
- }
- }
- return output;
- }
-
- public boolean saveAllyCrest(int newId, byte[] data)
- {
- boolean output = false;
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/AllyCrest_" + newId + ".bmp");
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(crestFile);
- out.write(data);
- _cacheAlly.put(newId, data);
-
- output = true;
- }
- catch (IOException e)
- {
- LOGGER.warning("Error saving ally crest" + crestFile + " " + e);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- LOGGER.warning("Problem with CrestCache: " + e.getMessage());
- }
- }
- }
- return output;
- }
-
- class BmpFilter implements FileFilter
- {
- @Override
- public boolean accept(File file)
- {
- return file.getName().endsWith(".bmp");
- }
- }
-
- class OldPledgeFilter implements FileFilter
- {
- @Override
- public boolean accept(File file)
- {
- return file.getName().startsWith("Pledge_");
- }
- }
-
- public static CrestCache getInstance()
- {
- return SingletonHolder.INSTANCE;
- }
-
- private static class SingletonHolder
- {
- protected static final CrestCache INSTANCE = new CrestCache();
- }
-}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/data/sql/CrestTable.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/data/sql/CrestTable.java
new file mode 100644
index 0000000000..6a27eae0c3
--- /dev/null
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/data/sql/CrestTable.java
@@ -0,0 +1,219 @@
+/*
+ * 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 .
+ */
+package org.l2jmobius.gameserver.data.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.l2jmobius.commons.database.DatabaseFactory;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
+import org.l2jmobius.gameserver.model.clan.Clan;
+
+/**
+ * Loads and saves crests from database.
+ * @author NosBit
+ */
+public class CrestTable
+{
+ private static final Logger LOGGER = Logger.getLogger(CrestTable.class.getName());
+
+ private final Map _crests = new ConcurrentHashMap<>();
+ private final AtomicInteger _nextId = new AtomicInteger(1);
+
+ protected CrestTable()
+ {
+ load();
+ }
+
+ public synchronized void load()
+ {
+ _crests.clear();
+ final Set crestsInUse = new HashSet<>();
+ for (Clan clan : ClanTable.getInstance().getClans())
+ {
+ if (clan.getCrestId() != 0)
+ {
+ crestsInUse.add(clan.getCrestId());
+ }
+
+ if (clan.getCrestLargeId() != 0)
+ {
+ crestsInUse.add(clan.getCrestLargeId());
+ }
+
+ if (clan.getAllyCrestId() != 0)
+ {
+ crestsInUse.add(clan.getAllyCrestId());
+ }
+ }
+
+ try (Connection con = DatabaseFactory.getConnection();
+ Statement statement = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs = statement.executeQuery("SELECT `crest_id`, `data`, `type` FROM `crests` ORDER BY `crest_id` DESC"))
+ {
+ while (rs.next())
+ {
+ final int id = rs.getInt("crest_id");
+
+ if (_nextId.get() <= id)
+ {
+ _nextId.set(id + 1);
+ }
+
+ // delete all unused crests except the last one we dont want to reuse
+ // a crest id because client will display wrong crest if its reused
+ if (!crestsInUse.contains(id) && (id != (_nextId.get() - 1)))
+ {
+ rs.deleteRow();
+ continue;
+ }
+
+ final byte[] data = rs.getBytes("data");
+ final CrestType crestType = CrestType.getById(rs.getInt("type"));
+ if (crestType != null)
+ {
+ _crests.put(id, new Crest(id, data, crestType));
+ }
+ else
+ {
+ LOGGER.warning("Unknown crest type found in database. Type:" + rs.getInt("type"));
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ LOGGER.log(Level.WARNING, "There was an error while loading crests from database:", e);
+ }
+
+ LOGGER.info(getClass().getSimpleName() + ": Loaded " + _crests.size() + " Crests.");
+
+ for (Clan clan : ClanTable.getInstance().getClans())
+ {
+ if ((clan.getCrestId() != 0) && (getCrest(clan.getCrestId()) == null))
+ {
+ LOGGER.info("Removing non-existent crest for clan " + clan.getName() + " [" + clan.getClanId() + "], crestId:" + clan.getCrestId());
+ clan.setCrestId(0);
+ clan.changeClanCrest(0);
+ }
+
+ if ((clan.getCrestLargeId() != 0) && (getCrest(clan.getCrestLargeId()) == null))
+ {
+ LOGGER.info("Removing non-existent large crest for clan " + clan.getName() + " [" + clan.getClanId() + "], crestLargeId:" + clan.getCrestLargeId());
+ clan.setCrestLargeId(0);
+ clan.changeLargeCrest(0);
+ }
+
+ if ((clan.getAllyCrestId() != 0) && (getCrest(clan.getAllyCrestId()) == null))
+ {
+ LOGGER.info("Removing non-existent ally crest for clan " + clan.getName() + " [" + clan.getClanId() + "], allyCrestId:" + clan.getAllyCrestId());
+ clan.setAllyCrestId(0);
+ clan.changeAllyCrest(0, true);
+ }
+ }
+ }
+
+ /**
+ * @param crestId The crest id
+ * @return {@code Crest} if crest is found, {@code null} if crest was not found.
+ */
+ public Crest getCrest(int crestId)
+ {
+ return _crests.get(crestId);
+ }
+
+ /**
+ * Creates a {@code Crest} object and inserts it in database and cache.
+ * @param data
+ * @param crestType
+ * @return {@code Crest} on success, {@code null} on failure.
+ */
+ public Crest createCrest(byte[] data, CrestType crestType)
+ {
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement statement = con.prepareStatement("INSERT INTO `crests`(`crest_id`, `data`, `type`) VALUES(?, ?, ?)"))
+ {
+ final Crest crest = new Crest(_nextId.getAndIncrement(), data, crestType);
+ statement.setInt(1, crest.getId());
+ statement.setBytes(2, crest.getData());
+ statement.setInt(3, crest.getType().getId());
+ statement.executeUpdate();
+ _crests.put(crest.getId(), crest);
+ return crest;
+ }
+ catch (SQLException e)
+ {
+ LOGGER.log(Level.WARNING, "There was an error while saving crest in database:", e);
+ }
+ return null;
+ }
+
+ /**
+ * Removes crest from database and cache.
+ * @param crestId the id of crest to be removed.
+ */
+ public void removeCrest(int crestId)
+ {
+ _crests.remove(crestId);
+
+ // avoid removing last crest id we dont want to lose index...
+ // because client will display wrong crest if its reused
+ if (crestId == (_nextId.get() - 1))
+ {
+ return;
+ }
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement statement = con.prepareStatement("DELETE FROM `crests` WHERE `crest_id` = ?"))
+ {
+ statement.setInt(1, crestId);
+ statement.executeUpdate();
+ }
+ catch (SQLException e)
+ {
+ LOGGER.log(Level.WARNING, "There was an error while deleting crest from database:", e);
+ }
+ }
+
+ /**
+ * @return The next crest id.
+ */
+ public int getNextId()
+ {
+ return _nextId.getAndIncrement();
+ }
+
+ public static CrestTable getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final CrestTable INSTANCE = new CrestTable();
+ }
+}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java
index ba4d7ba52a..a925d4c286 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java
@@ -20,8 +20,8 @@ import java.io.File;
import java.util.StringTokenizer;
import org.l2jmobius.Config;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.cache.HtmCache;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.util.BuilderUtil;
@@ -38,8 +38,7 @@ public class AdminCache implements IAdminCommandHandler
"admin_cache_reload_path",
"admin_cache_reload_file",
"admin_cache_crest_rebuild",
- "admin_cache_crest_reload",
- "admin_cache_crest_fix"
+ "admin_cache_crest_reload"
};
@Override
@@ -94,14 +93,7 @@ public class AdminCache implements IAdminCommandHandler
case "admin_cache_crest_rebuild":
case "admin_cache_crest_reload":
{
- CrestCache.getInstance().reload();
- BuilderUtil.sendSysMessage(activeChar, "Cache[Crest]: " + String.format("%.3f", CrestCache.getInstance().getMemoryUsage()) + " megabytes on " + CrestCache.getInstance().getLoadedFiles() + " files loaded");
- return true;
- }
- case "admin_cache_crest_fix":
- {
- CrestCache.getInstance().convertOldPedgeFiles();
- BuilderUtil.sendSysMessage(activeChar, "Cache[Crest]: crests fixed");
+ CrestTable.getInstance().load();
return true;
}
default:
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/Crest.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/Crest.java
new file mode 100644
index 0000000000..5389e63214
--- /dev/null
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/Crest.java
@@ -0,0 +1,120 @@
+/*
+ * 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 .
+ */
+package org.l2jmobius.gameserver.model;
+
+import org.l2jmobius.Config;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
+import org.l2jmobius.gameserver.network.serverpackets.AllyCrest;
+import org.l2jmobius.gameserver.network.serverpackets.ExPledgeEmblem;
+import org.l2jmobius.gameserver.network.serverpackets.PledgeCrest;
+
+/**
+ * @author NosBit
+ */
+public class Crest implements IIdentifiable
+{
+ public enum CrestType
+ {
+ PLEDGE(1),
+ PLEDGE_LARGE(2),
+ ALLY(3);
+
+ private final int _id;
+
+ CrestType(int id)
+ {
+ _id = id;
+ }
+
+ public int getId()
+ {
+ return _id;
+ }
+
+ public static CrestType getById(int id)
+ {
+ for (CrestType crestType : values())
+ {
+ if (crestType.getId() == id)
+ {
+ return crestType;
+ }
+ }
+ return null;
+ }
+ }
+
+ private final int _id;
+ private final byte[] _data;
+ private final CrestType _type;
+
+ public Crest(int id, byte[] data, CrestType type)
+ {
+ _id = id;
+ _data = data;
+ _type = type;
+ }
+
+ @Override
+ public int getId()
+ {
+ return _id;
+ }
+
+ public byte[] getData()
+ {
+ return _data;
+ }
+
+ public CrestType getType()
+ {
+ return _type;
+ }
+
+ /**
+ * Gets the client path to crest for use in html and sends the crest to {@code PlayerInstance}
+ * @param player the @{code PlayerInstance} where html is send to.
+ * @return the client path to crest
+ */
+ public String getClientPath(PlayerInstance player)
+ {
+ String path = null;
+ switch (_type)
+ {
+ case PLEDGE:
+ {
+ player.sendPacket(new PledgeCrest(_id, _data));
+ path = "Crest.crest_" + Config.SERVER_ID + "_" + _id;
+ break;
+ }
+ case PLEDGE_LARGE:
+ {
+ player.sendPacket(new ExPledgeEmblem(_id, _data));
+ path = "Crest.crest_" + Config.SERVER_ID + "_" + _id + "_l";
+ break;
+ }
+ case ALLY:
+ {
+ player.sendPacket(new AllyCrest(_id, _data));
+ path = "Crest.crest_" + Config.SERVER_ID + "_" + _id;
+ break;
+ }
+ }
+ return path;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index 144023972d..7328fac502 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -2959,7 +2959,7 @@ public class PlayerInstance extends Playable
*/
public int getClanCrestId()
{
- if ((_clan != null) && _clan.hasCrest())
+ if (_clan != null)
{
return _clan.getCrestId();
}
@@ -2972,7 +2972,7 @@ public class PlayerInstance extends Playable
*/
public int getClanCrestLargeId()
{
- if ((_clan != null) && _clan.hasCrestLarge())
+ if (_clan != null)
{
return _clan.getCrestLargeId();
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/clan/Clan.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/clan/Clan.java
index 9df7f867e7..1ad840be22 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/clan/Clan.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/clan/Clan.java
@@ -37,6 +37,7 @@ import org.l2jmobius.gameserver.communitybbs.BB.Forum;
import org.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.data.sql.ClanTable;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.CrownManager;
import org.l2jmobius.gameserver.instancemanager.SiegeManager;
@@ -73,11 +74,10 @@ public class Clan
private int _castleId;
private int _fortId;
private int _hideoutId;
- private boolean _hasCrest;
private int _hiredGuards;
- private int _crestId;
- private int _crestLargeId;
- private int _allyCrestId;
+ private int _crestId = 0;
+ private int _crestLargeId = 0;
+ private int _allyCrestId = 0;
private int _auctionBiddedAt = 0;
private long _allyPenaltyExpiryTime;
private int _allyPenaltyType;
@@ -97,8 +97,6 @@ public class Clan
private final List _atWarWith = new ArrayList<>();
private final List _atWarAttackers = new ArrayList<>();
- private boolean _hasCrestLarge;
-
private Forum _forum;
private final List _skillList = new ArrayList<>();
@@ -621,16 +619,6 @@ public class Clan
return _allyName;
}
- public void setAllyCrestId(int allyCrestId)
- {
- _allyCrestId = allyCrestId;
- }
-
- public int getAllyCrestId()
- {
- return _allyCrestId;
- }
-
public int getLevel()
{
return _level;
@@ -651,9 +639,16 @@ public class Clan
return _hideoutId;
}
- /**
- * @param crestId The id of pledge crest.
- */
+ public void setAllyCrestId(int allyCrestId)
+ {
+ _allyCrestId = allyCrestId;
+ }
+
+ public int getAllyCrestId()
+ {
+ return _allyCrestId;
+ }
+
public void setCrestId(int crestId)
{
_crestId = crestId;
@@ -828,20 +823,9 @@ public class Clan
setDissolvingExpiryTime(clanData.getLong("dissolving_expiry_time"));
setCrestId(clanData.getInt("crest_id"));
-
- if (_crestId != 0)
- {
- setHasCrest(true);
- }
-
setCrestLargeId(clanData.getInt("crest_large_id"));
-
- if (_crestLargeId != 0)
- {
- setHasCrestLarge(true);
- }
-
setAllyCrestId(clanData.getInt("ally_crest_id"));
+
setReputationScore(clanData.getInt("reputation_score"), false);
setAuctionBiddedAt(clanData.getInt("auction_bid_at"), false);
@@ -1178,26 +1162,6 @@ public class Clan
}
}
- public boolean hasCrest()
- {
- return _hasCrest;
- }
-
- public boolean hasCrestLarge()
- {
- return _hasCrestLarge;
- }
-
- public void setHasCrest(boolean flag)
- {
- _hasCrest = flag;
- }
-
- public void setHasCrestLarge(boolean flag)
- {
- _hasCrestLarge = flag;
- }
-
public ItemContainer getWarehouse()
{
return _warehouse;
@@ -2317,26 +2281,126 @@ public class Clan
broadcastToOnlineMembers(new PledgeShowInfoUpdate(this));
}
- public void setAllyCrest(int crestId)
+ /**
+ * Change the clan crest. If crest id is 0, crest is removed. New crest id is saved to database.
+ * @param crestId if 0, crest is removed, else new crest id is set and saved to database
+ */
+ public void changeClanCrest(int crestId)
{
- try (Connection con = DatabaseFactory.getConnection())
+ if (_crestId != 0)
{
- setAllyCrestId(crestId);
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET ally_crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, crestId);
- statement.setInt(2, _clanId);
- statement.executeUpdate();
- statement.close();
+ CrestTable.getInstance().removeCrest(getCrestId());
+ }
+
+ setCrestId(crestId);
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
+ {
+ ps.setInt(1, crestId);
+ ps.setInt(2, _clanId);
+ ps.executeUpdate();
}
catch (SQLException e)
{
- LOGGER.warning("could not update the ally crest id:" + e.getMessage());
+ LOGGER.warning("Could not update crest for clan " + _name + " [" + _clanId + "] : " + e.getMessage());
+ }
+
+ for (PlayerInstance member : getOnlineMembers())
+ {
+ member.broadcastUserInfo();
+ }
+ }
+
+ /**
+ * Change the ally crest. If crest id is 0, crest is removed. New crest id is saved to database.
+ * @param crestId if 0, crest is removed, else new crest id is set and saved to database
+ * @param onlyThisClan
+ */
+ public void changeAllyCrest(int crestId, boolean onlyThisClan)
+ {
+ String sqlStatement = "UPDATE clan_data SET ally_crest_id = ? WHERE clan_id = ?";
+ int allyId = _clanId;
+ if (!onlyThisClan)
+ {
+ if (_allyCrestId != 0)
+ {
+ CrestTable.getInstance().removeCrest(getAllyCrestId());
+ }
+ sqlStatement = "UPDATE clan_data SET ally_crest_id = ? WHERE ally_id = ?";
+ allyId = _allyId;
+ }
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement ps = con.prepareStatement(sqlStatement))
+ {
+ ps.setInt(1, crestId);
+ ps.setInt(2, allyId);
+ ps.executeUpdate();
+ }
+ catch (SQLException e)
+ {
+ LOGGER.warning("Could not update ally crest for ally/clan id " + allyId + " : " + e.getMessage());
+ }
+
+ if (onlyThisClan)
+ {
+ setAllyCrestId(crestId);
+ for (PlayerInstance member : getOnlineMembers())
+ {
+ member.broadcastUserInfo();
+ }
+ }
+ else
+ {
+ for (Clan clan : ClanTable.getInstance().getClans())
+ {
+ if ((clan.getAllyId() == getAllyId()) && (clan.getClanId() != getClanId()))
+ {
+ clan.setAllyCrestId(crestId);
+ for (PlayerInstance member : clan.getOnlineMembers())
+ {
+ member.broadcastUserInfo();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Change the large crest. If crest id is 0, crest is removed. New crest id is saved to database.
+ * @param crestId if 0, crest is removed, else new crest id is set and saved to database
+ */
+ public void changeLargeCrest(int crestId)
+ {
+ if (_crestLargeId != 0)
+ {
+ CrestTable.getInstance().removeCrest(getCrestLargeId());
+ }
+
+ setCrestLargeId(crestId);
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?"))
+ {
+ ps.setInt(1, crestId);
+ ps.setInt(2, _clanId);
+ ps.executeUpdate();
+ }
+ catch (SQLException e)
+ {
+ LOGGER.warning("Could not update large crest for clan " + _name + " [" + _clanId + "] : " + e.getMessage());
+ }
+
+ for (PlayerInstance member : getOnlineMembers())
+ {
+ member.broadcastUserInfo();
}
}
@Override
public String toString()
{
- return "Clan [_name=" + _name + ", _clanId=" + _clanId + ", _leader=" + _leader + ", _members=" + _members + ", _allyName=" + _allyName + ", _allyId=" + _allyId + ", _level=" + _level + ", _hasCastle=" + _castleId + ", _hasFort=" + _fortId + ", _hasHideout=" + _hideoutId + ", _hasCrest=" + _hasCrest + ", _hiredGuards=" + _hiredGuards + ", _crestId=" + _crestId + ", _crestLargeId=" + _crestLargeId + ", _allyCrestId=" + _allyCrestId + ", _auctionBiddedAt=" + _auctionBiddedAt + ", _allyPenaltyExpiryTime=" + _allyPenaltyExpiryTime + ", _allyPenaltyType=" + _allyPenaltyType + ", _charPenaltyExpiryTime=" + _charPenaltyExpiryTime + ", _dissolvingExpiryTime=" + _dissolvingExpiryTime + ", _warehouse=" + _warehouse + ", _atWarWith=" + _atWarWith + ", _atWarAttackers=" + _atWarAttackers + ", _hasCrestLarge=" + _hasCrestLarge + ", _forum=" + _forum + ", _skillList=" + _skillList + ", _notice=" + _notice + ", _noticeEnabled=" + _noticeEnabled + ", _skills=" + _skills + ", _privs=" + _privs + ", _subPledges=" + _subPledges + ", _reputationScore=" + _reputationScore + ", _rank=" + _rank + "]";
+ return "Clan [_name=" + _name + ", _clanId=" + _clanId + ", _leader=" + _leader + ", _members=" + _members + ", _allyName=" + _allyName + ", _allyId=" + _allyId + ", _level=" + _level + ", _hasCastle=" + _castleId + ", _hasFort=" + _fortId + ", _hasHideout=" + _hideoutId + ", _hiredGuards=" + _hiredGuards + ", _crestId=" + _crestId + ", _crestLargeId=" + _crestLargeId + ", _allyCrestId=" + _allyCrestId + ", _auctionBiddedAt=" + _auctionBiddedAt + ", _allyPenaltyExpiryTime=" + _allyPenaltyExpiryTime + ", _allyPenaltyType=" + _allyPenaltyType + ", _charPenaltyExpiryTime=" + _charPenaltyExpiryTime + ", _dissolvingExpiryTime=" + _dissolvingExpiryTime + ", _warehouse=" + _warehouse + ", _atWarWith=" + _atWarWith + ", _atWarAttackers=" + _atWarAttackers + ", _forum=" + _forum + ", _skillList=" + _skillList + ", _notice=" + _notice + ", _noticeEnabled=" + _noticeEnabled + ", _skills=" + _skills + ", _privs=" + _privs + ", _subPledges=" + _subPledges + ", _reputationScore=" + _reputationScore + ", _rank=" + _rank + "]";
}
}
\ No newline at end of file
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java
new file mode 100644
index 0000000000..7d5824a8b3
--- /dev/null
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java
@@ -0,0 +1,26 @@
+/*
+ * 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 .
+ */
+package org.l2jmobius.gameserver.model.interfaces;
+
+/**
+ * Identifiable objects interface.
+ * @author Zoey76
+ */
+public interface IIdentifiable
+{
+ int getId();
+}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/OutgoingPackets.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/OutgoingPackets.java
index 2bb8aef9cd..410663b645 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/OutgoingPackets.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/OutgoingPackets.java
@@ -150,7 +150,7 @@ public enum OutgoingPackets
MY_TARGET_SELECTED(0xA6),
PARTY_MEMBER_POSITION(0xA7),
ASK_JOIN_ALLY(0xA8),
- ALLY_CREST(0xAE),
+ ALLIANCE_CREST(0xAE),
PET_STATUS_SHOW(0xB0),
PET_INFO(0xB1),
PET_ITEM_LIST(0xB2),
@@ -239,7 +239,7 @@ public enum OutgoingPackets
EX_OPEN_MPCC(0xFE, 0x25),
EX_CLOSE_MPCC(0xFE, 0x26),
EX_ASK_JOIN_MPCC(0xFE, 0x27),
- EX_PLEDGE_CREST_LARGE(0xFE, 0x28),
+ EX_PLEDGE_EMBLEM(0xFE, 0x28),
EX_OLYMPIAD_USER_INFO(0xFE, 0x29),
EX_OLYMPIAD_SPELLED_INFO(0xFE, 0x2A),
EX_OLYMPIAD_MODE(0xFE, 0x2B),
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java
index 97bdaf7202..cb32febf8e 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java
@@ -94,8 +94,8 @@ public class AllyDismiss implements IClientIncomingPacket
clan.setAllyId(0);
clan.setAllyName(null);
+ clan.changeAllyCrest(0, true);
clan.setAllyPenaltyExpiryTime(currentTime + (Config.ALT_ALLY_JOIN_DAYS_WHEN_DISMISSED * 86400000), Clan.PENALTY_TYPE_CLAN_DISMISSED); // 24*60*60*1000 = 86400000
- clan.setAllyCrest(0);
clan.updateClanInDB();
player.sendPacket(SystemMessageId.YOU_HAVE_SUCCEEDED_IN_EXPELLING_A_CLAN);
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java
index 0fc2bb8b25..edbecf365e 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java
@@ -69,8 +69,8 @@ public class AllyLeave implements IClientIncomingPacket
final long currentTime = Chronos.currentTimeMillis();
clan.setAllyId(0);
clan.setAllyName(null);
+ clan.changeAllyCrest(0, true);
clan.setAllyPenaltyExpiryTime(currentTime + (Config.ALT_ALLY_JOIN_DAYS_WHEN_LEAVED * 86400000), Clan.PENALTY_TYPE_CLAN_LEAVED); // 24*60*60*1000 = 86400000
- clan.setAllyCrest(0);
clan.updateClanInDB();
player.sendPacket(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_THE_ALLIANCE);
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java
index c635ac9e8a..dfc8fbf470 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java
@@ -22,9 +22,6 @@ import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
-/**
- * sample 5F 01 00 00 00 format cdd
- */
public class RequestAnswerJoinAlly implements IClientIncomingPacket
{
private int _response;
@@ -70,10 +67,11 @@ public class RequestAnswerJoinAlly implements IClientIncomingPacket
// TODO: Need correct message id
requestor.sendPacket(SystemMessageId.YOU_HAVE_SUCCEEDED_IN_INVITING_A_FRIEND_TO_YOUR_FRIENDS_LIST);
player.sendPacket(SystemMessageId.YOU_HAVE_ACCEPTED_THE_ALLIANCE);
+
player.getClan().setAllyId(clan.getAllyId());
player.getClan().setAllyName(clan.getAllyName());
player.getClan().setAllyPenaltyExpiryTime(0, 0);
- player.getClan().setAllyCrest(clan.getAllyCrestId());
+ player.getClan().changeAllyCrest(clan.getAllyCrestId(), true);
player.getClan().updateClanInDB();
}
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java
index 9c9c5ee1f6..7e35c11822 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java
@@ -17,9 +17,8 @@
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.commons.network.PacketReader;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.network.GameClient;
-import org.l2jmobius.gameserver.network.serverpackets.ExPledgeCrestLarge;
+import org.l2jmobius.gameserver.network.serverpackets.ExPledgeEmblem;
/**
* Fomat : chd c: (id) 0xD0 h: (subid) 0x10 d: the crest id This is a trigger
@@ -39,10 +38,6 @@ public class RequestExPledgeCrestLarge implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
- final byte[] data = CrestCache.getInstance().getPledgeCrestLarge(_crestId);
- if (data != null)
- {
- client.sendPacket(new ExPledgeCrestLarge(_crestId, data));
- }
+ client.sendPacket(new ExPledgeEmblem(_crestId));
}
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java
index 92001fb795..130ab324b0 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java
@@ -16,14 +16,11 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.network.PacketReader;
-import org.l2jmobius.gameserver.cache.CrestCache;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
+import org.l2jmobius.commons.util.Chronos;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
@@ -35,23 +32,19 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
*/
public class RequestExSetPledgeCrestLarge implements IClientIncomingPacket
{
- private int _size;
- private byte[] _data;
+ private int _length;
+ private byte[] _data = null;
@Override
public boolean read(GameClient client, PacketReader packet)
{
- _size = packet.readD();
- if (_size > 2176)
+ _length = packet.readD();
+ if (_length > 2176)
{
return false;
}
- if (_size > 0) // client CAN send a RequestExSetPledgeCrestLarge with the size set to 0 then format is just chd
- {
- _data = packet.readB(_size);
- }
-
+ _data = packet.readB(_length);
return true;
}
@@ -70,68 +63,45 @@ public class RequestExSetPledgeCrestLarge implements IClientIncomingPacket
return;
}
- if (_data == null)
- {
- CrestCache.getInstance().removePledgeCrestLarge(clan.getCrestId());
-
- clan.setHasCrestLarge(false);
- player.sendMessage("The insignia has been removed.");
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
- }
-
- return;
- }
-
- if (_size > 2176)
+ if ((_length < 0) || (_length > 2176))
{
player.sendMessage("The insignia file size is greater than 2176 bytes.");
return;
}
- if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) == Clan.CP_CL_REGISTER_CREST)
+ if (clan.getDissolvingExpiryTime() > Chronos.currentTimeMillis())
{
- if ((clan.getCastleId() == 0) && (clan.getHideoutId() == 0))
+ player.sendPacket(SystemMessageId.DURING_THE_GRACE_PERIOD_FOR_DISSOLVING_A_CLAN_THE_REGISTRATION_OR_DELETION_OF_A_CLAN_S_CREST_IS_NOT_ALLOWED);
+ return;
+ }
+
+ if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) != Clan.CP_CL_REGISTER_CREST)
+ {
+ player.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
+ return;
+ }
+
+ if (_length == 0)
+ {
+ if (clan.getCrestLargeId() != 0)
{
- player.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
+ clan.changeLargeCrest(0);
+ player.sendPacket(SystemMessageId.THE_CLAN_S_CREST_HAS_BEEN_DELETED);
+ }
+ }
+ else
+ {
+ if (clan.getLevel() < 3)
+ {
+ player.sendPacket(SystemMessageId.A_CLAN_CREST_CAN_ONLY_BE_REGISTERED_WHEN_THE_CLAN_S_SKILL_LEVEL_IS_3_OR_ABOVE);
return;
}
- final CrestCache crestCache = CrestCache.getInstance();
- final int newId = IdManager.getInstance().getNextId();
- if (!crestCache.savePledgeCrestLarge(newId, _data))
+ final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.PLEDGE_LARGE);
+ if (crest != null)
{
- LOGGER.warning("Error loading large crest of clan:" + clan.getName());
- return;
- }
-
- if (clan.hasCrestLarge())
- {
- crestCache.removePledgeCrestLarge(clan.getCrestLargeId());
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final 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)
- {
- LOGGER.warning("could not update the large crest id:" + e.getMessage());
- }
-
- clan.setCrestLargeId(newId);
- clan.setHasCrestLarge(true);
-
- player.sendPacket(SystemMessageId.THE_CLAN_CREST_WAS_SUCCESSFULLY_REGISTERED_REMEMBER_ONLY_A_CLAN_THAT_OWNS_A_CLAN_HALL_OR_CASTLE_CAN_HAVE_THEIR_CREST_DISPLAYED);
-
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
+ clan.changeLargeCrest(crest.getId());
+ player.sendPacket(SystemMessageId.THE_CLAN_CREST_WAS_SUCCESSFULLY_REGISTERED_REMEMBER_ONLY_A_CLAN_THAT_OWNS_A_CLAN_HALL_OR_CASTLE_CAN_HAVE_THEIR_CREST_DISPLAYED);
}
}
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java
index f6b17550d0..fd38a5f9e1 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java
@@ -16,33 +16,32 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.network.PacketReader;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.data.sql.ClanTable;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
+import org.l2jmobius.gameserver.network.SystemMessageId;
+/**
+ * Client packet for setting ally crest.
+ */
public class RequestSetAllyCrest implements IClientIncomingPacket
{
private int _length;
- private byte[] _data;
+ private byte[] _data = null;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_length = packet.readD();
- if ((_length < 0) || (_length > 192))
+ if (_length > 192)
{
return false;
}
-
_data = packet.readB(_length);
return true;
}
@@ -64,54 +63,37 @@ public class RequestSetAllyCrest implements IClientIncomingPacket
if (_length > 192)
{
- player.sendMessage("The crest file size was too big (max 192 bytes).");
+ player.sendPacket(SystemMessageId.PLEASE_ADJUST_THE_IMAGE_SIZE_TO_8X12);
return;
}
- if (player.getAllyId() != 0)
+ if (player.getAllyId() == 0)
{
- final Clan leaderclan = ClanTable.getInstance().getClan(player.getAllyId());
- if ((player.getClanId() != leaderclan.getClanId()) || !player.isClanLeader())
+ player.sendPacket(SystemMessageId.THIS_FEATURE_IS_ONLY_AVAILABLE_ALLIANCE_LEADERS);
+ return;
+ }
+
+ final Clan leaderClan = ClanTable.getInstance().getClan(player.getAllyId());
+ if ((player.getClanId() != leaderClan.getClanId()) || !player.isClanLeader())
+ {
+ player.sendPacket(SystemMessageId.THIS_FEATURE_IS_ONLY_AVAILABLE_ALLIANCE_LEADERS);
+ return;
+ }
+
+ if (_length == 0)
+ {
+ if (leaderClan.getAllyCrestId() != 0)
{
- return;
+ leaderClan.changeAllyCrest(0, false);
}
-
- final CrestCache crestCache = CrestCache.getInstance();
- final int newId = IdManager.getInstance().getNextId();
- if (!crestCache.saveAllyCrest(newId, _data))
+ }
+ else
+ {
+ final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.ALLY);
+ if (crest != null)
{
- LOGGER.warning("Error loading crest of ally:" + leaderclan.getAllyName());
- return;
- }
-
- if (leaderclan.getAllyCrestId() != 0)
- {
- crestCache.removeAllyCrest(leaderclan.getAllyCrestId());
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET ally_crest_id = ? WHERE ally_id = ?");
- statement.setInt(1, newId);
- statement.setInt(2, leaderclan.getAllyId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("could not update the ally crest id:" + e.getMessage());
- }
-
- for (Clan clan : ClanTable.getInstance().getClans())
- {
- if (clan.getAllyId() == player.getAllyId())
- {
- clan.setAllyCrestId(newId);
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
- }
- }
+ leaderClan.changeAllyCrest(crest.getId(), false);
+ player.sendMessage("The crest was successfully registered.");
}
}
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java
index 7f836c7ee0..a7ea5d295d 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java
@@ -16,30 +16,29 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.commons.util.Chronos;
-import org.l2jmobius.gameserver.cache.CrestCache;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
+/**
+ * Client packet for setting/deleting clan crest.
+ */
public class RequestSetPledgeCrest implements IClientIncomingPacket
{
private int _length;
- private byte[] _data;
+ private byte[] _data = null;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_length = packet.readD();
- if ((_length < 0) || (_length > 256))
+ if (_length > 256)
{
return false;
}
@@ -57,6 +56,18 @@ public class RequestSetPledgeCrest implements IClientIncomingPacket
return;
}
+ if ((_length < 0))
+ {
+ player.sendMessage("File transfer error.");
+ return;
+ }
+
+ if (_length > 256)
+ {
+ player.sendMessage("The clan crest file size was too big (max 256 bytes).");
+ return;
+ }
+
final Clan clan = player.getClan();
if (clan == null)
{
@@ -69,46 +80,21 @@ public class RequestSetPledgeCrest implements IClientIncomingPacket
return;
}
- if (_length < 0)
+ if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) != Clan.CP_CL_REGISTER_CREST)
{
- player.sendMessage("File transfer error.");
+ player.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
return;
}
- if (_length > 256)
+ if (_length == 0)
{
- player.sendMessage("The clan crest file size was too big (max 256 bytes).");
- return;
+ if (clan.getCrestId() != 0)
+ {
+ clan.changeClanCrest(0);
+ player.sendPacket(SystemMessageId.THE_CLAN_S_CREST_HAS_BEEN_DELETED);
+ }
}
-
- if ((_length == 0) || (_data.length == 0))
- {
- CrestCache.getInstance().removePledgeCrest(clan.getCrestId());
-
- clan.setHasCrest(false);
- player.sendPacket(SystemMessageId.THE_CLAN_S_CREST_HAS_BEEN_DELETED);
-
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, 0);
- statement.setInt(2, clan.getClanId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("Could not update the crest id: " + e.getMessage());
- }
- return;
- }
-
- if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) == Clan.CP_CL_REGISTER_CREST)
+ else
{
if (clan.getLevel() < 3)
{
@@ -116,38 +102,11 @@ public class RequestSetPledgeCrest implements IClientIncomingPacket
return;
}
- final CrestCache crestCache = CrestCache.getInstance();
- final int newId = IdManager.getInstance().getNextId();
- if (clan.hasCrest())
+ final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.PLEDGE);
+ if (crest != null)
{
- crestCache.removePledgeCrest(newId);
- }
-
- if (!crestCache.savePledgeCrest(newId, _data))
- {
- LOGGER.warning("Error loading crest of clan:" + clan.getName());
- return;
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, newId);
- statement.setInt(2, clan.getClanId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("Could not update the crest id: " + e.getMessage());
- }
-
- clan.setCrestId(newId);
- clan.setHasCrest(true);
-
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
+ clan.changeClanCrest(crest.getId());
+ player.sendMessage("The crest was successfully registered.");
}
}
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java
index 05156dff5c..af7bf93f72 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java
@@ -17,20 +17,10 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.commons.network.PacketWriter;
-import org.l2jmobius.gameserver.cache.CrestCache;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
import org.l2jmobius.gameserver.network.OutgoingPackets;
-/**
- *
- * sample
- * 0000: c7 6d 06 00 00 36 05 00 00 42 4d 36 05 00 00 00 .m...6...BM6....
- * 0010: 00 00 00 36 04 00 00 28 00 00 00 10 00 00 00 10 ...6...(........
- * 0020: 00 00 00 01 00 08 00 00 00 00 00 00 01 00 00 c4 ................
- * 0030: ...
- * 0530: 10 91 00 00 00 60 9b d1 01 e4 6e ee 52 97 dd .....`....n.R..
- *
format dd x...x
- * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:39 $
- */
public class AllyCrest implements IClientOutgoingPacket
{
private final int _crestId;
@@ -39,13 +29,20 @@ public class AllyCrest implements IClientOutgoingPacket
public AllyCrest(int crestId)
{
_crestId = crestId;
- _data = CrestCache.getInstance().getAllyCrest(_crestId);
+ final Crest crest = CrestTable.getInstance().getCrest(crestId);
+ _data = crest != null ? crest.getData() : null;
+ }
+
+ public AllyCrest(int crestId, byte[] data)
+ {
+ _crestId = crestId;
+ _data = data;
}
@Override
public boolean write(PacketWriter packet)
{
- OutgoingPackets.ALLY_CREST.writeId(packet);
+ OutgoingPackets.ALLIANCE_CREST.writeId(packet);
packet.writeD(_crestId);
if (_data != null)
{
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeCrestLarge.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeEmblem.java
similarity index 63%
rename from L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeCrestLarge.java
rename to L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeEmblem.java
index 691633f5d7..023b5a0b41 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeCrestLarge.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeEmblem.java
@@ -17,18 +17,26 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.commons.network.PacketWriter;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
import org.l2jmobius.gameserver.network.OutgoingPackets;
/**
- * Format: (ch) ddd b d: ? d: crest ID d: crest size b: raw data
* @author -Wooden-
*/
-public class ExPledgeCrestLarge implements IClientOutgoingPacket
+public class ExPledgeEmblem implements IClientOutgoingPacket
{
private final int _crestId;
private final byte[] _data;
- public ExPledgeCrestLarge(int crestId, byte[] data)
+ public ExPledgeEmblem(int crestId)
+ {
+ _crestId = crestId;
+ final Crest crest = CrestTable.getInstance().getCrest(crestId);
+ _data = crest != null ? crest.getData() : null;
+ }
+
+ public ExPledgeEmblem(int crestId, byte[] data)
{
_crestId = crestId;
_data = data;
@@ -37,13 +45,18 @@ public class ExPledgeCrestLarge implements IClientOutgoingPacket
@Override
public boolean write(PacketWriter packet)
{
- OutgoingPackets.EX_PLEDGE_CREST_LARGE.writeId(packet);
-
- packet.writeD(0x00); // ???
+ OutgoingPackets.EX_PLEDGE_EMBLEM.writeId(packet);
+ packet.writeD(0x00);
packet.writeD(_crestId);
- packet.writeD(_data.length);
-
- packet.writeB(_data);
+ if (_data != null)
+ {
+ packet.writeD(_data.length);
+ packet.writeB(_data);
+ }
+ else
+ {
+ packet.writeD(0);
+ }
return true;
}
}
diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java
index b761558b68..5b93dca07b 100644
--- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java
+++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java
@@ -17,14 +17,10 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.commons.network.PacketWriter;
-import org.l2jmobius.gameserver.cache.CrestCache;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
import org.l2jmobius.gameserver.network.OutgoingPackets;
-/**
- * sample 0000: 84 6d 06 00 00 36 05 00 00 42 4d 36 05 00 00 00 .m...6...BM6.... 0010: 00 00 00 36 04 00 00 28 00 00 00 10 00 00 00 10 ...6...(........ 0020: 00 00 00 01 00 08 00 00 00 00 00 00 01 00 00 c4 ................ 0030: ... 0530: 10 91 00 00 00 60 9b d1 01 e4 6e ee 52 97 dd .....`....n.R..
- * format dd x...x
- * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:57 $
- */
public class PledgeCrest implements IClientOutgoingPacket
{
private final int _crestId;
@@ -33,7 +29,14 @@ public class PledgeCrest implements IClientOutgoingPacket
public PledgeCrest(int crestId)
{
_crestId = crestId;
- _data = CrestCache.getInstance().getPledgeCrest(_crestId);
+ final Crest crest = CrestTable.getInstance().getCrest(crestId);
+ _data = crest != null ? crest.getData() : null;
+ }
+
+ public PledgeCrest(int crestId, byte[] data)
+ {
+ _crestId = crestId;
+ _data = data;
}
@Override
diff --git a/L2J_Mobius_C6_Interlude/dist/db_installer/sql/game/crests.sql b/L2J_Mobius_C6_Interlude/dist/db_installer/sql/game/crests.sql
new file mode 100644
index 0000000000..b3e6dd8b67
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/dist/db_installer/sql/game/crests.sql
@@ -0,0 +1,6 @@
+CREATE TABLE IF NOT EXISTS `crests` (
+ `crest_id` INT,
+ `data` VARBINARY(2176) NOT NULL,
+ `type` TINYINT NOT NULL,
+ PRIMARY KEY(`crest_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
\ No newline at end of file
diff --git a/L2J_Mobius_C6_Interlude/dist/game/config/AdminCommands.xml b/L2J_Mobius_C6_Interlude/dist/game/config/AdminCommands.xml
index cd7610a619..68fd0f5328 100644
--- a/L2J_Mobius_C6_Interlude/dist/game/config/AdminCommands.xml
+++ b/L2J_Mobius_C6_Interlude/dist/game/config/AdminCommands.xml
@@ -51,9 +51,8 @@
-
-
-
+
+
diff --git a/L2J_Mobius_C6_Interlude/dist/game/data/html/admin/server_menu.htm b/L2J_Mobius_C6_Interlude/dist/game/data/html/admin/server_menu.htm
index 93eb0ac74a..48c285aeb2 100644
--- a/L2J_Mobius_C6_Interlude/dist/game/data/html/admin/server_menu.htm
+++ b/L2J_Mobius_C6_Interlude/dist/game/data/html/admin/server_menu.htm
@@ -19,12 +19,12 @@
|
|
|
- |
-
|
+
|
|
|
+ |
Geodata
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
index 3491b77692..9dcc602f5c 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/GameServer.java
@@ -33,7 +33,6 @@ import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.Chronos;
import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.commons.util.PropertiesParser;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
import org.l2jmobius.gameserver.data.ItemTable;
@@ -42,6 +41,7 @@ import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.data.sql.AnnouncementsTable;
import org.l2jmobius.gameserver.data.sql.CharNameTable;
import org.l2jmobius.gameserver.data.sql.ClanTable;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
import org.l2jmobius.gameserver.data.sql.HelperBuffTable;
import org.l2jmobius.gameserver.data.sql.NpcTable;
import org.l2jmobius.gameserver.data.sql.OfflineTraderTable;
@@ -185,12 +185,10 @@ public class GameServer
throw new Exception("Could not initialize the ID factory!");
}
- new File(Config.DATAPACK_ROOT, "data/clans").mkdirs();
- new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
new File(Config.DATAPACK_ROOT, "data/geodata").mkdirs();
HtmCache.getInstance();
- CrestCache.getInstance();
+ CrestTable.getInstance();
ScriptEngineManager.getInstance();
printSection("World");
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/cache/CrestCache.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/cache/CrestCache.java
deleted file mode 100644
index 8c086a3458..0000000000
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/cache/CrestCache.java
+++ /dev/null
@@ -1,380 +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 .
- */
-package org.l2jmobius.gameserver.cache;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-import org.l2jmobius.Config;
-import org.l2jmobius.commons.database.DatabaseFactory;
-import org.l2jmobius.gameserver.data.sql.ClanTable;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
-import org.l2jmobius.gameserver.model.clan.Clan;
-
-/**
- * @author Layane
- */
-public class CrestCache
-{
- private static final Logger LOGGER = Logger.getLogger(CrestCache.class.getName());
-
- private final Map _cachePledge = new HashMap<>();
- private final Map _cachePledgeLarge = new HashMap<>();
- private final Map _cacheAlly = new HashMap<>();
- private int _loadedFiles;
- private long _bytesBuffLen;
-
- protected CrestCache()
- {
- convertOldPedgeFiles();
- reload();
- }
-
- public void reload()
- {
- final FileFilter filter = new BmpFilter();
- final File dir = new File(Config.DATAPACK_ROOT, "data/crests/");
- final File[] files = dir.listFiles(filter);
- byte[] content;
- synchronized (this)
- {
- _loadedFiles = 0;
- _bytesBuffLen = 0;
- _cachePledge.clear();
- _cachePledgeLarge.clear();
- _cacheAlly.clear();
- }
-
- for (File file : files)
- {
- RandomAccessFile f = null;
- synchronized (this)
- {
- try
- {
- f = new RandomAccessFile(file, "r");
- content = new byte[(int) f.length()];
- f.readFully(content);
-
- if (file.getName().startsWith("Crest_Large_"))
- {
- _cachePledgeLarge.put(Integer.parseInt(file.getName().substring(12, file.getName().length() - 4)), content);
- }
- else if (file.getName().startsWith("Crest_"))
- {
- _cachePledge.put(Integer.parseInt(file.getName().substring(6, file.getName().length() - 4)), content);
- }
- else if (file.getName().startsWith("AllyCrest_"))
- {
- _cacheAlly.put(Integer.parseInt(file.getName().substring(10, file.getName().length() - 4)), content);
- }
-
- _loadedFiles++;
- _bytesBuffLen += content.length;
- }
- catch (Exception e)
- {
- LOGGER.warning("problem with crest bmp file " + e);
- }
- finally
- {
- if (f != null)
- {
- try
- {
- f.close();
- }
- catch (Exception e1)
- {
- LOGGER.warning("Problem with CrestCache: " + e1.getMessage());
- }
- }
- }
- }
- }
-
- LOGGER.info("Cache[Crest]: " + String.format("%.3f", getMemoryUsage()) + "MB on " + _loadedFiles + " files loaded.");
- }
-
- public void convertOldPedgeFiles()
- {
- final File dir = new File(Config.DATAPACK_ROOT, "data/crests/");
- final File[] files = dir.listFiles(new OldPledgeFilter());
- if (files == null)
- {
- LOGGER.info("No old crest files found in \"data/crests/\"!!! May be you deleted them?");
- return;
- }
-
- for (File file : files)
- {
- final int clanId = Integer.parseInt(file.getName().substring(7, file.getName().length() - 4));
-
- LOGGER.info("Found old crest file \"" + file.getName() + "\" for clanId " + clanId);
-
- final int newId = IdManager.getInstance().getNextId();
- final Clan clan = ClanTable.getInstance().getClan(clanId);
- if (clan != null)
- {
- removeOldPledgeCrest(clan.getCrestId());
-
- file.renameTo(new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp"));
- LOGGER.info("Renamed Clan crest to new format: Crest_" + newId + ".bmp");
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, newId);
- statement.setInt(2, clan.getClanId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("could not update the crest id:" + e.getMessage());
- }
-
- clan.setCrestId(newId);
- clan.setHasCrest(true);
- }
- else
- {
- LOGGER.info("Clan Id: " + clanId + " does not exist in table.. deleting.");
- file.delete();
- }
- }
- }
-
- public float getMemoryUsage()
- {
- return (float) _bytesBuffLen / 1048576;
- }
-
- public int getLoadedFiles()
- {
- return _loadedFiles;
- }
-
- public byte[] getPledgeCrest(int id)
- {
- return _cachePledge.get(id);
- }
-
- public byte[] getPledgeCrestLarge(int id)
- {
- return _cachePledgeLarge.get(id);
- }
-
- public byte[] getAllyCrest(int id)
- {
- return _cacheAlly.get(id);
- }
-
- public void removePledgeCrest(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + id + ".bmp");
- _cachePledge.remove(id);
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public void removePledgeCrestLarge(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_Large_" + id + ".bmp");
- _cachePledgeLarge.remove(id);
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public void removeOldPledgeCrest(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Pledge_" + id + ".bmp");
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public void removeAllyCrest(int id)
- {
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/AllyCrest_" + id + ".bmp");
- _cacheAlly.remove(id);
-
- try
- {
- crestFile.delete();
- }
- catch (Exception e)
- {
- }
- }
-
- public boolean savePledgeCrest(int newId, byte[] data)
- {
- boolean output = false;
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_" + newId + ".bmp");
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(crestFile);
- out.write(data);
- _cachePledge.put(newId, data);
-
- output = true;
- }
- catch (IOException e)
- {
- LOGGER.warning("Error saving pledge crest" + crestFile + " " + e);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- LOGGER.warning("Problem with CrestCache: " + e.getMessage());
- }
- }
- }
- return output;
- }
-
- public boolean savePledgeCrestLarge(int newId, byte[] data)
- {
- boolean output = false;
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/Crest_Large_" + newId + ".bmp");
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(crestFile);
- out.write(data);
- _cachePledgeLarge.put(newId, data);
-
- output = true;
- }
- catch (IOException e)
- {
- LOGGER.warning("Error saving Large pledge crest" + crestFile + " " + e);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- LOGGER.warning("Problem with CrestCache: " + e.getMessage());
- }
- }
- }
- return output;
- }
-
- public boolean saveAllyCrest(int newId, byte[] data)
- {
- boolean output = false;
- final File crestFile = new File(Config.DATAPACK_ROOT, "data/crests/AllyCrest_" + newId + ".bmp");
- FileOutputStream out = null;
- try
- {
- out = new FileOutputStream(crestFile);
- out.write(data);
- _cacheAlly.put(newId, data);
-
- output = true;
- }
- catch (IOException e)
- {
- LOGGER.warning("Error saving ally crest" + crestFile + " " + e);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- LOGGER.warning("Problem with CrestCache: " + e.getMessage());
- }
- }
- }
- return output;
- }
-
- class BmpFilter implements FileFilter
- {
- @Override
- public boolean accept(File file)
- {
- return file.getName().endsWith(".bmp");
- }
- }
-
- class OldPledgeFilter implements FileFilter
- {
- @Override
- public boolean accept(File file)
- {
- return file.getName().startsWith("Pledge_");
- }
- }
-
- public static CrestCache getInstance()
- {
- return SingletonHolder.INSTANCE;
- }
-
- private static class SingletonHolder
- {
- protected static final CrestCache INSTANCE = new CrestCache();
- }
-}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/data/sql/CrestTable.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/data/sql/CrestTable.java
new file mode 100644
index 0000000000..6a27eae0c3
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/data/sql/CrestTable.java
@@ -0,0 +1,219 @@
+/*
+ * 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 .
+ */
+package org.l2jmobius.gameserver.data.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.l2jmobius.commons.database.DatabaseFactory;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
+import org.l2jmobius.gameserver.model.clan.Clan;
+
+/**
+ * Loads and saves crests from database.
+ * @author NosBit
+ */
+public class CrestTable
+{
+ private static final Logger LOGGER = Logger.getLogger(CrestTable.class.getName());
+
+ private final Map _crests = new ConcurrentHashMap<>();
+ private final AtomicInteger _nextId = new AtomicInteger(1);
+
+ protected CrestTable()
+ {
+ load();
+ }
+
+ public synchronized void load()
+ {
+ _crests.clear();
+ final Set crestsInUse = new HashSet<>();
+ for (Clan clan : ClanTable.getInstance().getClans())
+ {
+ if (clan.getCrestId() != 0)
+ {
+ crestsInUse.add(clan.getCrestId());
+ }
+
+ if (clan.getCrestLargeId() != 0)
+ {
+ crestsInUse.add(clan.getCrestLargeId());
+ }
+
+ if (clan.getAllyCrestId() != 0)
+ {
+ crestsInUse.add(clan.getAllyCrestId());
+ }
+ }
+
+ try (Connection con = DatabaseFactory.getConnection();
+ Statement statement = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs = statement.executeQuery("SELECT `crest_id`, `data`, `type` FROM `crests` ORDER BY `crest_id` DESC"))
+ {
+ while (rs.next())
+ {
+ final int id = rs.getInt("crest_id");
+
+ if (_nextId.get() <= id)
+ {
+ _nextId.set(id + 1);
+ }
+
+ // delete all unused crests except the last one we dont want to reuse
+ // a crest id because client will display wrong crest if its reused
+ if (!crestsInUse.contains(id) && (id != (_nextId.get() - 1)))
+ {
+ rs.deleteRow();
+ continue;
+ }
+
+ final byte[] data = rs.getBytes("data");
+ final CrestType crestType = CrestType.getById(rs.getInt("type"));
+ if (crestType != null)
+ {
+ _crests.put(id, new Crest(id, data, crestType));
+ }
+ else
+ {
+ LOGGER.warning("Unknown crest type found in database. Type:" + rs.getInt("type"));
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ LOGGER.log(Level.WARNING, "There was an error while loading crests from database:", e);
+ }
+
+ LOGGER.info(getClass().getSimpleName() + ": Loaded " + _crests.size() + " Crests.");
+
+ for (Clan clan : ClanTable.getInstance().getClans())
+ {
+ if ((clan.getCrestId() != 0) && (getCrest(clan.getCrestId()) == null))
+ {
+ LOGGER.info("Removing non-existent crest for clan " + clan.getName() + " [" + clan.getClanId() + "], crestId:" + clan.getCrestId());
+ clan.setCrestId(0);
+ clan.changeClanCrest(0);
+ }
+
+ if ((clan.getCrestLargeId() != 0) && (getCrest(clan.getCrestLargeId()) == null))
+ {
+ LOGGER.info("Removing non-existent large crest for clan " + clan.getName() + " [" + clan.getClanId() + "], crestLargeId:" + clan.getCrestLargeId());
+ clan.setCrestLargeId(0);
+ clan.changeLargeCrest(0);
+ }
+
+ if ((clan.getAllyCrestId() != 0) && (getCrest(clan.getAllyCrestId()) == null))
+ {
+ LOGGER.info("Removing non-existent ally crest for clan " + clan.getName() + " [" + clan.getClanId() + "], allyCrestId:" + clan.getAllyCrestId());
+ clan.setAllyCrestId(0);
+ clan.changeAllyCrest(0, true);
+ }
+ }
+ }
+
+ /**
+ * @param crestId The crest id
+ * @return {@code Crest} if crest is found, {@code null} if crest was not found.
+ */
+ public Crest getCrest(int crestId)
+ {
+ return _crests.get(crestId);
+ }
+
+ /**
+ * Creates a {@code Crest} object and inserts it in database and cache.
+ * @param data
+ * @param crestType
+ * @return {@code Crest} on success, {@code null} on failure.
+ */
+ public Crest createCrest(byte[] data, CrestType crestType)
+ {
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement statement = con.prepareStatement("INSERT INTO `crests`(`crest_id`, `data`, `type`) VALUES(?, ?, ?)"))
+ {
+ final Crest crest = new Crest(_nextId.getAndIncrement(), data, crestType);
+ statement.setInt(1, crest.getId());
+ statement.setBytes(2, crest.getData());
+ statement.setInt(3, crest.getType().getId());
+ statement.executeUpdate();
+ _crests.put(crest.getId(), crest);
+ return crest;
+ }
+ catch (SQLException e)
+ {
+ LOGGER.log(Level.WARNING, "There was an error while saving crest in database:", e);
+ }
+ return null;
+ }
+
+ /**
+ * Removes crest from database and cache.
+ * @param crestId the id of crest to be removed.
+ */
+ public void removeCrest(int crestId)
+ {
+ _crests.remove(crestId);
+
+ // avoid removing last crest id we dont want to lose index...
+ // because client will display wrong crest if its reused
+ if (crestId == (_nextId.get() - 1))
+ {
+ return;
+ }
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement statement = con.prepareStatement("DELETE FROM `crests` WHERE `crest_id` = ?"))
+ {
+ statement.setInt(1, crestId);
+ statement.executeUpdate();
+ }
+ catch (SQLException e)
+ {
+ LOGGER.log(Level.WARNING, "There was an error while deleting crest from database:", e);
+ }
+ }
+
+ /**
+ * @return The next crest id.
+ */
+ public int getNextId()
+ {
+ return _nextId.getAndIncrement();
+ }
+
+ public static CrestTable getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+
+ private static class SingletonHolder
+ {
+ protected static final CrestTable INSTANCE = new CrestTable();
+ }
+}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java
index ba4d7ba52a..a925d4c286 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/handler/admincommandhandlers/AdminCache.java
@@ -20,8 +20,8 @@ import java.io.File;
import java.util.StringTokenizer;
import org.l2jmobius.Config;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.cache.HtmCache;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
import org.l2jmobius.gameserver.handler.IAdminCommandHandler;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.util.BuilderUtil;
@@ -38,8 +38,7 @@ public class AdminCache implements IAdminCommandHandler
"admin_cache_reload_path",
"admin_cache_reload_file",
"admin_cache_crest_rebuild",
- "admin_cache_crest_reload",
- "admin_cache_crest_fix"
+ "admin_cache_crest_reload"
};
@Override
@@ -94,14 +93,7 @@ public class AdminCache implements IAdminCommandHandler
case "admin_cache_crest_rebuild":
case "admin_cache_crest_reload":
{
- CrestCache.getInstance().reload();
- BuilderUtil.sendSysMessage(activeChar, "Cache[Crest]: " + String.format("%.3f", CrestCache.getInstance().getMemoryUsage()) + " megabytes on " + CrestCache.getInstance().getLoadedFiles() + " files loaded");
- return true;
- }
- case "admin_cache_crest_fix":
- {
- CrestCache.getInstance().convertOldPedgeFiles();
- BuilderUtil.sendSysMessage(activeChar, "Cache[Crest]: crests fixed");
+ CrestTable.getInstance().load();
return true;
}
default:
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/Crest.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/Crest.java
new file mode 100644
index 0000000000..5389e63214
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/Crest.java
@@ -0,0 +1,120 @@
+/*
+ * 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 .
+ */
+package org.l2jmobius.gameserver.model;
+
+import org.l2jmobius.Config;
+import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
+import org.l2jmobius.gameserver.model.interfaces.IIdentifiable;
+import org.l2jmobius.gameserver.network.serverpackets.AllyCrest;
+import org.l2jmobius.gameserver.network.serverpackets.ExPledgeEmblem;
+import org.l2jmobius.gameserver.network.serverpackets.PledgeCrest;
+
+/**
+ * @author NosBit
+ */
+public class Crest implements IIdentifiable
+{
+ public enum CrestType
+ {
+ PLEDGE(1),
+ PLEDGE_LARGE(2),
+ ALLY(3);
+
+ private final int _id;
+
+ CrestType(int id)
+ {
+ _id = id;
+ }
+
+ public int getId()
+ {
+ return _id;
+ }
+
+ public static CrestType getById(int id)
+ {
+ for (CrestType crestType : values())
+ {
+ if (crestType.getId() == id)
+ {
+ return crestType;
+ }
+ }
+ return null;
+ }
+ }
+
+ private final int _id;
+ private final byte[] _data;
+ private final CrestType _type;
+
+ public Crest(int id, byte[] data, CrestType type)
+ {
+ _id = id;
+ _data = data;
+ _type = type;
+ }
+
+ @Override
+ public int getId()
+ {
+ return _id;
+ }
+
+ public byte[] getData()
+ {
+ return _data;
+ }
+
+ public CrestType getType()
+ {
+ return _type;
+ }
+
+ /**
+ * Gets the client path to crest for use in html and sends the crest to {@code PlayerInstance}
+ * @param player the @{code PlayerInstance} where html is send to.
+ * @return the client path to crest
+ */
+ public String getClientPath(PlayerInstance player)
+ {
+ String path = null;
+ switch (_type)
+ {
+ case PLEDGE:
+ {
+ player.sendPacket(new PledgeCrest(_id, _data));
+ path = "Crest.crest_" + Config.SERVER_ID + "_" + _id;
+ break;
+ }
+ case PLEDGE_LARGE:
+ {
+ player.sendPacket(new ExPledgeEmblem(_id, _data));
+ path = "Crest.crest_" + Config.SERVER_ID + "_" + _id + "_l";
+ break;
+ }
+ case ALLY:
+ {
+ player.sendPacket(new AllyCrest(_id, _data));
+ path = "Crest.crest_" + Config.SERVER_ID + "_" + _id;
+ break;
+ }
+ }
+ return path;
+ }
+}
\ No newline at end of file
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
index f05ca815de..fd317eb83e 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/actor/instance/PlayerInstance.java
@@ -3027,7 +3027,7 @@ public class PlayerInstance extends Playable
*/
public int getClanCrestId()
{
- if ((_clan != null) && _clan.hasCrest())
+ if (_clan != null)
{
return _clan.getCrestId();
}
@@ -3040,7 +3040,7 @@ public class PlayerInstance extends Playable
*/
public int getClanCrestLargeId()
{
- if ((_clan != null) && _clan.hasCrestLarge())
+ if (_clan != null)
{
return _clan.getCrestLargeId();
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/clan/Clan.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/clan/Clan.java
index 57099689e3..a9fd11524a 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/clan/Clan.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/clan/Clan.java
@@ -37,6 +37,7 @@ import org.l2jmobius.gameserver.communitybbs.BB.Forum;
import org.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
import org.l2jmobius.gameserver.data.SkillTable;
import org.l2jmobius.gameserver.data.sql.ClanTable;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.CrownManager;
import org.l2jmobius.gameserver.instancemanager.SiegeManager;
@@ -74,11 +75,10 @@ public class Clan
private int _castleId;
private int _fortId;
private int _hideoutId;
- private boolean _hasCrest;
private int _hiredGuards;
- private int _crestId;
- private int _crestLargeId;
- private int _allyCrestId;
+ private int _crestId = 0;
+ private int _crestLargeId = 0;
+ private int _allyCrestId = 0;
private int _auctionBiddedAt = 0;
private long _allyPenaltyExpiryTime;
private int _allyPenaltyType;
@@ -98,8 +98,6 @@ public class Clan
private final List _atWarWith = new ArrayList<>();
private final List _atWarAttackers = new ArrayList<>();
- private boolean _hasCrestLarge;
-
private Forum _forum;
private final List _skillList = new ArrayList<>();
@@ -622,16 +620,6 @@ public class Clan
return _allyName;
}
- public void setAllyCrestId(int allyCrestId)
- {
- _allyCrestId = allyCrestId;
- }
-
- public int getAllyCrestId()
- {
- return _allyCrestId;
- }
-
public int getLevel()
{
return _level;
@@ -652,9 +640,16 @@ public class Clan
return _hideoutId;
}
- /**
- * @param crestId The id of pledge crest.
- */
+ public void setAllyCrestId(int allyCrestId)
+ {
+ _allyCrestId = allyCrestId;
+ }
+
+ public int getAllyCrestId()
+ {
+ return _allyCrestId;
+ }
+
public void setCrestId(int crestId)
{
_crestId = crestId;
@@ -829,20 +824,9 @@ public class Clan
setDissolvingExpiryTime(clanData.getLong("dissolving_expiry_time"));
setCrestId(clanData.getInt("crest_id"));
-
- if (_crestId != 0)
- {
- setHasCrest(true);
- }
-
setCrestLargeId(clanData.getInt("crest_large_id"));
-
- if (_crestLargeId != 0)
- {
- setHasCrestLarge(true);
- }
-
setAllyCrestId(clanData.getInt("ally_crest_id"));
+
setReputationScore(clanData.getInt("reputation_score"), false);
setAuctionBiddedAt(clanData.getInt("auction_bid_at"), false);
@@ -1195,26 +1179,6 @@ public class Clan
}
}
- public boolean hasCrest()
- {
- return _hasCrest;
- }
-
- public boolean hasCrestLarge()
- {
- return _hasCrestLarge;
- }
-
- public void setHasCrest(boolean flag)
- {
- _hasCrest = flag;
- }
-
- public void setHasCrestLarge(boolean flag)
- {
- _hasCrestLarge = flag;
- }
-
public ItemContainer getWarehouse()
{
return _warehouse;
@@ -2334,26 +2298,126 @@ public class Clan
broadcastToOnlineMembers(new PledgeShowInfoUpdate(this));
}
- public void setAllyCrest(int crestId)
+ /**
+ * Change the clan crest. If crest id is 0, crest is removed. New crest id is saved to database.
+ * @param crestId if 0, crest is removed, else new crest id is set and saved to database
+ */
+ public void changeClanCrest(int crestId)
{
- try (Connection con = DatabaseFactory.getConnection())
+ if (_crestId != 0)
{
- setAllyCrestId(crestId);
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET ally_crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, crestId);
- statement.setInt(2, _clanId);
- statement.executeUpdate();
- statement.close();
+ CrestTable.getInstance().removeCrest(getCrestId());
+ }
+
+ setCrestId(crestId);
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
+ {
+ ps.setInt(1, crestId);
+ ps.setInt(2, _clanId);
+ ps.executeUpdate();
}
catch (SQLException e)
{
- LOGGER.warning("could not update the ally crest id:" + e.getMessage());
+ LOGGER.warning("Could not update crest for clan " + _name + " [" + _clanId + "] : " + e.getMessage());
+ }
+
+ for (PlayerInstance member : getOnlineMembers())
+ {
+ member.broadcastUserInfo();
+ }
+ }
+
+ /**
+ * Change the ally crest. If crest id is 0, crest is removed. New crest id is saved to database.
+ * @param crestId if 0, crest is removed, else new crest id is set and saved to database
+ * @param onlyThisClan
+ */
+ public void changeAllyCrest(int crestId, boolean onlyThisClan)
+ {
+ String sqlStatement = "UPDATE clan_data SET ally_crest_id = ? WHERE clan_id = ?";
+ int allyId = _clanId;
+ if (!onlyThisClan)
+ {
+ if (_allyCrestId != 0)
+ {
+ CrestTable.getInstance().removeCrest(getAllyCrestId());
+ }
+ sqlStatement = "UPDATE clan_data SET ally_crest_id = ? WHERE ally_id = ?";
+ allyId = _allyId;
+ }
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement ps = con.prepareStatement(sqlStatement))
+ {
+ ps.setInt(1, crestId);
+ ps.setInt(2, allyId);
+ ps.executeUpdate();
+ }
+ catch (SQLException e)
+ {
+ LOGGER.warning("Could not update ally crest for ally/clan id " + allyId + " : " + e.getMessage());
+ }
+
+ if (onlyThisClan)
+ {
+ setAllyCrestId(crestId);
+ for (PlayerInstance member : getOnlineMembers())
+ {
+ member.broadcastUserInfo();
+ }
+ }
+ else
+ {
+ for (Clan clan : ClanTable.getInstance().getClans())
+ {
+ if ((clan.getAllyId() == getAllyId()) && (clan.getClanId() != getClanId()))
+ {
+ clan.setAllyCrestId(crestId);
+ for (PlayerInstance member : clan.getOnlineMembers())
+ {
+ member.broadcastUserInfo();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Change the large crest. If crest id is 0, crest is removed. New crest id is saved to database.
+ * @param crestId if 0, crest is removed, else new crest id is set and saved to database
+ */
+ public void changeLargeCrest(int crestId)
+ {
+ if (_crestLargeId != 0)
+ {
+ CrestTable.getInstance().removeCrest(getCrestLargeId());
+ }
+
+ setCrestLargeId(crestId);
+
+ try (Connection con = DatabaseFactory.getConnection();
+ PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?"))
+ {
+ ps.setInt(1, crestId);
+ ps.setInt(2, _clanId);
+ ps.executeUpdate();
+ }
+ catch (SQLException e)
+ {
+ LOGGER.warning("Could not update large crest for clan " + _name + " [" + _clanId + "] : " + e.getMessage());
+ }
+
+ for (PlayerInstance member : getOnlineMembers())
+ {
+ member.broadcastUserInfo();
}
}
@Override
public String toString()
{
- return "Clan [_name=" + _name + ", _clanId=" + _clanId + ", _leader=" + _leader + ", _members=" + _members + ", _allyName=" + _allyName + ", _allyId=" + _allyId + ", _level=" + _level + ", _hasCastle=" + _castleId + ", _hasFort=" + _fortId + ", _hasHideout=" + _hideoutId + ", _hasCrest=" + _hasCrest + ", _hiredGuards=" + _hiredGuards + ", _crestId=" + _crestId + ", _crestLargeId=" + _crestLargeId + ", _allyCrestId=" + _allyCrestId + ", _auctionBiddedAt=" + _auctionBiddedAt + ", _allyPenaltyExpiryTime=" + _allyPenaltyExpiryTime + ", _allyPenaltyType=" + _allyPenaltyType + ", _charPenaltyExpiryTime=" + _charPenaltyExpiryTime + ", _dissolvingExpiryTime=" + _dissolvingExpiryTime + ", _warehouse=" + _warehouse + ", _atWarWith=" + _atWarWith + ", _atWarAttackers=" + _atWarAttackers + ", _hasCrestLarge=" + _hasCrestLarge + ", _forum=" + _forum + ", _skillList=" + _skillList + ", _notice=" + _notice + ", _noticeEnabled=" + _noticeEnabled + ", _skills=" + _skills + ", _privs=" + _privs + ", _subPledges=" + _subPledges + ", _reputationScore=" + _reputationScore + ", _rank=" + _rank + "]";
+ return "Clan [_name=" + _name + ", _clanId=" + _clanId + ", _leader=" + _leader + ", _members=" + _members + ", _allyName=" + _allyName + ", _allyId=" + _allyId + ", _level=" + _level + ", _hasCastle=" + _castleId + ", _hasFort=" + _fortId + ", _hasHideout=" + _hideoutId + ", _hiredGuards=" + _hiredGuards + ", _crestId=" + _crestId + ", _crestLargeId=" + _crestLargeId + ", _allyCrestId=" + _allyCrestId + ", _auctionBiddedAt=" + _auctionBiddedAt + ", _allyPenaltyExpiryTime=" + _allyPenaltyExpiryTime + ", _allyPenaltyType=" + _allyPenaltyType + ", _charPenaltyExpiryTime=" + _charPenaltyExpiryTime + ", _dissolvingExpiryTime=" + _dissolvingExpiryTime + ", _warehouse=" + _warehouse + ", _atWarWith=" + _atWarWith + ", _atWarAttackers=" + _atWarAttackers + ", _forum=" + _forum + ", _skillList=" + _skillList + ", _notice=" + _notice + ", _noticeEnabled=" + _noticeEnabled + ", _skills=" + _skills + ", _privs=" + _privs + ", _subPledges=" + _subPledges + ", _reputationScore=" + _reputationScore + ", _rank=" + _rank + "]";
}
}
\ No newline at end of file
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java
new file mode 100644
index 0000000000..7d5824a8b3
--- /dev/null
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/model/interfaces/IIdentifiable.java
@@ -0,0 +1,26 @@
+/*
+ * 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 .
+ */
+package org.l2jmobius.gameserver.model.interfaces;
+
+/**
+ * Identifiable objects interface.
+ * @author Zoey76
+ */
+public interface IIdentifiable
+{
+ int getId();
+}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/OutgoingPackets.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/OutgoingPackets.java
index 2bb8aef9cd..410663b645 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/OutgoingPackets.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/OutgoingPackets.java
@@ -150,7 +150,7 @@ public enum OutgoingPackets
MY_TARGET_SELECTED(0xA6),
PARTY_MEMBER_POSITION(0xA7),
ASK_JOIN_ALLY(0xA8),
- ALLY_CREST(0xAE),
+ ALLIANCE_CREST(0xAE),
PET_STATUS_SHOW(0xB0),
PET_INFO(0xB1),
PET_ITEM_LIST(0xB2),
@@ -239,7 +239,7 @@ public enum OutgoingPackets
EX_OPEN_MPCC(0xFE, 0x25),
EX_CLOSE_MPCC(0xFE, 0x26),
EX_ASK_JOIN_MPCC(0xFE, 0x27),
- EX_PLEDGE_CREST_LARGE(0xFE, 0x28),
+ EX_PLEDGE_EMBLEM(0xFE, 0x28),
EX_OLYMPIAD_USER_INFO(0xFE, 0x29),
EX_OLYMPIAD_SPELLED_INFO(0xFE, 0x2A),
EX_OLYMPIAD_MODE(0xFE, 0x2B),
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java
index 97bdaf7202..cb32febf8e 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyDismiss.java
@@ -94,8 +94,8 @@ public class AllyDismiss implements IClientIncomingPacket
clan.setAllyId(0);
clan.setAllyName(null);
+ clan.changeAllyCrest(0, true);
clan.setAllyPenaltyExpiryTime(currentTime + (Config.ALT_ALLY_JOIN_DAYS_WHEN_DISMISSED * 86400000), Clan.PENALTY_TYPE_CLAN_DISMISSED); // 24*60*60*1000 = 86400000
- clan.setAllyCrest(0);
clan.updateClanInDB();
player.sendPacket(SystemMessageId.YOU_HAVE_SUCCEEDED_IN_EXPELLING_A_CLAN);
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java
index 0fc2bb8b25..edbecf365e 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/AllyLeave.java
@@ -69,8 +69,8 @@ public class AllyLeave implements IClientIncomingPacket
final long currentTime = Chronos.currentTimeMillis();
clan.setAllyId(0);
clan.setAllyName(null);
+ clan.changeAllyCrest(0, true);
clan.setAllyPenaltyExpiryTime(currentTime + (Config.ALT_ALLY_JOIN_DAYS_WHEN_LEAVED * 86400000), Clan.PENALTY_TYPE_CLAN_LEAVED); // 24*60*60*1000 = 86400000
- clan.setAllyCrest(0);
clan.updateClanInDB();
player.sendPacket(SystemMessageId.YOU_HAVE_WITHDRAWN_FROM_THE_ALLIANCE);
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java
index c635ac9e8a..dfc8fbf470 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestAnswerJoinAlly.java
@@ -22,9 +22,6 @@ import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
-/**
- * sample 5F 01 00 00 00 format cdd
- */
public class RequestAnswerJoinAlly implements IClientIncomingPacket
{
private int _response;
@@ -70,10 +67,11 @@ public class RequestAnswerJoinAlly implements IClientIncomingPacket
// TODO: Need correct message id
requestor.sendPacket(SystemMessageId.YOU_HAVE_SUCCEEDED_IN_INVITING_A_FRIEND_TO_YOUR_FRIENDS_LIST);
player.sendPacket(SystemMessageId.YOU_HAVE_ACCEPTED_THE_ALLIANCE);
+
player.getClan().setAllyId(clan.getAllyId());
player.getClan().setAllyName(clan.getAllyName());
player.getClan().setAllyPenaltyExpiryTime(0, 0);
- player.getClan().setAllyCrest(clan.getAllyCrestId());
+ player.getClan().changeAllyCrest(clan.getAllyCrestId(), true);
player.getClan().updateClanInDB();
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java
index 9c9c5ee1f6..7e35c11822 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExPledgeCrestLarge.java
@@ -17,9 +17,8 @@
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.commons.network.PacketReader;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.network.GameClient;
-import org.l2jmobius.gameserver.network.serverpackets.ExPledgeCrestLarge;
+import org.l2jmobius.gameserver.network.serverpackets.ExPledgeEmblem;
/**
* Fomat : chd c: (id) 0xD0 h: (subid) 0x10 d: the crest id This is a trigger
@@ -39,10 +38,6 @@ public class RequestExPledgeCrestLarge implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
- final byte[] data = CrestCache.getInstance().getPledgeCrestLarge(_crestId);
- if (data != null)
- {
- client.sendPacket(new ExPledgeCrestLarge(_crestId, data));
- }
+ client.sendPacket(new ExPledgeEmblem(_crestId));
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java
index 92001fb795..130ab324b0 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestExSetPledgeCrestLarge.java
@@ -16,14 +16,11 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.network.PacketReader;
-import org.l2jmobius.gameserver.cache.CrestCache;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
+import org.l2jmobius.commons.util.Chronos;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
@@ -35,23 +32,19 @@ import org.l2jmobius.gameserver.network.SystemMessageId;
*/
public class RequestExSetPledgeCrestLarge implements IClientIncomingPacket
{
- private int _size;
- private byte[] _data;
+ private int _length;
+ private byte[] _data = null;
@Override
public boolean read(GameClient client, PacketReader packet)
{
- _size = packet.readD();
- if (_size > 2176)
+ _length = packet.readD();
+ if (_length > 2176)
{
return false;
}
- if (_size > 0) // client CAN send a RequestExSetPledgeCrestLarge with the size set to 0 then format is just chd
- {
- _data = packet.readB(_size);
- }
-
+ _data = packet.readB(_length);
return true;
}
@@ -70,68 +63,45 @@ public class RequestExSetPledgeCrestLarge implements IClientIncomingPacket
return;
}
- if (_data == null)
- {
- CrestCache.getInstance().removePledgeCrestLarge(clan.getCrestId());
-
- clan.setHasCrestLarge(false);
- player.sendMessage("The insignia has been removed.");
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
- }
-
- return;
- }
-
- if (_size > 2176)
+ if ((_length < 0) || (_length > 2176))
{
player.sendMessage("The insignia file size is greater than 2176 bytes.");
return;
}
- if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) == Clan.CP_CL_REGISTER_CREST)
+ if (clan.getDissolvingExpiryTime() > Chronos.currentTimeMillis())
{
- if ((clan.getCastleId() == 0) && (clan.getHideoutId() == 0))
+ player.sendPacket(SystemMessageId.DURING_THE_GRACE_PERIOD_FOR_DISSOLVING_A_CLAN_THE_REGISTRATION_OR_DELETION_OF_A_CLAN_S_CREST_IS_NOT_ALLOWED);
+ return;
+ }
+
+ if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) != Clan.CP_CL_REGISTER_CREST)
+ {
+ player.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
+ return;
+ }
+
+ if (_length == 0)
+ {
+ if (clan.getCrestLargeId() != 0)
{
- player.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
+ clan.changeLargeCrest(0);
+ player.sendPacket(SystemMessageId.THE_CLAN_S_CREST_HAS_BEEN_DELETED);
+ }
+ }
+ else
+ {
+ if (clan.getLevel() < 3)
+ {
+ player.sendPacket(SystemMessageId.A_CLAN_CREST_CAN_ONLY_BE_REGISTERED_WHEN_THE_CLAN_S_SKILL_LEVEL_IS_3_OR_ABOVE);
return;
}
- final CrestCache crestCache = CrestCache.getInstance();
- final int newId = IdManager.getInstance().getNextId();
- if (!crestCache.savePledgeCrestLarge(newId, _data))
+ final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.PLEDGE_LARGE);
+ if (crest != null)
{
- LOGGER.warning("Error loading large crest of clan:" + clan.getName());
- return;
- }
-
- if (clan.hasCrestLarge())
- {
- crestCache.removePledgeCrestLarge(clan.getCrestLargeId());
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final 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)
- {
- LOGGER.warning("could not update the large crest id:" + e.getMessage());
- }
-
- clan.setCrestLargeId(newId);
- clan.setHasCrestLarge(true);
-
- player.sendPacket(SystemMessageId.THE_CLAN_CREST_WAS_SUCCESSFULLY_REGISTERED_REMEMBER_ONLY_A_CLAN_THAT_OWNS_A_CLAN_HALL_OR_CASTLE_CAN_HAVE_THEIR_CREST_DISPLAYED);
-
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
+ clan.changeLargeCrest(crest.getId());
+ player.sendPacket(SystemMessageId.THE_CLAN_CREST_WAS_SUCCESSFULLY_REGISTERED_REMEMBER_ONLY_A_CLAN_THAT_OWNS_A_CLAN_HALL_OR_CASTLE_CAN_HAVE_THEIR_CREST_DISPLAYED);
}
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java
index f6b17550d0..fd38a5f9e1 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetAllyCrest.java
@@ -16,33 +16,32 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.network.PacketReader;
-import org.l2jmobius.gameserver.cache.CrestCache;
import org.l2jmobius.gameserver.data.sql.ClanTable;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
+import org.l2jmobius.gameserver.network.SystemMessageId;
+/**
+ * Client packet for setting ally crest.
+ */
public class RequestSetAllyCrest implements IClientIncomingPacket
{
private int _length;
- private byte[] _data;
+ private byte[] _data = null;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_length = packet.readD();
- if ((_length < 0) || (_length > 192))
+ if (_length > 192)
{
return false;
}
-
_data = packet.readB(_length);
return true;
}
@@ -64,54 +63,37 @@ public class RequestSetAllyCrest implements IClientIncomingPacket
if (_length > 192)
{
- player.sendMessage("The crest file size was too big (max 192 bytes).");
+ player.sendPacket(SystemMessageId.PLEASE_ADJUST_THE_IMAGE_SIZE_TO_8X12);
return;
}
- if (player.getAllyId() != 0)
+ if (player.getAllyId() == 0)
{
- final Clan leaderclan = ClanTable.getInstance().getClan(player.getAllyId());
- if ((player.getClanId() != leaderclan.getClanId()) || !player.isClanLeader())
+ player.sendPacket(SystemMessageId.THIS_FEATURE_IS_ONLY_AVAILABLE_ALLIANCE_LEADERS);
+ return;
+ }
+
+ final Clan leaderClan = ClanTable.getInstance().getClan(player.getAllyId());
+ if ((player.getClanId() != leaderClan.getClanId()) || !player.isClanLeader())
+ {
+ player.sendPacket(SystemMessageId.THIS_FEATURE_IS_ONLY_AVAILABLE_ALLIANCE_LEADERS);
+ return;
+ }
+
+ if (_length == 0)
+ {
+ if (leaderClan.getAllyCrestId() != 0)
{
- return;
+ leaderClan.changeAllyCrest(0, false);
}
-
- final CrestCache crestCache = CrestCache.getInstance();
- final int newId = IdManager.getInstance().getNextId();
- if (!crestCache.saveAllyCrest(newId, _data))
+ }
+ else
+ {
+ final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.ALLY);
+ if (crest != null)
{
- LOGGER.warning("Error loading crest of ally:" + leaderclan.getAllyName());
- return;
- }
-
- if (leaderclan.getAllyCrestId() != 0)
- {
- crestCache.removeAllyCrest(leaderclan.getAllyCrestId());
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET ally_crest_id = ? WHERE ally_id = ?");
- statement.setInt(1, newId);
- statement.setInt(2, leaderclan.getAllyId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("could not update the ally crest id:" + e.getMessage());
- }
-
- for (Clan clan : ClanTable.getInstance().getClans())
- {
- if (clan.getAllyId() == player.getAllyId())
- {
- clan.setAllyCrestId(newId);
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
- }
- }
+ leaderClan.changeAllyCrest(crest.getId(), false);
+ player.sendMessage("The crest was successfully registered.");
}
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java
index 7f836c7ee0..a7ea5d295d 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/clientpackets/RequestSetPledgeCrest.java
@@ -16,30 +16,29 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.commons.util.Chronos;
-import org.l2jmobius.gameserver.cache.CrestCache;
-import org.l2jmobius.gameserver.instancemanager.IdManager;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
+import org.l2jmobius.gameserver.model.Crest.CrestType;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.clan.Clan;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
+/**
+ * Client packet for setting/deleting clan crest.
+ */
public class RequestSetPledgeCrest implements IClientIncomingPacket
{
private int _length;
- private byte[] _data;
+ private byte[] _data = null;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_length = packet.readD();
- if ((_length < 0) || (_length > 256))
+ if (_length > 256)
{
return false;
}
@@ -57,6 +56,18 @@ public class RequestSetPledgeCrest implements IClientIncomingPacket
return;
}
+ if ((_length < 0))
+ {
+ player.sendMessage("File transfer error.");
+ return;
+ }
+
+ if (_length > 256)
+ {
+ player.sendMessage("The clan crest file size was too big (max 256 bytes).");
+ return;
+ }
+
final Clan clan = player.getClan();
if (clan == null)
{
@@ -69,46 +80,21 @@ public class RequestSetPledgeCrest implements IClientIncomingPacket
return;
}
- if (_length < 0)
+ if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) != Clan.CP_CL_REGISTER_CREST)
{
- player.sendMessage("File transfer error.");
+ player.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT);
return;
}
- if (_length > 256)
+ if (_length == 0)
{
- player.sendMessage("The clan crest file size was too big (max 256 bytes).");
- return;
+ if (clan.getCrestId() != 0)
+ {
+ clan.changeClanCrest(0);
+ player.sendPacket(SystemMessageId.THE_CLAN_S_CREST_HAS_BEEN_DELETED);
+ }
}
-
- if ((_length == 0) || (_data.length == 0))
- {
- CrestCache.getInstance().removePledgeCrest(clan.getCrestId());
-
- clan.setHasCrest(false);
- player.sendPacket(SystemMessageId.THE_CLAN_S_CREST_HAS_BEEN_DELETED);
-
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, 0);
- statement.setInt(2, clan.getClanId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("Could not update the crest id: " + e.getMessage());
- }
- return;
- }
-
- if ((player.getClanPrivileges() & Clan.CP_CL_REGISTER_CREST) == Clan.CP_CL_REGISTER_CREST)
+ else
{
if (clan.getLevel() < 3)
{
@@ -116,38 +102,11 @@ public class RequestSetPledgeCrest implements IClientIncomingPacket
return;
}
- final CrestCache crestCache = CrestCache.getInstance();
- final int newId = IdManager.getInstance().getNextId();
- if (clan.hasCrest())
+ final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.PLEDGE);
+ if (crest != null)
{
- crestCache.removePledgeCrest(newId);
- }
-
- if (!crestCache.savePledgeCrest(newId, _data))
- {
- LOGGER.warning("Error loading crest of clan:" + clan.getName());
- return;
- }
-
- try (Connection con = DatabaseFactory.getConnection())
- {
- final PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?");
- statement.setInt(1, newId);
- statement.setInt(2, clan.getClanId());
- statement.executeUpdate();
- statement.close();
- }
- catch (SQLException e)
- {
- LOGGER.warning("Could not update the crest id: " + e.getMessage());
- }
-
- clan.setCrestId(newId);
- clan.setHasCrest(true);
-
- for (PlayerInstance member : clan.getOnlineMembers())
- {
- member.broadcastUserInfo();
+ clan.changeClanCrest(crest.getId());
+ player.sendMessage("The crest was successfully registered.");
}
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java
index 05156dff5c..af7bf93f72 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/AllyCrest.java
@@ -17,20 +17,10 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.commons.network.PacketWriter;
-import org.l2jmobius.gameserver.cache.CrestCache;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
import org.l2jmobius.gameserver.network.OutgoingPackets;
-/**
- *
- * sample
- * 0000: c7 6d 06 00 00 36 05 00 00 42 4d 36 05 00 00 00 .m...6...BM6....
- * 0010: 00 00 00 36 04 00 00 28 00 00 00 10 00 00 00 10 ...6...(........
- * 0020: 00 00 00 01 00 08 00 00 00 00 00 00 01 00 00 c4 ................
- * 0030: ...
- * 0530: 10 91 00 00 00 60 9b d1 01 e4 6e ee 52 97 dd .....`....n.R..
- *
format dd x...x
- * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:39 $
- */
public class AllyCrest implements IClientOutgoingPacket
{
private final int _crestId;
@@ -39,13 +29,20 @@ public class AllyCrest implements IClientOutgoingPacket
public AllyCrest(int crestId)
{
_crestId = crestId;
- _data = CrestCache.getInstance().getAllyCrest(_crestId);
+ final Crest crest = CrestTable.getInstance().getCrest(crestId);
+ _data = crest != null ? crest.getData() : null;
+ }
+
+ public AllyCrest(int crestId, byte[] data)
+ {
+ _crestId = crestId;
+ _data = data;
}
@Override
public boolean write(PacketWriter packet)
{
- OutgoingPackets.ALLY_CREST.writeId(packet);
+ OutgoingPackets.ALLIANCE_CREST.writeId(packet);
packet.writeD(_crestId);
if (_data != null)
{
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeCrestLarge.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeEmblem.java
similarity index 63%
rename from L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeCrestLarge.java
rename to L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeEmblem.java
index 691633f5d7..023b5a0b41 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeCrestLarge.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/ExPledgeEmblem.java
@@ -17,18 +17,26 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.commons.network.PacketWriter;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
import org.l2jmobius.gameserver.network.OutgoingPackets;
/**
- * Format: (ch) ddd b d: ? d: crest ID d: crest size b: raw data
* @author -Wooden-
*/
-public class ExPledgeCrestLarge implements IClientOutgoingPacket
+public class ExPledgeEmblem implements IClientOutgoingPacket
{
private final int _crestId;
private final byte[] _data;
- public ExPledgeCrestLarge(int crestId, byte[] data)
+ public ExPledgeEmblem(int crestId)
+ {
+ _crestId = crestId;
+ final Crest crest = CrestTable.getInstance().getCrest(crestId);
+ _data = crest != null ? crest.getData() : null;
+ }
+
+ public ExPledgeEmblem(int crestId, byte[] data)
{
_crestId = crestId;
_data = data;
@@ -37,13 +45,18 @@ public class ExPledgeCrestLarge implements IClientOutgoingPacket
@Override
public boolean write(PacketWriter packet)
{
- OutgoingPackets.EX_PLEDGE_CREST_LARGE.writeId(packet);
-
- packet.writeD(0x00); // ???
+ OutgoingPackets.EX_PLEDGE_EMBLEM.writeId(packet);
+ packet.writeD(0x00);
packet.writeD(_crestId);
- packet.writeD(_data.length);
-
- packet.writeB(_data);
+ if (_data != null)
+ {
+ packet.writeD(_data.length);
+ packet.writeB(_data);
+ }
+ else
+ {
+ packet.writeD(0);
+ }
return true;
}
}
diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java
index b761558b68..5b93dca07b 100644
--- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java
+++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/gameserver/network/serverpackets/PledgeCrest.java
@@ -17,14 +17,10 @@
package org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.commons.network.PacketWriter;
-import org.l2jmobius.gameserver.cache.CrestCache;
+import org.l2jmobius.gameserver.data.sql.CrestTable;
+import org.l2jmobius.gameserver.model.Crest;
import org.l2jmobius.gameserver.network.OutgoingPackets;
-/**
- * sample 0000: 84 6d 06 00 00 36 05 00 00 42 4d 36 05 00 00 00 .m...6...BM6.... 0010: 00 00 00 36 04 00 00 28 00 00 00 10 00 00 00 10 ...6...(........ 0020: 00 00 00 01 00 08 00 00 00 00 00 00 01 00 00 c4 ................ 0030: ... 0530: 10 91 00 00 00 60 9b d1 01 e4 6e ee 52 97 dd .....`....n.R..
- * format dd x...x
- * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:57 $
- */
public class PledgeCrest implements IClientOutgoingPacket
{
private final int _crestId;
@@ -33,7 +29,14 @@ public class PledgeCrest implements IClientOutgoingPacket
public PledgeCrest(int crestId)
{
_crestId = crestId;
- _data = CrestCache.getInstance().getPledgeCrest(_crestId);
+ final Crest crest = CrestTable.getInstance().getCrest(crestId);
+ _data = crest != null ? crest.getData() : null;
+ }
+
+ public PledgeCrest(int crestId, byte[] data)
+ {
+ _crestId = crestId;
+ _data = data;
}
@Override