This repository has been archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetTalk.cpp
284 lines (250 loc) · 6.36 KB
/
NetTalk.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
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
// NetTalk.cpp : implementation file
//
#include "stdafx.h"
#include "QZJ_NetKeeper_Cracker.h"
#include "NetTalk.h"
#include "MD5Checksum.h"
#include "MD5ChecksumDefines.h"
#include "VirtualizerSDK.h"
#include "Crypt.h"
#include "NetKeeperHeader.h"
bool isConnented;
CNetTalk::CNetTalk(CWnd* pParent /*=NULL*/)
: CDialog(CNetTalk::IDD)
, m_nickname(_T(""))
, m_msgValue(_T(""))
, m_txtnickname(_T(""))
{
}
CNetTalk::~CNetTalk()
{
}
void CNetTalk::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_MESSAGE_LIST, m_messageList);
DDX_Control(pDX, IDC_MESSAGE_SEND, m_messagePreSend);
//DDX_Text(pDX, IDC_EDITNICKNAME, m_nickname);
DDX_Text(pDX, IDC_MESSAGE_SEND, m_msgValue);
DDX_Text(pDX, IDC_EDITNICKNAME, m_txtnickname);
}
BOOL CNetTalk::OnInitDialog()
{
CDialog::OnInitDialog();
m_SocketManager.SetMessageWindow( &m_messageList );
m_SocketManager.SetServerState( false ); // run as client
m_SocketManager.SetSmartAddressing( false ); // always send to server
OnBtnConnect();
AfxBeginThread(KeepAlive,this);
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
BEGIN_MESSAGE_MAP(CNetTalk, CDialog)
ON_WM_CLOSE()
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BTN_SEND, &CNetTalk::OnBnClickedBtnSend)
ON_BN_CLICKED(IDC_BTNLOGIN, &CNetTalk::OnBnClickedBtnlogin)
ON_BN_CLICKED(IDC_BTNEXIT, &CNetTalk::OnBnClickedBtnexit)
ON_BN_CLICKED(IDC_BTNBIRD, &CNetTalk::OnBnClickedBtnbird)
ON_BN_CLICKED(IDC_BTNCHANGE, &CNetTalk::OnBnClickedBtnchange)
//ON_MESSAGE(WM_SHOWCHATWIN
END_MESSAGE_MAP()
void CNetTalk::OnBtnConnect()
{
VIRTUALIZER_START
UpdateData();
if (m_strPort == "")
m_strPort = "85";
if (strServer == "")
strServer = "nov30th.com";
bool bSuccess;
bSuccess = m_SocketManager.ConnectTo( strServer, m_strPort, AF_INET, SOCK_STREAM); // TCP
if (bSuccess && m_SocketManager.WatchComm())
{
//GetDlgItem(IDC_BTNLOGIN)->EnableWindow( FALSE );
PrevDlgCtrl();
GetDlgItem(IDC_BTN_SEND)->EnableWindow( TRUE );
//GetDlgItem(IDC_BTNEXIT)->EnableWindow( TRUE );
CString strMsg;
strMsg = _T("杭电极速(代号XL闪讯)\r\n ");
m_SocketManager.GetPeerName( m_SockPeer );
m_messageList.SetWindowText( strMsg );
/////////////////////////////////////////////////////SEND HASH
CString strText;
strText = m_nickname + "[" + m_version + "]";
strText = "|NAME:" + strText + "|Verify:" + HashString(strText) + "|";
strText = "[LOGIN]" + strText;
BYTE byBuffer[256] = { 0 };
int nLen = strText.GetLength();
if (nLen > 0)
{
//strText += _T("\r\n");
nLen = strText.GetLength() + 1;
USES_CONVERSION;
strcpy((LPSTR)byBuffer, T2CA(strText));
m_SocketManager.WriteComm( byBuffer, nLen, INFINITE);
}
/*
CString tempHASH;
CCrypt crypt;
tempHASH = m_nickname + "|" + m_version;
tempHASH = crypt.Encrypt(tempHASH,1);
tempHASH = "QZJ" + tempHASH + "QZJ";
tempHASH = crypt.Encrypt(tempHASH,2);
int nLen = tempHASH.GetLength() + 1;
USES_CONVERSION;
BYTE byBuffer[256] = {0};
strcpy((LPSTR)byBuffer, T2CA(tempHASH));
m_SocketManager.WriteComm( byBuffer, nLen, INFINITE);
*/
}
else
{
AfxMessageBox("连接失败!");
}
VIRTUALIZER_END
}
void CNetTalk::OnBtnDisconnect()
{
// Disconnect socket
m_SocketManager.StopComm();
if (!m_SocketManager.IsOpen())
{
//GetDlgItem(IDC_BTNLOGIN)->EnableWindow( TRUE );
PrevDlgCtrl();
GetDlgItem(IDC_BTN_SEND)->EnableWindow( FALSE );
//GetDlgItem(IDC_BTNEXIT)->EnableWindow( FALSE );
}
}
void CNetTalk::OnBtnSend()
{
VIRTUALIZER_START
if (!m_SocketManager.IsOpen())
{
AfxMessageBox("未连接");
return;
}
BYTE byBuffer[256] = { 0 };
CString strText;
CMD5Checksum md5;
char md5Temp[200];
strcpy(md5Temp,m_nickname);
strcat(md5Temp,"!@#$%^&*()(*&^%$#@!");
strcat(md5Temp,"41");
#ifndef DEBUG
if (m_username != md5.GetMD5((BYTE*)md5Temp,strlen(md5Temp)))
{
AfxMessageBox("奇怪了.名字不一样类...");
return;
}
#endif
// Update so that we can retrieve new port number also... :-)
UpdateData();
m_messagePreSend.GetWindowText( strText );
if (strText.GetLength() < 1)
return;
if (strText.GetLength() > 100)
{
AfxMessageBox("请小于100字~");
return;
}
int nLen = strText.GetLength();
if (nLen > 0)
{
//strText += _T("\r\n");
nLen = strText.GetLength() + 1;
USES_CONVERSION;
strcpy((LPSTR)byBuffer, T2CA(strText));
m_SocketManager.WriteComm( byBuffer, nLen, INFINITE);
}
m_msgValue = "";
UpdateData(false);
VIRTUALIZER_END
}
void CNetTalk::OnBnClickedBtnSend()
{
OnBtnSend();
}
void CNetTalk::OnBnClickedBtnlogin()
{
OnBtnConnect();
}
void CNetTalk::OnBnClickedBtnexit()
{
OnBtnDisconnect();
Sleep(2000);
OnBtnConnect();
}
void CNetTalk::OnBnClickedBtnbird()
{
AfxMessageBox("鸟人!!鸟人!!");
}
void CNetTalk::OnClose(void)
{
this->ShowWindow(SW_HIDE);
CWnd* pParent = this->GetParent();
pParent->SendMessage( WM_SHOWCHATICO,0,2);
}
void CNetTalk::OnBnClickedBtnchange()
{
VIRTUALIZER_START
UpdateData();
if (m_txtnickname.GetLength() > 8 || m_txtnickname.GetLength() < 2)
{
AfxMessageBox("名字长度有问题。。");
return;
}
if (m_txtnickname.Find("[")>=0 || m_txtnickname.Find("]")>=0 || m_txtnickname.Find("|")>=0 || m_txtnickname.Find(":")>=0 || m_txtnickname.Find("\\")>=0)
{
AfxMessageBox("名字中不能有特殊符号~");
return;
}
CString strText;
strText = m_txtnickname + "[" + m_version + "]";
strText = "|NAME:" + strText + "|Verify:" + HashString(strText) + "|";
strText = "[NAME]" + strText;
BYTE byBuffer[256] = { 0 };
int nLen = strText.GetLength();
if (nLen > 0)
{
nLen = strText.GetLength() + 1;
USES_CONVERSION;
strcpy((LPSTR)byBuffer, T2CA(strText));
m_SocketManager.WriteComm( byBuffer, nLen, INFINITE);
}
VIRTUALIZER_END
}
CString CNetTalk::HashString(CString yourString)
{
VIRTUALIZER_START
CMD5Checksum md5;
char md5Temp[200];
static CString retval;
strcpy(md5Temp,yourString);
strcat(md5Temp,"!@#$%^&*()(*&^%$#@!");
strcat(md5Temp,"41");
retval = md5.GetMD5((BYTE*)md5Temp,strlen(md5Temp));
VIRTUALIZER_END
return retval;
}
UINT CNetTalk::KeepAlive(LPVOID pParam)
{
CNetTalk* app = (CNetTalk*)pParam;
CString strText = "[KeepAlive]";
BYTE byBuffer[256] = { 0 };
int nLen = strText.GetLength() + 1;
USES_CONVERSION;
strcpy((LPSTR)byBuffer, T2CA(strText));
while(1)
{
Sleep(30000);
if (!app->m_SocketManager.IsOpen())
{
continue;
}
app->m_SocketManager.WriteComm( byBuffer, nLen, INFINITE);
}
return 0;
}