make the nickname and username nicked in the server don't worry about that

This commit is contained in:
mochaoui
2024-04-22 06:59:47 -05:00
parent 11789fe633
commit 099af1ff3f
4 changed files with 393 additions and 435 deletions

View File

@@ -24,172 +24,58 @@ private:
std::string Channelname;
std::string topic;
std::string key;
std::vector<std::string> users;
std::string pass;
// std::map<int, std::string> nicknames; // Replace unordered_map with map
std::map<std::string, int> userFdMap; // Mapping of usernames to file descriptors
std::map<std::string, int> invitedUsers;
std::map<std::string, int> operators;
int opperatorfd;
bool issettop;
bool isinveted;
public:
// Constructors
Channel() {}
Channel(const std::string& name) : Channelname(name) {}
Channel();
Channel(const std::string& name);
~Channel();
void setTopic(const std::string& newTopic);
std::string getTopic() const;
// Destructor
~Channel() {}
//checks
void setoperator(int value);
bool getoperator();
//checks
void setbooltopic(bool value);
bool getbooltopic();
//checks
void setboolinvited(bool value);
bool getboolinvited();
void setTopic(const std::string& newTopic) {
topic = newTopic;
}
void addClient(const std::string& client, int fd);
void addClientinveted(const std::string& client, int fd);
void addOperator(const std::string& operatorName, int fd);
int getUserFd(const std::string& username) const;
std::vector<std::string> getClients() const;
std::string getNickname(int fd) const;
bool isOperator(int fd);
bool isInvited(std::string nickname);
int findUserFdForKickRegulars(const std::string& username);
void ejectUserfromusers(int fd);
void ejectUserfromivited(std::string nickname);
std::string getOperatorNickname(int fd) const;
void removeOperator(const std::string& operatorName );
void setPass(const std::string &Newpass)
{
pass = Newpass;
}
// Get topic function
std::string getTopic() const {
return topic;
}
std::string getPass()
{
return pass;
}
void addClient(const std::string& client, int fd) {
userFdMap[client] = fd;
}
void addClientinveted(const std::string& client, int fd) {
invitedUsers[client] = fd;
}
// Add an operator to the channel
void addOperator(const std::string& operatorName, int fd) {
// Store the operator name and file descriptor in the map
operators[operatorName] = fd;
}
int getUserFd(const std::string& username) const {
std::map<std::string, int>::const_iterator it = userFdMap.find(username);
if (it != userFdMap.end()) {
return it->second;
}
return -1; // Return -1 if username not found
}
// Get all clients' usernames in the channel
std::vector<std::string> getClients() const {
std::vector<std::string> clients;
std::map<std::string, int>::const_iterator it;
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
clients.push_back(it->first);
}
return clients;
}
std::string getNickname(int fd) const {
std::map<std::string, int>::const_iterator it;
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
if (it->second == fd) {
return it->first; // Return the nickname if the file descriptor matches
}
}
return ""; // Return an empty string if the file descriptor is not found
}
bool isOperator(int fd) {
// Iterate through the map of operators
for (std::map<std::string, int>::iterator it = operators.begin(); it != operators.end(); ++it) {
// Check if the file descriptor matches
if (it->second == fd) {
return true; // Found the file descriptor in the map
}
}
return false; // File descriptor not found in the map
}
bool isInvited(std::string nickname) {
// Iterate through the map of operators
for (std::map<std::string, int>::iterator it = invitedUsers.begin(); it != invitedUsers.end(); ++it) {
// Check if the file descriptor matches
if (it->first == nickname) {
return true; // Found the file descriptor in the map
}
}
return false; // File descriptor not found in the map
}
int findUserFdForKickRegulars(const std::string& username) {
// Iterate through the userFdMap to find the user
std::map<std::string, int>::iterator it;
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
if (it->first == username) {
return it->second; // Return the file descriptor if the username matches
}
}
return -1; // Return -1 if the user is not found
}
void ejectUserfromusers(int fd) {
// Iterate over the map to find the user with the given file descriptor
std::map<std::string, int>::iterator it;
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
if (it->second == fd) {
// Erase the user from the map
userFdMap.erase(it);
std::cout << "the user earased " << std::endl;
return; // Exit the function after removing the user
}
}
}
void ejectUserfromivited(std::string nickname) {
// Iterate over the map to find the user with the given file descriptor
std::map<std::string, int>::iterator it;
for (it = invitedUsers.begin(); it != invitedUsers.end(); ++it) {
if (it->first == nickname) {
// Erase the user from the map
invitedUsers.erase(it);
std::cout << "the user earased " << std::endl;
return; // Exit the function after removing the user
}
}
}
std::string getOperatorNickname(int fd) const {
std::map<std::string, int>::const_iterator it;
for (it = operators.begin(); it != operators.end(); ++it) {
if (it->second == fd) {
return it->first;
}
}
return ""; // Return empty string if operator not found
}
void removeOperator(const std::string& operatorName )
{
// Iterate through the map to find the operator
std::map<std::string, int>::iterator it;
for (it = operators.begin(); it != operators.end(); ++it) {
if (it->first == operatorName) {
// Erase the operator from the map
operators.erase(it);
return; // Exit the function after removing the operator
}
}
}
// Remove an operator from the channel
};