From f5aaf1b1cc94e28d4fa423a3d0b8ca286cf7f87d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 21 May 2018 08:27:47 +0200 Subject: Implement online/offline users (pinging) --- include/Channel.hpp | 12 ++++++++++++ include/User.hpp | 3 +++ 2 files changed, 15 insertions(+) (limited to 'include') diff --git a/include/Channel.hpp b/include/Channel.hpp index 16c2fb3..28d174b 100644 --- a/include/Channel.hpp +++ b/include/Channel.hpp @@ -6,10 +6,13 @@ #include "Channel.hpp" #include "types.hpp" #include +#include #include #include #include #include +#include +#include namespace odhtdb { @@ -58,8 +61,14 @@ namespace dchat void processEvent(const sf::Event &event, Cache &cache); void draw(sf::RenderWindow &window, Cache &cache); + void update(); + // Returns 0 if we are offline + u64 getSyncedTimestampUtcCombined(); + static void setCurrent(Channel *channel); static Channel* getCurrent(); + private: + void sendPing(u32 pingCounter, u64 pingTimestamp); protected: odhtdb::Database *database; odhtdb::DatabaseNode databaseNodeInfo; @@ -70,5 +79,8 @@ namespace dchat SystemUser systemUser; std::vector users; odhtdb::Signature::MapPublicKey publicKeyOnlineUsersMap; + dht::InfoHash pingKey; + std::future pingListener; + sf::Clock pingTimer; }; } diff --git a/include/User.hpp b/include/User.hpp index 85418dc..ac08e36 100644 --- a/include/User.hpp +++ b/include/User.hpp @@ -1,5 +1,6 @@ #pragma once +#include "types.hpp" #include #include @@ -37,6 +38,8 @@ namespace dchat bool isOnlineUser() const override { return true; } std::string name; + u32 pingCounter; + u64 pingTimestamp; }; class OnlineRemoteUser : public OnlineUser -- cgit v1.2.3