cb21075d |
1 | // Bot.H -*- C++ -*- |
2 | // Copyright (c) 1997, 1998 Etienne BERNARD |
3 | // Copyright (c) 2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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 | |
30 | #include "String.H" |
31 | #include "Person.H" |
32 | #include "ServerList.H" |
33 | #include "ChannelList.H" |
34 | #include "UserList.H" |
35 | #include "ShitList.H" |
36 | #include "TodoList.H" |
37 | #include "Parser.H" |
38 | |
39 | #ifdef USESCRIPTS |
40 | #include "BotInterp.H" |
41 | #include <libguile.h> |
42 | // FIXME: remove guile/gh once transition is complete |
43 | // This is the last reference to this header! |
44 | #include <guile/gh.h> |
45 | #endif |
46 | |
47 | #define VERSION_STRING PACKAGE" version "VERSION" by unknown_lamer@OPN <clinton@unknownlamer.org>\n1.97 and below by eb@IRCNet <eb@via.ecp.fr>" |
48 | #define COPYRIGHT_STRING PACKAGE" version "VERSION", Copyright (C) 1997-2000 Etienne BERNARD\nCopyright (C) 2002 Clinton Ebadi" |
49 | |
50 | class Channel; |
51 | class DCCConnection; |
52 | class Parser; |
53 | class DCCParser; |
54 | class ServerConnection; |
55 | class Commands; |
56 | class UserCommands; |
57 | class Utils; |
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 | |
cb21075d |
70 | String userListFileName; |
71 | String shitListFileName; |
cb21075d |
72 | String helpFileName; |
73 | String initFileName; |
cb21075d |
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::list<class userFunction *> userFunctions; |
91 | |
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 | std::list<DCCConnection *> dccConnections; |
101 | |
102 | std::map<unsigned long, String, std::less<unsigned long> > userhostMap; |
103 | unsigned long sentUserhostID; |
104 | unsigned long receivedUserhostID; |
105 | |
106 | static const unsigned int MAX_MESSAGES = 2; |
107 | static const std::time_t NICK_CHANGE = 60; |
108 | static const std::time_t CHANNEL_JOIN = 60; |
109 | static const std::time_t IGNORE_DELAY = 180; |
110 | static const std::time_t DCC_DELAY = 300; |
111 | static const std::time_t PING_TIME = 90; |
112 | static const std::time_t TIMEOUT = 120; |
113 | |
439869bf |
114 | private: |
115 | String logFileName; |
116 | String logs_dir; |
117 | String configFileName; |
118 | #ifdef USESCRIPTS |
119 | String scriptLogFileName; |
120 | String autoexecFileName; |
121 | #endif |
122 | |
cb21075d |
123 | public: |
124 | |
125 | Bot(String, bool=false); |
126 | ~Bot(); |
127 | |
128 | void run(); |
129 | |
130 | void waitForInput(); |
131 | |
132 | void logLine(String); |
133 | void readConfig(); |
134 | |
135 | void reconnect(); |
136 | |
439869bf |
137 | |
cb21075d |
138 | friend class Parser; |
139 | friend class DCCParser; |
140 | friend class Person; |
141 | friend class Channel; |
142 | friend class Utils; |
143 | friend class ServerConnection; |
144 | friend class UserCommands; |
145 | friend class Commands; |
146 | |
147 | private: |
148 | bool canChangeServer(); |
149 | void nextServer(); |
150 | void connect(int); |
151 | |
152 | void addDCC(Person *, unsigned long, int); |
153 | |
154 | void rehash(); |
155 | String getUserhost(String, String); |
156 | bool iAmOp(String); |
157 | }; |
158 | |
159 | #endif |
31433d27 |
160 | |