Skip to content

Commit

Permalink
Merge pull request #135 from jdomingu98/127-bug-rpl_welcome
Browse files Browse the repository at this point in the history
fix register msg
  • Loading branch information
Atrujillo02 authored Apr 27, 2024
2 parents a224156 + f64d804 commit 0bd920f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions includes/libsUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# include <string>
# include <vector>
# include <unistd.h>
# include <ctime>

# include "Logger.hpp"

Expand All @@ -32,6 +33,7 @@

# define DEFAULT_PORT "6666"
# define DEFAULT_PASS "1234"
# define DEFAULT_SERVER_VERSION "ft_messenger-v1.0.0"

// ========================================= IRC SERVER ERROR MESSAGES =========================================
# define INVALID_ARGS "[ERROR] Invalid args.\nUsage: ./ircserv <port> <password>"
Expand Down Expand Up @@ -62,6 +64,10 @@
// # define RPL_AWAY(nickname, username, hostname, awayMessage) USER_ID(nickname, username, hostname) + " " + (nickname) + " :" + (awayMessage)
// # define RPL_CHANNEL_MODE_IS(nickname, username, hostname, channel, mode, modeParams) USER_ID(nickname, username, hostname) + " " + (channel) + " " + (mode) + " " + (modeParams)
# define RPL_END_OF_NAMES(nickname, usermane, hostname, channel) USER_ID(nickname, username, hostname) + " " + (channel) + " :End of NAMES list."
# define RPL_WELCOME(nickname, username, hostname) std::string("Welcome to the Internet Relay Network ") + USER_ID(nickname, username, hostname)
# define RPL_YOURHOST(servername) "Your host is " + (servername) + ", running version " + (DEFAULT_SERVER_VERSION)
# define RPL_CREATED(date) "This server was create: " + (date)
# define RPL_MYINFO(servername, channelModes) (servername) + " " + (DEFAULT_SERVER_VERSION) + " Available user modes: " + ", Available channel modes: " + (channelModes)

# define ERROR_MSG(errorCode, nickname, errorMsg) ":irc.ft_messenger.net " + (errorCode) + " " + (nickname) + " " + (errorMsg) + "."

Expand All @@ -77,5 +83,6 @@

std::vector<std::string> split(const std::string &s, char delim);
bool isNumber(const std::string& s);
std::string getCurrentDate();

#endif
11 changes: 10 additions & 1 deletion src/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,16 @@ bool User::canRegister() const {
void User::makeRegistration() {
if (!Server::getInstance().isValidPassword(this->_password))
throw PasswordMismatchException();
this->_registered = true;
this->_registered = true;

std::string date = getCurrentDate();
std::string channelModes = "iklot";

Server& server = Server::getInstance();
server.sendMessage(this->getFd(), RPL_WELCOME(_nickname, _username, _hostname));
server.sendMessage(this->getFd(), RPL_YOURHOST(_serverName));
server.sendMessage(this->getFd(), RPL_CREATED(date));
server.sendMessage(this->getFd(), RPL_MYINFO(_serverName, channelModes));
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/libsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ bool isNumber(const std::string& s) {
++it;
return !s.empty() && it == s.end();
}

/**
* Gets the current date.
*
* @return The string with the current date.
*/
std::string getCurrentDate() {
std::time_t t = std::time(0);
std::tm* now = std::localtime(&t);
char buffer[100];

strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S UTC", now);
return std::string(buffer);
}

0 comments on commit 0bd920f

Please sign in to comment.