From: <ps...@us...> - 2008-12-06 16:07:10
|
Revision: 1281 http://znc.svn.sourceforge.net/znc/?rev=1281&view=rev Author: psychon Date: 2008-12-06 16:07:00 +0000 (Sat, 06 Dec 2008) Log Message: ----------- Minor stylistic fixes for schat Modified Paths: -------------- trunk/modules/schat.cpp Modified: trunk/modules/schat.cpp =================================================================== --- trunk/modules/schat.cpp 2008-12-06 14:49:56 UTC (rev 1280) +++ trunk/modules/schat.cpp 2008-12-06 16:07:00 UTC (rev 1281) @@ -45,6 +45,7 @@ { m_pModule = pMod; } + CSChatSock(int itimeout = 60) : Csock(itimeout) { m_pModule = NULL; @@ -81,6 +82,7 @@ { m_pModule = p; } + void SetChatNick(const CString & sNick) { m_sChatNick = sNick; @@ -122,8 +124,7 @@ { m_sPemFile = sArgs; - if (m_sPemFile.empty()) - { + if (m_sPemFile.empty()) { m_sPemFile = CZNC::Get().GetPemLocation(); } @@ -138,10 +139,9 @@ virtual void OnClientLogin() { CString sName = "SCHAT::" + m_pUser->GetUserName(); - for (u_int a = 0; a < m_pManager->size(); a++) - { - if ((*m_pManager)[a]->GetSockName() != sName.c_str() || - ((*m_pManager)[a]->GetType() == CSChatSock::LISTENER)) + for (u_int a = 0; a < m_pManager->size(); a++) { + if ((*m_pManager)[a]->GetSockName() != sName || + (*m_pManager)[a]->GetType() == CSChatSock::LISTENER) continue; CSChatSock *p = (CSChatSock *)(*m_pManager)[a]; @@ -152,8 +152,7 @@ void CleanSocks() { CString sName = "SCHAT::" + m_pUser->GetUserName(); - for (u_int a= 0; a < m_pManager->size(); a++) - { + for (u_int a= 0; a < m_pManager->size(); a++) { if ((*m_pManager)[a]->GetSockName() == sName) m_pManager->DelSock(a--); } @@ -161,17 +160,14 @@ virtual EModRet OnUserRaw(CString & sLine) { - if (sLine.Equals("schat ", false, 6)) - { + if (sLine.Equals("schat ", false, 6)) { OnModCommand("chat " + sLine.substr(6)); return(HALT); - } else if (sLine.Equals("schat")) - { + } else if (sLine.Equals("schat")) { PutModule("SChat User Area ..."); OnModCommand("help"); return(HALT); - } return(CONTINUE); @@ -179,22 +175,18 @@ virtual void OnModCommand(const CString& sCommand) { - CString sCom, sArgs; + CString sCom = sCommand.Token(0); + CString sArgs = sCommand.Token(1, true); - sCom = sCommand.Token(0); - sArgs = sCommand.Token(1, true); - if (sCom.Equals("chat") && !sArgs.empty()) { CString sSockName = "SCHAT::" + m_pUser->GetUserName(); CString sNick = "(s)" + sArgs; - for (u_int a= 0; a < m_pManager->size(); a++) - { + for (u_int a= 0; a < m_pManager->size(); a++) { if ((*m_pManager)[a]->GetSockName() != sSockName) continue; CSChatSock *pSock = (CSChatSock *)(*m_pManager)[a]; - if (pSock->GetChatNick().Equals(sNick)) - { + if (pSock->GetChatNick().Equals(sNick)) { PutModule("Already Connected to [" + sArgs + "]"); return; } @@ -209,8 +201,7 @@ u_short iPort = m_pManager->ListenRand(sSockName, m_pUser->GetLocalIP(), true, SOMAXCONN, pSock, 60); - if (iPort == 0) - { + if (iPort == 0) { PutModule("Failed to start chat!"); return; } @@ -223,8 +214,7 @@ PutIRC(s.str()); - } else if (sCom.Equals("list")) - { + } else if (sCom.Equals("list")) { CString sName = "SCHAT::" + m_pUser->GetUserName(); CTable Table; Table.AddColumn("Nick"); @@ -233,8 +223,7 @@ Table.AddColumn("Port"); Table.AddColumn("Status"); Table.AddColumn("Cipher"); - for (u_int a= 0; a < m_pManager->size(); a++) - { + for (u_int a= 0; a < m_pManager->size(); a++) { if ((*m_pManager)[a]->GetSockName() != sName) continue; @@ -245,24 +234,21 @@ unsigned long long iStartTime = pSock->GetStartTime(); time_t iTime = iStartTime / 1000; char *pTime = ctime(&iTime); - if (pTime) - { + if (pTime) { CString sTime = pTime; sTime.Trim(); Table.SetCell("Created", sTime); } - if (pSock->GetType() != CSChatSock::LISTENER) - { + if (pSock->GetType() != CSChatSock::LISTENER) { Table.SetCell("Status", "Established"); Table.SetCell("Host", pSock->GetRemoteIP()); Table.SetCell("Port", CString(pSock->GetRemotePort())); SSL_SESSION *pSession = pSock->GetSSLSession(); - if ((pSession) && (pSession->cipher) && (pSession->cipher->name)) + if (pSession && pSession->cipher && pSession->cipher->name) Table.SetCell("Cipher", pSession->cipher->name); - } else - { + } else { Table.SetCell("Status", "Waiting"); Table.SetCell("Port", CString(pSock->GetLocalPort())); } @@ -272,11 +258,9 @@ } else PutModule("No SDCCs currently in session"); - } else if (sCom.Equals("close")) - { + } else if (sCom.Equals("close")) { CString sName = "SCHAT::" + m_pUser->GetUserName(); - for (u_int a = 0; a < m_pManager->size(); a++) - { + for (u_int a = 0; a < m_pManager->size(); a++) { if ((*m_pManager)[a]->GetSockName() != sName) continue; @@ -284,15 +268,13 @@ if (!sArgs.Equals("(s)", false, 3)) sArgs = "(s)" + sArgs; - if (sArgs.Equals(pSock->GetChatNick())) - { + if (sArgs.Equals(pSock->GetChatNick())) { pSock->Close(); return; } } PutModule("No Such Chat [" + sArgs + "]"); - } else if (sCom.Equals("showsocks") && m_pUser->IsAdmin()) - { + } else if (sCom.Equals("showsocks") && m_pUser->IsAdmin()) { CTable Table; Table.AddColumn("SockName"); Table.AddColumn("Created"); @@ -300,23 +282,20 @@ Table.AddColumn("RemoteIP:Port"); Table.AddColumn("Type"); Table.AddColumn("Cipher"); - for (u_int a = 0; a < m_pManager->size(); a++) - { + for (u_int a = 0; a < m_pManager->size(); a++) { Table.AddRow(); Csock *pSock = (*m_pManager)[a]; Table.SetCell("SockName", pSock->GetSockName()); unsigned long long iStartTime = pSock->GetStartTime(); time_t iTime = iStartTime / 1000; char *pTime = ctime(&iTime); - if (pTime) - { + if (pTime) { CString sTime = pTime; sTime.Trim(); Table.SetCell("Created", sTime); } - if (pSock->GetType() != Csock::LISTENER) - { + if (pSock->GetType() != Csock::LISTENER) { if (pSock->GetType() == Csock::OUTBOUND) Table.SetCell("Type", "Outbound"); else @@ -326,13 +305,12 @@ Table.SetCell("RemoteIP:Port", pSock->GetRemoteIP() + ":" + CString(pSock->GetRemotePort())); SSL_SESSION *pSession = pSock->GetSSLSession(); - if ((pSession) && (pSession->cipher) && (pSession->cipher->name)) + if (pSession && pSession->cipher && pSession->cipher->name) Table.SetCell("Cipher", pSession->cipher->name); else Table.SetCell("Cipher", "None"); - } else - { + } else { Table.SetCell("Type", "Listener"); Table.SetCell("LocalIP:Port", pSock->GetLocalIP() + ":" + CString(pSock->GetLocalPort())); @@ -344,9 +322,8 @@ else PutModule("Error Finding Sockets"); - } else if (sCom.Equals("help")) - { - PutModule("Commands are: "); + } else if (sCom.Equals("help")) { + PutModule("Commands are:"); PutModule(" help - This text."); PutModule(" chat <nick> - Chat a nick."); PutModule(" list - List current chats."); @@ -363,14 +340,12 @@ virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage) { - if (sMessage.Equals("DCC SCHAT ", false, 10)) - { + if (sMessage.Equals("DCC SCHAT ", false, 10)) { // chat ip port unsigned long iIP = sMessage.Token(3).ToULong(); unsigned short iPort = sMessage.Token(4).ToUShort(); - if ((iIP > 0) && (iPort > 0)) - { + if (iIP > 0 && iPort > 0) { pair<u_long, u_short> pTmp; CString sMask; @@ -402,19 +377,17 @@ m_pManager->Connect(CUtils::GetIP(iIP), iPort, sSockName, 60, true, m_pUser->GetLocalIP(), p); RemTimer("Remove " + sNick); // delete any associated timer to this nick } + virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { - if (sTarget.Left(3) == "(s)") - { + if (sTarget.Left(3) == "(s)") { CString sSockName = "SCHAT::" + m_pUser->GetUserName() + "::" + sTarget; CSChatSock *p = (CSChatSock *)m_pManager->FindSockByName(sSockName); - if (!p) - { + if (!p) { map< CString,pair< u_long,u_short > >::iterator it; it = m_siiWaitingChats.find(sTarget); - if (it != m_siiWaitingChats.end()) - { + if (it != m_siiWaitingChats.end()) { if (!sMessage.Equals("yes")) SendToUser(sTarget + "!" + sTarget + "@" + CUtils::GetIP(it->second.first), @@ -469,8 +442,7 @@ void CSChatSock::ReadLine(const CS_STRING & sLine) { - if (m_pModule) - { + if (m_pModule) { CString sText = sLine; if (sText[sText.length()-1] == '\n') sText.erase(sText.length()-1, 1); @@ -501,8 +473,7 @@ void CSChatSock::Timeout() { - if (m_pModule) - { + if (m_pModule) { if (GetType() == LISTENER) m_pModule->PutModule("Timeout while waiting for [" + m_sChatNick + "]"); else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |