38 lines
1.0 KiB
C++
38 lines
1.0 KiB
C++
#include "irc_parse_thread.hpp"
|
|
|
|
#include "connection.hpp"
|
|
#include "ircmsg.hpp"
|
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
#include <cstring>
|
|
|
|
namespace {
|
|
|
|
#include "irc_commands.inc"
|
|
|
|
} // namespace
|
|
|
|
IrcMsgEvent::IrcMsgEvent(IrcCommand command, IrcMsg const& irc)
|
|
: command{command}, irc{irc} {}
|
|
|
|
auto IrcParseThread::start(Connection& connection) -> void
|
|
{
|
|
connection.add_listener<LineEvent>([&connection](LineEvent const& event)
|
|
{
|
|
auto const msg = parse_irc_message(event.line);
|
|
auto const recognized = IrcCommandHash::in_word_set(msg.command.data(), msg.command.size());
|
|
auto const command
|
|
= recognized
|
|
&& recognized->min_args <= msg.args.size()
|
|
&& recognized->max_args >= msg.args.size()
|
|
? recognized->command : IrcCommand::UNKNOWN;
|
|
|
|
if (IrcCommand::UNKNOWN == command)
|
|
{
|
|
BOOST_LOG_TRIVIAL(warning) << "Unrecognized command: " << msg.command << " " << msg.args.size();
|
|
}
|
|
connection.make_event<IrcMsgEvent>(command, msg);
|
|
});
|
|
}
|