Moved crest data to SQL.

This commit is contained in:
MobiusDevelopment 2021-05-29 01:04:55 +00:00
parent 24e82859ca
commit 22db860d42
44 changed files with 1322 additions and 1400 deletions

View File

@ -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;

View File

@ -51,9 +51,8 @@
<admin command="admin_cache_htm_reload" accessLevel="100" /> <!-- reload all htmls cache -->
<admin command="admin_cache_reload_path" accessLevel="100" /> <!-- reload just 1 html path -->
<admin command="admin_cache_reload_file" accessLevel="100" /> <!-- reload just 1 html file -->
<admin command="admin_cache_crest_rebuild" accessLevel="100" /> <!-- CrestCache.getInstance().reload(); -->
<admin command="admin_cache_crest_reload" accessLevel="100" /> <!-- CrestCache.getInstance().reload(); -->
<admin command="admin_cache_crest_fix" accessLevel="100" /> <!-- CrestCache.getInstance().convertOldPedgeFiles(); -->
<admin command="admin_cache_crest_rebuild" accessLevel="100" /> <!-- CrestTable.getInstance().load() -->
<admin command="admin_cache_crest_reload" accessLevel="100" /> <!-- CrestTable.getInstance().load() -->
<!-- Section: ChangeLevel -->
<admin command="admin_changelvl" accessLevel="90" />

View File

@ -19,12 +19,12 @@
<td><button value="Reload CW" action="bypass -h admin_cw_reload" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Reload Zone" action="bypass -h admin_zone_reload" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Reload Crest" action="bypass -h admin_cache_crest_rebuild" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Crest Fix" action="bypass -h admin_cache_crest_fix" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
</tr><tr>
<td><button value="Reload Tele" action="bypass -h admin_teleport_reload" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
</tr><tr>
<td><button value="Open All" action="bypass -h admin_openall" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Close All" action="bypass -h admin_closeall" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Zone Check" action="bypass -h admin_zone_check" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td></td>
</tr>
</table>
<font color="aadd77">Geodata</font>

View File

@ -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");

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Integer, byte[]> _cachePledge = new HashMap<>();
private final Map<Integer, byte[]> _cachePledgeLarge = new HashMap<>();
private final Map<Integer, byte[]> _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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Integer, Crest> _crests = new ConcurrentHashMap<>();
private final AtomicInteger _nextId = new AtomicInteger(1);
protected CrestTable()
{
load();
}
public synchronized void load()
{
_crests.clear();
final Set<Integer> 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();
}
}

View File

@ -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:

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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();
}

View File

@ -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<Integer> _atWarWith = new ArrayList<>();
private final List<Integer> _atWarAttackers = new ArrayList<>();
private boolean _hasCrestLarge;
private Forum _forum;
private final List<Skill> _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 + "]";
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.model.interfaces;
/**
* Identifiable objects interface.
* @author Zoey76
*/
public interface IIdentifiable
{
int getId();
}

View File

@ -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),

View File

@ -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);

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}
}

View File

@ -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())
{
return;
}
player.sendPacket(SystemMessageId.THIS_FEATURE_IS_ONLY_AVAILABLE_ALLIANCE_LEADERS);
return;
}
final CrestCache crestCache = CrestCache.getInstance();
final int newId = IdManager.getInstance().getNextId();
if (!crestCache.saveAllyCrest(newId, _data))
{
LOGGER.warning("Error loading crest of ally:" + leaderclan.getAllyName());
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 (leaderclan.getAllyCrestId() != 0)
if (_length == 0)
{
if (leaderClan.getAllyCrestId() != 0)
{
crestCache.removeAllyCrest(leaderclan.getAllyCrestId());
leaderClan.changeAllyCrest(0, false);
}
try (Connection con = DatabaseFactory.getConnection())
}
else
{
final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.ALLY);
if (crest != null)
{
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.");
}
}
}

View File

@ -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.");
}
}
}

View File

