I'm trying to calculate the total time spent on the server by a Player.
I have a PHP cron job every 5 minutes that will query the details from the server https://developer.valvesoftware.com/wiki/Server_queries
array (
'id' => '1',
'name' => 'Player',
'score' => '3',
'time' => '1234',
),
array (
'id' => '2',
'name' => 'Player 2',
'score' => '12',
'time' => '2453',
) other 100k players.
// The 'time' is starting from 0 seconds when the player join the server, if she leave and then join again the time is starting from 0 seconds
Just adding the live data to DB from the PHP Query
| id | name | last_score | total_score | last_time | total_time |
| -- | -------- | ---------- | ----------- | --------- | ---------- |
| 1 | Player | 3 | 0 | 1234 | 0 |
| 2 | Player 2 | 12 | 0 | 2453 | 0 |
I'm not the owner of the servers where the players are online so i can't instantly LOG when the player leaves.
I'm trying to do something like this https://www.gametracker.com/server_info/109.120.135.78:2302/top_players/
CodePudding user response:
Solved!
$time = $query['Time'];
$last = $db_players['last_time'];
$total = $db_players['total_time'];
if ($time < $last) {
$total = $time;
} else {
$total = ($time - $last);
}