Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix register msg #135

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hace falta el std::string??

Suggested change
# define RPL_WELCOME(nickname, username, hostname) std::string("Welcome to the Internet Relay Network ") + USER_ID(nickname, username, hostname)
# define RPL_WELCOME(nickname, username, hostname) "Welcome to the Internet Relay Network " + USER_ID(nickname, username, hostname)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mi eso me pesaba con la de los rpl que tengo que hacer. Es necesario porque coge el USER_ID como un string y el mensaje del principio como un const char * o algo así. En mi tarea lo arreglaré

Damos por bueno esto, me traigo los cambios y lo arreglo con el resto

# 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 @@ -75,5 +81,6 @@

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string getCurrentDate() const;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si lo pongo da error, según copilot dice que no tiene sentido poner const en una función no miembro, porque no hay objeto para modificar. Este es el error"a type qualifier is not allowed on a nonmember function"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah claro, que es el libUtils. Cuando hagas el singleton añadelo a todas las funciones


#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);
}
Loading