Pass known/compatible tags to clients

This commit is contained in:
J-P Nurmi
2015-07-12 11:37:27 +02:00
parent c17c8c022b
commit 8a7c79bb78
6 changed files with 53 additions and 5 deletions
+2
View File
@@ -29,6 +29,7 @@ class CUser;
class CIRCNetwork;
class CIRCSock;
class CClient;
class CMessage;
// !Forward Declarations
class CAuthBase {
@@ -175,6 +176,7 @@ public:
void PutIRC(const CString& sLine);
void PutClient(const CString& sLine);
void PutClient(const CMessage& Message);
unsigned int PutStatus(const CTable& table);
void PutStatus(const CString& sLine);
void PutStatusNotice(const CString& sLine);
+2
View File
@@ -35,6 +35,7 @@ class CServer;
class CIRCSock;
class CIRCNetworkPingTimer;
class CIRCNetworkJoinTimer;
class CMessage;
class CIRCNetwork {
public:
@@ -90,6 +91,7 @@ public:
// !Modules
bool PutUser(const CString& sLine, CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
bool PutUser(const CMessage& Message, CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
bool PutStatus(const CString& sLine, CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
bool PutModule(const CString& sModule, const CString& sLine, CClient* pClient = nullptr, CClient* pSkipClient = nullptr);
+1
View File
@@ -114,6 +114,7 @@ public:
CString GetISupport(const CString& sKey, const CString& sDefault = "") const;
// !Getters
// TODO: CMessage
// This handles NAMESX and UHNAMES in a raw 353 reply
void ForwardRaw353(const CString& sLine) const;
void ForwardRaw353(const CString& sLine, CClient* pClient) const;
+30
View File
@@ -794,6 +794,36 @@ void CClient::PutClient(const CString& sLine) {
Write(sCopy + "\r\n");
}
void CClient::PutClient(const CMessage& Message)
{
CString sLine = Message.ToString(CMessage::ExcludeTags);
// TODO: introduce a module hook that gives control over the tags that are sent
MCString mssTags;
if (HasServerTime()) {
CString sServerTime = Message.GetTag("time");
if (!sServerTime.empty()) {
mssTags["time"] = sServerTime;
} else {
mssTags["time"] = CUtils::FormatServerTime(Message.GetTime());
}
}
if (HasBatch()) {
CString sBatch = Message.GetTag("batch");
if (!sBatch.empty()) {
mssTags["batch"] = sBatch;
}
}
if (!mssTags.empty()) {
CUtils::SetMessageTags(sLine, mssTags);
}
PutClient(sLine);
}
void CClient::PutStatusNotice(const CString& sLine) {
PutModNotice("status", sLine);
}
+14
View File
@@ -726,6 +726,20 @@ bool CIRCNetwork::PutUser(const CString& sLine, CClient* pClient, CClient* pSkip
return (pClient == nullptr);
}
bool CIRCNetwork::PutUser(const CMessage& Message, CClient* pClient, CClient* pSkipClient) {
for (CClient* pEachClient : m_vClients) {
if ((!pClient || pClient == pEachClient) && pSkipClient != pEachClient) {
pEachClient->PutClient(Message);
if (pClient) {
return true;
}
}
}
return (pClient == nullptr);
}
bool CIRCNetwork::PutStatus(const CString& sLine, CClient* pClient, CClient* pSkipClient) {
for (CClient* pEachClient : m_vClients) {
if ((!pClient || pClient == pEachClient) && pSkipClient != pEachClient) {
+4 -5
View File
@@ -369,7 +369,7 @@ void CIRCSock::ReadLine(const CString& sData) {
const vector<CClient*>& vClients = m_pNetwork->GetClients();
for (CClient* pClient : vClients) {
if (pClient->HasNamesx()) {
m_pNetwork->PutUser(sLine, pClient);
m_pNetwork->PutUser(Message, pClient);
} else {
// The client doesn't support multi-prefix so we need to remove
// the other prefixes.
@@ -379,6 +379,7 @@ void CIRCSock::ReadLine(const CString& sData) {
if (pos >= 2 && pos != CString::npos) {
sNewNick = sNick[0] + sNick.substr(pos);
}
// TODO: CMessage
CString sNewLine = sServer + " 352 " + sLine.Token(2) + " " +
sChan + " " + sIdent + " " + sHost + " " +
sLine.Token(6) + " " + sNewNick + " " +
@@ -528,7 +529,7 @@ void CIRCSock::ReadLine(const CString& sData) {
// We are changing our own nick, the clients always must see this!
bIsVisible = false;
SetNick(sNewNick);
m_pNetwork->PutUser(sLine);
m_pNetwork->PutUser(Message);
}
IRCSOCKMODULECALL(OnNickMessage(NickMsg, vFoundChans), NOTHING);
@@ -749,8 +750,6 @@ void CIRCSock::ReadLine(const CString& sData) {
if (pChan->IsDetached()) {
return; // Don't forward this
}
sLine = ":" + Nick.GetNickMask() + " TOPIC " + pChan->GetName() + " :" + pChan->GetTopic();
}
} else if (sCmd.Equals("PRIVMSG")) {
// :nick!ident@host.com PRIVMSG #chan :Message
@@ -878,7 +877,7 @@ void CIRCSock::ReadLine(const CString& sData) {
}
}
m_pNetwork->PutUser(sLine);
m_pNetwork->PutUser(Message);
}
void CIRCSock::SendNextCap() {