Example #1
0
bool TTsentence::fn1(const CString &str, int wordId1, const CString &str1, const CString &str2,
		const CString &str3, int wordId2, int val1, int val2, const TTconceptNode *node) const {
	if (node)
		node = &_sentenceConcept;

	if (!node && !node)
		return false;
	if (val1 && !is18(val1, node))
		return false;
	if (!str.empty() && !fn2(0, str, node))
		return false;
	if (wordId1 && !fn4(1, wordId1, node))
		return false;
	if (!str1.empty() && !fn2(2, str1, node))
		return false;
	if (!str2.empty() && !fn2(3, str2, node))
		return false;
	if (!str3.empty() && !fn2(4, str3, node))
		return false;
	if (wordId2 && !fn4(5, wordId2, node))
		return false;
	if (val2 && !is1C(val2, node))
		return false;

	return true;
}
Example #2
0
	bool DecryptChannel(const CString & sChan, CString & sBuffer)
	{
		CString sChannel = GetPath(sChan);
		CString sFile;
		sBuffer = "";

		CFile File(sChannel);

		if (sChannel.empty() || !File.Open() || !File.ReadFile(sFile))
			 return(true); // gonna be successful here

		File.Close();

		if (!sFile.empty())
		{
			CBlowfish c(m_sPassword, BF_DECRYPT);
			sBuffer = c.Crypt(sFile);

			if (sBuffer.Left(strlen(CRYPT_VERIFICATION_TOKEN)) != CRYPT_VERIFICATION_TOKEN)
			{
				// failed to decode :(
				PutModule("Unable to decode Encrypted file [" + sChannel + "]");
				return(false);
			}
			sBuffer.erase(0, strlen(CRYPT_VERIFICATION_TOKEN));
		}
		return(true);
	}
