ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
Client.hpp
[詳解]
1
8#ifndef CLIENT_HPP
9#define CLIENT_HPP
10
11#include <ctime>
12#include <string>
13#include <vector>
14
15class Channel; // Forward declaration
16
25class Client {
26 public:
27 static const size_t MAX_SENDBUFF_SIZE = 1024 * 1024;
28 private:
29 int _fd;
30 std::string _nickname;
31 std::string _username;
32 std::string _hostname;
33 bool _isAuthenticated;
34 bool _isRegistered;
35 std::string _receiveBuffer;
36 std::string _sendBuffer;
37 bool _isMarkedForDisconnect;
38 std::string _quitMessage;
39 std::string _realname;
40 std::vector<Channel *> _channels;
42 protected:
46 public:
52 Client(int fd, const std::string &hostname);
53
57 virtual ~Client(); // デストラクタをvirtualにする
58
59 // Getters
64 int getFd() const;
65
70 const std::string &getNickname() const;
71
76 const std::string &getUsername() const;
77
82 const std::string &getHostname() const;
83
88 bool isAuthenticated() const;
89
94 bool isRegistered() const;
95
100 std::string getPrefix() const;
101
106 bool isMarkedForDisconnect() const;
107
112 const std::string &getQuitMessage() const;
113
118 const std::string &getRealname() const;
119
124 const std::string &getSendBuffer() const;
125
130 const std::vector<Channel *> &getChannels() const;
131
137
143
144 // Setters
149 void setNickname(const std::string &nickname);
150
155 void setUsername(const std::string &username);
156
161 void setRealname(const std::string &realname);
162
167 void setAuthenticated(bool value);
168
173 void setRegistered(bool value);
174
179 void markForDisconnect(const std::string &message);
180
185 void addChannel(Channel *channel);
186
191 void removeChannel(Channel *channel);
192
196 void updateActivityTime();
197
203
208 void clearPingSentTime();
209
210 // Buffer management
215 void appendBuffer(const std::string &data);
216
221 void appendToSendBuffer(const std::string &data);
222
228
233 void removeSentData(size_t bytes_sent);
234
235 // Communication
240 virtual void sendMessage(const std::string &message) const;
241};
242
243#endif
チャンネルのメンバーと状態を管理するクラス。
Definition Channel.hpp:25
Represents an IRC client connected to the server.
Definition Client.hpp:25
std::time_t _lastPingSentTime
Timestamp of the last PING sent to the client.
Definition Client.hpp:44
void setNickname(const std::string &nickname)
Sets the client's nickname.
Definition Client.cpp:58
const std::string & getSendBuffer() const
Gets the client's send buffer content.
Definition Client.cpp:41
void setUsername(const std::string &username)
Sets the client's username.
Definition Client.cpp:60
bool isRegistered() const
Checks if the client is registered.
Definition Client.cpp:33
const std::vector< Channel * > & getChannels() const
Gets the list of channels the client is in.
Definition Client.cpp:43
void removeChannel(Channel *channel)
Removes a channel from the client's list of joined channels.
Definition Client.cpp:83
static const size_t MAX_SENDBUFF_SIZE
Maximum size of the send buffer (1MB).
Definition Client.hpp:27
void clearPingSentTime()
Clears the last PING sent time, indicating no PING is currently pending a PONG. This should be called...
Definition Client.cpp:91
const std::string & getRealname() const
Gets the client's real name.
Definition Client.cpp:39
std::string getPrefix() const
Generates the client's IRC prefix (e.g., :nick!user@host).
Definition Client.cpp:50
void setRealname(const std::string &realname)
Sets the client's real name.
Definition Client.cpp:62
void updateActivityTime()
Updates the client's last activity time to the current time.
Definition Client.cpp:87
std::time_t getLastActivityTime() const
Gets the timestamp of the client's last activity.
Definition Client.cpp:45
bool isAuthenticated() const
Checks if the client is authenticated.
Definition Client.cpp:31
void appendBuffer(const std::string &data)
Appends data to the client's receive buffer.
Definition Client.cpp:94
virtual void sendMessage(const std::string &message) const
Sends a message to the client by appending it to the send buffer.
Definition Client.cpp:135
const std::string & getNickname() const
Gets the client's nickname.
Definition Client.cpp:25
virtual ~Client()
Destroys the Client object.
Definition Client.cpp:20
void setLastPingSentTime(std::time_t time)
Sets the timestamp of the last PING sent to the client.
Definition Client.cpp:89
const std::string & getHostname() const
Gets the client's hostname.
Definition Client.cpp:29
std::time_t getLastPingSentTime() const
Gets the timestamp of the last PING sent to the client.
Definition Client.cpp:47
const std::string & getUsername() const
Gets the client's username.
Definition Client.cpp:27
void addChannel(Channel *channel)
Adds a channel to the client's list of joined channels.
Definition Client.cpp:73
void markForDisconnect(const std::string &message)
Marks the client for disconnection with a specified message.
Definition Client.cpp:68
const std::string & getQuitMessage() const
Gets the client's quit message.
Definition Client.cpp:37
void appendToSendBuffer(const std::string &data)
Appends data to the client's send buffer.
Definition Client.cpp:97
bool isMarkedForDisconnect() const
Checks if the client is marked for disconnection.
Definition Client.cpp:35
std::string readLineFromBuffer()
Reads a single line from the receive buffer.
Definition Client.cpp:118
std::time_t _lastActivityTime
Timestamp of the last activity from the client.
Definition Client.hpp:43
int getFd() const
Gets the client's file descriptor.
Definition Client.cpp:23
void removeSentData(size_t bytes_sent)
Removes a specified number of bytes from the beginning of the send buffer.
Definition Client.cpp:109
void setRegistered(bool value)
Sets the client's registration status.
Definition Client.cpp:66
void setAuthenticated(bool value)
Sets the client's authentication status.
Definition Client.cpp:64