mirror of
https://github.com/Ladebeze66/ft_irc.git
synced 2025-12-17 06:28:03 +01:00
modif
This commit is contained in:
parent
0c3c24a2f1
commit
2e8f987c0f
@ -44,6 +44,9 @@ public:
|
||||
std::string getKey() const;
|
||||
void setkey(const std::string &key);
|
||||
|
||||
char buffer[1024];
|
||||
char buffer2[1024];
|
||||
|
||||
private:
|
||||
int _fd;
|
||||
std::string _nickname;
|
||||
|
||||
@ -42,6 +42,7 @@ class ClientManager
|
||||
public:
|
||||
ClientManager(Server *server);
|
||||
void acceptClient();
|
||||
void handleClientNext(int client_fd, char * buffer, int bytes_received);
|
||||
void handleClient(int client_fd);
|
||||
void removeClient(int client_fd);
|
||||
|
||||
|
||||
@ -59,7 +59,6 @@ class Server
|
||||
void broadcast(const std::string &message);
|
||||
Client* getClientByName(const std::string &name);
|
||||
Channel* getChannelByName(const std::string &name);
|
||||
void sendChannelListToClient(Client *client);
|
||||
void disconnectClient(int clientFd);
|
||||
bool MatchFd(const pollfd& pfd, int clientFd);
|
||||
void removePollFd(int clientFd);
|
||||
|
||||
BIN
ft_irc3/ircserv
Normal file
BIN
ft_irc3/ircserv
Normal file
Binary file not shown.
0
ft_irc3/logs/irc_server.log
Normal file
0
ft_irc3/logs/irc_server.log
Normal file
BIN
ft_irc3/obj/AdditionalCommands.o
Normal file
BIN
ft_irc3/obj/AdditionalCommands.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Channel.o
Normal file
BIN
ft_irc3/obj/Channel.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Client.o
Normal file
BIN
ft_irc3/obj/Client.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/ClientManager.o
Normal file
BIN
ft_irc3/obj/ClientManager.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/CommandHandler.o
Normal file
BIN
ft_irc3/obj/CommandHandler.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/InviteHandler.o
Normal file
BIN
ft_irc3/obj/InviteHandler.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Join.o
Normal file
BIN
ft_irc3/obj/Join.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/KickHandler.o
Normal file
BIN
ft_irc3/obj/KickHandler.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/ModeHandler.o
Normal file
BIN
ft_irc3/obj/ModeHandler.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Server.o
Normal file
BIN
ft_irc3/obj/Server.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/TopicHandler.o
Normal file
BIN
ft_irc3/obj/TopicHandler.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Utils.o
Normal file
BIN
ft_irc3/obj/Utils.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Welcome.o
Normal file
BIN
ft_irc3/obj/Welcome.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/Who.o
Normal file
BIN
ft_irc3/obj/Who.o
Normal file
Binary file not shown.
BIN
ft_irc3/obj/main.o
Normal file
BIN
ft_irc3/obj/main.o
Normal file
Binary file not shown.
@ -65,7 +65,7 @@ void AdditionalCommands::broadcastChannelList(Client *client, Server *server)
|
||||
std::map<std::string, Channel *> &channels = server->getChannels();
|
||||
for (std::map<std::string, Channel *>::iterator it = channels.begin(); it != channels.end(); ++it)
|
||||
{
|
||||
server->sendToClient(client->getFd(), RPL_LIST(client, it->first, it->second->getClients().size(), "Existing channel"));
|
||||
server->sendToClient(client->getFd(), RPL_LIST(client, it->first, it->second->getClients().size(), it->second->getTopic()));
|
||||
}
|
||||
server->sendToClient(client->getFd(), RPL_LISTEND(client));
|
||||
}
|
||||
|
||||
@ -38,9 +38,12 @@ void ClientManager::acceptClient()
|
||||
|
||||
void ClientManager::handleClient(int client_fd)
|
||||
{
|
||||
char buffer[1024];
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
int bytes_received = recv(client_fd, buffer, sizeof(buffer), 0);
|
||||
Client* client = _server->getClients()[client_fd];
|
||||
// char buffer[1024];
|
||||
// char buffer2[1024];
|
||||
|
||||
std::memset(client->buffer, 0, sizeof(client->buffer));
|
||||
int bytes_received = recv(client_fd, client->buffer, sizeof(client->buffer), 0);
|
||||
|
||||
if (bytes_received <= 0)
|
||||
{
|
||||
@ -51,6 +54,34 @@ void ClientManager::handleClient(int client_fd)
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << std::string(client->buffer).size() << " client->buffer " << std::string(client->buffer).find('\n') << std::endl;
|
||||
|
||||
for (size_t i = 0; client->buffer[i];i++)
|
||||
{
|
||||
std::cout << client->buffer[i] << " .. ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
if (std::string(client->buffer).find('\n') != std::string::npos)
|
||||
{
|
||||
strcat(client->buffer2, client->buffer);
|
||||
handleClientNext(client_fd, client->buffer2, std::string(client->buffer2).size());
|
||||
std::memset(client->buffer2, 0, std::string(client->buffer2).size());
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat(client->buffer2, client->buffer);
|
||||
for (size_t i = 0; client->buffer2[i];i++)
|
||||
{
|
||||
std::cout << client->buffer2[i] << " . ";
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void ClientManager::handleClientNext(int client_fd, char * buffer, int bytes_received)
|
||||
{
|
||||
std::string message(buffer, bytes_received);
|
||||
std::ostringstream oss;
|
||||
oss << "Received from client " << client_fd << ": " << message;
|
||||
|
||||
@ -201,6 +201,7 @@ void CommandHandler::handleNick(Client* client, const std::vector<std::string>&
|
||||
std::string nickMessage = ":" + oldNick + " NICK " + newNick + "\r\n";
|
||||
for (std::map<int, Client*>::iterator it = _server->_clients.begin(); it != _server->_clients.end(); ++it)
|
||||
{
|
||||
if (it->second->isAuthenticated())
|
||||
_server->sendToClient(it->second->getFd(), nickMessage);
|
||||
}
|
||||
|
||||
|
||||
@ -218,16 +218,6 @@ Channel* Server::getChannelByName(const std::string &name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Server::sendChannelListToClient(Client *client)
|
||||
{
|
||||
std::map<std::string, Channel *> &channels = getChannels();
|
||||
for (std::map<std::string, Channel *>::iterator it = channels.begin(); it != channels.end(); ++it)
|
||||
{
|
||||
sendToClient(client->getFd(), RPL_LIST(client, it->first, it->second->getClients().size(), "Existing channel"));
|
||||
}
|
||||
sendToClient(client->getFd(), RPL_LISTEND(client));
|
||||
}
|
||||
|
||||
bool Server::MatchFd(const pollfd& pfd, int clientFd)
|
||||
{
|
||||
return pfd.fd == clientFd;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user