Remove last GH header reference
[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 #include "Person.H"
34 #include "ServerList.H"
35 #include "ChannelList.H"
36 #include "UserList.H"
37 #include "ShitList.H"
38 #include "TodoList.H"
39 #include "Parser.H"
40
41 #ifdef USESCRIPTS
42 #include "BotInterp.H"
43 #include <libguile.h>
44 #endif
45
46 #define VERSION_STRING PACKAGE" version "VERSION" by unknown_lamer@FreeNode <clinton@unknownlamer.org>\n1.97 and below by eb@IRCNet <eb@via.ecp.fr>"
47 #define COPYRIGHT_STRING PACKAGE" version "VERSION", Copyright (C) 1997-2000 Etienne BERNARD\nCopyright (C) 2002,2003,2004,2005,2008 Clinton Ebadi"
48
49 class Channel;
50 class DCCConnection;
51 class Parser;
52 class DCCParser;
53 class DCCManager;
54 class ServerConnection;
55 class Commands;
56 class UserCommands;
57
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
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 TodoList * todoList;
86 #ifdef USESCRIPTS
87 BotInterp * botInterp;
88 #endif
89 std::map<std::string, class userFunction*,
90 std::less<std::string> > userFunctions;
91 std::map<String, wantedChannel *, std::less<String> > wantedChannels;
92
93 std::map<String, unsigned int, std::less<String> > ignoredUserhosts;
94 std::map<String, Person *, std::less<String> > spyList;
95
96 std::time_t startTime, currentTime, lastNickNameChange, lastChannelJoin;
97
98 ServerConnection * serverConnection;
99 DCCManager* dccConnections;
100
101 std::map<unsigned long, String, std::less<unsigned long> > userhostMap;
102 unsigned long sentUserhostID;
103 unsigned long receivedUserhostID;
104
105 static unsigned int MAX_MESSAGES;
106 static unsigned int MAX_NICKLENGTH;
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
114 private:
115 String logFileName;
116 String logs_dir;
117 String configFileName;
118 #ifdef USESCRIPTS
119 String scriptLogFileName;
120 String autoexecFileName;
121 #endif
122
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
137 // getters and setters
138 void set_log_dir (String);
139 void set_log_file (String);
140
141 friend class Parser;
142 friend class DCCParser;
143 friend class Person;
144 friend class Channel;
145 friend class ServerConnection;
146 friend class UserCommands;
147 friend class Commands;
148
149 private:
150 bool canChangeServer();
151 void nextServer();
152 void connect(int);
153
154 enum DCC_TYPE { CHAT };
155 void addDCC(Person *, unsigned long, int, int);
156
157 void rehash();
158 String getUserhost(String, String);
159 bool iAmOp(String);
160
161 void init_user_functions ();
162 void destroy_user_functions ();
163 };
164
165 #endif
166