17bool NickCommand::isValidNickname(
const std::string &nick)
const {
23 if (std::isdigit(
static_cast<unsigned char>(nick[0])) || nick[0] ==
'-') {
26 for (
size_t i = 0; i < nick.
length(); ++i) {
28 if (!std::isalnum(
static_cast<unsigned char>(c)) && c !=
'[' && c !=
']' && c !=
'{' && c !=
'}' && c !=
'^' &&
29 c !=
'`' && c !=
'_' && c !=
'|' && c !=
'-') {
36void NickCommand::registerClient(
Client *client) {
69 if (!isValidNickname(newNick)) {
91 client->
sendMessage(oldPrefix +
" NICK :" + newNick);
95 registerClient(client);
Manages client connection and state.
Handles the NICK command.
std::string formatReply(const std::string &serverName, const std::string &clientNickname, const std::string &replyCodeAndText)
Formats an IRC reply message without extra parameters.
Defines IRC numeric replies and error messages.
#define ERR_ERRONEUSNICKNAME
#define ERR_NICKNAMEINUSE
#define ERR_NONICKNAMEGIVEN
Core IRC server implementation.
Represents an IRC client connected to the server.
void setNickname(const std::string &nickname)
Sets the client's nickname.
bool isRegistered() const
Checks if the client is registered.
std::string getPrefix() const
Generates the client's IRC prefix (e.g., :nick!user@host).
bool isAuthenticated() const
Checks if the client is authenticated.
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.
const std::string & getUsername() const
Gets the client's username.
void setRegistered(bool value)
Sets the client's registration status.
Abstract base class (interface) for all IRC commands.
Server * _server
Pointer to the IRC server instance.
NickCommand(Server *server)
Constructs a NickCommand object.
void execute(Client *client, const std::vector< std::string > &args)
Executes the NICK command.
Implements the core IRC server functionality as a Singleton.
Client * getClientByNickname(const std::string &nickname)
Retrieves a Client object by its nickname.
const std::string & getServerName() const
Gets the server's name.