Example #3
0
bool CClient::OnPartMessage(CPartMessage& Message) {
    CString sChans = Message.GetTarget();

    VCString vsChans;
    sChans.Split(",", vsChans, false);
    sChans.clear();

    for (CString& sChan : vsChans) {
        bool bContinue = false;
        Message.SetTarget(sChan);
        NETWORKMODULECALL(OnUserPartMessage(Message), m_pUser, m_pNetwork, this,
                          &bContinue);
        if (bContinue) continue;

        sChan = Message.GetTarget();

        CChan* pChan = m_pNetwork ? m_pNetwork->FindChan(sChan) : nullptr;

        if (pChan && !pChan->IsOn()) {
            PutStatusNotice("Removing channel [" + sChan + "]");
            m_pNetwork->DelChan(sChan);
        } else {
            sChans += (sChans.empty()) ? sChan : CString("," + sChan);
        }
    }

    if (sChans.empty()) {
        return true;
    }

    Message.SetTarget(sChans);

    return false;
}
Example #4
0
bool CClient::OnOtherMessage(CMessage& Message) {
    const CString& sCommand = Message.GetCommand();

    if (sCommand.Equals("ZNC")) {
        CString sTarget = Message.GetParam(0);
        CString sModCommand;

        if (sTarget.TrimPrefix(m_pUser->GetStatusPrefix())) {
            sModCommand = Message.GetParams(1);
        } else {
            sTarget = "status";
            sModCommand = Message.GetParams(0);
        }

        if (sTarget.Equals("status")) {
            if (sModCommand.empty())
                PutStatus("Hello. How may I help you?");
            else
                UserCommand(sModCommand);
        } else {
            if (sModCommand.empty())
                CALLMOD(sTarget, this, m_pUser, m_pNetwork,
                        PutModule("Hello. How may I help you?"))
            else
                CALLMOD(sTarget, this, m_pUser, m_pNetwork,
                        OnModCommand(sModCommand))
        }
        return true;
    } else if (sCommand.Equals("ATTACH")) {
Example #5
0
    bool OnLoad(const CString& sArgs, CString& sMessage) override {
        CString sReasonArg;

        // Load AwayWait
        CString sFirstArg = sArgs.Token(0);
        if (sFirstArg.Equals("-notimer")) {
            SetAwayWait(0);
            sReasonArg = sArgs.Token(1, true);
        } else if (sFirstArg.Equals("-timer")) {
            SetAwayWait(sArgs.Token(1).ToUInt());
            sReasonArg = sArgs.Token(2, true);
        } else {
            CString sAwayWait = GetNV("awaywait");
            if (!sAwayWait.empty()) SetAwayWait(sAwayWait.ToUInt(), false);
            sReasonArg = sArgs;
        }

        // Load Reason
        if (!sReasonArg.empty()) {
            SetReason(sReasonArg);
        } else {
            CString sSavedReason = GetNV("reason");
            if (!sSavedReason.empty()) SetReason(sSavedReason, false);
        }

        // MinClients
        CString sMinClients = GetNV("minclients");
        if (!sMinClients.empty()) SetMinClients(sMinClients.ToUInt(), false);

        // Set away on load, required if loaded via webadmin
        if (GetNetwork()->IsIRCConnected() && MinClientsConnected())
            SetAway(false);

        return true;
    }
Example #6
0
File: User.cpp Project: johnfb/znc
bool CUser::SetStatusPrefix(const CString& s) {
	if ((!s.empty()) && (s.length() < 6) && (s.find(' ') == CString::npos)) {
		m_sStatusPrefix = (s.empty()) ? "*" : s;
		return true;
	}

	return false;
}
Example #7
0
void CIRCSock::ParseISupport(const CMessage& Message) {
    const VCString vsParams = Message.GetParams();

    for (size_t i = 1; i < vsParams.size() - 1; ++i) {
        const CString& sParam = vsParams[i];
        CString sName = sParam.Token(0, false, "=");
        CString sValue = sParam.Token(1, true, "=");

        if (0 < sName.length() && ':' == sName[0]) {
            break;
        }

        m_mISupport[sName] = sValue;

        if (sName.Equals("PREFIX")) {
            CString sPrefixes = sValue.Token(1, false, ")");
            CString sPermModes = sValue.Token(0, false, ")");
            sPermModes.TrimLeft("(");

            if (!sPrefixes.empty() && sPermModes.size() == sPrefixes.size()) {
                m_sPerms = sPrefixes;
                m_sPermModes = sPermModes;
            }
        } else if (sName.Equals("CHANTYPES")) {
            m_pNetwork->SetChanPrefixes(sValue);
        } else if (sName.Equals("NICKLEN")) {
            unsigned int uMax = sValue.ToUInt();

            if (uMax) {
                m_uMaxNickLen = uMax;
            }
        } else if (sName.Equals("CHANMODES")) {
            if (!sValue.empty()) {
                m_mueChanModes.clear();

                for (unsigned int a = 0; a < 4; a++) {
                    CString sModes = sValue.Token(a, false, ",");

                    for (unsigned int b = 0; b < sModes.size(); b++) {
                        m_mueChanModes[sModes[b]] = (EChanModeArgs) a;
                    }
                }
            }
        } else if (sName.Equals("NAMESX")) {
            if (m_bNamesx)
                continue;
            m_bNamesx = true;
            PutIRC("PROTOCTL NAMESX");
        } else if (sName.Equals("UHNAMES")) {
            if (m_bUHNames)
                continue;
            m_bUHNames = true;
            PutIRC("PROTOCTL UHNAMES");
        }
    }
}
Example #8
0
	VAttachIter FindEntry(const CString& sChan, const CString& sHost) {
		VAttachIter it = m_vMatches.begin();
		for (; it != m_vMatches.end(); ++it) {
			if (sHost.empty() || it->GetHostMask() != sHost)
				continue;
			if (sChan.empty() || it->GetChans() != sChan)
				continue;
			return it;
		}
		return m_vMatches.end();
	}
Example #9
0
CString CChan::GetModeForNames() const {
	CString sMode;

	for (map<unsigned char, CString>::const_iterator it = m_musModes.begin(); it != m_musModes.end(); ++it) {
		if (it->first == 's') {
			sMode = "@";
		} else if ((it->first == 'p') && sMode.empty()){
			sMode = "*";
		}
	}

	return (sMode.empty() ? "=" : sMode);
}
Example #10
0
CString CChan::GetOptions() const {
	CString sRet;

	if (IsDetached()) {
		sRet += (sRet.empty()) ? "Detached" : ", Detached";
	}

	if (AutoClearChanBuffer()) {
		sRet += (sRet.empty()) ? "AutoClearChanBuffer" : ", AutoClearChanBuffer";
	}

	return sRet;
}
Example #11
0
File: Chan.cpp Project: BtbN/znc
CString CChan::GetModeForNames() const {
    CString sMode;

    for (const auto& it : m_mcsModes) {
        if (it.first == 's') {
            sMode = "@";
        } else if ((it.first == 'p') && sMode.empty()) {
            sMode = "*";
        }
    }

    return (sMode.empty() ? "=" : sMode);
}
Example #12
0
bool CHTTPSock::SendCookie(const CString& sKey, const CString& sValue) {
    if (!sKey.empty() && !sValue.empty()) {
        if (m_msRequestCookies.find(sKey) == m_msRequestCookies.end() ||
            m_msRequestCookies[sKey].StrCmp(sValue) != 0) {
            // only queue a Set-Cookie to be sent if the client didn't send a
            // Cookie header of the same name+value.
            m_msResponseCookies[sKey] = sValue;
        }
        return true;
    }

    return false;
}
Example #13
0
	virtual void OnModCommand(const CString& sCommand) {
		CString sCmd = sCommand.Token(0);

		if (sCmd.Equals("DELKEY")) {
			CString sTarget = sCommand.Token(1);

			if (!sTarget.empty()) {
				if (DelNV(sTarget.AsLower())) {
					PutModule("Target [" + sTarget + "] deleted");
				} else {
					PutModule("Target [" + sTarget + "] not found");
				}
			} else {
				PutModule("Usage DelKey <#chan|Nick>");
			}
		} else if (sCmd.Equals("SETKEY")) {
			CString sTarget = sCommand.Token(1);
			CString sKey = sCommand.Token(2, true);

			// Strip "cbc:" from beginning of string incase someone pastes directly from mircryption
			sKey.TrimPrefix("cbc:");

			if (!sKey.empty()) {
				SetNV(sTarget.AsLower(), sKey);
				PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]");
			} else {
				PutModule("Usage: SetKey <#chan|Nick> <Key>");
			}
		} else if (sCmd.Equals("LISTKEYS")) {
			if (BeginNV() == EndNV()) {
				PutModule("You have no encryption keys set.");
			} else {
				CTable Table;
				Table.AddColumn("Target");
				Table.AddColumn("Key");

				for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) {
					Table.AddRow();
					Table.SetCell("Target", it->first);
					Table.SetCell("Key", it->second);
				}

				PutModule(Table);
			}
		} else if (sCmd.Equals("HELP")) {
			PutModule("Try: SetKey, DelKey, ListKeys");
		} else {
			PutModule("Unknown command, try 'Help'");
		}
	}
