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 | |
70 | String configFileName; |
71 | String userListFileName; |
72 | String shitListFileName; |
73 | String logFileName; |
74 | String helpFileName; |
75 | String initFileName; |
76 | #ifdef USESCRIPTS |
77 | String scriptLogFileName; |
78 | String autoexecFileName; |
79 | #endif |
80 | |
81 | std::ofstream logFile; |
82 | |
83 | bool connected; |
84 | bool debug; |
85 | bool stop; |
86 | bool sentPing; |
87 | |
88 | ChannelList * channelList; |
89 | UserList * userList; |
90 | ShitList * shitList; |
91 | ServerList * serverList; |
92 | TodoList * todoList; |
93 | #ifdef USESCRIPTS |
94 | BotInterp * botInterp; |
95 | #endif |
96 | std::list<class userFunction *> userFunctions; |
97 | |
98 | std::map<String, wantedChannel *, std::less<String> > wantedChannels; |
99 | |
100 | std::map<String, unsigned int, std::less<String> > ignoredUserhosts; |
101 | std::map<String, Person *, std::less<String> > spyList; |
102 | |
103 | std::time_t startTime, currentTime, lastNickNameChange, lastChannelJoin; |
104 | |
105 | ServerConnection * serverConnection; |
106 | std::list<DCCConnection *> dccConnections; |
107 | |
108 | std::map<unsigned long, String, std::less<unsigned long> > userhostMap; |
109 | unsigned long sentUserhostID; |
110 | unsigned long receivedUserhostID; |
111 | |
112 | static const unsigned int MAX_MESSAGES = 2; |
113 | static const std::time_t NICK_CHANGE = 60; |
114 | static const std::time_t CHANNEL_JOIN = 60; |
115 | static const std::time_t IGNORE_DELAY = 180; |
116 | static const std::time_t DCC_DELAY = 300; |
117 | static const std::time_t PING_TIME = 90; |
118 | static const std::time_t TIMEOUT = 120; |
119 | |
120 | public: |
121 | |
122 | Bot(String, bool=false); |
123 | ~Bot(); |
124 | |
125 | void run(); |
126 | |
127 | void waitForInput(); |
128 | |
129 | void logLine(String); |
130 | void readConfig(); |
131 | |
132 | void reconnect(); |
133 | |
134 | friend class Parser; |
135 | friend class DCCParser; |
136 | friend class Person; |
137 | friend class Channel; |
138 | friend class Utils; |
139 | friend class ServerConnection; |
140 | friend class UserCommands; |
141 | friend class Commands; |
142 | |
143 | private: |
144 | bool canChangeServer(); |
145 | void nextServer(); |
146 | void connect(int); |
147 | |
148 | void addDCC(Person *, unsigned long, int); |
149 | |
150 | void rehash(); |
151 | String getUserhost(String, String); |
152 | bool iAmOp(String); |
153 | }; |
154 | |
155 | #endif |