fixed ctrl+D bug
This commit is contained in:
56
.vscode/settings.json
vendored
56
.vscode/settings.json
vendored
@@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
15
Client.cpp
15
Client.cpp
@@ -16,7 +16,6 @@ std::string Client::getPassowrd() const {
|
|||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of getter and setter functions for name
|
|
||||||
std::string Client::getName() const {
|
std::string Client::getName() const {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@@ -25,7 +24,6 @@ void Client::setName(const std::string& newName) {
|
|||||||
name = newName;
|
name = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of getter and setter functions for nick
|
|
||||||
std::string Client::getNick() const {
|
std::string Client::getNick() const {
|
||||||
return nick;
|
return nick;
|
||||||
}
|
}
|
||||||
@@ -34,7 +32,6 @@ void Client::setNick(const std::string& newNick) {
|
|||||||
nick = newNick;
|
nick = newNick;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of getter and setter functions for user
|
|
||||||
std::string Client::getUser() const {
|
std::string Client::getUser() const {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
@@ -50,3 +47,15 @@ int Client::getAuthentication() const {
|
|||||||
void Client::setAuthentication(int auth) {
|
void Client::setAuthentication(int auth) {
|
||||||
_authentication = auth;
|
_authentication = auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::appendToCommand(std::string toAppend) {
|
||||||
|
command += toAppend;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Client::getCommand() const {
|
||||||
|
return command;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::clearCommand() {
|
||||||
|
command.clear();
|
||||||
|
}
|
12
Client.hpp
12
Client.hpp
@@ -10,6 +10,7 @@ class Client {
|
|||||||
std::string name;
|
std::string name;
|
||||||
std::string nick;
|
std::string nick;
|
||||||
std::string user;
|
std::string user;
|
||||||
|
std::string command;
|
||||||
int _authentication;
|
int _authentication;
|
||||||
public:
|
public:
|
||||||
Client();
|
Client();
|
||||||
@@ -18,22 +19,25 @@ class Client {
|
|||||||
|
|
||||||
int getFd() const;
|
int getFd() const;
|
||||||
std::string getPassowrd() const;
|
std::string getPassowrd() const;
|
||||||
void setPassword(const std::string& password); // Function to set the password
|
void setPassword(const std::string& password);
|
||||||
// Getter and setter for name
|
|
||||||
std::string getName() const;
|
std::string getName() const;
|
||||||
void setName(const std::string& newName);
|
void setName(const std::string& newName);
|
||||||
|
|
||||||
// Getter and setter for nick
|
|
||||||
std::string getNick() const;
|
std::string getNick() const;
|
||||||
void setNick(const std::string& newNick);
|
void setNick(const std::string& newNick);
|
||||||
|
|
||||||
// Getter and setter for user
|
|
||||||
std::string getUser() const;
|
std::string getUser() const;
|
||||||
void setUser(const std::string& newUser);
|
void setUser(const std::string& newUser);
|
||||||
|
|
||||||
int getAuthentication() const;
|
int getAuthentication() const;
|
||||||
void setAuthentication(int auth);
|
void setAuthentication(int auth);
|
||||||
|
|
||||||
|
void appendToCommand(std::string toAppend);
|
||||||
|
|
||||||
|
const std::string& getCommand() const;
|
||||||
|
|
||||||
|
void clearCommand();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
17
Server.cpp
17
Server.cpp
@@ -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);
|
it->second.addClient(nickname, fd);
|
||||||
std::string operators = channels[channelName].getOperatorNickname(opperatorfd);
|
std::string operators = channels[channelName].getOperatorNickname(opperatorfd);
|
||||||
std::string operators1 = channels[channelName].getOperatorNickname(abaaba);
|
std::string operators1 = channels[channelName].getOperatorNickname(abaaba);
|
||||||
@@ -518,12 +518,11 @@ int stringToInt(const std::string& str) {
|
|||||||
|
|
||||||
void Server::handleClientData(int fd)
|
void Server::handleClientData(int fd)
|
||||||
{
|
{
|
||||||
std::string command;
|
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
||||||
ssize_t bytesRead;
|
ssize_t bytesRead = recv(fd, buffer, BUFFER_SIZE - 1, 0);
|
||||||
while ((bytesRead = recv(fd, buffer, BUFFER_SIZE - 1, 0)) > 0) {
|
if (bytesRead > 0) {
|
||||||
bool foundEof = false;
|
bool foundEof = false;
|
||||||
for (ssize_t i = 0; i < bytesRead; ++i) {
|
for (ssize_t i = 0; i < bytesRead; ++i) {
|
||||||
if (buffer[i] == '\n') {
|
if (buffer[i] == '\n') {
|
||||||
@@ -534,9 +533,12 @@ void Server::handleClientData(int fd)
|
|||||||
|
|
||||||
if (!foundEof) {
|
if (!foundEof) {
|
||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
command += buffer;
|
getClientByFd(fd).appendToCommand(buffer);
|
||||||
|
return;
|
||||||
} else {
|
} 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;
|
std::cout << "Received data from client " << fd << ": " << command << std::endl;
|
||||||
int auth = getClientByFd(fd).getAuthentication();
|
int auth = getClientByFd(fd).getAuthentication();
|
||||||
|
|
||||||
@@ -1140,10 +1142,9 @@ void Server::handleClientData(int fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//**************** STOOOOOOP HERE TOP G ...
|
//**************** STOOOOOOP HERE TOP G ...
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
getClientByFd(fd).clearCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
|
@@ -38,9 +38,9 @@ class Server {
|
|||||||
std::vector<struct pollfd> _fds;
|
std::vector<struct pollfd> _fds;
|
||||||
std::vector<Client> _clients;
|
std::vector<Client> _clients;
|
||||||
// THAT'S THA DATA OF TOOOP GGG START FROM THERE .
|
// 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> nicknames;
|
||||||
std::map<int, std::string> usernames; // Replace unordered_map with map
|
std::map<int, std::string> usernames;
|
||||||
// std::map<std::string, std::vector<std::string> > channels; //here a chanel name and list of client in every chanel
|
|
||||||
std::map<std::string, Channel> channels;
|
std::map<std::string, Channel> channels;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user