Adding join channels and privmsg
This commit is contained in:
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@ NAME = ircserv
|
|||||||
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
||||||
Channel/Channel.cpp \
|
Channel/Channel.cpp \
|
||||||
commands/pass.cpp commands/nick.cpp commands/user.cpp \
|
commands/pass.cpp commands/nick.cpp commands/user.cpp \
|
||||||
commands/join.cpp
|
commands/join.cpp commands/privmsg.cpp
|
||||||
|
|
||||||
|
|
||||||
OBJ = $(SRC:.cpp=.o)
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|||||||
@@ -156,4 +156,8 @@ void Server::parseCommand(int fd, std::string line)
|
|||||||
cmd_nick(fd, ss);
|
cmd_nick(fd, ss);
|
||||||
else if (command == "USER")
|
else if (command == "USER")
|
||||||
cmd_user(fd, ss);
|
cmd_user(fd, ss);
|
||||||
|
else if (command == "JOIN")
|
||||||
|
cmd_join(fd, ss);
|
||||||
|
else if (command == "PRIVMSG")
|
||||||
|
cmd_privmsg(fd, ss);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/04/17 16:26:18 by aortigos #+# #+# */
|
/* Created: 2026/04/17 16:26:18 by aortigos #+# #+# */
|
||||||
/* Updated: 2026/04/17 18:44:02 by aortigos ### ########.fr */
|
/* Updated: 2026/04/17 18:54:46 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -20,15 +20,26 @@ void Server::cmd_join(int fd, std::istringstream &ss)
|
|||||||
|
|
||||||
if (!clients[fd].isRegistered())
|
if (!clients[fd].isRegistered())
|
||||||
{
|
{
|
||||||
std::string msg = "You are not registered";
|
std::string msg = "You are not registered\r\n";
|
||||||
send(fd, msg.c_str(), msg.size(), 0);
|
send(fd, msg.c_str(), msg.size(), 0);
|
||||||
|
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channels.find(channelName) == channels.end())
|
if (channels.find(args) == channels.end())
|
||||||
{
|
{
|
||||||
|
channels.insert(std::make_pair(args, Channel(args)));
|
||||||
|
channels[args].addMember(fd);
|
||||||
|
|
||||||
|
std::string msg = "Channel created\r\n";
|
||||||
|
send(fd, msg.c_str(), msg.size(), 0);
|
||||||
} else {
|
} else {
|
||||||
|
channels[args].addMember(fd);
|
||||||
|
|
||||||
|
std::string msg = "Channel already exists\r\n";
|
||||||
|
send(fd, msg.c_str(), msg.size(), 0);
|
||||||
|
|
||||||
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/04/17 11:56:55 by aortigos #+# #+# */
|
/* Created: 2026/04/17 11:56:55 by aortigos #+# #+# */
|
||||||
/* Updated: 2026/04/17 14:19:29 by aortigos ### ########.fr */
|
/* Updated: 2026/04/17 18:59:47 by aortigos ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -47,15 +47,16 @@ void Server::cmd_nick(int fd, std::istringstream &ss)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!clients[fd].getNick().empty())
|
||||||
std::string msg = ":"
|
{
|
||||||
+ clients[fd].getNick()
|
std::string msg = ":"
|
||||||
+ " NICK "
|
+ clients[fd].getNick()
|
||||||
+ args
|
+ " NICK "
|
||||||
+ "\r\n";
|
+ args
|
||||||
|
+ "\r\n";
|
||||||
clients[fd].setNick(args);
|
send(fd, msg.c_str(), msg.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
send(fd, msg.c_str(), msg.size(), 0);
|
clients[fd].setNick(args);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* privmsg.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/04/17 19:02:55 by aortigos #+# #+# */
|
||||||
|
/* Updated: 2026/04/17 19:11:54 by aortigos ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../Server/Server.hpp"
|
||||||
|
|
||||||
|
void Server::cmd_privmsg(int fd, std::istringstream &ss)
|
||||||
|
{
|
||||||
|
std::string channel;
|
||||||
|
std::string message;
|
||||||
|
|
||||||
|
ss >> channel;
|
||||||
|
std::getline(ss, message);
|
||||||
|
message += "\r\n"
|
||||||
|
|
||||||
|
std::vector<int> members = channels[channel].getMembers();
|
||||||
|
|
||||||
|
|
||||||
|
// iterador para recorrer los miembros e ir enviandoles el mensaje
|
||||||
|
for (size_t i = 0; i < members.size(); i++)
|
||||||
|
{
|
||||||
|
if (members[i] != fd)
|
||||||
|
send(members[i], message.c_str(), message.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user