This commit is contained in:
jcheca 2024-06-04 15:23:43 +02:00
parent 0c3c24a2f1
commit 2e8f987c0f
24 changed files with 42 additions and 17 deletions

View File

@ -43,6 +43,9 @@ public:
void setAway(bool away);
std::string getKey() const;
void setkey(const std::string &key);
char buffer[1024];
char buffer2[1024];
private:
int _fd;

View File

@ -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);

View File

@ -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

Binary file not shown.

View File

Binary file not shown.

BIN
ft_irc3/obj/Channel.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/Client.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/ClientManager.o Normal file

Binary file not shown.

Binary file not shown.

BIN
ft_irc3/obj/InviteHandler.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/Join.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/KickHandler.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/ModeHandler.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/Server.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/TopicHandler.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/Utils.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/Welcome.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/Who.o Normal file

Binary file not shown.

BIN
ft_irc3/obj/main.o Normal file

Binary file not shown.

View File

@ -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));
}

View File

@ -38,10 +38,13 @@ 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)
{
std::ostringstream oss;
@ -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;

View File

@ -201,7 +201,8 @@ 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)
{
_server->sendToClient(it->second->getFd(), nickMessage);
if (it->second->isAuthenticated())
_server->sendToClient(it->second->getFd(), nickMessage);
}
std::ostringstream oss;

View File

@ -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;