{
boolean res;
int obj_id = Util.GetCharIDbyName(actor);
res = obj_id > 0;
ThreadConnection con = null;
FiltredPreparedStatement statement = null;
if(res)
{
try
{
con = L2DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE obj_Id=?");
statement.setInt(1, acc_level);
statement.setInt(2, obj_id);
statement.executeUpdate();
DatabaseUtils.closeStatement(statement);
if(acc_level < 0)
{
int endban;
if(period == -1)
{
endban = Integer.MAX_VALUE;
}
else if(period > 0)
{
Calendar end = Calendar.getInstance();
end.add(Calendar.DAY_OF_MONTH, period);
endban = (int) (end.getTimeInMillis() / 1000);
}
else
{
_log.warning("Negative ban period: " + period);
return false;
}
String date = new SimpleDateFormat("yy.MM.dd H:mm:ss").format(new Date());
String enddate = new SimpleDateFormat("yy.MM.dd H:mm:ss").format(new Date(endban * 1000L));
if(endban * 1000L <= Calendar.getInstance().getTimeInMillis())
{
_log.warning("Negative ban period | From " + date + " to " + enddate);
return false;
}
statement = con.prepareStatement("INSERT INTO bans (obj_id, baned, unban, reason, GM, endban) VALUES(?,?,?,?,?,?)");
statement.setInt(1, obj_id);
statement.setString(2, date);
statement.setString(3, enddate);
statement.setString(4, msg);
statement.setString(5, GM);
statement.setLong(6, endban);
statement.execute();
}
else
{
statement = con.prepareStatement("DELETE FROM bans WHERE obj_id=?");
statement.setInt(1, obj_id);
statement.execute();
}
}
catch(Exception e)
{
e.printStackTrace();