Add gnulib gettext module for config.rpath
[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 "BotThreading.H"
33 #include "String.H"
34
35 #define VERSION_STRING PACKAGE " version " VERSION " by unknown_lamer@FreeNode <clinton@unknownlamer.org>\n1.97 and below by eb@IRCNet <eb@via.ecp.fr>"
36 #define COPYRIGHT_STRING PACKAGE " version " VERSION ", Copyright (C) 1997-2000 Etienne BERNARD\nCopyright (C) 2002,2003,2004,2005,2008,2009,2020 Clinton Ebadi"
37
38 class Channel;
39 class ChannelList;
40 class Commands;
41 class DCCConnection;
42 class DCCManager;
43 class DCCParser;
44 class Parser;
45 class Person;
46 class ServerConnection;
47 class ServerList;
48 class ShitList;
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 userHost;
66 String localIP;
67 char commandChar;
68
69 String userListFileName;
70 String shitListFileName;
71 String helpFileName;
72 String initFileName;
73
74 std::ofstream logFile;
75
76 bool connected;
77 bool debug;
78 bool stop;
79 bool sentPing;
80
81 ChannelList * channelList;
82 UserList * userList;
83 ShitList * shitList;
84 ServerList * serverList;
85 #ifdef USESCRIPTS
86 BotInterp * botInterp;
87 #endif
88 std::map<std::string, class userFunction*,
89 std::less<std::string> > userFunctions;
90 std::map<String, wantedChannel *, std::less<String> > wantedChannels;
91
92 std::map<String, unsigned int, std::less<String> > ignoredUserhosts;
93 std::map<String, Person *, std::less<String> > spyList;
94
95 std::time_t startTime, currentTime, lastNickNameChange, lastChannelJoin;
96
97 ServerConnection * serverConnection;
98 DCCManager* dccConnections;
99
100 std::map<unsigned long, String, std::less<unsigned long> > userhostMap;
101 unsigned long sentUserhostID;
102 unsigned long receivedUserhostID;
103
104 static unsigned int MAX_MESSAGES;
105 static unsigned int MAX_NICKLENGTH;
106 static const std::time_t NICK_CHANGE = 60;
107 static const std::time_t CHANNEL_JOIN = 60;
108 static const std::time_t IGNORE_DELAY = 180;
109 static const std::time_t DCC_DELAY = 300;
110 static const std::time_t PING_TIME = 90;
111 static const std::time_t TIMEOUT = 120;
112
113 static const std::string release_revision;
114
115 private:
116 String logFileName;
117 String logs_dir;
118 String configFileName;
119 String versionString;
120
121 // mutexes (one per settable variable, although a global lock on bot
122 // state might not be unreasonable since setting is so rare)
123 mutable BotMutex version_mutex;
124
125 #ifdef USESCRIPTS
126 String scriptLogFileName;
127 String autoexecFileName;
128 #endif
129
130 public:
131
132 Bot(String, bool=false);
133 ~Bot();
134
135 void run();
136
137 void waitForInput();
138
139 void logLine(String);
140 void readConfig();
141
142 void reconnect();
143
144 // getters and setters
145 void set_log_dir (String);
146 void set_log_file (String);
147
148 String get_version () const;
149 void set_version (String);
150
151 friend class Parser;
152 friend class DCCParser;
153 friend class Person;
154 friend class Channel;
155 friend class ServerConnection;
156 friend class UserCommands;
157 friend class Commands;
158
159 private:
160 bool canChangeServer();
161 void nextServer();
162 void connect(int);
163
164 enum DCC_TYPE { CHAT };
165 void addDCC(Person *, unsigned long, int, int);
166
167 void rehash();
168 String getUserhost(String, String);
169 bool iAmOp(String);
170
171 void init_user_functions ();
172 void destroy_user_functions ();
173 };
174
175 #endif
176