From cf4573c0699c5e4ad5041230dc5acb58c7debb2f Mon Sep 17 00:00:00 2001 From: acetone Date: Thu, 20 May 2021 13:34:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=83=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 15 +++++++-------- tcpsyncclient.cpp | 21 ++++++--------------- tcpsyncclient.h | 3 +-- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/main.cpp b/main.cpp index bd06b91..34ff6e7 100644 --- a/main.cpp +++ b/main.cpp @@ -26,13 +26,13 @@ int write_log(std::string msg) std::ofstream out; - if (boost::filesystem::exists("/usr/share/kiwiirc/irc-log")) // unix, продакшен + if (boost::filesystem::exists("/var/www/html/doc/irc-log")) // unix, продакшен { - if (! boost::filesystem::exists("/usr/share/kiwiirc/irc-log/" + year + "/" + month)) + if (! boost::filesystem::exists("/var/www/html/doc/irc-log/" + year + "/" + month)) { - boost::filesystem::create_directories("/usr/share/kiwiirc/irc-log/" + year + "/" + month); + boost::filesystem::create_directories("/var/www/html/doc/irc-log/" + year + "/" + month); } - out.open("/usr/share/kiwiirc/irc-log/" + year + "/" + month + "/" + day + ".txt", std::ios::app); + out.open("/var/www/html/doc/irc-log/" + year + "/" + month + "/" + day + ".txt", std::ios::app); if (! out.is_open()) return 1; } else if (boost::filesystem::exists("D:\\irc-log")) // win, тесты @@ -103,10 +103,9 @@ int main(int argc, char * argv[]) if(tsc->to_read) { // Есть сообщения, адресованные боту std::string msg = tsc->get_msg(); if(msg != ERROR_START_FAILED) { - tsc->write_to_channel(tsc->get_msg_nick() + ", лог чата: " + - "http://irc.acetone.i2p/irc-log || " + - "http://[324:9de3:fea4:f6ac::41]/irc-log || " + - "http://ilitafrzzgxymv6umx2ux7kbz3imyeko6cnqkvy4nisjjj4qpqkrptid.onion/irc-log"); + tsc->write_to_channel(tsc->get_msg_nick() + ", лог чата: http://acetone.i2p/doc/irc-log/ #" + + " http://[324:9de3:fea4:f6ac::ace]/doc/irc-log/ #" + + " http://acetonemadzhxzi2e5tomavam6xpucdfwn2g35vrsz6izgaxv5bmuhad.onion/doc/irc-log/"); } else break; } diff --git a/tcpsyncclient.cpp b/tcpsyncclient.cpp index a5921be..bd26a38 100644 --- a/tcpsyncclient.cpp +++ b/tcpsyncclient.cpp @@ -1,13 +1,9 @@ #include "tcpsyncclient.h" -template -void TcpSyncClient::log(T message) +void TcpSyncClient::log(std::string message) { -#ifdef WIN32 std::cout << "[TSC] " << message; -#else - std::cout << "[TSC] " << message << std::endl; -#endif + if (message[message.size() - 1] != '\n') std::cout << std::endl; } TcpSyncClient::TcpSyncClient(boost::asio::ip::tcp::endpoint ep, boost::asio::io_service& s, @@ -20,9 +16,9 @@ TcpSyncClient::TcpSyncClient(boost::asio::ip::tcp::endpoint ep, boost::asio::io_ m_mynick(n), m_password(p) { - log(ep.address().to_string()); - log(ep.port()); - log(m_channel); + log (ep.address().to_string()); + log (std::to_string (ep.port()) ); + log (m_channel); } bool TcpSyncClient::write(std::string msg) @@ -130,10 +126,6 @@ void TcpSyncClient::process_msg() log("[MSG] " + msg); if (msg.find("PING :") == 0) answer_to_ping(msg.substr(6)); - /* if (msg.find("JOIN :" + m_channel) != std::string::npos && msg.find(m_mynick) == std::string::npos) { - write_to_channel(msg.substr(1, msg.find('!') - 1) + ", welcome to " + m_channel + "!"); - } */ - // Парсинг сообщений, адресованных боту. Сохраняет ник отправителя и текст. if (msg.find("PRIVMSG " + m_channel + " :" + m_mynick) != std::string::npos) { @@ -144,8 +136,7 @@ void TcpSyncClient::process_msg() } // Парсинг всех сообщений на канале. Сохраняет ник отправителя и текст. - else if (msg.find("PRIVMSG " + m_channel + " :") != std::string::npos && - msg.find(m_mynick) == std::string::npos) + else if (msg.find("PRIVMSG " + m_channel + " :") != std::string::npos) { m_raw = msg.substr(msg.find(m_channel + " :") + 2 + m_channel.size() ); while (m_raw[0] == ' ') m_raw = m_raw.substr(1); diff --git a/tcpsyncclient.h b/tcpsyncclient.h index aea56e6..37bc4d6 100644 --- a/tcpsyncclient.h +++ b/tcpsyncclient.h @@ -28,8 +28,7 @@ public: bool to_raw; private: - template - void log(T); + void log(std::string); bool connect_to_ep(); size_t read_complete(const error_code&, size_t); void read_answer();