Compare commits
20 Commits
readme
...
3a43f9d2bd
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a43f9d2bd | |||
| 5051c6cfcd | |||
| f70a46dde0 | |||
| def1787cb3 | |||
| 38823adb9d | |||
|
|
fd7a24de3d | ||
| 635335831c | |||
|
|
cbc6c7fc41 | ||
| f2bbec366b | |||
|
|
b47c7dc9b8 | ||
| d2e02440b3 | |||
|
|
e08ef37928 | ||
| bbeaae5923 | |||
|
|
c31c69c0fa | ||
|
|
206ff02eb4 | ||
| ddfe1202fd | |||
|
|
77e3166f15 | ||
|
|
c7bc6f90ca | ||
| 279a71aa31 | |||
|
|
b520ef7c34 |
44
Makefile
Normal file
44
Makefile
Normal file
@@ -0,0 +1,44 @@
|
||||
NAME = ircserv
|
||||
|
||||
SRC = main.cpp Server/Server.cpp Client/Client.cpp
|
||||
|
||||
HEADERS = Server/Server.hpp
|
||||
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
|
||||
GREEN = \033[0;32m
|
||||
RED = \033[0;31m
|
||||
RESET = \033[0m
|
||||
|
||||
TOTAL := $(words $(SRC))
|
||||
COUNT = 0
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ) $(HEADERS)
|
||||
@rm -f .build_start
|
||||
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME)
|
||||
@printf "\n$(GREEN)✔ Listo (100%%)\n$(RESET)"
|
||||
|
||||
%.o: %.cpp
|
||||
@if [ ! -f .build_start ]; then printf "$(GREEN)Compiling objects...\n$(RESET)"; touch .build_start; fi
|
||||
@$(eval COUNT = $(shell echo $$(($(COUNT)+1))))
|
||||
@PERCENT=$$(($(COUNT)*100/$(TOTAL))); \
|
||||
BAR=$$(printf "%0.s#" $$(seq 1 $$((PERCENT/5)))); \
|
||||
SPACE=$$(printf "%0.s " $$(seq 1 $$((20-PERCENT/5)))); \
|
||||
printf "\r [$$BAR$$SPACE] %3d%% (%d/%d) $< " $$PERCENT $(COUNT) $(TOTAL)
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
@printf "$(RED)Removing objects...\n$(RESET)"
|
||||
@rm -f $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
@@ -1,4 +1,4 @@
|
||||
**This project has been created as part of the 42 curriculum by iherman- and aortigos**
|
||||
*This project has been created as part of the 42 curriculum by iherman- and aortigos*
|
||||
|
||||
# Description
|
||||
|
||||
@@ -8,3 +8,5 @@ The goal of this project is to do an IRC Server
|
||||
|
||||
# Resources
|
||||
|
||||
|
||||
Thanks for reading :)
|
||||
|
||||
41
Server/Server.cpp
Normal file
41
Server/Server.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Server.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/06 17:19:12 by iherman- #+# #+# */
|
||||
/* Updated: 2026/05/06 18:22:36 by iherman- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Server.hpp"
|
||||
|
||||
Server::Server()
|
||||
{
|
||||
std::cout << "Hello from server" << std::endl;
|
||||
}
|
||||
|
||||
Server::Server(int port, const std::string& password)
|
||||
{
|
||||
if (port < 1 || port > 65535)
|
||||
throw std::runtime_error("Invalid port");
|
||||
|
||||
std::cout << "Server port: " << port << "\nServer Password: " << password << std::endl;
|
||||
}
|
||||
|
||||
Server::~Server()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Server &Server::operator=(const Server& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
std::cout << "operator= called" << std::endl;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
53
Server/Server.hpp
Normal file
53
Server/Server.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Server.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/06 17:18:11 by iherman- #+# #+# */
|
||||
/* Updated: 2026/05/06 17:41:04 by iherman- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SERVER_HPP
|
||||
# define SERVER_HPP
|
||||
|
||||
// C lib functions
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <poll.h>
|
||||
|
||||
// C++ lib functions
|
||||
#include <iostream>
|
||||
|
||||
# include <string>
|
||||
# include <sstream>
|
||||
|
||||
class Server
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
Server();
|
||||
Server(int port, const std::string& password);
|
||||
~Server();
|
||||
|
||||
Server &operator=(const Server& other);
|
||||
};
|
||||
|
||||
#endif // 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
|
||||
49
main.cpp
Normal file
49
main.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/05/06 17:57:53 by iherman- #+# #+# */
|
||||
/* Updated: 2026/05/06 17:57:58 by iherman- ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Server/Server.hpp"
|
||||
|
||||
int get_port(const char* arg)
|
||||
{
|
||||
std::stringstream input(arg);
|
||||
int port;
|
||||
|
||||
if (!(input >> port))
|
||||
throw std::runtime_error("Invalid port");
|
||||
|
||||
if (input.peek() != EOF)
|
||||
throw std::runtime_error("Malformed port");
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 3)
|
||||
{
|
||||
std::cerr << "Usage: ./ircserv <port> <password>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
int port = get_port(argv[1]);
|
||||
Server server(port, argv[2]);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// run server
|
||||
}
|
||||
52
tasks.md
Normal file
52
tasks.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Tasks for IRC
|
||||
|
||||
### Useful info
|
||||
|
||||
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
|
||||
|
||||
---
|
||||
|
||||
### First stage
|
||||
|
||||
- Server starts
|
||||
- It accepts two params, ./ircserv <port> <password>
|
||||
- The server accepts one user, user can send messages and we can see from server
|
||||
- Only 1 poll()
|
||||
|
||||
### Second stage
|
||||
|
||||
- Server can handle multiple clients simultaneously
|
||||
|
||||
### Third stage
|
||||
|
||||
- Client has nickname and username
|
||||
- Client needs password for authenticate
|
||||
- Client can be regular user or operator (admin)
|
||||
|
||||
### Fourth stage
|
||||
|
||||
- Client can create/connect to channels
|
||||
- Client can send message inside channel (only people inside this channel can read)
|
||||
|
||||
*It will continue...*
|
||||
Reference in New Issue
Block a user