Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions includes/channels/Channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "ReplyHandler.hpp"
#include "reply_codes.hpp"

#include <cstddef>
#include <queue>
#include <set>
#include <string>
#include <vector>
Expand Down Expand Up @@ -173,6 +175,8 @@ class Channel
* @param client
* @return true
* @return false
* @pre return from erase is ignored in case client is not invited, so it safe to use in that case.
* Yet still better if the caller function has checked that client is invited
*/
bool remove_from_invited_list(Client& client);

Expand Down Expand Up @@ -214,6 +218,8 @@ class Channel
*
* @param client
* @return false if member was not in the channel
* @pre return from erase is ignored in case client is not an member, so it safe to use in that case.
* Yet still better if the caller function has checked that client is member
*/
bool remove_member(Client& client);

Expand All @@ -230,7 +236,8 @@ class Channel
* @brief removes op status from client
*
* @param client
* @pre caller function should have checked that client is operator
* @pre return from erase is ignored in case client is not an operator, so it safe to use in that case.
* Yet still better if the caller function has checked that client is operator
*/
void remove_operator(Client& client);

Expand Down Expand Up @@ -277,6 +284,20 @@ class Channel
*/
size_t get_nb_members() const;

/**
* @brief Get the message history
*
* @return const std::queue<std::string>
*/
const std::deque<std::string> get_history() const;

/**
* @brief adds a message to channel history
* @details if message number reaches MAX_MESSAGES_HISTORY, the oldest one is removed
* @param message
*/
void add_message_to_history(const std::string& message);

/**
* @brief Get a list of #Client members
*
Expand Down Expand Up @@ -331,6 +352,7 @@ class Channel
* @return false otherwise
*/
static bool is_valid_channel_name(const std::string& name);

/**
* @brief
* @details cf [grammar](https://datatracker.ietf.org/doc/html/rfc2812#section-2.3.1)
Expand All @@ -344,15 +366,16 @@ class Channel
static bool is_valid_channel_key(const std::string& key);

private:
std::string _name;
std::string _topic;
std::string _key;
unsigned short _mode;
int _userLimit; // -1 if -l not set
std::set<Client*> _members;
std::set<Client*> _invites;
std::set<Client*> _operators;
std::set<Client*> _banList;
std::string _name;
std::string _topic;
std::string _key;
unsigned short _mode;
int _userLimit; // -1 if -l not set
std::set<Client*> _members;
std::set<Client*> _invites;
std::set<Client*> _operators;
std::set<Client*> _banList;
std::deque<std::string> _lastMessages;

Channel();
};
Expand Down
4 changes: 2 additions & 2 deletions includes/colors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* @brief ANSI color codes
* @version 0.1
* @date 2025-10-25
*
*
* @copyright Copyright (c) 2025
*
*
*/
#ifndef COLORS_H
#define COLORS_H
Expand Down
3 changes: 2 additions & 1 deletion includes/commands/Bot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Bot : public ICommand
std::vector<Client*> _targetClients;
std::string _subcommand;
std::string _prompt;
std::string _channelHistory;
TcpSocket _socket;

Bot();
Expand Down Expand Up @@ -118,4 +119,4 @@ class Bot : public ICommand
bool _register_bot(Server& s, TcpSocket& so);
};

#endif
#endif
3 changes: 2 additions & 1 deletion includes/commands/Kick.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ class Kick : public ICommand
/**
* @brief removes specified users from channel
*
* @param server
* @param chanName
* @param usersNames
* @param p
*/
void _kick_users_from_chan(std::string& chanName, std::vector<std::string>& usersNames, Parser& p);
void _kick_users_from_chan(Server& server, std::string& chanName, std::vector<std::string>& usersNames, Parser& p);
};

#endif
12 changes: 4 additions & 8 deletions includes/commands/Mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ class Mode : public ICommand
* @param validPositiveModes
* @param validNegativeModes
*/
void _mode_with_noparams(Channel* channel,
std::string& currentMode,
std::string& validPositiveModes,
std::string& validNegativeModes);
void _mode_with_noparams(Channel* channel, std::string& currentMode, std::string& validModes);
/**
* @brief use case of +k mode
* build mode is + mode args
Expand All @@ -126,7 +123,7 @@ class Mode : public ICommand
Parser& p,
std::string& currentMode,
std::string& currentParam,
std::string& validPositiveModes,
std::string& validModes,
std::string& validModesParams);
/**
* @brief use case of +l mode
Expand All @@ -144,7 +141,7 @@ class Mode : public ICommand
Parser& p,
std::string& currentMode,
std::string& currentParam,
std::string& validPositiveModes,
std::string& validModes,
std::string& validModesParams);
/**
* @brief use case of +o mode
Expand All @@ -167,8 +164,7 @@ class Mode : public ICommand
Parser& p,
std::string& currentMode,
std::string& currentParam,
std::string& validPositiveModes,
std::string& validNegativeModes,
std::string& validModes,
std::string& validModesParams);
std::string _channelName;
std::queue<std::string> _modeQueue;
Expand Down
11 changes: 6 additions & 5 deletions includes/consts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* @brief constants used throughout IRC server program
* @version 0.1
* @date 2025-10-25
*
*
* @copyright Copyright (c) 2025
*
*
*/
#ifndef CONSTS_HPP
#define CONSTS_HPP
Expand All @@ -32,8 +32,8 @@
#define FORBIDEN_CHAR_BOT_PROMPT "|;"
#define FORBIDEN_CHAR_CHAN_NAME "\x00\x07\x0D\x0A\x20\x2C\x3A" // NOLINT(clang-diagnostic-null-character)
#define FORBIDEN_CHAR_CHAN_KEY "\x00\x09\x0A\x0B\x0C\x0D\x20" // NOLINT(clang-diagnostic-null-character)
#define FORBIDDEN_CHAR_SERVER_KEY "\x00\x09\x0A\x0B\x0D\x20" // NOLINT(clang-diagnostic-null-character) NUL, HT, LF, VT, CR, space
#define FORBIDEN_CHAR_USER "\x00\x0A\x0D\x20\x40" // NOLINT(clang-diagnostic-null-character)
#define FORBIDDEN_CHAR_SERVER_KEY "\x00\x09\x0A\x0B\x0D\x20" // NOLINT(clang-diagnostic-null-character) NUL, HT, LF, VT, CR, space
#define FORBIDEN_CHAR_USER "\x00\x0A\x0D\x20\x40" // NOLINT(clang-diagnostic-null-character)
#define NUMBER_FORB_CCNK 7
#define NUMBER_FORB_CSK 6
#define NUMBER_FORB_CCU 5
Expand All @@ -47,7 +47,8 @@
#define DYNAMIC_PORT_MIN 49152
#define NICKNAME_MAX_LEN 9
#define NB_AVAILABLE_CMD 15
#define NB_AVAILABLE_BOT_SUBCMD 2
#define MAX_MESSAGES_HISTORY 10
#define NB_AVAILABLE_BOT_SUBCMD 3
#define USERS_PER_LINE 10
#define CHANMODE_INIT 0b00000
#define CHANMODE_KEY 0b00001
Expand Down
Loading