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
Flashy
Posts: 310
Joined: Mon Sep 29, 2008 11:49 am
Location: Germany

Character online time

Post by Flashy »

in what class is the player online time handled?
I want change that offline shops are not count as onlinetime.

thx.
User avatar
tukune
Posts: 533
Joined: Sun Mar 29, 2009 2:35 pm
Location: Japan

Re: Character online time

Post by tukune »

L2pcInstance.java
long _onlineTime
long _onlineBeginTime

I have a idea. (not verify)

Code: Select all

            long totalOnlineTime = _onlineTime;                        if (_onlineBeginTime > 0)                totalOnlineTime += (System.currentTimeMillis()-_onlineBeginTime)/1000;+            if (! isOnline())+            {+                _onlineTime = totalOnlineTime;+                _onlineBeginTime = 0;+            }                    statement.setLong(37, totalOnlineTime);
returNix
Posts: 76
Joined: Thu Oct 07, 2010 9:03 pm

Re: Character online time

Post by returNix »

tukune wrote:L2pcInstance.java
long _onlineTime
long _onlineBeginTime

I have a idea. (not verify)

Code: Select all

            long totalOnlineTime = _onlineTime;                        if (_onlineBeginTime > 0)                totalOnlineTime += (System.currentTimeMillis()-_onlineBeginTime)/1000;+            if (! isOnline())+            {+                _onlineTime = totalOnlineTime;+                _onlineBeginTime = 0;+            }                    statement.setLong(37, totalOnlineTime);
tRIED, not workin :x
PoRnosJH
Posts: 332
Joined: Wed Mar 17, 2010 10:33 am
Location: Greece
Contact:

Re: Character online time

Post by PoRnosJH »

Cauze im searching the same code...someone can help??

you maybe find it???


ty
Image
User avatar
Szponiasty
Advanced User
Advanced User
Posts: 557
Joined: Mon Apr 21, 2008 1:31 pm
Location: Eastern Poland

Re: Character online time

Post by Szponiasty »

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).
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
PoRnosJH
Posts: 332
Joined: Wed Mar 17, 2010 10:33 am
Location: Greece
Contact:

Re: Character online time

Post by PoRnosJH »

man can you explain a little more...
what i haev to put and where??

the 1st onw looks like ascript...

dunno...plz give some help...


ty
Image
User avatar
Szponiasty
Advanced User
Advanced User
Posts: 557
Joined: Mon Apr 21, 2008 1:31 pm
Location: Eastern Poland

Re: Character online time

Post by Szponiasty »

Put code that I've attached, for example into your .java script. Then you use

Code: Select all

   long _timelastseen = getLastSeen("PoRnosJH"); 
To get an unix timestamp for the time when "PoRnosJH" was lastly being online in game. To get the total time, that player spent on server, do a little change:

Code: Select all

             // change this line:            PreparedStatement statement = con.prepareStatement("SELECT lastaccess FROM characters WHERE charId=?");            // to that, to get total online not last logon:            PreparedStatement statement = con.prepareStatement("SELECT onlinetime FROM characters WHERE charId=?"); 
Same way you can get all other info from table.
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
PoRnosJH
Posts: 332
Joined: Wed Mar 17, 2010 10:33 am
Location: Greece
Contact:

Re: Character online time

Post by PoRnosJH »

listen man...tnx for your help first..

and second..i have a script who takes from db onlinetime of a player and place top 50 online players in the server..

here is the main code :

Code: Select all

 con.prepareStatement("SELECT char_name,onlinetime FROM characters WHERE onlinetime>0 order by onlinetime desc limit 50") 
so ...i need to know...what i have to change for...i''onlinetime''in db saves only the real online time no onlinetime+offline shop's time

i cant understand your's code im a little noobie...

if i create for example scripts/custom/online.java
also add this on scripts.cfg
and add this code for total time as you say not from last logon...

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 onlinetime 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; }    
my npc will gives me the real time of the players???

