-storing the channel in another file with the channel requirment and the client : it's when registerd in the irssi client with the pass and the nick and the user all this data stored in the client file and make the irssi client connecte with the server , after tha handle the join commande to make the user join a channel and handle the brodcast msg to all the clients in the channel
This commit is contained in:
96
channel.hpp
Normal file
96
channel.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef CHANNEL_HPP
|
||||
#define CHANNEL_HPP
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <unistd.h> // Include for the send function
|
||||
#include <cstring> // Include for the strlen function
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
#include <arpa/inet.h>
|
||||
#include <fcntl.h>
|
||||
#include <vector>
|
||||
#include <poll.h>
|
||||
#include "Client.hpp"
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
|
||||
|
||||
class Channel {
|
||||
private:
|
||||
std::string Channelname;
|
||||
std::string topic;
|
||||
std::string key;
|
||||
std::vector<std::string> users;
|
||||
std::map<int, std::string> nicknames; // Replace unordered_map with map
|
||||
std::map<std::string, int> userFdMap; // Mapping of usernames to file descriptors
|
||||
|
||||
std::vector<std::string> invitedUsers;
|
||||
std::vector<std::string> operators;
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
Channel(const std::string& name) : Channelname(name) {}
|
||||
|
||||
// Destructor
|
||||
~Channel() {}
|
||||
|
||||
// Add a client to the channel
|
||||
|
||||
void addClient(const std::string& client, int fd) {
|
||||
userFdMap[client] = fd;
|
||||
}
|
||||
|
||||
void addClient(const std::string& client) {
|
||||
users.push_back(client);
|
||||
}
|
||||
|
||||
// Remove a client from the channel
|
||||
void removeClient(const std::string& nickname) {
|
||||
// Implement removal logic
|
||||
// Iterate through clients vector, find the client by nickname, and remove it
|
||||
}
|
||||
|
||||
// Add an invited user to the channel
|
||||
void inviteUser(const std::string& user) {
|
||||
invitedUsers.push_back(user);
|
||||
}
|
||||
|
||||
// Remove an invited user from the channel
|
||||
void uninviteUser(const std::string& user) {
|
||||
// Implement removal logic
|
||||
// Iterate through invitedUsers vector, find the user, and remove it
|
||||
}
|
||||
|
||||
// Add an operator to the channel
|
||||
void addOperator(const std::string& operatorName) {
|
||||
operators.push_back(operatorName);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// Remove an operator from the channel
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user