~ubuntu-branches/debian/sid/libdc0/sid

« back to all changes in this revision

Viewing changes to dclib/cclient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pasi Savilaakso
  • Date: 2004-06-05 23:01:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040605230137-2ty5g6rcfyguk4et
Tags: upstream-0.3.2
Import upstream version 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          cclient.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Sun Sep 30 2001
 
5
    copyright            : (C) 2001-2004 by Mathias K�ster
 
6
    email                : mathen@users.berlios.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include <stdio.h>
 
19
#include <sys/types.h>
 
20
#include <fcntl.h>
 
21
 
 
22
#ifndef WIN32
 
23
#include <stdlib.h>
 
24
#include <unistd.h>
 
25
#include <sys/socket.h>
 
26
#include <netinet/in.h>
 
27
#include <netdb.h>
 
28
#endif
 
29
 
 
30
#ifdef HAVE_CONFIG_H
 
31
#include <config.h>
 
32
#endif
 
33
 
 
34
#include <dclib/dcos.h>
 
35
#include <dclib/core/clist.h>
 
36
#include <dclib/dcobject.h>
 
37
#include <dclib/cquerymanager.h>
 
38
#include <dclib/cdownloadmanager.h>
 
39
#include <dclib/cconnectionmanager.h>
 
40
#include <dclib/cencrypt.h>
 
41
#include <dclib/cmessagehandler.h>
 
42
#include <dclib/core/cstringlist.h>
 
43
#include <dclib/cconfig.h>
 
44
#include <dclib/chubsearch.h>
 
45
 
 
46
#include "cclient.h"
 
47
 
 
48
CClient::CClient()
 
49
{
 
50
        m_pCallback = 0;
 
51
        
 
52
        m_sBuffer          = "";
 
53
        m_sHubName         = "";
 
54
        m_sHubTopic        = "";
 
55
        m_sVersion         = "";
 
56
        m_bHandshake       = TRUE;
 
57
        m_bHandleUserList  = TRUE;
 
58
        m_bHandleSearch    = TRUE;
 
59
        m_bHandleMyinfo    = TRUE;
 
60
        m_bHandleForceMove = TRUE;
 
61
        m_bHandleTransfer  = TRUE;
 
62
        m_bUpdateMyinfo    = FALSE;
 
63
        m_bSendMyinfo      = TRUE;
 
64
        m_bSSLMode         = FALSE;
 
65
        m_nNickListHandler = 0;
 
66
        m_nOpListHandler   = 0;
 
67
 
 
68
        // set reconnect parameter
 
69
        m_eReconnectState      = ersNONE;
 
70
        m_nReconnectCount      = 0;
 
71
        m_timeReconnectTimeout = 0;
 
72
        m_timeMyinfoTimeout    = 0;
 
73
}
 
74
 
 
75
CClient::~CClient()
 
76
{
 
77
        SetCallBackFunction(0);
 
78
}
 
79
 
 
80
/** */
 
81
void CClient::ConnectionState( eConnectionState state )
 
