-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (84 loc) · 2.57 KB
/
main.cpp
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
// Hebi - A node for the Hydra Decentralised IRC Bot
/* Main.cpp: Program skeleton
* Author: frony0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "irc/connection.hpp"
#include "irc/message.hpp"
#include "hydra/session.hpp"
#include "plugin/manager.hpp"
#include "thread.hpp"
#include "logger.hpp"
#include <iostream>
#include <thread>
#include <vector>
#include <memory>
void work(std::shared_ptr<irc::connection> pConn, std::shared_ptr<hydra::session> pSess, std::shared_ptr<plugin::manager> pMngr)
{
//pConn->start();
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
pSess->connect(std::string("localhost"), HYDRA_PORT+1);
while (pConn->running() || true)
{
std::vector<irc::message> lines = pConn->get();
for (irc::message msg : lines)
{
pMngr->handle(msg);
}
}
}
void usage(char *pBinary)
{
std::cout << "Usage: " << pBinary << " <host> <port>" << std::endl;
}
int main(int argc, char *argv[])
{
thread::init();
std::vector<std::string> args(argv + 1, argv + argc);
logs::info << "Starting Hebi" << logs::done;
auto logentry = logs::debug << "Args:";
for (std::string arg : args)
{
logentry << " " << arg;
}
logentry << logs::done;
logs::info << logs::done;
if (args.size() < 1)
{
usage(argv[0]);
}
else
{
std::string &host = args[0];
int port = 6667;
if (args.size() < 2)
{
logs::warn << "No port specified, defaulting to 6667" << logs::done;
}
else
{
try
{
port = stoi(args[1]);
}
catch (const std::invalid_argument&)
{
logs::fatal << "Port must be a number" << logs::done;
return EXIT_FAILURE;
}
if (port > 65535 || port < 1)
{
logs::fatal << "Port must be between 1-65535" << logs::done;
return EXIT_FAILURE;
}
}
std::shared_ptr<hydra::session> sessPtr(new hydra::session(HYDRA_PORT));
std::shared_ptr<hydra::session> sess2Ptr(new hydra::session(HYDRA_PORT+1));
std::shared_ptr<irc::connection> connPtr(new irc::connection(host, port));
std::shared_ptr<plugin::manager> mngrPtr(new plugin::manager(connPtr, &argc, &argv));
work(connPtr, sessPtr, mngrPtr);
}
return EXIT_SUCCESS;
}