commit b39245ddf1d6f64e826bc63a2eaf1874f61e0c70 Author: aortigos Date: Tue Apr 14 01:01:01 2026 +0200 Empezando proyecto diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..19c9bd3 --- /dev/null +++ b/Makefile @@ -0,0 +1,42 @@ +NAME = ircserver + +SRC = main.cpp Server/Server.cpp + +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) + @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)Compilando archivos...\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)Eliminando...\n$(RESET)" + @rm -f $(OBJ) + +fclean: clean + @rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/Server/Server.cpp b/Server/Server.cpp new file mode 100644 index 0000000..6c51d7a --- /dev/null +++ b/Server/Server.cpp @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Server.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/04/13 22:31:44 by aortigos #+# #+# */ +/* Updated: 2026/04/13 22:31:44 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Server.hpp" + +////////////////// +// Constructors // +////////////////// + +Server::Server() +{ + std::cout << "Server default constructor called" << std::endl; +} + +Server::Server(int port) : port(port) +{ + std::cout << "Server will use port: " << port << std::endl; +} + +Server::~Server() +{ + std::cout << "Server destructor called" << std::endl; +} + +int Server::run() +{ + int server_fd = socket(AF_INET, SOCK_STREAM, 0); + + sockaddr_in addr = {}; + addr.sin_family = AF_INET; + addr.sin_port = htons(this->port); + addr.sin_addr.s_addr = INADDR_ANY; + + bind(server_fd, (sockaddr*)&addr, sizeof(addr)); + listen(server_fd, 1); + std::cout << "Esperando conexion" << std::endl; + + int client_fd = accept(server_fd, NULL, NULL); + std::cout << "Cliente conectado" << std::endl; + + char buf[512] = {0}; + recv(client_fd, buf, sizeof(buf), 0); + std::cout << "Mensaje: " << buf << std::endl; + + close(client_fd); + close(server_fd); + + return (0); + +} diff --git a/Server/Server.hpp b/Server/Server.hpp new file mode 100644 index 0000000..b97a39e --- /dev/null +++ b/Server/Server.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Server.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/04/13 22:31:44 by aortigos #+# #+# */ +/* Updated: 2026/04/13 22:31:44 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SERVER_HPP +# define SERVER_HPP + +# include +# include +# include +# include +# include + +class Server +{ + private: + int port; + public: + Server(); + Server(int port); + ~Server(); + int run(); +}; + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..f344eae --- /dev/null +++ b/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos