-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
101 lines (87 loc) · 1.97 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
95
96
97
98
99
100
101
/*
* main.cpp
*
* Created on 30 May 2013
* By: Synergiance
*/
#include <iostream>
#include <string>
#include <signal.h>
#include <cstdlib>
#include <cstring>
#include <new>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <thread>
#include "bot.h"
#include "config.h"
#include "miscbotlib.h"
using namespace std;
//Global
IrcBot* bot;
void sigHandler(int signum)
{
switch (signum)
{
// SIGINT
case 2:
cout<<"\nDetected ctrl+c\n";
bot->stop();
//exit(signum);
break;
// Mistake
default:
cout<<"\nUnknown signal detected...\n";
break;
}
return;
}
int main(int argc, char* argv[])
{
// Allocate memory
char* botmem = new char[sizeof(IrcBot)];
// Variables
int debugMode = 0;
bool verbose = false;
bool silent = false;
for (int c = 1; c < argc; c++)
{
if (strncmp(argv[c], "-d", 20) == 0)
{
if (++c < argc)
{
debugMode = atoi(argv[c]);
if (debugMode == 0 && strncmp(argv[c],"0",20) != 0)
{
c--;
debugMode = 5;
}
}
else
{
c--;
debugMode = 5;
}
}
if (strncmp(argv[c], "-v", 20) == 0)
verbose = true;
if (strncmp(argv[c], "-s", 20) == 0)
silent = true;
}
if (verbose && silent) { // Verbose and silent are incompatible
cout<<"Verbose and Silent cannot both be enabled at the same time\n"
<<"Program terminated\n";
}
else { // No conflicts
// Register SIGINT signal
signal(SIGINT, sigHandler);
// Launch bot
bot = new (botmem) IrcBot("ibot.cfg", debugMode, verbose);
bot->start();
delete bot;
}
return 0;
}