or...
what i must to change in my script from top online char's npc...to gives me the real time--top 50...??

ty for all
Image
User avatar
Szponiasty
Advanced User
Advanced User
Posts: 557
Joined: Mon Apr 21, 2008 1:31 pm
Location: Eastern Poland

Re: Character online time

Post by Szponiasty »

Hmm. Sorry, but I can't teach you Java (ask someone who knows it better :P)
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
User avatar
Flashy
Posts: 310
Joined: Mon Sep 29, 2008 11:49 am
Location: Germany

Re: Character online time

Post by Flashy »

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).
hmm your code have nothing to do with the problem ask in this thread...
the problem is to add / find a way to exclude the online time for offline shops.

mabye this can be a solution:

Code: Select all

 Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java===================================================================--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (revision 4425)+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java    (working copy)@@ -7179,24 +7179,27 @@     */    public void updateOnlineStatus()    {-       Connection con = null;-       try-       {-           con = L2DatabaseFactory.getInstance().getConnection();-           PreparedStatement statement = con.prepareStatement("UPDATE characters SET online=?, lastAccess=? WHERE charId=?");-           statement.setInt(1, isOnlineInt());-           statement.setLong(2, System.currentTimeMillis());-           statement.setInt(3, getObjectId());-           statement.execute();-           statement.close();-       }-       catch (Exception e)-       {-           _log.log(Level.SEVERE, "Failed updating character online status.", e);-       }-       finally+       if (L2PcInstance.this.getPrivateStoreType() == 0 && L2PcInstance.this.getClient() != null || !L2PcInstance.this.getClient().isDetached())        {-           L2DatabaseFactory.close(con);+           Connection con = null;+           try+           {+               con = L2DatabaseFactory.getInstance().getConnection();+               PreparedStatement statement = con.prepareStatement("UPDATE characters SET online=?, lastAccess=? WHERE charId=?");+               statement.setInt(1, isOnlineInt());+               statement.setLong(2, System.currentTimeMillis());+               statement.setInt(3, getObjectId());+               statement.execute();+               statement.close();+           }+           catch (Exception e)+           {+               _log.log(Level.SEVERE, "Failed updating character online status.", e);+           }+           finally+           {+               L2DatabaseFactory.close(con);+           }        }    }     
Last edited by Flashy on Fri Nov 26, 2010 12:31 am, edited 1 time in total.
_DS_
L2j Veteran
L2j Veteran
Posts: 3437
Joined: Wed Apr 30, 2008 8:53 am
Location: Russia

Re: Character online time

Post by _DS_ »

Add check for shop/craft mode, or you will lost info about online time for players disconnected in combat.
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
User avatar
Flashy
Posts: 310
Joined: Mon Sep 29, 2008 11:49 am
Location: Germany

Re: Character online time

Post by Flashy »

ah, ok thx for this info.. your right of course...
...code in post updated.
is this ok, now?
User avatar
Szponiasty
Advanced User
Advanced User
Posts: 557
Joined: Mon Apr 21, 2008 1:31 pm
Location: Eastern Poland

Re: Character online time

Post by Szponiasty »

Flashy wrote: hmm your code have nothing to do with the problem ask in this thread...
the problem is to add / find a way to exclude the online time for offline shops.
Ahhh, sorry. You're right. Just sometimes I read two-three words and not get into whole case :(

You have great example how to quickly deal with that problem, within game server's terminal thread:

