Commit 6c8fe7ba authored by Romain Bignon's avatar Romain Bignon

motd feature (refs #158)

parent 15cbff8b
......@@ -37,6 +37,7 @@ ADD_EXECUTABLE(${BIN_NAME}
src/irc/conversation_channel.cpp
)
SET(CONF_NAME minbif.conf)
SET(MOTD_NAME minbif.motd)
target_link_libraries(${BIN_NAME})
......@@ -52,7 +53,7 @@ IF(ENABLE_CACA)
IF(IMLIB_FOUND AND CACA_FOUND)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_CACA")
ELSE(IMLIB_FOUND AND CACA_FOUND)
MESSAGE(FATAL_ERROR "Unable to find the libcaca or imlib2 library. To disable caca output, run 'make ENABLE_CACA=0'")
MESSAGE(FATAL_ERROR "Unable to find the libcaca and/or imlib2 libraries. To disable caca output, run 'make ENABLE_CACA=0'")
ENDIF(IMLIB_FOUND AND CACA_FOUND)
ENDIF(ENABLE_CACA)
......@@ -105,5 +106,5 @@ INSTALL(FILES COPYING README
DESTINATION doc/minbif)
INSTALL(DIRECTORY doc/
DESTINATION doc/minbif)
INSTALL(FILES ${CONF_NAME}
INSTALL(FILES ${CONF_NAME} ${MOTD_NAME}
DESTINATION ${CONF_PREFIX})
......@@ -4,6 +4,9 @@ path {
# Users directory, where minbif will write
# every settings.
users = /var/lib/minbif/users
# Path to motd file.
motd = /etc/minbif/minbif.motd
}
irc {
......
MinBif
Hey dear, this is the MinBif IRC instant messaging gateway!
Website: http://minbif.im
Enjoy.
......@@ -22,6 +22,7 @@
#include <cstring>
#include <algorithm>
#include <cassert>
#include <fstream>
#include "../log.h"
#include "../util.h"
......@@ -137,6 +138,8 @@ IRC::IRC(ServerPoll* _poll, int _fd, string _hostname, unsigned _ping_freq)
ping_id = g_timeout_add_seconds((int)ping_freq, g_callback, ping_cb);
}
setMotd(conf.GetSection("path")->GetItem("motd")->String());
user->send(Message(MSG_NOTICE).setSender(this).setReceiver("AUTH").addArg("Minbif-IRCd initialized, please go on"));
}
......@@ -350,6 +353,23 @@ void IRC::cleanUpServers()
servers.clear();
}
void IRC::setMotd(const string& path)
{
std::ifstream fp(path.c_str());
if(!fp)
{
b_log[W_WARNING] << "Unable to read MOTD";
return;
}
char buf[512];
motd.clear();
while(fp)
{
fp.getline(buf, 511);
motd.push_back(buf);
}
}
void IRC::quit(string reason)
{
......@@ -403,12 +423,12 @@ void IRC::sendWelcome()
user->setFlag(Nick::REGISTERED);
user->send(Message(RPL_WELCOME).setSender(this).setReceiver(user).addArg("Welcome to the Minbif gateway, " + user->getNickname() + "!"));
user->send(Message(RPL_WELCOME).setSender(this).setReceiver(user).addArg("Welcome to the Minbif IRC gateway, " + user->getNickname() + "!"));
user->send(Message(RPL_YOURHOST).setSender(this).setReceiver(user).addArg("Host " + getServerName() + " is running Minbif"));
user->send(Message(RPL_MOTDSTART).setSender(this).setReceiver(user).addArg("- " + getServerName() + " Message Of The Day -"));
if (im->getAccountsList().empty())
user->send(Message(RPL_MOTD).setSender(this).setReceiver(user).addArg("Advice: you should start by adding an account using the /MAP command."));
for(vector<string>::iterator s = motd.begin(); s != motd.end(); ++s)
user->send(Message(RPL_MOTD).setSender(this).setReceiver(user).addArg(*s));
user->send(Message(RPL_ENDOFMOTD).setSender(this).setReceiver(user).addArg("End of /MOTD command."));
......
......@@ -71,6 +71,7 @@ namespace irc
map<string, Channel*> channels;
map<string, Server*> servers;
vector<DCC*> dccs;
vector<string> motd;
struct command_t
{
......@@ -154,6 +155,8 @@ namespace irc
Channel* getChannel(string channame) const;
void removeChannel(string channame);
void setMotd(const string& path);
void addNick(Nick* nick);
Nick* getNick(string nick, bool case_sensitive = false) const;
Nick* getNick(const im::Buddy& buddy) const;
......
......@@ -133,6 +133,7 @@ Minbif::Minbif()
ConfigSection* section;
section = conf.AddSection("path", "Path information", false);
section->AddItem(new ConfigItem_string("users", "Users directory"));
section->AddItem(new ConfigItem_string("motd", "Path to motd", " "));
section = conf.AddSection("irc", "Server information", false);
section->AddItem(new ConfigItem_string("hostname", "Server hostname", " "));
......
......@@ -36,7 +36,7 @@ InetdServerPoll::InetdServerPoll(Minbif* application)
{
irc = new irc::IRC(this, 0,
conf.GetSection("irc")->GetItem("hostname")->String(),
conf.GetSection("irc")->GetItem("ping")->Integer());
conf.GetSection("irc")->GetItem("ping")->Integer());
}
catch(irc::AuthError &e)
{
......
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