blob: 070a8d4fed36dc12a0bd89c100aab6c32bc45935 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#pragma once
#include "FileDescriptor.hpp"
#include "chatManager.hpp"
#include "format.hpp"
#include <memory>
#include <netinet/in.h>
#include <string>
#include <thread>
class CSession {
public:
CSession();
~CSession();
struct SRecvData {
std::string data;
const size_t size = 1024;
bool good = false;
bool isEmpty() const;
void sanitize();
};
const std::string &getName() const;
const char *getIp() const;
void setSelf(std::pair<std::jthread, std::shared_ptr<CSession>> *self);
std::unique_ptr<SRecvData> read();
std::unique_ptr<SRecvData> read(const std::string &msg);
bool write(const std::string &msg);
template <typename... Args>
bool write(std::format_string<Args...> fmt, Args &&...args);
template <typename... Args>
bool write(eFormatType type, std::format_string<Args...> fmt, Args &&...args);
void writeChat(const CChatManager::SMessage &msg);
bool isMuted() const;
void setMuted(bool mute);
void run();
bool isValid();
private:
constexpr static char m_adminIps[1][INET_ADDRSTRLEN] = {"127.0.0.1"};
enum eEventType : std::uint8_t {
READ,
WRITE
};
std::pair<std::jthread, std::shared_ptr<CSession>> *self;
Hyprutils::OS::CFileDescriptor m_sockfd;
sockaddr_in m_addr;
socklen_t m_addrLen = sizeof(m_addr);
std::string m_name;
char m_ip[INET_ADDRSTRLEN];
int m_port;
bool m_isAdmin = false;
bool m_isReading = false;
bool m_isMuted = false;
void recvLoop();
bool registerSession();
#ifdef DEBUG
void onConnect();
void onDisconnect();
#endif
void onErrno(eEventType);
#ifdef DEBUG
void onRecv(const SRecvData &data);
void onSend(const std::string &msg);
#endif
friend class CSessionManager;
};
|