16 : _fd(fd), _hostname(hostname), _isAuthenticated(false), _isRegistered(false), _receiveBuffer(
""), _sendBuffer(
""),
17 _isMarkedForDisconnect(false), _realname(
""), _lastActivityTime(
std::time(NULL)),
18 _lastPingSentTime(0) {}
54 return ":" + _nickname +
"!" + _username +
"@" + _hostname;
69 _isMarkedForDisconnect =
true;
70 _quitMessage = message;
75 for (
size_t i = 0; i < _channels.
size(); ++i) {
76 if (_channels[i] == channel) {
84 _channels.
erase(std::remove(_channels.
begin(), _channels.
end(), channel), _channels.
end());
110 if (bytes_sent >= _sendBuffer.
length()) {
113 _sendBuffer = _sendBuffer.
substr(bytes_sent);
119 size_t pos = _receiveBuffer.
find(
"\r\n");
120 if (pos == std::string::npos) {
122 pos = _receiveBuffer.
find(
"\n");
125 if (pos != std::string::npos) {
128 _receiveBuffer.
erase(0, pos + (_receiveBuffer[pos] ==
'\r' ? 2 : 1));
Manages channel members and states.
Manages client connection and state.
Represents an IRC client connected to the server.
std::time_t _lastPingSentTime
Timestamp of the last PING sent to the client.
void setNickname(const std::string &nickname)
Sets the client's nickname.
const std::string & getSendBuffer() const
Gets the client's send buffer content.
void setUsername(const std::string &username)
Sets the client's username.
bool isRegistered() const
Checks if the client is registered.
const std::vector< Channel * > & getChannels() const
Gets the list of channels the client is in.
void removeChannel(Channel *channel)
Removes a channel from the client's list of joined channels.
static const size_t MAX_SENDBUFF_SIZE
Maximum size of the send buffer (1MB).
void clearPingSentTime()
Clears the last PING sent time, indicating no PING is currently pending a PONG. This should be called...
const std::string & getRealname() const
Gets the client's real name.
std::string getPrefix() const
Generates the client's IRC prefix (e.g., :nick!user@host).
void setRealname(const std::string &realname)
Sets the client's real name.
void updateActivityTime()
Updates the client's last activity time to the current time.
std::time_t getLastActivityTime() const
Gets the timestamp of the client's last activity.
bool isAuthenticated() const
Checks if the client is authenticated.
void appendBuffer(const std::string &data)
Appends data to the client's receive buffer.
virtual void sendMessage(const std::string &message) const
Sends a message to the client by appending it to the send buffer.
const std::string & getNickname() const
Gets the client's nickname.
virtual ~Client()
Destroys the Client object.
void setLastPingSentTime(std::time_t time)
Sets the timestamp of the last PING sent to the client.
const std::string & getHostname() const
Gets the client's hostname.
std::time_t getLastPingSentTime() const
Gets the timestamp of the last PING sent to the client.
const std::string & getUsername() const
Gets the client's username.
void addChannel(Channel *channel)
Adds a channel to the client's list of joined channels.
void markForDisconnect(const std::string &message)
Marks the client for disconnection with a specified message.
const std::string & getQuitMessage() const
Gets the client's quit message.
Client(int fd, const std::string &hostname)
Constructs a new Client object.
void appendToSendBuffer(const std::string &data)
Appends data to the client's send buffer.
bool isMarkedForDisconnect() const
Checks if the client is marked for disconnection.
std::string readLineFromBuffer()
Reads a single line from the receive buffer.
std::time_t _lastActivityTime
Timestamp of the last activity from the client.
int getFd() const
Gets the client's file descriptor.
void removeSentData(size_t bytes_sent)
Removes a specified number of bytes from the beginning of the send buffer.
void setRegistered(bool value)
Sets the client's registration status.
void setAuthenticated(bool value)
Sets the client's authentication status.