ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
PartCommand.cpp
[詳解]
1
8#include "PartCommand.hpp"
9#include "Channel.hpp"
10#include "Client.hpp"
11#include "CommandUtils.hpp" // For split
12#include "Replies.hpp"
13#include "Server.hpp"
14
16
18 if (args.empty()) {
20 params.push_back("PART");
22 return;
23 }
24
25 std::vector<std::string> channels = split(args[0], ',');
26 std::string partMessageSuffix = (args.size() > 1) ? " :" + args[1] : "";
27
28 for (size_t i = 0; i < channels.size(); ++i) {
29 const std::string &channelName = channels[i];
30
31 Channel *channel = _server->getChannel(channelName);
32 if (channel == NULL) {
34 params.push_back(channelName);
35 client->sendMessage(
37 continue;
38 }
39
40 if (!channel->isMember(client)) {
42 params.push_back(channelName);
44 continue;
45 }
46
47 std::string partMessage = client->getPrefix() + " PART " + channelName + partMessageSuffix + "\r\n";
48 channel->broadcast(partMessage, NULL); // Broadcast to all including the client
49
50 channel->removeMember(client);
51 client->removeChannel(channel);
52
53 if (channel->getMembers().empty()) {
54 _server->removeChannel(channelName);
55 }
56 }
57}
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 PART 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_NOTONCHANNEL
Definition Replies.hpp:75
#define ERR_NOSUCHCHANNEL
Definition Replies.hpp:65
#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
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 PART command.
PartCommand(Server *server)
Constructs a PartCommand 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
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)