Character /playtime

Hypnotoad
Posts: 15
Joined: Fri Dec 14, 2012 7:25 am

Character /playtime

Post by Hypnotoad » Wed Feb 27, 2013 10:05 pm

Hello, today I bring to you from the work shop of Hypnotoad:
Character /playtime implementation.

Since this is already an available field in the database, this is a small ordeal.

Although it has been tested, I think the implementation may be a little bloated.
Due to that, I implore you to give feedback on a better implementation, as I would love to improve upon this.

Small explanation on how it works:
The playtime is measured in 'seconds' played, as such, the database field will be in that format also.
Playtime server side is kept to the nearest second, and saved to the database every 10 minutes.
It is primarily saved to the database when a character zones/leaves the game.
Character playtime is only updated for a client when they zone or login, as such, the client handles playtime internally until you zone, at which point the server sends this time. I'm guessing this is to keep the client in sync and updated.
playtime.patch
(9.37 KiB) Downloaded 396 times

User avatar
diatanato
Developer
Posts: 112
Joined: Thu Aug 30, 2012 9:59 pm

Re: Character /playtime

Post by diatanato » Fri Mar 01, 2013 3:42 am

не очень удачное решение. слишком много кода для такой простой задачи ((

Hypnotoad
Posts: 15
Joined: Fri Dec 14, 2012 7:25 am

Re: Character /playtime

Post by Hypnotoad » Fri Mar 01, 2013 6:33 pm

diatanato wrote:не очень удачное решение. слишком много кода для такой простой задачи ((
Originally I was just saving on zone change, but a friend suggested "what if the server crashes, or a person is in same zone for hours."
Thanks for the feedback, I will look at improvement. :idea:

Translated to Russian:
Оригинал был области изменения сохраняются только. Поступило предложение для непредвиденных обстоятельств. Аварии сервера или долгое время в одной области.
Благодарю вас за предложение. Я буду исследовать улучшения. :idea:

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Character /playtime

Post by kjLotus » Fri Mar 01, 2013 7:38 pm

load playtime on login

save server time when they login

on /playtime, get difference between current time with login time, add that to playtime to get total playtime

on logout/disconnect, write difference between current time with login time + playtime to DB

this just leaves the issue of server crashes

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: Character /playtime

Post by bluekirby0 » Sat Mar 02, 2013 1:07 am

I don't believe the accuracy of the info is of vital importance on server crashes. I'm ok with just ignoring that case.

User avatar
diatanato
Developer
Posts: 112
Joined: Thu Aug 30, 2012 9:59 pm

Re: Character /playtime

Post by diatanato » Mon Mar 04, 2013 4:21 am

если в таблицу accounts_sessions добавить новое поле "update_time" и заполнять его текущим временем при каждом изменении session_key (переход между зонами), то можно использовать это значение для подсчета времени, проведенного в игре. делать этот подсчет лишь при переходе между зонами и выходе из игры (что практически одно и тоже). все просто. берем значение update_time (именно в этот момент персонаж вошел в зону) и вычетаем его из текущего времени, а результат добавляем к переменной play_time. в итоге получаем общее время, проведенное в игре.

User avatar
atom0s
Developer
Posts: 537
Joined: Thu Oct 25, 2012 9:52 am

Re: Character /playtime

Post by atom0s » Mon Mar 04, 2013 9:13 am

bluekirby0 wrote:I don't believe the accuracy of the info is of vital importance on server crashes. I'm ok with just ignoring that case.
Ignoring server crash happenings kind of a big deal in my opinion. Server crashes can happen any time at random. Be it 10 minutes after starting, or 10 days. If a person has played on the server for hours on end, a day, weeks, etc. and it crashes, having all that playtime not recorded isn't really that great.

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: Character /playtime

Post by bluekirby0 » Mon Mar 04, 2013 12:20 pm

10 days without zoning? Sounds like a fish bot :P

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Character /playtime

Post by kjLotus » Mon Mar 04, 2013 1:01 pm

bluekirby0 wrote:10 days without zoning? Sounds like a fish bot :P
rolanberry afk while on vacation

i think i'd be okay with that not counting though

User avatar
diatanato
Developer
Posts: 112
Joined: Thu Aug 30, 2012 9:59 pm

Re: Character /playtime

Post by diatanato » Tue Mar 05, 2013 12:29 am

we can save play time in game midnight with guild shop update (every 1 hour) - CZone::TOTDChange() case TIME_MIDNIGHT

Post Reply