added authentication

This commit is contained in:
Anselme 2016-03-15 00:17:35 +01:00
parent afa0b3f90f
commit e943dc185b
7 changed files with 40 additions and 3 deletions

View File

@ -176,11 +176,28 @@ bool RPGModule::messageHandler(Message msg)
return true;
}
}
else if(msg.args.startsWith("travel "))
{
QStringList paramList = msg.args.split(' ');
if(charOnline.count(src) > 0 && paramList.size() == 2)
{
answer = say(playerTravel(charOnline[src], paramList[1]));
return true;
}
}
else if(msg.args.startsWith("look "))
{
// look around
// look at [object]
}
else if(msg.args.compare("!rpg help") == 0)
{
answer = privateSay("Create new character (works only in private message) : !rpg register [name of character] [password]", msg.nick);
answer += privateSay("Join game with character (works only in private message) : !rpg join [name of character] [password]", msg.nick);
answer += privateSay("leave the game : !rpg leave", msg.nick);
answer += privateSay("show your stats : !rpg stats", msg.nick);
answer += privateSay("show all in-game players : !rpg list", msg.nick);
return true;
}
}

View File

@ -32,6 +32,8 @@ bool BaseModule::messageHandler(Message msg)
if(msg.command.compare("376") == 0)
{
status = ON_CHAN;
if(!getPass().isNull())
answer += privateSay(QString("identify %1 %2").arg(getNick()).arg(getPass()), "nickserv");
answer += join(getChan());
ret = true;
}

View File

@ -10,6 +10,7 @@ BotApp::BotApp(int argc, char** argv) : nogui(false)
int port = 6667;
QString nick = QString("SparrowBotDebug");
QString chan = QString("epicsparrow");
QString pass;
// parsing arguments
for(int i=1; i<argc; ++i)
@ -31,12 +32,14 @@ BotApp::BotApp(int argc, char** argv) : nogui(false)
nick = argList.at(1);
else if(key.compare("chan") == 0)
chan = argList.at(1);
else if(key.compare("pass") == 0)
pass = argList.at(1);
}
}
}
sock = new SocketIRC(server, port);
bot = new IRCBot(nick, chan);
bot = new IRCBot(nick, chan, pass);
if(nogui)
coreApp = new QCoreApplication(argc, argv);
else

View File

@ -2,7 +2,7 @@
#include "basemodule.h"
#include "message.h"
IRCBot::IRCBot(QString nick_, QString chan_) : nick(nick_), chan(chan_)
IRCBot::IRCBot(QString nick_, QString chan_, QString pass_) : nick(nick_), chan(chan_), pass(pass_)
{
addModule(new BaseModule());
}
@ -28,6 +28,7 @@ void IRCBot::addModule(Module* module)
modules.push_back(module);
module->setChan(chan);
module->setNick(nick);
module->setPass(pass);
module->setModuleList(&modules);
}

View File

@ -14,11 +14,12 @@ class IRCBot : public QObject
QString nick;
QString chan;
QString pass;
std::vector<Module*> modules;
BaseModule *base;
public:
IRCBot(QString nick_, QString chan_);
IRCBot(QString nick_, QString chan_, QString pass_ = QString());
public:
void addModule(Module* module);

View File

@ -22,6 +22,11 @@ QString Module::getNick()
return nick;
}
QString Module::getPass()
{
return pass;
}
QString Module::getChan()
{
return chan;
@ -54,6 +59,11 @@ void Module::setNick(QString nick_)
nick = nick_;
}
void Module::setPass(QString pass_)
{
pass = pass_;
}
void Module::setChan(QString chan_)
{
chan = chan_;

View File

@ -12,6 +12,7 @@ class Module
private:
bool enabled;
QString nick;
QString pass;
QString chan;
std::vector<Module*>* modules;
@ -19,6 +20,7 @@ protected:
QString answer;
QString getNick();
QString getPass();
QString getChan();
int getNbModules();
Module* getModule(int index);
@ -42,6 +44,7 @@ public:
bool isEnabled();
void setEnabled(bool newStatus);
void setNick(QString nick_);
void setPass(QString pass_);
void setChan(QString chan_);
void setModuleList(std::vector<Module*>* modList);
//TODO: add serialization methods