Commit | Line | Data |
---|---|---|
cb21075d | 1 | // Bot.H -*- C++ -*- |
2 | // Copyright (c) 1997, 1998 Etienne BERNARD | |
4edefeb6 | 3 | // Copyright (c) 2002,2003 Clinton Ebadi |
cb21075d | 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 | |
39b022cb | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
cb21075d | 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> | |
e07b6b46 | 29 | #include <string> |
30 | #include <map> | |
cb21075d | 31 | |
32 | #include "String.H" | |
cb21075d | 33 | |
9eabf92f DS |
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,2009 Clinton Ebadi" | |
cb21075d | 36 | |
37 | class Channel; | |
cfa82921 | 38 | class ChannelList; |
39 | class Commands; | |
cb21075d | 40 | class DCCConnection; |
6530edbf | 41 | class DCCManager; |
cfa82921 | 42 | class DCCParser; |
43 | class Parser; | |
44 | class Person; | |
cb21075d | 45 | class ServerConnection; |
cfa82921 | 46 | class ServerList; |
47 | class ShitList; | |
cfa82921 | 48 | class UserList; |
cb21075d | 49 | class UserCommands; |
cb21075d | 50 | |
cfa82921 | 51 | class userFunction; |
52 | class wantedChannel; | |
53 | ||
54 | #ifdef USESCRIPTS | |
55 | class BotInterp; | |
56 | #endif | |
57 | ||
cb21075d | 58 | class Bot { |
59 | public: | |
60 | String nickName; | |
61 | String wantedNickName; | |
62 | String userName; | |
63 | String ircName; | |
64 | String versionString; | |
65 | String userHost; | |
66 | String localIP; | |
67 | char commandChar; | |
68 | ||
cb21075d | 69 | String userListFileName; |
70 | String shitListFileName; | |
cb21075d | 71 | String helpFileName; |
72 | String initFileName; | |
cb21075d | 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; | |
cb21075d | 85 | #ifdef USESCRIPTS |
86 | BotInterp * botInterp; | |
87 | #endif | |
e07b6b46 | 88 | std::map<std::string, class userFunction*, |
89 | std::less<std::string> > userFunctions; | |
cb21075d | 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; | |
6530edbf | 98 | DCCManager* dccConnections; |
cb21075d | 99 | |
100 | std::map<unsigned long, String, std::less<unsigned long> > userhostMap; | |
101 | unsigned long sentUserhostID; | |
102 | unsigned long receivedUserhostID; | |
103 | ||
e171dcce | 104 | static unsigned int MAX_MESSAGES; |
6b7614a8 | 105 | static unsigned int MAX_NICKLENGTH; |
cb21075d | 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 | ||
439869bf | 113 | private: |
114 | String logFileName; | |
115 | String logs_dir; | |
116 | String configFileName; | |
117 | #ifdef USESCRIPTS | |
118 | String scriptLogFileName; | |
119 | String autoexecFileName; | |
120 | #endif | |
121 | ||
cb21075d | 122 | public: |
123 | ||
124 | Bot(String, bool=false); | |
125 | ~Bot(); | |
126 | ||
127 | void run(); | |
128 | ||
129 | void waitForInput(); | |
130 | ||
131 | void logLine(String); | |
132 | void readConfig(); | |
133 | ||
134 | void reconnect(); | |
135 | ||
be3612f3 | 136 | // getters and setters |
137 | void set_log_dir (String); | |
138 | void set_log_file (String); | |
439869bf | 139 | |
cb21075d | 140 | friend class Parser; |
141 | friend class DCCParser; | |
142 | friend class Person; | |
143 | friend class Channel; | |
cb21075d | 144 | friend class ServerConnection; |
145 | friend class UserCommands; | |
146 | friend class Commands; | |
147 | ||
148 | private: | |
149 | bool canChangeServer(); | |
150 | void nextServer(); | |
151 | void connect(int); | |
152 | ||
4edefeb6 | 153 | enum DCC_TYPE { CHAT }; |
154 | void addDCC(Person *, unsigned long, int, int); | |
cb21075d | 155 | |
156 | void rehash(); | |
157 | String getUserhost(String, String); | |
158 | bool iAmOp(String); | |
e07b6b46 | 159 | |
160 | void init_user_functions (); | |
161 | void destroy_user_functions (); | |
cb21075d | 162 | }; |
163 | ||
164 | #endif | |
31433d27 | 165 |