@ -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;
/**
* <code>
* 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..
* </code> 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)
{

View File

@ -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;
}
}

View File

@ -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

View File

@ -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;

View File

@ -51,9 +51,8 @@
<admin command="admin_cache_htm_reload" accessLevel="100" /> <!-- reload all htmls cache -->
<admin command="admin_cache_reload_path" accessLevel="100" /> <!-- reload just 1 html path -->
<admin command="admin_cache_reload_file" accessLevel="100" /> <!-- reload just 1 html file -->
<admin command="admin_cache_crest_rebuild" accessLevel="100" /> <!-- CrestCache.getInstance().reload(); -->
<admin command="admin_cache_crest_reload" accessLevel="100" /> <!-- CrestCache.getInstance().reload(); -->
<admin command="admin_cache_crest_fix" accessLevel="100" /> <!-- CrestCache.getInstance().convertOldPedgeFiles(); -->
<admin command="admin_cache_crest_rebuild" accessLevel="100" /> <!-- CrestTable.getInstance().load() -->
<admin command="admin_cache_crest_reload" accessLevel="100" /> <!-- CrestTable.getInstance().load() -->
<!-- Section: ChangeLevel -->
<admin command="admin_changelvl" accessLevel="90" />

View File

@ -19,12 +19,12 @@
<td><button value="Reload CW" action="bypass -h admin_cw_reload" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Reload Zone" action="bypass -h admin_zone_reload" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Reload Crest" action="bypass -h admin_cache_crest_rebuild" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Crest Fix" action="bypass -h admin_cache_crest_fix" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
</tr><tr>
<td><button value="Reload Tele" action="bypass -h admin_teleport_reload" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
</tr><tr>
<td><button value="Open All" action="bypass -h admin_openall" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Close All" action="bypass -h admin_closeall" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td><button value="Zone Check" action="bypass -h admin_zone_check" width=60 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
<td></td>
</tr>
</table>
<font color="aadd77">Geodata</font>

View File

@ -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");

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Integer, byte[]> _cachePledge = new HashMap<>();
private final Map<Integer, byte[]> _cachePledgeLarge = new HashMap<>();
private final Map<Integer, byte[]> _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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<Integer, Crest> _crests = new ConcurrentHashMap<>();
private final AtomicInteger _nextId = new AtomicInteger(1);
protected CrestTable()
{
load();
}
public synchronized void load()
{
_crests.clear();
final Set<Integer> 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();
}
}

View File

@ -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:

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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();
}

View File

@ -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<Integer> _atWarWith = new ArrayList<>();
private final List<Integer> _atWarAttackers = new ArrayList<>();
private boolean _hasCrestLarge;
private Forum _forum;
private final List<Skill> _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 + "]";
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.model.interfaces;
/**
* Identifiable objects interface.
* @author Zoey76
*/
public interface IIdentifiable
{
int getId();
}

View File

@ -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),

View File

@ -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);

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}
}

View File

@ -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())
{
return;
}
player.sendPacket(SystemMessageId.THIS_FEATURE_IS_ONLY_AVAILABLE_ALLIANCE_LEADERS);
return;
}
final CrestCache crestCache = CrestCache.getInstance();
final int newId = IdManager.getInstance().getNextId();
if (!crestCache.saveAllyCrest(newId, _data))
{
LOGGER.warning("Error loading crest of ally:" + leaderclan.getAllyName());
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 (leaderclan.getAllyCrestId() != 0)
if (_length == 0)
{
if (leaderClan.getAllyCrestId() != 0)
{
crestCache.removeAllyCrest(leaderclan.getAllyCrestId());
leaderClan.changeAllyCrest(0, false);
}
try (Connection con = DatabaseFactory.getConnection())
}
else
{
final Crest crest = CrestTable.getInstance().createCrest(_data, CrestType.ALLY);
if (crest != null)
{
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.");
}
}
}

View File

@ -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.");
}
}
}

View File

@ -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;
/**
* <code>
* 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..
* </code> 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)
{

View File

@ -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;
}
}

View File

@ -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