82
{
 
83
        int err = -1;
 
84
 
 
85
        CMessageConnectionState *Object = new CMessageConnectionState();
 
86
 
 
87
        if (!Object)
 
88
        {
 
89
                return;
 
90
        }
 
91
 
 
92
        if ( (state == estCONNECTED) ||
 
93
             (state == estDISCONNECTED) )
 
94
        {
 
95
                // reset all values
 
96
                m_sBuffer           = "";
 
97
                m_bHandshake        = TRUE;
 
98
                m_timeMyinfoTimeout = time(0);
 
99
                m_nNickListHandler  = 0;
 
100
                m_nOpListHandler    = 0;
 
101
 
 
102
                m_UserList.Clear();
 
103
#ifdef HAVE_SSL
 
104
                m_pMessageSSL.Init();
 
105
#endif
 
106
                // update reconnect state
 
107
                if ( state == estCONNECTED )
 
108
                {
 
109
                        UpdateReconnect( ersNONE );
 
110
 
 
111
                        if ( m_bSSLMode == TRUE )
 
112
                        {
 
113
                                if ( ChangeSocketMode(esmSSLCLIENT) == FALSE )
 
114
                                {
 
115
                                        printf("change ssl mode failed\n");
 
116
                                }
 
117
                        }
 
118
                }
 
119
                else
 
120
                {
 
121
                        if ( m_eReconnectState == ersFORCEMOVE )
 
122
                        {
 
123
                                UpdateReconnect( ersNONE );
 
124
                        }
 
125
                        else
 
126
                        {
 
127
                                UpdateReconnect( ersENABLED );
 
128
                        }
 
129
                }
 
130
        }
 
131
 
 
132
        Object->m_eState   = state;
 
133
        Object->m_sMessage = GetSocketError();
 
134
 
 
135
        if ( m_pCallback != 0 )
 
136
        {
 
137
                err = m_pCallback->notify( this, Object );
 
138
        }
 
139
        else
 
140
        {
 
141
                err = DC_CallBack( Object );
 
142
        }
 
143
 
 
144
        // callback failed
 
145
        if ( err == -1 )
 
146
        {
 
147
                delete Object;
 
148
        }
 
149
 
 
150
        // update myinfo
 
151
        if ( m_bHandleMyinfo )
 
152
        {
 
153
                CConnectionManager::Instance()->SendMyInfoToConnectedServers();
 
154
        }
 
155
}
 
156
 
 
157
/** */
 
158
void CClient::DataAvailable( const char * buffer, int len )
 
159
{
 
160
        CString s;
 
161
        int i;
 
162
 
 
163
        if ( len <= 0 )
 
164
        {
 
165
                return;
 
166
        }
 
167
 
 
168
        // add traffic control
 
169
        CSocket::m_Traffic.AddTraffic(ettCONTROLRX,len);
 
170
 
 
171
        i = 0;
 
172
 
 
173
        s = m_sBuffer + CString().Set(buffer,len);
 
174
 
 
175
        // search last '|'
 
176
        i = s.FindRev('|');
 
177
        i++;
 
178
 
 
179
        if ( i > 0 )
 
180
        {
 
181
                m_sBuffer = s.Mid(0,i);
 
182
                HandleMessage( m_sBuffer );
 
183
        }
 
184
 
 
185
        if ( i == s.Length() )
 
186
        {
 
187
                m_sBuffer = "";
 
188
        }
 
189
        else
 
190
        {
 
191
                m_sBuffer = s.Mid( i, s.Length()-i );
 
192
        }
 
193
}
 
194
 
 
195
/** */
 
196
void CClient::DataTimeout()
 
197
{
 
198
        SendString("|");
 
199
}
 
200
 
 
201
/** */
 
202
void CClient::Notify()
 
