Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 197 lines (155 sloc) 4.547 kb
a09a7e7 Switch to the copyright headers the GPLv2 wants us to have
psychon authored
1 /*
73270ff @Un1matr1x Welcome in 2012
Un1matr1x authored
2 * Copyright (C) 2004-2012 See the AUTHORS file for details.
a09a7e7 Switch to the copyright headers the GPLv2 wants us to have
psychon authored
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
7 */
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
8
9 // @todo handle raw 433 (nick in use)
e354c24 Move ZNC headers into own directory.
Alexey Sokolov authored
10 #include <znc/IRCSock.h>
11 #include <znc/User.h>
12 #include <znc/IRCNetwork.h>
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
13
14 class CAwayNickMod;
15
16 class CAwayNickTimer : public CTimer {
17 public:
18 CAwayNickTimer(CAwayNickMod& Module);
19
20 private:
21 virtual void RunJob();
22
23 private:
99f1efc Some more fun with tabs
psychon authored
24 CAwayNickMod& m_Module;
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
25 };
26
27 class CBackNickTimer : public CTimer {
28 public:
29 CBackNickTimer(CModule& Module)
30 : CTimer(&Module, 3, 1, "BackNickTimer", "Set your nick back when you reattach"),
31 m_Module(Module) {}
32
33 private:
34 virtual void RunJob() {
0b1627c @kylef Make all the modules support networks
kylef authored
35 CIRCNetwork* pNetwork = m_Module.GetNetwork();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
36
0b1627c @kylef Make all the modules support networks
kylef authored
37 if (pNetwork->IsUserAttached() && pNetwork->IsIRCConnected()) {
cd1192e Honor per-network nick in awaynick and keepnick.
Alexey Sokolov authored
38 CString sConfNick = pNetwork->GetNick();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
39 m_Module.PutIRC("NICK " + sConfNick);
40 }
41 }
42
43 private:
99f1efc Some more fun with tabs
psychon authored
44 CModule& m_Module;
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
45 };
46
47 class CAwayNickMod : public CModule {
48 public:
49 MODCONSTRUCTOR(CAwayNickMod) {}
50
ee350ab Change second argument to module in OnLoad() from sErrorMsg to sMessage.
psychon authored
51 virtual bool OnLoad(const CString& sArgs, CString& sMessage) {
b0e84a0 Awaynick now saves its latest setting and restores it on reload
psychon authored
52 if (!sArgs.empty())
53 m_sFormat = sArgs;
54 else
55 m_sFormat = GetNV("nick");
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
56
57 if (m_sFormat.empty()) {
58 m_sFormat = "zz_%nick%";
59 }
60
b0e84a0 Awaynick now saves its latest setting and restores it on reload
psychon authored
61 SetNV("nick", m_sFormat);
62
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
63 return true;
64 }
65
66 virtual ~CAwayNickMod() {
67 }
68
69 void StartAwayNickTimer() {
70 RemTimer("AwayNickTimer");
d6525a8 Fixed awaynick so it doesnt evaluate the awaynick multiple times. Also f...
silverleo authored
71 if (FindTimer("BackNickTimer")) {
72 // Client disconnected before we got set back, so do nothing.
73 RemTimer("BackNickTimer");
74 return;
75 }
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
76 AddTimer(new CAwayNickTimer(*this));
77 }
78
79 void StartBackNickTimer() {
0b1627c @kylef Make all the modules support networks
kylef authored
80 CIRCSock* pIRCSock = m_pNetwork->GetIRCSock();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
81
82 if (pIRCSock) {
cd1192e Honor per-network nick in awaynick and keepnick.
Alexey Sokolov authored
83 CString sConfNick = m_pNetwork->GetNick();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
84
d6525a8 Fixed awaynick so it doesnt evaluate the awaynick multiple times. Also f...
silverleo authored
85 if (pIRCSock->GetNick().Equals(m_sAwayNick.Left(pIRCSock->GetNick().length()))) {
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
86 RemTimer("BackNickTimer");
87 AddTimer(new CBackNickTimer(*this));
88 }
89 }
90 }
91
e493c23 awaynick: Set awaynick on connect, not some time after that
psychon authored
92 virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick,
93 CString& sIdent, CString& sRealName) {
cd1192e Honor per-network nick in awaynick and keepnick.
Alexey Sokolov authored
94 if (m_pNetwork && !m_pNetwork->IsUserAttached()) {
d6525a8 Fixed awaynick so it doesnt evaluate the awaynick multiple times. Also f...
silverleo authored
95 m_sAwayNick = m_sFormat;
e493c23 awaynick: Set awaynick on connect, not some time after that
psychon authored
96
97 // ExpandString doesn't know our nick yet, so do it by hand.
d6525a8 Fixed awaynick so it doesnt evaluate the awaynick multiple times. Also f...
silverleo authored
98 m_sAwayNick.Replace("%nick%", sNick);
e493c23 awaynick: Set awaynick on connect, not some time after that
psychon authored
99
100 // We don't limit this to NICKLEN, because we dont know
101 // NICKLEN yet.
fa7ec78 @kylef Add CIRCNetwork::ExpandString
kylef authored
102 sNick = m_sAwayNick = m_pNetwork->ExpandString(m_sAwayNick);
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
103 }
e493c23 awaynick: Set awaynick on connect, not some time after that
psychon authored
104 return CONTINUE;
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
105 }
106
107 virtual void OnIRCDisconnected() {
108 RemTimer("AwayNickTimer");
109 RemTimer("BackNickTimer");
110 }
111
db21f88 Rename OnUserAttached and OnUserDetached and add OnClientConnect
psychon authored
112 virtual void OnClientLogin() {
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
113 StartBackNickTimer();
114 }
115
db21f88 Rename OnUserAttached and OnUserDetached and add OnClientConnect
psychon authored
116 virtual void OnClientDisconnect() {
cd1192e Honor per-network nick in awaynick and keepnick.
Alexey Sokolov authored
117 if (!m_pNetwork->IsUserAttached()) {
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
118 StartAwayNickTimer();
119 }
120 }
121
5237a24 Use CString::Equals() everywhere.
kroimon authored
122 virtual void OnModCommand(const CString& sLine) {
123 CString sCommand = sLine.Token(0);
124 if (sCommand.Equals("TIMERS")) {
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
125 ListTimers();
5237a24 Use CString::Equals() everywhere.
kroimon authored
126 }
127 else if (sCommand.Equals("SET")) {
128 CString sFormat = sLine.Token(1);
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
129
130 if (!sFormat.empty()) {
131 m_sFormat = sFormat;
b0e84a0 Awaynick now saves its latest setting and restores it on reload
psychon authored
132 SetNV("nick", m_sFormat);
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
133 }
134
cd1192e Honor per-network nick in awaynick and keepnick.
Alexey Sokolov authored
135 if (m_pNetwork) {
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
136 CString sExpanded = GetAwayNick();
137 CString sMsg = "AwayNick is set to [" + m_sFormat + "]";
138
139 if (m_sFormat != sExpanded) {
140 sMsg += " (" + sExpanded + ")";
141 }
142
143 PutModule(sMsg);
144 }
5237a24 Use CString::Equals() everywhere.
kroimon authored
145 } else if (sCommand.Equals("SHOW")) {
cd1192e Honor per-network nick in awaynick and keepnick.
Alexey Sokolov authored
146 if (m_pNetwork) {
0a62274 Committing patches from crox/psychon
prozacx authored
147 CString sExpanded = GetAwayNick();
148 CString sMsg = "AwayNick is set to [" + m_sFormat + "]";
149
150 if (m_sFormat != sExpanded) {
151 sMsg += " (" + sExpanded + ")";
152 }
153
154 PutModule(sMsg);
155 }
5237a24 Use CString::Equals() everywhere.
kroimon authored
156 } else if (sCommand.Equals("HELP")) {
0a62274 Committing patches from crox/psychon
prozacx authored
157 PutModule("Commands are: show, timers, set [awaynick]");
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
158 }
159 }
160
161 CString GetAwayNick() {
162 unsigned int uLen = 9;
0b1627c @kylef Make all the modules support networks
kylef authored
163 CIRCSock* pIRCSock = m_pNetwork->GetIRCSock();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
164
165 if (pIRCSock) {
0a62274 Committing patches from crox/psychon
prozacx authored
166 uLen = pIRCSock->GetMaxNickLen();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
167 }
168
fa7ec78 @kylef Add CIRCNetwork::ExpandString
kylef authored
169 m_sAwayNick = m_pNetwork->ExpandString(m_sFormat).Left(uLen);
d6525a8 Fixed awaynick so it doesnt evaluate the awaynick multiple times. Also f...
silverleo authored
170 return m_sAwayNick;
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
171 }
172
173 private:
99f1efc Some more fun with tabs
psychon authored
174 CString m_sFormat;
175 CString m_sAwayNick;
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
176 };
177
178 CAwayNickTimer::CAwayNickTimer(CAwayNickMod& Module)
179 : CTimer(&Module, 30, 1, "AwayNickTimer", "Set your nick while you're detached"),
180 m_Module(Module) {}
181
182 void CAwayNickTimer::RunJob() {
0b1627c @kylef Make all the modules support networks
kylef authored
183 CIRCNetwork* pNetwork = m_Module.GetNetwork();
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
184
0b1627c @kylef Make all the modules support networks
kylef authored
185 if (!pNetwork->IsUserAttached() && pNetwork->IsIRCConnected()) {
70aafde Moved awaynick functionality into modules/awaynick.cpp module
prozacx authored
186 m_Module.PutIRC("NICK " + m_Module.GetAwayNick());
187 }
188 }
189
2622167 Add link to wiki page from any nonextra module.
Alexey Sokolov authored
190 template<> void TModInfo<CAwayNickMod>(CModInfo& Info) {
191 Info.SetWikiPage("awaynick");
92ec938 @jakoch Added Webskin "znc-ation"
jakoch authored
192 Info.SetHasArgs(true);
193 Info.SetArgsHelpText("This will be your nickname while you are away. Examples: nick_off or zzz_nick.");
2622167 Add link to wiki page from any nonextra module.
Alexey Sokolov authored
194 }
195
0b1627c @kylef Make all the modules support networks
kylef authored
196 NETWORKMODULEDEFS(CAwayNickMod, "Change your nick while you are away")
Something went wrong with that request. Please try again.