- if (this->capab->CapKeys.find("CHANMODES")->second != ServerInstance->Modes->GiveModeList(MODETYPE_CHANNEL))
- reason = "One or more of the channel modes on the remote server are invalid on this server.";
+ if (this->capab->CapKeys.find("CHANMODES") != this->capab->CapKeys.end())
+ {
+ if (this->capab->CapKeys.find("CHANMODES")->second != ServerInstance->Modes->GiveModeList(MODETYPE_CHANNEL))
+ reason = "One or more of the channel modes on the remote server are invalid on this server.";
+ }
+
+ else if (this->capab->CapKeys.find("PREFIX") != this->capab->CapKeys.end())
+ {
+ if (this->capab->CapKeys.find("PREFIX")->second != ServerInstance->Modes->BuildPrefixes())
+ reason = "One or more of the prefixes on the remote server are invalid on this server.";
+ }
+ }
+
+ if (!reason.empty())
+ {
+ this->SendError("CAPAB negotiation failed: " + reason);
+ return false;