Character online time

This is not a Support area! Discuss about the Server here. Non-Server related discussion goes in Off-Topic Discussion.
Forum rules
READ NOW: L2j Forums Rules of Conduct
User avatar
jorgeromero
Posts: 65
Joined: Thu Sep 03, 2009 4:33 pm
Location: France

Re: Character online time

Post by jorgeromero »

Anyone got a solution for this?
fakoykas
Posts: 32
Joined: Wed May 06, 2009 11:11 pm

Re: Character online time

Post by fakoykas »

It's rather simple...

Code: Select all

### Eclipse Workspace Patch 1.0#P L2J_ServerIndex: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java===================================================================--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (revision 5165)+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (working copy)@@ -7828,7 +7828,7 @@            long totalOnlineTime = _onlineTime;                        if (_onlineBeginTime > 0)-               totalOnlineTime += (System.currentTimeMillis()-_onlineBeginTime)/1000;+               totalOnlineTime += (System.currentTimeMillis()-getOfflineStartTime()-_onlineBeginTime)/1000;                        statement.setLong(35, totalOnlineTime);            statement.setInt(36, getPunishLevel().value()); 
User avatar
lucan
Posts: 590
Joined: Wed Mar 16, 2011 10:39 pm
Location: Brazil

Re: Character online time

Post by lucan »

Szponiasty wrote:

Code: Select all

     private long getLastSeen(String CharName)    {   //lastaccess        long chObjectId = getObjectIdByName(CharName);        long result = -1;        if (chObjectId < 1)            return result;         L2PcInstance _playerInstance = L2World.getInstance().findPlayer((int)chObjectId);         if (_playerInstance != null && (_playerInstance.isOnline() == 1))            return 0;         Connection con = null;        try        {   // CharName             con = L2DatabaseFactory.getInstance().getConnection();            PreparedStatement statement = con.prepareStatement("SELECT lastaccess FROM characters WHERE charId=?");            statement.setLong(1, chObjectId);            ResultSet rset = statement.executeQuery();            if (rset.next())            {                result = rset.getLong(1);                               }            //_log.warning("Repair Attempt: Output Result for searching characters on account:"+result);            rset.close();            statement.close();        }        catch (SQLException e)        {            e.printStackTrace();            return result;        }        finally        {            try            {                if (con != null)                    con.close();            }            catch (SQLException e)            {                // I really don't care...            }        }        return result;    } 
Have fun.

PS. You can access that also in L2PcInstance with no need for SQL queries.

Code: Select all

 L2pcInstance.javalong _onlineTimelong _onlineBeginTime 
Make getters for that variables, as they're private as I recall (or make them public If you want to).
Sorry for necroposting but i need this to .py script.
I need know the online time of a character, someone can help me?
Post Reply