Code: Select all

 public String getServerStatus(){        int playerCount = 0, objectCount = 0;        int max = LoginServerThread.getInstance().getMaxPlayer();         playerCount = L2World.getInstance().getAllPlayersCount();        objectCount = L2World.getInstance().getAllVisibleObjectsCount();         int itemCount=0;        int itemVoidCount=0;        int monsterCount=0;        int minionCount = 0;        int minionsGroupCount = 0;        int npcCount=0;        int charCount=0;        int pcCount=0;        int detachedCount=0;        int doorCount=0;        int summonCount=0;        int AICount=0;         Collection<L2Object> objs = L2World.getInstance().getAllVisibleObjects().values();        //synchronized (L2World.getInstance().getAllVisibleObjects())        {            for (L2Object obj : objs)            {                if(obj == null)                    continue;                if (obj instanceof L2Character)                    if (((L2Character)obj).hasAI())                        AICount++;                if (obj instanceof L2ItemInstance)                    if (((L2ItemInstance)obj).getLocation() == L2ItemInstance.ItemLocation.VOID)                        itemVoidCount++;                    else                        itemCount++;                 else if (obj instanceof L2MonsterInstance)                {                    monsterCount++;                    minionCount += ((L2MonsterInstance)obj).getTotalSpawnedMinionsInstances();                    minionsGroupCount += ((L2MonsterInstance)obj).getTotalSpawnedMinionsGroups();                }                else if (obj instanceof L2Npc)                    npcCount++;                else if (obj instanceof L2PcInstance)                {                    pcCount++;                   /** ---------------- here is what you need --------------------- */                    if (((L2PcInstance)obj).getClient() != null                            && ((L2PcInstance)obj).getClient().isDetached())                        detachedCount++;                 }                else if (obj instanceof L2Summon)                    summonCount++;                else if (obj instanceof L2DoorInstance)                    doorCount++;                else if (obj instanceof L2Character)                    charCount++;            }        }        StringBuilder sb = new StringBuilder();        sb.append("Server Status: ");        sb.append("\r\n  --->  Player Count: " + playerCount + "/" + max);        sb.append("\r\n  ---> Offline Count: " + detachedCount + "/" + playerCount);        sb.append("\r\n  +-->  Object Count: " + objectCount);        sb.append("\r\n  +-->      AI Count: " + AICount);        sb.append("\r\n  +.... L2Item(Void): " + itemVoidCount);        sb.append("\r\n  +.......... L2Item: " + itemCount);        sb.append("\r\n  +....... L2Monster: " + monsterCount);  
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
_DS_
L2j Veteran
L2j Veteran
Posts: 3437
Joined: Wed Apr 30, 2008 8:53 am
Location: Russia

Re: Character online time

Post by _DS_ »

Flashy wrote:+       if (L2PcInstance.this.getPrivateStoreType() == 0 && L2PcInstance.this.getClient() != null || !L2PcInstance.this.getClient().isDetached())
Incorrect logic.
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
PoRnosJH
Posts: 332
Joined: Wed Mar 17, 2010 10:33 am
Location: Greece
Contact:

Re: Character online time

Post by PoRnosJH »

Flashy wrote:ah, ok thx for this info.. your right of course...
...code in post updated.
is this ok, now?

i got this error each time someone trys to login

Code: Select all

 28 Νοε 2010 2:12:01 πμ com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket runSEVERE: Client: [Account: bryan - IP: 190.78.217.229] - Failed running: [C] 0D CharacterSelect - L2J Server Version: ${l2j.revision} - DP Revision: ${l2jdp.revision} ; nulljava.lang.NullPointerException    at com.l2jserver.gameserver.model.actor.instance.L2PcInstance.updateOnlineStatus(L2PcInstance.java:7311)    at com.l2jserver.gameserver.model.actor.instance.L2PcInstance.setOnlineStatus(L2PcInstance.java:7298)    at com.l2jserver.gameserver.network.L2GameClient.loadCharFromDisk(L2GameClient.java:573)    at com.l2jserver.gameserver.network.clientpackets.CharacterSelect.runImpl(CharacterSelect.java:103)    at com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket.run(L2GameClientPacket.java:62)    at com.l2jserver.gameserver.network.L2GameClient.run(L2GameClient.java:997)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)    at java.lang.Thread.run(Unknown Source) 
Image
Post Reply