ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
WhoisCommand.cpp
[詳解]
1
8#include "WhoisCommand.hpp"
9#include "Channel.hpp"
10#include "Client.hpp"
11#include "Replies.hpp"
12#include "Server.hpp"
13#include <ctime> // For std::time
14#include <sstream>
15
17
19 if (args.empty()) {
22 return;
23 }
24
25 const std::string &targetNick = args[0];
26 Client *targetClient = _server->getClientByNickname(targetNick);
27
28 if (targetClient == NULL) {
30 params.push_back(targetNick);
32 return;
33 }
34
35 // RPL_WHOISUSER (311)
36 {
38 params.push_back(targetClient->getNickname());
39 params.push_back(targetClient->getUsername());
40 params.push_back(targetClient->getHostname());
41 params.push_back("*"); // Unused parameter
42 params.push_back(targetClient->getRealname()); // Use the actual real name
44 }
45
46 // RPL_WHOISCHANNELS (319)
47 {
48 std::string channelList;
49 const std::vector<Channel *> &channels = targetClient->getChannels();
50 for (size_t i = 0; i < channels.size(); ++i) {
51 if (channels[i]->isOperator(targetClient)) {
52 channelList += "@";
53 }
54 channelList += channels[i]->getName();
55 if (i < channels.size() - 1) {
56 channelList += " ";
57 }
58 }
59 if (!channelList.empty()) {
61 params.push_back(targetClient->getNickname());
62 params.push_back(channelList);
63 client->sendMessage(
65 }
66 }
67
68 // RPL_WHOISIDLE (317)
69 {
70 std::stringstream idleSeconds;
71 idleSeconds << (std::time(NULL) - targetClient->getLastActivityTime());
73 params.push_back(targetClient->getNickname());
74 params.push_back(idleSeconds.str());
76 }
77
78 // RPL_ENDOFWHOIS (318)
79 {
81 params.push_back(targetClient->getNickname());
83 }
84}
Manages channel members and states.
Manages client connection and state.
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 RPL_WHOISCHANNELS
Definition Replies.hpp:59
#define RPL_ENDOFWHOIS
Definition Replies.hpp:61
#define RPL_WHOISIDLE
Definition Replies.hpp:60
#define RPL_WHOISUSER
Definition Replies.hpp:58
#define ERR_NONICKNAMEGIVEN
Definition Replies.hpp:71
Core IRC server implementation.
Handles the WHOIS command.
Represents an IRC client connected to the server.
Definition Client.hpp:25
const std::vector< Channel * > & getChannels() const
Gets the list of channels the client is in.
Definition Client.cpp:43
const std::string & getRealname() const
Gets the client's real name.
Definition Client.cpp:39
std::time_t getLastActivityTime() const
Gets the timestamp of the client's last activity.
Definition Client.cpp:45
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
const std::string & getHostname() const
Gets the client's hostname.
Definition Client.cpp:29
const std::string & getUsername() const
Gets the client's username.
Definition Client.cpp:27
Abstract base class (interface) for all IRC commands.
Definition ICommand.hpp:26
Server * _server
Pointer to the IRC server instance.
Definition ICommand.hpp:28
Implements the core IRC server functionality as a Singleton.
Definition Server.hpp:49
Client * getClientByNickname(const std::string &nickname)
Retrieves a Client object by its nickname.
Definition Server.cpp:391
const std::string & getServerName() const
Gets the server's name.
Definition Server.cpp:381
void execute(Client *client, const std::vector< std::string > &args)
Executes the WHOIS command.
WhoisCommand(Server *server)
Constructs a WhoisCommand object.
T empty(T... args)
T push_back(T... args)
T size(T... args)
T str(T... args)
T time(T... args)