203
{
 
204
        // check away mode
 
205
        if ( (m_bHandshake == FALSE) && ((time(0)-m_timeMyinfoTimeout) >= 30) )
 
206
        {
 
207
                if ( CConfig::Instance()->GetAwayMode() != m_MyInfo.m_eAwayMode)
 
208
                {
 
209
                        m_MyInfo.m_eAwayMode = CConfig::Instance()->GetAwayMode();
 
210
                        m_bUpdateMyinfo = TRUE;
 
211
                }
 
212
        }
 
213
 
 
214
        if ( (m_bHandshake == FALSE) && (m_bUpdateMyinfo == TRUE) && ((time(0)-m_timeMyinfoTimeout) >= 30) )
 
215
        {
 
216
                m_bUpdateMyinfo     = FALSE;
 
217
                m_timeMyinfoTimeout = time(0);
 
218
 
 
219
                if ( m_bSendMyinfo )
 
220
                        SendMyInfo( m_MyInfo.m_sNick, m_MyInfo.m_sComment, m_MyInfo.m_sUserSpeed, m_MyInfo.m_eAwayMode, m_MyInfo.m_sEMail, CString().setNum(m_MyInfo.m_nShared) );
 
221
        }
 
222
 
 
223
        if ( m_eReconnectState == ersENABLED )
 
224
        {
 
225
                if ( m_nReconnectCount >= CConfig::Instance()->GetReconnectCount() )
 
226
                {
 
227
                        UpdateReconnect( ersNONE, 0 );
 
228
                }
 
229
                else
 
230
                {
 
231
                        if ( GetConnectionState() != estNONE )
 
232
                        {
 
233
                                printf("warning, wrong reconnect state, you are connected !\n");
 
234
                        }
 
235
 
 
236
                        // init timer
 
237
                        if ( m_timeReconnectTimeout == 0 )
 
238
                        {
 
239
                                m_timeReconnectTimeout = time(0);
 
240
                        }
 
241
 
 
242
                        if ( (time(0)-m_timeReconnectTimeout) >= CConfig::Instance()->GetReconnectTimeout() )
 
243
                        {
 
244
                                UpdateReconnect( ersNONE );
 
245
 
 
246
                                if ( CConfig::Instance()->GetReconnectCount() != 9999 )
 
247
                                {
 
248
                                        m_nReconnectCount++;
 
249
                                }
 
250
 
 
251
                                Connect();
 
252
                        }
 
253
                }
 
254
        }
 
255
}
 
256
 
 
257
/** */
 
258
void CClient::UpdateReconnect( eReconnectState state, int count )
 
259
{
 
260
        // reconnect disabled
 
261
        if ( CConfig::Instance()->GetReconnectCount() == 0 )
 
262
        {
 
263
                m_eReconnectState = ersNONE;
 
264
                return;
 
265
        }
 
266
 
 
267
        // don't change state if reconnect disables
 
268
        if ( (m_eReconnectState == ersDISABLED) && (state != ersNONE) )
 
269
        {
 
270
                return;
 
271
        }
 
272
 
 
273
        // update state
 
274
        m_eReconnectState      = state;
 
275
        // reset timeout
 
276
        m_timeReconnectTimeout = 0;
 
277
        // update counter
 
278
        if ( count != -1 )
 
279
        {
 
280
                m_nReconnectCount = count;
 
281
        }
 
282
}
 
283
 
 
284
/** */
 
285
int CClient::HandleMessage( const CString & message )
 
