diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 89bff54..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "files.associations": { - "cstring": "cpp", - "iostream": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "map": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "numbers": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/Client.cpp b/Client.cpp index 8270496..914a3ff 100644 --- a/Client.cpp +++ b/Client.cpp @@ -2,13 +2,12 @@ Client::Client() : _isRegistered(false) {} -Client::Client(int fd, std::string addr) : _fd(fd), _addr(addr) {} +Client::Client(int fd) : _fd(fd) {} Client::~Client() {} int Client::getFd() const {return _fd;} - void Client::setPassword(const std::string& password) { pass = password; } diff --git a/Client.hpp b/Client.hpp index 0d67e8e..068565f 100644 --- a/Client.hpp +++ b/Client.hpp @@ -10,11 +10,10 @@ class Client { std::string name; std::string nick; std::string user; - std::string _addr; bool _isRegistered; public: Client(); - Client(int fd, std::string addr); + Client(int fd); ~Client(); int getFd() const; diff --git a/Server.cpp b/Server.cpp index 732e95e..e721372 100644 --- a/Server.cpp +++ b/Server.cpp @@ -37,7 +37,7 @@ void Server::parseArgs(int ac, char **av) { throw std::runtime_error("Error: Invalid arguments"); long _port = atol(av[1]); - if (!(_port >= 1 && _port <= 65535)) + if (!(_port >= 0 && _port <= 65535)) throw std::runtime_error("Error: Invalid arguments"); if (pwd.empty()) @@ -96,7 +96,7 @@ void Server::createServerSocket() { if (listen(_serverSocketFd, SOMAXCONN) == -1) throw std::runtime_error("Error: listen() failed"); - addPollfd(_serverSocketFd, POLLIN, 0); + addPollfd(_serverSocketFd); } void Server::bindServerSocket() { @@ -109,11 +109,11 @@ void Server::bindServerSocket() { } } -void Server::addPollfd(int fd, short events, short revents) { +void Server::addPollfd(int fd) { struct pollfd newPollfd; newPollfd.fd = fd; - newPollfd.events = events; - newPollfd.revents = revents; + newPollfd.events = POLLIN; + newPollfd.revents = 0; _fds.push_back(newPollfd); } @@ -145,8 +145,8 @@ std::string art = send(newFd, art.c_str(), art.length(), 0); send(newFd, passwordRequest.c_str(), passwordRequest.length(), 0); - addPollfd(newFd, POLLIN, 0); - _clients.push_back(Client(newFd, inet_ntoa((client_addr.sin_addr)))); + addPollfd(newFd); + _clients.push_back(Client(newFd)); std::cout << "Client <" << newFd << "> Connected" << std::endl; } diff --git a/Server.hpp b/Server.hpp index 0131352..5676f8a 100644 --- a/Server.hpp +++ b/Server.hpp @@ -84,7 +84,7 @@ class Server { void createServerSocket(); void bindServerSocket(); - void addPollfd(int fd, short events, short revents); + void addPollfd(int fd); void handleClientConnection(); void handleClientData(int fd); void clientCleanup(int fd);