Added MOTD support

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@571 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-10-13 05:31:42 +00:00
parent a2b647c5cd
commit d2e7285070
5 changed files with 87 additions and 9 deletions
+52 -5
View File
@@ -579,6 +579,33 @@ void CUserSock::UserCommand(const CString& sLine) {
}
} else if (sCommand.CaseCmp("VERSION") == 0) {
PutStatus(CZNC::GetTag());
} else if (sCommand.CaseCmp("MOTD") == 0) {
if (!SendMotd()) {
PutStatus("There is no MOTD set.");
}
} else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SaveConfig") == 0) {
CZNC::Get().WriteConfig();
} else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SetMOTD") == 0) {
CString sMessage = sLine.Token(1, true);
if (sMessage.empty()) {
PutStatus("Usage: SetMOTD <Message>");
} else {
CZNC::Get().SetMotd(sMessage);
PutStatus("MOTD set to [" + sMessage + "]");
}
} else if (m_pUser->IsAdmin() && sCommand.CaseCmp("AddMOTD") == 0) {
CString sMessage = sLine.Token(1, true);
if (sMessage.empty()) {
PutStatus("Usage: AddMOTD <Message>");
} else {
CZNC::Get().AddMotd(sMessage);
PutStatus("Added [" + sMessage + "] to MOTD");
}
} else if (m_pUser->IsAdmin() && sCommand.CaseCmp("ClearMOTD") == 0) {
CZNC::Get().ClearMotd();
PutStatus("Cleared MOTD");
} else if (m_pUser->IsAdmin() && sCommand.CaseCmp("BROADCAST") == 0) {
CZNC::Get().Broadcast(sLine.Token(1, true));
} else if (m_pUser->IsAdmin() && sCommand.CaseCmp("SHUTDOWN") == 0) {
@@ -995,6 +1022,20 @@ void CUserSock::UserCommand(const CString& sLine) {
}
}
bool CUserSock::SendMotd() {
const VCString& vsMotd = CZNC::Get().GetMotd();
if (!vsMotd.size()) {
return false;
}
for (unsigned int a = 0; a < vsMotd.size(); a++) {
PutStatusNotice(vsMotd[a]);
}
return true;
}
void CUserSock::HelpUser() {
CTable Table;
Table.AddColumn("Command");
@@ -1017,14 +1058,18 @@ void CUserSock::HelpUser() {
if (m_pUser) {
if (!m_pUser->DenyLoadMod()) {
Table.AddRow(); Table.SetCell("Command", "LoadMod"); Table.SetCell("Arguments", "<module>"); Table.SetCell("Description", "Load a module");
Table.AddRow(); Table.SetCell("Command", "UnloadMod"); Table.SetCell("Arguments", "<module>"); Table.SetCell("Description", "Unload a module");
Table.AddRow(); Table.SetCell("Command", "ReloadMod"); Table.SetCell("Arguments", "<module>"); Table.SetCell("Description", "Reload a module");
Table.AddRow(); Table.SetCell("Command", "LoadMod"); Table.SetCell("Arguments", "<module>"); Table.SetCell("Description", "Load a module");
Table.AddRow(); Table.SetCell("Command", "UnloadMod"); Table.SetCell("Arguments", "<module>"); Table.SetCell("Description", "Unload a module");
Table.AddRow(); Table.SetCell("Command", "ReloadMod"); Table.SetCell("Arguments", "<module>"); Table.SetCell("Description", "Reload a module");
}
if (m_pUser->IsAdmin()) {
Table.AddRow(); Table.SetCell("Command", "Broadcast"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Broadcast a message to all users");
Table.AddRow(); Table.SetCell("Command", "Shutdown"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Shutdown znc completely");
Table.AddRow(); Table.SetCell("Command", "SaveConfig"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Save the current settings to disk");
Table.AddRow(); Table.SetCell("Command", "SetMOTD"); Table.SetCell("Arguments", "<Message>"); Table.SetCell("Description", "Set the message of the day");
Table.AddRow(); Table.SetCell("Command", "AddMOTD"); Table.SetCell("Arguments", "<Message>"); Table.SetCell("Description", "Append <Message> to MOTD");
Table.AddRow(); Table.SetCell("Command", "ClearMOTD"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Clear the MOTD");
Table.AddRow(); Table.SetCell("Command", "Broadcast"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Broadcast a message to all users");
Table.AddRow(); Table.SetCell("Command", "Shutdown"); Table.SetCell("Arguments", "[message]"); Table.SetCell("Description", "Shutdown znc completely");
}
}
@@ -1073,6 +1118,8 @@ void CUserSock::AuthUser() {
m_pUser->UserConnected(this);
}
SendMotd();
CZNC::Get().GetModules().SetUserSock(this);
VOIDMODULECALL(OnUserAttached());
CZNC::Get().GetModules().SetUserSock(NULL);
+1
View File
@@ -49,6 +49,7 @@ public:
void PutModNotice(const CString& sModule, const CString& sLine);
virtual void ReadLine(const CString& sData);
bool SendMotd();
void HelpUser();
void AuthUser();
virtual void Connected();
+18 -4
View File
@@ -402,13 +402,18 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
if (!GetParam("submitted").ToUInt()) {
sPageRet = Header("Settings");
CString sVHosts;
CString sVHosts, sMotd;
const VCString& vsVHosts = CZNC::Get().GetVHosts();
for (unsigned int a = 0; a < vsVHosts.size(); a++) {
sVHosts += vsVHosts[a] + "\r\n";
}
const VCString& vsMotd = CZNC::Get().GetMotd();
for (unsigned int b = 0; b < vsMotd.size(); b++) {
sMotd += vsMotd[b] + "\r\n";
}
sPageRet += "<br><form action='/settings' method='POST'>\r\n"
"<input type='hidden' name='submitted' value='1'>\r\n"
"<div style='white-space: nowrap; margin-top: -8px; margin-right: 8px; margin-left: 8px; padding: 1px 5px 1px 5px; float: left; border: 1px solid #000; font-size: 16px; font-weight: bold; background: #ff9;'>Global Settings</div><div style='padding: 25px 5px 5px 15px; border: 2px solid #000; background: #cc9;'><div style='clear: both;'>\r\n"
@@ -421,6 +426,9 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
"<div><small><b>ISpoofFormat:</b></small><br>\r\n"
"<input type='text' name='ispoofformat' value='" + CZNC::Get().GetISpoofFormat().Escape_n(CString::EHTML) + "' size='32' maxlength='128'></div>\r\n"
"<br><div><small><b>MOTD:</b></small><br>\r\n"
"<textarea name='motd' cols='80' rows='5'>" + sMotd.Escape_n(CString::EHTML) + "</textarea></div>\r\n"
"<br><div><small><b>VHosts:</b></small><br>\r\n"
"<textarea name='vhosts' cols='40' rows='5'>" + sVHosts.Escape_n(CString::EHTML) + "</textarea></div>\r\n"
@@ -443,7 +451,6 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
}
sPageRet += "</table><br></div></div><br><br>\r\n"
"<br></div></div><br><br>\r\n"
"<input type='submit' value='Submit'>\r\n"
"</form>\r\n";
@@ -457,10 +464,17 @@ bool CWebAdminSock::SettingsPage(CString& sPageRet) {
sArg = GetParam("ispoofformat"); CZNC::Get().SetISpoofFormat(sArg);
//sArg = GetParam(""); if (!sArg.empty()) { CZNC::Get().Set(sArg); }
VCString vsArgs = GetParam("vhosts").Split("\n");
CZNC::Get().ClearVHosts();
VCString vsArgs = GetParam("motd").Split("\n");
CZNC::Get().ClearMotd();
unsigned int a = 0;
for (a = 0; a < vsArgs.size(); a++) {
CZNC::Get().AddMotd(vsArgs[a].TrimRight_n());
}
vsArgs = GetParam("vhosts").Split("\n");
CZNC::Get().ClearVHosts();
for (a = 0; a < vsArgs.size(); a++) {
CZNC::Get().AddVHost(vsArgs[a].Trim_n());
}
+8
View File
@@ -347,6 +347,10 @@ bool CZNC::WriteConfig() {
if (!m_sPidFile.empty()) { File.Write("PidFile = " + m_sPidFile + "\r\n"); }
if (!m_sStatusPrefix.empty()) { File.Write("StatusPrefix = " + m_sStatusPrefix + "\r\n"); }
for (unsigned int m = 0; m < m_vsMotd.size(); m++) {
File.Write("Motd = " + m_vsMotd[m] + "\r\n");
}
for (unsigned int v = 0; v < m_vsVHosts.size(); v++) {
File.Write("VHost = " + m_vsVHosts[v] + "\r\n");
}
@@ -492,6 +496,7 @@ bool CZNC::WriteNewConfig(const CString& sConfig) {
CUtils::GetInput("Ident", sAnswer, sNick); vsLines.push_back("\tIdent = " + sAnswer);
CUtils::GetInput("Real Name", sAnswer, "Got ZNC?"); vsLines.push_back("\tRealName = " + sAnswer);
CUtils::GetInput("VHost", sAnswer, "", "optional"); if (!sAnswer.empty()) { vsLines.push_back("\tVHost = " + sAnswer); }
// todo: Possibly add motd
if (CUtils::GetBoolInput("Would you like ZNC to keep trying for your primary nick?", true)) {
vsLines.push_back("\tKeepNick = true");
@@ -1008,6 +1013,9 @@ bool CZNC::ParseConfig(const CString& sConfig) {
} else if (sName.CaseCmp("ISpoofFile") == 0) {
m_sISpoofFile = sValue;
continue;
} else if (sName.CaseCmp("MOTD") == 0) {
AddMotd(sValue);
continue;
} else if (sName.CaseCmp("VHost") == 0) {
AddVHost(sValue);
continue;
+8
View File
@@ -85,6 +85,13 @@ public:
bool AddUser(CUser* pUser);
const map<CString,CUser*> & GetUserMap() const { return( m_msUsers ); }
// Message of the Day
void SetMotd(const CString& sMessage) { ClearMotd(); AddMotd(sMessage); }
void AddMotd(const CString& sMessage) { if (!sMessage.empty()) { m_vsMotd.push_back(sMessage); } }
void ClearMotd() { m_vsMotd.clear(); }
const VCString& GetMotd() const { return m_vsMotd; }
// !MOTD
private:
protected:
unsigned short m_uListenPort;
@@ -107,6 +114,7 @@ protected:
CString m_sISpoofFormat;
CString m_sPidFile;
VCString m_vsVHosts;
VCString m_vsMotd;
CLockFile m_LockFile;
bool m_bISpoofLocked;
bool m_bSSL;