/**
* Loads the access levels from database<br>
*/
private AccessLevels()
{
_masterAccessLevel = new AccessLevel(Config.MASTERACCESS_LEVEL, "Master Access", Config.MASTERACCESS_NAME_COLOR, Config.MASTERACCESS_TITLE_COLOR, true, true, true, true, true, true, true, true, true, true, true);
_userAccessLevel = new AccessLevel(Config.USERACCESS_LEVEL, "User", Integer.decode("0xFFFFFF"), Integer.decode("0xFFFFFF"), false, false, false, true, false, true, true, true, true, true, false);
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection(false);
final PreparedStatement stmt = con.prepareStatement("SELECT * FROM `access_levels` ORDER BY `accessLevel` DESC");
final ResultSet rset = stmt.executeQuery();
int accessLevel = 0;
String name = null;
int nameColor = 0;
int titleColor = 0;
boolean isGm = false;
boolean allowPeaceAttack = false;
boolean allowFixedRes = false;
boolean allowTransaction = false;
boolean allowAltG = false;
boolean giveDamage = false;
boolean takeAggro = false;
boolean gainExp = false;
//L2EMU_ADD
boolean useNameColor = true;
boolean useTitleColor = false;
boolean canDisableGmStatus = true;
//L2EMU_ADD
while(rset.next())
{
accessLevel = rset.getInt("accessLevel");
name = rset.getString("name");
if(accessLevel == Config.USERACCESS_LEVEL) {
_log.finest("AccessLevels: Access level with name {} is using reserved user access level {}. Ignoring it.. "+ name+" "+ Config.USERACCESS_LEVEL);
continue;
}
else if(accessLevel == Config.MASTERACCESS_LEVEL)
{
_log.finest("AccessLevels: Access level with name {} is using reserved master access level {}. Ignoring it.. "+ name+" "+ Config.MASTERACCESS_LEVEL );
continue;
}
else if(accessLevel < 0)
{
_log.finest("AccessLevels: Access level with name {} is using banned access level state(below 0). Ignoring it.. "+ name);
continue;
}
try
{
nameColor = Integer.decode("0x" + rset.getString("nameColor"));
}
catch(NumberFormatException nfe)
{
_log.finest(nfe.getMessage()+" "+ nfe);
try
{
nameColor = Integer.decode("0xFFFFFF");
}
catch(NumberFormatException nfe2)
{
_log.finest(nfe.getMessage() + nfe);
}
}
try
{
titleColor = Integer.decode("0x" + rset.getString("titleColor"));
}
catch(NumberFormatException nfe)
{
_log.finest(nfe.getMessage()+" "+ nfe);
try
{
titleColor = Integer.decode("0x77FFFF");
}
catch(NumberFormatException nfe2)
{
_log.finest(nfe.getMessage()+" "+ nfe);
}
}
isGm = rset.getBoolean("isGm");
allowPeaceAttack = rset.getBoolean("allowPeaceAttack");
allowFixedRes = rset.getBoolean("allowFixedRes");
allowTransaction = rset.getBoolean("allowTransaction");
allowAltG = rset.getBoolean("allowAltg");
giveDamage = rset.getBoolean("giveDamage");
takeAggro = rset.getBoolean("takeAggro");
gainExp = rset.getBoolean("gainExp");
//L2EMU_ADD - Rayan for temp access
useNameColor = rset.getBoolean("useNameColor");
useTitleColor = rset.getBoolean("useTitleColor");
canDisableGmStatus = rset.getBoolean("canDisableGmStatus");
//L2EMU_EDIT - Rayan for temp access
_accessLevels.put(accessLevel, new AccessLevel(accessLevel, name, nameColor, titleColor, isGm, allowPeaceAttack, allowFixedRes, allowTransaction, allowAltG, giveDamage, takeAggro, gainExp, useNameColor, useTitleColor, canDisableGmStatus));
//L2EMU_EDIT
}
rset.close();
stmt.close();
}
catch(SQLException e)
{
_log.severe("AccessLevels: Error loading from database "+ e);
}
finally
{
CloseUtil.close(con);
}
//_log.info("AccessLevels: Loaded " + _accessLevels.size() + " Access Levels from database.");
_log.finest("AccessLevels: Master Access Level is " + Config.MASTERACCESS_LEVEL);
_log.finest("AccessLevels: User Access Level is " + Config.USERACCESS_LEVEL);
if(Config.DEBUG) for(int actual : _accessLevels.keySet()){
AccessLevel actual_access = _accessLevels.get(actual);
_log.finest("AccessLevels: {} Access Level is {} "+ actual_access.getName()+" "+ actual_access.getLevel());
}
}