Compare commits
2 Commits
d2e02440b3
...
f2bbec366b
| Author | SHA1 | Date | |
|---|---|---|---|
| f2bbec366b | |||
|
|
b47c7dc9b8 |
10
Makefile
10
Makefile
@@ -1,14 +1,8 @@
|
|||||||
NAME = ircserv
|
NAME = ircserv
|
||||||
|
|
||||||
SRC = main.cpp Server/Server.cpp Client/Client.cpp \
|
SRC = main.cpp Server/Server.cpp
|
||||||
Channel/Channel.cpp \
|
|
||||||
commands/pass.cpp commands/nick.cpp commands/user.cpp \
|
|
||||||
commands/join.cpp commands/privmsg.cpp \
|
|
||||||
commands/part.cpp
|
|
||||||
|
|
||||||
HEADERS = Client/Client.hpp \
|
HEADERS = Server/Server.hpp
|
||||||
Server/Server.hpp \
|
|
||||||
Channel/Channel.hpp
|
|
||||||
|
|
||||||
OBJ = $(SRC:.cpp=.o)
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|
||||||
|
|||||||
38
Server/Server.cpp
Normal file
38
Server/Server.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Server.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: iherman- <iherman-@student.42malaga.com +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/05/06 17:19:12 by iherman- #+# #+# */
|
||||||
|
/* Updated: 2026/05/06 17:40:52 by iherman- ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Server.hpp"
|
||||||
|
|
||||||
|
Server::Server()
|
||||||
|
{
|
||||||
|
std::cout << "Hello from server" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Server::Server(int port, const std::string& password)
|
||||||
|
{
|
||||||
|
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
|
||||||
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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user