mirror of https://notabug.org/acetone/ircabot.git
Стабильно отвечает на пинги. Начало работы парсинга
parent
1647b969f2
commit
2fcf79338f
|
@ -7,7 +7,7 @@ void TcpSyncClient::log(T message)
|
|||
}
|
||||
|
||||
TcpSyncClient::TcpSyncClient(boost::asio::ip::tcp::endpoint ep, boost::asio::io_service& service,
|
||||
const std::string channel) : m_started(true),
|
||||
const std::string channel) : started(true),
|
||||
m_ep(ep), m_sock(service),
|
||||
m_channel(channel)
|
||||
|
||||
|
@ -54,6 +54,11 @@ size_t TcpSyncClient::read_complete(const error_code & err, size_t bytes) {
|
|||
|
||||
void TcpSyncClient::read_answer()
|
||||
{
|
||||
// boost::system::error_code ec;
|
||||
// size_t result = m_sock.available(ec);
|
||||
// if (ec || result == 0) { std::cout << "RES: "<< result << std::endl; return; }
|
||||
// std::cout << "READ_ANSWER_DEBUG_LINE\n";
|
||||
|
||||
m_already_read = 0;
|
||||
read(m_sock, boost::asio::buffer(m_buff),
|
||||
boost::bind(&TcpSyncClient::read_complete, this, _1, _2));
|
||||
|
@ -63,6 +68,7 @@ void TcpSyncClient::read_answer()
|
|||
void TcpSyncClient::answer_to_ping(std::string ping)
|
||||
{
|
||||
write("PONG :" + ping);
|
||||
log("[PONG] " + ping);
|
||||
}
|
||||
|
||||
bool TcpSyncClient::connect_to_server()
|
||||
|
@ -70,18 +76,26 @@ bool TcpSyncClient::connect_to_server()
|
|||
write("USER " + USER + " . . :" + REALNAME);
|
||||
write("NICK " + NICK);
|
||||
read_answer();
|
||||
write("PRIVMSG NICKSERV IDENTIFY 906090");
|
||||
read_answer();
|
||||
write("JOIN " + m_channel);
|
||||
loop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TcpSyncClient::loop()
|
||||
{
|
||||
|
||||
while (started) {
|
||||
read_answer();
|
||||
}
|
||||
}
|
||||
|
||||
void TcpSyncClient::process_msg()
|
||||
{
|
||||
std::string msg(m_buff, m_already_read);
|
||||
log("Readed: " + msg);
|
||||
log("[PROCESS] " + msg);
|
||||
if (msg.find("PING :") == 0) answer_to_ping(msg.substr(6));
|
||||
if (msg.find("PRIVMSG " + m_channel + " :" + NICK) != std::string::npos)
|
||||
write("PRIVMSG " + m_channel + " yeah!");
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <boost/enable_shared_from_this.hpp>
|
||||
|
||||
const static std::string USER = "acetonebot";
|
||||
const static std::string NICK = "bot";
|
||||
const static std::string NICK = "abot";
|
||||
const static std::string REALNAME = "IRC bot in C++";
|
||||
|
||||
using boost::system::error_code;
|
||||
|
@ -20,6 +20,8 @@ public:
|
|||
TcpSyncClient(boost::asio::ip::tcp::endpoint, boost::asio::io_service&, const std::string);
|
||||
bool write(std::string);
|
||||
|
||||
bool started;
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void log(T);
|
||||
|
@ -27,15 +29,14 @@ private:
|
|||
size_t read_complete(const error_code&, size_t);
|
||||
void read_answer();
|
||||
void process_msg();
|
||||
void loop();
|
||||
|
||||
int m_already_read;
|
||||
bool m_started;
|
||||
char m_buff[1024]; // Буффер 1Кб
|
||||
boost::asio::ip::tcp::endpoint m_ep;
|
||||
boost::asio::ip::tcp::socket m_sock;
|
||||
|
||||
std::string m_channel;
|
||||
void loop();
|
||||
void answer_to_ping(std::string);
|
||||
bool connect_to_server();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue