IRC SERVER
The goal of this project is to make you write your own IRC server.
|
Go to the documentation of this file.
5 #include "../Command.hpp"
13 _description =
"Send message to a set of users/channels";
14 _usage =
"privmsg <receptor|channel>{,<receptor|channel>} :<texto>";
15 _example[0] =
"privmsg alfred hello";
16 _example[1] =
"privmsg alfred,manolo hello";
17 _example[2] =
"privmsg #uruguay :hola, buenas tardes";
18 _example[3] =
"privmsg #uruguay,#peru :hola, buenas tardes";
30 else if (p[0].at(0) ==
'#')
32 std::vector<std::string> _ch_params =
split(p[0],
",");
33 for (
size_t i = 0; i < _ch_params.size(); i++)
42 else if ((channel == NULL ||
56 std::vector<std::string> _cl_params =
split(p[0],
",");
57 for (
size_t i = 0; i < _cl_params.size(); i++)
67 std::string(
"You cannot send a message yourself!\n").c_str());
77 std::map<size_t, std::string> p = message->
getParams();
80 throw std::runtime_error(
84 std::string msg = std::string(p[1] +
"\n").c_str();
85 std::vector<std::string> _ch_params =
split(p[0],
",");
87 std::vector<Message> messages;
88 for (
size_t i = 0; i < _ch_params.size(); i++)
90 std::string tmp(this->
getName() +
" " + _ch_params[i] +
" :" + msg);
91 std::cout << tmp << std::endl;
92 messages.push_back(
Message(tmp));
100 std::string msg = std::string(p[1] +
"\n").c_str();
101 if (p[0].at(0) ==
'#')
103 std::vector<std::string> _ch_params =
split(p[0],
",");
104 for (
size_t i = 0; i < _ch_params.size(); i++)
106 std::string name = _ch_params[i].substr(1).c_str();
108 std::vector<Client *> clients = channel->
getClients();
109 for (
size_t j = 0; j < clients.size(); j++)
113 clients[j]->message(std::string(
":" +
_sender->
_nick +
" PRIVMSG #" +
114 channel->
getName() +
" :" + msg +
"\n")
122 std::vector<std::string> _cl_params =
split(p[0],
",");
123 for (
size_t i = 0; i < _cl_params.size(); i++)
Definition: Channel.hpp:26
std::string & getName(void)
Definition: Channel.hpp:82
bool isOpe(Client *client)
Definition: Channel.hpp:195
#define ERR_NOSUCHCHANNEL(servername, nick, channel)
Definition: Replies.hpp:107
std::string _description
Definition: Command.hpp:12
const std::string getNick(void) const
Definition: Client.hpp:142
std::string _name
Definition: Command.hpp:11
Definition: Command.hpp:7
std::string getCmd(void) const
Definition: message.cpp:74
void message(char const *message)
Definition: client.cpp:15
PrivMsg()
Definition: PrivMsg.hpp:10
#define ERR_CANNOTSENDTOCHAN(servername, nick, channel)
Definition: Replies.hpp:109
#define ERR_NOSUCHNICK(servername, nick)
Definition: Replies.hpp:104
Message * _message
Definition: Command.hpp:21
std::vector< std::string > split(const std::string &str, const std::string &delimiters)
Definition: functions.cpp:37
#define ERR_NEEDMOREPARAMS(servername, nick, command)
Definition: Replies.hpp:131
@ CHANNEL_MODE_CANT_SENT_MESSAGES_OUTSIDE
Definition: Channel.hpp:13
std::map< size_t, std::string > _example
Definition: Command.hpp:16
bool validate(void)
Definition: PrivMsg.hpp:21
std::string getName() const
Definition: Command.hpp:25
std::vector< Message > parser(Message *message)
Definition: PrivMsg.hpp:75
Client * getClient(std::string const &name)
Definition: Server.hpp:140
std::vector< Client * > getClients(void) const
Definition: Channel.hpp:172
bool joined(Client *client)
Definition: Channel.hpp:183
std::map< size_t, std::string > getParams(void) const
Definition: message.cpp:79
Definition: Message.hpp:12
void execute()
Definition: PrivMsg.hpp:97
Channel * getChannel(std::string &name)
Definition: Server.hpp:202
Definition: Client.hpp:22
std::string _usage
Definition: Command.hpp:13
bool hasMode(ChannelMode mode)
Definition: Channel.hpp:337
Client * _sender
Definition: Command.hpp:19
Definition: PrivMsg.hpp:7
std::string _nick
Definition: Client.hpp:26
bool isModerated(void)
Definition: Channel.hpp:393
std::string _servername
Definition: Client.hpp:30
Server * _server
Definition: Command.hpp:20