aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-21 08:27:47 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-21 08:27:50 +0200
commitf5aaf1b1cc94e28d4fa423a3d0b8ca286cf7f87d (patch)
tree839418cbb8a8f5ee4bbabc79c3ca915babab8302 /include
parente1322b06148b633df365d8916404a2748945de65 (diff)
Implement online/offline users (pinging)
Diffstat (limited to 'include')
-rw-r--r--include/Channel.hpp12
-rw-r--r--include/User.hpp3
2 files changed, 15 insertions, 0 deletions
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 <vector>
+#include <SFML/System/Clock.hpp>
#include <odhtdb/DatabaseNode.hpp>
#include <odhtdb/Signature.hpp>
#include <odhtdb/Group.hpp>
#include <odhtdb/Hash.hpp>
+#include <odhtdb/DhtKey.hpp>
+#include <future>
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<User*> users;
odhtdb::Signature::MapPublicKey<OnlineUser*> publicKeyOnlineUsersMap;
+ dht::InfoHash pingKey;
+ std::future<size_t> 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 <string>
#include <odhtdb/Signature.hpp>
@@ -37,6 +38,8 @@ namespace dchat
bool isOnlineUser() const override { return true; }
std::string name;
+ u32 pingCounter;
+ u64 pingTimestamp;
};
class OnlineRemoteUser : public OnlineUser