【问题标题】:Time spent on the game server在游戏服务器上花费的时间
【发布时间】:2022-02-11 09:02:46
【问题描述】:

我正在尝试计算玩家在服务器上花费的总时间。

我每 5 分钟有一个 PHP cron 作业,它将从服务器查询详细信息 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

只需将实时数据从 PHP 查询添加到数据库

| id | name     | last_score | total_score | last_time | total_time |
| -- | -------- | ---------- | ----------- | --------- | ---------- |
| 1  | Player   | 3          | 0           | 1234      | 0          |
| 2  | Player 2 | 12         | 0           | 2453      | 0          |

我不是玩家在线的服务器的所有者,因此我无法在玩家离开时立即登录。

我正在尝试做这样的事情https://www.gametracker.com/server_info/109.120.135.78:2302/top_players/

【问题讨论】:

  • 创建一个新表来按玩家 ID 存储开始和停止时间,然后您的 CRON 作业只需​​从中计算总数。
  • 感谢您的评论,我现在添加了一个更详细的示例。

标签: php date time calculation


【解决方案1】:

解决了!

  $time = $query['Time'];
  $last = $db_players['last_time'];
  $total = $db_players['total_time'];

  if ($time < $last) {
    $total += $time;
  } else {
    $total += ($time - $last);
  }

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多