IRC SERVER
The goal of this project is to make you write your own IRC server.
|
Go to the documentation of this file.
35 typedef std::map<size_t, Client *>::iterator clientMap_iterator;
36 typedef std::map<std::string, Channel *>::iterator channelMap_iterator;
37 typedef std::vector<pollfd>::iterator pollVector_iterator;
40 std::string
const host;
41 std::string
const servername;
42 std::string
const version;
43 std::string
const port;
44 std::string
const password;
69 Server(std::string host, std::string port, std::string password);
81 return (password !=
"");
95 std::vector<Channel *> channels = this->
getChannels();
96 std::vector<Client *> related_clients;
98 for (
size_t i = 0; i < channels.size(); i++)
100 if (channels[i]->joined(client))
102 std::vector<Client *> channel_clients = channels[i]->getClients();
103 for (
size_t u = 0; u < channel_clients.size(); u++)
105 if (channel_clients[u] != client &&
106 !std::count(related_clients.begin(), related_clients.end(), channel_clients[u]))
107 related_clients.push_back(channel_clients[u]);
111 return (related_clients);
116 std::map<std::string, Channel *> related_channels;
118 std::map<std::string, Channel *>::iterator it =
_channels.begin();
121 if (it->second->joined(client))
123 related_channels.insert(std::pair<std::string, Channel *>(it->first, it->second));
126 return (related_channels);
130 void createServerListener(
void);
131 void createServerPoll(
void);
132 void removeClientFromServer(
size_t clientId);
133 int readClient(
size_t &i);
134 void setupCommands(
void);
142 std::map<size_t, Client *>::iterator it =
_clients.begin();
145 if (it->second->_nick == name)
157 if (it->second->_fd == fd)
159 for (channelMap_iterator itc =
_channels.begin();
162 itc->second->removeClientFromChannel(it->second);
163 if (itc->second->getClients().size() == 0)
173 for (pollVector_iterator it2 =
_pfds.begin(); it2 !=
_pfds.end();)
191 for (
size_t i = 0; i <
_clients.size(); i++)
204 if (name.at(0) ==
'#')
205 name = name.substr(1);
214 std::vector<Channel *> channels;
215 std::map<std::string, Channel *>::iterator it;
217 channels.push_back(it->second);
223 if (name.at(0) ==
'#')
224 name = name.substr(1);
@ CLOSED
Definition: Server.hpp:61
Definition: Channel.hpp:26
@ ONLINE
Definition: Server.hpp:60
size_t getClientIndex(std::string &name)
Definition: Server.hpp:189
std::map< std::string, Command * > _commands
Definition: Server.hpp:51
std::vector< pollfd > _pfds
Definition: Server.hpp:65
Status
Definition: Server.hpp:57
~Server()
Definition: server.cpp:191
bool validate_args(int argc, char **argv)
Definition: validation.cpp:15
@ OFFLINE
Definition: Server.hpp:59
Definition: Command.hpp:7
std::vector< Client * > getRelatedClients(Client *client)
Definition: Server.hpp:93
std::map< std::string, Channel * > _channels
Definition: Server.hpp:54
Channel * createChannel(std::string &name, std::string &password)
Definition: Server.hpp:221
bool is_running(void)
Definition: Server.hpp:75
std::map< size_t, Client * > _clients
Definition: Server.hpp:48
std::vector< Channel * > getChannels(void)
Definition: Server.hpp:212
bool hasPassword(void)
Definition: Server.hpp:79
Command * getCommand(std::string &name)
Definition: Server.hpp:232
int _fd
Definition: Server.hpp:66
void deleteClient(int fd)
Definition: Server.hpp:153
const std::string getPassword(void)
Definition: Server.hpp:83
Server(std::string host, std::string port, std::string password)
Here we init the server instance.
Definition: server.cpp:162
enum Server::Status _status
Client * getClient(std::string const &name)
Definition: Server.hpp:140
Channel * getChannel(std::string &name)
Definition: Server.hpp:202
Definition: Client.hpp:22
const std::string getServerName(void)
Definition: Server.hpp:88
std::map< std::string, Channel * > getRelatedChannels(Client *client)
Definition: Server.hpp:114
Definition: Server.hpp:32