286
{
 
287
        int err;
 
288
        int pointer;
 
289
        eDCMessage type;
 
290
        CObject * Object;
 
291
        CMessageHandler MessageHandler;
 
292
        CString sAnswer;
 
293
        CEncrypt Encrypt;
 
294
 
 
295
        if ( message == "" )
 
296
        {
 
297
                return 0;
 
298
        }
 
299
 
 
300
        pointer = 0;
 
301
 
 
302
        while( (type=MessageHandler.Parse(&message,pointer,Object=0)) != DC_MESSAGE_PARSE_ERROR )
 
303
        {
 
304
                if ( !Object )
 
305
                {
 
306
                        continue;
 
307
                }
 
308
 
 
309
                switch (type)
 
310
                {
 
311
                        case DC_MESSAGE_LOCK:
 
312
                        {
 
313
                                CMessageLock * msg = (CMessageLock*)Object;
 
314
 
 
315
                                // only handle the first lock in handshake mode
 
316
                                if ( m_bHandshake == TRUE )
 
317
                                {
 
318
                                        Encrypt.Encrypt(msg->m_sData,sAnswer);
 
319
 
 
320
                                        SendKey( sAnswer );
 
321
 
 
322
                                        if ( msg->m_bExtProtocol == TRUE )
 
323
                                        {
 
324
                                                // quicklist ??? http://forum.dcstats.net/showthread.php?s=&threadid=802
 
325
                                        }
 
326
 
 
327
                                        SendValidateNick( m_MyInfo.m_sNick );
 
328
                                }
 
329
 
 
330
                                break;
 
331
                        }
 
332
 
 
333
                        case DC_MESSAGE_LOGEDIN:
 
334
                        {
 
335
                                // update myinfo
 
336
//                              if ( m_bHandleMyinfo )
 
337
//                                      CConnectionManager::Instance()->SendMyInfoToConnectedServers();
 
338
 
 
339
                                break;
 
340
                        }
 
341
 
 
342
                        case DC_MESSAGE_HUBNAME:
 
343
                        {
 
344
                                CMessageHubName * msg = (CMessageHubName*)Object;
 
345
 
 
346
                                // set the old hubname in this message
 
347
                                if ( GetHubName() != msg->m_sHubName )
 
348
                                        msg->m_sOldHubName = GetHubName();
 
349
                                SetHubName(msg->m_sHubName);
 
350
 
 
351
                                break;
 
352
                        }
 
353
 
 
354
                        case DC_MESSAGE_HUB_TOPIC:
 
355
                        {
 
356
                                CMessageHubTopic * msg = (CMessageHubTopic*) Object;
 
357
 
 
358
                                SetHubTopic(msg->m_sTopic);
 
359
 
 
360
                                break;
 
361
                        }
 
362
 
 
363
                        case DC_MESSAGE_HELLO:
 
364
                        {
 
365
                                CMessageHello * msg = (CMessageHello*)Object;
 
366
 
 
367
                                if ( (msg->m_sNick == m_MyInfo.m_sNick) && (m_bHandshake == TRUE) )
 
368
                                {
 
369
                                        SendVersion( m_sVersion );
 
370
 
 
371
                                        // get nicklist
 
372
                                        if ( m_bHandleUserList == TRUE )
 
373
                                                RequestNickList();
 
374
 
 
375
                                        if ( m_bSendMyinfo )
 
376
                                                SendMyInfo( m_MyInfo.m_sNick, m_MyInfo.m_sComment, m_MyInfo.m_sUserSpeed, m_MyInfo.m_eAwayMode, m_MyInfo.m_sEMail, CString().setNum(m_MyInfo.m_nShared) );
 
377
 
 
378
                                        m_bHandshake = FALSE;
 
379
 
 
380
                                        // update myinfo
 
381
                                        if ( m_bHandleMyinfo )
 
382
                                                CConnectionManager::Instance()->SendMyInfoToConnectedServers();
 
383
                                }
 
384
                                else if ( m_bHandleUserList == TRUE )
 
385
                                {
 
386
                                        if ( (m_UserList.AppendUser(msg->m_sNick) == TRUE) && (!m_bHandshake) )
 
387
                                                SendGetInfo(msg->m_sNick,GetNick());
 
388
#ifdef HAVE_SSL
 
389
                                        m_pMessageSSL.JoinHub(this,msg->m_sNick);
 
390
#endif
 
391
                                }
 
392
 
 
393
                                break;
 
394
                        }
 
395
 
 
396
                        case DC_MESSAGE_MYINFO:
 
397
                        {
 
398
                                CMessageMyInfo * msg = (CMessageMyInfo*)Object;
 
399
 
 
400
                                if( m_bHandleUserList == TRUE )
 
401
                                {
 
402
                                        if ( m_UserList.UpdateUser(msg) == FALSE )
 
403
                                        {
 
404
                                                delete Object;
 
405
                                                Object = 0;
 
406
                                        }
 
407
                                }
 
408
 
 
409
                                break;
 
410
                        }
 
411
 
 
412
                        case DC_MESSAGE_QUIT:
 
413
                        {
 
414
                                CMessageQuit * msg = (CMessageQuit*)Object;
 
415
 
 
416
                                if ( m_bHandleUserList == TRUE )
 
417
                                {
 
418
                                        m_UserList.RemoveUser(msg->m_sNick);
 
419
#ifdef HAVE_SSL
 
420
                                        m_pMessageSSL.LeaveHub(this,msg->m_sNick);
 
421
#endif
 
422
                                }
 
423
 
 
424
                                break;
 
425
                        }
 
426
 
 
427
                        case DC_MESSAGE_NICKLIST:
 
428
                        {
 
429
                                CString *nick;
 
430
                                
 
431
                                CMessageNickList * msg = (CMessageNickList*)Object;
 
432
 
 
433
                                if( m_bHandleUserList == TRUE )
 
434
                                {
 
435
                                        // 0: update nicklist 1: requested nicklist
 
436
                                        if ( m_nNickListHandler == 1 )
 
437
                                        {
 
438
                                                m_UserList.Clear();
 
439
 
 
440
                                                m_nNickListHandler = 0;
 
441
                                        }
 
442
 
 
443
                                        m_UserList.InitUserList(msg);
 
444
                                        
 
445
                                        for(nick=0;(nick=msg->m_NickList.Next(nick))!=0;)
 
446
                                        {
 
447
                                                SendGetInfo(*nick,GetNick());
 
448
                                        }
 
449
                                }
 
450
 
 
451
                                break;
 
452
                        }
 
453
 
 
454
                        case DC_MESSAGE_OPLIST:
 
455
                        {
 
456
                                CMessageNickList * msg = (CMessageNickList*)Object;
 
457
 
 
458
                                // operators allready in the userlist
 
459
                                if( m_bHandleUserList == TRUE )
 
460
                                {
 
461
                                        // init operator list
 
462
                                        m_UserList.InitOperatorList(msg);
 
463
                                }
 
464
                                break;
 
465
                        }
 
466
 
 
467
                        case DC_MESSAGE_SEARCH:
 
468
                        {
 
469
                                bool search = TRUE;
 
470
                                CMessageSearch * msg = (CMessageSearch*)Object;
 
471
 
 
472
                                if ( m_bHandleSearch == TRUE )
 
473
                                {
 
474
                                        // check for loopback search
 
475
                                        if ( msg->m_bLocal )
 
476
                                        {
 
477
                                                if ( msg->m_sSource == GetNick() )
 
478
                                                {
 
479
                                                        search = FALSE;
 
480
                                                }
 
481
                                        }
 
482
                                        else
 
483
                                        {
 
484
                                                // disable global search, compare search with own ip and port
 
485
                                                if ( (msg->m_nPort == CConfig::Instance()->GetUDPListenPort()) &&
 
486
                                                     (msg->m_sSource == CConfig::Instance()->GetUDPHostString(FALSE)) )
 
487
                                                {
 
488
                                                        search = FALSE;
 
489
                                                }
 
490
                                        }
 
491
 
 
492
                                        if ( (search == TRUE) && (CQueryManager::Instance() != 0) )
 
493
                                        {
 
494
                                                CQueryManager::Instance()->SearchQuery( GetHubName(), GetHost(), GetNick(), msg );
 
495
                                        }
 
496
                                }
 
497
 
 
498
                                break;
 
499
                        }
 
500
 
 
501
                        case DC_MESSAGE_SEARCHRESULT:
 
502
                        {
 
503
                                if( m_bHandleUserList == TRUE )
 
504
                                {
 
505
                                        UpdateUserSlots( (CMessageSearchResult *) Object );
 
506
                                }
 
507
 
 
508
                                if ( CHubSearch::Instance() )
 
509
                                        if ( CHubSearch::Instance()->HandleMessage( (CMessageSearchResult *) Object ) == TRUE )
 
510
                                                Object = 0;
 
511
                                break;
 
512
                        }
 
513
 
 
514
                        case DC_MESSAGE_CONNECTTOME:
 
515
                        {
 
516
                                CMessageConnectToMe * msg = (CMessageConnectToMe*) Object;
 
517
 
 
518
                                if ( m_bHandleTransfer == TRUE )
 
519
                                {
 
520
                                        CDownloadManager::Instance()->DLM_AddTransferRequest( msg->m_sHost, msg->m_nPort, GetHubName(), GetHost() );
 
521
                                }
 
522
 
 
523
                                break;
 
524
                        }
 
525
 
 
526
                        case DC_MESSAGE_REVCONNECTTOME:
 
527
                        {
 
528
                                CMessageRevConnectToMe * msg = (CMessageRevConnectToMe*) Object;
 
529
 
 
530
                                if ( (GetMode() == ecmACTIVE) && (m_bHandleTransfer == TRUE) )
 
531
                                {
 
532
                                        CString s = CConfig::Instance()->GetTCPHostString();
 
533
 
 
534
                                        if ( s != "" )
 
535
                                        {
 
536
                                                if ( CDownloadManager::Instance()->DLM_AddTransferRequest( msg->m_sDstNick, "", GetHubName(), GetHost() ) == TRUE )
 
537
                                                {
 
538
                                                        SendConnectToMe(msg->m_sDstNick,s);
 
539
                                                }
 
540
                                        }
 
541
                                }
 
542
 
 
543
                                break;
 
544
                        }
 
545
 
 
546
                        case DC_MESSAGE_FORCEMOVE:
 
547
                        {
 
548
                                CMessageForceMove * msg = (CMessageForceMove*) Object;
 
549
 
 
550
                                if ( (CConfig::Instance()->GetForceMoveEnabled() == TRUE) && (m_bHandleForceMove == TRUE) )
 
551
                                {
 
552
                                        SetHubName(msg->m_sHost);
 
553
 
 
554
                                        UpdateReconnect( ersFORCEMOVE, 0 );
 
555
 
 
556
                                        Connect(msg->m_sHost,msg->m_nPort);
 
557
                                }
 
558
 
 
559
                                break;
 
560
                        }
 
561
 
 
562
                        case DC_MESSAGE_PRIVATECHAT:
 
563
                        {
 
564
                                CMessagePrivateChat * msg = (CMessagePrivateChat*) Object;
 
565
 
 
566
                                if ( (CConfig::Instance()->GetChatRecvOfflineMessages() == TRUE) && (m_UserList.IsUserOnline(msg->m_sSrcNick) == FALSE) )
 
567
                                {
 
568
                                        delete Object;
 
569
                                        Object = 0;
 
570
                                        msg = 0;
 
571
                                }
 
572
#ifdef HAVE_SSL
 
573
                                if ( msg )
 
574
                                {
 
575
                                        m_pMessageSSL.PrivateChat(this,msg);
 
576
                                }
 
577
#endif
 
578
                                break;
 
579
                        }
 
580
 
 
581
                        case DC_MESSAGE_CAPABILITIES:
 
582
                        {
 
583
                                m_MessageCapabilities = *((CMessageCapabilities*) Object);
 
584
                                break;
 
585
                        }
 
586
 
 
587
                        default:
 
588
                        {
 
589
                                break;
 
590
                        }
 
591
                }
 
592
 
 
593
                if (Object)
 
594
                {
 
595
                        ((CDCMessage*)Object)->m_eType = type;
 
596
 
 
597
                        if ( m_pCallback != 0 )
 
598
                        {
 
599
                                err = m_pCallback->notify( this, Object );
 
600
                        }
 
601
                        else
 
602
                        {
 
603
                                err = DC_CallBack( Object );
 
604
                        }
 
605
 
 
606
                        if ( err == -1 )
 
607
                        {
 
608
                                delete Object;
 
609
                        }
 
610
                }
 
611
        }
 
612
 
 
613
        return 0;
 
614
}
 
