void CUser::UserConnected(CClient* pClient) { if (!MultiClients()) { BounceAllClients(); } pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() + " :- Welcome to ZNC -"); m_vClients.push_back(pClient); }
CConfig CUser::ToConfig() { CConfig config; CConfig passConfig; CString sHash; switch (m_eHashType) { case HASH_NONE: sHash = "Plain"; break; case HASH_MD5: sHash = "MD5"; break; case HASH_SHA256: sHash = "SHA256"; break; } passConfig.AddKeyValuePair("Salt", m_sPassSalt); passConfig.AddKeyValuePair("Method", sHash); passConfig.AddKeyValuePair("Hash", GetPass()); config.AddSubConfig("Pass", "password", passConfig); config.AddKeyValuePair("Nick", GetNick()); config.AddKeyValuePair("AltNick", GetAltNick()); config.AddKeyValuePair("Ident", GetIdent()); config.AddKeyValuePair("RealName", GetRealName()); config.AddKeyValuePair("BindHost", GetBindHost()); config.AddKeyValuePair("DCCBindHost", GetDCCBindHost()); config.AddKeyValuePair("QuitMsg", GetQuitMsg()); if (CZNC::Get().GetStatusPrefix() != GetStatusPrefix()) config.AddKeyValuePair("StatusPrefix", GetStatusPrefix()); config.AddKeyValuePair("Skin", GetSkinName()); config.AddKeyValuePair("Language", GetLanguage()); config.AddKeyValuePair("ChanModes", GetDefaultChanModes()); config.AddKeyValuePair("Buffer", CString(GetBufferCount())); config.AddKeyValuePair("KeepBuffer", CString(KeepBuffer())); config.AddKeyValuePair("MultiClients", CString(MultiClients())); config.AddKeyValuePair("DenyLoadMod", CString(DenyLoadMod())); config.AddKeyValuePair("Admin", CString(IsAdmin())); config.AddKeyValuePair("DenySetBindHost", CString(DenySetBindHost())); config.AddKeyValuePair("TimestampFormat", GetTimestampFormat()); config.AddKeyValuePair("AppendTimestamp", CString(GetTimestampAppend())); config.AddKeyValuePair("PrependTimestamp", CString(GetTimestampPrepend())); config.AddKeyValuePair("TimezoneOffset", CString(m_fTimezoneOffset)); config.AddKeyValuePair("JoinTries", CString(m_uMaxJoinTries)); config.AddKeyValuePair("MaxJoins", CString(m_uMaxJoins)); config.AddKeyValuePair("IRCConnectEnabled", CString(GetIRCConnectEnabled())); // Allow Hosts if (!m_ssAllowedHosts.empty()) { for (set<CString>::iterator it = m_ssAllowedHosts.begin(); it != m_ssAllowedHosts.end(); ++it) { config.AddKeyValuePair("Allow", *it); } } // CTCP Replies if (!m_mssCTCPReplies.empty()) { for (MCString::const_iterator itb = m_mssCTCPReplies.begin(); itb != m_mssCTCPReplies.end(); ++itb) { config.AddKeyValuePair("CTCPReply", itb->first.AsUpper() + " " + itb->second); } } // Modules CModules& Mods = GetModules(); if (!Mods.empty()) { for (unsigned int a = 0; a < Mods.size(); a++) { CString sArgs = Mods[a]->GetArgs(); if (!sArgs.empty()) { sArgs = " " + sArgs; } config.AddKeyValuePair("LoadModule", Mods[a]->GetModName() + sArgs); } } // Networks for (unsigned int d = 0; d < m_vIRCNetworks.size(); d++) { CIRCNetwork *pNetwork = m_vIRCNetworks[d]; config.AddSubConfig("Network", pNetwork->GetName(), pNetwork->ToConfig()); } return config; }
bool CUser::WriteConfig(CFile& File) { File.Write("<User " + GetUserName().FirstLine() + ">\n"); if (m_eHashType != HASH_NONE) { CString sHash = "md5"; if (m_eHashType == HASH_SHA256) sHash = "sha256"; if (m_sPassSalt.empty()) { PrintLine(File, "Pass", sHash + "#" + GetPass()); } else { PrintLine(File, "Pass", sHash + "#" + GetPass() + "#" + m_sPassSalt + "#"); } } else { PrintLine(File, "Pass", "plain#" + GetPass()); } PrintLine(File, "Nick", GetNick()); PrintLine(File, "AltNick", GetAltNick()); PrintLine(File, "Ident", GetIdent()); PrintLine(File, "RealName", GetRealName()); PrintLine(File, "BindHost", GetBindHost()); PrintLine(File, "DCCBindHost", GetDCCBindHost()); PrintLine(File, "QuitMsg", GetQuitMsg()); if (CZNC::Get().GetStatusPrefix() != GetStatusPrefix()) PrintLine(File, "StatusPrefix", GetStatusPrefix()); PrintLine(File, "Skin", GetSkinName()); PrintLine(File, "ChanModes", GetDefaultChanModes()); PrintLine(File, "Buffer", CString(GetBufferCount())); PrintLine(File, "KeepBuffer", CString(KeepBuffer())); PrintLine(File, "MultiClients", CString(MultiClients())); PrintLine(File, "BounceDCCs", CString(BounceDCCs())); PrintLine(File, "DenyLoadMod", CString(DenyLoadMod())); PrintLine(File, "Admin", CString(IsAdmin())); PrintLine(File, "DenySetBindHost", CString(DenySetBindHost())); PrintLine(File, "DCCLookupMethod", CString((UseClientIP()) ? "client" : "default")); PrintLine(File, "TimestampFormat", GetTimestampFormat()); PrintLine(File, "AppendTimestamp", CString(GetTimestampAppend())); PrintLine(File, "PrependTimestamp", CString(GetTimestampPrepend())); PrintLine(File, "TimezoneOffset", CString(m_fTimezoneOffset)); PrintLine(File, "JoinTries", CString(m_uMaxJoinTries)); PrintLine(File, "MaxJoins", CString(m_uMaxJoins)); PrintLine(File, "IRCConnectEnabled", CString(GetIRCConnectEnabled())); File.Write("\n"); // Allow Hosts if (!m_ssAllowedHosts.empty()) { for (set<CString>::iterator it = m_ssAllowedHosts.begin(); it != m_ssAllowedHosts.end(); ++it) { PrintLine(File, "Allow", *it); } File.Write("\n"); } // CTCP Replies if (!m_mssCTCPReplies.empty()) { for (MCString::const_iterator itb = m_mssCTCPReplies.begin(); itb != m_mssCTCPReplies.end(); ++itb) { PrintLine(File, "CTCPReply", itb->first.AsUpper() + " " + itb->second); } File.Write("\n"); } // Modules CModules& Mods = GetModules(); if (!Mods.empty()) { for (unsigned int a = 0; a < Mods.size(); a++) { CString sArgs = Mods[a]->GetArgs(); if (!sArgs.empty()) { sArgs = " " + sArgs; } PrintLine(File, "LoadModule", Mods[a]->GetModName() + sArgs); } File.Write("\n"); } // Servers for (unsigned int b = 0; b < m_vServers.size(); b++) { PrintLine(File, "Server", m_vServers[b]->GetString()); } // Chans for (unsigned int c = 0; c < m_vChans.size(); c++) { CChan* pChan = m_vChans[c]; if (pChan->InConfig()) { File.Write("\n"); if (!pChan->WriteConfig(File)) { return false; } } } File.Write("</User>\n"); return true; }
void CUser::UserConnected(CClient* pClient) { if (!MultiClients()) { BounceAllClients(); } m_vClients.push_back(pClient); if (m_RawBuffer.IsEmpty()) { pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() + " :- Welcome to ZNC -"); } else { unsigned int uIdx = 0; CString sLine; while (m_RawBuffer.GetLine(GetIRCNick().GetNick(), sLine, uIdx++)) { pClient->PutClient(sLine); } // The assumption is that the client got this nick from the 001 reply pClient->SetNick(GetIRCNick().GetNick()); } // Send the cached MOTD unsigned int uIdx = 0; CString sLine; while (m_MotdBuffer.GetLine(GetIRCNick().GetNick(), sLine, uIdx++)) { pClient->PutClient(sLine); } if (GetIRCSock() != NULL) { CString sUserMode(""); const set<unsigned char>& scUserModes = GetIRCSock()->GetUserModes(); for (set<unsigned char>::const_iterator it = scUserModes.begin(); it != scUserModes.end(); ++it) { sUserMode += *it; } if (!sUserMode.empty()) { pClient->PutClient(":" + GetIRCNick().GetNickMask() + " MODE " + GetIRCNick().GetNick() + " :+" + sUserMode); } } if (m_bIRCAway) { // If they want to know their away reason they'll have to whois // themselves. At least we can tell them their away status... pClient->PutClient(":irc.znc.in 306 " + GetIRCNick().GetNick() + " :You have been marked as being away"); } const vector<CChan*>& vChans = GetChans(); for (unsigned int a = 0; a < vChans.size(); a++) { if ((vChans[a]->IsOn()) && (!vChans[a]->IsDetached())) { vChans[a]->JoinUser(true, "", pClient); } } CString sBufLine; while (m_QueryBuffer.GetNextLine(GetIRCNick().GetNick(), sBufLine)) { MODULECALL(OnPrivBufferPlayLine(*pClient, sBufLine), this, NULL, continue); pClient->PutClient(sBufLine); } // Tell them why they won't connect if (!GetIRCConnectEnabled()) pClient->PutStatus("You are currently disconnected from IRC. " "Use 'connect' to reconnect."); }