18 if (args.
size() < 2) {
29 if (channel == NULL) {
43 if (modeStr.
length() != 2 || (modeStr[0] !=
'+' && modeStr[0] !=
'-')) {
48 bool add = (modeStr[0] ==
'+');
49 char mode = modeStr[1];
52 if (args.
size() < 3) {
62 if (targetClient == NULL) {
69 if (!channel->
isMember(targetClient)) {
84 std::string modeMsg = client->
getPrefix() +
" MODE " + channelName +
" " + modeStr +
" " + targetNick +
"\r\n";
87 }
else if (mode ==
't' || mode ==
'n') {
92 }
else if (mode ==
'k') {
94 if (args.
size() < 3) {
104 if (args.
size() < 3) {
111 if (channel->
getKey() != args[2]) {
120 client->
getPrefix() +
" MODE " + channelName +
" " + modeStr + (add ?
" " + args[2] :
"") +
"\r\n";
122 }
else if (mode ==
'l') {
124 if (args.
size() < 3) {
131 unsigned int limit =
static_cast<unsigned int>(
std::atoi(args[2].c_str()));
139 client->
getPrefix() +
" MODE " + channelName +
" " + modeStr + (add ?
" " + args[2] :
"") +
"\r\n";
141 }
else if (mode ==
'i') {
Manages channel members and states.
Manages client connection and state.
Handles the MODE 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_CHANOPRIVSNEEDED
#define ERR_NOSUCHCHANNEL
#define ERR_USERNOTINCHANNEL
#define ERR_NEEDMOREPARAMS
Core IRC server implementation.
void setMode(char mode, bool value)
bool isMember(Client *client) const
void setLimit(unsigned int limit)
void removeOperator(Client *client)
void addOperator(Client *client)
const std::string & getKey() const
void broadcast(const std::string &message, Client *excludeClient)
bool isOperator(Client *client) const
void setKey(const std::string &key)
Represents an IRC client connected to the server.
std::string getPrefix() const
Generates the client's IRC prefix (e.g., :nick!user@host).
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.
Abstract base class (interface) for all IRC commands.
Server * _server
Pointer to the IRC server instance.
void execute(Client *client, const std::vector< std::string > &args)
Executes the MODE command.
ModeCommand(Server *server)
Constructs a ModeCommand object.
Implements the core IRC server functionality as a Singleton.
Channel * getChannel(const std::string &name)
Retrieves a Channel object by its name.
Client * getClientByNickname(const std::string &nickname)
Retrieves a Client object by its nickname.
const std::string & getServerName() const
Gets the server's name.