Skip to content

Commit efdaca2

Browse files
committed
implemented sendReply
1 parent 08db250 commit efdaca2

7 files changed

Lines changed: 380 additions & 7 deletions

File tree

IRCat.motd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
⢀⡴⠑⡄⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣤⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
2+
⠸⡇⠀⠿⡀⠀⠀⠀⣀⡴⢿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
3+
⠀⠀⠀⠀⠑⢄⣠⠾⠁⣀⣄⡈⠙⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀
4+
⠀⠀⠀⠀⢀⡀⠁⠀⠀⠈⠙⠛⠂⠈⣿⣿⣿⣿⣿⠿⡿⢿⣆⠀⠀⠀⠀⠀⠀⠀
5+
⠀⠀⠀⢀⡾⣁⣀⠀⠴⠂⠙⣗⡀⠀⢻⣿⣿⠭⢤⣴⣦⣤⣹⠀⠀⠀⢀⢴⣶⣆
6+
⠀⠀⢀⣾⣿⣿⣿⣷⣮⣽⣾⣿⣥⣴⣿⣿⡿⢂⠔⢚⡿⢿⣿⣦⣴⣾⠁⠸⣼⡿
7+
⠀⢀⡞⠁⠙⠻⠿⠟⠉⠀⠛⢹⣿⣿⣿⣿⣿⣌⢤⣼⣿⣾⣿⡟⠉⠀⠀⠀⠀⠀
8+
⠀⣾⣷⣶⠇⠀⠀⣤⣄⣀⡀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
9+
⠀⠉⠈⠉⠀⠀⢦⡈⢻⣿⣿⣿⣶⣶⣶⣶⣤⣽⡹⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
10+
⠀⠀⠀⠀⠀⠀⠀⠉⠲⣽⡻⢿⣿⣿⣿⣿⣿⣿⣷⣜⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
11+
⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣷⣶⣮⣭⣽⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀
12+
⠀⠀⠀⠀⠀⠀⣀⣀⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀
13+
⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀
14+
⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
15+
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠻⠿⠿⠿⠿⠛⠉

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ SOURCE= main.cpp \
55
User.cpp \
66
Message.cpp \
77
utils.cpp \
8-
sendError.cpp
8+
sendError.cpp \
9+
sendReply.cpp
910

1011
OSOURCEFOLDER= objects/
1112

Server.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
Server::Server(int port, const std::string &password) :
44
port(port), timeout(20), password(password), name("IRCat")
5-
{}
5+
{
6+
// Read MOTD
7+
std::string line;
8+
std::ifstream motdFile("IRCat.motd");
9+
if (motdFile.is_open())
10+
{
11+
while (getline(motdFile, line))
12+
motd.push_back(line);
13+
motdFile.close();
14+
}
15+
}
616

717
Server::~Server()
818
{}
@@ -111,4 +121,11 @@ void Server::sendMOTD(const User &user) const
111121
{
112122
if (motd.size() == 0)
113123
sendError(user, ERR_NOMOTD);
124+
else
125+
{
126+
sendReply(user, RPL_MOTDSTART, name);
127+
for (size_t i = 0; i < motd.size(); ++i)
128+
sendReply(user, RPL_MOTD, motd[i]);
129+
sendReply(user, RPL_ENDOFMOTD);
130+
}
114131
}

Server.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
# define SERVER_HPP
33

44
class User;
5+
class Channel;
56

6-
# include "User.hpp"
77
# include <sys/socket.h> // For socket functions
88
# include <netinet/in.h> // For sockaddr_in
99
# include <cstdlib> // For exit() and EXIT_FAILURE
1010
# include <iostream> // For cout
1111
# include <unistd.h>
1212
# include <errno.h>
1313
# include <poll.h>
14+
# include <fstream>
15+
# include <string>
16+
# include "User.hpp"
17+
# include "Channel.hpp"
1418
# include "sendError.hpp"
19+
# include "sendReply.hpp"
1520

1621
class Server
1722
{
@@ -24,7 +29,8 @@ class Server
2429
const id_t timeout;
2530
std::string password;
2631
std::string name;
27-
std::string motd;
32+
std::vector<std::string> motd;
33+
std::vector<Channel> channels;
2834
public:
2935
Server(int port, const std::string &password);
3036
~Server();

User.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int User::userCmd(const Message &msg)
133133
else if (registered)
134134
sendError(*this, ERR_ALREADYREGISTRED);
135135
else
136-
{
136+
{ // Проверить валидность всего этого
137137
username = msg.getParams()[0];
138138
hostname = msg.getParams()[1];
139139
servername = msg.getParams()[2];
@@ -159,9 +159,15 @@ int User::hadleMessages()
159159
if (msg.getCommand() == "PASS")
160160
this->passCmd(msg);
161161
else if (msg.getCommand() == "USER")
162-
return (this->userCmd(msg));
162+
{
163+
if (this->userCmd(msg) == -1)
164+
return (-1);
165+
}
163166
else if (msg.getCommand() == "NICK")
164-
return (this->nickCmd(msg));
167+
{
168+
if (this->nickCmd(msg) == -1)
169+
return (-1);
170+
}
165171
else
166172
sendError(*this, ERR_NOTREGISTERED);
167173
}

0 commit comments

Comments
 (0)