7dd25a1b1ed945df1a5ad8236c50e64f0537aa8f
[clinton/bobotpp.git] / source / Bot.H
1 // Bot.H -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (c) 2002,2003 Clinton Ebadi
4
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19 #ifndef BOT_H
20 #define BOT_H
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <ctime>
27 #include <set>
28 #include <fstream>
29 #include <string>
30 #include <map>
31
32 #include "String.H"
33
34 #define VERSION_STRING PACKAGE" version "VERSION" by unknown_lamer@FreeNode <clinton@unknownlamer.org>\n1.97 and below by eb@IRCNet <eb@via.ecp.fr>"
35 #define COPYRIGHT_STRING PACKAGE" version "VERSION", Copyright (C) 1997-2000 Etienne BERNARD\nCopyright (C) 2002,2003,2004,2005,2008 Clinton Ebadi"
36
37 class Channel;
38 class ChannelList;
39 class Commands;
40 class DCCConnection;
41 class DCCManager;
42 class DCCParser;
43 class Parser;
44 class Person;
45 class ServerConnection;
46 class ServerList;
47 class ShitList;
48 class TodoList;
49 class UserList;
50 class UserCommands;
51
52 class userFunction;
53 class wantedChannel;
54
55 #ifdef USESCRIPTS
56 class BotInterp;
57 #endif
58
59 class Bot {
60 public:
61 String nickName;
62 String wantedNickName;
63 String userName;
64 String ircName;
65 String versionString;
66 String userHost;
67 String localIP;
68 char commandChar;
69
70 String userListFileName;
71 String shitListFileName;
72 String helpFileName;
73 String initFileName;
74
75 std::ofstream logFile;
76
77 bool connected;
78 bool debug;
79 bool stop;
80 bool sentPing;
81
82 ChannelList * channelList;
83 UserList * userList;
84 ShitList * shitList;
85 ServerList * serverList;
86 TodoList * todoList;
87 #ifdef USESCRIPTS
88 BotInterp * botInterp;
89 #endif
90 std::map<std::string, class userFunction*,
91 std::less<std::string> > userFunctions;
92 std::map<String, wantedChannel *, std::less<String> > wantedChannels;
93
94 std::map<String, unsigned int, std::less<String> > ignoredUserhosts;
95 std::map<String, Person *, std::less<String> > spyList;
96
97 std::time_t startTime, currentTime, lastNickNameChange, lastChannelJoin;
98
99 ServerConnection * serverConnection;
100 DCCManager* dccConnections;
101
102 std::map<unsigned long, String, std::less<unsigned long> > userhostMap;
103 unsigned long sentUserhostID;
104 unsigned long receivedUserhostID;
105
106 static unsigned int MAX_MESSAGES;
107 static unsigned int MAX_NICKLENGTH;
108 static const std::time_t NICK_CHANGE = 60;
109 static const std::time_t CHANNEL_JOIN = 60;
110 static const std::time_t IGNORE_DELAY = 180;
111 static const std::time_t DCC_DELAY = 300;
112 static const std::time_t PING_TIME = 90;
113 static const std::time_t TIMEOUT = 120;
114
115 private:
116 String logFileName;
117 String logs_dir;
118 String configFileName;
119 #ifdef USESCRIPTS
120 String scriptLogFileName;
121 String autoexecFileName;
122 #endif
123
124 public:
125
126 Bot(String, bool=false);
127 ~Bot();
128
129 void run();
130
131 void waitForInput();
132
133 void logLine(String);
134 void readConfig();
135
136 void reconnect();
137
138 // getters and setters
139 void set_log_dir (String);
140 void set_log_file (String);
141
142 friend class Parser;
143 friend class DCCParser;
144 friend class Person;
145 friend class Channel;
146 friend class ServerConnection;
147 friend class UserCommands;
148 friend class Commands;
149
150 private:
151 bool canChangeServer();
152 void nextServer();
153 void connect(int);
154
155 enum DCC_TYPE { CHAT };
156 void addDCC(Person *, unsigned long, int, int);
157
158 void rehash();
159 String getUserhost(String, String);
160 bool iAmOp(String);
161
162 void init_user_functions ();
163 void destroy_user_functions ();
164 };
165
166 #endif
167