ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
ListCommand.cpp
[詳解]
1
8#include "ListCommand.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 <sstream>
15#include <string>
16#include <vector>
17
19
21 // RPL_LISTSTART
22 client->sendMessage(
24
25 if (args.empty()) {
26 // List all channels
28 for (std::map<std::string, Channel *>::const_iterator it = channels.begin(); it != channels.end(); ++it) {
29 Channel *channel = it->second;
31 ss << channel->getMembers().size();
32 std::vector<std::string> list_params;
33 list_params.push_back(channel->getName());
34 list_params.push_back(ss.str());
35 list_params.push_back(channel->getTopic());
36 client->sendMessage(formatReply(_server->getServerName(), client->getNickname(), RPL_LIST, list_params));
37 }
38 } else {
39 // List specified channels
40 std::vector<std::string> channelNames = split(args[0], ',');
41 for (size_t i = 0; i < channelNames.size(); ++i) {
42 Channel *channel = _server->getChannel(channelNames[i]);
43 if (channel) {
45 ss << channel->getMembers().size();
46 std::vector<std::string> list_params;
47 list_params.push_back(channel->getName());
48 list_params.push_back(ss.str());
49 list_params.push_back(channel->getTopic());
50 client->sendMessage(
51 formatReply(_server->getServerName(), client->getNickname(), RPL_LIST, list_params));
52 }
53 }
54 }
55
56 // RPL_LISTEND
57 client->sendMessage(
59}
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 LIST 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 RPL_LISTSTART
Definition Replies.hpp:50
#define RPL_LISTEND
Definition Replies.hpp:52
#define RPL_LIST
Definition Replies.hpp:51
Core IRC server implementation.
T begin(T... args)
チャンネルのメンバーと状態を管理するクラス。
Definition Channel.hpp:25
const std::map< int, Client * > & getMembers() const
Definition Channel.cpp:24
const std::string & getName() const
Definition Channel.cpp:22
const std::string & getTopic() const
Definition Channel.cpp:26
Represents an IRC client connected to the server.
Definition Client.hpp:25
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 LIST command.
ListCommand(Server *server)
Constructs a ListCommand 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
const std::map< std::string, Channel * > & getChannels() const
Gets a constant reference to the map of channels managed by the server.
Definition Server.cpp:422
const std::string & getServerName() const
Gets the server's name.
Definition Server.cpp:381
T empty(T... args)
T end(T... args)
T push_back(T... args)
T size(T... args)
T str(T... args)