From 72b26043b2f1729a2d183b01310747303fe385fd Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 18 Apr 2014 02:21:06 -0400 Subject: Remove unused event. Mark some oper only usermodes as oper only. Fix reading SID in TS6_SID_Retrieve --- src/servers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/servers.cpp b/src/servers.cpp index 3f698815c..e1b66baa8 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -385,7 +385,7 @@ const Anope::string Servers::TS6_SID_Retrieve() if (!IRCD || !IRCD->RequiresID) return ""; - static Anope::string current_sid = Config->GetBlock("options")->Get("id"); + static Anope::string current_sid = Config->GetBlock("serverinfo")->Get("id"); if (current_sid.empty()) current_sid = "00A"; -- cgit From e36f8143e3bdf136dd6b6d43d1187500c3db6c43 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Sat, 19 Apr 2014 14:35:50 +0200 Subject: Fix SVSNICK target being a nick even when UIDs are available --- src/protocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/protocol.cpp b/src/protocol.cpp index b90c44400..89e4a3c86 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -276,7 +276,7 @@ void IRCDProto::SendNickChange(User *u, const Anope::string &newnick) void IRCDProto::SendForceNickChange(User *u, const Anope::string &newnick, time_t when) { - UplinkSocket::Message() << "SVSNICK " << u->nick << " " << newnick << " " << when; + UplinkSocket::Message() << "SVSNICK " << u->GetUID() << " " << newnick << " " << when; } void IRCDProto::SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...) -- cgit From 00b2cc9ce6b9e4d4869d986ada1cf64d22b95455 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Apr 2014 01:38:45 -0400 Subject: Require at least user@host format for akills. Fix XLine::GetHost() not returning anything if an xline only has a host --- src/xline.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/xline.cpp b/src/xline.cpp index ea74ba8c7..6b3ba90f4 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -103,7 +103,12 @@ Anope::string XLine::GetHost() const return this->mask.substr(host_t + 1); } else - return ""; + { + if (real_t != Anope::string::npos) + return this->mask.substr(0, real_t); + else + return this->mask; + } } Anope::string XLine::GetReal() const -- cgit From 2ab4f175a8ff96355bbb58302eee87138577a3c5 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 25 Apr 2014 16:20:23 -0400 Subject: Don't allow users to join channels they are already in --- src/messages.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/messages.cpp b/src/messages.cpp index bb699a18e..97f0dd968 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -128,6 +128,9 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co User *u = it->second; keep_their_modes = ts <= c->creation_time; // OnJoinChannel can call modules which can modify this channel's ts + if (c->FindUser(u)) + continue; + /* Add the user to the channel */ c->JoinUser(u, keep_their_modes ? &status : NULL); -- cgit From 6a03eb69ebbe773f1d4139ff88d74ecdb2b0af4b Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 25 Apr 2014 16:51:06 -0400 Subject: Add "virtual mode" support This allows fully tracking extbans and other modes set by a different underlying mode, such as InspIRCd's namedmodes Add two configuration options to cs_ban to configure which mode is set and whether or not to kick banned users. Add default "mute" fantasy command to botserv.example.conf --- src/channels.cpp | 38 ++++++++----- src/config.cpp | 15 ++++++ src/modes.cpp | 160 ++++++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 163 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index 37d04c44e..b705c8584 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -248,11 +248,14 @@ std::pair Channel::Get return std::make_pair(it, it_end); } -void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) +void Channel::SetModeInternal(MessageSource &setter, ChannelMode *ocm, const Anope::string &oparam, bool enforce_mlock) { - if (!cm) + if (!ocm) return; + Anope::string param = oparam; + ChannelMode *cm = ocm->Unwrap(param); + EventReturn MOD_RESULT; /* Setting v/h/o/a/q etc */ @@ -315,11 +318,14 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop this->CheckModes(); } -void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) +void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *ocm, const Anope::string &oparam, bool enforce_mlock) { - if (!cm) + if (!ocm) return; + Anope::string param = oparam; + ChannelMode *cm = ocm->Unwrap(param); + EventReturn MOD_RESULT; /* Setting v/h/o/a/q etc */ @@ -433,9 +439,12 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, this->chanserv_modecount++; } - ModeManager::StackerAdd(bi, this, cm, true, param); + Anope::string wparam = param; + ChannelMode *wcm = cm->Wrap(wparam); + + ModeManager::StackerAdd(bi, this, wcm, true, wparam); MessageSource ms(bi); - SetModeInternal(ms, cm, param, enforce_mlock); + SetModeInternal(ms, wcm, wparam, enforce_mlock); } void Channel::SetMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) @@ -484,9 +493,12 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶ this->chanserv_modecount++; } - ModeManager::StackerAdd(bi, this, cm, false, realparam); + Anope::string wparam = realparam; + ChannelMode *wcm = cm->Wrap(wparam); + + ModeManager::StackerAdd(bi, this, wcm, false, wparam); MessageSource ms(bi); - RemoveModeInternal(ms, cm, realparam, enforce_mlock); + RemoveModeInternal(ms, wcm, wparam, enforce_mlock); } void Channel::RemoveMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) @@ -849,21 +861,21 @@ void Channel::SetCorrectModes(User *user, bool give_modes) } } -bool Channel::Unban(User *u, bool full) +bool Channel::Unban(User *u, const Anope::string &mode, bool full) { - if (!this->HasMode("BAN")) + if (!this->HasMode(mode)) return false; bool ret = false; - std::pair bans = this->GetModeList("BAN"); + std::pair bans = this->GetModeList(mode); for (; bans.first != bans.second;) { - Entry ban("BAN", bans.first->second); + Entry ban(mode, bans.first->second); ++bans.first; if (ban.Matches(u, full)) { - this->RemoveMode(NULL, "BAN", ban.GetMask()); + this->RemoveMode(NULL, mode, ban.GetMask()); ret = true; } } diff --git a/src/config.cpp b/src/config.cpp index e402080db..110045786 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -620,6 +620,21 @@ BotInfo *Conf::GetClient(const Anope::string &cname) return GetClient(cname); } +Block *Conf::GetCommand(CommandSource &source) +{ + const Anope::string &block_name = source.c ? "fantasy" : "command"; + + for (std::pair iters = blocks.equal_range(block_name); iters.first != iters.second; ++iters.first) + { + Block *b = &iters.first->second; + + if (b->Get("name") == source.command) + return b; + } + + return NULL; +} + File::File(const Anope::string &n, bool e) : name(n), executable(e), fp(NULL) { } diff --git a/src/modes.cpp b/src/modes.cpp index 13cda797f..891dcf6a8 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -21,9 +21,15 @@ struct StackerInfo; static std::map UserStackerObjects; static std::map ChannelStackerObjects; -/* List of all modes Anope knows about */ -std::vector ModeManager::ChannelModes; -std::vector ModeManager::UserModes; +/* Array of all modes Anope knows about.*/ +static std::vector ChannelModes; +static std::vector UserModes; + +/* Modes are in this array are at position + * modechar. Additionally, status modes are in this array (again) at statuschar. + */ +static std::vector ChannelModesIdx; +static std::vector UserModesIdx; static std::map ChannelModesByName; static std::map UserModesByName; @@ -142,6 +148,28 @@ bool ChannelMode::CanSet(User *u) const return MOD_RESULT != EVENT_STOP; } +ChannelMode *ChannelMode::Wrap(Anope::string ¶m) +{ + return this; +} + +ChannelMode *ChannelMode::Unwrap(Anope::string ¶m) +{ + for (unsigned i = 0; i < listeners.size(); ++i) + { + ChannelMode *cm = listeners[i]->Unwrap(this, param); + if (cm != this) + return cm; + } + + return this; +} + +ChannelMode *ChannelMode::Unwrap(ChannelMode *, Anope::string ¶m) +{ + throw CoreException("Unwrap in channel mode"); +} + ChannelModeList::ChannelModeList(const Anope::string &cm, char mch) : ChannelMode(cm, mch) { this->type = MODE_LIST; @@ -157,6 +185,42 @@ ChannelModeStatus::ChannelModeStatus(const Anope::string &mname, char modeChar, this->type = MODE_STATUS; } +template +ChannelModeVirtual::ChannelModeVirtual(const Anope::string &mname, const Anope::string &basename) : T(mname, 0) + , base(basename) +{ + basech = ModeManager::FindChannelModeByName(base); + if (basech) + basech->listeners.push_back(this); +} + +template +ChannelModeVirtual::~ChannelModeVirtual() +{ + if (basech) + { + std::vector::iterator it = std::find(basech->listeners.begin(), basech->listeners.end(), this); + if (it != basech->listeners.end()) + basech->listeners.erase(it); + } +} + +template +ChannelMode *ChannelModeVirtual::Wrap(Anope::string ¶m) +{ + if (basech == NULL) + { + basech = ModeManager::FindChannelModeByName(base); + if (basech) + basech->listeners.push_back(this); + } + + return basech; +} + +template class ChannelModeVirtual; +template class ChannelModeVirtual; + bool UserModeOperOnly::CanSet(User *u) const { return u && u->HasMode("OPER"); @@ -321,6 +385,8 @@ bool ModeManager::AddUserMode(UserMode *um) { if (ModeManager::FindUserModeByChar(um->mchar) != NULL) return false; + if (ModeManager::FindUserModeByName(um->name) != NULL) + return false; if (um->name.empty()) { @@ -329,12 +395,14 @@ bool ModeManager::AddUserMode(UserMode *um) } unsigned want = um->mchar; - if (want >= ModeManager::UserModes.size()) - ModeManager::UserModes.resize(want + 1); - ModeManager::UserModes[want] = um; + if (want >= UserModesIdx.size()) + UserModesIdx.resize(want + 1); + UserModesIdx[want] = um; UserModesByName[um->name] = um; + UserModes.push_back(um); + FOREACH_MOD(OnUserModeAdd, (um)); return true; @@ -342,7 +410,9 @@ bool ModeManager::AddUserMode(UserMode *um) bool ModeManager::AddChannelMode(ChannelMode *cm) { - if (ModeManager::FindChannelModeByChar(cm->mchar) != NULL) + if (cm->mchar && ModeManager::FindChannelModeByChar(cm->mchar) != NULL) + return false; + if (ModeManager::FindChannelModeByName(cm->name) != NULL) return false; if (cm->name.empty()) @@ -351,24 +421,29 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) Log() << "ModeManager: Added generic support for channel mode " << cm->mchar; } - unsigned want = cm->mchar; - if (want >= ModeManager::ChannelModes.size()) - ModeManager::ChannelModes.resize(want + 1); - ModeManager::ChannelModes[want] = cm; + if (cm->mchar) + { + unsigned want = cm->mchar; + if (want >= ChannelModesIdx.size()) + ChannelModesIdx.resize(want + 1); + ChannelModesIdx[want] = cm; + } if (cm->type == MODE_STATUS) { ChannelModeStatus *cms = anope_dynamic_static_cast(cm); - want = cms->symbol; - if (want >= ModeManager::ChannelModes.size()) - ModeManager::ChannelModes.resize(want + 1); - ModeManager::ChannelModes[want] = cms; + unsigned want = cms->symbol; + if (want >= ChannelModesIdx.size()) + ChannelModesIdx.resize(want + 1); + ChannelModesIdx[want] = cms; RebuildStatusModes(); } ChannelModesByName[cm->name] = cm; + ChannelModes.push_back(cm); + FOREACH_MOD(OnChannelModeAdd, (cm)); return true; @@ -378,18 +453,22 @@ void ModeManager::RemoveUserMode(UserMode *um) { if (!um) return; - + unsigned want = um->mchar; - if (want >= ModeManager::UserModes.size()) + if (want >= UserModesIdx.size()) return; - if (ModeManager::UserModes[want] != um) + if (UserModesIdx[want] != um) return; - ModeManager::UserModes[want] = NULL; + UserModesIdx[want] = NULL; UserModesByName.erase(um->name); + std::vector::iterator it = std::find(UserModes.begin(), UserModes.end(), um); + if (it != UserModes.end()) + UserModes.erase(it); + StackerDel(um); } @@ -397,53 +476,60 @@ void ModeManager::RemoveChannelMode(ChannelMode *cm) { if (!cm) return; + + if (cm->mchar) + { + unsigned want = cm->mchar; + if (want >= ChannelModesIdx.size()) + return; - unsigned want = cm->mchar; - if (want >= ModeManager::ChannelModes.size()) - return; - - if (ModeManager::ChannelModes[want] != cm) - return; + if (ChannelModesIdx[want] != cm) + return; - ModeManager::ChannelModes[want] = NULL; + ChannelModesIdx[want] = NULL; + } if (cm->type == MODE_STATUS) { ChannelModeStatus *cms = anope_dynamic_static_cast(cm); - want = cms->symbol; + unsigned want = cms->symbol; - if (want >= ModeManager::ChannelModes.size()) + if (want >= ChannelModesIdx.size()) return; - if (ModeManager::ChannelModes[want] != cm) + if (ChannelModesIdx[want] != cm) return; - ModeManager::ChannelModes[want] = NULL; + ChannelModesIdx[want] = NULL; RebuildStatusModes(); } ChannelModesByName.erase(cm->name); + std::vector::iterator it = std::find(ChannelModes.begin(), ChannelModes.end(), cm); + if (it != ChannelModes.end()) + ChannelModes.erase(it); + StackerDel(cm); } ChannelMode *ModeManager::FindChannelModeByChar(char mode) { unsigned want = mode; - if (want >= ModeManager::ChannelModes.size()) + if (want >= ChannelModesIdx.size()) return NULL; - return ModeManager::ChannelModes[want]; + return ChannelModesIdx[want]; } UserMode *ModeManager::FindUserModeByChar(char mode) { unsigned want = mode; - if (want >= ModeManager::UserModes.size()) + if (want >= UserModesIdx.size()) return NULL; - return ModeManager::UserModes[want]; + return UserModesIdx[want]; } ChannelMode *ModeManager::FindChannelModeByName(const Anope::string &name) @@ -465,10 +551,10 @@ UserMode *ModeManager::FindUserModeByName(const Anope::string &name) char ModeManager::GetStatusChar(char value) { unsigned want = value; - if (want >= ModeManager::ChannelModes.size()) + if (want >= ChannelModesIdx.size()) return 0; - ChannelMode *cm = ModeManager::ChannelModes[want]; + ChannelMode *cm = ChannelModesIdx[want]; if (cm == NULL || cm->type != MODE_STATUS || cm->mchar == value) return 0; @@ -505,7 +591,7 @@ void ModeManager::RebuildStatusModes() { ChannelMode *cm = ModeManager::GetChannelModes()[j]; - if (cm && cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end()) + if (cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end()) ChannelModesByStatus.push_back(anope_dynamic_static_cast(cm)); } std::sort(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), statuscmp); -- cgit From 4eb0a3bdb73874aa87095f566677166764ef1ccc Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 26 Apr 2014 15:24:19 -0400 Subject: Fix ModeManager::RebuildStatusModes, not all modes are in GetChannelModes() at the time this is called --- src/modes.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/modes.cpp b/src/modes.cpp index 891dcf6a8..668f7c150 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -587,11 +587,11 @@ static struct StatusSort void ModeManager::RebuildStatusModes() { ChannelModesByStatus.clear(); - for (unsigned j = 0; j < ModeManager::GetChannelModes().size(); ++j) + for (unsigned j = 0; j < ChannelModesIdx.size(); ++j) { - ChannelMode *cm = ModeManager::GetChannelModes()[j]; + ChannelMode *cm = ChannelModesIdx[j]; - if (cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end()) + if (cm && cm->type == MODE_STATUS && std::find(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), cm) == ChannelModesByStatus.end()) ChannelModesByStatus.push_back(anope_dynamic_static_cast(cm)); } std::sort(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), statuscmp); -- cgit From 0663f5e41296df36c196425f72516e7dad7c8f2d Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 26 Apr 2014 17:45:16 -0400 Subject: Fire the on user quit event when bots are deleted too --- src/bots.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/bots.cpp b/src/bots.cpp index 77b7d1c35..9ce918a91 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -55,6 +55,7 @@ BotInfo::~BotInfo() if (Me && Me->IsSynced()) { IRCD->SendQuit(this, ""); + FOREACH_MOD(OnUserQuit, (this, "")); this->introduced = false; XLine x(this->nick); IRCD->SendSQLineDel(&x); -- cgit From 76a953844100d8d1762a79053c4feba74ed4639c Mon Sep 17 00:00:00 2001 From: Michael Wobst Date: Tue, 13 May 2014 18:28:53 +0200 Subject: Fix compile warning in base64.cpp:B64Encode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /home/ircd/anope/src/base64.cpp: In function ‘void Anope::B64Encode(const Anope::string&, Anope::string&)’: /home/ircd/anope/src/base64.cpp:85: warning: ‘input’ is used uninitialized in this function --- src/base64.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/base64.cpp b/src/base64.cpp index d4d9ff43e..c00527d42 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -82,7 +82,7 @@ static const char Pad64 = '='; void Anope::B64Encode(const Anope::string &src, Anope::string &target) { size_t src_pos = 0, src_len = src.length(); - unsigned char input[3]; + unsigned char input[3] = { '\0', '\0', '\0' }; target.clear(); -- cgit From 63b02b8c97e73d5a1fc7005e9693a954179ded0d Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 13 May 2014 22:57:53 -0400 Subject: Sanitize nuh masks more to prevent the other side from rewriting them, which screws with our internal tracking of them --- src/channels.cpp | 12 ++++++++---- src/modes.cpp | 19 +++++++++++++++++-- src/protocol.cpp | 5 +++++ 3 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index b705c8584..409cf6b55 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -400,6 +400,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *ocm, const void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { + Anope::string wparam = param; if (!cm) return; /* Don't set modes already set */ @@ -408,11 +409,11 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, else if (cm->type == MODE_PARAM) { ChannelModeParam *cmp = anope_dynamic_static_cast(cm); - if (!cmp->IsValid(param)) + if (!cmp->IsValid(wparam)) return; Anope::string cparam; - if (GetParam(cm->name, cparam) && cparam.equals_cs(param)) + if (GetParam(cm->name, cparam) && cparam.equals_cs(wparam)) return; } else if (cm->type == MODE_STATUS) @@ -424,7 +425,11 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, else if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast(cm); - if (this->HasMode(cm->name, param) || !cml->IsValid(param)) + + if (!cml->IsValid(wparam)) + return; + + if (this->HasMode(cm->name, wparam)) return; } @@ -439,7 +444,6 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, this->chanserv_modecount++; } - Anope::string wparam = param; ChannelMode *wcm = cm->Wrap(wparam); ModeManager::StackerAdd(bi, this, wcm, true, wparam); diff --git a/src/modes.cpp b/src/modes.cpp index 668f7c150..4138cfebe 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -175,6 +175,13 @@ ChannelModeList::ChannelModeList(const Anope::string &cm, char mch) : ChannelMod this->type = MODE_LIST; } +bool ChannelModeList::IsValid(Anope::string &mask) const +{ + if (name == "BAN" || name == "EXCEPT" || name == "INVITEOVERRIDE") + mask = IRCD->NormalizeMask(mask); + return true; +} + ChannelModeParam::ChannelModeParam(const Anope::string &cm, char mch, bool ma) : ChannelMode(cm, mch), minus_no_arg(ma) { this->type = MODE_PARAM; @@ -231,7 +238,7 @@ bool UserModeNoone::CanSet(User *u) const return false; } -bool ChannelModeKey::IsValid(const Anope::string &value) const +bool ChannelModeKey::IsValid(Anope::string &value) const { if (!value.empty() && value.find(':') == Anope::string::npos && value.find(',') == Anope::string::npos) return true; @@ -796,7 +803,7 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh this->host = cidr_ip; - Log(LOG_DEBUG) << "Ban " << this->mask << " has cidr " << this->cidr_len; + Log(LOG_DEBUG) << "Ban " << m << " has cidr " << this->cidr_len; } } catch (const ConvertException &) { } @@ -812,6 +819,14 @@ const Anope::string Entry::GetMask() const return this->mask; } +const Anope::string Entry::GetNUHMask() const +{ + Anope::string n = nick.empty() ? "*" : nick, + u = user.empty() ? "*" : user, + h = host.empty() ? "*" : host; + return n + "!" + u + "@" + h; +} + bool Entry::Matches(User *u, bool full) const { /* First check if this mode has defined any matches (usually for extbans). */ diff --git a/src/protocol.cpp b/src/protocol.cpp index 89e4a3c86..a32f521f2 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -387,6 +387,11 @@ unsigned IRCDProto::GetMaxListFor(Channel *c) return c->HasMode("LBAN") ? 0 : Config->GetBlock("networkinfo")->Get("modelistsize"); } +Anope::string IRCDProto::NormalizeMask(const Anope::string &mask) +{ + return Entry("", mask).GetNUHMask(); +} + MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL) { /* no source for incoming message is our uplink */ -- cgit From df321a118e7dd44dcd3a389f8ee75e9ff915b55e Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 14 May 2014 19:10:23 -0400 Subject: Fix access lists showing the wrong mask if the display nick for a group expires but the group still exists. This can cause access entries for nicks to not be deleted whenever the nicks are deleted. --- src/access.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- src/regchannel.cpp | 16 +--------------- 2 files changed, 50 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/access.cpp b/src/access.cpp index 1b90bb59f..74ff018b9 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -151,9 +151,8 @@ ChanAccess::~ChanAccess() if (it != this->ci->access->end()) this->ci->access->erase(it); - const NickAlias *na = NickAlias::Find(this->mask); - if (na != NULL) - na->nc->RemoveChannelReference(this->ci); + if (nc != NULL) + nc->RemoveChannelReference(this->ci); else { ChannelInfo *c = ChannelInfo::Find(this->mask); @@ -163,6 +162,50 @@ ChanAccess::~ChanAccess() } } +void ChanAccess::SetMask(const Anope::string &m, ChannelInfo *c) +{ + if (nc != NULL) + nc->RemoveChannelReference(this->ci); + else if (!this->mask.empty()) + { + ChannelInfo *targc = ChannelInfo::Find(this->mask); + if (targc) + targc->RemoveChannelReference(this->ci->name); + } + + ci = c; + mask.clear(); + nc = NULL; + + const NickAlias *na = NickAlias::Find(m); + if (na != NULL) + { + nc = na->nc; + nc->AddChannelReference(ci); + } + else + { + mask = m; + + ChannelInfo *targci = ChannelInfo::Find(mask); + if (targci != NULL) + targci->AddChannelReference(ci->name); + } +} + +const Anope::string &ChanAccess::Mask() const +{ + if (nc) + return nc->display; + else + return mask; +} + +NickCore *ChanAccess::GetAccount() const +{ + return nc; +} + void ChanAccess::Serialize(Serialize::Data &data) const { data["provider"] << this->provider->name; @@ -192,7 +235,9 @@ Serializable* ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data) else access = aprovider->Create(); access->ci = ci; - data["mask"] >> access->mask; + Anope::string m; + data["mask"] >> m; + access->SetMask(m, ci); data["creator"] >> access->creator; data["last_seen"] >> access->last_seen; data["created"] >> access->created; diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 0228196a0..7e0ce300c 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -143,8 +143,7 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), AccessProvider *provider = taccess->provider; ChanAccess *newaccess = provider->Create(); - newaccess->ci = this; - newaccess->mask = taccess->mask; + newaccess->SetMask(taccess->Mask(), this); newaccess->creator = taccess->creator; newaccess->last_seen = taccess->last_seen; newaccess->created = taccess->created; @@ -399,19 +398,6 @@ BotInfo *ChannelInfo::WhoSends() const void ChannelInfo::AddAccess(ChanAccess *taccess) { this->access->push_back(taccess); - - const NickAlias *na = NickAlias::Find(taccess->mask); - if (na != NULL) - { - na->nc->AddChannelReference(this); - taccess->nc = na->nc; - } - else - { - ChannelInfo *ci = ChannelInfo::Find(taccess->mask); - if (ci != NULL) - ci->AddChannelReference(this->name); - } } ChanAccess *ChannelInfo::GetAccess(unsigned index) const -- cgit From db56a61f86fad54c7b95f020fe67057d84f89e46 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 19 May 2014 22:45:45 -0400 Subject: Fixup previous commit when serializing access entries --- src/access.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/access.cpp b/src/access.cpp index 74ff018b9..6ccca0fed 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -210,7 +210,7 @@ void ChanAccess::Serialize(Serialize::Data &data) const { data["provider"] << this->provider->name; data["ci"] << this->ci->name; - data["mask"] << this->mask; + data["mask"] << this->Mask(); data["creator"] << this->creator; data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created; -- cgit From 13ea98a02e58777db33c262b4bc27c22fb441b21 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 19 May 2014 22:46:28 -0400 Subject: Fix server usercounter not being incremented when servers are bursting --- src/users.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/users.cpp b/src/users.cpp index 9b790a98c..94ab75fb4 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -68,10 +68,11 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: this->Login(account); this->UpdateHost(); - if (sserver && sserver->IsSynced()) // Our bots are introduced on startup with no server + if (sserver) // Our bots are introduced on startup with no server { ++sserver->users; - Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!sip.empty() && sip != host ? "[" + sip + "] " : "") << "connected to the network (" << sserver->GetName() << ")"; + if (server->IsSynced()) + Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!sip.empty() && sip != host ? "[" + sip + "] " : "") << "connected to the network (" << sserver->GetName() << ")"; } if (UserListByNick.size() > MaxUserCount) -- cgit From e5811586450a8818f46f7d668afbfbcb42c08037 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 20 May 2014 10:00:34 -0400 Subject: Fix two compile warnings in access.cpp on newer compiles --- src/access.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/access.cpp b/src/access.cpp index 6ccca0fed..0c0713c49 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -151,7 +151,7 @@ ChanAccess::~ChanAccess() if (it != this->ci->access->end()) this->ci->access->erase(it); - if (nc != NULL) + if (*nc != NULL) nc->RemoveChannelReference(this->ci); else { @@ -164,7 +164,7 @@ ChanAccess::~ChanAccess() void ChanAccess::SetMask(const Anope::string &m, ChannelInfo *c) { - if (nc != NULL) + if (*nc != NULL) nc->RemoveChannelReference(this->ci); else if (!this->mask.empty()) { -- cgit From 4034b3054aaff28da1db5545063cf8b3c2e8aa24 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 20 May 2014 11:41:05 -0400 Subject: Add English language file which users can edit to modify language strings --- src/language.cpp | 7 ------- src/win32/windows.cpp | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'src') diff --git a/src/language.cpp b/src/language.cpp index fdfb4c15e..bf99a4707 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -76,19 +76,12 @@ const char *Language::Translate(const NickCore *nc, const char *string) #if GETTEXT_FOUND -/* Used by gettext to make it always dynamically load language strings (so we can drop them in while Anope is running) */ extern "C" int _nl_msg_cat_cntr; const char *Language::Translate(const char *lang, const char *string) { if (!string || !*string) return ""; - - if (!lang || !*lang) - lang = Config->DefLanguage.c_str(); - - if (Anope::string(lang) == "en") - return string; ++_nl_msg_cat_cntr; #ifdef _WIN32 diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp index a9e0521d0..04eb2fae3 100644 --- a/src/win32/windows.cpp +++ b/src/win32/windows.cpp @@ -26,6 +26,7 @@ static struct WindowsLanguage {"ca_ES", LANG_CATALAN}, {"de_DE", LANG_GERMAN}, {"el_GR", LANG_GREEK}, + {"en_US", LANG_ENGLISH}, {"es_ES", LANG_SPANISH}, {"fr_FR", LANG_FRENCH}, {"hu_HU", LANG_HUNGARIAN}, -- cgit From 20ce170024779aebbc1462146905c976836a552f Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 20 May 2014 12:19:26 -0400 Subject: Show account names in log messages --- src/logger.cpp | 58 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/logger.cpp b/src/logger.cpp index 445e71949..2b6d06e87 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -137,6 +137,27 @@ Log::~Log() Config->LogInfos[i].ProcessMessage(this); } +Anope::string Log::FormatSource() const +{ + if (u) + if (nc) + return this->u->GetMask() + " (" + this->nc->display + ")"; + else + return this->u->GetMask(); + else if (nc) + return nc->display; + return ""; +} + +Anope::string Log::FormatCommand() const +{ + Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->name) + " "; + if (this->ci) + buffer += "on " + this->ci->name + " "; + + return buffer; +} + Anope::string Log::BuildPrefix() const { Anope::string buffer; @@ -147,61 +168,34 @@ Anope::string Log::BuildPrefix() const { if (!this->c) break; - buffer += "ADMIN: "; - Anope::string cname = source != NULL && !source->command.empty() ? source->command : this->c->name; - if (this->u) - buffer += this->u->GetMask() + " used " + cname + " "; - else if (this->nc) - buffer += this->nc->display + " used " + cname + " "; - if (this->ci) - buffer += "on " + this->ci->name + " "; + buffer += "ADMIN: " + FormatCommand(); break; } case LOG_OVERRIDE: { if (!this->c) break; - buffer += "OVERRIDE: "; - Anope::string cname = source != NULL && !source->command.empty() ? source->command : this->c->name; - if (this->u) - buffer += this->u->GetMask() + " used " + cname + " "; - else if (this->nc) - buffer += this->nc->display + " used " + cname + " "; - if (this->ci) - buffer += "on " + this->ci->name + " "; + buffer += "OVERRIDE: " + FormatCommand(); break; } case LOG_COMMAND: { if (!this->c) break; - buffer += "COMMAND: "; - Anope::string cname = source != NULL && !source->command.empty() ? source->command : this->c->name; - if (this->u) - buffer += this->u->GetMask() + " used " + cname + " "; - else if (this->source) - buffer += this->source->GetNick() + " used " + cname + " "; - else if (this->nc) - buffer += this->nc->display + " used " + cname + " "; - if (this->ci) - buffer += "on " + this->ci->name + " "; + buffer += "COMMAND: " + FormatCommand(); break; } case LOG_CHANNEL: { if (!this->chan) break; - buffer += "CHANNEL: "; - if (this->u) - buffer += this->u->GetMask() + " " + this->category + " " + this->chan->name + " "; - else - buffer += this->category + " " + this->chan->name + " "; + buffer += "CHANNEL: " + FormatSource() + " " + this->category + " " + this->chan->name + " "; break; } case LOG_USER: { if (this->u) - buffer += "USERS: " + this->u->GetMask() + " "; + buffer += "USERS: " + FormatSource() + " "; break; } case LOG_SERVER: -- cgit From 866f3f32ab3713e9867747f150df3698e456744e Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 20 May 2014 21:10:49 -0400 Subject: Speed up akill xline checks Cache xline nick, user, host, etc instead of rebuilding it everytime its requested. Store users ip in sockaddr form and not string form to prevent having to rebuild sockaddrs when checking xlines. Also do not try to convert empty config values in Config::Get as this can be rather common if a non string configuration value is not set, and the cost of the ConvertException is great. --- src/messages.cpp | 2 -- src/modes.cpp | 2 +- src/sockets.cpp | 15 ++++---- src/users.cpp | 5 ++- src/xline.cpp | 102 ++++++++++++++++++++++++++++++------------------------- 5 files changed, 67 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/messages.cpp b/src/messages.cpp index 97f0dd968..8e92d19c2 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -158,8 +158,6 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co if (c->CheckDelete()) delete c; - else - c->CheckModes(); } } } diff --git a/src/modes.cpp b/src/modes.cpp index 4138cfebe..dafe2ddca 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -867,7 +867,7 @@ bool Entry::Matches(User *u, bool full) const } } else if (!this->host.empty() && !Anope::Match(u->GetDisplayedHost(), this->host) && !Anope::Match(u->GetCloakedHost(), this->host) && - (!full || (!Anope::Match(u->host, this->host) && !Anope::Match(u->ip, this->host)))) + (!full || (!Anope::Match(u->host, this->host) && !Anope::Match(u->ip.addr(), this->host)))) ret = false; if (!this->real.empty() && !Anope::Match(u->realname, this->real)) diff --git a/src/sockets.cpp b/src/sockets.cpp index f047c5f44..9b88de4c6 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -96,9 +96,9 @@ bool sockaddrs::ipv6() const return sa.sa_family == AF_INET6; } -bool sockaddrs::operator()() const +bool sockaddrs::valid() const { - return valid(); + return size() != 0; } bool sockaddrs::operator==(const sockaddrs &other) const @@ -180,11 +180,6 @@ void sockaddrs::ntop(int type, const void *src) this->clear(); } -bool sockaddrs::valid() const -{ - return size() != 0; -} - cidr::cidr(const Anope::string &ip) { bool ipv6 = ip.find(':') != Anope::string::npos; @@ -221,6 +216,12 @@ cidr::cidr(const Anope::string &ip, unsigned char len) this->cidr_len = len; } +cidr::cidr(const sockaddrs &a, unsigned char len) : addr(a) +{ + this->cidr_ip = a.addr(); + this->cidr_len = len; +} + Anope::string cidr::mask() const { if ((this->addr.ipv6() && this->cidr_len == 128) || (!this->addr.ipv6() && this->cidr_len == 32)) diff --git a/src/users.cpp b/src/users.cpp index 94ab75fb4..8a4246e2f 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -33,7 +33,7 @@ time_t MaxUserTime = 0; std::list User::quitting_users; -User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account) +User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &uip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account) : ip(uip) { if (snick.empty() || sident.empty() || shost.empty()) throw CoreException("Bad args passed to User::User"); @@ -49,7 +49,6 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: this->host = shost; this->vhost = svhost; this->chost = svhost; - this->ip = sip; this->server = sserver; this->realname = srealname; this->timestamp = this->signon = ts; @@ -72,7 +71,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: { ++sserver->users; if (server->IsSynced()) - Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!sip.empty() && sip != host ? "[" + sip + "] " : "") << "connected to the network (" << sserver->GetName() << ")"; + Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!uip.empty() && uip != host ? "[" + uip + "] " : "") << "connected to the network (" << sserver->GetName() << ")"; } if (UserListByNick.size() > MaxUserCount) diff --git a/src/xline.cpp b/src/xline.cpp index 6b3ba90f4..8f02b930e 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -24,7 +24,7 @@ std::list XLineManager::XLineManagers; Serialize::Checker > XLineManager::XLinesByUID("XLine"); -void XLine::InitRegex() +void XLine::Init() { if (this->mask.length() >= 2 && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/' && !Config->GetBlock("options")->Get("regexengine").empty()) { @@ -43,82 +43,92 @@ void XLine::InitRegex() } } } + + size_t nick_t = this->mask.find('!'); + if (nick_t != Anope::string::npos) + nick = this->mask.substr(0, nick_t); + + size_t user_t = this->mask.find('!'), host_t = this->mask.find('@'); + if (host_t != Anope::string::npos) + { + if (user_t != Anope::string::npos && host_t > user_t) + user = this->mask.substr(user_t + 1, host_t - user_t - 1); + else + user = this->mask.substr(0, host_t); + } + + size_t real_t = this->mask.find('#'); + if (host_t != Anope::string::npos) + { + if (real_t != Anope::string::npos && real_t > host_t) + host = this->mask.substr(host_t + 1, real_t - host_t - 1); + else + host = this->mask.substr(host_t + 1); + } + else + { + if (real_t != Anope::string::npos) + host = this->mask.substr(0, real_t); + else + host = this->mask; + } + + if (real_t != Anope::string::npos) + real = this->mask.substr(real_t + 1); + + if (host.find('/') != Anope::string::npos) + { + c = new cidr(host); + if (!c->valid()) + { + delete c; + c = NULL; + } + } } XLine::XLine(const Anope::string &ma, const Anope::string &r, const Anope::string &uid) : Serializable("XLine"), mask(ma), by(Me->GetName()), created(0), expires(0), reason(r), id(uid) { regex = NULL; manager = NULL; + c = NULL; - this->InitRegex(); + this->Init(); } XLine::XLine(const Anope::string &ma, const Anope::string &b, const time_t ex, const Anope::string &r, const Anope::string &uid) : Serializable("XLine"), mask(ma), by(b), created(Anope::CurTime), expires(ex), reason(r), id(uid) { regex = NULL; manager = NULL; + c = NULL; - this->InitRegex(); + this->Init(); } XLine::~XLine() { delete regex; + delete c; } -Anope::string XLine::GetNick() const +const Anope::string &XLine::GetNick() const { - size_t nick_t = this->mask.find('!'); - - if (nick_t == Anope::string::npos) - return ""; - - return this->mask.substr(0, nick_t); + return nick; } -Anope::string XLine::GetUser() const +const Anope::string &XLine::GetUser() const { - size_t user_t = this->mask.find('!'), host_t = this->mask.find('@'); - - if (host_t != Anope::string::npos) - { - if (user_t != Anope::string::npos && host_t > user_t) - return this->mask.substr(user_t + 1, host_t - user_t - 1); - else - return this->mask.substr(0, host_t); - } - else - return ""; + return user; } -Anope::string XLine::GetHost() const +const Anope::string &XLine::GetHost() const { - size_t host_t = this->mask.find('@'), real_t = this->mask.find('#'); - - if (host_t != Anope::string::npos) - { - if (real_t != Anope::string::npos && real_t > host_t) - return this->mask.substr(host_t + 1, real_t - host_t - 1); - else - return this->mask.substr(host_t + 1); - } - else - { - if (real_t != Anope::string::npos) - return this->mask.substr(0, real_t); - else - return this->mask; - } + return host; } -Anope::string XLine::GetReal() const +const Anope::string &XLine::GetReal() const { - size_t real_t = this->mask.find('#'); - - if (real_t != Anope::string::npos) - return this->mask.substr(real_t + 1); - else - return ""; + return real; } Anope::string XLine::GetReason() const -- cgit From 5a1257b7f0b44ee3fd4639e5be288d160ceb5095 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 May 2014 08:40:54 -0400 Subject: Fix extra space in log messages with logtype channel and no source --- src/logger.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/logger.cpp b/src/logger.cpp index 2b6d06e87..4297bcab0 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -189,7 +189,11 @@ Anope::string Log::BuildPrefix() const { if (!this->chan) break; - buffer += "CHANNEL: " + FormatSource() + " " + this->category + " " + this->chan->name + " "; + buffer += "CHANNEL: "; + Anope::string src = FormatSource(); + if (!src.empty()) + buffer += src + " "; + buffer += this->category + " " + this->chan->name + " "; break; } case LOG_USER: -- cgit From f627a3bacd0d058e94260dac1555790cafd9a926 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 May 2014 08:50:40 -0400 Subject: Core prep for p10 stuff --- src/bots.cpp | 36 +++++++++++++++------------ src/config.cpp | 2 +- src/init.cpp | 2 +- src/logger.cpp | 2 +- src/messages.cpp | 14 ++++++++--- src/process.cpp | 71 +++++++++++++++++++++++++++++++++--------------------- src/protocol.cpp | 49 ++++++++++++++++++++++++++++++++++++- src/regchannel.cpp | 2 +- src/servers.cpp | 49 +------------------------------------ src/uplink.cpp | 15 +++--------- src/users.cpp | 17 +++++++------ 11 files changed, 141 insertions(+), 118 deletions(-) (limited to 'src') diff --git a/src/bots.cpp b/src/bots.cpp index 9ce918a91..16e6a1cf9 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -21,7 +21,7 @@ Serialize::Checker BotListByNick("BotInfo"), BotListByUID("BotInfo"); -BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes) +BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes) { this->lastmsg = this->created = Anope::CurTime; this->introduced = false; @@ -96,7 +96,7 @@ Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data) BotInfo *bi; if (obj) bi = anope_dynamic_static_cast(obj); - else if (!(bi = BotInfo::Find(nick))) + else if (!(bi = BotInfo::Find(nick, true))) bi = new BotInfo(nick, user, host, realname); data["created"] >> bi->created; @@ -118,7 +118,7 @@ void BotInfo::GenerateUID() UserListByUID.erase(this->uid); } - this->uid = Servers::TS6_UID_Retrieve(); + this->uid = IRCD->UID_Retrieve(); (*BotListByUID)[this->uid] = this; UserListByUID[this->uid] = this; } @@ -215,9 +215,9 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); - FOREACH_MOD(OnPartChannel, (this, c, c->name, reason)); - c->DeleteUser(this); + + FOREACH_MOD(OnPartChannel, (this, c, c->name, reason)); } void BotInfo::OnMessage(User *u, const Anope::string &message) @@ -248,22 +248,28 @@ CommandInfo *BotInfo::GetCommand(const Anope::string &cname) BotInfo* BotInfo::Find(const Anope::string &nick, bool nick_only) { - BotInfo *bi = NULL; - if (!nick_only && isdigit(nick[0]) && IRCD->RequiresID) + if (!nick_only && IRCD != NULL && IRCD->RequiresID) { botinfo_map::iterator it = BotListByUID->find(nick); if (it != BotListByUID->end()) - bi = it->second; + { + BotInfo *bi = it->second; + bi->QueueUpdate(); + return bi; + } + + if (IRCD->AmbiguousID) + return NULL; } - else + + botinfo_map::iterator it = BotListByNick->find(nick); + if (it != BotListByNick->end()) { - botinfo_map::iterator it = BotListByNick->find(nick); - if (it != BotListByNick->end()) - bi = it->second; + BotInfo *bi = it->second; + bi->QueueUpdate(); + return bi; } - if (bi) - bi->QueueUpdate(); - return bi; + return NULL; } diff --git a/src/config.cpp b/src/config.cpp index 110045786..3ce4251e7 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -394,7 +394,7 @@ Conf::Conf() : Block("") LogInfo l(logage, rawio, debug); - l.bot = BotInfo::Find(log->Get("bot", "Global")); + l.bot = BotInfo::Find(log->Get("bot", "Global"), true); spacesepstream(log->Get("target")).GetTokens(l.targets); spacesepstream(log->Get("source")).GetTokens(l.sources); spacesepstream(log->Get("admin")).GetTokens(l.admin); diff --git a/src/init.cpp b/src/init.cpp index 07f847d70..da91e2fcf 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -527,7 +527,7 @@ void Anope::Init(int ac, char **av) /* Auto assign sid if applicable */ if (IRCD->RequiresID) { - Anope::string sid = Servers::TS6_SID_Retrieve(); + Anope::string sid = IRCD->SID_Retrieve(); if (Me->GetSID() == Me->GetName()) Me->SetSID(sid); for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) diff --git a/src/logger.cpp b/src/logger.cpp index 4297bcab0..977af0a5f 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -90,7 +90,7 @@ Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.G size_t sl = c->name.find('/'); this->bi = NULL; if (sl != Anope::string::npos) - this->bi = BotInfo::Find(c->name.substr(0, sl)); + this->bi = BotInfo::Find(c->name.substr(0, sl), true); this->category = c->name; } diff --git a/src/messages.cpp b/src/messages.cpp index 8e92d19c2..d6fd99143 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -208,19 +208,23 @@ void Kill::Run(MessageSource &source, const std::vector ¶ms) void Message::Mode::Run(MessageSource &source, const std::vector ¶ms) { + Anope::string buf; + for (unsigned i = 1; i < params.size(); ++i) + buf += " " + params[i]; + if (IRCD->IsChannelValid(params[0])) { Channel *c = Channel::Find(params[0]); if (c) - c->SetModesInternal(source, params[1], 0); + c->SetModesInternal(source, buf.substr(1), 0); } else { User *u = User::Find(params[0]); if (u) - u->SetModesInternal(source, "%s", params[1].c_str()); + u->SetModesInternal(source, "%s", buf.substr(1).c_str()); } } @@ -313,10 +317,12 @@ void Privmsg::Run(MessageSource &source, const std::vector ¶m * us, and strip it off. */ Anope::string botname = receiver; size_t s = receiver.find('@'); + bool nick_only = false; if (s != Anope::string::npos) { Anope::string servername(receiver.begin() + s + 1, receiver.end()); botname = botname.substr(0, s); + nick_only = true; if (!servername.equals_ci(Me->GetName())) return; } @@ -330,7 +336,7 @@ void Privmsg::Run(MessageSource &source, const std::vector ¶m return; } - BotInfo *bi = BotInfo::Find(botname); + BotInfo *bi = BotInfo::Find(botname, nick_only); if (bi) { @@ -469,7 +475,7 @@ void Whois::Run(MessageSource &source, const std::vector ¶ms) if (u && u->server == Me) { - const BotInfo *bi = BotInfo::Find(u->nick); + const BotInfo *bi = BotInfo::Find(u->GetUID()); IRCD->SendNumeric(311, source.GetSource(), "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str()); if (bi) IRCD->SendNumeric(307, source.GetSource(), "%s :is a registered nick", bi->nick.c_str()); diff --git a/src/process.cpp b/src/process.cpp index 16373b144..2d7a1561a 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -24,34 +24,10 @@ void Anope::Process(const Anope::string &buffer) if (buffer.empty()) return; - spacesepstream buf_sep(buffer); - - Anope::string source; - if (buffer[0] == ':') - { - buf_sep.GetToken(source); - source.erase(0, 1); - } - - Anope::string command; - if (!buf_sep.GetToken(command)) - return; - - Anope::string buf_token; + Anope::string source, command; std::vector params; - while (buf_sep.GetToken(buf_token)) - { - if (buf_token[0] == ':') - { - if (!buf_sep.StreamEnd()) - params.push_back(buf_token.substr(1) + " " + buf_sep.GetRemaining()); - else - params.push_back(buf_token.substr(1)); - break; - } - else - params.push_back(buf_token); - } + + IRCD->Parse(buffer, source, command, params); if (Anope::ProtocolDebug) { @@ -65,6 +41,12 @@ void Anope::Process(const Anope::string &buffer) Log() << "params " << i << ": " << params[i]; } + if (command.empty()) + { + Log(LOG_DEBUG) << "No command? " << buffer; + return; + } + static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : ""; MessageSource src(source); @@ -91,3 +73,38 @@ void Anope::Process(const Anope::string &buffer) m->Run(src, params); } +void IRCDProto::Parse(const Anope::string &buffer, Anope::string &source, Anope::string &command, std::vector ¶ms) +{ + spacesepstream sep(buffer); + + if (buffer[0] == ':') + { + sep.GetToken(source); + source.erase(0, 1); + } + + sep.GetToken(command); + + for (Anope::string token; sep.GetToken(token);) + { + if (token[0] == ':') + { + if (!sep.StreamEnd()) + params.push_back(token.substr(1) + " " + sep.GetRemaining()); + else + params.push_back(token.substr(1)); + break; + } + else + params.push_back(token); + } +} + +Anope::string IRCDProto::Format(const Anope::string &source, const Anope::string &message) +{ + if (!source.empty()) + return ":" + source + " " + message; + else + return message; +} + diff --git a/src/protocol.cpp b/src/protocol.cpp index a32f521f2..17b43e292 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -26,7 +26,7 @@ IRCDProto::IRCDProto(Module *creator, const Anope::string &p) : Service(creator, { DefaultPseudoclientModes = "+io"; CanSVSNick = CanSVSJoin = CanSetVHost = CanSetVIdent = CanSNLine = CanSQLine = CanSQLineChannel - = CanSZLine = CanSVSHold = CanSVSO = CanCertFP = RequiresID = false; + = CanSZLine = CanSVSHold = CanSVSO = CanCertFP = RequiresID = AmbiguousID = false; MaxModes = 3; MaxLine = 512; @@ -45,6 +45,53 @@ const Anope::string &IRCDProto::GetProtocolName() return this->proto_name; } +static inline char& nextID(char &c) +{ + if (c == 'Z') + c = '0'; + else if (c != '9') + ++c; + else + c = 'A'; + return c; +} + +Anope::string IRCDProto::UID_Retrieve() +{ + if (!IRCD || !IRCD->RequiresID) + return ""; + + static Anope::string current_uid = "AAAAAA"; + + do + { + int current_len = current_uid.length() - 1; + while (current_len >= 0 && nextID(current_uid[current_len--]) == 'A'); + } + while (User::Find(Me->GetSID() + current_uid) != NULL); + + return Me->GetSID() + current_uid; +} + +Anope::string IRCDProto::SID_Retrieve() +{ + if (!IRCD || !IRCD->RequiresID) + return ""; + + static Anope::string current_sid = Config->GetBlock("serverinfo")->Get("id"); + if (current_sid.empty()) + current_sid = "00A"; + + do + { + int current_len = current_sid.length() - 1; + while (current_len >= 0 && nextID(current_sid[current_len--]) == 'A'); + } + while (Server::Find(current_sid) != NULL); + + return current_sid; +} + void IRCDProto::SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason) { UplinkSocket::Message(source) << "KILL " << target << " :" << reason; diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 7e0ce300c..5c00e291a 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -271,7 +271,7 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) } catch (const ConvertException &) { } } - BotInfo *bi = BotInfo::Find(sbi); + BotInfo *bi = BotInfo::Find(sbi, true); if (*ci->bi != bi) { if (bi) diff --git a/src/servers.cpp b/src/servers.cpp index e1b66baa8..3427c2beb 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -95,7 +95,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano { User *u = it->second; - BotInfo *bi = BotInfo::Find(u->nick); + BotInfo *bi = BotInfo::Find(u->GetUID()); if (bi) { XLine x(bi->nick, "Reserved for services"); @@ -352,53 +352,6 @@ Server *Server::Find(const Anope::string &name, bool name_only) return NULL; } -static inline char& nextID(char &c) -{ - if (c == 'Z') - c = '0'; - else if (c != '9') - ++c; - else - c = 'A'; - return c; -} - -const Anope::string Servers::TS6_UID_Retrieve() -{ - if (!IRCD || !IRCD->RequiresID) - return ""; - - static Anope::string current_uid = "AAAAAA"; - - do - { - int current_len = current_uid.length() - 1; - while (current_len >= 0 && nextID(current_uid[current_len--]) == 'A'); - } - while (User::Find(Me->GetSID() + current_uid) != NULL); - - return Me->GetSID() + current_uid; -} - -const Anope::string Servers::TS6_SID_Retrieve() -{ - if (!IRCD || !IRCD->RequiresID) - return ""; - - static Anope::string current_sid = Config->GetBlock("serverinfo")->Get("id"); - if (current_sid.empty()) - current_sid = "00A"; - - do - { - int current_len = current_sid.length() - 1; - while (current_len >= 0 && nextID(current_sid[current_len--]) == 'A'); - } - while (Server::Find(current_sid) != NULL); - - return current_sid; -} - Server* Servers::GetUplink() { for (unsigned i = 0; Me && i < Me->GetLinks().size(); ++i) diff --git a/src/uplink.cpp b/src/uplink.cpp index 80727487a..549df85b3 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -77,7 +77,7 @@ UplinkSocket::~UplinkSocket() { /* Don't use quitmsg here, it may contain information you don't want people to see */ IRCD->SendQuit(u, "Shutting down"); - BotInfo* bi = BotInfo::Find(u->nick); + BotInfo* bi = BotInfo::Find(u->GetUID()); if (bi != NULL) bi->introduced = false; } @@ -195,14 +195,7 @@ UplinkSocket::Message::~Message() return; } - if (!message_source.empty()) - { - UplinkSock->Write(":" + message_source + " " + this->buffer.str()); - Log(LOG_RAWIO) << "Sent: :" << message_source << " " << this->buffer.str(); - } - else - { - UplinkSock->Write(this->buffer.str()); - Log(LOG_RAWIO) << "Sent: " << this->buffer.str(); - } + Anope::string sent = IRCD->Format(message_source, this->buffer.str()); + UplinkSock->Write(sent); + Log(LOG_RAWIO) << "Sent: " << sent; } diff --git a/src/users.cpp b/src/users.cpp index 8a4246e2f..2a04fca20 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -118,7 +118,7 @@ User* User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, // How IRCds handle collisions varies a lot, for safety well just always kill both sides // With properly set qlines, this can almost never happen anyway - User *u = User::Find(snick); + User *u = User::Find(snick, true); if (u) { Collide(u, !suid.empty() ? suid : snick, "Nick collision"); @@ -814,18 +814,19 @@ bool User::BadPassword() User* User::Find(const Anope::string &name, bool nick_only) { - if (!nick_only && isdigit(name[0]) && IRCD->RequiresID) + if (!nick_only && IRCD->RequiresID) { user_map::iterator it = UserListByUID.find(name); if (it != UserListByUID.end()) return it->second; + + if (IRCD->AmbiguousID) + return NULL; } - else - { - user_map::iterator it = UserListByNick.find(name); - if (it != UserListByNick.end()) - return it->second; - } + + user_map::iterator it = UserListByNick.find(name); + if (it != UserListByNick.end()) + return it->second; return NULL; } -- cgit From 7a2d027e1da37df9b4243e03c050ed06e0b76a53 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 21 May 2014 10:47:50 -0400 Subject: Fix deflanguage from 4034b3054aaff28da1db5545063cf8b3c2e8aa24, this shouldn't have been removed --- src/language.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/language.cpp b/src/language.cpp index bf99a4707..3404daba3 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -83,6 +83,9 @@ const char *Language::Translate(const char *lang, const char *string) if (!string || !*string) return ""; + if (!lang || !*lang) + lang = Config->DefLanguage.c_str(); + ++_nl_msg_cat_cntr; #ifdef _WIN32 SetThreadLocale(MAKELCID(MAKELANGID(WindowsGetLanguage(lang), SUBLANG_DEFAULT), SORT_DEFAULT)); -- cgit From 37b3ed8ef39bb0e3e4f730f354a646b4cdc36e8e Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 27 May 2014 12:49:22 -0400 Subject: Do not normalize extban masks --- src/protocol.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/protocol.cpp b/src/protocol.cpp index 17b43e292..692ce005a 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -436,6 +436,8 @@ unsigned IRCDProto::GetMaxListFor(Channel *c) Anope::string IRCDProto::NormalizeMask(const Anope::string &mask) { + if (IsExtbanValid(mask)) + return mask; return Entry("", mask).GetNUHMask(); } -- cgit From e8ad509aa5b4bed4f61f32fd1ac7bfeb49685be5 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 27 May 2014 12:53:20 -0400 Subject: Fix dlerror() on Windows and do not abort if err is not set --- src/modulemanager.cpp | 16 +++++++++------- src/win32/dl/dl.cpp | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 07ac46ee1..2832a562a 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -159,25 +159,25 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) dlerror(); void *handle = dlopen(pbuf.c_str(), RTLD_NOW); const char *err = dlerror(); - if (!handle && err && *err) + if (!handle) { - Log() << err; + if (err && *err) + Log() << err; return MOD_ERR_NOLOAD; } dlerror(); Module *(*func)(const Anope::string &, const Anope::string &) = function_cast(dlsym(handle, "AnopeInit")); err = dlerror(); - if (!func && err && *err) + if (!func) { Log() << "No init function found, not an Anope module"; + if (err && *err) + Log(LOG_DEBUG) << err; dlclose(handle); return MOD_ERR_NOLOAD; } - - if (!func) - throw CoreException("Couldn't find constructor, yet moderror wasn't set?"); - + /* Create module. */ Anope::string nick; if (u) @@ -192,6 +192,8 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) catch (const ModuleException &ex) { Log() << "Error while loading " << modname << ": " << ex.GetReason(); + /*if (dlclose(handle)) + Log() << dlerror();*/ return MOD_ERR_EXCEPTION; } diff --git a/src/win32/dl/dl.cpp b/src/win32/dl/dl.cpp index b7ffddaa3..5b19d7441 100644 --- a/src/win32/dl/dl.cpp +++ b/src/win32/dl/dl.cpp @@ -15,7 +15,8 @@ void *dlopen(const char *filename, int) char *dlerror(void) { - static Anope::string err = Anope::LastError(); + static Anope::string err; + err = Anope::LastError(); SetLastError(0); return err.empty() ? NULL : const_cast(err.c_str()); } -- cgit From f8829783d241bab07d2144a4a8f5ba440d08b321 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 30 May 2014 11:07:14 -0400 Subject: Queue the grouped nicks to update when NickCore::SetDisplay is called, since they serialize the display field --- src/nickcore.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/nickcore.cpp b/src/nickcore.cpp index c055491db..9c0e25f32 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -158,6 +158,10 @@ void NickCore::SetDisplay(const NickAlias *na) FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick)); + /* this affects the serialized aliases */ + for (unsigned i = 0; i < aliases->size(); ++i) + aliases->at(i)->QueueUpdate(); + /* Remove the core from the list */ NickCoreList->erase(this->display); -- cgit From f20bac996da46556a821c1b0244a202e652fe247 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 30 May 2014 15:45:57 -0400 Subject: Fix Windows build and update library names to the newer ones. Also fix crash on Windows when unloading a module because it threw an exception. --- src/modulemanager.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 2832a562a..71e692dd2 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -185,6 +185,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) Module *m; + ModuleReturn moderr = MOD_ERR_OK; try { m = func(modname, nick); @@ -192,9 +193,14 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) catch (const ModuleException &ex) { Log() << "Error while loading " << modname << ": " << ex.GetReason(); - /*if (dlclose(handle)) - Log() << dlerror();*/ - return MOD_ERR_EXCEPTION; + moderr = MOD_ERR_EXCEPTION; + } + + if (moderr != MOD_ERR_OK) + { + if (dlclose(handle)) + Log() << dlerror(); + return moderr; } m->filename = pbuf; @@ -236,18 +242,22 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) catch (const ModuleException &ex) { Log() << "Module " << modname << " couldn't load:" << ex.GetReason(); - DeleteModule(m); - return MOD_ERR_EXCEPTION; + moderr = MOD_ERR_EXCEPTION; } catch (const ConfigException &ex) { Log() << "Module " << modname << " couldn't load due to configuration problems: " << ex.GetReason(); - DeleteModule(m); - return MOD_ERR_EXCEPTION; + moderr = MOD_ERR_EXCEPTION; } catch (const NotImplementedException &ex) { } + + if (moderr != MOD_ERR_OK) + { + DeleteModule(m); + return moderr; + } Log(LOG_DEBUG) << "Module " << modname << " loaded."; -- cgit From 4d8e3b847d4ecd532643d5cb0925a2d701c84b23 Mon Sep 17 00:00:00 2001 From: Adam