mirror of
https://github.com/anope/anope.git
synced 2026-07-05 06:53:12 +02:00
Added src/regchannel.cpp and moved the code from include/regchannel.h there
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2612 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
+16
-144
@@ -15,28 +15,7 @@ class CoreExport ChannelInfo : public Extensible
|
||||
std::map<ChannelModeName, std::string> Params;
|
||||
|
||||
public:
|
||||
ChannelInfo()
|
||||
{
|
||||
next = prev = NULL;
|
||||
name[0] = last_topic_setter[0] = '\0';
|
||||
founder = successor = NULL;
|
||||
desc = url = email = last_topic = forbidby = forbidreason = NULL;
|
||||
time_registered = last_used = last_topic_time = 0;
|
||||
flags = 0;
|
||||
bantype = akickcount = 0;
|
||||
levels = NULL;
|
||||
akick = NULL;
|
||||
entry_message = NULL;
|
||||
c = NULL;
|
||||
bi = NULL;
|
||||
botflags = 0;
|
||||
ttb = NULL;
|
||||
bwcount = 0;
|
||||
badwords = NULL;
|
||||
capsmin = capspercent = 0;
|
||||
floodlines = floodsecs = 0;
|
||||
repeattimes = 0;
|
||||
}
|
||||
ChannelInfo();
|
||||
|
||||
ChannelInfo *next, *prev;
|
||||
char name[CHANMAX];
|
||||
@@ -95,20 +74,7 @@ class CoreExport ChannelInfo : public Extensible
|
||||
*
|
||||
* Creates a new access list entry and inserts it into the access list.
|
||||
*/
|
||||
void AddAccess(NickCore *nc, int16 level, const std::string &creator, int32 last_seen = 0)
|
||||
{
|
||||
ChanAccess *new_access = new ChanAccess();
|
||||
new_access->in_use = 1;
|
||||
new_access->nc = nc;
|
||||
new_access->level = level;
|
||||
new_access->last_seen = last_seen;
|
||||
if (!creator.empty())
|
||||
new_access->creator = creator;
|
||||
else
|
||||
new_access->creator = "Unknown";
|
||||
|
||||
access.push_back(new_access);
|
||||
}
|
||||
void AddAccess(NickCore *nc, int16 level, const std::string &creator, int32 last_seen = 0);
|
||||
|
||||
/** Get an entry from the channel access list by index
|
||||
*
|
||||
@@ -117,13 +83,7 @@ class CoreExport ChannelInfo : public Extensible
|
||||
*
|
||||
* Retrieves an entry from the access list that matches the given index.
|
||||
*/
|
||||
ChanAccess *GetAccess(unsigned index)
|
||||
{
|
||||
if (access.empty() || index >= access.size())
|
||||
return NULL;
|
||||
|
||||
return access[index];
|
||||
}
|
||||
ChanAccess *GetAccess(unsigned index);
|
||||
|
||||
/** Get an entry from the channel access list by NickCore
|
||||
*
|
||||
@@ -133,17 +93,7 @@ class CoreExport ChannelInfo : public Extensible
|
||||
*
|
||||
* Retrieves an entry from the access list that matches the given NickCore, optionally also matching a certain level.
|
||||
*/
|
||||
ChanAccess *GetAccess(NickCore *nc, int16 level = 0)
|
||||
{
|
||||
if (access.empty())
|
||||
return NULL;
|
||||
|
||||
for (unsigned i = 0; i < access.size(); i++)
|
||||
if (access[i]->in_use && access[i]->nc == nc && (level ? access[i]->level == level : true))
|
||||
return access[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
ChanAccess *GetAccess(NickCore *nc, int16 level = 0);
|
||||
|
||||
/** Erase an entry from the channel access list
|
||||
*
|
||||
@@ -151,146 +101,68 @@ class CoreExport ChannelInfo : public Extensible
|
||||
*
|
||||
* Clears the memory used by the given access entry and removes it from the vector.
|
||||
*/
|
||||
void EraseAccess(unsigned index)
|
||||
{
|
||||
if (access.empty() || index >= access.size())
|
||||
return;
|
||||
delete access[index];
|
||||
access.erase(access.begin() + index);
|
||||
}
|
||||
void EraseAccess(unsigned index);
|
||||
|
||||
/** Cleans the channel access list
|
||||
*
|
||||
* Cleans up the access list so it no longer contains entries no longer in use.
|
||||
*/
|
||||
void CleanAccess()
|
||||
{
|
||||
for (unsigned j = access.size(); j > 0; --j)
|
||||
if (!access[j - 1]->in_use)
|
||||
EraseAccess(j - 1);
|
||||
}
|
||||
void CleanAccess();
|
||||
|
||||
/** Clear the entire channel access list
|
||||
*
|
||||
* Clears the entire access list by deleting every item and then clearing the vector.
|
||||
*/
|
||||
void ClearAccess()
|
||||
{
|
||||
while (access.begin() != access.end())
|
||||
EraseAccess(0);
|
||||
}
|
||||
void ClearAccess();
|
||||
|
||||
/** Check if a mode is mlocked
|
||||
* @param Name The mode
|
||||
* @param status True to check mlock on, false for mlock off
|
||||
* @return true on success, false on fail
|
||||
*/
|
||||
const bool HasMLock(ChannelModeName Name, bool status)
|
||||
{
|
||||
if (status)
|
||||
return mlock_on[(size_t)Name];
|
||||
else
|
||||
return mlock_off[(size_t)Name];
|
||||
}
|
||||
const bool HasMLock(ChannelModeName Name, bool status);
|
||||
|
||||
/** Set a mlock
|
||||
* @param Name The mode
|
||||
* @param status True for mlock on, false for mlock off
|
||||
*/
|
||||
void SetMLock(ChannelModeName Name, bool status)
|
||||
{
|
||||
size_t value = (size_t)Name;
|
||||
|
||||
if (status)
|
||||
mlock_on[value] = true;
|
||||
else
|
||||
mlock_off[value] = true;
|
||||
}
|
||||
void SetMLock(ChannelModeName Name, bool status);
|
||||
|
||||
/** Remove a mlock
|
||||
* @param Name The mode
|
||||
* @param status True for mlock on, false for mlock off
|
||||
*/
|
||||
void RemoveMLock(ChannelModeName Name, bool status)
|
||||
{
|
||||
size_t value = (size_t)Name;
|
||||
|
||||
if (status)
|
||||
mlock_on[value] = false;
|
||||
else
|
||||
mlock_off[value] = false;
|
||||
}
|
||||
void RemoveMLock(ChannelModeName Name, bool status);
|
||||
|
||||
/** Clear all mlocks on the channel
|
||||
*/
|
||||
void ClearMLock()
|
||||
{
|
||||
mlock_on.reset();
|
||||
mlock_off.reset();
|
||||
}
|
||||
void ClearMLock();
|
||||
|
||||
/** Set a channel mode param on the channel
|
||||
* @param Name The mode
|
||||
* @param param The param
|
||||
* @param true on success
|
||||
*/
|
||||
bool SetParam(ChannelModeName Name, std::string Value)
|
||||
{
|
||||
return Params.insert(std::make_pair(Name, Value)).second;
|
||||
}
|
||||
bool SetParam(ChannelModeName Name, std::string Value);
|
||||
|
||||
/** Unset a param from the channel
|
||||
* @param Name The mode
|
||||
*/
|
||||
void UnsetParam(ChannelModeName Name)
|
||||
{
|
||||
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
|
||||
|
||||
if (it != Params.end())
|
||||
{
|
||||
Params.erase(it);
|
||||
}
|
||||
}
|
||||
void UnsetParam(ChannelModeName Name);
|
||||
|
||||
/** Get a param from the channel
|
||||
* @param Name The mode
|
||||
* @param Target a string to put the param into
|
||||
* @return true on success
|
||||
*/
|
||||
const bool GetParam(ChannelModeName Name, std::string *Target)
|
||||
{
|
||||
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
|
||||
|
||||
(*Target).clear();
|
||||
|
||||
if (it != Params.end())
|
||||
{
|
||||
*Target = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
const bool GetParam(ChannelModeName Name, std::string *Target);
|
||||
|
||||
/** Check if a mode is set and has a param
|
||||
* @param Name The mode
|
||||
*/
|
||||
const bool HasParam(ChannelModeName Name)
|
||||
{
|
||||
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
|
||||
|
||||
if (it != Params.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
const bool HasParam(ChannelModeName Name);
|
||||
|
||||
/** Clear all the params from the channel
|
||||
*/
|
||||
void ClearParams()
|
||||
{
|
||||
Params.clear();
|
||||
}
|
||||
void ClearParams();
|
||||
};
|
||||
|
||||
+2
-1
@@ -2,7 +2,7 @@ OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o command.o comm
|
||||
config.o datafiles.o encrypt.o hashcomp.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \
|
||||
memory.o memoserv.o messages.o misc.o modules.o nickserv.o operserv.o \
|
||||
process.o protocol.o send.o servers.o sessions.o slist.o sockutil.o opertype.o users.o module.o modulemanager.o configreader.o \
|
||||
wildcard.o nickcore.o nickalias.o timers.o modes.o
|
||||
wildcard.o nickcore.o nickalias.o timers.o modes.o regchannel.o
|
||||
|
||||
INCLUDES = ../include/commands.h ../include/defs.h ../include/language.h \
|
||||
../include/pseudo.h ../include/sysconf.h ../include/config.h \
|
||||
@@ -67,6 +67,7 @@ nickserv.o: nickserv.c $(INCLUDES)
|
||||
operserv.o: operserv.c $(INCLUDES)
|
||||
process.o: process.c $(INCLUDES)
|
||||
protocol.o: protocol.cpp $(INCLUDES)
|
||||
regchannel.o: regchannel.cpp $(INCLUDES)
|
||||
send.o: send.c $(INCLUDES)
|
||||
servers.o: servers.c $(INCLUDES)
|
||||
sessions.o: sessions.c $(INCLUDES)
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
/* Registered channel functions
|
||||
*
|
||||
* (C) 2003-2009 Anope Team
|
||||
* Contact us at team@anope.org
|
||||
*
|
||||
* Please read COPYING and README for further details.
|
||||
*
|
||||
* Based on the original code of Epona by Lara.
|
||||
* Based on the original code of Services by Andy Church.
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
*/
|
||||
|
||||
#include "services.h"
|
||||
|
||||
ChannelInfo::ChannelInfo()
|
||||
{
|
||||
next = prev = NULL;
|
||||
name[0] = last_topic_setter[0] = '\0';
|
||||
founder = successor = NULL;
|
||||
desc = url = email = last_topic = forbidby = forbidreason = NULL;
|
||||
time_registered = last_used = last_topic_time = 0;
|
||||
flags = 0;
|
||||
bantype = akickcount = 0;
|
||||
levels = NULL;
|
||||
akick = NULL;
|
||||
entry_message = NULL;
|
||||
c = NULL;
|
||||
bi = NULL;
|
||||
botflags = 0;
|
||||
ttb = NULL;
|
||||
bwcount = 0;
|
||||
badwords = NULL;
|
||||
capsmin = capspercent = 0;
|
||||
floodlines = floodsecs = 0;
|
||||
repeattimes = 0;
|
||||
}
|
||||
|
||||
/** Add an entry to the channel access list
|
||||
*
|
||||
* @param nc The NickCore of the user that the access entry should be tied to
|
||||
* @param level The channel access level the user has on the channel
|
||||
* @param creator The user who added the access
|
||||
* @param last_seen When the user was last seen within the channel
|
||||
*
|
||||
* Creates a new access list entry and inserts it into the access list.
|
||||
*/
|
||||
|
||||
void ChannelInfo::AddAccess(NickCore *nc, int16 level, const std::string &creator, int32 last_seen)
|
||||
{
|
||||
ChanAccess *new_access = new ChanAccess();
|
||||
new_access->in_use = 1;
|
||||
new_access->nc = nc;
|
||||
new_access->level = level;
|
||||
new_access->last_seen = last_seen;
|
||||
if (!creator.empty())
|
||||
new_access->creator = creator;
|
||||
else
|
||||
new_access->creator = "Unknown";
|
||||
|
||||
access.push_back(new_access);
|
||||
}
|
||||
|
||||
/** Get an entry from the channel access list by index
|
||||
*
|
||||
* @param index The index in the access list vector
|
||||
* @return A ChanAccess struct corresponding to the index given, or NULL if outside the bounds
|
||||
*
|
||||
* Retrieves an entry from the access list that matches the given index.
|
||||
*/
|
||||
ChanAccess *ChannelInfo::GetAccess(unsigned index)
|
||||
{
|
||||
if (access.empty() || index >= access.size())
|
||||
return NULL;
|
||||
|
||||
return access[index];
|
||||
}
|
||||
|
||||
/** Get an entry from the channel access list by NickCore
|
||||
*
|
||||
* @param nc The NickCore to find within the access list vector
|
||||
* @param level Optional channel access level to compare the access entries to
|
||||
* @return A ChanAccess struct corresponding to the NickCore, or NULL if not found
|
||||
*
|
||||
* Retrieves an entry from the access list that matches the given NickCore, optionally also matching a
|
||||
certain level.
|
||||
*/
|
||||
|
||||
ChanAccess *ChannelInfo::GetAccess(NickCore *nc, int16 level)
|
||||
{
|
||||
if (access.empty())
|
||||
return NULL;
|
||||
|
||||
for (unsigned i = 0; i < access.size(); i++)
|
||||
if (access[i]->in_use && access[i]->nc == nc && (level ? access[i]->level == level : true))
|
||||
return access[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/** Erase an entry from the channel access list
|
||||
*
|
||||
* @param index The index in the access list vector
|
||||
*
|
||||
* Clears the memory used by the given access entry and removes it from the vector.
|
||||
*/
|
||||
void ChannelInfo::EraseAccess(unsigned index)
|
||||
{
|
||||
if (access.empty() || index >= access.size())
|
||||
return;
|
||||
delete access[index];
|
||||
access.erase(access.begin() + index);
|
||||
}
|
||||
|
||||
/** Cleans the channel access list
|
||||
*
|
||||
* Cleans up the access list so it no longer contains entries no longer in use.
|
||||
*/
|
||||
void ChannelInfo::CleanAccess()
|
||||
{
|
||||
for (unsigned j = access.size(); j > 0; --j)
|
||||
if (!access[j - 1]->in_use)
|
||||
EraseAccess(j - 1);
|
||||
}
|
||||
|
||||
/** Clear the entire channel access list
|
||||
*
|
||||
* Clears the entire access list by deleting every item and then clearing the vector.
|
||||
*/
|
||||
void ChannelInfo::ClearAccess()
|
||||
{
|
||||
while (access.begin() != access.end())
|
||||
EraseAccess(0);
|
||||
}
|
||||
|
||||
|
||||
/** Check if a mode is mlocked
|
||||
* @param Name The mode
|
||||
* @param status True to check mlock on, false for mlock off
|
||||
* @return true on success, false on fail
|
||||
*/
|
||||
const bool ChannelInfo::HasMLock(ChannelModeName Name, bool status)
|
||||
{
|
||||
if (status)
|
||||
return mlock_on[(size_t)Name];
|
||||
else
|
||||
return mlock_off[(size_t)Name];
|
||||
}
|
||||
|
||||
/** Set a mlock
|
||||
* @param Name The mode
|
||||
* @param status True for mlock on, false for mlock off
|
||||
*/
|
||||
void ChannelInfo::SetMLock(ChannelModeName Name, bool status)
|
||||
{
|
||||
size_t value = (size_t)Name;
|
||||
|
||||
if (status)
|
||||
mlock_on[value] = true;
|
||||
else
|
||||
mlock_off[value] = true;
|
||||
}
|
||||
|
||||
/** Remove a mlock
|
||||
* @param Name The mode
|
||||
* @param status True for mlock on, false for mlock off
|
||||
*/
|
||||
void ChannelInfo::RemoveMLock(ChannelModeName Name, bool status)
|
||||
{
|
||||
size_t value = (size_t)Name;
|
||||
|
||||
if (status)
|
||||
mlock_on[value] = false;
|
||||
else
|
||||
mlock_off[value] = false;
|
||||
}
|
||||
|
||||
/** Clear all mlocks on the channel
|
||||
*/
|
||||
void ChannelInfo::ClearMLock()
|
||||
{
|
||||
mlock_on.reset();
|
||||
mlock_off.reset();
|
||||
}
|
||||
|
||||
|
||||
/** Set a channel mode param on the channel
|
||||
* @param Name The mode
|
||||
* @param param The param
|
||||
* @param true on success
|
||||
*/
|
||||
bool ChannelInfo::SetParam(ChannelModeName Name, std::string Value)
|
||||
{
|
||||
return Params.insert(std::make_pair(Name, Value)).second;
|
||||
}
|
||||
|
||||
/** Unset a param from the channel
|
||||
* @param Name The mode
|
||||
*/
|
||||
void ChannelInfo::UnsetParam(ChannelModeName Name)
|
||||
{
|
||||
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
|
||||
|
||||
if (it != Params.end())
|
||||
{
|
||||
Params.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
/** Get a param from the channel
|
||||
* @param Name The mode
|
||||
* @param Target a string to put the param into
|
||||
* @return true on success
|
||||
*/
|
||||
const bool ChannelInfo::GetParam(ChannelModeName Name, std::string *Target)
|
||||
{
|
||||
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
|
||||
|
||||
(*Target).clear();
|
||||
|
||||
if (it != Params.end())
|
||||
{
|
||||
*Target = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Check if a mode is set and has a param
|
||||
* @param Name The mode
|
||||
*/
|
||||
const bool ChannelInfo::HasParam(ChannelModeName Name)
|
||||
{
|
||||
std::map<ChannelModeName, std::string>::iterator it = Params.find(Name);
|
||||
|
||||
if (it != Params.end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Clear all the params from the channel
|
||||
*/
|
||||
void ChannelInfo::ClearParams()
|
||||
{
|
||||
Params.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user