возникла проблема в сборке first-team
входе добавление в бан какого либо hwid,
абсолютно все чары кикаются из игры. (естественно зайти за них обратно также не получается)
Если кто то решил у себя данную проблему, прошу помочь.
входе добавление в бан какого либо hwid,
абсолютно все чары кикаются из игры. (естественно зайти за них обратно также не получается)
2
Цитата:package l2ft.gameserver.utils;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import javolution.util.FastMap;
import l2ft.commons.dbutils.DbUtils;
import ftGuard.ftConfig;
import l2ft.gameserver.database.DatabaseFactory;
import l2ft.gameserver.database.mysql;
import l2ft.gameserver.model.GameObjectsStorage;
import l2ft.gameserver.model.Player;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HWID
{
private static final Logger _log = LoggerFactory.getLogger(HWID.class);
private static final GArray<HardwareID> banned_hwids = new GArray<HardwareID>();
private static final GSArray<Entry<HardwareID, FastMap<String, Integer>>> bonus_hwids = new GSArray<Entry<HardwareID, FastMap<String, Integer>>>();
public static final HWIDComparator DefaultComparator = new HWIDComparator();
public static final HWIDComparator BAN_Comparator = new HWIDComparator();
public static final String SELECT_HWID = "SELECT HWID FROM " + ftConfig.HWID_BANS_TABLE;
public static final String REPLACE_HWID = "REPLACE INTO " + ftConfig.HWID_BANS_TABLE + " (hwid,comments) VALUES (?,?)";
public static final String DELETE_HWID = "DELETE FROM " + ftConfig.HWID_BANS_TABLE + " WHERE hwid=?";
public static void reloadBannedHWIDs()
{
synchronized (banned_hwids)
{
banned_hwids.clear();
}
Connection con = null;
PreparedStatement st = null;
ResultSet rs = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
st = con.prepareStatement(SELECT_HWID);
rs = st.executeQuery();
synchronized (banned_hwids)
{
while (rs.next())
banned_hwids.add(new HardwareID(rs.getString("HWID")));
}
_log.info("Protection: Loaded " + banned_hwids.size() + " banned HWIDs");
}
catch(final Exception e)
{
_log.warn("Protection: Failed to load banned HWIDs", e);
}
finally
{
DbUtils.closeQuietly(con, st, rs);
}
}
public static boolean checkHWIDBanned(final HardwareID hwid)
{
synchronized (banned_hwids)
{
return hwid != null && BAN_Comparator.contains(hwid, banned_hwids);
}
}
public static String handleBanHWID(final String[] argv)
{
if(!ftConfig.ALLOW_GUARD_SYSTEM || !ftConfig.PROTECT_GS_ENABLE_HWID_BANS)
return "HWID bans feature disabled";
if(argv == null || argv.length < 2)
return "USAGE: banhwid char_name|hwid [kick:true|false] [reason]";
String hwid = argv[1]; // либо HWID, либо имя чара
if(hwid.length() != 32)
{
final Player player = GameObjectsStorage.getPlayer(hwid);
if(player == null)
return "Player " + hwid + " not found in world";
if(!player.hasHWID())
return "Player " + hwid + " not connected (offline trade)";
hwid = player.getHWID().Full;
}
if(argv.length == 2)
BanHWID(hwid, "", true);
else
{
boolean kick = true;
String reason = "";
if(argv[2].equalsIgnoreCase("true") || argv[2].equalsIgnoreCase("false"))
{
kick = Boolean.parseBoolean(argv[2]);
if(argv.length > 3)
{
for(int i = 3; i < argv.length; i++)
reason += argv[i] + " ";
reason = reason.trim();
}
}
// значит комменты
else
{
for(int i = 2; i < argv.length; i++)
reason += argv[i] + " ";
reason = reason.trim();
}
BanHWID(hwid, reason, kick);
}
return "HWID " + hwid + " banned";
}
public static boolean BanHWID(final String hwid, final String comment)
{
return BanHWID(hwid, comment, false);
}
public static boolean BanHWID(final String hwid, final String comment, final boolean kick)
{
if(!ftConfig.ALLOW_GUARD_SYSTEM || !ftConfig.PROTECT_GS_ENABLE_HWID_BANS || hwid == null || hwid.isEmpty())
return false;
return BanHWID(new HardwareID(hwid), comment, kick);
}
public static boolean BanHWID(final HardwareID hwid, final String comment, final boolean kick)
{
if(!ftConfig.ALLOW_GUARD_SYSTEM || !ftConfig.PROTECT_GS_ENABLE_HWID_BANS || hwid == null)
return false;
if(checkHWIDBanned(hwid))
{
_log.info("Protection: HWID: " + hwid + " already banned");
return true;
}
Connection con = null;
PreparedStatement st = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
st = con.prepareStatement(REPLACE_HWID);
st.setString(1, hwid.Full);
st.setString(2, comment);
st.execute();
synchronized (banned_hwids)
{
banned_hwids.add(hwid);
}
Log.add("Banned HWID: " + hwid, "protect");
if(kick)
for(final Player cha : getPlayersByHWID(hwid))
cha.logout();
}
catch(final Exception e)
{
_log.warn("Protection: Failed to ban HWID: " + hwid, e);
}
finally
{
DbUtils.closeQuietly(con, st);
}
return checkHWIDBanned(hwid);
}
public static boolean UnbanHWID(final String hwid)
{
if(!ftConfig.ALLOW_GUARD_SYSTEM || !ftConfig.PROTECT_GS_ENABLE_HWID_BANS || hwid == null || hwid.isEmpty())
return false;
return UnbanHWID(new HardwareID(hwid));
}
public static boolean UnbanHWID(final HardwareID hwid)
{
if(!ftConfig.ALLOW_GUARD_SYSTEM || !ftConfig.PROTECT_GS_ENABLE_HWID_BANS || hwid == null)
return false;
if(!checkHWIDBanned(hwid))
{
_log.info("Protection: HWID: " + hwid + " already not banned");
return true;
}
Connection con = null;
PreparedStatement st = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
st = con.prepareStatement(DELETE_HWID);
st.setString(1, hwid.Full);
st.execute();
synchronized (banned_hwids)
{
BAN_Comparator.remove(hwid, banned_hwids);
}
Log.add("Unbanned HWID: " + hwid, "protect");
}
catch(final Exception e)
{
_log.warn("Protection: Failed to unban HWID: " + hwid, e);
}
finally
{
DbUtils.closeQuietly(con, st);
}
return !checkHWIDBanned(hwid);
}
public static GArray<Player> getPlayersByHWID(final HardwareID hwid)
{
final GArray<Player> result = new GArray<Player>();
if(hwid != null)
for(final Player cha : GameObjectsStorage.getAllPlayers())
if(!cha.isInOfflineMode() && cha.getNetConnection() != null && cha.getNetConnection().protect_used && hwid.equals(cha.getHWID()))
result.add(cha);
return result;
}
/**
* Возвращает список всех HWID, кторые попадают под условия компаратора.
*/
public static GArray<Entry<HardwareID, FastMap<String, Integer>>> getAllMatches(final HardwareID hwid, final HWIDComparator comparator)
{
final GArray<Entry<HardwareID, FastMap<String, Integer>>> ret = new GArray<Entry<HardwareID, FastMap<String, Integer>>>();
synchronized (bonus_hwids)
{
for(final Entry<HardwareID, FastMap<String, Integer>> entry : bonus_hwids)
if(comparator.compare(entry.getKey(), hwid) == HWIDComparator.EQUALS)
ret.add(entry);
}
return ret;
}
public static class HardwareID
{
public final String Full;
public HardwareID(final String s)
{
Full = s;
}
@Override
public int hashCode()
{
return Full.hashCode();
}
@Override
public boolean equals(final Object obj)
{
if(obj == null || !(obj instanceof HardwareID))
return false;
return DefaultComparator.compare(this, (HardwareID) obj) == HWIDComparator.EQUALS;
}
@Override
public String toString()
{
return String.format("%s", Full);
}
}
public static class HWIDComparator implements Comparator<HardwareID>
{
public static final int EQUALS = 0;
public static final int NOT_EQUALS = 1;
public HWIDComparator()
{}
@Override
public int compare(final HardwareID o1, final HardwareID o2)
{
if(o1 == null || o2 == null)
return o1 == o2 ? EQUALS : NOT_EQUALS;
return EQUALS;
}
public int find(final HardwareID hwid, final List<HardwareID> in)
{
for(int i = 0; i < in.size(); i++)
if(compare(hwid, in.get(i)) == EQUALS)
return i;
return -1;
}
public boolean contains(final HardwareID hwid, final List<HardwareID> in)
{
return find(hwid, in) != -1;
}
public boolean remove(final HardwareID hwid, final List<HardwareID> in)
{
final int i = find(hwid, in);
return i == -1 ? false : in.remove(i) != null;
}
public int find(final HardwareID hwid, final GArray<HardwareID> in)
{
for(int i = 0; i < in.size(); i++)
if(compare(hwid, in.get(i)) == EQUALS)
return i;
return -1;
}
public boolean contains(final HardwareID hwid, final GArray<HardwareID> in)
{
return find(hwid, in) != -1;
}
public boolean remove(final HardwareID hwid, final GArray<HardwareID> in)
{
final int i = find(hwid, in);
return i == -1 ? false : in.remove(i) != null;
}
@Override
public String toString()
{
return "HWIDComparator";
}
}
private static final class Entry<K, V> implements Map.Entry<K, V>
{
private final K _key;
private V _value;
public Entry(final K key, final V value)
{
_key = key;
_value = value;
}
@Override
public K getKey()
{
return _key;
}
@Override
public V getValue()
{
return _value;
}
@Override
public V setValue(final V value)
{
return _value = value;
}
}
}
2
Цитата:package l2ft.gameserver.network.l2;
import java.nio.ByteBuffer;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.io.IOException;
import l2ft.commons.dbutils.DbUtils;
import l2ft.commons.net.nio.impl.MMOClient;
import l2ft.commons.net.nio.impl.MMOConnection;
import l2ft.gameserver.Config;
import l2ft.gameserver.dao.AccountPointsDAO;
import l2ft.gameserver.dao.CharacterDAO;
import l2ft.gameserver.database.DatabaseFactory;
import l2ft.gameserver.model.CharSelectInfoPackage;
import l2ft.gameserver.model.GameObjectsStorage;
import l2ft.gameserver.model.Player;
import l2ft.gameserver.network.authcomm.AuthServerCommunication;
import l2ft.gameserver.network.authcomm.SessionKey;
import l2ft.gameserver.network.authcomm.gspackets.PlayerLogout;
import l2ft.gameserver.network.l2.components.SystemMsg;
import l2ft.gameserver.network.l2.s2c.L2GameServerPacket;
import l2ft.gameserver.network.security.SecondaryPasswordAuth;
import l2ft.gameserver.utils.HWID;
import l2ft.gameserver.utils.HWID.HardwareID;
import ftGuard.ftGuard;
import ftGuard.ftConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class GameClient extends MMOClient<MMOConnection<GameClient>>
{
private static final Logger _log = LoggerFactory.getLogger(GameClient.class);
private static final String NO_IP = "?.?.?.?";
private SecondaryPasswordAuth _secondaryAuth;
public static boolean SESSION_OK = MMOClient.SESSION_OK;
public HardwareID HWIDS = null, ALLOW_HWID = null;
public boolean protect_used = false;
public GameCrypt _crypt = null;
public GameClientState _state;
public static enum GameClientState
{
CONNECTED,
AUTHED,
IN_GAME,
DISCONNECTED
}
/** Данные аккаунта */
private String _login;
private double _bonus = 1.0;
private int _bonusExpire;
private Player _activeChar;
private SessionKey _sessionKey;
private String _ip = NO_IP;
private int revision = 0;
private boolean _gameGuardOk = false;
//private SecondaryPasswordAuth _secondaryAuth;
private List<Integer> _charSlotMapping = new ArrayList<Integer>();
public GameClient(MMOConnection<GameClient> con)
{
super(con);
if(ftGuard.isProtectionOn())
protect_used = !ftConfig.PROTECT_UNPROTECTED_IPS.isIpInNets(getIpAddr());
_state = GameClientState.CONNECTED;
_crypt = new GameCrypt();
_ip = con.getSocket().getInetAddress().getHostAddress();
}
@Override
protected void onDisconnection()
{
final Player player;
setState(GameClientState.DISCONNECTED);
player = getActiveChar();
setActiveChar(null);
if(player != null)
{
player.setNetConnection(null);
player.logout();
}
if(getSessionKey() != null)
{
if(isAuthed())
{
AuthServerCommunication.getInstance().removeAuthedClient(getLogin());
AuthServerCommunication.getInstance().sendPacket(new PlayerLogout(getLogin()));
}
else
{
AuthServerCommunication.getInstance().removeWaitingClient(getLogin());
}
}
}
@Override
protected void onForcedDisconnection()
{
// TODO Auto-generated method stub
}
public void markRestoredChar(int charslot) throws Exception
{
int objid = getObjectIdForSlot(charslot);
if(objid < 0)
return;
if(_activeChar != null && _activeChar.getObjectId() == objid)
_activeChar.setDeleteTimer(0);
Connection con = null;
PreparedStatement statement = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE characters SET deletetime=0 WHERE obj_id=?");
statement.setInt(1, objid);
statement.execute();
}
catch(Exception e)
{
_log.error("", e);
}
finally
{
DbUtils.closeQuietly(con, statement);
}
}
public void markToDeleteChar(int charslot) throws Exception
{
int objid = getObjectIdForSlot(charslot);
if(objid < 0)
return;
if(_activeChar != null && _activeChar.getObjectId() == objid)
_activeChar.setDeleteTimer((int) (System.currentTimeMillis() / 1000));
Connection con = null;
PreparedStatement statement = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE characters SET deletetime=? WHERE obj_id=?");
statement.setLong(1, (int) (System.currentTimeMillis() / 1000L));
statement.setInt(2, objid);
statement.execute();
}
catch(Exception e)
{
_log.error("data error on update deletime char:", e);
}
finally
{
DbUtils.closeQuietly(con, statement);
}
}
public void deleteChar(int charslot) throws Exception
{
//have to make sure active character must be nulled
if(_activeChar != null)
return;
int objid = getObjectIdForSlot(charslot);
if(objid == -1)
return;
CharacterDAO.getInstance().deleteCharByObjId(objid);
}
public Player loadCharFromDisk(int charslot)
{
int objectId = getObjectIdForSlot(charslot);
if(objectId == -1)
return null;
Player character = null;
Player oldPlayer = GameObjectsStorage.getPlayer(objectId);
if(oldPlayer != null)
if(oldPlayer.isInOfflineMode() || oldPlayer.isLogoutStarted())
{
// оффтрейдового чара проще выбить чем восстанавливать
oldPlayer.kick();
return null;
}
else
{
oldPlayer.sendPacket(SystemMsg.ANOTHER_PERSON_HAS_LOGGED_IN_WITH_THE_SAME_ACCOUNT);
GameClient oldClient = oldPlayer.getNetConnection();
if(oldClient != null)
{
oldClient.setActiveChar(null);
oldClient.closeNow(false);
}
oldPlayer.setNetConnection(this);
character = oldPlayer;
}
if(character == null)
character = Player.restore(objectId);
if(character != null)
setActiveChar(character);
else
_log.warn("could not restore obj_id: " + objectId + " in slot:" + charslot);
if(checkHWIDBanned())
character.logout();
if(protect_used && ftConfig.PROTECT_GS_STORE_HWID && hasHWID())
character.storeHWID(HWIDS.Full);
return character;
}
public int getObjectIdForSlot(int charslot)
{
if(charslot < 0 || charslot >= _charSlotMapping.size())
{
_log.warn(getLogin() + " tried to modify Character in slot " + charslot + " but no characters exits at that slot.");
return -1;
}
return _charSlotMapping.get(charslot);
}
public Player getActiveChar()
{
return _activeChar;
}
/**
* @return Returns the sessionId.
*/
public SessionKey getSessionKey()
{
return _sessionKey;
}
public String getLogin()
{
return _login;
}
public void setLoginName(String loginName)
{
_login = loginName;
if(protect_used && ftConfig.PROTECT_GS_LOG_HWID && !getIpAddr().equalsIgnoreCase("Disconnected"))
logHWID();
if (Config.SECOND_AUTH_ENABLED)
_secondaryAuth = new SecondaryPasswordAuth(this);
}
public void setActiveChar(Player player)
{
_activeChar = player;
if(player != null)
player.setNetConnection(this);
}
public void setSessionId(SessionKey sessionKey)
{
_sessionKey = sessionKey;
}
public void setCharSelection(CharSelectInfoPackage[] chars)
{
_charSlotMapping.clear();
for(CharSelectInfoPackage element : chars)
{
int objectId = element.getObjectId();
_charSlotMapping.add(objectId);
}
}
public void setCharSelection(int c)
{
_charSlotMapping.clear();
_charSlotMapping.add©;
}
public int getRevision()
{
return revision;
}
public void setRevision(int revision)
{
this.revision = revision;
}
@Override
public boolean encrypt(final ByteBuffer buf, final int size)
{
_crypt.encrypt(buf.array(), buf.position(), size);
buf.position(buf.position() + size);
return true;
}
@Override
public boolean decrypt(ByteBuffer buf, int size)
{
boolean ret = _crypt.decrypt(buf.array(), buf.position(), size);
return ret;
}
public void sendPacket(L2GameServerPacket gsp)
{
if(isConnected())
getConnection().sendPacket(gsp);
}
public void sendPacket(L2GameServerPacket... gsp)
{
if(isConnected())
getConnection().sendPacket(gsp);
}
public void sendPackets(List<L2GameServerPacket> gsp)
{
if(isConnected())
getConnection().sendPackets(gsp);
}
public void close(L2GameServerPacket gsp)
{
if(isConnected())
getConnection().close(gsp);
}
public String getIpAddr()
{
return _ip;
}
public byte[] enableCrypt()
{
byte[] key = BlowFishKeygen.getRandomKey();
_crypt.setKey(key);
if(ftGuard.isProtectionOn())
key = ftGuard.getKey(key);
return key;
}
public double getBonus()
{
return _bonus;
}
public int getBonusExpire()
{
return _bonusExpire;
}
public void setBonus(double bonus)
{
_bonus = bonus;
}
public void setBonusExpire(int bonusExpire)
{
_bonusExpire = bonusExpire;
}
public int getPointG()
{
return AccountPointsDAO.getInstance().getPoint(getLogin());
}
public void setPointG(int point)
{
AccountPointsDAO.getInstance().setPoint(getLogin(), point);
}
public GameClientState getState()
{
return _state;
}
public void setState(GameClientState state)
{
_state = state;
}
private int _failedPackets = 0;
private int _unknownPackets = 0;
public void onPacketReadFail()
{
if(_failedPackets++ >= 10)
{
_log.warn("Too many client packet fails, connection closed : " + this);
closeNow(true);
}
}
public void onUnknownPacket()
{
if(_unknownPackets++ >= 10)
{
_log.warn("Too many client unknown packets, connection closed : " + this);
closeNow(true);
}
}
@SuppressWarnings("deprecation")
public void checkHwid(String allowedHwid)
{
if(!allowedHwid.equalsIgnoreCase("") && !getHWID().equalsIgnoreCase(allowedHwid))
closeNow(false);
}
public boolean checkHWIDBanned()
{
return HWID.checkHWIDBanned(new HardwareID(getHWID()));
}
@Override
public String toString()
{
return _state + " IP: " + getIpAddr() + (_login == null ? "" : " Account: " + _login) + (_activeChar == null ? "" : " Player : " + _activeChar);
}
private String _hwid;
private boolean _isProtected;
public String getHWID()
{
return HWIDS != null ? HWIDS.Full : null;
}
public boolean isProtected() {
return _isProtected;
}
public void setHWID(final String hwid)
{
HWIDS = new HardwareID(hwid);
}
public void setProtected(boolean isProtected) {
_isProtected = isProtected;
}
public SecondaryPasswordAuth getSecondaryAuth()
{
return _secondaryAuth;
}
public void setGameGuardOk(boolean gameGuardOk)
{
_gameGuardOk = gameGuardOk;
}
public boolean isGameGuardOk()
{
return _gameGuardOk;
}
private static byte[] _keyClientEn = new byte[8];
public static void setKeyClientEn(byte[] key)
{
_keyClientEn = key;
}
public static byte[] getKeyClientEn()
{
return _keyClientEn;
}
public boolean hasHWID()
{
return HWIDS != null;
}
public void setAllowHWID(final String hwid)
{
if(hwid != null && !hwid.isEmpty())
ALLOW_HWID = new HardwareID(hwid);;
}
private void logHWID()
{
Connection con = null;
PreparedStatement statement = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement(ftConfig.PROTECT_GS_LOG_HWID_QUERY);
statement.setString(1, _login);
statement.setString(2, getIpAddr());
statement.setString(3, HWIDS.Full);
statement.setInt(4, Config.REQUEST_ID);
statement.execute();
}
catch(final Exception e)
{
_log.warn("Could not log HWID:", e);
}
finally
{
DbUtils.closeQuietly(con, statement);
}
}
}