-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatIdentd.cpp
More file actions
136 lines (99 loc) · 2.86 KB
/
Copy pathChatIdentd.cpp
File metadata and controls
136 lines (99 loc) · 2.86 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
/********************************************************************************
Gnucleus - An Application for the Gnutella Network
Copyright (C) 2000-2005 John Marshall Group
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 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.
By contributing code you grant John Marshall Group an unlimited, non-exclusive
license to your contribution.
For support, questions, commercial use, etc...
E-Mail: swabby@c0re.net
********************************************************************************/
#include "stdafx.h"
#include "gnucleus.h"
#include "GnucleusDoc.h"
#include "ChatPrefs.h"
#include "ChatControl.h"
#include "ChatIdentd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CChatIdentd::CChatIdentd(CChatControl* pChat)
{
m_pChat = pChat;
m_DataSending = false;
m_SecsAlive = 0;
}
CChatIdentd::~CChatIdentd()
{
// Flush receive buffer
byte pBuff[4096];
while(Receive(pBuff, 4096) > 0)
;
if(m_hSocket != INVALID_SOCKET)
AsyncSelect(0);
}
#if 0
BEGIN_MESSAGE_MAP(CChatIdentd, CAsyncSocket)
//{{AFX_MSG_MAP(CChatIdentd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif // 0
/////////////////////////////////////////////////////////////////////////////
// CChatIdentd member functions
void CChatIdentd::OnReceive(int nErrorCode)
{
// Receive Data
DWORD BuffLength = Receive(m_pBuff, 4096);
// Check for errors
switch (BuffLength)
{
case 0:
Close();
return;
break;
case SOCKET_ERROR:
Close();
return;
break;
}
m_pBuff[BuffLength] = '\0';
CString Header(m_pBuff);
// We are assuming here that the server is sending valid stuff
Header = Header + " : USERID : UNIX :" + m_pChat->m_pPrefs->m_Nick + "\r\n";
// Server -> 1025, 6667
// Client -> 1025 , 6667 : USERID : UNIX :gnucleus
Send(Header, Header.GetLength());
CAsyncSocket::OnReceive(nErrorCode);
}
int CChatIdentd::Send(const void* lpBuf, int nBufLen, int nFlags)
{
int Command = CAsyncSocket::Send(lpBuf, nBufLen, nFlags);
if(Command != SOCKET_ERROR)
m_DataSending = true;
return Command;
}
void CChatIdentd::OnSend(int nErrorCode)
{
m_DataSending = false;
CAsyncSocket::OnSend(nErrorCode);
}
void CChatIdentd::Close()
{
if(m_hSocket != INVALID_SOCKET)
{
AsyncSelect(0);
ShutDown(1);
CAsyncSocket::Close();
}
}