- Addition of Faction Manager.

- Prohibit sending mails in opposite faction.
This commit is contained in:
mobius 2015-01-26 18:24:32 +00:00
parent c71cc1c5a3
commit 49e5ae022e
3 changed files with 139 additions and 0 deletions

View File

@ -107,6 +107,7 @@ import com.l2jserver.gameserver.instancemanager.ClanHallManager;
import com.l2jserver.gameserver.instancemanager.CoupleManager;
import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager;
import com.l2jserver.gameserver.instancemanager.FactionManager;
import com.l2jserver.gameserver.instancemanager.FishingChampionshipManager;
import com.l2jserver.gameserver.instancemanager.FortManager;
import com.l2jserver.gameserver.instancemanager.FortSiegeManager;
@ -257,6 +258,11 @@ public class GameServer
CharSummonTable.getInstance().init();
BeautyShopData.getInstance();
MentorManager.getInstance();
if (Config.FACTION_SYSTEM_ENABLED)
{
_log.info("FactionTable: Faction system is enabled.");
FactionManager.getInstance();
}
if (Config.PREMIUM_SYSTEM_ENABLED)
{
_log.info("PremiumManager: Premium system is enabled.");

View File

@ -0,0 +1,126 @@
/*
* Copyright (C) 2004-2015 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
/**
* Contains objectId and factionId for all players.
* @author Mobius
*/
public class FactionManager
{
private static Logger _log = Logger.getLogger(FactionManager.class.getName());
private final Map<Integer, Integer> _playerFactions = new ConcurrentHashMap<>();
protected FactionManager()
{
loadAll();
}
private void loadAll()
{
_playerFactions.clear();
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT charId, faction FROM characters"))
{
while (rs.next())
{
final int id = rs.getInt(1);
_playerFactions.put(id, rs.getInt(4));
}
}
catch (SQLException e)
{
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not load character faction information: " + e.getMessage(), e);
}
_log.info(getClass().getSimpleName() + ": Loaded " + _playerFactions.size() + " char faction values.");
}
public final int getFactionByCharId(int id)
{
if (id <= 0)
{
return 0;
}
Integer factionId = _playerFactions.get(id);
if (factionId != null)
{
return factionId;
}
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT faction FROM characters WHERE charId=?"))
{
ps.setInt(1, id);
try (ResultSet rset = ps.executeQuery())
{
if (rset.next())
{
factionId = rset.getInt(1);
_playerFactions.put(id, factionId);
return factionId;
}
}
}
catch (SQLException e)
{
_log.log(Level.WARNING, getClass().getSimpleName() + ": Could not check existing char id: " + e.getMessage(), e);
}
return 0; // not found
}
public final boolean isSameFaction(L2PcInstance player1, L2PcInstance player2)
{
// TODO: Maybe add support for multiple factions?
// if (getFactionByCharId(player1.getId()) == getFactionByCharId(player2.getId()))
// {
// return true;
// }
if ((player1.isGood() && player2.isGood()) || (player1.isEvil() && player2.isEvil()))
{
return true;
}
return false;
}
public static FactionManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final FactionManager _instance = new FactionManager();
}
}

View File

@ -25,6 +25,7 @@ import com.l2jserver.Config;
import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
import com.l2jserver.gameserver.data.xml.impl.AdminData;
import com.l2jserver.gameserver.enums.PrivateStoreType;
import com.l2jserver.gameserver.instancemanager.FactionManager;
import com.l2jserver.gameserver.instancemanager.MailManager;
import com.l2jserver.gameserver.model.BlockList;
import com.l2jserver.gameserver.model.L2AccessLevel;
@ -249,6 +250,12 @@ public final class RequestSendPost extends L2GameClientPacket
return;
}
if (Config.FACTION_SYSTEM_ENABLED && (FactionManager.getInstance().getFactionByCharId(activeChar.getObjectId()) != FactionManager.getInstance().getFactionByCharId(receiverId)))
{
activeChar.sendMessage("You cannot send mails to the opposing faction.");
return;
}
if (!getClient().getFloodProtectors().getSendMail().tryPerformAction("sendmail"))
{
activeChar.sendPacket(SystemMessageId.THE_PREVIOUS_MAIL_WAS_FORWARDED_LESS_THAN_1_MINUTE_AGO_AND_THIS_CANNOT_BE_FORWARDED);