// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+// 02110-1301, USA.
-#include <fstream>
-#include <algorithm>
-#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <cstdio>
+
+#include <fstream>
+#include <algorithm>
+#include <iomanip>
+
+#include <dirent.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
+#ifdef USESCRIPTS
+#include <libguile.h>
+#endif
+
#include "Bot.H"
#include "DCCConnection.H"
#include "DCCChatConnection.H"
-#include "StringTokenizer.H"
+#include "ChannelList.H"
+#include "DCCManager.H"
+#include "DCCPerson.H"
+#include "Parser.H"
+#include "Person.H"
+#include "Server.H"
#include "ServerConnection.H"
-#include "Utils.H"
+#include "ServerList.H"
+#include "ShitList.H"
+#include "StringTokenizer.H"
+#include "User.H"
#include "UserCommands.H"
-#include "DCCManager.H"
+#include "UserList.H"
+#include "Utils.H"
+#ifdef USESCRIPTS
+#include "BotInterp.H"
+#include "Interp.H"
+#endif
+
unsigned int Bot::MAX_MESSAGES = 2;
unsigned int Bot::MAX_NICKLENGTH = 9;
readConfig();
userList = new UserList(userListFileName);
shitList = new ShitList(shitListFileName);
- todoList = new TodoList();
dccConnections = new DCCManager ();
// Let's read the alias file
- std::ifstream initFile(initFileName);
+ std::ifstream initFile(initFileName.c_str ());
if (initFile)
{
#ifdef USESCRIPTS
botInterp = new BotInterp(this, logs_dir + scriptLogFileName);
+ Interp::Startup2 (this);
botInterp->LoadScript(autoexecFileName);
#endif
}
shitList->save();
delete channelList;
delete userList;
- delete todoList;
delete serverList;
delete shitList;
delete serverConnection;
void
Bot::readConfig()
{
- std::ifstream file(configFileName);
+ std::ifstream file(configFileName.c_str ());
String temp;
int line = 1;
{
if (parameters[(unsigned int)0] == '/')
{
- set_log_dir ("/");
- set_log_file (parameters.subString (1));
+ StringTokenizer log_st (parameters);
+ std::string log_dir = "/";
+
+ for (unsigned int m = log_st.count_tokens ('/');
+ --m;
+ m > 0)
+ {
+ log_dir += log_st.next_token ('/') + "/";
+ }
+
+ std::cerr << "==" << log_dir << std::endl;
+
+ set_log_dir (log_dir);
+ set_log_file (log_st.rest ());
}
else
set_log_file (parameters);
else if (command == "LOCALIP")
localIP = parameters;
else if (command == "MAXNICKLENGTH")
- MAX_NICKLENGTH = std::atoi (parameters);
+ MAX_NICKLENGTH = std::atoi (parameters.c_str ());
else if (command == "SERVER") {
if (parameters.indexOf(' ') == -1)
serverList->addServer(new Server(parameters));
st2.next_token()));
}
}
+ else if (command == "")
+ {
+ // do nothing
+ }
else {
logLine(String("Syntax error in file ") + configFileName +
", line " + String((long)line));
{
// Disconnected
#ifdef USESCRIPTS
- // Run hooks/disconnected
+ // Run hooks/disconnect
this->botInterp->RunHooks
(Hook::DISCONNECT,
serverConnection->server->getHostName (),
scm_list_n
- (Utils::str2scm (serverConnection->server->getHostName ())));
+ (Utils::str2scm (serverConnection->server->getHostName ()),
+ SCM_BOOL_F));
#endif
nextServer();
}
if ((*it).second > 0)
(*it).second--;
- String line;
- while ((line = todoList->getNext()) != "") {
- serverConnection->queue->sendChannelMode(line);
- }
+ for (std::map<String, Channel *, std::less<String> >::iterator it = channelList->begin ();
+ it != channelList->end ();
+ ++it)
+ {
+ it->second->purge_expired_bans ();
+ }
#ifdef USESCRIPTS
botInterp->RunTimers(currentTime);
it != channelList->end(); ++it) {
channel = (*it).first;
c = channelList->getChannel(channel);
- if (c->countOp == 1 &&
- c->count > 1 && this->iAmOp(channel))
+ if (c->operator_count () == 1 &&
+ c->user_count () > 1 && this->iAmOp(channel))
return false;
}
return true;
if (c && c->hasNick(nick))
- return c->getUser(nick)->userhost;
+ return c->getUser(nick).userhost;
unsigned long num = sentUserhostID++;
bool
Bot::iAmOp(String channel)
{
- User * me = channelList->getChannel(channel)->getUser(nickName);
- return (me->mode & User::OP_MODE);
+ return channelList->getChannel(channel)->getUser(nickName).mode & User::OP_MODE;
}
void
logFile.close ();
logFile.clear ();
#if HAVE_IOSBASE
- logFile.open(logs_dir + logFileName, std::ios_base::out |
+ logFile.open((logs_dir + logFileName).c_str (), std::ios_base::out |
std::ios_base::ate | std::ios_base::app);
#else
- logFile.open(logs_dir + logFileName, ios::out | ios::ate
+ logFile.open((logs_dir + logFileName).c_str (), ios::out | ios::ate
| ios::app);
#endif
Bot::set_log_dir (String dir)
{
logs_dir = dir;
+
+ DIR *temp = opendir (logs_dir.c_str ());
+
+ if (!temp)
+ {
+ mkdir (logs_dir.c_str (), S_IRWXU);
+ }
+ else
+ {
+ closedir (temp);
+ }
}