Skip to content
Open
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
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Language: Cpp
BasedOnStyle: Microsoft
AccessModifierOffset: -4
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: false
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
IndentWidth: 4
TabWidth: 4
18 changes: 8 additions & 10 deletions include/typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#ifndef TYPEDEFS_HPP
#define TYPEDEFS_HPP

// #include "class.User.hpp" // needed for User class
// #include "class.Channel.hpp" // needed for Channel class
#include <map> // needed for std::map <-- c11 would be unordered map
#include <poll.h> // needed for poll_fd
#include <string> // needed for std::string
Expand All @@ -18,15 +16,15 @@ class Channel;
/* used to describe channel users rights */
enum UserPrivilege
{
USER,
OPERATOR,
USER,
OPERATOR,
};

/* used to store bot information/data */
struct ServerBot
{
int socket;
User *self;
int socket;
User *self;
};

// ------------------ std::string --------------------------- //
Expand All @@ -44,13 +42,13 @@ typedef t_vec_str const t_vec_str_c;
typedef t_vec_str::iterator t_vec_str_it;
typedef t_vec_str::const_iterator t_vec_str_cit;

/* used to store all accepted socket fd */
/* used to store all accepted socket fds */
typedef std::vector<pollfd> t_vec_pollfd;
typedef t_vec_pollfd::iterator t_vec_pollfd_it;

// ------------------ std::maps --------------------------- //

/* used to store sockets and their User class */
/* used to store user sockets and their User class */
typedef std::map<int, User> t_um_users;
typedef t_um_users::iterator t_um_users_it;
typedef t_um_users::const_iterator t_um_users_cit;
Expand All @@ -60,11 +58,11 @@ typedef std::map<t_str, Channel> t_um_channels;
typedef t_um_channels::iterator t_um_channels_it;
typedef t_um_channels::const_iterator t_um_channels_cit;

/* used to store users and their privileges in a channel */
/* used to store user sockets and their privileges in a channel */
typedef std::map<int, UserPrivilege> t_channel_users;
typedef t_channel_users::iterator t_channel_users_it;
typedef t_channel_users::const_iterator t_channel_users_cit;

#endif // TYPEDEFS_HPP

// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //
10 changes: 9 additions & 1 deletion src/class.Server.Messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ void Server::CMD_KICK(int socketSender)
}
else
{
if (nicknameKicked == "Marvin")
{
broadcast(nicknameKicked, channelName, "",
"Hey " + um.getNickname(socketSender) + ", you tried to kick me ... Bloody Bastard!",
"PRIVMSG");
continue;
}

int socketTarget = um.getSocket(nicknameKicked);
if (channel->isMember(socketTarget) == false)
{
Expand Down Expand Up @@ -570,4 +578,4 @@ void Server::CMD_MODE(int socket)
}
}

// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //
7 changes: 4 additions & 3 deletions src/class.Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ void Server::start(int argc, char **argv)
bool Server::getPortAndPasswd(char **argv)
{
std::string str = argv[1];
for (size_t i = 0; i < str.size(); i++)
if (isnumber(str[i]) == false)
for (size_t i = 0; i < str.size(); i++){
if (std::isdigit(str[i]) == false)
{
LOG_ERR("Bad input as Port");
return false;
}
}
this->m_port = atoi(argv[1]);
if (this->m_port != PORT)
{
Expand Down Expand Up @@ -686,4 +687,4 @@ void Server::broadcast(t_str_c &sender, t_str_c &channelName, t_str_c &nicknameK
}
}

// -------------------------------------------------------------------------- //
// -------------------------------------------------------------------------- //