-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.hpp
More file actions
187 lines (166 loc) · 3.64 KB
/
Library.hpp
File metadata and controls
187 lines (166 loc) · 3.64 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma once
# include <sys/socket.h>
# include <sys/wait.h>
# include <unistd.h>
# include <stdlib.h>
# include <netinet/in.h>
# include <iostream>
# include <stdio.h>
# include <string.h>
# include <sys/types.h>
# include <netdb.h>
# include <fcntl.h>
# include <poll.h>
# include <vector>
# include <list>
# include <string>
# include <sstream>
# include <fstream>
# include <map>
# include <cstdio>
# include <cstring>
# include <arpa/inet.h>
# include <algorithm>
# include <csignal>
# include <ctime>
# include <iomanip>
# include <cstring>
# include <locale>
#include <cmath>
#include <stdlib.h>
#define PATH_TO_CONFIG "config.conf"
#define PATH_TO_MOTD "welcome.motd"
#define SERV_NAME "serverName"
#define ADMIN_NAME "adminName"
#define OPERATORS "operators"
#define ONE_USER 1
#define TO_ALL_BUT_NO_THIS_USER 2
#define TO_ALL 3
#define TO_CHANNEL_BUT_NO_THIS_USER 4
#define TO_CHANNEL 5
#define ANOTHER_ONE_USER 6
#define SYSTEM_MSG 11
#define LIST_OF_RECIEVERS 7
#define HOST "127.0.0.1"
#define CHANGE_NICK 777
#define DELETE_USER 999
#define PART_USER 998
#define KICK_IN_CHANNEL 888
template<typename T>
std::string toString(const T& value)
{
std::ostringstream oss;
oss << value;
return oss.str();
}
inline std::vector<std::string> splitString(std::string s, char del)
{
std::stringstream ss(s);
std::string word;
std::vector<std::string> vector_string;
while (!ss.eof()) {
getline(ss, word, del);
if ((word[0] == '\n' && word.length() == 1) || word.length() == 0)
continue;
else if (word[0] == '\n')
vector_string.push_back(word.substr(1));
else
vector_string.push_back(word);
}
return(vector_string);
}
inline std::string getFirstLine(std::string s) {
std::stringstream ss(s);
std::string line;
size_t pos = 0;
getline(ss, line, '\r');
pos = line.find("\n");
if (pos != std::string::npos) {
line = line.substr(0, pos);
}
return(line);
}
inline std::vector<std::string> splitString2(std::string s, char del)
{
std::stringstream ss(s);
std::string word;
std::vector<std::string> vector_string;
size_t flag = 0;
while (!ss.eof()) {
getline(ss, word, del);
if (word[0] == '\n' && word.length() == 1)
continue;
else {
size_t pos = word.find("\n");
if (pos != std::string::npos) {
word = word.substr(0, pos);
}
vector_string.push_back(word);
++flag;
}
}
return(vector_string);
}
inline std::string strTrimBegin(std::string str, char ch) {
size_t lenStr = 0;
lenStr = str.length();
char * cstr = new char [lenStr+1];
std::strcpy (cstr, str.c_str());
size_t i = 0;
while (cstr[i] == ch && cstr[i] != '\0')
i++;
if(i > 0)
str = str.substr(i, lenStr);
if (i == lenStr)
str = "";
i = str.length();
std::strcpy (cstr, str.c_str());
while ((cstr[i] == ch || cstr[i] == '\0' || cstr[i] == '\n') && i > 0)
i--;
if(i < str.length())
str = str.substr(0, i+1);
if (i == 0)
str = "";
return str;
}
inline std::string toUpperCase(std::string str, std::string strCmd){
std::string uppStr = "";
std::locale loc;
char c;
for (std::string::size_type i=0; i<strCmd.length(); ++i){
c = std::toupper(str[i],loc);
uppStr.append(1, c);
}
return uppStr;
}
typedef struct s_message{
std::string cmd;
std::string receiver;
std::string restMess;
} t_message;
enum t_bot_command
{
HELLO_BOT,
PLAY,
WEATHER,
BYE_BOT,
READY,
NO_COMM,
YES,
NO,
FINISH
};
# include "Server.hpp"
# include "ErrorsAndReplies.hpp"
# include "User.hpp"
typedef struct s_channel {
std::string name;
std::string topic;
std::list<std::string> banned_users;
std::list<User*> list_users;
} t_channel;
# include "Message.hpp"
# include "Bot.hpp"
# include "ChannelsStorage.hpp"
# include "Messenger.hpp"
# include "Core.hpp"