Example #14
0
bool CIRCNetwork::DelServer(const CString& sName, unsigned short uPort,
                            const CString& sPass) {
    if (sName.empty()) {
        return false;
    }

    unsigned int a = 0;
    bool bSawCurrentServer = false;
    CServer* pCurServer = GetCurrentServer();

    for (vector<CServer*>::iterator it = m_vServers.begin();
         it != m_vServers.end(); ++it, a++) {
        CServer* pServer = *it;

        if (pServer == pCurServer) bSawCurrentServer = true;

        if (!pServer->GetName().Equals(sName)) continue;

        if (uPort != 0 && pServer->GetPort() != uPort) continue;

        if (!sPass.empty() && pServer->GetPass() != sPass) continue;

        m_vServers.erase(it);

        if (pServer == pCurServer) {
            CIRCSock* pIRCSock = GetIRCSock();

            // Make sure we don't skip the next server in the list!
            if (m_uServerIdx) {
                m_uServerIdx--;
            }

            if (pIRCSock) {
                pIRCSock->Quit();
                PutStatus("Your current server was removed, jumping...");
            }
        } else if (!bSawCurrentServer) {
            // Our current server comes after the server which we
            // are removing. This means that it now got a different
            // index in m_vServers!
            m_uServerIdx--;
        }

        delete pServer;

        return true;
    }

    return false;
}
Example #15
0
void CClient::PutModNotice(const CString& sModule, const CString& sLine) {
    if (!m_pUser) {
        return;
    }

    DEBUG("(" << GetFullName()
              << ") ZNC -> CLI [:" + m_pUser->GetStatusPrefix() +
                     ((sModule.empty()) ? "status" : sModule) +
                     "!znc@znc.in NOTICE " << GetNick() << " :" << sLine
              << "]");
    Write(":" + m_pUser->GetStatusPrefix() +
          ((sModule.empty()) ? "status" : sModule) + "!znc@znc.in NOTICE " +
          GetNick() + " :" + sLine + "\r\n");
}
Example #16
0
bool CDir::MakeDir(const CString& sPath, mode_t iMode) {
#ifdef _WIN32
	if (sPath.empty())
		return false;

	CString sFixedPath = sPath;
	sFixedPath.Replace("/", "\\");

	int iResult = SHCreateDirectoryEx(0, sFixedPath.c_str(), NULL);

	return (iResult == ERROR_SUCCESS || iResult == ERROR_FILE_EXISTS || iResult == ERROR_ALREADY_EXISTS);
#else
	CString sDir;
	VCString dirs;
	VCString::iterator it;

	// Just in case someone tries this...
	if (sPath.empty())
		return false;

	// If this is an absolute path, we need to handle this now!
	if (sPath.Left(1) == "/")
		sDir = "/";

	// For every single subpath, do...
	sPath.Split("/", dirs, false);
	for (it = dirs.begin(); it != dirs.end(); ++it) {
		// Add this to the path we already created
		sDir += *it;

		int i = mkdir(sDir.c_str(), iMode);

		if (i != 0) {
			// All errors except EEXIST are fatal
			if (errno != EEXIST)
				return false;

			// If it's EEXIST we have to make sure it's a dir
			if (!CFile::IsDir(sDir))
				return false;
		}

		sDir += "/";
	}

	// All went well
	return true;
#endif
}
Example #17
0
void CServer::VerifyTlsSettings(CAdminSocket *pAdminSocket)
{
	bool enableSsl = m_pOptions->GetOptionVal(OPTION_ENABLETLS) != 0;
	if (!enableSsl) {
		ShowStatus(_T("Warning: FTP over TLS is not enabled, users cannot securely log in."), 1, pAdminSocket);
	}
	else {
		if (m_nServerState & STATE_ONLINE) {
			bool allowExplicit = m_pOptions->GetOptionVal(OPTION_ALLOWEXPLICITTLS) != 0;
			bool hasExplicit = false;
			for (auto const& s : m_ListenSocketList) {
				if (!s->ImplicitTLS()) {
					hasExplicit = true;
				}
			}
			if (!allowExplicit || !hasExplicit) {
				ShowStatus(_T("Warning: Explicit FTP over TLS is not enabled or there is no FTP listen socket configured."), 1, pAdminSocket);
			}
		}

		CAsyncSslSocketLayer layer(0);
		CString error;

		CString cert = m_pOptions->GetOption(OPTION_TLSCERTFILE);
		CString key = m_pOptions->GetOption(OPTION_TLSKEYFILE);
		CString pass = m_pOptions->GetOption(OPTION_TLSKEYPASS);

		int res = layer.SetCertKeyFile(cert, key, pass, &error, true);
		if (error.empty()) {
			if (res == SSL_FAILURE_LOADDLLS) {
				error = _T("Failed to load TLS libraries");
			}
			else if (res == SSL_FAILURE_INITSSL) {
				error = _T("Failed to initialize TLS libraries");
			}
			else if (res == SSL_FAILURE_VERIFYCERT) {
				error = _T("Failed to set certificate and private key");
			}
			else if (res) {
				error = _T("Unknown error loading TLS certificate and private key");
			}
		}

		if (!error.empty()) {
			ShowStatus(error, 1, pAdminSocket);
		}
	}
}
Example #18
0
    bool OnWebRequest(CWebSock& WebSock, const CString& sPageName,
                      CTemplate& Tmpl) override {
        if (sPageName != "index") {
            // only accept requests to index
            return false;
        }

        if (WebSock.IsPost()) {
            SetNV("username", WebSock.GetParam("username"));
            CString sPassword = WebSock.GetParam("password");
            if (!sPassword.empty()) {
                SetNV("password", sPassword);
            }
            SetNV(NV_REQUIRE_AUTH, WebSock.GetParam("require_auth"));
            SetNV(NV_MECHANISMS, WebSock.GetParam("mechanisms"));
        }

        Tmpl["Username"] = GetNV("username");
        Tmpl["Password"] = GetNV("password");
        Tmpl["RequireAuth"] = GetNV(NV_REQUIRE_AUTH);
        Tmpl["Mechanisms"] = GetMechanismsString();

        for (const auto& it : SupportedMechanisms) {
            CTemplate& Row = Tmpl.AddRow("MechanismLoop");
            CString sName(it.szName);
            Row["Name"] = sName;
            Row["Description"] = CString(it.szDescription);
        }

        return true;
    }
