// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, 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;
#define DEFAULT_NICKNAME "Bobot"
#define DEFAULT_USERNAME "bobot"
receivedUserhostID(0),
logFileName(DEFAULT_LOGFILENAME),
logs_dir (DEFAULT_LOGDIR),
- configFileName (filename),
+ configFileName (filename)
#ifdef USESCRIPTS
- scriptLogFileName(DEFAULT_SCRIPTLOGFILENAME),
+ ,scriptLogFileName(DEFAULT_SCRIPTLOGFILENAME),
autoexecFileName(DEFAULT_AUTOEXECFILENAME)
#endif
{
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);
initFileName = parameters;
else if (command == "LOCALIP")
localIP = parameters;
+ else if (command == "MAXNICKLENGTH")
+ 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);
if (thisTime->tm_sec == 0)
{
char s[6];
- std::sprintf(s, "%2d:%2d", thisTime->tm_hour, thisTime->tm_min);
+ std::snprintf(s, 6, "%02d:%02d", thisTime->tm_hour, thisTime->tm_min);
botInterp->RunHooks(Hook::TIMER, String(s),
scm_list_n (Utils::str2scm (std::string (s)),
void
Bot::set_log_file (String name)
{
- logFileName = name;
+ logFileName = logs_dir + name;
logFile.close ();
logFile.clear ();
#if HAVE_IOSBASE
- logFile.open(logs_dir + logFileName, std::ios_base::out |
+ logFile.open(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(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);
+ }
}