diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..99f8cad --- /dev/null +++ b/main.cpp | |||
@@ -0,0 +1,81 @@ | |||
1 | /* | ||
2 | * File: main.cpp | ||
3 | * Author: hatkirby | ||
4 | * | ||
5 | * Created on August 10, 2013, 12:32 PM | ||
6 | */ | ||
7 | |||
8 | #include <stdlib.h> | ||
9 | #include "IRC.h" | ||
10 | #include <time.h> | ||
11 | #include <signal.h> | ||
12 | #include <cstring> | ||
13 | #include <string> | ||
14 | #include <dirent.h> | ||
15 | #include <deque> | ||
16 | #include <algorithm> | ||
17 | #include <yaml-cpp/yaml.h> | ||
18 | |||
19 | /* | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | char* hostname, nick, port, password, channel; | ||
24 | |||
25 | char* _(const char* str) | ||
26 | { | ||
27 | char* res = new char[strlen(str)+1]; | ||
28 | strcpy(res, str); | ||
29 | return res; | ||
30 | } | ||
31 | |||
32 | int message(char* params, irc_reply_data* hostd, void* conn) | ||
33 | { | ||
34 | std::string str(params); | ||
35 | std::string thetime(asctime(gettime())); | ||
36 | thetime = thetime.substr(4,15); | ||
37 | |||
38 | if (*hostd->target != '#') | ||
39 | { | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | // Examine content of strings | ||
44 | |||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | int end_of_motd(char* params, irc_reply_data* hostd, void* conn) | ||
49 | { | ||
50 | IRC* irc_conn = (IRC*) conn; | ||
51 | irc_conn->privmsg(_("NickServ"), strcat(_("Identify "), password)); | ||
52 | irc_conn->join(channel); | ||
53 | irc_conn->hook_irc_command(_("PRIVMSG"), &message); | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | void terminate(int param) | ||
59 | { | ||
60 | exit(1); | ||
61 | } | ||
62 | |||
63 | int main(int argc, char** argv) | ||
64 | { | ||
65 | atexit(end_logging); | ||
66 | signal(SIGTERM, terminate); | ||
67 | |||
68 | YAML::Node config = YAML::LoadFile("config.yml"); | ||
69 | hostname = _(config["hostname"].as<std::string>().c_str()); | ||
70 | port = _(config["port"].as<std::string>().c_str()); | ||
71 | nick = _(config["nick"].as<std::string>().c_str()); | ||
72 | password = _(config["password"].as<std::string>().c_str()); | ||
73 | channel = _(config["password"].as<std::string>().c_str()); | ||
74 | |||
75 | IRC conn; | ||
76 | conn.hook_irc_command("266", &end_of_motd); | ||
77 | conn.start(hostname, port, nick, nick, nick, password); | ||
78 | conn.message_loop(); | ||
79 | |||
80 | return (EXIT_SUCCESS); | ||
81 | } | ||