[go: up one dir, main page]

Menu

[ab7a0e]: / src / server_glines.cc  Maximize  Restore  History

Download this file

286 lines (251 with data), 6.3 kB

  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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/**
* server_glines.cc
* This is the implementation file for the xServer class.
* This class is the entity which is the GNUWorld server
* proper. It manages network I/O, parsing and distributing
* incoming messages, notifying attached clients of
* system events, on, and on, and on.
*
* Copyright (C) 2002 Daniel Karrels <dan@karrels.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*
* $Id: server_glines.cc,v 1.3 2007/12/14 03:06:10 isomer Exp $
*/
#include <new>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include "server.h"
#include "Network.h"
#include "Gline.h"
#include "ELog.h"
RCSTAG( "$Id: server_glines.cc,v 1.3 2007/12/14 03:06:10 isomer Exp $" ) ;
namespace gnuworld
{
using std::string ;
using std::vector ;
using std::endl ;
using std::stringstream ;
bool xServer::removeGline( const string& userHost, const xClient* remClient )
{
// This method is true if we find the gline in our internal
// structure of glines.
bool foundGline = false ;
// Perform a search for the gline
glineIterator gItr = findGlineIterator( userHost ) ;
if( gItr != glines_end() )
{
foundGline = true ;
}
// Notify the network that we are removing it
stringstream s ;
if ( foundGline ) {
s << getCharYY()
<< " GL * -"
<< userHost
<< " "
<< gItr->second->getExpiration() // expiration
<< " "
<< ::time(0) // lastmod
<< " "
<< gItr->second->getExpiration() // expiration
<< " :"
<< gItr->second->getReason();
}
else {
// Even if we didn't find the gline here, it may be present
// to someone on the network *shrug*
s << getCharYY()
<< " GL * -"
<< userHost
<< " "
<< ::time(0) + 60 // expire
<< " "
<< ::time(0) // lastmod
<< " "
<< ::time(0) + 60 // lifetime
<< " "
<< ":Unknown G-Line";
}
// Write the data to the network output buffer(s)
Write( s ) ;
// Did we find the gline in the interal gline structure?
if( foundGline )
{
// Let all clients know that the gline has been removed
if( remClient )
{
PostEvent( EVT_REMGLINE,
static_cast< void* >( gItr->second ),
0,0,0,remClient ) ;
}
else
{
PostEvent( EVT_REMGLINE,
static_cast< void* >( gItr->second ) ) ;
}
// Deallocate the gline
delete gItr->second ;
// Remove the gline from the internal gline structure
eraseGline( gItr ) ;
}
// Return success
return foundGline ;
}
// C GL * +~*@209.9.117.131 180 :Banned (~*@209.9.117.131) until 957235403 (On Mon May 1
// 22:40:23 2000 GMT from SE5 for 180 seconds: remgline test.. [0])
bool xServer::setGline(
const string& setBy,
const string& userHost,
const string& reason,
const time_t& duration,
const time_t& lastmod,
const xClient* setClient,
const string& server )
{
// Remove any old matches
{
xServer::glineIterator gItr = findGlineIterator( userHost ) ;
if( gItr != glines_end() )
{
// This gline is already present
delete gItr->second ;
eraseGline( gItr ) ;
}
}
Gline* newGline =
new (std::nothrow) Gline( setBy,
userHost,
reason,
duration ,
lastmod) ;
assert( newGline != 0 ) ;
// Notify the rest of the network
stringstream s ;
s << getCharYY() << " GL "
<< server << " !+"
<< userHost << ' '
<< duration << ' '
<< lastmod << " :"
<< reason ;
Write( s ) ;
glineList.insert( glineListType::value_type(
newGline->getUserHost(), newGline ) ) ;
if(setClient)
{
PostEvent( EVT_GLINE,
static_cast< void* >( newGline ), 0,0,0,setClient ) ;
}
else
{
PostEvent( EVT_GLINE,
static_cast< void* >( newGline ) ) ;
}
return true ;
}
vector< const Gline* > xServer::matchGline( const string& userHost ) const
{
vector< const Gline* > retMe ;
for( const_glineIterator ptr = glines_begin() ;
ptr != glines_end() ; ++ptr )
{
if( !match( ptr->second->getUserHost(), userHost ) )
{
retMe.push_back( ptr->second ) ;
}
}
return retMe ;
}
const Gline* xServer::findGline( const string& userHost ) const
{
const_glineIterator gItr = glineList.find( userHost ) ;
if( gItr == glineList.end() )
{
return 0 ;
}
return gItr->second ;
}
xServer::glineIterator xServer::findGlineIterator(
const string& userHost )
{
return glineList.find( userHost ) ;
}
void xServer::addGline( Gline* newGline )
{
assert( newGline != 0 ) ;
glineList.insert( glineListType::value_type( newGline->getUserHost(),
newGline ) ) ;
}
void xServer::sendGlinesToNetwork()
{
time_t now = ::time( 0 ) ;
for( const_glineIterator ptr = glines_begin() ;
ptr != glines_end() ; ++ptr )
{
stringstream s ;
s << getCharYY() << " GL * +"
<< ptr->second->getUserHost() << ' '
<< (ptr->second->getExpiration() - now) << ' '
<< ptr->second->getLastmod() << " :"
<< ptr->second->getReason() ;
Write( s ) ;
}
}
void xServer::removeMatchingGlines( const string& wildHost )
{
for( glineIterator ptr = glines_begin() ; ptr != glines_end() ;
++ptr )
{
// TODO: Does this work with two wildHost's?
if( !match( wildHost, ptr->second->getUserHost() ) )
{
PostEvent( EVT_REMGLINE,
static_cast< void* >( ptr->second ) ) ;
delete ptr->second ;
glineList.erase( ptr ) ;
}
}
}
void xServer::BurstGlines()
{
xNetwork::localClientIterator ptr = Network->localClient_begin() ;
while( ptr != Network->localClient_end() )
{
ptr->second->BurstGlines() ;
++ptr ;
}
}
void xServer::updateGlines()
{
time_t now = ::time( 0 ) ;
glineIterator ptr = glines_begin();
while (ptr != glines_end())
{
if( ptr->second->getExpiration() <= now )
{
// Expire the gline
PostEvent( EVT_REMGLINE,
static_cast< void* >( ptr->second ) ) ;
delete ptr->second ;
glineList.erase( ptr++ ) ;
} else {
ptr++;
}
}
} // updateGlines()
} // namespace gnuworld