-
Notifications
You must be signed in to change notification settings - Fork 76
/
chatlistensock.cpp
71 lines (46 loc) · 1.47 KB
/
chatlistensock.cpp
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
// chatlistensock.cpp : implementation file
//
// But does it get goat's blood out?
#include "stdafx.h"
#include "MUSHclient.h"
#include "doc.h"
#include <stddef.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CChatListenSocket, CAsyncSocket)
CChatListenSocket::CChatListenSocket(CMUSHclientDoc* pDoc)
{
m_pDoc = pDoc;
} // end of constructor
CChatListenSocket::~CChatListenSocket()
{
// cancel callbacks for closed sockets
Close ();
} // end of destructor
void CChatListenSocket::OnAccept(int nErrorCode)
{
m_pDoc->ChatNote (eChatConnection, "Incoming chat call");
CChatSocket * pSocket = new CChatSocket (m_pDoc);
int SockAddrLen = sizeof(pSocket->m_ServerAddr) ;
if (!Accept(*pSocket,
(SOCKADDR*) &pSocket->m_ServerAddr,
&SockAddrLen))
{
m_pDoc->ChatNote (eChatConnection, "Cannot accept call.");
delete pSocket;
return;
}
pSocket->AsyncSelect ();
pSocket->m_bIncoming = true;
pSocket->m_strServerName = inet_ntoa (pSocket->m_ServerAddr.sin_addr);
m_pDoc->ChatNote (eChatConnection,
TFormat (
"Accepted call from %s port %d",
(LPCTSTR) pSocket->m_strServerName,
ntohs (pSocket->m_ServerAddr.sin_port)));
m_pDoc->m_ChatList.AddTail (pSocket);
pSocket->m_iChatStatus = eChatAwaitingConnectionRequest;
} // end of OnAccept