mirror of
https://github.com/anope/anope.git
synced 2026-07-06 11:33:13 +02:00
Expand more on m_alias and changed some std::string usage in sockets.cpp to use Anope::string
This commit is contained in:
+23
-2
@@ -1883,12 +1883,19 @@ db_plain
|
||||
*
|
||||
* The first encryption module loaded is the primary encryption module. All new passwords are
|
||||
* encrypted by this module. Old passwords stored in another encryption method are
|
||||
* automatically re-encrypted by the active encryption module on next identify.
|
||||
* automatically re-encrypted by the primary encryption module on next identify.
|
||||
*/
|
||||
module { name = "enc_md5" }
|
||||
#module { name = "enc_sha1" }
|
||||
#module { name = "enc_sha256" }
|
||||
|
||||
/*
|
||||
* When using enc_none, passwords will be stored without encryption in plain
|
||||
* text, allowing for passwords to be recovered later. This isn't secure therefore
|
||||
* is not recommended.
|
||||
*/
|
||||
#module { name = "enc_none" }
|
||||
|
||||
/*
|
||||
* enc_old is Anope's previous (broken) MD5 implementation, if your databases
|
||||
* were made using that module, load it here to allow conversion to the primary
|
||||
@@ -1928,6 +1935,8 @@ alias
|
||||
fantasy = no
|
||||
/* Set to yes to make this alias oper only */
|
||||
operonly = no
|
||||
/* Set to yes to hide this command from HELP */
|
||||
#hide = yes
|
||||
|
||||
/* Source client and command.
|
||||
*/
|
||||
@@ -1939,6 +1948,18 @@ alias
|
||||
target_client = "NickServ"
|
||||
target_command = "IDENTIFY"
|
||||
}
|
||||
/* Adds the /chanserv alist command which becomes rewritten to /chanserv access #channel list"
|
||||
alias
|
||||
{
|
||||
hide = yes
|
||||
|
||||
source_client = "ChanServ"
|
||||
source_command = "ALIST"
|
||||
|
||||
target_client = "ChanServ"
|
||||
target_command = "ACCESS"
|
||||
target_rewrite = "$0 LIST"
|
||||
}
|
||||
/* Provides the !k fantasy command */
|
||||
alias
|
||||
{
|
||||
@@ -1967,7 +1988,7 @@ alias
|
||||
*
|
||||
* If this is loaded with db_mysql_live then Anope will support
|
||||
* processing multiple commands at once which will negate the "lag"
|
||||
* issues caused from the overhead of SQL queries by db_mysq_live.
|
||||
* issues caused from the overhead of SQL queries by db_mysql_live.
|
||||
*
|
||||
* Note that this module is currently EXPERIMENTAL and you should report
|
||||
* any bugs you find.
|
||||
|
||||
@@ -173,6 +173,17 @@ namespace Anope
|
||||
inline iterator erase(const iterator &first, const iterator &last) { return this->_string.erase(first, last); }
|
||||
inline void erase(size_type pos = 0, size_type n = std::string::npos) { this->_string.erase(pos, n); }
|
||||
|
||||
/**
|
||||
* Trim leading and trailing white spaces from the string.
|
||||
*/
|
||||
inline void trim()
|
||||
{
|
||||
while (!this->_string.empty() && isspace(this->_string[0]))
|
||||
this->_string.erase(this->_string.begin());
|
||||
while (!this->_string.empty() && isspace(this->_string[this->_string.length() - 1]))
|
||||
this->_string.erase(this->_string.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the string.
|
||||
*/
|
||||
|
||||
@@ -110,6 +110,11 @@ class CoreExport Command : public Flags<CommandFlag>, public Base
|
||||
void SetDesc(const Anope::string &d);
|
||||
|
||||
public:
|
||||
/** Get the command description
|
||||
* @return The commands description
|
||||
*/
|
||||
const Anope::string &GetDesc() const;
|
||||
|
||||
/** Execute this command.
|
||||
* @param source The source
|
||||
* @param params Command parameters
|
||||
|
||||
+2
-2
@@ -234,9 +234,9 @@ class CoreExport BufferedSocket : public Socket
|
||||
{
|
||||
protected:
|
||||
/* Things to be written to the socket */
|
||||
std::string WriteBuffer;
|
||||
Anope::string WriteBuffer;
|
||||
/* Part of a message sent from the server, but not totally received */
|
||||
std::string extrabuf;
|
||||
Anope::string extrabuf;
|
||||
/* How much data was received from this socket */
|
||||
size_t RecvLen;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ class BotServBotInfo : public BotInfo
|
||||
if (sep.GetToken(command) && sep.GetToken(param))
|
||||
{
|
||||
Command *c = FindCommand(this, command);
|
||||
if (c)
|
||||
if (c && !c->HasFlag(CFLAG_STRIP_CHANNEL))
|
||||
{
|
||||
if (ircdproto->IsChannelValid(param))
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ class ChanServBotInfo : public BotInfo
|
||||
if (sep.GetToken(command) && sep.GetToken(param))
|
||||
{
|
||||
Command *c = FindCommand(this, command);
|
||||
if (c)
|
||||
if (c && !c->HasFlag(CFLAG_STRIP_CHANNEL))
|
||||
{
|
||||
if (ircdproto->IsChannelValid(param))
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ class CommandOSModInfo : public Command
|
||||
|
||||
if (c->module && c->module->name.equals_ci(mod_name) && c->service)
|
||||
{
|
||||
source.Reply(_("Providing command: %\002%s %s\002"), c->service->nick.c_str(), c->name.c_str());
|
||||
source.Reply(_("Providing command: \002%s %s\002"), c->service->nick.c_str(), c->name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+107
-1
@@ -14,16 +14,104 @@ struct CommandAlias
|
||||
bool operonly;
|
||||
Anope::string source_client;
|
||||
Anope::string source_command;
|
||||
Anope::string source_desc;
|
||||
Anope::string target_client;
|
||||
Anope::string target_command;
|
||||
Anope::string target_rewrite;
|
||||
};
|
||||
|
||||
class AliasCommand : public Command
|
||||
{
|
||||
CommandAlias alias;
|
||||
dynamic_reference<Command> target_command_c;
|
||||
public:
|
||||
AliasCommand(CommandAlias &a) : Command(a.source_command, 0, 0), alias(a), target_command_c(NULL) { }
|
||||
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { return MOD_CONT; }
|
||||
|
||||
void OnServHelp(CommandSource &source)
|
||||
{
|
||||
Anope::string cdesc = this->alias.source_desc;
|
||||
if (!this->target_command_c)
|
||||
this->target_command_c = FindCommand(findbot(this->alias.target_client), this->alias.target_command);
|
||||
if (this->target_command_c && cdesc.empty())
|
||||
cdesc = this->target_command_c->GetDesc();
|
||||
if (this->target_command_c)
|
||||
source.Reply(" %-14s %s", this->name.c_str(), _(cdesc.c_str()));
|
||||
}
|
||||
|
||||
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
|
||||
{
|
||||
if (!this->alias.target_rewrite.empty())
|
||||
return false;
|
||||
|
||||
if (!this->target_command_c)
|
||||
this->target_command_c = FindCommand(findbot(this->alias.target_client), this->alias.target_command);
|
||||
if (!this->target_command_c)
|
||||
return false;
|
||||
|
||||
mod_help_cmd(this->target_command_c->service, source.u, source.ci, this->target_command_c->name);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ModuleAlias : public Module
|
||||
{
|
||||
std::multimap<Anope::string, CommandAlias, std::less<ci::string> > aliases;
|
||||
std::vector<AliasCommand *> commands;
|
||||
|
||||
Anope::string RewriteCommand(Anope::string &message, const Anope::string &rewrite)
|
||||
{
|
||||
if (rewrite.empty())
|
||||
return message;
|
||||
|
||||
std::vector<Anope::string> tokens = BuildStringVector(message);
|
||||
spacesepstream sep(rewrite);
|
||||
Anope::string token, final_message;
|
||||
while (sep.GetToken(token))
|
||||
{
|
||||
if (token[0] == '$' && token.length() > 1)
|
||||
{
|
||||
Anope::string number = token.substr(1);
|
||||
bool all = false;
|
||||
if (number[number.length() - 1] == '-')
|
||||
{
|
||||
number.erase(number.length() - 1);
|
||||
all = true;
|
||||
}
|
||||
if (number.empty())
|
||||
continue;
|
||||
|
||||
int index;
|
||||
try
|
||||
{
|
||||
index = convertTo<int>(number);
|
||||
}
|
||||
catch (const ConvertException &ex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (index < 0 || static_cast<unsigned>(index) >= tokens.size())
|
||||
continue;
|
||||
|
||||
final_message += tokens[index] + " ";
|
||||
if (all)
|
||||
for (unsigned i = index + i; i < tokens.size(); ++i)
|
||||
final_message += tokens[i] + " ";
|
||||
}
|
||||
else
|
||||
final_message += token + " ";
|
||||
}
|
||||
|
||||
final_message.trim();
|
||||
return final_message;
|
||||
}
|
||||
|
||||
public:
|
||||
ModuleAlias(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
Implementation i[] = { I_OnReload, I_OnPreCommandRun, I_OnBotFantasy };
|
||||
ModuleManager::Attach(i, this, 3);
|
||||
|
||||
@@ -35,15 +123,21 @@ class ModuleAlias : public Module
|
||||
ConfigReader config;
|
||||
|
||||
this->aliases.clear();
|
||||
for (unsigned i = 0; i < this->commands.size(); ++i)
|
||||
delete this->commands[i];
|
||||
this->commands.clear();
|
||||
|
||||
for (int i = 0; i < config.Enumerate("alias"); ++i)
|
||||
{
|
||||
bool fantasy = config.ReadFlag("alias", "fantasy", "no", i);
|
||||
bool operonly = config.ReadFlag("alias", "operonly", "no", i);
|
||||
bool hide = config.ReadFlag("alias", "hide", "no", i);
|
||||
Anope::string source_client = config.ReadValue("alias", "source_client", "", i);
|
||||
Anope::string source_command = config.ReadValue("alias", "source_command", "", i);
|
||||
Anope::string source_desc = config.ReadValue("alias", "source_desc", "", i);
|
||||
Anope::string target_client = config.ReadValue("alias", "target_client", "", i);
|
||||
Anope::string target_command = config.ReadValue("alias", "target_command", "", i);
|
||||
Anope::string target_rewrite = config.ReadValue("alias", "target_rewrite", "", i);
|
||||
|
||||
if ((!fantasy && source_client.empty()) || source_command.empty() || target_client.empty() || target_command.empty())
|
||||
continue;
|
||||
@@ -53,10 +147,20 @@ class ModuleAlias : public Module
|
||||
alias.operonly = operonly;
|
||||
alias.source_client = source_client;
|
||||
alias.source_command = source_command;
|
||||
alias.source_desc = source_desc;
|
||||
alias.target_client = target_client;
|
||||
alias.target_command = target_command;
|
||||
alias.target_rewrite = target_rewrite;
|
||||
|
||||
this->aliases.insert(std::make_pair(source_command, alias));
|
||||
if (hide == false)
|
||||
{
|
||||
AliasCommand *cmd = new AliasCommand(alias);
|
||||
this->commands.push_back(cmd);
|
||||
BotInfo *bi = findbot(alias.source_client);
|
||||
if (bi != NULL)
|
||||
this->AddCommand(bi, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +179,7 @@ class ModuleAlias : public Module
|
||||
else if (fantasy != alias.fantasy)
|
||||
continue;
|
||||
else if (fantasy && alias.fantasy) // OnBotFantasy gets this!
|
||||
return EVENT_STOP;
|
||||
continue;
|
||||
else if (!bi->nick.equals_ci(alias.source_client))
|
||||
continue;
|
||||
|
||||
@@ -83,6 +187,7 @@ class ModuleAlias : public Module
|
||||
if (target)
|
||||
bi = target;
|
||||
command = alias.target_command;
|
||||
message = this->RewriteCommand(message, alias.target_rewrite);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -115,6 +220,7 @@ class ModuleAlias : public Module
|
||||
if (!params.empty())
|
||||
full_message += + " " + params;
|
||||
|
||||
full_message = this->RewriteCommand(full_message, alias.target_rewrite);
|
||||
mod_run_cmd(target, u, ci, full_message);
|
||||
break;
|
||||
}
|
||||
|
||||
+6
-1
@@ -69,9 +69,14 @@ void Command::SetDesc(const Anope::string &d)
|
||||
this->desc = d;
|
||||
}
|
||||
|
||||
const Anope::string &Command::GetDesc() const
|
||||
{
|
||||
return this->desc;
|
||||
}
|
||||
|
||||
void Command::OnServHelp(CommandSource &source)
|
||||
{
|
||||
source.Reply(" %-14s %s", this->name.c_str(), _(this->desc.c_str()));
|
||||
source.Reply(" %-14s %s", this->name.c_str(), _(this->GetDesc().c_str()));
|
||||
}
|
||||
|
||||
bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; }
|
||||
|
||||
+13
-28
@@ -7,17 +7,6 @@ int32 TotalWritten = 0;
|
||||
|
||||
SocketIO normalSocketIO;
|
||||
|
||||
/** Trims all the \r and \ns from the begining and end of a string
|
||||
* @param buffer The buffer to trim
|
||||
*/
|
||||
static void TrimBuf(std::string &buffer)
|
||||
{
|
||||
while (!buffer.empty() && (buffer[0] == '\r' || buffer[0] == '\n'))
|
||||
buffer.erase(buffer.begin());
|
||||
while (!buffer.empty() && (buffer[buffer.length() - 1] == '\r' || buffer[buffer.length() - 1] == '\n'))
|
||||
buffer.erase(buffer.length() - 1);
|
||||
}
|
||||
|
||||
/** Construct the object, sets everything to 0
|
||||
*/
|
||||
sockaddrs::sockaddrs()
|
||||
@@ -459,19 +448,19 @@ bool BufferedSocket::ProcessRead()
|
||||
if (RecvLen <= 0)
|
||||
return false;
|
||||
|
||||
std::string sbuffer = extrabuf;
|
||||
sbuffer.append(tbuffer);
|
||||
extrabuf.clear();
|
||||
Anope::string sbuffer = this->extrabuf;
|
||||
sbuffer += tbuffer;
|
||||
this->extrabuf.clear();
|
||||
size_t lastnewline = sbuffer.rfind('\n');
|
||||
if (lastnewline == std::string::npos)
|
||||
if (lastnewline == Anope::string::npos)
|
||||
{
|
||||
extrabuf = sbuffer;
|
||||
this->extrabuf = sbuffer;
|
||||
return true;
|
||||
}
|
||||
if (lastnewline < sbuffer.size() - 1)
|
||||
if (lastnewline < sbuffer.length() - 1)
|
||||
{
|
||||
extrabuf = sbuffer.substr(lastnewline);
|
||||
TrimBuf(extrabuf);
|
||||
this->extrabuf = sbuffer.substr(lastnewline);
|
||||
this->extrabuf.trim();
|
||||
sbuffer = sbuffer.substr(0, lastnewline);
|
||||
}
|
||||
|
||||
@@ -480,13 +469,9 @@ bool BufferedSocket::ProcessRead()
|
||||
Anope::string tbuf;
|
||||
while (stream.GetToken(tbuf))
|
||||
{
|
||||
std::string tmp_tbuf = tbuf.str();
|
||||
TrimBuf(tmp_tbuf);
|
||||
tbuf = tmp_tbuf;
|
||||
|
||||
if (!tbuf.empty())
|
||||
if (!Read(tbuf))
|
||||
return false;
|
||||
tbuf.trim();
|
||||
if (!tbuf.empty() && !Read(tbuf))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -542,7 +527,7 @@ void BufferedSocket::Write(const char *message, ...)
|
||||
*/
|
||||
void BufferedSocket::Write(const Anope::string &message)
|
||||
{
|
||||
WriteBuffer.append(message.str() + "\r\n");
|
||||
this->WriteBuffer += message + "\r\n";
|
||||
SocketEngine::MarkWritable(this);
|
||||
}
|
||||
|
||||
@@ -559,7 +544,7 @@ size_t BufferedSocket::ReadBufferLen() const
|
||||
*/
|
||||
size_t BufferedSocket::WriteBufferLen() const
|
||||
{
|
||||
return WriteBuffer.length();
|
||||
return this->WriteBuffer.length();
|
||||
}
|
||||
|
||||
/** Constructor
|
||||
|
||||
Reference in New Issue
Block a user