[project @ 2005-06-28 03:16:45 by unknown_lamer]
[clinton/bobotpp.git] / source / Bot.H
CommitLineData
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"
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// FIXME: remove guile/gh once transition is complete
45// This is the last reference to this header!
46#include <guile/gh.h>
47#endif
48
4edefeb6 49#define VERSION_STRING PACKAGE" version "VERSION" by unknown_lamer@FreeNode <clinton@unknownlamer.org>\n1.97 and below by eb@IRCNet <eb@via.ecp.fr>"
0bca109b 50#define COPYRIGHT_STRING PACKAGE" version "VERSION", Copyright (C) 1997-2000 Etienne BERNARD\nCopyright (C) 2002,2003,2004,2005 Clinton Ebadi"
cb21075d 51
52class Channel;
53class DCCConnection;
54class Parser;
55class DCCParser;
6530edbf 56class DCCManager;
cb21075d 57class ServerConnection;
58class Commands;
59class UserCommands;
cb21075d 60
61class Bot {
62public:
63 String nickName;
64 String wantedNickName;
65 String userName;
66 String ircName;
67 String versionString;
68 String userHost;
69 String localIP;
70 char commandChar;
71
cb21075d 72 String userListFileName;
73 String shitListFileName;
cb21075d 74 String helpFileName;
75 String initFileName;
cb21075d 76
77 std::ofstream logFile;
78
79 bool connected;
80 bool debug;
81 bool stop;
82 bool sentPing;
83
84 ChannelList * channelList;
85 UserList * userList;
86 ShitList * shitList;
87 ServerList * serverList;
88 TodoList * todoList;
89#ifdef USESCRIPTS
90 BotInterp * botInterp;
91#endif
e07b6b46 92 std::map<std::string, class userFunction*,
93 std::less<std::string> > userFunctions;
cb21075d 94 std::map<String, wantedChannel *, std::less<String> > wantedChannels;
95
96 std::map<String, unsigned int, std::less<String> > ignoredUserhosts;
97 std::map<String, Person *, std::less<String> > spyList;
98
99 std::time_t startTime, currentTime, lastNickNameChange, lastChannelJoin;
100
101 ServerConnection * serverConnection;
6530edbf 102 DCCManager* dccConnections;
cb21075d 103
104 std::map<unsigned long, String, std::less<unsigned long> > userhostMap;
105 unsigned long sentUserhostID;
106 unsigned long receivedUserhostID;
107
e171dcce 108 static unsigned int MAX_MESSAGES;
6b7614a8 109 static unsigned int MAX_NICKLENGTH;
cb21075d 110 static const std::time_t NICK_CHANGE = 60;
111 static const std::time_t CHANNEL_JOIN = 60;
112 static const std::time_t IGNORE_DELAY = 180;
113 static const std::time_t DCC_DELAY = 300;
114 static const std::time_t PING_TIME = 90;
115 static const std::time_t TIMEOUT = 120;
116
439869bf 117private:
118 String logFileName;
119 String logs_dir;
120 String configFileName;
121#ifdef USESCRIPTS
122 String scriptLogFileName;
123 String autoexecFileName;
124#endif
125
cb21075d 126public:
127
128 Bot(String, bool=false);
129 ~Bot();
130
131 void run();
132
133 void waitForInput();
134
135 void logLine(String);
136 void readConfig();
137
138 void reconnect();
139
be3612f3 140 // getters and setters
141 void set_log_dir (String);
142 void set_log_file (String);
439869bf 143
cb21075d 144 friend class Parser;
145 friend class DCCParser;
146 friend class Person;
147 friend class Channel;
cb21075d 148 friend class ServerConnection;
149 friend class UserCommands;
150 friend class Commands;
151
152private:
153 bool canChangeServer();
154 void nextServer();
155 void connect(int);
156
4edefeb6 157 enum DCC_TYPE { CHAT };
158 void addDCC(Person *, unsigned long, int, int);
cb21075d 159
160 void rehash();
161 String getUserhost(String, String);
162 bool iAmOp(String);
e07b6b46 163
164 void init_user_functions ();
165 void destroy_user_functions ();
cb21075d 166};
167
168#endif
31433d27 169