Character online time
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
- Flashy
- Posts: 310
- Joined: Mon Sep 29, 2008 11:49 am
- Location: Germany
Character online time
in what class is the player online time handled?
I want change that offline shops are not count as onlinetime.
thx.
I want change that offline shops are not count as onlinetime.
thx.
- tukune
- Posts: 533
- Joined: Sun Mar 29, 2009 2:35 pm
- Location: Japan
Re: Character online time
L2pcInstance.java
long _onlineTime
long _onlineBeginTime
I have a idea. (not verify)
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);
-
- Posts: 76
- Joined: Thu Oct 07, 2010 9:03 pm
Re: Character online time
tRIED, not workintukune 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);
-
- Posts: 332
- Joined: Wed Mar 17, 2010 10:33 am
- Location: Greece
- Contact:
Re: Character online time
Cauze im searching the same code...someone can help??
you maybe find it???
ty
you maybe find it???
ty
- Szponiasty
- Advanced User
- Posts: 557
- Joined: Mon Apr 21, 2008 1:31 pm
- Location: Eastern Poland
Re: Character online time
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; }
PS. You can access that also in L2PcInstance with no need for SQL queries.
Code: Select all
L2pcInstance.javalong _onlineTimelong _onlineBeginTime
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
-
- Posts: 332
- Joined: Wed Mar 17, 2010 10:33 am
- Location: Greece
- Contact:
Re: Character online time
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
what i haev to put and where??
the 1st onw looks like ascript...
dunno...plz give some help...
ty
- Szponiasty
- Advanced User
- Posts: 557
- Joined: Mon Apr 21, 2008 1:31 pm
- Location: Eastern Poland
Re: Character online time
Put code that I've attached, for example into your .java script. Then you use
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:
Same way you can get all other info from table.
Code: Select all
long _timelastseen = getLastSeen("PoRnosJH");
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=?");
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
-
- Posts: 332
- Joined: Wed Mar 17, 2010 10:33 am
- Location: Greece
- Contact:
Re: Character online time
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 :
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...
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
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")
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; }
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
- Szponiasty
- Advanced User
- Posts: 557
- Joined: Mon Apr 21, 2008 1:31 pm
- Location: Eastern Poland
Re: Character online time
Hmm. Sorry, but I can't teach you Java (ask someone who knows it better )
And in the next chronicle they went into space, fighting the evil empire... In a galaxy far, far away xD
- Flashy
- Posts: 310
- Joined: Mon Sep 29, 2008 11:49 am
- Location: Germany
Re: Character online time
hmm your code have nothing to do with the problem ask in this thread...Szponiasty wrote:Have fun.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; }
PS. You can access that also in L2PcInstance with no need for SQL queries.Make getters for that variables, as they're private as I recall (or make them public If you want to).Code: Select all
L2pcInstance.javalong _onlineTimelong _onlineBeginTime
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.
-
- L2j Veteran
- Posts: 3437
- Joined: Wed Apr 30, 2008 8:53 am
- Location: Russia
Re: Character online time
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;
public static final int PI = 3.1415926535897932384626433832795;
- Flashy
- Posts: 310
- Joined: Mon Sep 29, 2008 11:49 am
- Location: Germany
Re: Character online time
ah, ok thx for this info.. your right of course...
...code in post updated.
is this ok, now?
...code in post updated.
is this ok, now?
- Szponiasty
- Advanced User
- Posts: 557
- Joined: Mon Apr 21, 2008 1:31 pm
- Location: Eastern Poland
Re: Character online time
Ahhh, sorry. You're right. Just sometimes I read two-three words and not get into whole caseFlashy 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.
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
-
- L2j Veteran
- Posts: 3437
- Joined: Wed Apr 30, 2008 8:53 am
- Location: Russia
Re: Character online time
Incorrect logic.Flashy wrote:+ if (L2PcInstance.this.getPrivateStoreType() == 0 && L2PcInstance.this.getClient() != null || !L2PcInstance.this.getClient().isDetached())
Commiter of the shit
public static final int PI = 3.1415926535897932384626433832795;
public static final int PI = 3.1415926535897932384626433832795;
-
- Posts: 332
- Joined: Wed Mar 17, 2010 10:33 am
- Location: Greece
- Contact:
Re: Character online time
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)