// Let's read the alias file
std::ifstream initFile(initFileName);
- if (initFile) {
- String temp, alias, command;
- int line = 0;
- while (initFile >> temp, temp.length() != 0) {
- line++;
- StringTokenizer st(temp);
- temp = Utils::trim_str (temp);
- if (temp[(unsigned int)0]=='#') continue;
- if (st.count_tokens (' ') != 2) {
- std::cerr << "Error when reading alias file (" << initFileName
- << ") line " << line << "...\n";
- continue;
- }
- alias = Utils::to_upper (st.next_token());
- command = Utils::to_upper (st.next_token());
-
- // Does the function already exist ?
- if (!userFunctions[alias])
+ if (initFile)
+ {
+ // FIXME: these variables are current String instead of
+ // std::string because String>> reads an entire line. This code
+ // needs to be rewritten to use std::string and std::getline (or
+ // better yet, be removed entirely once BotConfig is in place)
+ String temp, alias, command;
+ int line = 0;
+
+ while (initFile >> temp, temp.length() != 0)
{
- if (userFunction *u = userFunctions[command])
- userFunctions[alias] =
- new
- userFunction(u->function,
- u->minLevel,
- u->needsChannelName);
+ StringTokenizer st(temp);
+
+ line++;
+ temp = Utils::trim_str (temp);
+
+ if (temp[0]=='#')
+ {
+ continue;
+ }
+
+ if (st.count_tokens (' ') != 2)
+ {
+ std::cerr << "Error when reading alias file (" << initFileName
+ << ") line " << line << "...\n";
+ continue;
+ }
+
+ alias = Utils::to_upper (st.next_token());
+ command = Utils::to_upper (st.next_token());
+
+ // Does the function already exist ?
+ if (!userFunctions[alias])
+ {
+ if (userFunction *u = userFunctions[command])
+ userFunctions[alias] =
+ new
+ userFunction(u->function,
+ u->minLevel,
+ u->needsChannelName);
+ }
}
}
- }
std::srand (std::time (0)); // srand for bot-random
+
#ifdef USESCRIPTS
botInterp = new BotInterp(this, logs_dir + scriptLogFileName);
botInterp->LoadScript(autoexecFileName);
{
char s[6];
std::sprintf(s, "%2d:%2d", thisTime->tm_hour, thisTime->tm_min);
- // FIXME: uses gh_list
+
botInterp->RunHooks(Hook::TIMER, String(s),
- gh_list(Utils::str2scm (std::string (s)),
- SCM_UNDEFINED));
+ scm_list_n (Utils::str2scm (std::string (s)),
+ SCM_UNDEFINED));
}
#endif
serverConnection->queue->sendJoin((*it).first, (*it).second->key);
}
- if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::PING_TIME) && !sentPing) {
- serverConnection->queue->sendPing("Testing connection");
- sentPing = true;
- }
+ if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken
+ + Bot::PING_TIME) && !sentPing)
+ {
+ serverConnection->queue->sendPing("Testing connection");
+ sentPing = true;
+ }
- if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::TIMEOUT)) {
- sentPing = false;
- nextServer();
- }
+ if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken
+ + Bot::TIMEOUT))
+ {
+ sentPing = false;
+ nextServer();
+ }
}
// We can change server if we will not lose op on a channel
DCCConnection *d = 0;
if (type == CHAT)
- d = new DCCChatConnection(this, from->getAddress (),
- address, port);
+ {
+ d = new DCCChatConnection(this, from->getAddress (),
+ address, port);
+ }
else
- return;
+ {
+ return;
+ }
if (!d->connect())
{
logLine ("DCC Connection failed from " + from->getAddress ());
return;
}
+
logLine ("DCC CHAT accepted from" + from->getAddress ());
dccConnections->addConnection (d);
}
-// Main.C -*- C++ -*-
-// Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (C) 2002 Clinton Ebadi
-
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// any later version.
-
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// 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.
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <unistd.h>
-#include <iostream>
-#include <cstdio>
-#include <csignal>
-#include <cstdlib>
-#include <getopt.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#ifdef USESCRIPTS
-#include "Interp.H"
-#endif
-
-#include "Bot.H"
-
-namespace
-{
-Bot *b;
-
-option bot_options[] =
-{
- { "help", no_argument, 0, 'h' },
- { "version", no_argument, 0, 'v' },
- { "no-background", no_argument, 0, 'b'},
- { "config-file", required_argument, 0, 'f'},
- { "config-dir", required_argument, 0, 'd'},
- { "config", required_argument, 0, 'c'},
- { "sys-config", required_argument, 0, 's'},
- { "user-config", required_argument, 0, 'u'},
- { "debug", no_argument, 0, 'D' }
-};
-
-void sig_hup(int) {
- if (b) {
- b->userList->read();
- b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, "");
- b->reconnect();
- }
-}
-
-void print_version ()
-{
- std::cerr << VERSION_STRING << std::endl
- << COPYRIGHT_STRING << std::endl
- << PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
- << "This is free software, and you are welcome to redistribute it\n"
- << "under certain conditions; See the COPYING file for details.\n";
-}
-void print_short_help (const char *name)
-{
- std::cerr << "Usage: "
- << name
- << " [--help] [--version] [--no-background]\n\t"
- << "[--config-file file] [--config-dir dir] [--debug]\n\t"
- << "[--config dir-under-configpath]\n\t"
- << "[--sys-config dir-in-sysconfdir]\n\t"
- << "[--user-config dir-userdir] [--debug]\n"
- << "\n--help shows long help.\n";
-}
-
-void print_long_help (const char *name)
-{
- std::cerr << "Long Help for " << PACKAGE << std::endl;
- std::cerr <<
- "The manual (info bobot++) will contain the best information on general\n"
- "usage of Bobot++. Here is a detailed summary of the command line\n"
- "arguments: (in long arg short arg format). All args are optional.\n";
- print_short_help (name);
- std::cerr <<
-"[--help][-h] Shows this help and exits\n"
-"[--version][-v] Shows version information and exits\n"
-"[--no-background][-b] Run bobot++ in the foreground\n"
-"[--config-file file][-f] Use file instead of bot.conf\n"
-"[--config-dir dir][-d] Use dir as dir to load config file from\n"
-"[--config dir][-c] Search your config path (defaults to\n"
-" "
- << getenv ("HOME")
- << "/.bobotpp/config/ and then\n"
- <<
-" /etc/bobotpp/) for dir and\n"
-" then loads your config data using dir\n"
-"[--sys-config dir][-s] Looks for config in /etc/bobotpp/dir. Note\n"
-" that the user dir is still searched first\n"
-"[--user-config dir][-u] Looks for config in\n"
-" "
- << getenv("HOME")
- << "/.bobotpp/config/dir/.\n"
- <<
-" Note that\n"
-" the system dir is still searched after this if\n"
-" dir is not found.\n"
-"[--debug][-D] Makes Bobot++ print debugging info and run in\n"
-" the foreground"
- << std::endl
- << std::endl
- << "The default configuration is read from\n"
- << getenv("HOME")
- << "/.bobotpp/config/default/ and then\n"
- "/etc/bobotpp/default/ if the user config is not found.\n";
-}
-
-static void real_main(void* DONOTUSE, int argc, char **argv)
-{
- // FIXME: User directory
- int opt;
- bool background = true;
- String configFile = "bot.conf";
- String cmd_directory = "";
- String sys_directory = "/etc/bobotpp/";
- String sys_subdir = "default";
- String user_directory = String(getenv ("HOME")) + "/.bobotpp/config/";
- String user_subdir = "default";
- bool debug = false;
-
- std::signal(SIGPIPE, SIG_IGN);
- std::signal(SIGALRM, SIG_IGN);
- std::signal(SIGHUP, sig_hup);
-
- // We parse the command line options
- while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0))
- != -1)
- switch (opt) {
- case 'h':
- print_long_help (argv[0]);
- exit(0);
- break;
- case 'v':
- print_version ();
- exit (0);
- break;
- case 'b':
- background = false;
- break;
- case 'f':
- configFile = optarg;
- break;
- case 'd':
- cmd_directory = optarg;
- break;
- case 'c':
- sys_subdir = optarg;
- user_subdir = optarg;
- break;
- case 'u':
- user_subdir = optarg;
- break;
- case 's':
- sys_subdir = optarg;
- break;
- case 'D':
- debug = true;
- break;
- default:
- print_short_help (argv[0]);
- std::exit(1);
- }
-
- DIR * temp;
- if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs")))
- mkdir (String(getenv ("HOME")) + "/.bobotpp/logs",
- S_IRWXU);
- else
- closedir (temp);
-
- if (!cmd_directory.length ())
- {
- if (chdir(user_directory + user_subdir) < 0)
- if (chdir(sys_directory + sys_subdir) < 0)
- {
- std::cerr << "Dirs don't exist! Exiting\n";
- std::exit (2); // no execution
- }
- }
- else
- if (chdir(cmd_directory) < 0)
- {
- std::perror("Error: ");
- std::cerr << "Exiting...\n";
- std::exit (2);
- }
-
- // std::cout << COPYRIGHT_STRING <<
- // "\n"PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
- // "This is free software, and you are welcome to redistribute it\n"
- // "under certain conditions; See the COPYING file for details.\n";
- print_version ();
-
- // initialize the Parser
- Parser::init ();
-
- if (!debug) {
- if (background)
- switch (fork()) {
- case -1:
- std::cout << "Could not run in the background. Exiting...\n";
- perror("fork");
- exit(1);
- case 0:
- break;
- default:
- std::cout << "Running in the background...\n";
- exit(0);
- }
- }
-
-#ifdef USESCRIPTS
- Interp::Startup();
-#endif
-
- b = new Bot(configFile, debug);
- b->run();
- delete b;
-
-#ifdef USESCRIPTS
- Interp::Shutdown();
-#endif
-}
-
-} // static functions and data
-
-int main(int argc, char **argv)
-{
-#ifdef USESCRIPTS
- scm_boot_guile (argc, argv, real_main, 0);
-#else
- real_main(0, argc, argv);
-#endif
-
- return 0;
-}
+// Main.C -*- C++ -*-
+// Copyright (c) 1997, 1998 Etienne BERNARD
+// Copyright (C) 2002,2005 Clinton Ebadi
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// 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.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <cstdio>
+#include <csignal>
+#include <cstdlib>
+#include <getopt.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <iostream>
+#include <string>
+
+#ifdef USESCRIPTS
+#include "Interp.H"
+#endif
+
+#include "Bot.H"
+
+namespace
+{
+ Bot *b;
+
+ option bot_options[] =
+ {
+ { "help", no_argument, 0, 'h' },
+ { "version", no_argument, 0, 'v' },
+ { "no-background", no_argument, 0, 'b'},
+ { "config-file", required_argument, 0, 'f'},
+ { "config-dir", required_argument, 0, 'd'},
+ { "config", required_argument, 0, 'c'},
+ { "sys-config", required_argument, 0, 's'},
+ { "user-config", required_argument, 0, 'u'},
+ { "debug", no_argument, 0, 'D' }
+ };
+
+ void sig_hup(int) {
+ if (b) {
+ b->userList->read();
+ b->userList->addUserFirst("bidon", "bidon", 0, 0, false, 0, "");
+ b->reconnect();
+ }
+ }
+
+ void print_version ()
+ {
+ std::cerr << VERSION_STRING << std::endl
+ << COPYRIGHT_STRING << std::endl
+ << PACKAGE" comes with ABSOLUTELY NO WARRANTY\n"
+ << "This is free software, and you are welcome to redistribute it\n"
+ << "under certain conditions; See the COPYING file for details.\n";
+ }
+ void print_short_help (const char *name)
+ {
+ std::cerr << "Usage: "
+ << name
+ << " [--help] [--version] [--no-background]\n\t"
+ << "[--config-file file] [--config-dir dir] [--debug]\n\t"
+ << "[--config dir-under-configpath]\n\t"
+ << "[--sys-config dir-in-sysconfdir]\n\t"
+ << "[--user-config dir-userdir] [--debug]\n"
+ << "\n--help shows long help.\n";
+ }
+
+ void print_long_help (const char *name)
+ {
+ std::cerr << "Long Help for " << PACKAGE << std::endl;
+ std::cerr <<
+ "The manual (info bobot++) will contain the best information on general\n"
+ "usage of Bobot++. Here is a detailed summary of the command line\n"
+ "arguments: (in long arg short arg format). All args are optional.\n";
+ print_short_help (name);
+ std::cerr <<
+ "[--help][-h] Shows this help and exits\n"
+ "[--version][-v] Shows version information and exits\n"
+ "[--no-background][-b] Run bobot++ in the foreground\n"
+ "[--config-file file][-f] Use file instead of bot.conf\n"
+ "[--config-dir dir][-d] Use dir as dir to load config file from\n"
+ "[--config dir][-c] Search your config path (defaults to\n"
+ " "
+ << getenv ("HOME")
+ << "/.bobotpp/config/ and then\n"
+ <<
+ " /etc/bobotpp/) for dir and\n"
+ " then loads your config data using dir\n"
+ "[--sys-config dir][-s] Looks for config in /etc/bobotpp/dir. Note\n"
+ " that the user dir is still searched first\n"
+ "[--user-config dir][-u] Looks for config in\n"
+ " "
+ << getenv("HOME")
+ << "/.bobotpp/config/dir/.\n"
+ <<
+ " Note that\n"
+ " the system dir is still searched after this if\n"
+ " dir is not found.\n"
+ "[--debug][-D] Makes Bobot++ print debugging info and run in\n"
+ " the foreground"
+ << std::endl
+ << std::endl
+ << "The default configuration is read from\n"
+ << getenv("HOME")
+ << "/.bobotpp/config/default/ and then\n"
+ "/etc/bobotpp/default/ if the user config is not found.\n";
+ }
+
+ static void real_main(void* DONOTUSE, int argc, char **argv)
+ {
+ // FIXME: User directory
+ int opt;
+ bool background = true;
+ std::string configFile = "bot.conf";
+ std::string cmd_directory = "";
+ std::string sys_directory = "/etc/bobotpp/";
+ std::string sys_subdir = "default";
+ std::string user_directory =
+ std::string (getenv ("HOME")) + "/.bobotpp/config/";
+ String user_subdir = "default";
+ bool debug = false;
+
+ std::signal(SIGPIPE, SIG_IGN);
+ std::signal(SIGALRM, SIG_IGN);
+ std::signal(SIGHUP, sig_hup);
+
+ // We parse the command line options
+ while ((opt = getopt_long (argc,argv,"vhbf:d:c:D", bot_options, 0))
+ != -1)
+ {
+ switch (opt)
+ {
+ case 'h':
+ print_long_help (argv[0]);
+ exit(0);
+ break;
+ case 'v':
+ print_version ();
+ exit (0);
+ break;
+ case 'b':
+ background = false;
+ break;
+ case 'f':
+ configFile = optarg;
+ break;
+ case 'd':
+ cmd_directory = optarg;
+ break;
+ case 'c':
+ sys_subdir = optarg;
+ user_subdir = optarg;
+ break;
+ case 'u':
+ user_subdir = optarg;
+ break;
+ case 's':
+ sys_subdir = optarg;
+ break;
+ case 'D':
+ debug = true;
+ break;
+ default:
+ print_short_help (argv[0]);
+ std::exit(1);
+ }
+ }
+
+ DIR * temp;
+
+ if (! (temp = opendir (String(getenv ("HOME")) + "/.bobotpp/logs")))
+ {
+ mkdir (String(getenv ("HOME")) + "/.bobotpp/logs",
+ S_IRWXU);
+ }
+ else
+ {
+ closedir (temp);
+ }
+
+ if (!cmd_directory.length ())
+ {
+ if (chdir((user_directory + user_subdir).c_str ()) < 0)
+ {
+ if (chdir ((sys_directory + sys_subdir).c_str ()) < 0)
+ {
+ std::cerr << "Dirs don't exist! Exiting\n";
+ std::exit (2); // no execution
+ }
+ }
+ }
+ else
+ {
+ if (chdir (cmd_directory.c_str ()) < 0)
+ {
+ std::perror("Error: ");
+ std::cerr << "Exiting...\n";
+ std::exit (2);
+ }
+ }
+
+ print_version ();
+
+ // initialize the Parser
+ Parser::init ();
+
+ if (!debug) {
+ if (background)
+ switch (fork()) {
+ case -1:
+ std::cout << "Could not run in the background. Exiting...\n";
+ perror("fork");
+ exit(1);
+ case 0:
+ break;
+ default:
+ std::cout << "Running in the background...\n";
+ exit(0);
+ }
+ }
+
+#ifdef USESCRIPTS
+ Interp::Startup();
+#endif
+
+ b = new Bot(configFile, debug);
+ b->run();
+ delete b;
+
+#ifdef USESCRIPTS
+ Interp::Shutdown();
+#endif
+ }
+
+} // static functions and data
+
+int main(int argc, char **argv)
+{
+#ifdef USESCRIPTS
+ scm_boot_guile (argc, argv, real_main, 0);
+#else
+ real_main(0, argc, argv);
+#endif
+
+ return 0;
+}
clear();
- if (!file) {
- std::cerr << "I cannot find the file " << listFilename << std::endl;
- return;
- }
-
- while (file >> temp, temp.length() != 0) {
- StringTokenizer st(temp);
- if (st.count_tokens(':') != 7) {
- std::cerr << "Error when reading userlist (" << listFilename <<
- ") line " << line << "...\n";
+ if (!file)
+ {
+ std::cerr << "I cannot find the file " << listFilename << std::endl;
return;
}
- String mask = st.next_token(':');
- String maskChannel = st.next_token(':');
- String level = st.next_token(':');
- String prot = st.next_token(':');
- String aop = st.next_token(':');
- String expiration = st.next_token(':');
- String password = Utils::trim_str (st.rest());
- if (password == "*NONE*")
- password = "";
- l.push_back(new UserListItem(mask, maskChannel, atoi(level),
- atoi(prot), atoi(aop),
- atol(expiration), password));
- line++;
- }
+
+ while (file >> temp, temp.length() != 0)
+ {
+ StringTokenizer st(temp);
+
+ if (st.count_tokens(':') != 7)
+ {
+ std::cerr << "Error when reading userlist (" << listFilename <<
+ ") line " << line << "...\n";
+ return;
+ }
+
+ String mask = st.next_token(':');
+ String maskChannel = st.next_token(':');
+ String level = st.next_token(':');
+ String prot = st.next_token(':');
+ String aop = st.next_token(':');
+ String expiration = st.next_token(':');
+ String password = Utils::trim_str (st.rest());
+
+ if (password == "*NONE*")
+ {
+ password = "";
+ }
+
+ l.push_back(new UserListItem(mask, maskChannel, atoi(level),
+ atoi(prot), atoi(aop),
+ atol(expiration), password));
+ line++;
+ }
+
file.close();
}
if (!file)
return;
- // FIXME: fix bug (see BUGS) and inc once
- ++it; ++it; // We skip the bot's entry
+ ++it; // Skip the bot's entry
+
for ( ; it != l.end(); ++it)
- if ((*it)->isStillValid()) {
- file << (*it)->mask.getMask() << ":"
- << (*it)->channelMask.getMask() << ":"
- << (*it)->level << ":"
- << (*it)->prot << ":"
- << (*it)->aop << ":"
- << (*it)->expirationDate << ":";
- if ((*it)->passwd == "")
- file << "*NONE*";
- else
- file << (*it)->passwd;
- file << std::endl;
+ {
+ if ((*it)->isStillValid())
+ {
+ file << (*it)->mask.getMask() << ":"
+ << (*it)->channelMask.getMask() << ":"
+ << (*it)->level << ":"
+ << (*it)->prot << ":"
+ << (*it)->aop << ":"
+ << (*it)->expirationDate << ":";
+
+ if ((*it)->passwd == "")
+ {
+ file << "*NONE*";
+ }
+ else
+ {
+ file << (*it)->passwd;
+ }
+
+ file << std::endl;
+ }
}
}
{
UserListItem *uli;
- while (!l.empty()) {
- uli = (*l.begin());
- l.erase(l.begin());
- delete uli;
- }
+ while (!l.empty())
+ {
+ uli = (*l.begin());
+ l.erase(l.begin());
+ delete uli;
+ }
}
void
for (std::list<UserListItem *>::iterator it = l.begin();
it != l.end(); it++)
- if ((*it)->matches(nuh) && level < (*it)->level &&
- ((*it)->expirationDate == -1 ||
- (*it)->expirationDate > current_time) &&
- ((*it)->passwd == "" || (*it)->identified > 0))
- level = (*it)->level;
+ {
+ if ((*it)->matches(nuh) && level < (*it)->level
+ && ((*it)->expirationDate == -1
+ || (*it)->expirationDate > current_time)
+ && ((*it)->passwd == ""
+ || (*it)->identified > 0))
+ {
+ level = (*it)->level;
+ }
+ }
return level;
}