Page 1 of 2
Character online time
Posted: Sun Oct 17, 2010 8:42 pm
by Flashy
in what class is the player online time handled?
I want change that offline shops are not count as onlinetime.
thx.
Re: Character online time
Posted: Mon Oct 18, 2010 11:27 am
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);
Re: Character online time
Posted: Mon Oct 18, 2010 1:33 pm
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
![Mad :x](./images/smilies/icon_mad.gif)
Re: Character online time
Posted: Tue Nov 16, 2010 2:46 am
by PoRnosJH
Cauze im searching the same code...someone can help??
you maybe find it???
ty
Re: Character online time
Posted: Tue Nov 23, 2010 7:25 pm
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).
Re: Character online time
Posted: Tue Nov 23, 2010 11:03 pm
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
Re: Character online time
Posted: Wed Nov 24, 2010 12:28 am
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.
Re: Character online time
Posted: Wed Nov 24, 2010 6:01 pm
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
Re: Character online time
Posted: Wed Nov 24, 2010 11:29 pm
by Szponiasty
Hmm. Sorry, but I can't teach you Java (ask someone who knows it better
![Razz :P](./images/smilies/icon_razz.gif)
)
Re: Character online time
Posted: Thu Nov 25, 2010 10:27 pm
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);+ } } }
Re: Character online time
Posted: Thu Nov 25, 2010 11:38 pm
by _DS_
Add check for shop/craft mode, or you will lost info about online time for players disconnected in combat.
Re: Character online time
Posted: Fri Nov 26, 2010 12:30 am
by Flashy
ah, ok thx for this info.. your right of course...
...code in post updated.
is this ok, now?
Re: Character online time
Posted: Fri Nov 26, 2010 2:57 am
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);
Re: Character online time
Posted: Fri Nov 26, 2010 4:53 pm
by _DS_
Flashy wrote:+ if (L2PcInstance.this.getPrivateStoreType() == 0 && L2PcInstance.this.getClient() != null || !L2PcInstance.this.getClient().isDetached())
Incorrect logic.
Re: Character online time
Posted: Sun Nov 28, 2010 3:44 am
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)