1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>InspIRCd: channels.cpp Source File</title>
<link href="inspircd.doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.3 -->
<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div>
<h1>channels.cpp</h1><a href="channels_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/* +------------------------------------+</span>
00002 <span class="comment"> * | Inspire Internet Relay Chat Daemon |</span>
00003 <span class="comment"> * +------------------------------------+</span>
00004 <span class="comment"> *</span>
00005 <span class="comment"> * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.</span>
00006 <span class="comment"> * E-mail:</span>
00007 <span class="comment"> * <brain@chatspike.net></span>
00008 <span class="comment"> * <Craig@chatspike.net></span>
00009 <span class="comment"> * </span>
00010 <span class="comment"> * Written by Craig Edwards, Craig McLure, and others.</span>
00011 <span class="comment"> * This program is free but copyrighted software; see</span>
00012 <span class="comment"> * the file COPYING for details.</span>
00013 <span class="comment"> *</span>
00014 <span class="comment"> * ---------------------------------------------------</span>
00015 <span class="comment"> */</span>
00016
00017 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
00018
00019 <span class="preprocessor">#include "inspircd.h"</span>
00020 <span class="preprocessor">#include "inspircd_io.h"</span>
00021 <span class="preprocessor">#include "inspircd_util.h"</span>
00022 <span class="preprocessor">#include "inspircd_config.h"</span>
00023 <span class="preprocessor">#include <unistd.h></span>
00024 <span class="preprocessor">#include <sys/errno.h></span>
00025 <span class="preprocessor">#include <sys/ioctl.h></span>
00026 <span class="preprocessor">#include <sys/utsname.h></span>
00027 <span class="preprocessor">#include <time.h></span>
00028 <span class="preprocessor">#include <string></span>
00029 <span class="preprocessor">#ifdef GCC3</span>
00030 <span class="preprocessor"></span><span class="preprocessor">#include <ext/hash_map></span>
00031 <span class="preprocessor">#else</span>
00032 <span class="preprocessor"></span><span class="preprocessor">#include <hash_map></span>
00033 <span class="preprocessor">#endif</span>
00034 <span class="preprocessor"></span><span class="preprocessor">#include <map></span>
00035 <span class="preprocessor">#include <sstream></span>
00036 <span class="preprocessor">#include <vector></span>
00037 <span class="preprocessor">#include <deque></span>
00038 <span class="preprocessor">#include "<a class="code" href="connection_8h.html">connection.h</a>"</span>
00039 <span class="preprocessor">#include "<a class="code" href="users_8h.html">users.h</a>"</span>
00040 <span class="preprocessor">#include "<a class="code" href="servers_8h.html">servers.h</a>"</span>
00041 <span class="preprocessor">#include "<a class="code" href="ctables_8h.html">ctables.h</a>"</span>
00042 <span class="preprocessor">#include "globals.h"</span>
00043 <span class="preprocessor">#include "<a class="code" href="modules_8h.html">modules.h</a>"</span>
00044 <span class="preprocessor">#include "dynamic.h"</span>
00045 <span class="preprocessor">#include "wildcard.h"</span>
00046 <span class="preprocessor">#include "<a class="code" href="message_8h.html">message.h</a>"</span>
00047 <span class="preprocessor">#include "<a class="code" href="mode_8h.html">mode.h</a>"</span>
00048 <span class="preprocessor">#include "<a class="code" href="xline_8h.html">xline.h</a>"</span>
00049 <span class="preprocessor">#include "inspstring.h"</span>
00050 <span class="preprocessor">#include "helperfuncs.h"</span>
00051
00052 <span class="preprocessor">#ifdef GCC3</span>
00053 <span class="preprocessor"></span><span class="preprocessor">#define nspace __gnu_cxx</span>
00054 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00055"></a><a class="code" href="channels_8cpp.html#a0">00055</a> <span class="preprocessor"></span><span class="preprocessor">#define nspace std</span>
00056 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00057 <span class="preprocessor"></span>
00058 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="modules_8cpp.html#a1">MODCOUNT</a>;
<a name="l00059"></a><a class="code" href="channels_8cpp.html#a2">00059</a> <span class="keyword">extern</span> std::vector<Module*> <a class="code" href="channels_8cpp.html#a2">modules</a>;
<a name="l00060"></a><a class="code" href="channels_8cpp.html#a3">00060</a> <span class="keyword">extern</span> std::vector<ircd_module*> <a class="code" href="channels_8cpp.html#a3">factory</a>;
00061
<a name="l00062"></a><a class="code" href="channels_8cpp.html#a4">00062</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a4">LogLevel</a>;
<a name="l00063"></a><a class="code" href="channels_8cpp.html#a5">00063</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a5">ServerName</a>[MAXBUF];
<a name="l00064"></a><a class="code" href="channels_8cpp.html#a6">00064</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a6">Network</a>[MAXBUF];
<a name="l00065"></a><a class="code" href="channels_8cpp.html#a7">00065</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a7">ServerDesc</a>[MAXBUF];
<a name="l00066"></a><a class="code" href="channels_8cpp.html#a8">00066</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a8">AdminName</a>[MAXBUF];
<a name="l00067"></a><a class="code" href="channels_8cpp.html#a9">00067</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a9">AdminEmail</a>[MAXBUF];
<a name="l00068"></a><a class="code" href="channels_8cpp.html#a10">00068</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a10">AdminNick</a>[MAXBUF];
<a name="l00069"></a><a class="code" href="channels_8cpp.html#a11">00069</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a11">diepass</a>[MAXBUF];
<a name="l00070"></a><a class="code" href="channels_8cpp.html#a12">00070</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a12">restartpass</a>[MAXBUF];
<a name="l00071"></a><a class="code" href="channels_8cpp.html#a13">00071</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a13">motd</a>[MAXBUF];
<a name="l00072"></a><a class="code" href="channels_8cpp.html#a14">00072</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a14">rules</a>[MAXBUF];
<a name="l00073"></a><a class="code" href="channels_8cpp.html#a15">00073</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a15">list</a>[MAXBUF];
<a name="l00074"></a><a class="code" href="channels_8cpp.html#a16">00074</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a16">PrefixQuit</a>[MAXBUF];
<a name="l00075"></a><a class="code" href="channels_8cpp.html#a17">00075</a> <span class="keyword">extern</span> <span class="keywordtype">char</span> <a class="code" href="channels_8cpp.html#a17">DieValue</a>[MAXBUF];
00076
<a name="l00077"></a><a class="code" href="channels_8cpp.html#a18">00077</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a18">debugging</a>;
<a name="l00078"></a><a class="code" href="channels_8cpp.html#a19">00078</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a19">WHOWAS_STALE</a>;
<a name="l00079"></a><a class="code" href="channels_8cpp.html#a20">00079</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a20">WHOWAS_MAX</a>;
<a name="l00080"></a><a class="code" href="channels_8cpp.html#a21">00080</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a21">DieDelay</a>;
<a name="l00081"></a><a class="code" href="channels_8cpp.html#a22">00081</a> <span class="keyword">extern</span> time_t <a class="code" href="channels_8cpp.html#a22">startup_time</a>;
<a name="l00082"></a><a class="code" href="channels_8cpp.html#a23">00082</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a23">NetBufferSize</a>;
<a name="l00083"></a><a class="code" href="channels_8cpp.html#a24">00083</a> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a24">MaxWhoResults</a>;
<a name="l00084"></a><a class="code" href="channels_8cpp.html#a25">00084</a> <span class="keyword">extern</span> time_t <a class="code" href="channels_8cpp.html#a25">nb_start</a>;
00085
<a name="l00086"></a><a class="code" href="channels_8cpp.html#a26">00086</a> <span class="keyword">extern</span> std::vector<std::string> <a class="code" href="channels_8cpp.html#a26">module_names</a>;
00087
<a name="l00088"></a><a class="code" href="channels_8cpp.html#a27">00088</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a27">boundPortCount</a>;
<a name="l00089"></a><a class="code" href="channels_8cpp.html#a28">00089</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a28">portCount</a>;
<a name="l00090"></a><a class="code" href="channels_8cpp.html#a29">00090</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a29">SERVERportCount</a>;
<a name="l00091"></a><a class="code" href="channels_8cpp.html#a30">00091</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a30">ports</a>[MAXSOCKS];
<a name="l00092"></a><a class="code" href="channels_8cpp.html#a31">00092</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="channels_8cpp.html#a31">defaultRoute</a>;
00093
<a name="l00094"></a><a class="code" href="channels_8cpp.html#a32">00094</a> <span class="keyword">extern</span> std::vector<long> <a class="code" href="channels_8cpp.html#a32">auth_cookies</a>;
<a name="l00095"></a><a class="code" href="channels_8cpp.html#a33">00095</a> <span class="keyword">extern</span> std::stringstream <a class="code" href="channels_8cpp.html#a33">config_f</a>;
00096
<a name="l00097"></a><a class="code" href="channels_8cpp.html#a34">00097</a> <span class="keyword">extern</span> <a class="code" href="classserverrec.html">serverrec</a>* <a class="code" href="channels_8cpp.html#a34">me</a>[32];
00098
<a name="l00099"></a><a class="code" href="channels_8cpp.html#a35">00099</a> <span class="keyword">extern</span> FILE *<a class="code" href="channels_8cpp.html#a35">log_file</a>;
00100
<a name="l00101"></a><a class="code" href="channels_8cpp.html#a36">00101</a> <span class="keyword">extern</span> time_t <a class="code" href="channels_8cpp.html#a36">TIME</a>;
00102
00103 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
00104
<a name="l00105"></a><a class="code" href="channels_8cpp.html#a37">00105</a> std::vector<ModeParameter> <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>;
00106
<a name="l00107"></a><a class="code" href="classchanrec.html#a8">00107</a> <a class="code" href="classchanrec.html#a8">chanrec::chanrec</a>()
00108 {
00109 strcpy(<a class="code" href="classchanrec.html#o0">name</a>,<span class="stringliteral">""</span>);
00110 strcpy(<a class="code" href="classchanrec.html#o1">custom_modes</a>,<span class="stringliteral">""</span>);
00111 strcpy(<a class="code" href="classchanrec.html#o3">topic</a>,<span class="stringliteral">""</span>);
00112 strcpy(<a class="code" href="classchanrec.html#o6">setby</a>,<span class="stringliteral">""</span>);
00113 strcpy(<a class="code" href="classchanrec.html#o8">key</a>,<span class="stringliteral">""</span>);
00114 <a class="code" href="classchanrec.html#o4">created</a> = <a class="code" href="classchanrec.html#o5">topicset</a> = <a class="code" href="classchanrec.html#o7">limit</a> = 0;
00115 <a class="code" href="classchanrec.html#o9">binarymodes</a> = 0;
00116 <a class="code" href="classchanrec.html#o2">internal_userlist</a>.clear();
00117 }
00118
<a name="l00119"></a><a class="code" href="classchanrec.html#a0">00119</a> <span class="keywordtype">void</span> <a class="code" href="classchanrec.html#a0">chanrec::SetCustomMode</a>(<span class="keywordtype">char</span> mode,<span class="keywordtype">bool</span> mode_on)
00120 {
00121 <span class="keywordflow">if</span> (mode_on) {
00122 <span class="keyword">static</span> <span class="keywordtype">char</span> m[3];
00123 m[0] = mode;
00124 m[1] = <span class="charliteral">'\0'</span>;
00125 <span class="keywordflow">if</span> (!strchr(this->custom_modes,mode))
00126 {
00127 strlcat(<a class="code" href="classchanrec.html#o1">custom_modes</a>,m,MAXMODES);
00128 }
00129 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Custom mode %c set"</span>,mode);
00130 }
00131 <span class="keywordflow">else</span> {
00132
00133 std::string a = this-><a class="code" href="classchanrec.html#o1">custom_modes</a>;
00134 <span class="keywordtype">int</span> pos = a.find(mode);
00135 a.erase(pos,1);
00136 strncpy(this->custom_modes,a.c_str(),MAXMODES);
00137
00138 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Custom mode %c removed: modelist='%s'"</span>,mode,this->custom_modes);
00139 this-><a class="code" href="classchanrec.html#a1">SetCustomModeParam</a>(mode,<span class="stringliteral">""</span>,<span class="keyword">false</span>);
00140 }
00141 }
00142
00143
<a name="l00144"></a><a class="code" href="classchanrec.html#a1">00144</a> <span class="keywordtype">void</span> <a class="code" href="classchanrec.html#a1">chanrec::SetCustomModeParam</a>(<span class="keywordtype">char</span> mode,<span class="keywordtype">char</span>* parameter,<span class="keywordtype">bool</span> mode_on)
00145 {
00146
00147 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"SetCustomModeParam called"</span>);
00148 <a class="code" href="classModeParameter.html">ModeParameter</a> M;
00149 M.<a class="code" href="classModeParameter.html#o0">mode</a> = mode;
00150 strlcpy(M.<a class="code" href="classModeParameter.html#o2">channel</a>,this->name,CHANMAX);
00151 strlcpy(M.<a class="code" href="classModeParameter.html#o1">parameter</a>,parameter,MAXBUF);
00152 <span class="keywordflow">if</span> (mode_on)
00153 {
00154 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Custom mode parameter %c %s added"</span>,mode,parameter);
00155 <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.push_back(M);
00156 }
00157 <span class="keywordflow">else</span>
00158 {
00159 <span class="keywordflow">if</span> (<a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.size())
00160 {
00161 <span class="keywordflow">for</span> (vector<ModeParameter>::iterator i = <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.begin(); i < <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.end(); i++)
00162 {
00163 <span class="keywordflow">if</span> ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
00164 {
00165 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Custom mode parameter %c %s removed"</span>,mode,parameter);
00166 <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.erase(i);
00167 <span class="keywordflow">return</span>;
00168 }
00169 }
00170 }
00171 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"*** BUG *** Attempt to remove non-existent mode parameter!"</span>);
00172 }
00173 }
00174
<a name="l00175"></a><a class="code" href="classchanrec.html#a2">00175</a> <span class="keywordtype">bool</span> <a class="code" href="classchanrec.html#a2">chanrec::IsCustomModeSet</a>(<span class="keywordtype">char</span> mode)
00176 {
00177 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Checking ISCustomModeSet: %c %s"</span>,mode,this->custom_modes);
00178 <span class="keywordflow">return</span> (strchr(this->custom_modes,mode) != 0);
00179 }
00180
<a name="l00181"></a><a class="code" href="classchanrec.html#a3">00181</a> std::string <a class="code" href="classchanrec.html#a3">chanrec::GetModeParameter</a>(<span class="keywordtype">char</span> mode)
00182 {
00183 <span class="keywordflow">if</span> (<a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.size())
00184 {
00185 <span class="keywordflow">for</span> (vector<ModeParameter>::iterator i = <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.begin(); i < <a class="code" href="channels_8cpp.html#a37">custom_mode_params</a>.end(); i++)
00186 {
00187 <span class="keywordflow">if</span> ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
00188 {
00189 <span class="keywordflow">return</span> i->parameter;
00190 }
00191 }
00192 }
00193 <span class="keywordflow">return</span> <span class="stringliteral">""</span>;
00194 }
00195
<a name="l00196"></a><a class="code" href="classchanrec.html#a4">00196</a> <span class="keywordtype">long</span> <a class="code" href="classchanrec.html#a4">chanrec::GetUserCounter</a>()
00197 {
00198 <span class="keywordflow">return</span> (this-><a class="code" href="classchanrec.html#o2">internal_userlist</a>.size());
00199 }
00200
<a name="l00201"></a><a class="code" href="classchanrec.html#a5">00201</a> <span class="keywordtype">void</span> <a class="code" href="classchanrec.html#a5">chanrec::AddUser</a>(<span class="keywordtype">char</span>* castuser)
00202 {
00203 <a class="code" href="classchanrec.html#o2">internal_userlist</a>.push_back(castuser);
00204 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Added casted user to channel's internal list"</span>);
00205 }
00206
<a name="l00207"></a><a class="code" href="classchanrec.html#a6">00207</a> <span class="keywordtype">void</span> <a class="code" href="classchanrec.html#a6">chanrec::DelUser</a>(<span class="keywordtype">char</span>* castuser)
00208 {
00209 <span class="keywordflow">for</span> (std::vector<char*>::iterator a = <a class="code" href="classchanrec.html#o2">internal_userlist</a>.begin(); a < <a class="code" href="classchanrec.html#o2">internal_userlist</a>.end(); a++)
00210 {
00211 <span class="keywordflow">if</span> (*a == castuser)
00212 {
00213 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Removed casted user from channel's internal list"</span>);
00214 <a class="code" href="classchanrec.html#o2">internal_userlist</a>.erase(a);
00215 <span class="keywordflow">return</span>;
00216 }
00217 }
00218 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"BUG BUG BUG! Attempt to remove an uncasted user from the internal list of %s!"</span>,<a class="code" href="classchanrec.html#o0">name</a>);
00219 }
00220
<a name="l00221"></a><a class="code" href="classchanrec.html#a7">00221</a> std::vector<char*> *<a class="code" href="classchanrec.html#a7">chanrec::GetUsers</a>()
00222 {
00223 <span class="keywordflow">return</span> &<a class="code" href="classchanrec.html#o2">internal_userlist</a>;
00224 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Wed May 25 21:42:12 2005 for InspIRCd by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 >
</a>1.3.3 </small></address>
</body>
</html>
|