Commit 92017902 authored by Romain Bignon's avatar Romain Bignon

create the cmdChan and user joins it automatically

parent 1a10f5ac
......@@ -12,6 +12,7 @@ ADD_EXECUTABLE(${BIN_NAME}
src/irc/irc.cpp
src/irc/message.cpp
src/irc/nick.cpp
src/irc/channel.cpp
)
SET(CONF_NAME bitlbee.conf)
......
......@@ -7,6 +7,8 @@ path {
irc {
#hostname = localhost.localdomain
command_chan = &bitlbee
}
# Log function
......
......@@ -51,6 +51,7 @@ Bitlbee::Bitlbee()
section = conf.AddSection("irc", "Server information", false);
section->AddItem(new ConfigItem_string("hostname", "Server hostname", " "));
section->AddItem(new ConfigItem_string("command_chan", "Command channel name", "&bitlbee"));
section = conf.AddSection("logging", "Log informations", false);
section->AddItem(new ConfigItem_string("level", "Logging level"));
......@@ -79,10 +80,10 @@ int Bitlbee::main(int argc, char** argv)
}
b_log.SetLoggedFlags(conf.GetSection("logging")->GetItem("level")->String(), conf.GetSection("logging")->GetItem("to_syslog")->Boolean());
irc = new IRC(0, conf.GetSection("irc")->GetItem("hostname")->String());
irc = new IRC(0, conf.GetSection("irc")->GetItem("hostname")->String(),
conf.GetSection("irc")->GetItem("command_chan")->String());
b_log.setIRC(irc);
loop = g_main_new(FALSE);
g_main_run(loop);
......
......@@ -26,6 +26,7 @@
#include "irc.h"
#include "message.h"
#include "nick.h"
#include "channel.h"
static struct
{
......@@ -38,11 +39,12 @@ static struct
{ "QUIT", &IRC::m_quit, 0 }
};
IRC::IRC(int _fd, string _hostname)
IRC::IRC(int _fd, string _hostname, string cmd_chan_name)
: fd(_fd),
read_cb(NULL),
hostname("localhost.localdomain"),
userNick(NULL)
userNick(NULL),
cmdChan(NULL)
{
struct sockaddr_storage sock;
socklen_t socklen = sizeof(sock);
......@@ -63,8 +65,6 @@ IRC::IRC(int _fd, string _hostname)
userhost = buf;
}
userNick = new Nick("*", "", userhost);
/* Get my own hostname (if not given in arguments) */
if(_hostname.empty() || _hostname == " ")
{
......@@ -85,6 +85,16 @@ IRC::IRC(int _fd, string _hostname)
else
hostname = _hostname;
if(cmd_chan_name.empty() || (cmd_chan_name[0] != '&' and cmd_chan_name[0] != '#') ||
cmd_chan_name.find(' ') != string::npos)
{
b_log[W_ERR] << "'" << cmd_chan_name << "' is not a valid command channel name";
throw IRCAuthError();
}
userNick = new Nick("*", "", userhost);
cmdChan = new Channel(cmd_chan_name);
sendmsg(Message(MSG_NOTICE).setSender(this).setReceiver("AUTH").addArg("BitlBee-IRCd initialized, please go on"));
}
......@@ -111,6 +121,9 @@ void IRC::sendWelcome()
userNick->setFlag(Nick::REGISTERED);
sendmsg(Message(RPL_WELCOME).setSender(this).setReceiver(userNick).addArg("Welcome to the BitlBee gateway, " + userNick->getNickname() + "!"));
sendmsg(Message(RPL_YOURHOST).setSender(this).setReceiver(userNick).addArg("Host " + hostname + " is running BitlBee 2.0"));
sendmsg(Message(MSG_JOIN).setSender(userNick).setReceiver(cmdChan));
}
void IRC::readIO(void*)
......
......@@ -28,6 +28,7 @@ using std::string;
class IRCAuthError : public std::exception {};
class Nick;
class Channel;
class _CallBack;
class IRC
......@@ -36,10 +37,11 @@ class IRC
_CallBack *read_cb;
string hostname;
Nick* userNick;
Channel* cmdChan;
public:
IRC(int fd, string hostname="");
IRC(int fd, string hostname, string command_chan);
~IRC();
bool sendmsg(Message msg) const;
......
......@@ -20,6 +20,7 @@
#include "message.h"
#include "irc.h"
#include "nick.h"
#include "channel.h"
#include "../util.h"
Message::Message(string _cmd)
......@@ -93,6 +94,14 @@ Message& Message::setReceiver(const Nick* nick)
return *this;
}
Message& Message::setReceiver(const Channel* chan)
{
assert (chan != NULL);
receiver = chan->getName();
return *this;
}
Message& Message::setReceiver(string r)
{
assert (r.empty() == false);
......
......@@ -46,6 +46,7 @@
#define MSG_NICK "NICK"
class Nick;
class Channel;
class IRC;
using std::string;
......@@ -69,6 +70,7 @@ public:
Message& setSender(const Nick* nick);
Message& setSender(const IRC* me);
Message& setReceiver(const Nick* nick);
Message& setReceiver(const Channel* chan);
Message& setReceiver(string r);
Message& addArg(string);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment