fixed ctrl+D bug

This commit is contained in:
Bettercallous
2024-04-29 16:06:48 +01:00
parent 23f12a5e61
commit 9abced38a0
5 changed files with 32 additions and 74 deletions

56
.vscode/settings.json vendored
View File

@@ -1,56 +0,0 @@
{
"files.associations": {
"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",
"cstring": "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"
}
}

View File

@@ -16,7 +16,6 @@ std::string Client::getPassowrd() const {
return pass;
}
// Implementation of getter and setter functions for name
std::string Client::getName() const {
return name;
}
@@ -25,7 +24,6 @@ void Client::setName(const std::string& newName) {
name = newName;
}
// Implementation of getter and setter functions for nick
std::string Client::getNick() const {
return nick;
}
@@ -34,7 +32,6 @@ void Client::setNick(const std::string& newNick) {
nick = newNick;
}
// Implementation of getter and setter functions for user
std::string Client::getUser() const {
return user;
}
@@ -50,3 +47,15 @@ int Client::getAuthentication() const {
void Client::setAuthentication(int auth) {
_authentication = auth;
}
void Client::appendToCommand(std::string toAppend) {
command += toAppend;
}
const std::string& Client::getCommand() const {
return command;
}
void Client::clearCommand() {
command.clear();
}

View File

@@ -10,6 +10,7 @@ class Client {
std::string name;
std::string nick;
std::string user;
std::string command;
int _authentication;
public:
Client();
@@ -18,22 +19,25 @@ class Client {
int getFd() const;
std::string getPassowrd() const;
void setPassword(const std::string& password); // Function to set the password
// Getter and setter for name
void setPassword(const std::string& password);
std::string getName() const;
void setName(const std::string& newName);
// Getter and setter for nick
std::string getNick() const;
void setNick(const std::string& newNick);
// Getter and setter for user
std::string getUser() const;
void setUser(const std::string& newUser);
int getAuthentication() const;
void setAuthentication(int auth);
void appendToCommand(std::string toAppend);
const std::string& getCommand() const;
void clearCommand();
};
#endif

View File

@@ -224,7 +224,7 @@ void Server::createChannel(const std::string& channelName, const std::string& ni
}
// Channel already exists, just add the user to it
// Channel already exists, just add the user to it
it->second.addClient(nickname, fd);
std::string operators = channels[channelName].getOperatorNickname(opperatorfd);
std::string operators1 = channels[channelName].getOperatorNickname(abaaba);
@@ -518,12 +518,11 @@ int stringToInt(const std::string& str) {
void Server::handleClientData(int fd)
{
std::string command;
char buffer[BUFFER_SIZE];
memset(buffer, 0, sizeof(buffer));
ssize_t bytesRead;
while ((bytesRead = recv(fd, buffer, BUFFER_SIZE - 1, 0)) > 0) {
ssize_t bytesRead = recv(fd, buffer, BUFFER_SIZE - 1, 0);
if (bytesRead > 0) {
bool foundEof = false;
for (ssize_t i = 0; i < bytesRead; ++i) {
if (buffer[i] == '\n') {
@@ -534,9 +533,12 @@ void Server::handleClientData(int fd)
if (!foundEof) {
buffer[bytesRead] = '\0';
command += buffer;
getClientByFd(fd).appendToCommand(buffer);
return;
} else {
command.append(buffer, bytesRead - 1);
buffer[bytesRead] = '\0';
getClientByFd(fd).appendToCommand(buffer);
std::string command = getClientByFd(fd).getCommand();
std::cout << "Received data from client " << fd << ": " << command << std::endl;
int auth = getClientByFd(fd).getAuthentication();
@@ -1140,10 +1142,9 @@ void Server::handleClientData(int fd)
}
}
}
//**************** STOOOOOOP HERE TOP G ...
break;
}
getClientByFd(fd).clearCommand();
}
if (bytesRead == 0) {

View File

@@ -38,9 +38,9 @@ class Server {
std::vector<struct pollfd> _fds;
std::vector<Client> _clients;
// THAT'S THA DATA OF TOOOP GGG START FROM THERE .
std::map<int, std::string> nicknames; // Replace unordered_map with map
std::map<int, std::string> usernames; // Replace unordered_map with map
// std::map<std::string, std::vector<std::string> > channels; //here a chanel name and list of client in every chanel
std::map<int, std::string> nicknames;
std::map<int, std::string> usernames;
std::map<std::string, Channel> channels;