[go: up one dir, main page]

Menu

[322d50]: / src / iClient.cc  Maximize  Restore  History

Download this file

335 lines (298 with data), 7.4 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/**
* iClient.cc
* 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: iClient.cc,v 1.38 2007/05/26 09:41:24 mrbean_ Exp $
*/
#include <new>
#include <string>
#include <iostream>
#include <ctime>
#include <map>
#include <algorithm>
#include <cassert>
#include "iClient.h"
#include "client.h"
#include "ip.h"
#include "gnuworld_config.h"
#include "Network.h"
namespace gnuworld
{
using std::string ;
using std::map ;
string iClient::hiddenHostSuffix( "we.all.worship.mrbean.org" ) ;
iClient::iClient( const unsigned int& /* _uplink */,
const string& _yyxxx,
const string& _nickName,
const string& _userName,
const string& _hostBase64,
const string& _insecureHost,
const string& _realInsecureHost,
const string& _mode,
const string& _account,
const unsigned int _account_id,
const flagType _account_flags,
const string& _description,
const time_t& _nick_ts )
: NetworkTarget( _yyxxx ),
nickName( _nickName ),
userName( _userName ),
IP( xIP( _hostBase64, true ).GetLongIP() ),
insecureHost( _insecureHost ),
realInsecureHost( _realInsecureHost ),
description( _description),
nick_ts( _nick_ts ),
first_nick_ts( _nick_ts ),
mode( 0 ),
account( _account ),
account_id( _account_id ),
account_flags( _account_flags )
{
setModes( _mode ) ;
customDataMap = 0 ;
numericIP = xIP( IP ).GetNumericIP();
}
iClient::iClient( const unsigned int& /* _uplink */,
const string& _yyxxx,
const string& _nickName,
const string& _userName,
const string& _hostBase64,
const string& _insecureHost,
const string& _realInsecureHost,
const string& _mode,
const string& _account,
const unsigned int _account_id,
const flagType _account_flags,
const string& _setHost,
const string& _fakeHost,
const string& _description,
const time_t& _nick_ts )
: NetworkTarget( _yyxxx ),
nickName( _nickName ),
userName( _userName ),
IP( xIP( _hostBase64, true ).GetLongIP() ),
insecureHost( _insecureHost ),
realInsecureHost( _realInsecureHost ),
description( _description),
nick_ts( _nick_ts ),
first_nick_ts( _nick_ts ),
mode( 0 ),
account( _account ),
account_id( _account_id ),
account_flags( _account_flags )
#ifdef ASUKA
,setHost( _setHost )
#endif
#ifdef SRVX
,fakeHost( _fakeHost )
#endif
{
#ifndef ASUKA
(void) _setHost ;
#endif
#ifndef SRVX
(void) _fakeHost ;
#endif
setModes( _mode ) ;
customDataMap = 0 ;
numericIP = xIP( IP ).GetNumericIP();
}
iClient::~iClient()
{
delete customDataMap ;
customDataMap = 0 ;
}
const iServer* iClient::getServer()
{
return Network->findServer(getIntYY());
}
void iClient::setModes( const string& newModes )
{
for( string::size_type i = 0 ; i < newModes.size() ; i++ )
{
switch( newModes[ i ] )
{
case 'o':
case 'O':
setModeO() ;
break ;
case 'i':
case 'I':
setModeI() ;
break ;
case 'w':
case 'W':
setModeW() ;
break ;
case 'k':
case 'K':
setModeK() ;
break ;
case 'd':
case 'D':
setModeD() ;
break ;
case 'g':
setModeG() ;
break ;
case 'r':
case 'R':
setModeR() ;
if (isModeR() && isModeX()) setHiddenHost();
break ;
case 'x':
case 'X':
setModeX() ;
if (isModeR() && isModeX()) setHiddenHost();
break ;
case '+':
break ;
case 'n':
case 'h':
// Unsupported but used on networks that
// GNUWorld runs on.
// TODO?
break ;
default:
// Unknown mode
elog << "iClient> Unknown user mode: "
<< newModes[ i ]
<< ", in modes string: "
<< newModes
<< std::endl ;
break ;
} // switch
} // for
} // setModes()
bool iClient::removeChannel( Channel* theChan )
{
// No need to remove all duplicate channel instances, since
// addChannel() guarantees that none exist
for( channelIterator ptr = channelList.begin() ;
ptr != channelList.end() ; ++ptr )
{
if( *ptr == theChan )
{
channelList.erase( ptr ) ;
return true ;
}
}
// Channel not found
return false ;
}
const string iClient::getStringModes() const
{
string retMe( "+" ) ;
if( isModeO() ) retMe += 'o' ;
if( isModeW() ) retMe += 'w' ;
if( isModeI() ) retMe += 'i' ;
if( isModeD() ) retMe += 'd' ;
if( isModeK() ) retMe += 'k' ;
if( isModeR() ) retMe += 'r' ;
if( isModeX() ) retMe += 'x' ;
if( isModeG() ) retMe += 'g' ;
return retMe ;
}
bool iClient::setCustomData( xClient* theClient, void* data )
{
assert( theClient != 0 ) ;
// Is the customDataMap empty?
if( NULL == customDataMap )
{
// Yes, go ahead and allocate it
customDataMap = new (std::nothrow) customDataMapType ;
assert( customDataMap != 0 ) ;
}
// Is this xClient already using its customDataMap slot?
if( customDataMap->find( theClient ) != customDataMap->end() )
{
// Yes, return failure
return false ;
}
// Attempt to add this data into the customDataMap. Return the
// success/failure of the operation
return customDataMap->insert( customDataMapType::value_type(
theClient, data ) ).second ;
}
void* iClient::getCustomData( xClient* theClient ) const
{
assert( theClient != 0 ) ;
// Has the customDataMap been allocated?
if( NULL == customDataMap )
{
// Nope, return NULL
return 0 ;
}
// Attempt to find this xClient's data element
customDataMapType::const_iterator ptr =
customDataMap->find( theClient ) ;
// Did we find the element?
if( ptr == customDataMap->end() )
{
// Nope, return NULL
return 0 ;
}
// Found it, go ahead and return this xClient's data element
return ptr->second ;
}
void* iClient::removeCustomData( xClient* theClient )
{
assert( theClient != 0 ) ;
// Has the customDataMap been allocated?
if( NULL == customDataMap )
{
// No, return NULL
return 0 ;
}
// Attempt to find this xClient's data element
customDataMapType::iterator ptr = customDataMap->find( theClient ) ;
// Did we find it?
if( ptr == customDataMap->end() )
{
// Nope, return NULL
return 0 ;
}
// Yes, we found this xClient's data element. Remove it from
// the customDataMap
void* data = ptr->second ;
customDataMap->erase( ptr ) ;
// The customDataMap may now be empty, but let it remain allocated.
// Return the data element
return data ;
}
bool iClient::addChannel( Channel* theChan )
{
// This method is public, make sure the pointer is valid
assert( theChan != 0 ) ;
if( std::find( channelList.begin(), channelList.end(), theChan )
!= channelList.end() )
{
// Channel already found
return false ;
}
// Add the channel to the channelList
channelList.push_front( theChan ) ;
return true ;
}
bool iClient::findChannel( const Channel* theChan ) const
{
// Doesn't matter if theChan is NULL, it is never dereferenced
return std::find( channelList.begin(), channelList.end(),
theChan ) != channelList.end() ;
}
} // namespace gnuworld