Example #19
0
void ActiveAttackList::Refresh()
{
	CString s;

	const AttackArray& attacks = GAMESTATE->m_ActiveAttacks[m_PlayerNumber];	// NUM_INVENTORY_SLOTS
	
	// clear all lines, then add all active attacks
	for( unsigned i=0; i<attacks.size(); i++ )
	{
		if( !attacks[i].bOn )
			continue; /* hasn't started yet */

		CStringArray asMods;
		split( attacks[i].sModifier, ",", asMods );
		for( unsigned j=0; j<asMods.size(); j++ )
		{
			CString& sMod = asMods[j];
			TrimLeft( sMod );
			TrimRight( sMod );

			sMod = PlayerOptions::ThemeMod( sMod );

			if( s.empty() )
				s = sMod;
			else
				s = sMod + "\n" + s;
		}
	}

	this->SetText( s );	// BitmapText will not rebuild vertices if these strings are the same.
}
Example #20
0
    void Set(const CString& sLine) {
        if (sLine.Token(1).empty()) {
            CString sUsername = GetNV("username");
            CString sPassword = GetNV("password");

            PutModule("Username is currently " + (sUsername.empty() ? "not set" : "set to '" + sUsername + "'") +
                      ", a password was " + (sPassword.empty() ? "not " : "") + "supplied.");
            return;
        }

        SetNV("username", sLine.Token(1));
        SetNV("password", sLine.Token(2));

        PutModule("Username has been set to [" + GetNV("username") + "]");
        PutModule("Password has been set to [" + GetNV("password") + "]");
    }
