summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-23 20:20:41 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-23 20:20:41 +0000
commit8b864c8a828d6ca97b5ec15fa7bf8fcc35027294 (patch)
tree2aad4b5f18e3746bebd062496d906d44741d067f /src
parent985169b6ee6d6af8c24f4e2aee95d15b38f2401d (diff)
Mode handlers handling listmodes where a listmode item is a nickname can now specify prefixes!!!!!!
This isnt documented yet. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4997 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/channels.cpp59
-rw-r--r--src/mode.cpp34
-rw-r--r--src/modes/cmode_h.cpp7
-rw-r--r--src/modes/cmode_o.cpp7
-rw-r--r--src/modes/cmode_v.cpp7
5 files changed, 93 insertions, 21 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index a89b9b2c4..4d68af99c 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -430,6 +430,7 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* u
/* first user in is given ops */
a->uc_modes = UCMODE_OP;
Ptr->AddOppedUser(user);
+ Ptr->SetPrefix(user, '@', OP_VALUE, true);
}
else
{
@@ -880,26 +881,26 @@ long chanrec::GetMaxBans()
const char* chanrec::GetStatusChar(userrec *user)
{
- for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+ static char px[2];
+ unsigned int mx = 0;
+
+ *px = 0;
+ *(px+1) = 0;
+
+ prefixlist::iterator n = prefixes.find(user);
+ if (n != prefixes.end())
{
- if ((*i)->channel == this)
+ for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
{
- if (((*i)->uc_modes & UCMODE_OP) > 0)
- {
- return "@";
- }
- if (((*i)->uc_modes & UCMODE_HOP) > 0)
- {
- return "%";
- }
- if (((*i)->uc_modes & UCMODE_VOICE) > 0)
+ if (x->second > mx)
{
- return "+";
+ *px = x->first;
+ mx = x->second;
}
- return "";
}
}
- return "";
+
+ return px;
}
@@ -944,4 +945,34 @@ int chanrec::GetStatus(userrec *user)
return STATUS_NORMAL;
}
+void chanrec::SetPrefix(userrec* user, char prefix, unsigned int prefix_value, bool adding)
+{
+ prefixlist::iterator n = prefixes.find(user);
+ prefixtype pfx = std::make_pair(prefix,prefix_value);
+ if (adding)
+ {
+ if (n != prefixes.end())
+ {
+ if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
+ {
+ n->second.push_back(pfx);
+ }
+ }
+ else
+ {
+ pfxcontainer one;
+ one.push_back(pfx);
+ prefixes.insert(std::make_pair<userrec*,pfxcontainer>(user, one));
+ }
+ }
+ else
+ {
+ if (n != prefixes.end())
+ {
+ pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
+ if (x != n->second.end())
+ n->second.erase(x);
+ }
+ }
+}
diff --git a/src/mode.cpp b/src/mode.cpp
index f3cf54e6a..790720c6b 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -65,8 +65,8 @@ using namespace std;
/* +n (notice mask - our implementation of snomasks) */
#include "modes/umode_n.h"
-ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly)
- : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly)
+ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix)
+ : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix)
{
}
@@ -79,6 +79,11 @@ bool ModeHandler::IsListMode()
return list;
}
+unsigned int ModeHandler::GetPrefixRank()
+{
+ return 0;
+}
+
ModeType ModeHandler::GetModeType()
{
return m_type;
@@ -89,6 +94,11 @@ bool ModeHandler::NeedsOper()
return oper;
}
+char ModeHandler::GetPrefix()
+{
+ return prefix;
+}
+
int ModeHandler::GetNumParams(bool adding)
{
return adding ? n_params_on : n_params_off;
@@ -273,9 +283,10 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
*/
if ((targetchannel) && (pcnt == 2))
{
+ ServerInstance->Log(DEBUG,"Spool list");
const char* mode = parameters[1];
if (*mode == '+')
- mode++;
+ mode++;
unsigned char handler_id = ((*mode) - 65) | MASK_CHANNEL;
ModeHandler* mh = modehandlers[handler_id];
if ((mh) && (mh->IsListMode()))
@@ -287,10 +298,13 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
if (pcnt == 1)
{
+ ServerInstance->Log(DEBUG,"Mode list request");
this->DisplayCurrentModes(user, targetuser, targetchannel, parameters[0]);
}
else if (pcnt > 1)
{
+ ServerInstance->Log(DEBUG,"More than one parameter");
+
if (targetchannel)
{
type = MODETYPE_CHANNEL;
@@ -341,6 +355,8 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
{
unsigned char modechar = *letter;
+ ServerInstance->Log(DEBUG,"Process letter %c", modechar);
+
switch (modechar)
{
/* NB:
@@ -397,7 +413,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
parameter = parameters[parameter_counter++];
/* Yerk, invalid! */
- if ((parameter.rfind(':') || (parameter.rfind(' '))))
+ if ((parameter.rfind(':') != std::string::npos) || (parameter.rfind(' ') != std::string::npos))
parameter = "";
}
else
@@ -436,7 +452,17 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
/* Is there a valid parameter for this mode? If so add it to the parameter list */
if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter != ""))
+ {
parameter_list << " " << parameter;
+ /* Does this mode have a prefix? */
+ if (modehandlers[handler_id]->GetPrefix() && targetchannel)
+ {
+ userrec* user_to_prefix = ServerInstance->FindNick(parameter);
+ if (user_to_prefix)
+ targetchannel->SetPrefix(user_to_prefix, modehandlers[handler_id]->GetPrefix(),
+ modehandlers[handler_id]->GetPrefixRank(), adding);
+ }
+ }
/* Call all the AfterMode events in the mode watchers for this mode */
for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
diff --git a/src/modes/cmode_h.cpp b/src/modes/cmode_h.cpp
index 21c97cabc..1b0370439 100644
--- a/src/modes/cmode_h.cpp
+++ b/src/modes/cmode_h.cpp
@@ -14,10 +14,15 @@
#include "hashcomp.h"
#include "modes/cmode_h.h"
-ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false)
+ModeChannelHalfOp::ModeChannelHalfOp(InspIRCd* Instance) : ModeHandler(Instance, 'h', 1, 1, true, MODETYPE_CHANNEL, false, '%')
{
}
+unsigned int ModeChannelHalfOp::GetPrefixRank()
+{
+ return HALFOP_VALUE;
+}
+
ModePair ModeChannelHalfOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
{
userrec* x = ServerInstance->FindNick(parameter);
diff --git a/src/modes/cmode_o.cpp b/src/modes/cmode_o.cpp
index 0ab3d9d95..c631ec779 100644
--- a/src/modes/cmode_o.cpp
+++ b/src/modes/cmode_o.cpp
@@ -14,10 +14,15 @@
#include "hashcomp.h"
#include "modes/cmode_o.h"
-ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false)
+ModeChannelOp::ModeChannelOp(InspIRCd* Instance) : ModeHandler(Instance, 'o', 1, 1, true, MODETYPE_CHANNEL, false, '@')
{
}
+unsigned int ModeChannelOp::GetPrefixRank()
+{
+ return OP_VALUE;
+}
+
ModePair ModeChannelOp::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
{
userrec* x = ServerInstance->FindNick(parameter);
diff --git a/src/modes/cmode_v.cpp b/src/modes/cmode_v.cpp
index af1fbe22a..7b14d84d4 100644
--- a/src/modes/cmode_v.cpp
+++ b/src/modes/cmode_v.cpp
@@ -14,10 +14,15 @@
#include "hashcomp.h"
#include "modes/cmode_v.h"
-ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false)
+ModeChannelVoice::ModeChannelVoice(InspIRCd* Instance) : ModeHandler(Instance, 'v', 1, 1, true, MODETYPE_CHANNEL, false, '+')
{
}
+unsigned int ModeChannelVoice::GetPrefixRank()
+{
+ return VOICE_VALUE;
+}
+
ModePair ModeChannelVoice::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
{
userrec* x = ServerInstance->FindNick(parameter);