615
 
 
616
/** */
 
617
void CClient::UpdateUserSlots( CMessageSearchResult * pSearchResult )
 
618
{
 
619
        int err;
 
620
        CMessageMyInfo myinfo,*mi;
 
621
        
 
622
        if ( m_UserList.UpdateUserSlots(pSearchResult) == TRUE )
 
623
        {
 
624
                if ( m_UserList.GetUserMyInfo( pSearchResult->m_sNick, &myinfo ) == TRUE )
 
625
                {
 
626
                        mi = new CMessageMyInfo();
 
627
                        *mi = myinfo;
 
628
 
 
629
                        if ( m_pCallback != 0 )
 
630
                        {
 
631
                                err = m_pCallback->notify( this, mi );
 
632
                        }
 
633
                        else
 
634
                        {
 
635
                                err = DC_CallBack( mi );
 
636
                        }
 
637
 
 
638
                        if ( err == -1 )
 
639
                        {
 
640
                                delete mi;
 
641
                        }
 
642
                }
 
643
        }
 
644
}
 
645
 
 
646
/** */
 
647
bool CClient::SetUserTransferInfo( CString nick, CDCMessage * msg )
 
648
{
 
649
        int err;
 
650
        bool res = FALSE;
 
651
        CMessageMyInfo myinfo,*mi;
 
652
 
 
653
        if ( m_UserList.SetUserTransferInfo(nick,msg) == TRUE )
 
654
        {
 
655
                if ( m_UserList.GetUserMyInfo( nick, &myinfo ) == TRUE )
 
656
                {
 
657
                        mi = new CMessageMyInfo();
 
658
                        *mi = myinfo;
 
659
 
 
660
                        if ( m_pCallback != 0 )
 
661
                        {
 
662
                                err = m_pCallback->notify( this, mi );
 
663
                        }
 
664
                        else
 
665
                        {
 
666
                                err = DC_CallBack( mi );
 
667
                        }
 
668
 
 
669
                        if ( err == -1 )
 
670
                        {
 
671
                                delete mi;
 
672
                        }
 
673
                        
 
674
                        res = TRUE;
 
675
                }
 
676
        }
 
677
        
 
678
        return res;
 
679
}
 
