mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
Include explicit parameter list in ProtocolInterface::SendMode
Also leave the strings split into deque, there's no need to pack it into a string just to unpack it during the translate. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11181 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
526f5a4a02
commit
96a4a1d41e
@ -203,7 +203,7 @@ class CoreExport CommandParser : public classbase
|
||||
*/
|
||||
int TranslateUIDs(TranslateType to, const std::string &source, std::string &dest);
|
||||
|
||||
int TranslateUIDs(const std::vector<TranslateType> to, const std::string &source, std::string &dest);
|
||||
int TranslateUIDs(const std::deque<TranslateType> to, const std::deque<std::string> &source, std::string &dest);
|
||||
};
|
||||
|
||||
/** Command handler class for the RELOAD command.
|
||||
|
@ -721,7 +721,6 @@ class CoreExport InspIRCd : public classbase
|
||||
* The parameters provided are identical to that sent to the
|
||||
* handler for class cmd_mode.
|
||||
* @param parameters The mode parameters
|
||||
* @param pcnt The number of items you have given in the first parameter
|
||||
* @param user The user to send error messages to
|
||||
*/
|
||||
void SendMode(const std::vector<std::string>& parameters, User *user);
|
||||
|
@ -445,6 +445,8 @@ class CoreExport ModeParser : public classbase
|
||||
* Use GetLastParse() to get this value, to be used for display purposes.
|
||||
*/
|
||||
std::string LastParse;
|
||||
std::deque<std::string> LastParseParams;
|
||||
std::deque<TranslateType> LastParseTranslate;
|
||||
|
||||
unsigned int sent[256];
|
||||
|
||||
@ -486,6 +488,8 @@ class CoreExport ModeParser : public classbase
|
||||
* @return Last parsed string, as seen by users.
|
||||
*/
|
||||
const std::string& GetLastParse();
|
||||
const std::deque<std::string>& GetLastParseParams() { return LastParseParams; }
|
||||
const std::deque<TranslateType>& GetLastParseTranslate() { return LastParseTranslate; }
|
||||
/** Add a mode to the mode parser.
|
||||
* @return True if the mode was successfully added.
|
||||
*/
|
||||
|
@ -741,7 +741,7 @@ class CoreExport Module : public Extensible
|
||||
* @param text The actual modes and their parameters if any
|
||||
* @param translate The translation types of the mode parameters
|
||||
*/
|
||||
virtual void OnMode(User* user, void* dest, int target_type, const std::string &text, const std::vector<TranslateType> &translate);
|
||||
virtual void OnMode(User* user, void* dest, int target_type, const std::deque<std::string> &text, const std::deque<TranslateType> &translate);
|
||||
|
||||
/** Allows modules to alter or create server descriptions
|
||||
* Whenever a module requires a server description, for example for display in
|
||||
@ -850,7 +850,7 @@ class CoreExport Module : public Extensible
|
||||
* @param modeline The modes and parameters to be sent
|
||||
* @param translate The translation types of the mode parameters
|
||||
*/
|
||||
virtual void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::string &modeline, const std::vector<TranslateType> &translate);
|
||||
virtual void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::deque<std::string> &modeline, const std::deque<TranslateType> &translate);
|
||||
|
||||
/** Implemented by modules which provide the ability to link servers.
|
||||
* These modules will implement this method, which allows metadata (extra data added to
|
||||
|
@ -68,7 +68,7 @@ class ProtocolInterface : public Extensible
|
||||
* @param target The channel name or user to send mode changes for.
|
||||
* @param The mode changes to send.
|
||||
*/
|
||||
virtual void SendMode(const std::string &target, parameterlist &modedata) { }
|
||||
virtual void SendMode(const std::string &target, const parameterlist &modedata, const std::deque<TranslateType> &translate) { }
|
||||
|
||||
/** Convenience function, string wrapper around the above.
|
||||
*/
|
||||
@ -76,10 +76,14 @@ class ProtocolInterface : public Extensible
|
||||
{
|
||||
irc::spacesepstream x(modeline);
|
||||
parameterlist n;
|
||||
std::deque<TranslateType> types;
|
||||
std::string v;
|
||||
while (x.GetToken(v))
|
||||
{
|
||||
n.push_back(v);
|
||||
SendMode(target, n);
|
||||
types.push_back(TR_TEXT);
|
||||
}
|
||||
SendMode(target, n, types);
|
||||
}
|
||||
|
||||
/** Send a notice to users with a given mode(s).
|
||||
|
@ -423,21 +423,19 @@ class ListModeBase : public ModeHandler
|
||||
chan->GetExt(infokey, mlist);
|
||||
irc::modestacker modestack(ServerInstance, true);
|
||||
std::deque<std::string> stackresult;
|
||||
std::vector<TranslateType> types;
|
||||
std::deque<TranslateType> types;
|
||||
types.push_back(TR_TEXT);
|
||||
if (mlist)
|
||||
{
|
||||
for (modelist::iterator it = mlist->begin(); it != mlist->end(); it++)
|
||||
{
|
||||
modestack.Push(std::string(1, mode)[0], it->mask);
|
||||
types.push_back(this->GetTranslateType());
|
||||
}
|
||||
}
|
||||
while (modestack.GetStackedLine(stackresult))
|
||||
{
|
||||
irc::stringjoiner mode_join(" ", stackresult, 0, stackresult.size() - 1);
|
||||
std::string line = mode_join.GetJoined();
|
||||
proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, line, types);
|
||||
types.assign(stackresult.size(), this->GetTranslateType());
|
||||
proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, stackresult, types);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -609,19 +609,20 @@ void CommandParser::SetupCommandTable()
|
||||
this->CreateCommand(new CommandReload(ServerInstance));
|
||||
}
|
||||
|
||||
int CommandParser::TranslateUIDs(const std::vector<TranslateType> to, const std::string &source, std::string &dest)
|
||||
int CommandParser::TranslateUIDs(const std::deque<TranslateType> to, const std::deque<std::string> &source, std::string &dest)
|
||||
{
|
||||
irc::spacesepstream items(source);
|
||||
std::vector<TranslateType>::const_iterator types = to.begin();
|
||||
std::deque<std::string>::const_iterator items = source.begin();
|
||||
std::deque<TranslateType>::const_iterator types = to.begin();
|
||||
User* user = NULL;
|
||||
std::string item;
|
||||
int translations = 0;
|
||||
dest.clear();
|
||||
|
||||
while (items.GetToken(item))
|
||||
while (items != source.end() && types != to.end())
|
||||
{
|
||||
TranslateType t = *types;
|
||||
std::string item = *items;
|
||||
types++;
|
||||
items++;
|
||||
|
||||
switch (t)
|
||||
{
|
||||
|
13
src/mode.cpp
13
src/mode.cpp
@ -371,6 +371,8 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
|
||||
User* targetuser = ServerInstance->FindNick(parameters[0]);
|
||||
|
||||
LastParse.clear();
|
||||
LastParseParams.clear();
|
||||
LastParseTranslate.clear();
|
||||
|
||||
/* Special case for displaying the list for listmodes,
|
||||
* e.g. MODE #chan b, or MODE #chan +b without a parameter
|
||||
@ -503,14 +505,13 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
|
||||
std::string mode_sequence = parameters[1];
|
||||
std::string parameter;
|
||||
std::ostringstream parameter_list;
|
||||
std::vector<TranslateType> parameter_xlate;
|
||||
parameter_xlate.push_back(TR_TEXT);
|
||||
std::string output_sequence;
|
||||
bool adding = true, state_change = false;
|
||||
unsigned char handler_id = 0;
|
||||
unsigned int parameter_counter = 2; /* Index of first parameter */
|
||||
unsigned int parameter_count = 0;
|
||||
bool last_successful_state_change = false;
|
||||
LastParseTranslate.push_back(TR_TEXT);
|
||||
|
||||
/* A mode sequence that doesnt start with + or -. Assume +. - Thanks for the suggestion spike (bug#132) */
|
||||
if ((*mode_sequence.begin() != '+') && (*mode_sequence.begin() != '-'))
|
||||
@ -717,7 +718,8 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
|
||||
if ((modehandlers[handler_id]->GetNumParams(adding)) && (!parameter.empty()))
|
||||
{
|
||||
parameter_list << " " << parameter;
|
||||
parameter_xlate.push_back(modehandlers[handler_id]->GetTranslateType());
|
||||
LastParseParams.push_back(parameter);
|
||||
LastParseTranslate.push_back(modehandlers[handler_id]->GetTranslateType());
|
||||
parameter_count++;
|
||||
/* Does this mode have a prefix? */
|
||||
if (modehandlers[handler_id]->GetPrefix() && targetchannel)
|
||||
@ -773,16 +775,17 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
|
||||
}
|
||||
else
|
||||
{
|
||||
LastParseParams.push_front(output_sequence);
|
||||
if (type == MODETYPE_CHANNEL)
|
||||
{
|
||||
targetchannel->WriteChannel(user, "MODE %s %s%s", targetchannel->name.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
|
||||
FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, output_sequence + parameter_list.str(), parameter_xlate));
|
||||
FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, LastParseParams, LastParseTranslate));
|
||||
this->LastParse = targetchannel->name;
|
||||
}
|
||||
else
|
||||
{
|
||||
user->WriteTo(targetuser, "MODE %s %s%s", targetuser->nick.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
|
||||
FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, output_sequence + parameter_list.str(), parameter_xlate));
|
||||
FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, LastParseParams, LastParseTranslate));
|
||||
this->LastParse = targetuser->nick;
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ void Module::OnPostJoin(User*, Channel*) { }
|
||||
void Module::OnUserPart(User*, Channel*, std::string&, bool&) { }
|
||||
void Module::OnRehash(User*, const std::string&) { }
|
||||
int Module::OnUserPreJoin(User*, Channel*, const char*, std::string&, const std::string&) { return 0; }
|
||||
void Module::OnMode(User*, void*, int, const std::string&, const std::vector<TranslateType>&) { }
|
||||
void Module::OnMode(User*, void*, int, const std::deque<std::string>&, const std::deque<TranslateType>&) { }
|
||||
Version Module::GetVersion() { return Version("Misconfigured", VF_VENDOR, -1); }
|
||||
void Module::OnOper(User*, const std::string&) { }
|
||||
void Module::OnPostOper(User*, const std::string&, const std::string &) { }
|
||||
@ -170,7 +170,7 @@ void Module::OnPostLocalTopicChange(User*, Channel*, const std::string&) { }
|
||||
void Module::OnGetServerDescription(const std::string&, std::string&) { }
|
||||
void Module::OnSyncUser(User*, Module*, void*) { }
|
||||
void Module::OnSyncChannel(Channel*, Module*, void*) { }
|
||||
void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::string&, const std::vector<TranslateType>&) { }
|
||||
void Module::ProtoSendMode(void*, TargetTypeFlags, void*, const std::deque<std::string>&, const std::deque<TranslateType>&) { }
|
||||
void Module::OnSyncChannelMetaData(Channel*, Module*, void*, const std::string&, bool) { }
|
||||
void Module::OnSyncUserMetaData(User*, Module*, void*, const std::string&, bool) { }
|
||||
void Module::OnSyncOtherMetaData(Module*, void*, bool) { }
|
||||
|
@ -109,10 +109,14 @@ class ModuleModesOnOper : public Module
|
||||
}
|
||||
|
||||
std::deque<std::string> n;
|
||||
std::deque<TranslateType> t;
|
||||
for (unsigned int j = 1; j < tokens.size(); j++)
|
||||
{
|
||||
n.push_back(modes[j]);
|
||||
t.push_back(TR_TEXT);
|
||||
}
|
||||
|
||||
ServerInstance->PI->SendMode(u->uuid, n);
|
||||
ServerInstance->PI->SendMode(u->uuid, n, t);
|
||||
ServerInstance->SendMode(modes, u);
|
||||
}
|
||||
};
|
||||
|
@ -37,20 +37,9 @@ class CommandSamode : public Command
|
||||
{
|
||||
ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick) + " used SAMODE: " + ServerInstance->Modes->GetLastParse());
|
||||
|
||||
std::deque<std::string> n;
|
||||
irc::spacesepstream spaced(ServerInstance->Modes->GetLastParse());
|
||||
std::string one;
|
||||
while (spaced.GetToken(one))
|
||||
n.push_back(one);
|
||||
std::string channel = parameters[0];
|
||||
ServerInstance->PI->SendMode(channel, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
|
||||
|
||||
std::string channel = n[0];
|
||||
n.pop_front();
|
||||
ServerInstance->PI->SendMode(channel, n);
|
||||
|
||||
/* XXX: Yes, this is right. We dont want to propagate the
|
||||
* actual SAMODE command, just the MODE command generated
|
||||
* by the Protocol Interface
|
||||
*/
|
||||
return CMD_LOCALONLY;
|
||||
}
|
||||
else
|
||||
|
@ -800,7 +800,7 @@ void ModuleSpanningTree::OnDelLine(User* user, XLine *x)
|
||||
}
|
||||
}
|
||||
|
||||
void ModuleSpanningTree::OnMode(User* user, void* dest, int target_type, const std::string &text, const std::vector<TranslateType> &translate)
|
||||
void ModuleSpanningTree::OnMode(User* user, void* dest, int target_type, const std::deque<std::string> &text, const std::deque<TranslateType> &translate)
|
||||
{
|
||||
if ((IS_LOCAL(user)) && (user->registered == REG_ALL))
|
||||
{
|
||||
@ -851,7 +851,7 @@ int ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModuleSpanningTree::ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::string &modeline, const std::vector<TranslateType> &translate)
|
||||
void ModuleSpanningTree::ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::deque<std::string> &modeline, const std::deque<TranslateType> &translate)
|
||||
{
|
||||
TreeSocket* s = (TreeSocket*)opaque;
|
||||
std::string output_text;
|
||||
|
@ -174,10 +174,10 @@ class ModuleSpanningTree : public Module
|
||||
void OnLine(User* source, const std::string &host, bool adding, char linetype, long duration, const std::string &reason);
|
||||
virtual void OnAddLine(User *u, XLine *x);
|
||||
virtual void OnDelLine(User *u, XLine *x);
|
||||
virtual void OnMode(User* user, void* dest, int target_type, const std::string &text, const std::vector<TranslateType> &translate);
|
||||
virtual void OnMode(User* user, void* dest, int target_type, const std::deque<std::string> &text, const std::deque<TranslateType> &translate);
|
||||
virtual int OnStats(char statschar, User* user, string_list &results);
|
||||
virtual int OnSetAway(User* user, const std::string &awaymsg);
|
||||
virtual void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::string &modeline, const std::vector<TranslateType> &translate);
|
||||
virtual void ProtoSendMode(void* opaque, TargetTypeFlags target_type, void* target, const std::deque<std::string> &modeline, const std::deque<TranslateType> &translate);
|
||||
virtual void ProtoSendMetaData(void* opaque, TargetTypeFlags target_type, void* target, const std::string &extname, const std::string &extdata);
|
||||
virtual void OnEvent(Event* event);
|
||||
virtual void OnLoadModule(Module* mod,const std::string &name);
|
||||
|
@ -68,28 +68,25 @@ void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &top
|
||||
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC", params);
|
||||
}
|
||||
|
||||
void SpanningTreeProtocolInterface::SendMode(const std::string &target, parameterlist &modedata)
|
||||
void SpanningTreeProtocolInterface::SendMode(const std::string &target, const parameterlist &modedata, const std::deque<TranslateType> &translate)
|
||||
{
|
||||
if (modedata.empty())
|
||||
return;
|
||||
|
||||
std::string outdata;
|
||||
|
||||
/* Warning: in-place translation is only safe for type TR_NICK */
|
||||
for (size_t n = 0; n < modedata.size(); n++)
|
||||
{
|
||||
ServerInstance->Parser->TranslateUIDs(TR_NICK, modedata[n], outdata);
|
||||
modedata[n] = outdata;
|
||||
}
|
||||
ServerInstance->Parser->TranslateUIDs(translate, modedata, outdata);
|
||||
|
||||
std::string uidtarget;
|
||||
ServerInstance->Parser->TranslateUIDs(TR_NICK, target, uidtarget);
|
||||
modedata.insert(modedata.begin(), uidtarget);
|
||||
|
||||
parameterlist outlist;
|
||||
outlist.push_back(uidtarget);
|
||||
outlist.push_back(outdata);
|
||||
|
||||
User* a = ServerInstance->FindNick(uidtarget);
|
||||
if (a)
|
||||
{
|
||||
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",modedata);
|
||||
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",outlist);
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -97,8 +94,8 @@ void SpanningTreeProtocolInterface::SendMode(const std::string &target, paramete
|
||||
Channel* c = ServerInstance->FindChan(target);
|
||||
if (c)
|
||||
{
|
||||
modedata.insert(modedata.begin() + 1, ConvToStr(c->age));
|
||||
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",modedata);
|
||||
outlist.insert(outlist.begin() + 1, ConvToStr(c->age));
|
||||
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",outlist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class SpanningTreeProtocolInterface : public ProtocolInterface
|
||||
virtual void SendEncapsulatedData(parameterlist &encap);
|
||||
virtual void SendMetaData(void* target, TargetTypeFlags type, const std::string &key, const std::string &data);
|
||||
virtual void SendTopic(Channel* channel, std::string &topic);
|
||||
virtual void SendMode(const std::string &target, parameterlist &modedata);
|
||||
virtual void SendMode(const std::string &target, const parameterlist &modedata, const std::deque<TranslateType> &types);
|
||||
virtual void SendModeNotice(const std::string &modes, const std::string &text);
|
||||
virtual void SendSNONotice(const std::string &snomask, const std::string &text);
|
||||
virtual void PushToClient(User* target, const std::string &rawline);
|
||||
|
Loading…
x
Reference in New Issue
Block a user