https://wiki.znc.in/index.php?title=Online/code&feed=atom&action=history
Online/code - Revision history
2024-03-29T08:00:49Z
Revision history for this page on the wiki
MediaWiki 1.42.0-alpha
https://wiki.znc.in/index.php?title=Online/code&diff=893&oldid=prev
KindOne: Add category
2013-07-23T20:09:28Z
<p>Add category</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 20:09, 23 July 2013</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l179">Line 179:</td>
<td colspan="2" class="diff-lineno">Line 179:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>};</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>};</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>GLOBALMODULEDEFS(COnlineMod, "Creates a channel which shows all users that are currently connected to znc. (Optional: channel name as the argument)")</pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>GLOBALMODULEDEFS(COnlineMod, "Creates a channel which shows all users that are currently connected to znc. (Optional: channel name as the argument)")</pre></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Modules/Code]]</ins></div></td></tr>
</table>
KindOne
https://wiki.znc.in/index.php?title=Online/code&diff=892&oldid=prev
>Resistance: Restored code from internet-cached version, to which a link was provided in the IRC channel #znc @ irc.freenode.net
2012-01-05T18:24:21Z
<p>Restored code from internet-cached version, to which a link was provided in the IRC channel #znc @ irc.freenode.net</p>
<p><b>New page</b></p><div><pre>/*<br />
<br />
Creates a channel which shows all users that are currently connected to znc.<br />
(even if they leave this channel)<br />
<br />
With Partyline active you can send messages to users.<br />
<br />
Nobody can post to that channel, it's only for information.<br />
<br />
<br />
<br />
Based on: Partyline<br />
<br />
Coded by: ALeX Kazik<br />
<br />
*/<br />
<br />
#include "User.h"<br />
#include "znc.h"<br />
<br />
#define DEFAULT_CHAN_NAME "#*online"<br />
<br />
class COnlineMod : public CGlobalModule {<br />
public:<br />
GLOBALMODCONSTRUCTOR(COnlineMod) <br />
{<br />
}<br />
<br />
virtual bool OnLoad(const CString& sArgs, CString& sMessage) {<br />
m_sChanName = sArgs;<br />
if(m_sChanName.empty()){<br />
m_sChanName = DEFAULT_CHAN_NAME;<br />
}<br />
return true;<br />
}<br />
<br />
virtual void OnClientLogin() {<br />
m_ssNicksOnline.insert(m_pUser->GetUserName());<br />
<br />
const CString& sNick = m_pUser->GetUserName();<br />
<br />
CString sHost = m_pUser->GetBindHost();<br />
<br />
if (sHost.empty()) {<br />
sHost = m_pUser->GetIRCNick().GetHost();<br />
}<br />
<br />
// make that the user joins<br />
UserJoin();<br />
<br />
// put it into the list (even if not there)<br />
PutChan(":?" + sNick + "!" + m_pUser->GetIdent() + "@" + sHost + " JOIN " + m_sChanName, false);<br />
}<br />
<br />
virtual void OnClientDisconnect() {<br />
m_ssNicksOnline.erase(m_pUser->GetUserName());<br />
m_ssNicksInChan.erase(m_pUser->GetUserName());<br />
<br />
CString sHost = m_pUser->GetBindHost();<br />
<br />
if (sHost.empty()) {<br />
sHost = m_pUser->GetIRCNick().GetHost();<br />
}<br />
<br />
PutChan(":?" + m_pUser->GetUserName() + "!" + m_pUser->GetIdent() + "@" + sHost + " PART " + m_sChanName, false);<br />
}<br />
<br />
virtual EModRet OnUserRaw(CString& sLine) {<br />
CString sCommand = sLine.Token(0);<br />
CString sChannel = sLine.Token(1);<br />
<br />
if(!sChannel.Equals(m_sChanName)){<br />
return CONTINUE;<br />
}<br />
<br />
if (sCommand.Equals("WHO")) {<br />
// just drop<br />
} else if (sCommand.Equals("MODE")) {<br />
// just drop<br />
} else if (sCommand.Equals("TOPIC")) {<br />
CString sTopic = sLine.Token(2, true);<br />
<br />
sTopic.TrimPrefix(":");<br />
<br />
if (!sTopic.empty()) {<br />
m_pUser->PutUser(":irc.znc.in 482 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :You're not channel operator");<br />
} else {<br />
m_pUser->PutUser(":irc.znc.in 331 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :No topic is set.");<br />
}<br />
} else if (sCommand.Equals("PRIVMSG")) {<br />
m_pUser->PutUser(":irc.znc.in 401 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :No such nick/channel");<br />
} else if (sCommand.Equals("PART")) {<br />
if(m_ssNicksInChan.find(m_pUser->GetUserName()) != m_ssNicksInChan.end()){<br />
// user in list -> leave (only as seen by the user itself)<br />
m_ssNicksInChan.erase(m_pUser->GetUserName());<br />
<br />
m_pUser->PutUser(":" + m_pUser->GetIRCNick().GetNickMask() + " PART " + m_sChanName);<br />
}<br />
} else if (sCommand.Equals("JOIN")) {<br />
UserJoin();<br />
}else{<br />
m_pUser->PutUser(":irc.znc.in 401 " + m_pUser->GetIRCNick().GetNick() + " " + sChannel + " :No such nick/channel");<br />
}<br />
<br />
return HALT;<br />
}<br />
<br />
protected:<br />
void UserJoin(){<br />
if(m_ssNicksInChan.find(m_pUser->GetUserName()) == m_ssNicksInChan.end()){<br />
// user not in list -> join<br />
m_ssNicksInChan.insert(m_pUser->GetUserName());<br />
m_pUser->PutUser(":" + m_pUser->GetIRCNick().GetNickMask() + " JOIN " + m_sChanName);<br />
<br />
SendNickList(m_pUser, m_ssNicksOnline, m_sChanName);<br />
}<br />
}<br />
<br />
void PutChan(const CString& sLine, bool bIncludeCurUser = true, bool bIncludeClient = true) {<br />
const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();<br />
<br />
for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) {<br />
if (m_ssNicksInChan.find(it->first) != m_ssNicksInChan.end()) {<br />
if (it->second == m_pUser) {<br />
if (bIncludeCurUser) {<br />
it->second->PutUser(sLine, NULL, (bIncludeClient ? NULL : m_pClient));<br />
}<br />
} else {<br />
it->second->PutUser(sLine);<br />
}<br />
}<br />
}<br />
}<br />
<br />
const CString GetIRCServer(CUser *pUser) {<br />
const CString& sServer = pUser->GetIRCServer();<br />
<br />
if (!sServer.empty())<br />
return sServer;<br />
return "irc.znc.in";<br />
}<br />
<br />
void SendNickList(CUser* pUser, const set<CString>& ssNicks, const CString& sChan) {<br />
CString sNickList;<br />
<br />
for (set<CString>::const_iterator it = ssNicks.begin(); it != ssNicks.end(); it++) {<br />
sNickList += "?" + (*it) + " ";<br />
<br />
if (sNickList.size() >= 500) {<br />
PutUserIRCNick(pUser, ":" + GetIRCServer(pUser) + " 353 ", " @ " + sChan + " :" + sNickList);<br />
sNickList.clear();<br />
}<br />
}<br />
<br />
if (sNickList.size()) {<br />
PutUserIRCNick(pUser, ":" + GetIRCServer(pUser) + " 353 ", " @ " + sChan + " :" + sNickList);<br />
}<br />
<br />
PutUserIRCNick(pUser, ":" + GetIRCServer(pUser) + " 366 ", " " + sChan + " :End of /NAMES list.");<br />
}<br />
<br />
void PutUserIRCNick(CUser *pUser, const CString& sPre, const CString& sPost) {<br />
const CString& sIRCNick = pUser->GetIRCNick().GetNick();<br />
if (!sIRCNick.empty()) {<br />
pUser->PutUser(sPre + sIRCNick + sPost);<br />
return;<br />
}<br />
<br />
const vector<CClient*>& vClients = pUser->GetClients();<br />
vector<CClient*>::const_iterator it;<br />
for (it = vClients.begin(); it != vClients.end(); it++) {<br />
(*it)->PutClient(sPre + (*it)->GetNick() + sPost);<br />
}<br />
}<br />
<br />
set<CString> m_ssNicksOnline;<br />
set<CString> m_ssNicksInChan;<br />
CString m_sChanName;<br />
};<br />
GLOBALMODULEDEFS(COnlineMod, "Creates a channel which shows all users that are currently connected to znc. (Optional: channel name as the argument)")</pre></div>
>Resistance