This commit is contained in:
2024-02-06 11:53:25 +01:00
parent 7555a6427a
commit 24462adbd5
10 changed files with 46 additions and 33 deletions

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:36:21 by maldavid #+# #+# */
/* Updated: 2024/02/06 10:33:44 by vvaas ### ########.fr */
/* Updated: 2024/02/06 11:37:55 by vvaas ### ########.fr */
/* */
/******************************************************************************/
@@ -93,7 +93,7 @@ namespace irc
void Channel::sendWho(unstd::SharedPtr<Client> client)
{
std::string clientlist(":yipirc " RPL_NAMREPLY " " + client->getNickName() + " @ " + getName() + " :");
std::string clientlist(":YipIRC " RPL_NAMREPLY " " + client->getNickName() + " @ " + getName() + " :");
for(client_it it = _clients.begin(); it != _clients.end(); ++it)
{
@@ -102,8 +102,8 @@ namespace irc
clientlist += const_cast<unstd::SharedPtr<irc::Client>&>(*it)->getNickName() + ' ';
}
client->sendModular("%s", clientlist.c_str());
clientlist = ":yipirc " RPL_NAMREPLY " " + client->getNickName() + " @ " + getName() + " :";
client->sendModular(":yipirc %s %s %s : End of names list", RPL_ENDOFNAMES, client->getNickName().c_str(), getName().c_str());
clientlist = ":YipIRC " RPL_NAMREPLY " " + client->getNickName() + " @ " + getName() + " :";
client->sendModular(":YipIRC %s %s %s : End of names list", RPL_ENDOFNAMES, client->getNickName().c_str(), getName().c_str());
}
void Channel::handleMessage(const std::string& msg, unstd::SharedPtr<Client> client, bool notice) const

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 10:35:52 by maldavid #+# #+# */
/* Updated: 2024/02/06 10:53:59 by vvaas ### ########.fr */
/* Updated: 2024/02/06 11:40:41 by vvaas ### ########.fr */
/* */
/******************************************************************************/
@@ -31,7 +31,7 @@ namespace irc
void Client::sendCode(const std::string& code, const std::string& msg)
{
const std::string command = ":yipirc " + code + " " + getNickName() + " :" + msg + "\r\n";
const std::string command = ":YipIRC " + code + " " + getNickName() + " :" + msg + "\r\n";
#ifdef DEBUG
logs::report(log_message, "sending '%s'", command.c_str());
#endif
@@ -41,7 +41,7 @@ namespace irc
void Client::sendCode(const std::string& code, const std::string& msg0, const std::string& msg1)
{
const std::string command = ":yipirc " + code + " " + msg0 + " :" + msg1 + "\r\n";
const std::string command = ":YipIRC " + code + " " + msg0 + " :" + msg1 + "\r\n";
#ifdef DEBUG
logs::report(log_message, "sending '%s'", command.c_str());
#endif
@@ -51,7 +51,7 @@ namespace irc
void Client::sendCodeInChannel(const std::string& code, const Channel &chan, const std::string& msg)
{
const std::string command = ":yipirc " + code + " " + getNickName() + " " + chan.getName() + " :" + msg + "\r\n";
const std::string command = ":YipIRC " + code + " " + getNickName() + " " + chan.getName() + " :" + msg + "\r\n";
#ifdef DEBUG
logs::report(log_message, "sending '%s'", command.c_str());
#endif
@@ -156,16 +156,16 @@ namespace irc
tosend = "This server is running since ";
tosend += server.getRunDate();
sendCode(RPL_CREATED, tosend);
sendModular("%s %s %s %s %s %s %s %s", ":yipirc", RPL_MYINFO, getNickName().c_str(), "YipIRC", "1.0", "o", "tikl", "kl");
sendModular("%s %s %s %s %s %s %s %s", ":YipIRC", RPL_MYINFO, getNickName().c_str(), "YipIRC", "1.0", "o", "tikl", "kl");
sendModular("There are %u users on %u channels", server.getClientCount(), server.getChannelCount());
sendModular("You are connected using %s", proto->p_name);
sendCode(RPL_WELCOME, "Welcome to yipirc :), your nickname is : " + _nickname);
sendCode(RPL_WELCOME, "Welcome to YipIRC 😀, your nickname is : " + _nickname);
}
void Client::kill(const std::string& reason)
{
std::string cmd = "KILL " + getNickName();
sendMsg("yipirc", cmd, reason);
sendMsg("YipIRC", cmd, reason);
}
Client::~Client() {}

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 09:31:17 by maldavid #+# #+# */
/* Updated: 2024/02/06 10:22:58 by vvaas ### ########.fr */
/* Updated: 2024/02/06 11:37:58 by vvaas ### ########.fr */
/* */
/******************************************************************************/
@@ -35,8 +35,6 @@ namespace irc
struct tm tstruct = *localtime(&ltime);
char buf[100];
strftime(buf, 100, "%a %b %d %Y %T CET", &tstruct);
_run_date = buf;
if (password.empty() || password.find_first_of(" \t\r\v") != std::string::npos)
{
logs::report(log_error, "Password is invalid !");
@@ -44,6 +42,8 @@ namespace irc
}
std::memset(&_s_data, 0, sizeof(sockaddr));
initSocket();
strftime(buf, 100, "%a %b %d %Y %T CET", &tstruct);
_run_date = buf;
}
void Server::initSocketData()
@@ -238,6 +238,11 @@ namespace irc
Server::~Server()
{
for (client_it it = _client.begin(); it != _client.end(); ++it)
{
if ((*it)->isWelcomed())
(*it)->kill("Server shutting down");
}
closeMainSocket();
for(int i = 0; i < FD_MAX; ++i)
{

View File

@@ -6,7 +6,7 @@
/* By: vvaas <vvaas@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 17:31:06 by maldavid #+# #+# */
/* Updated: 2024/02/06 10:59:29 by vvaas ### ########.fr */
/* Updated: 2024/02/06 11:38:00 by vvaas ### ########.fr */
/* */
/******************************************************************************/