summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2010-08-28 20:56:45 -0400
committerAdam <Adam@anope.org>2010-08-28 20:56:45 -0400
commite820e1af0d01011dbe9d91d2971cc3518f7f3d42 (patch)
tree9eb52cf891c4cd92ad08ad8d2f7c019780bc6223
parent26ba944d55fb4ee92dd5d7a3d2cfa869a8be151f (diff)
Properly store our clients internal channel status's and burst them if needed.
Also made Flag::HasFlag use test() instead of operator[] to catch errors, and fixed an out of bounds access to a Flags bitset causing crashes on some systems.
-rw-r--r--include/channels.h2
-rw-r--r--include/extern.h4
-rw-r--r--include/operserv.h4
-rw-r--r--include/regchannel.h4
-rw-r--r--include/services.h4
-rw-r--r--include/users.h4
-rw-r--r--src/bots.cpp2
-rw-r--r--src/channels.cpp15
-rw-r--r--src/init.cpp6
-rw-r--r--src/logger.cpp8
-rw-r--r--src/modes.cpp6
-rw-r--r--src/operserv.cpp4
12 files changed, 38 insertions, 25 deletions
diff --git a/include/channels.h b/include/channels.h
index d1e82fa8d..ec886c9ca 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -70,7 +70,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
std::map<ChannelModeName, Anope::string> Params;
/* Modes set on the channel */
- Flags<ChannelModeName> modes;
+ Flags<ChannelModeName, CMODE_END * 2> modes;
public:
/** Default constructor
diff --git a/include/extern.h b/include/extern.h
index 05e43a980..9f2071a88 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -282,8 +282,8 @@ E bool str_is_cidr(const Anope::string &str, uint32 &ip, uint32 &mask, Anope::st
/**** modes.cpp ****/
/* Number of generic modes we support */
E unsigned GenericChannelModes, GenericUserModes;
-E Flags<ChannelModeName> DefMLockOn;
-E Flags<ChannelModeName> DefMLockOff;
+E Flags<ChannelModeName, CMODE_END * 2> DefMLockOn;
+E Flags<ChannelModeName, CMODE_END * 2> DefMLockOff;
E std::map<ChannelModeName, Anope::string> DefMLockParams;
E void SetDefaultMLock(ServerConfig *config);
diff --git a/include/operserv.h b/include/operserv.h
index 679a066a0..2711520cd 100644
--- a/include/operserv.h
+++ b/include/operserv.h
@@ -12,8 +12,8 @@
extern CoreExport std::vector<NewsItem *> News;
extern CoreExport std::vector<std::bitset<32> > DefCon;
extern CoreExport bool DefConModesSet;
-extern CoreExport Flags<ChannelModeName> DefConModesOn;
-extern CoreExport Flags<ChannelModeName> DefConModesOff;
+extern CoreExport Flags<ChannelModeName, CMODE_END * 2> DefConModesOn;
+extern CoreExport Flags<ChannelModeName, CMODE_END * 2> DefConModesOff;
extern CoreExport std::map<ChannelModeName, Anope::string> DefConModesOnParams;
class XLineManager;
diff --git a/include/regchannel.h b/include/regchannel.h
index e19b07f5e..80b25abfb 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -69,8 +69,8 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
std::vector<ChanAccess *> access; /* List of authorized users */
std::vector<AutoKick *> akick; /* List of users to kickban */
std::vector<BadWord *> badwords; /* List of badwords */
- Flags<ChannelModeName> mlock_on; /* Modes mlocked on */
- Flags<ChannelModeName> mlock_off; /* Modes mlocked off */
+ Flags<ChannelModeName, CMODE_END * 2> mlock_on; /* Modes mlocked on */
+ Flags<ChannelModeName, CMODE_END * 2> mlock_off; /* Modes mlocked off */
public:
/** Default constructor
diff --git a/include/services.h b/include/services.h
index f8f37be6e..4702dcff1 100644
--- a/include/services.h
+++ b/include/services.h
@@ -301,7 +301,7 @@ template<typename T, typename O> inline T debug_cast(O ptr)
{
#ifdef DEBUG_BUILD
T ret = dynamic_cast<T>(ptr);
- if (ret == NULL)
+ if (ptr != NULL && ret == NULL)
throw CoreException(Anope::string("debug_cast<") + typeid(T).name() + ">(" + typeid(O).name() + ") fail");
return ret;
#else
@@ -342,7 +342,7 @@ template<typename T, size_t Size = 32> class Flags
*/
bool HasFlag(T Value) const
{
- return Flag_Values[Value];
+ return Flag_Values.test(Value);
}
/** Check how many flags are set
diff --git a/include/users.h b/include/users.h
index e65068f33..596f5ee39 100644
--- a/include/users.h
+++ b/include/users.h
@@ -17,7 +17,7 @@ typedef unordered_map_namespace::unordered_map<Anope::string, User *, Anope::has
extern CoreExport user_map UserListByNick;
extern CoreExport user_uid_map UserListByUID;
-class ChannelStatus : public Flags<ChannelModeName>
+class ChannelStatus : public Flags<ChannelModeName, CMODE_END * 2>
{
public:
Anope::string BuildCharPrefixList() const;
@@ -43,7 +43,7 @@ class CoreExport User : public Extensible
Anope::string ident;
Anope::string uid;
bool OnAccess; /* If the user is on the access list of the nick theyre on */
- Flags<UserModeName> modes; /* Bitset of mode names the user has set on them */
+ Flags<UserModeName, UMODE_END * 2> modes; /* Bitset of mode names the user has set on them */
std::map<UserModeName, Anope::string> Params; /* Map of user modes and the params this user has */
NickCore *nc; /* NickCore account the user is currently loggged in as */
diff --git a/src/bots.cpp b/src/bots.cpp
index e6124e135..13b21e1ce 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -183,7 +183,7 @@ void BotInfo::Join(Channel *c, bool update_ts)
}
if (!update_ts)
ircdproto->SendJoin(this, c->name, c->creation_time);
- else
+ else if (Me && Me->IsSynced())
{
ircdproto->SendJoin(this, cc);
diff --git a/src/channels.cpp b/src/channels.cpp
index 55de669fd..389577f71 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -82,10 +82,21 @@ void Channel::Reset()
{
UserContainer *uc = *it;
+ Flags<ChannelModeName, CMODE_END * 2> flags = *debug_cast<Flags<ChannelModeName, CMODE_END * 2> *>(uc->Status);
+ uc->Status->ClearFlags();
+
if (findbot(uc->user->nick))
- continue;
+ {
+ for (std::map<char, ChannelMode *>::iterator mit = ModeManager::ChannelModesByChar.begin(), mit_end = ModeManager::ChannelModesByChar.end(); mit != mit_end; ++mit)
+ {
+ ChannelMode *cm = mit->second;
- uc->Status->ClearFlags();
+ if (flags.HasFlag(cm->Name))
+ {
+ this->SetMode(NULL, cm, uc->user->nick, false);
+ }
+ }
+ }
}
check_modes(this);
diff --git a/src/init.cpp b/src/init.cpp
index 94cf37ce9..da3c30587 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -353,9 +353,6 @@ void Init(int ac, char **av)
if (!Config->s_GlobalNoticer.empty())
new BotInfo(Config->s_GlobalNoticer, Config->ServiceUser, Config->ServiceHost, Config->desc_GlobalNoticer);
- /* Init the log channels */
- InitLogChannels(Config);
-
/* Add Encryption Modules */
ModuleManager::LoadModuleList(Config->EncModuleList);
@@ -437,6 +434,9 @@ void Init(int ac, char **av)
rand_init();
add_entropy_userkeys();
+ /* Init log channels */
+ InitLogChannels(Config);
+
/* Load up databases */
Log() << "Loading databases...";
EventReturn MOD_RESULT;
diff --git a/src/logger.cpp b/src/logger.cpp
index de5e58c32..a5637d4d8 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -27,8 +27,12 @@ void InitLogChannels(ServerConfig *config)
if (target[0] == '#')
{
Channel *c = findchan(target);
+ bool created = false;
if (!c)
+ {
c = new Channel(target);
+ created = true;
+ }
c->SetFlag(CH_LOGCHAN);
c->SetFlag(CH_PERSIST);
@@ -38,9 +42,7 @@ void InitLogChannels(ServerConfig *config)
if (bi->HasFlag(BI_CORE) && !c->FindUser(bi))
{
- bi->Join(c);
- for (unsigned j = 0; j < config->BotModeList.size(); ++j)
- c->SetMode(OperServ, config->BotModeList[j], bi->nick, false);
+ bi->Join(c, created);
}
}
}
diff --git a/src/modes.cpp b/src/modes.cpp
index da9f22bef..d3f8ddb9f 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -28,9 +28,9 @@ std::map<ChannelModeName, ChannelMode *> ModeManager::ChannelModesByName;
/* Number of generic modes we support */
unsigned GenericChannelModes = 0, GenericUserModes = 0;
/* Default mlocked modes on */
-Flags<ChannelModeName> DefMLockOn;
+Flags<ChannelModeName, CMODE_END * 2> DefMLockOn;
/* Default mlocked modes off */
-Flags<ChannelModeName> DefMLockOff;
+Flags<ChannelModeName, CMODE_END * 2> DefMLockOff;
/* Map for default mlocked mode parameters */
std::map<ChannelModeName, Anope::string> DefMLockParams;
@@ -41,7 +41,7 @@ void SetDefaultMLock(ServerConfig *config)
DefMLockOn.ClearFlags();
DefMLockOff.ClearFlags();
DefMLockParams.clear();
- Flags<ChannelModeName> *ptr = NULL;
+ Flags<ChannelModeName, CMODE_END * 2> *ptr = NULL;
Anope::string modes, param;
spacesepstream sep(config->MLock);
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 89e84a73e..bbc38eb1a 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -18,9 +18,9 @@ std::vector<NewsItem *> News;
std::vector<std::bitset<32> > DefCon;
bool DefConModesSet = false;
/* Defcon modes mlocked on */
-Flags<ChannelModeName> DefConModesOn;
+Flags<ChannelModeName, CMODE_END * 2> DefConModesOn;
/* Defcon modes mlocked off */
-Flags<ChannelModeName> DefConModesOff;
+Flags<ChannelModeName, CMODE_END * 2> DefConModesOff;
/* Map of Modesa and Params for DefCon */
std::map<ChannelModeName, Anope::string> DefConModesOnParams;