ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
KickCommand.cpp
[詳解]
1
8#include "KickCommand.hpp"
9#include "Channel.hpp"
10#include "Client.hpp"
11#include "CommandUtils.hpp" // For split
12#include "Replies.hpp"
13#include "Server.hpp"
14#include <string>
15#include <vector>
16
18
20 if (args.size() < 2) {
22 params.push_back("KICK");
24 return;
25 }
26
27 const std::string &channelName = args[0];
28 const std::string &usersStr = args[1];
29 std::string reason = (args.size() > 2) ? args[2] : client->getNickname();
30
31 Channel *channel = _server->getChannel(channelName);
32
33 if (channel == NULL) {
35 params.push_back(channelName);
37 return;
38 }
39
40 if (!channel->isOperator(client)) {
42 params.push_back(channelName);
44 return;
45 }
46
47 std::vector<std::string> users = split(usersStr, ',');
48 for (size_t i = 0; i < users.size(); ++i) {
49 const std::string &targetNick = users[i];
50 Client *targetClient = _server->getClientByNickname(targetNick);
51
52 if (targetClient == NULL) {
54 params.push_back(targetNick);
56 continue;
57 }
58
59 if (!channel->isMember(targetClient)) {
61 params.push_back(targetNick);
62 params.push_back(channelName);
63 client->sendMessage(
65 continue;
66 }
67
68 std::string kickMessage =
69 client->getPrefix() + " KICK " + channelName + " " + targetNick + " :" + reason + "\r\n";
70 channel->broadcast(kickMessage, NULL);
71
72 channel->removeMember(targetClient);
73 targetClient->removeChannel(channel);
74
75 if (channel->getMembers().empty()) {
76 _server->removeChannel(channelName);
77 }
78 }
79}
Manages channel members and states.
Manages client connection and state.
std::vector< std::string > split(const std::string &s, char delimiter)
Splits a string into a vector of strings based on a delimiter.
Utility functions for command handling.
Handles the KICK command.
std::string formatReply(const std::string &serverName, const std::string &clientNickname, const std::string &replyCodeAndText)
Formats an IRC reply message without extra parameters.
Definition Replies.cpp:14
Defines IRC numeric replies and error messages.
#define ERR_NOSUCHNICK
Definition Replies.hpp:64
#define ERR_CHANOPRIVSNEEDED
Definition Replies.hpp:80
#define ERR_NOSUCHCHANNEL
Definition Replies.hpp:65
#define ERR_USERNOTINCHANNEL
Definition Replies.hpp:74
#define ERR_NEEDMOREPARAMS
Definition Replies.hpp:76
Core IRC server implementation.
チャンネルのメンバーと状態を管理するクラス。
Definition Channel.hpp:25
const std::map< int, Client * > & getMembers() const
Definition Channel.cpp:24
bool isMember(Client *client) const
Definition Channel.cpp:37
void broadcast(const std::string &message, Client *excludeClient)
Definition Channel.cpp:39
bool isOperator(Client *client) const
Definition Channel.cpp:51
void removeMember(Client *client)
Definition Channel.cpp:32
Represents an IRC client connected to the server.
Definition Client.hpp:25
void removeChannel(Channel *channel)
Removes a channel from the client's list of joined channels.
Definition Client.cpp:83
std::string getPrefix() const
Generates the client's IRC prefix (e.g., :nick!user@host).
Definition Client.cpp:50
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
Abstract base class (interface) for all IRC commands.
Definition ICommand.hpp:26
Server * _server
Pointer to the IRC server instance.
Definition ICommand.hpp:28
void execute(Client *client, const std::vector< std::string > &args)
Executes the KICK command.
KickCommand(Server *server)
Constructs a KickCommand object.
Implements the core IRC server functionality as a Singleton.
Definition Server.hpp:49
Channel * getChannel(const std::string &name)
Retrieves a Channel object by its name.
Definition Server.cpp:406
Client * getClientByNickname(const std::string &nickname)
Retrieves a Client object by its nickname.
Definition Server.cpp:391
void removeChannel(const std::string &name)
Removes a channel from the server, deleting the Channel object.
Definition Server.cpp:414
const std::string & getServerName() const
Gets the server's name.
Definition Server.cpp:381
T empty(T... args)
T push_back(T... args)
T size(T... args)