Example #21
0
void CIRCSock::Disconnected() {
    IRCSOCKMODULECALL(OnIRCDisconnected(), NOTHING);

    DEBUG(GetSockName() << " == Disconnected()");
    if (!m_pNetwork->GetUser()->IsBeingDeleted() && m_pNetwork->GetIRCConnectEnabled() &&
            m_pNetwork->GetServers().size() != 0) {
        m_pNetwork->PutStatus("Disconnected from IRC. Reconnecting...");
    }
    m_pNetwork->ClearRawBuffer();
    m_pNetwork->ClearMotdBuffer();

    CString sPrefix = m_pNetwork->GetUser()->GetStatusPrefix();
    for (CChan* pChan : m_pNetwork->GetChans()) {
        if(pChan->IsOn()) {
            m_pNetwork->PutUser(":" + sPrefix + "status!znc@znc.in KICK " + pChan->GetName() + " " + GetNick()
                                + " :You have been disconnected from the IRC server");
        }
    }

    ResetChans();

    // send a "reset user modes" cmd to the client.
    // otherwise, on reconnect, it might think it still
    // had user modes that it actually doesn't have.
    CString sUserMode;
    for (unsigned char cMode : m_scUserModes) {
        sUserMode += cMode;
    }
    if (!sUserMode.empty()) {
        m_pNetwork->PutUser(":" + m_pNetwork->GetIRCNick().GetNickMask() + " MODE " + m_pNetwork->GetIRCNick().GetNick() + " :-" + sUserMode);
    }

    // also clear the user modes in our space:
    m_scUserModes.clear();
}
Example #22
0
	virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
		if (!sArgs.empty()) {
			SetReply(sArgs);
		}

		return true;
	}
