diff --git a/Channel/Channel.cpp b/Channel/Channel.cpp index 2b6ccca..892fb12 100644 --- a/Channel/Channel.cpp +++ b/Channel/Channel.cpp @@ -33,6 +33,7 @@ Channel& Channel::operator=(const Channel &other) name_ = other.name_; members_ = other.members_; operators_ = other.operators_; + topic_ = other.topic_; isInviteOnly_ = other.isInviteOnly_; invitedMembers_ = other.invitedMembers_; } @@ -81,6 +82,14 @@ void Channel::broadcast(const std::string &msg, const std::map &clien } } +// Topic + +void Channel::setTopic(std::string content) { this->topic_ = content; } +std::string Channel::getTopic() { return (this->topic_); } + + +// Mode + void Channel::setMode(std::string& mode, std::string& args) { bool value; diff --git a/Channel/Channel.hpp b/Channel/Channel.hpp index f951e96..bda3ece 100644 --- a/Channel/Channel.hpp +++ b/Channel/Channel.hpp @@ -28,6 +28,8 @@ class Channel std::set members_; std::set operators_; + std::string topic_; + bool isInviteOnly_; std::set invitedMembers_; @@ -43,6 +45,10 @@ class Channel std::string getName() const; const std::set &getMembers() const; + // Topic + void setTopic(std::string content); + std::string getTopic(); + // Users void addMember(int fd); void removeMember(int fd); diff --git a/Makefile b/Makefile index 95980d3..6867442 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ SRC = main.cpp Server/Server.cpp User/User.cpp \ cmds/pass.cpp cmds/nick.cpp cmds/user.cpp \ cmds/join.cpp cmds/privmsg.cpp cmds/quit.cpp \ cmds/mode.cpp cmds/invite.cpp cmds/kick.cpp \ + cmds/topic.cpp HEADERS = Server/Server.hpp User/User.hpp diff --git a/Server/Server.cpp b/Server/Server.cpp index bda78ae..2131559 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -6,7 +6,7 @@ /* By: aortigos > channel; + getline(ss, message); + + if (!client.isRegistered()) return (client.send(":" SERVER_NAME " 451 " + client.getNick() + " :You have not registered\r\n")); + + + std::map::iterator it = channels_.find(channel); + + if (it == channels_.end()) + return (client.send(":" SERVER_NAME " 403 " + client.getNick() + " " + channel + " :No such channel\r\n")); + + if (!it->second.hasMember(client.getFd())) + return (client.send(":" SERVER_NAME " 404 " + client.getNick() + " " + channel + " :Cannot send to channel\r\n")); + + if (message.empty()) + { + std::string res = it->second.getTopic(); + if (res.empty()) + return (client.send(":" SERVER_NAME " 331 " + client.getNick() + " " + channel + " :No topic is set\r\n")); + client.send(":" SERVER_NAME " 332 " + client.getNick() + " " + channel + " :" + res + "\r\n"); + } + else + { + if (!message.empty() && message[0] == ' ') + message = message.substr(1); + if (!it->second.hasOperator(client.getFd())) + return (client.send(":" SERVER_NAME " 482 " + client.getNick() + " " + channel + " :You're not channel operator\r\n")); + it->second.setTopic(message); + it->second.broadcast(":" + client.getNick() + "!" + client.getUsername() + "@localhost TOPIC " + channel + " :" + message + "\r\n", clients_, -1); + } + +} \ No newline at end of file