reconstructing code
This commit is contained in:
0
Authentication.cpp
Normal file
0
Authentication.cpp
Normal file
@@ -1,5 +1,4 @@
|
||||
#include "channel.hpp"
|
||||
|
||||
#include "Channel.hpp"
|
||||
|
||||
Channel::Channel(){}
|
||||
|
||||
@@ -7,38 +6,29 @@ Channel::Channel(const std::string& name) : Channelname(name) {}
|
||||
|
||||
Channel::~Channel() {}
|
||||
|
||||
void Channel::setlimitchannel(int value) {limit = value;}
|
||||
|
||||
void Channel::setlimitchannel(int value)
|
||||
{
|
||||
limite = value;
|
||||
}
|
||||
int Channel::getChannelLimit() {return limit;}
|
||||
|
||||
int Channel::getlimitechannel()
|
||||
{
|
||||
return limite;
|
||||
}
|
||||
void Channel::setTopic(const std::string& newTopic) {topic = newTopic;}
|
||||
|
||||
std::string Channel::getTopic() const {return topic;}
|
||||
|
||||
void Channel::setTopic(const std::string& newTopic) {
|
||||
topic = newTopic;
|
||||
}
|
||||
void Channel::addClient(const std::string& client, int fd) {userFdMap[client] = fd;}
|
||||
|
||||
std::string Channel::getTopic() const {
|
||||
return topic;
|
||||
void Channel::addClientinveted(const std::string& client, int fd) {invitedUsers[client] = fd;}
|
||||
|
||||
}
|
||||
void Channel::addOperator(const std::string& operatorName, int fd) {operators[operatorName] = fd;}
|
||||
|
||||
void Channel::addClient(const std::string& client, int fd) {
|
||||
userFdMap[client] = fd;
|
||||
}
|
||||
std::map<std::string, int>& Channel::getUserFdMap() {return userFdMap;}
|
||||
|
||||
void Channel::addClientinveted(const std::string& client, int fd) {
|
||||
invitedUsers[client] = fd;
|
||||
}
|
||||
std::map<std::string, int>& Channel::invitedUserss() {return invitedUsers;}
|
||||
|
||||
void Channel::addOperator(const std::string& operatorName, int fd) {
|
||||
operators[operatorName] = fd;
|
||||
}
|
||||
std::map<std::string, int>& Channel::getOperators() {return operators;}
|
||||
|
||||
void Channel::setPass(const std::string &Newpass) {pass = Newpass;}
|
||||
|
||||
std::string Channel::getPass() {return pass;}
|
||||
|
||||
int Channel::getUserFd(const std::string& username) const {
|
||||
std::map<std::string, int>::const_iterator it = userFdMap.find(username);
|
||||
@@ -48,7 +38,6 @@ int Channel::getUserFd(const std::string& username) const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
bool Channel::isUserInChannel(const std::string& nickname) const {
|
||||
std::map<std::string, int>::const_iterator it = userFdMap.find(nickname);
|
||||
if (it != userFdMap.end() && it->second) {
|
||||
@@ -78,43 +67,38 @@ std::string Channel::getNickname(int fd) const {
|
||||
|
||||
|
||||
bool Channel::isOperator(int fd) {
|
||||
|
||||
for (std::map<std::string, int>::iterator it = operators.begin(); it != operators.end(); ++it) {
|
||||
if (it->second == fd) {
|
||||
return true;
|
||||
for (std::map<std::string, int>::iterator it = operators.begin(); it != operators.end(); ++it) {
|
||||
if (it->second == fd) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Channel::isInvited(std::string nickname) {
|
||||
for (std::map<std::string, int>::iterator it = invitedUsers.begin(); it != invitedUsers.end(); ++it) {
|
||||
if (it->first == nickname) {
|
||||
return true;
|
||||
for (std::map<std::string, int>::iterator it = invitedUsers.begin(); it != invitedUsers.end(); ++it) {
|
||||
if (it->first == nickname) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Channel::findUserFdForKickRegulars(const std::string& username) {
|
||||
std::map<std::string, int>::iterator it;
|
||||
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
|
||||
if (it->first == username) {
|
||||
return it->second;
|
||||
std::map<std::string, int>::iterator it;
|
||||
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
|
||||
if (it->first == username) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void Channel::ejectUserfromusers(int fd) {
|
||||
std::map<std::string, int>::iterator it;
|
||||
for (it = userFdMap.begin(); it != userFdMap.end(); ++it) {
|
||||
if (it->second == fd) {
|
||||
userFdMap.erase(it);
|
||||
std::cout << "the user earased " << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +109,6 @@ void Channel::ejectUserfromivited(std::string nickname) {
|
||||
for (it = invitedUsers.begin(); it != invitedUsers.end(); ++it) {
|
||||
if (it->first == nickname) {
|
||||
invitedUsers.erase(it);
|
||||
std::cout << "the user earased " << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -151,26 +134,3 @@ void Channel::removeOperator(const std::string& operatorName )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, int>& Channel::getUserFdMap() {
|
||||
return userFdMap;
|
||||
}
|
||||
|
||||
std::map<std::string, int>& Channel::invitedUserss() {
|
||||
return invitedUsers;
|
||||
}
|
||||
|
||||
std::map<std::string, int>& Channel::getOperators() {
|
||||
return operators;
|
||||
}
|
||||
|
||||
|
||||
void Channel::setPass(const std::string &Newpass)
|
||||
{
|
||||
pass = Newpass;
|
||||
}
|
||||
|
||||
std::string Channel::getPass()
|
||||
{
|
||||
return pass;
|
||||
}
|
@@ -1,12 +1,11 @@
|
||||
#ifndef CHANNEL_HPP
|
||||
#define CHANNEL_HPP
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <unistd.h> // Include for the send function
|
||||
#include <cstring> // Include for the strlen function
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
@@ -25,11 +24,10 @@ private:
|
||||
std::string topic;
|
||||
std::string key;
|
||||
std::string pass;
|
||||
int limite;
|
||||
int limit;
|
||||
std::map<std::string, int> userFdMap;
|
||||
std::map<std::string, int> invitedUsers;
|
||||
std::map<std::string, int> operators;
|
||||
bool channelconnect;
|
||||
|
||||
public:
|
||||
|
||||
@@ -39,7 +37,7 @@ public:
|
||||
void setTopic(const std::string& newTopic);
|
||||
std::string getTopic() const;
|
||||
void setlimitchannel(int value);
|
||||
int getlimitechannel();
|
||||
int getChannelLimit();
|
||||
|
||||
|
||||
void addClient(const std::string& client, int fd);
|
||||
@@ -66,7 +64,4 @@ public:
|
||||
std::map<std::string, int>& getOperators();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
58
Client.cpp
58
Client.cpp
@@ -8,60 +8,30 @@ Client::~Client() {}
|
||||
|
||||
int Client::getFd() const {return _fd;}
|
||||
|
||||
void Client::setPassword(const std::string& password) {
|
||||
pass = password;
|
||||
}
|
||||
void Client::setPassword(const std::string& password) {pass = password;}
|
||||
|
||||
std::string Client::getPassowrd() const {
|
||||
return pass;
|
||||
}
|
||||
std::string Client::getPassowrd() const {return pass;}
|
||||
|
||||
std::string Client::getName() const {
|
||||
return name;
|
||||
}
|
||||
std::string Client::getName() const {return name;}
|
||||
|
||||
void Client::setName(const std::string& newName) {
|
||||
name = newName;
|
||||
}
|
||||
void Client::setName(const std::string& newName) {name = newName;}
|
||||
|
||||
std::string Client::getNick() const {
|
||||
return nick;
|
||||
}
|
||||
std::string Client::getNick() const {return nick;}
|
||||
|
||||
void Client::setNick(const std::string& newNick) {
|
||||
nick = newNick;
|
||||
}
|
||||
void Client::setNick(const std::string& newNick) {nick = newNick;}
|
||||
|
||||
std::string Client::getUser() const {
|
||||
return user;
|
||||
}
|
||||
std::string Client::getUser() const {return user;}
|
||||
|
||||
void Client::setUser(const std::string& newUser) {
|
||||
user = newUser;
|
||||
}
|
||||
void Client::setUser(const std::string& newUser) {user = newUser;}
|
||||
|
||||
int Client::getAuthentication() const {
|
||||
return _authentication;
|
||||
}
|
||||
int Client::getAuthentication() const {return _authentication;}
|
||||
|
||||
void Client::setAuthentication(int auth) {
|
||||
_authentication = auth;
|
||||
}
|
||||
void Client::setAuthentication(int auth) {_authentication = auth;}
|
||||
|
||||
const std::string& Client::getCommand() const {return command;}
|
||||
|
||||
const std::string& Client::getCommand() const {
|
||||
return command;
|
||||
}
|
||||
void Client::clearCommand() {command = "";}
|
||||
|
||||
void Client::clearCommand() {
|
||||
command.clear();
|
||||
command = "";
|
||||
}
|
||||
void Client::appendCommand(std::string str) {command += str;}
|
||||
|
||||
void Client::appendCommand(std::string str) {
|
||||
command += str;
|
||||
}
|
||||
|
||||
void Client::setCommand(std::string cmd) {
|
||||
command = cmd;
|
||||
}
|
||||
void Client::setCommand(std::string cmd) {command = cmd;}
|
0
Helpers.cpp
Normal file
0
Helpers.cpp
Normal file
37
Macros.hpp
Normal file
37
Macros.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef MACROS_HPP
|
||||
#define MACROS_HPP
|
||||
|
||||
#define OO1 ":irc.l9oroch 001 " + nickname + " :Welcome to the MiniChat Network, " + nickname + '\n'
|
||||
#define OO2 ":irc.l9oroch 002 " + nickname + " :Your host is MiniChat, running version 4.5" + '\n'
|
||||
#define OO3 ":irc.l9oroch 003 " + nickname + " :This server was created " + formatCreationTime() + '\n'
|
||||
#define OO4 ":irc.l9oroch 004 " + nickname + " MiniChat MiniChat(enterprise)-2.3(12)-netty(5.4c)-proxy(0.9) MiniChat" + '\n'
|
||||
|
||||
#define JOIN_MESSAGE(nickname, channelName) (":" + nickname + " JOIN #" + channelName + "\n")
|
||||
#define MODE_MESSAGE(channelName) (":irc.l9oroch MODE #" + channelName + " +nt\n")
|
||||
#define NAMES_MESSAGE(nickname, channelName) (":irc.l9oroch 353 " + nickname + " = #" + channelName + " :@" + nickname + "\n")
|
||||
#define NAMES_MESSAGE2(nickname, channelName) (":irc.l9oroch 353 " + nickname + " @ #" + channelName + " :")
|
||||
#define END_OF_NAMES_MESSAGE(nickname, channelName) (":irc.l9oroch 366 " + nickname + " #" + channelName + " :End of /NAMES list.\n")
|
||||
#define CHANNEL_MESSAGE(channelName, creationTimeMessage) (":irc.l9oroch 354 " + channelName + " " + creationTimeMessage + "\n")
|
||||
#define TOPIC_MESSAGE(nickname, channelName, topic) (":irc.l9oroch 332 " + nickname + " #" + channelName + " :" + topic + " https://irc.com\n")
|
||||
#define PRIVATE_MESSAGE(senderFd, recipient, message) (":" + nicknames[senderFd] + " PRIVMSG " + recipient + " :" + message + "\r\n")
|
||||
#define ERROR_MESSAGE(senderFd, recipient) (":server.host NOTICE " + nicknames[senderFd] + " :Error: User '" + recipient + "' not found or offline\r\n")
|
||||
|
||||
|
||||
|
||||
#define BUFFER_SIZE 1024
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define CYAN "\033[36m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
#define MINICHAT "\n$$\\ $$\\ $$\\ $$\\ $$$$$$\\ $$\\ $$\\ \n" \
|
||||
"$$$\\ $$$ |\\__| \\__|$$ __$$\\ $$ | $$ | \n" \
|
||||
"$$$$\\ $$$$ |$$\\ $$$$$$$\\ $$\\ $$ / \\__|$$$$$$$\\ $$$$$$\\ $$$$$$\\ \n" \
|
||||
"$$\\$$\\$$ $$ |$$ |$$ __$$\\ $$ |$$ | $$ __$$\\ \\____$$\\_$$ _| \n" \
|
||||
"$$ \\$$$ $$ |$$ |$$ | $$ |$$ |$$ | $$ | $$ | $$$$$$$ | $$ | \n" \
|
||||
"$$ |\\$ /$$ |$$ |$$ | $$ |$$ |$$ | $$\\ $$ | $$ |$$ __$$ | $$ |$$\\ \n" \
|
||||
"$$ | \\_/ $$ |$$ |$$ | $$ |$$ |\\$$$$$$ |$$ | $$ |\\$$$$$$$ | \\$$$$ |\n" \
|
||||
"\\__| \\__|\\__|\\__| \\__|\\__| \\______/ \\__| \\__| \\_______| \\____/ \n\n"
|
||||
|
||||
|
||||
#endif
|
2
Makefile
2
Makefile
@@ -1,6 +1,6 @@
|
||||
NAME = ircserv
|
||||
|
||||
SRC = main.cpp Server.cpp Client.cpp channel.cpp
|
||||
SRC = main.cpp Server.cpp Client.cpp Channel.cpp
|
||||
|
||||
OBJ = ${SRC:.cpp=.o}
|
||||
|
||||
|
1433
Server.cpp
1433
Server.cpp
File diff suppressed because it is too large
Load Diff
55
Server.hpp
55
Server.hpp
@@ -16,18 +16,10 @@
|
||||
#include "Client.hpp"
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include "channel.hpp"
|
||||
#include "Channel.hpp"
|
||||
#include <ctime>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#define BUFFER_SIZE 1024
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define BLUE "\033[34m"
|
||||
#define MAGENTA "\033[35m"
|
||||
#define CYAN "\033[36m"
|
||||
#define RESET "\033[0m"
|
||||
|
||||
class Server {
|
||||
private:
|
||||
@@ -41,21 +33,25 @@ class Server {
|
||||
std::map<int, std::string> usernames;
|
||||
std::map<std::string, Channel> channels;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
Server();
|
||||
~Server();
|
||||
void setNickname(int fd, const std::string& nickname);
|
||||
|
||||
std::string getPassowrd() const;
|
||||
Client& getClientByFd(int fd);
|
||||
|
||||
void setNickname(int fd, const std::string& nickname);
|
||||
void setUsernames(int fd, const std::string& username);
|
||||
void setUsernameregular(int fd, const std::string& username);
|
||||
|
||||
std::string formatCreationTime();
|
||||
std::string constructCreationTimeMessage(const std::string& channelName);
|
||||
std::string constructJoinedTimeMessage(const std::string& channelName);
|
||||
void setUsernameregular(int fd, const std::string& username);
|
||||
|
||||
void createChannel(const std::string& channel, const std::string& nickname, int fd);
|
||||
void handlePrivateMessage(int senderFd, const std::string& recipient, const std::string& message);
|
||||
void handleInvitation(int senderFd, const std::string& recipient, std::string channelName);
|
||||
|
||||
void broadcastMessage(const std::string& channel, const std::string& senderNickname, const std::string& msg);
|
||||
void smallbroadcastMessagefortheckick(std::string nicknamesender , const std::string& channelname, const std::string& usertokick, const std::string& reason);
|
||||
void smallbroadcastMessageforjoin(std::string nicknamesender , const std::string& channelname);
|
||||
@@ -64,11 +60,12 @@ class Server {
|
||||
int findUserFd1(const std::string& username);
|
||||
bool dontputthesamenick(const std::string& nickname);
|
||||
bool dontputthesameusername(const std::string& username);
|
||||
void parseArgs(int ac, char **av);
|
||||
static void receiveSignal(int signum);
|
||||
|
||||
// Server
|
||||
void init();
|
||||
void run();
|
||||
|
||||
void parseArgs(int ac, char **av);
|
||||
static void receiveSignal(int signum);
|
||||
void createServerSocket();
|
||||
void bindServerSocket();
|
||||
void addPollfd(int fd);
|
||||
@@ -78,8 +75,32 @@ class Server {
|
||||
void cleanChannel(int fd);
|
||||
void closeFds();
|
||||
|
||||
Client& getClientByFd(int fd);
|
||||
void addUserToChannel(const std::string& nickname, const std::string& channelName, int fd);
|
||||
void sendJoinMsg(const std::string& nickname, const std::string& channelName, int fd);
|
||||
void ping(const std::string& command, int fd);
|
||||
|
||||
// User authentication
|
||||
void processPassword(Client& client, const std::string& command, int fd);
|
||||
void processNickCmd(Client& client, const std::string& command, int fd);
|
||||
void processUserCmd(Client& client, const std::string& command, int fd);
|
||||
void welcome(const std::string& nickname, int fd);
|
||||
|
||||
// Commands
|
||||
void processJoinCmd(Client& client, const std::string& command, int fd);
|
||||
void processPrivmsgCmd(Client& client, const std::string& command, int fd);
|
||||
void processQuitCmd(int fd);
|
||||
void processKickCmd(Client& client, const std::string& command, int fd);
|
||||
void processTopicCmd(Client& client, const std::string& command, int fd);
|
||||
void processInviteCmd(Client& client, const std::string& command, int fd);
|
||||
void processModeCmd(Client& client, const std::string& command, int fd);
|
||||
void processBotCmd(Client& client, const std::string& command, int fd);
|
||||
|
||||
// Channel modes
|
||||
void handleOpPrivilege(const std::string& nick, const std::string& channelName, const std::string& mode, int fd);
|
||||
void handleTopicRestriction(const std::string& nick, const std::string& channelName, const std::string& mode, int fd);
|
||||
void handleInviteOnly(const std::string& nick, const std::string& channelName, const std::string& mode, int fd);
|
||||
void handleChannelKey(std::string& nick, const std::string& channelName, const std::string& mode, int fd);
|
||||
void handleChannelLimit(const std::string& nick, const std::string& channelName, const std::string& mode, int fd);
|
||||
};
|
||||
|
||||
int randomInRange(int min, int max);
|
||||
|
Reference in New Issue
Block a user