diff --git a/includes/libsUtils.hpp b/includes/libsUtils.hpp index 55ed0e3..7a3fd65 100644 --- a/includes/libsUtils.hpp +++ b/includes/libsUtils.hpp @@ -17,6 +17,7 @@ # include # include # include +# include # include "Logger.hpp" @@ -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 " @@ -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) + "." @@ -75,5 +81,6 @@ std::vector split(const std::string &s, char delim); bool isNumber(const std::string& s); +std::string getCurrentDate(); #endif \ No newline at end of file diff --git a/src/User.cpp b/src/User.cpp index 9630980..106ef2d 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -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)); } /** diff --git a/src/libsUtils.cpp b/src/libsUtils.cpp index 5dde1f9..f085ea0 100644 --- a/src/libsUtils.cpp +++ b/src/libsUtils.cpp @@ -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); +} \ No newline at end of file