ft_irc 1.0
読み取り中…
検索中…
一致する文字列を見つけられません
InviteCommand.cpp
[詳解]
1
8#include "InviteCommand.hpp"
9#include "Channel.hpp"
10#include "Client.hpp"
11#include "Replies.hpp"
12#include "Server.hpp"
13
15
17 if (args.size() < 2) {
19 params.push_back("INVITE");
21 return;
22 }
23
24 const std::string &targetNick = args[0];
25 const std::string &channelName = args[1];
26
27 Client *targetClient = _server->getClientByNickname(targetNick);
28 if (targetClient == NULL) {
30 params.push_back(targetNick);
32 return;
33 }
34
35 Channel *channel = _server->getChannel(channelName);
36 if (channel == NULL) {
38 params.push_back(channelName);
40 return;
41 }
42
43 if (!channel->isMember(client)) {
45 params.push_back(channelName);
47 return;
48 }
49
50 if (channel->hasMode('i') && !channel->isOperator(client)) {
52 params.push_back(channelName);
54 return;
55 }
56
57 if (channel->isMember(targetClient)) {
59 params.push_back(targetNick);
60 params.push_back(channelName);
62 return;
63 }
64
65 // Add target client to the channel's invited list
66 channel->addInvitedUser(targetClient);
67
68 // Notify the invited client
69 std::string inviteMessage = client->getPrefix() + " INVITE " + targetNick + " :" + channelName + "\r\n";
70 targetClient->sendMessage(inviteMessage);
71
72 // Optionally, notify the inviter (RPL_INVITING is not strictly required by RFC, but good practice)
73 // client->sendMessage(formatReply(_server->getServerName(), client->getNickname(), RPL_INVITING, targetNick,
74 // channelName));
75}
Manages channel members and states.
Manages client connection and state.
Handles the INVITE 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_USERONCHANNEL
Definition Replies.hpp:84
#define ERR_NOTONCHANNEL
Definition Replies.hpp:75
#define ERR_NOSUCHNICK
Definition Replies.hpp:64
#define ERR_CHANOPRIVSNEEDED
Definition Replies.hpp:80
#define ERR_NOSUCHCHANNEL
Definition Replies.hpp:65
#define ERR_NEEDMOREPARAMS
Definition Replies.hpp:76
Core IRC server implementation.
チャンネルのメンバーと状態を管理するクラス。
Definition Channel.hpp:25
bool hasMode(char mode) const
Definition Channel.cpp:59
bool isMember(Client *client) const
Definition Channel.cpp:37
void addInvitedUser(Client *client)
Definition Channel.cpp:87
bool isOperator(Client *client) const
Definition Channel.cpp:51
Represents an IRC client connected to the server.
Definition Client.hpp:25
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 INVITE command.
InviteCommand(Server *server)
Constructs an InviteCommand 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
const std::string & getServerName() const
Gets the server's name.
Definition Server.cpp:381
T push_back(T... args)
T size(T... args)