mirror of
https://github.com/znc/znc.git
synced 2026-08-11 19:32:46 +02:00
Support having a nickname per network
This commit is contained in:
+101
@@ -178,11 +178,31 @@ CString CIRCNetwork::GetNetworkPath() {
|
||||
return sNetworkPath;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct TOption {
|
||||
const char *name;
|
||||
void (CIRCNetwork::*pSetter)(T);
|
||||
};
|
||||
|
||||
bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade) {
|
||||
VCString vsList;
|
||||
VCString::const_iterator vit;
|
||||
|
||||
if (!bUpgrade) {
|
||||
TOption<const CString&> StringOptions[] = {
|
||||
{ "nick", &CIRCNetwork::SetNick },
|
||||
{ "altnick", &CIRCNetwork::SetAltNick },
|
||||
{ "ident", &CIRCNetwork::SetIdent },
|
||||
{ "realname", &CIRCNetwork::SetRealName }
|
||||
};
|
||||
size_t numStringOptions = sizeof(StringOptions) / sizeof(StringOptions[0]);
|
||||
|
||||
for (size_t i = 0; i < numStringOptions; i++) {
|
||||
CString sValue;
|
||||
if (pConfig->FindStringEntry(StringOptions[i].name, sValue))
|
||||
(this->*StringOptions[i].pSetter)(sValue);
|
||||
}
|
||||
|
||||
pConfig->FindStringVector("loadmodule", vsList);
|
||||
for (vit = vsList.begin(); vit != vsList.end(); ++vit) {
|
||||
CString sValue = *vit;
|
||||
@@ -247,6 +267,22 @@ bool CIRCNetwork::ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade)
|
||||
CConfig CIRCNetwork::ToConfig() {
|
||||
CConfig config;
|
||||
|
||||
if (!m_sNick.empty()) {
|
||||
config.AddKeyValuePair("Nick", m_sNick);
|
||||
}
|
||||
|
||||
if (!m_sAltNick.empty()) {
|
||||
config.AddKeyValuePair("AltNick", m_sAltNick);
|
||||
}
|
||||
|
||||
if (!m_sIdent.empty()) {
|
||||
config.AddKeyValuePair("Ident", m_sIdent);
|
||||
}
|
||||
|
||||
if (!m_sRealName.empty()) {
|
||||
config.AddKeyValuePair("RealName", m_sRealName);
|
||||
}
|
||||
|
||||
// Modules
|
||||
CModules& Mods = GetModules();
|
||||
|
||||
@@ -795,3 +831,68 @@ bool CIRCNetwork::PutIRC(const CString& sLine) {
|
||||
pIRCSock->PutIRC(sLine);
|
||||
return true;
|
||||
}
|
||||
|
||||
const CString& CIRCNetwork::GetNick(const bool bAllowDefault) const {
|
||||
if (m_sNick.empty()) {
|
||||
return m_pUser->GetNick(bAllowDefault);
|
||||
}
|
||||
|
||||
return m_sNick;
|
||||
}
|
||||
|
||||
const CString& CIRCNetwork::GetAltNick(const bool bAllowDefault) const {
|
||||
if (m_sAltNick.empty()) {
|
||||
return m_pUser->GetAltNick(bAllowDefault);
|
||||
}
|
||||
|
||||
return m_sAltNick;
|
||||
}
|
||||
|
||||
const CString& CIRCNetwork::GetIdent(const bool bAllowDefault) const {
|
||||
if (m_sIdent.empty()) {
|
||||
return m_pUser->GetIdent(bAllowDefault);
|
||||
}
|
||||
|
||||
return m_sIdent;
|
||||
}
|
||||
|
||||
const CString& CIRCNetwork::GetRealName() const {
|
||||
if (m_sRealName.empty()) {
|
||||
return m_pUser->GetRealName();
|
||||
}
|
||||
|
||||
return m_sRealName;
|
||||
}
|
||||
|
||||
void CIRCNetwork::SetNick(const CString& s) {
|
||||
if (m_pUser->GetNick().Equals(s)) {
|
||||
m_sNick = "";
|
||||
} else {
|
||||
m_sNick = s;
|
||||
}
|
||||
}
|
||||
|
||||
void CIRCNetwork::SetAltNick(const CString& s) {
|
||||
if (m_pUser->GetAltNick().Equals(s)) {
|
||||
m_sAltNick = "";
|
||||
} else {
|
||||
m_sAltNick = s;
|
||||
}
|
||||
}
|
||||
|
||||
void CIRCNetwork::SetIdent(const CString& s) {
|
||||
if (m_pUser->GetIdent().Equals(s)) {
|
||||
m_sIdent = "";
|
||||
} else {
|
||||
m_sIdent = s;
|
||||
}
|
||||
}
|
||||
|
||||
void CIRCNetwork::SetRealName(const CString& s) {
|
||||
if (m_pUser->GetRealName().Equals(s)) {
|
||||
m_sRealName = "";
|
||||
} else {
|
||||
m_sRealName = s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,16 @@ public:
|
||||
void ClearQueryBuffer() { m_QueryBuffer.Clear(); }
|
||||
// !Buffers
|
||||
|
||||
// la
|
||||
const CString& GetNick(const bool bAllowDefault = true) const;
|
||||
const CString& GetAltNick(const bool bAllowDefault = true) const;
|
||||
const CString& GetIdent(const bool bAllowDefault = true) const;
|
||||
const CString& GetRealName() const;
|
||||
|
||||
void SetNick(const CString& s);
|
||||
void SetAltNick(const CString& s);
|
||||
void SetIdent(const CString& s);
|
||||
void SetRealName(const CString& s);
|
||||
private:
|
||||
bool JoinChan(CChan* pChan);
|
||||
void JoinChans(set<CChan*>& sChans);
|
||||
@@ -126,6 +136,11 @@ protected:
|
||||
CString m_sName;
|
||||
CUser* m_pUser;
|
||||
|
||||
CString m_sNick;
|
||||
CString m_sAltNick;
|
||||
CString m_sIdent;
|
||||
CString m_sRealName;
|
||||
|
||||
CModules* m_pModules;
|
||||
|
||||
vector<CClient*> m_vClients;
|
||||
|
||||
+6
-6
@@ -24,7 +24,7 @@ CIRCSock::CIRCSock(CIRCNetwork* pNetwork) : CZNCSock() {
|
||||
m_bNamesx = false;
|
||||
m_bUHNames = false;
|
||||
EnableReadLine();
|
||||
m_Nick.SetIdent(m_pNetwork->GetUser()->GetIdent());
|
||||
m_Nick.SetIdent(m_pNetwork->GetIdent());
|
||||
m_Nick.SetHost(m_pNetwork->GetUser()->GetBindHost());
|
||||
|
||||
m_uMaxNickLen = 9;
|
||||
@@ -904,9 +904,9 @@ void CIRCSock::Connected() {
|
||||
DEBUG(GetSockName() << " == Connected()");
|
||||
|
||||
CString sPass = m_sPass;
|
||||
CString sNick = m_pNetwork->GetUser()->GetNick();
|
||||
CString sIdent = m_pNetwork->GetUser()->GetIdent();
|
||||
CString sRealName = m_pNetwork->GetUser()->GetRealName();
|
||||
CString sNick = m_pNetwork->GetNick();
|
||||
CString sIdent = m_pNetwork->GetIdent();
|
||||
CString sRealName = m_pNetwork->GetRealName();
|
||||
|
||||
NETWORKMODULECALL(OnIRCRegistration(sPass, sNick, sIdent, sRealName), m_pNetwork->GetUser(), m_pNetwork, NULL, return);
|
||||
|
||||
@@ -1128,8 +1128,8 @@ void CIRCSock::SendAltNick(const CString& sBadNick) {
|
||||
|
||||
unsigned int uMax = m_uMaxNickLen;
|
||||
|
||||
const CString& sConfNick = m_pNetwork->GetUser()->GetNick();
|
||||
const CString& sAltNick = m_pNetwork->GetUser()->GetAltNick();
|
||||
const CString& sConfNick = m_pNetwork->GetNick();
|
||||
const CString& sAltNick = m_pNetwork->GetAltNick();
|
||||
CString sNewNick;
|
||||
|
||||
if (sLastNick.Equals(sConfNick)) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<? IF Edit ?><input type="hidden" name="network" value="<? VAR Name ?>" /><? ENDIF ?>
|
||||
|
||||
<h3>Network Info</h3>
|
||||
<span class="info">Nick, AltNick, Ident, RealName can be left empty to use the value from the user.</span>
|
||||
<div class="sectionbg">
|
||||
<div class="sectionbody">
|
||||
<? IF !Edit ?>
|
||||
@@ -19,6 +20,24 @@
|
||||
</div>
|
||||
<? ENDIF ?>
|
||||
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Nickname:</div>
|
||||
<div><input type="text" name="nick" value="<? VAR Nick ?>" class="half" maxlength="128" /></div>
|
||||
</div>
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Alt. Nickname:</div>
|
||||
<div><input type="text" name="altnick" value="<? VAR AltNick ?>" class="half" maxlength="128" /></div>
|
||||
</div>
|
||||
<div style="clear: both;"></div>
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Ident:</div>
|
||||
<div><input type="text" name="ident" value="<? VAR Ident ?>" class="half" maxlength="128" /></div>
|
||||
</div>
|
||||
<div class="subsection">
|
||||
<div class="inputlabel">Realname:</div>
|
||||
<div><input type="text" name="realname" value="<? VAR RealName ?>" class="full" maxlength="256" /></div>
|
||||
</div>
|
||||
|
||||
<div class="subsection half">
|
||||
<div class="inputlabel">Servers:</div>
|
||||
<div><textarea name="servers" cols="70" rows="5"><? LOOP ServerLoop ?><? VAR Server ?>
|
||||
|
||||
@@ -659,6 +659,11 @@ public:
|
||||
Tmpl["Title"] = "Edit Network" + CString(" [" + pNetwork->GetName() + "]");
|
||||
Tmpl["Name"] = pNetwork->GetName();
|
||||
|
||||
Tmpl["Nick"] = pNetwork->GetNick();
|
||||
Tmpl["AltNick"] = pNetwork->GetAltNick();
|
||||
Tmpl["Ident"] = pNetwork->GetIdent();
|
||||
Tmpl["RealName"] = pNetwork->GetRealName();
|
||||
|
||||
const vector<CServer*>& vServers = pNetwork->GetServers();
|
||||
for (unsigned int a = 0; a < vServers.size(); a++) {
|
||||
CTemplate& l = Tmpl.AddRow("ServerLoop");
|
||||
@@ -705,6 +710,28 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
CString sArg;
|
||||
|
||||
sArg = WebSock.GetParam("nick");
|
||||
if (!sArg.Equals(pUser->GetNick())) {
|
||||
pNetwork->SetNick(sArg);
|
||||
}
|
||||
|
||||
sArg = WebSock.GetParam("altnick");
|
||||
if (!sArg.Equals(pUser->GetAltNick())) {
|
||||
pNetwork->SetAltNick(sArg);
|
||||
}
|
||||
|
||||
sArg = WebSock.GetParam("ident");
|
||||
if (!sArg.Equals(pUser->GetIdent())) {
|
||||
pNetwork->SetIdent(sArg);
|
||||
}
|
||||
|
||||
sArg = WebSock.GetParam("realname");
|
||||
if (!sArg.Equals(pUser->GetRealName())) {
|
||||
pNetwork->SetRealName(sArg);
|
||||
}
|
||||
|
||||
VCString vsArgs;
|
||||
|
||||
WebSock.GetRawParam("servers").Split("\n", vsArgs);
|
||||
|
||||
Reference in New Issue
Block a user