Example #23
0
CString
CKeyMap::formatKey(KeyID key, KeyModifierMask mask)
{
	// initialize tables
	initKeyNameMaps();

	CString x;
	for (SInt32 i = 0; i < kKeyModifierNumBits; ++i) {
		KeyModifierMask mod = (1u << i);
		if ((mask & mod) != 0 && s_modifierToNameMap->count(mod) > 0) {
			x += s_modifierToNameMap->find(mod)->second;
			x += "+";
		}
	}
	if (key != kKeyNone) {
		if (s_keyToNameMap->count(key) > 0) {
			x += s_keyToNameMap->find(key)->second;
		}
		// XXX -- we're assuming ASCII here
		else if (key >= 33 && key < 127) {
			x += (char)key;
		}
		else {
			x += CStringUtil::print("\\u%04x", key);
		}
	}
	else if (!x.empty()) {
		// remove trailing '+'
		x.erase(x.size() - 1);
	}
	return x;
}
Example #24
0
bool
CKeyMap::parseKey(const CString& x, KeyID& key)
{
	// initialize tables
	initKeyNameMaps();

	// parse the key
	key = kKeyNone;
	if (s_nameToKeyMap->count(x) > 0) {
		key = s_nameToKeyMap->find(x)->second;
	}
	// XXX -- we're assuming ASCII encoding here
	else if (x.size() == 1) {
		if (!isgraph(x[0])) {
			// unknown key
			return false;
		}
		key = (KeyID)x[0];
	}
	else if (x.size() == 6 && x[0] == '\\' && x[1] == 'u') {
		// escaped unicode (\uXXXX where XXXX is a hex number)
		char* end;
		key = (KeyID)strtol(x.c_str() + 2, &end, 16);
		if (*end != '\0') {
			return false;
		}
	}
	else if (!x.empty()) {
		// unknown key
		return false;
	}

	return true;
}
Example #25
0
    bool AddNote(const CString& sKey, const CString& sNote) {
        if (sKey.empty()) {
            return false;
        }

        return SetNV(sKey, sNote);
    }
