Merge pull request 'client-class-init' (#9) from client-class-init into main
Reviewed-on: http://gitea.hadi.es/aortigos/ft_irc/pulls/9
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
||||
NAME = ircserv
|
||||
|
||||
SRC = main.cpp Server/Server.cpp
|
||||
SRC = main.cpp Server/Server.cpp Client/Client.cpp
|
||||
|
||||
HEADERS = Server/Server.hpp
|
||||
|
||||
|
||||
65
User/User.cpp
Normal file
65
User/User.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* User.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/07 10:22:52 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/07 10:22:52 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "User.hpp"
|
||||
|
||||
//////////////////
|
||||
// Constructors //
|
||||
//////////////////
|
||||
|
||||
User::User()
|
||||
{
|
||||
// std::cout << "User default constructor called" << std::endl;
|
||||
}
|
||||
|
||||
User::User(const User &other)
|
||||
{
|
||||
*this = other;
|
||||
// std::cout << "User copy constructor called" << std::endl;
|
||||
}
|
||||
|
||||
User& User::operator=(const User &other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
// Copy attributes here
|
||||
}
|
||||
// std::cout << "User copy assignment operator called" << std::endl;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
User::~User()
|
||||
{
|
||||
// std::cout << "User destructor called" << std::endl;
|
||||
}
|
||||
|
||||
// Getters
|
||||
|
||||
int User::getFd() const { return (this->fd) };
|
||||
std::string User::getNick() const { return (this->nick) };
|
||||
std::string User::getUsername() const { return (this->username) };
|
||||
std::string User::getRealname() const { return (this->realname) };
|
||||
std::string &User::getBuffer() { return (this->buffer) };
|
||||
bool User::isAuthenticated() const { return (this->authenticated) };
|
||||
bool User::isRegistered() const { return (this->registered) };
|
||||
|
||||
|
||||
// Setters
|
||||
|
||||
void setNick(std::string nick) { this->nick = nick; }
|
||||
void setUsername(std::string username) { this->username = username; }
|
||||
void setRealname(std::string realname) { this->realname = realname; }
|
||||
void appendBuffer(std::string buff) { this->buffer = buff; }
|
||||
void clearBuffer() { this->buffer.clear(); }
|
||||
|
||||
void setAuthenticated(bool value) { this->authenticated = value; }
|
||||
void setRegistered(bool value) { this->registered = value; }
|
||||
60
User/User.hpp
Normal file
60
User/User.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* User.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/07 10:22:52 by aortigos #+# #+# */
|
||||
/* Updated: 2026/05/07 10:22:52 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef USER_HPP
|
||||
|
||||
# define USER_HPP
|
||||
|
||||
# include <iostream>
|
||||
|
||||
class User
|
||||
{
|
||||
private:
|
||||
int fd;
|
||||
std::string nick;
|
||||
std::string username;
|
||||
std::string realname;
|
||||
std::string buffer;
|
||||
bool authenticated;
|
||||
bool registered;
|
||||
|
||||
public:
|
||||
User();
|
||||
User(const User &other);
|
||||
User& operator=(const User &other);
|
||||
~User();
|
||||
|
||||
|
||||
// Getters
|
||||
|
||||
int getFd() const;
|
||||
std::string getNick() const;
|
||||
std::string getUsername() const;
|
||||
std::string getRealname() const;
|
||||
std::string &getBuffer();
|
||||
bool isAuthenticated() const;
|
||||
bool isRegistered() const;
|
||||
|
||||
|
||||
// Setters
|
||||
|
||||
void setNick(std::string nick);
|
||||
void setUsername(std::string username);
|
||||
void setRealname(std::string realname);
|
||||
void appendBuffer(std::string buff);
|
||||
void clearBuffer();
|
||||
|
||||
void setAuthenticated(bool value);
|
||||
void setRegistered(bool value);
|
||||
};
|
||||
|
||||
#endif
|
||||
17
tasks.md
17
tasks.md
@@ -7,6 +7,23 @@ You can try connect IRC server with
|
||||
```bash
|
||||
nc localhost <port>
|
||||
```
|
||||
---
|
||||
|
||||
### User
|
||||
|
||||
Represents a connected IRC client.
|
||||
|
||||
| Attribute | Type | Description |
|
||||
|-----------------|----------|------------------------------------------------|
|
||||
| `fd` | `int` | TCP s-ocket file descriptor |
|
||||
| `nick` | `string` | IRC nickname |
|
||||
| `username` | `string` | Username |
|
||||
| `realname` | `string` | Real name |
|
||||
| `buffer` | `string` | Incoming data buffer, accumulates until `\r\n` |
|
||||
| `authenticated` | `bool` | `true` after correct `PASS` |
|
||||
| `registered` | `bool` | `true` after `NICK` + `USER` received |
|
||||
|
||||
**Registration flow:** `PASS` → authenticated → `NICK` + `USER` → registered → client ready
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user