Skip to content

Commit

Permalink
Stat time online
Browse files Browse the repository at this point in the history
  • Loading branch information
proller committed Oct 4, 2024
1 parent 88d6daa commit 2e93d55
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/game/stat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ end
dig = "Digged",
drop = "Dropped",
join = "Join",
online = "Online",
move = "Traveled",
place = "Placed",
punch = "Punches",
Expand Down
2 changes: 2 additions & 0 deletions src/network/serverpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt)

stat.add("join", playersao->getPlayer()->getName());

playersao->last_time_online = m_uptime_counter->get();

// Send shutdown timer if shutdown has been scheduled
if (m_shutdown_state.isTimerRunning())
SendChatMessage(peer_id, m_shutdown_state.getShutdownTimerMessage());
Expand Down
6 changes: 6 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,12 @@ void Server::DeleteClient(session_t peer_id, ClientDeletionReason reason)
m_script->on_leaveplayer(playersao, reason == CDR_TIMEOUT);

playersao->disconnected();
{
// TODO also make periodic (on save player)
const auto online = m_uptime_counter->get() - playersao->last_time_online;
stat.add("online", player_name, online);
playersao->last_time_online = m_uptime_counter->get();
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/server/player_sao.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class PlayerSAO : public UnitSAO
void addSpeed(v3f);
std::atomic_uint m_ms_from_last_respawn {10000}; //more than ignore move time (1)
v3f m_last_stat_position {};
double last_time_online = 0;


void addedToEnvironment(u32 dtime_s) override;
Expand Down

0 comments on commit 2e93d55

Please sign in to comment.