46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
|
#include "Kick.hpp"
|
||
|
#include "../IRC.hpp"
|
||
|
#include <string>
|
||
|
|
||
|
bool Kick::validate(const User &user, const std::string &msg)
|
||
|
{
|
||
|
size_t pos;
|
||
|
size_t leng;
|
||
|
|
||
|
leng = msg.length();
|
||
|
pos = msg.find(":");
|
||
|
this->reason = msg.substr(pos, leng - pos);
|
||
|
if (!this->reason[0])
|
||
|
this->reason = " :" + this->targetUser->getNickName();
|
||
|
std::istringstream iss(msg);
|
||
|
std::string word;
|
||
|
iss >> word; // should be KICK
|
||
|
iss >> word; // should be the channel you want to kick from
|
||
|
this->targetChannel = IRCManager::getChannelByName(word);
|
||
|
iss >> word; // should be the user you want to kick
|
||
|
this->targetUser = IRCManager::getUserByName(word);
|
||
|
if (this->targetChannel) // Check if the channel exists
|
||
|
{
|
||
|
if (this->targetUser) // Check if the user exists
|
||
|
{
|
||
|
if (this->targetChannel->checkOper(user)) // Check if we have operator permissions in the channel
|
||
|
return (true);
|
||
|
}
|
||
|
}
|
||
|
return (false);
|
||
|
}
|
||
|
|
||
|
int Kick::run(User &user, IRC::t_send_f &send)
|
||
|
{
|
||
|
std::istringstream iss(this->targetChannel->getUserList());
|
||
|
std::string target;
|
||
|
iss >> target;
|
||
|
while (target[0])
|
||
|
{
|
||
|
send(this->targetUser, user.getNickName() + "!~" + user.getUserName() + "@" + user.getHostName() + " KICK " + this->targetChannel->getChannelName() + " " + this->targetUser->getNickName() + " :" + this->reason);
|
||
|
iss >> target;
|
||
|
}
|
||
|
this->targetChannel->removeUser(this->targetUser);
|
||
|
return (0);
|
||
|
}
|