Example #26
0
bool CIRCNetwork::IsChan(const CString& sChan) const {
    if (sChan.empty()) return false;  // There is no way this is a chan
    if (GetChanPrefixes().empty())
        return true;  // We can't know, so we allow everything
    // Thanks to the above if (empty), we can do sChan[0]
    return GetChanPrefixes().find(sChan[0]) != CString::npos;
}
Example #27
0
	bool OnBoot() override
	{
		CDir saveDir(GetSavePath());
		for (CFile* pFile : saveDir) {
			CString sName;
			CString sBuffer;

			EBufferType eType = DecryptBuffer(pFile->GetLongName(), sBuffer, sName);
			switch (eType) {
			case InvalidBuffer:
				m_sPassword = "";
				CUtils::PrintError("[" + GetModName() + ".so] Failed to Decrypt [" + pFile->GetLongName() + "]");
				if (!sName.empty()) {
					PutUser(":***!znc@znc.in PRIVMSG " + sName + " :Failed to decrypt this buffer, did you change the encryption pass?");
				}
				break;
			case ChanBuffer:
				if (CChan *pChan = GetNetwork()->FindChan(sName)) {
					BootStrap(pChan, sBuffer);
				}
				break;
			case QueryBuffer:
				if (CQuery* pQuery = GetNetwork()->AddQuery(sName)) {
					BootStrap(pQuery, sBuffer);
				}
				break;
			default:
				break;
			}
		}
		return true;
	}
Example #28
0
File: User.cpp Project: johnfb/znc
bool CUser::AddAllowedHost(const CString& sHostMask) {
	if (sHostMask.empty() || m_ssAllowedHosts.find(sHostMask) != m_ssAllowedHosts.end()) {
		return false;
	}

	m_ssAllowedHosts.insert(sHostMask);
	return true;
}
Example #29
0
bool CClient::OnJoinMessage(CJoinMessage& Message) {
    CString sChans = Message.GetTarget();
    CString sKeys = Message.GetKey();

    VCString vsChans;
    sChans.Split(",", vsChans, false);
    sChans.clear();

    VCString vsKeys;
    sKeys.Split(",", vsKeys, true);
    sKeys.clear();

    for (unsigned int a = 0; a < vsChans.size(); a++) {
        Message.SetTarget(vsChans[a]);
        Message.SetKey((a < vsKeys.size()) ? vsKeys[a] : "");
        bool bContinue = false;
        NETWORKMODULECALL(OnUserJoinMessage(Message), m_pUser, m_pNetwork, this,
                          &bContinue);
        if (bContinue) continue;

        CString sChannel = Message.GetTarget();
        CString sKey = Message.GetKey();

        CChan* pChan = m_pNetwork ? m_pNetwork->FindChan(sChannel) : nullptr;
        if (pChan) {
            if (pChan->IsDetached())
                pChan->AttachUser(this);
            else
                pChan->JoinUser(sKey);
            continue;
        }

        if (!sChannel.empty()) {
            sChans += (sChans.empty()) ? sChannel : CString("," + sChannel);

            if (!vsKeys.empty()) {
                sKeys += (sKeys.empty()) ? sKey : CString("," + sKey);
            }
        }
    }

    Message.SetTarget(sChans);
    Message.SetKey(sKeys);

    return sChans.empty();
}
Example #30
0
File: Message.cpp Project: BtbN/znc
CString CMessage::ToString(unsigned int uFlags) const {
    CString sMessage;

    // <tags>
    if (!(uFlags & ExcludeTags) && !m_mssTags.empty()) {
        CString sTags;
        for (const auto& it : m_mssTags) {
            if (!sTags.empty()) {
                sTags += ";";
            }
            sTags += it.first;
            if (!it.second.empty())
                sTags += "=" + it.second.Escape_n(CString::EMSGTAG);
        }
        sMessage = "@" + sTags;
    }

    // <prefix>
    if (!(uFlags & ExcludePrefix)) {
        CString sPrefix = m_Nick.GetHostMask();
        if (!sPrefix.empty()) {
            if (!sMessage.empty()) {
                sMessage += " ";
            }
            sMessage += ":" + sPrefix;
        }
    }

    // <command>
    if (!m_sCommand.empty()) {
        if (!sMessage.empty()) {
            sMessage += " ";
        }
        sMessage += m_sCommand;
    }

    // <params>
    if (!m_vsParams.empty()) {
        if (!sMessage.empty()) {
            sMessage += " ";
        }
        sMessage += GetParamsColon(0);
    }

    return sMessage;
}