fix fix fix
This commit is contained in:
56
.vscode/settings.json
vendored
Normal file
56
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
30
Server.cpp
30
Server.cpp
@@ -560,7 +560,8 @@ void Server::handleClientData(int fd)
|
||||
std::cout << "Received data from client " << fd << ": " << command << std::endl;
|
||||
int auth = getClientByFd(fd).getAuthentication();
|
||||
|
||||
//******************* FROM THERE IM STARTING TOP GGG ************ .
|
||||
//******************* FROM THERE IM STARTING TOP GGG ************
|
||||
|
||||
if ((startsWith(command, "pass") || startsWith(command, "PASS")) && auth == 0)
|
||||
{
|
||||
std::string cmd, password;
|
||||
@@ -579,7 +580,34 @@ void Server::handleClientData(int fd)
|
||||
getClientByFd(fd).setAuthentication(1);
|
||||
}
|
||||
}
|
||||
else if (startsWith(command, "QUIT"))
|
||||
{
|
||||
// Iterate over channels
|
||||
std::map<std::string, Channel>::iterator it;
|
||||
for (it = channels.begin(); it != channels.end(); ++it)
|
||||
{
|
||||
Channel& channel = it->second;
|
||||
|
||||
std::string nickname = channel.getNickname(fd);
|
||||
// Check if the user is part of the channel
|
||||
if (channel.isUserInChannel(nickname))
|
||||
{
|
||||
// Mark the user as disconnected in the channel
|
||||
channel.ejectUserfromusers(fd);
|
||||
}
|
||||
}
|
||||
std::map<int, std::string>::iterator userIt;
|
||||
userIt = usernames.find(fd);
|
||||
if (userIt != usernames.end()) {
|
||||
usernames.erase(userIt);
|
||||
}
|
||||
std::map<int, std::string>::iterator nickIt;
|
||||
userIt = nicknames.find(fd);
|
||||
if (userIt != nicknames.end()) {
|
||||
nicknames.erase(userIt);
|
||||
}
|
||||
clientCleanup(fd);
|
||||
}
|
||||
else if (startsWith(command, "PING"))
|
||||
{
|
||||
std::istringstream iss(command);
|
||||
|
11
channel.cpp
11
channel.cpp
@@ -80,6 +80,17 @@ int Channel::getUserFd(const std::string& username) const {
|
||||
return -1; // Return -1 if username not found
|
||||
}
|
||||
|
||||
|
||||
bool Channel::isUserInChannel(const std::string& nickname) const {
|
||||
// Search for the nickname in the userMap
|
||||
std::map<std::string, int>::const_iterator it = userFdMap.find(nickname);
|
||||
// If the nickname is found and the user is connected, return true
|
||||
if (it != userFdMap.end() && it->second) {
|
||||
return true;
|
||||
}
|
||||
// Otherwise, return false
|
||||
return false;
|
||||
}
|
||||
// Get all clients' usernames in the channel
|
||||
std::vector<std::string> Channel::getClients() const {
|
||||
std::vector<std::string> clients;
|
||||
|
@@ -32,6 +32,7 @@ private:
|
||||
int opperatorfd;
|
||||
bool issettop;
|
||||
bool isinveted;
|
||||
bool channelconnect;
|
||||
|
||||
public:
|
||||
|
||||
@@ -62,6 +63,7 @@ public:
|
||||
void addClientinveted(const std::string& client, int fd);
|
||||
void addOperator(const std::string& operatorName, int fd);
|
||||
int getUserFd(const std::string& username) const;
|
||||
bool isUserInChannel(const std::string& nickname) const;
|
||||
std::vector<std::string> getClients() const;
|
||||
std::string getNickname(int fd) const;
|
||||
bool isOperator(int fd);
|
||||
|
Reference in New Issue
Block a user