topic mode done
This commit is contained in:
56
Server.cpp
56
Server.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include "Server.hpp"
|
#include "Server.hpp"
|
||||||
int a = 0;
|
int a = 0;
|
||||||
int opperatorfd;
|
int opperatorfd = 0;
|
||||||
|
int issettop = 0;
|
||||||
|
|
||||||
|
|
||||||
bool Server::_signal = false;
|
bool Server::_signal = false;
|
||||||
@@ -518,6 +519,42 @@ void Server::smallbroadcastMessageforTopic(std::string nicknamesender, const std
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Server::smallbroadcastMOOD(std::string nicknamesender, const std::string& channelname, std::string mode) {
|
||||||
|
std::map<std::string, Channel>::iterator it = channels.find(channelname);
|
||||||
|
if (it == channels.end()) {
|
||||||
|
std::cerr << "Channel " << channelname << " does not exist" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct the mode change message
|
||||||
|
std::string modeChangeMessage;
|
||||||
|
if (mode == "+t") {
|
||||||
|
modeChangeMessage = ":server.host MODE #" + channelname + " +t by " + nicknamesender + "\n";
|
||||||
|
} else if(mode == "-t") {
|
||||||
|
modeChangeMessage = ":server.host MODE #" + channelname + " -t by " + nicknamesender + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file descriptor of the sender
|
||||||
|
int senderFd = it->second.getUserFd(nicknamesender);
|
||||||
|
|
||||||
|
// Get a reference to the vector of clients in the channel
|
||||||
|
const std::vector<std::string>& clients = it->second.getClients();
|
||||||
|
|
||||||
|
// Iterate over the vector of clients and send the message to each one
|
||||||
|
for (size_t i = 0; i < clients.size(); ++i) {
|
||||||
|
// Get the current client nickname
|
||||||
|
const std::string& client = clients[i];
|
||||||
|
|
||||||
|
int recipientFd = it->second.getUserFd(client);
|
||||||
|
if (recipientFd != -1 && recipientFd != senderFd) {
|
||||||
|
send(recipientFd, modeChangeMessage.c_str(), modeChangeMessage.size(), 0);
|
||||||
|
} else {
|
||||||
|
std::cerr << "Client " << client << " not found or is the sender" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//check if ope or not
|
//check if ope or not
|
||||||
@@ -774,7 +811,7 @@ void Server::handleClientData(int fd) {
|
|||||||
topic = trim(topic);
|
topic = trim(topic);
|
||||||
topic = topic.substr(1);
|
topic = topic.substr(1);
|
||||||
|
|
||||||
if (channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd))
|
if ((channels.find(channelName) != channels.end() && channels[channelName].isOperator(fd)) || issettop == 1)
|
||||||
{
|
{
|
||||||
channels[channelName].setTopic(topic);
|
channels[channelName].setTopic(topic);
|
||||||
smallbroadcastMessageforTopic(channels[channelName].getNickname(fd), channelName, topic );
|
smallbroadcastMessageforTopic(channels[channelName].getNickname(fd), channelName, topic );
|
||||||
@@ -840,12 +877,17 @@ void Server::handleClientData(int fd) {
|
|||||||
send(fd, errorMessage.c_str(), errorMessage.size(), 0);
|
send(fd, errorMessage.c_str(), errorMessage.size(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else if (mode == "-i")
|
else if (mode == "-t")
|
||||||
// {
|
{
|
||||||
|
smallbroadcastMOOD(channels[channelName].getNickname(fd), channelName, mode);
|
||||||
// }
|
issettop = 1;
|
||||||
|
}
|
||||||
|
else if (mode == "+t")
|
||||||
|
{
|
||||||
|
smallbroadcastMOOD(channels[channelName].getNickname(fd), channelName, mode);
|
||||||
|
issettop = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//**************** STOOOOOOP HERE TOP G ...
|
//**************** STOOOOOOP HERE TOP G ...
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -60,6 +60,7 @@ class Server {
|
|||||||
void smallbroadcastMessagefortheckick(std::string nicknamesender , const std::string& channelname, const std::string& usertokick, const std::string& reason);
|
void smallbroadcastMessagefortheckick(std::string nicknamesender , const std::string& channelname, const std::string& usertokick, const std::string& reason);
|
||||||
void smallbroadcastMessageforjoin(std::string nicknamesender , const std::string& channelname);
|
void smallbroadcastMessageforjoin(std::string nicknamesender , const std::string& channelname);
|
||||||
void smallbroadcastMessageforTopic(std::string nicknamesender, const std::string& channelname, std::string topic);
|
void smallbroadcastMessageforTopic(std::string nicknamesender, const std::string& channelname, std::string topic);
|
||||||
|
void smallbroadcastMOOD(std::string nicknamesender, const std::string& channelname, std::string mode);
|
||||||
int findUserFd1(const std::string& username);
|
int findUserFd1(const std::string& username);
|
||||||
std::string findUsernameforsending(int fd);
|
std::string findUsernameforsending(int fd);
|
||||||
bool isOperator(int fd);
|
bool isOperator(int fd);
|
||||||
|
Reference in New Issue
Block a user