680
 
 
681
/** send private message */
 
682
int CClient::SendPrivateMessage( CString sNick, CString sTo, CString sMsg, CString sFromNick )
 
683
{
 
684
        int i=-1;
 
685
        CString s;
 
686
 
 
687
        if ( m_UserList.IsUserOnline( sTo ) || CConfig::Instance()->GetChatSendOfflineMessages() )
 
688
        {
 
689
#ifdef HAVE_SSL
 
690
                s = m_pMessageSSL.EncryptMessage( this, sTo, sMsg );
 
691
 
 
692
                if ( s != "" )
 
693
                {
 
694
                        sMsg = s;
 
695
                }
 
696
#endif
 
697
 
 
698
                i = CDCProto::SendPrivateMessage( sNick, sTo, sMsg, sFromNick );
 
699
        }
 
700
 
 
701
        return i;
 
702
}
 
703
 
 
704
/** */
 
705
int CClient::RequestNickList()
 
706
{
 
707
        int res = 0;
 
708
        if (m_nNickListHandler==0) {
 
709
                // if m_nNickListHandler == 1 we are still waiting for the nicklist, TODO handling ???
 
710
                m_nNickListHandler = 1;
 
711
                m_nOpListHandler   = 1;
 
712
                res = CDCProto::RequestNickList();
 
713
                if (res==1)
 
714
                        printf("Error requesting the NickList.\n");
 
715
        } else
 
716
                printf("We are still waiting for a NickList.\n");
 
717
        return res;
 
718
}
 
719
 
 
720
/** */
 
721
int CClient::Disconnect( bool force )
 
722
{
 
723
        UpdateReconnect( ersDISABLED );
 
724
 
 
725
        return CConnection::Disconnect(force);
 
726
}