forked from OthelloPlusPlus/ft_irc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAClient.hpp
More file actions
138 lines (123 loc) · 4.37 KB
/
AClient.hpp
File metadata and controls
138 lines (123 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* ************************************************************************** */
/* */
/* :::::::: */
/* AClient.hpp :+: :+: */
/* +:+ */
/* By: ohengelm <ohengelm@student.42.fr> +#+ */
/* +#+ */
/* Created: 2023/10/19 20:25:50 by ohengelm #+# #+# */
/* Updated: 2023/10/19 20:25:51 by ohengelm ######## odam.nl */
/* */
/* ************************************************************************** */
#ifndef ACLIENT_HPP
# define ACLIENT_HPP
class Server;
# include <string>
// std::string
class AClient
{
private:
bool _isOperator;
protected:
Server &_server;
std::string _clientIP;
std::string _nickName;
std::string _userName; //Ident Name
std::string _realName;
std::string _away;
bool _isRegistered;
std::string _buffer;
public:
//(De)constructors
AClient(Server &server);
virtual ~AClient(void) = 0;
//Pure Virtual functions - Mandatory for derived classes
virtual bool stillActive(void) const = 0;
virtual void closeFD(void) = 0;
virtual std::string getMsg(void) = 0;
virtual void sendMsg(std::string msg) = 0;
//Virtual functions - Optional for derived classes
virtual void passwordValidation(bool val);
virtual void setIsRegistered(bool value);
virtual void printInfo(void) const;
//Non-virtual functions - Cannot not overridden by derived classes
void setClientIP(std::string clientIP);
void setNickName(std::string nickName);
void setUserName(std::string userName);
void setRealName(std::string realName);
void setAway(std::string away);
void setIsOperator(bool value);
void setBuffer(std::string buffer);
Server *getServer(void) const;
const std::string &getClientIP(void) const;
const std::string &getNickName(void) const;
const std::string &getUserName(void) const;
const std::string &getRealName(void) const;
const std::string &getBestName(void) const;
const std::string &getAway(void) const;
const bool &getIsRegistered(void) const;
const bool &getIsOperator(void) const;
const std::string &getBuffer(void) const;
//Operator overloads for admin state comparison
bool operator==(const AClient &cmp) const;
bool operator!=(const AClient &cmp) const;
bool operator>(const AClient &cmp) const;
bool operator>=(const AClient &cmp) const;
bool operator<(const AClient &cmp) const;
bool operator<=(const AClient &cmp) const;
//Operator overload to caternate to character strings
# ifdef __APPLE__
friend std::string operator+(char c, const AClient &src)
{
return (std::string(1, c) + src);
}
friend std::string operator+(const char *str, const AClient &src)
{
return (std::string(str) + src);
}
friend std::string operator+(std::string str, const AClient &src)
{
return (str + src._nickName + "!~" + src._userName + '@' + src._clientIP);
}
std::string operator+(char c)
{
return (*this + std::string(1, c));
}
std::string operator+(const char *str)
{
return (*this + std::string(str));
}
std::string operator+(std::string str)
{
return (this->_nickName + "!~" + this->_userName + '@' + this->_clientIP + str);
}
# else
# include <type_traits>
template <typename T>
friend std::string operator+(const T add, const AClient &src)
{
static_assert(std::is_same<T, char>::value ||
std::is_same<T, char*>::value ||
std::is_same<T, const char*>::value ||
std::is_same<T, std::string>::value, "Invalid type");
std::string ret;
ret = add;
return (ret + src._nickName + "!~" + src._userName + '@' + src._clientIP);
}
template <typename T>
std::string operator+(const T add)
{
static_assert(std::is_same<T, char>::value ||
std::is_same<T, char*>::value ||
std::is_same<T, const char*>::value ||
std::is_same<T, std::string>::value, "Invalid type");
std::string ret;
ret = add;
return (this->_nickName + "!~" + this->_userName + '@' + this->_clientIP + ret);
}
# endif
};
#include "Server.hpp"
#else
class AClient;
#endif