-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonline.cpp
52 lines (47 loc) · 1.3 KB
/
online.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
#include "online.h"
#include "ui_online.h"
#include "protocol.h"
#include "tcpclient.h"
#include <QMessageBox>
Online::Online(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Online)
{
ui->setupUi(this);
}
Online::~Online()
{
delete ui;
}
void Online::showOnlie(PDU *pdu)
{
if (NULL == pdu) {
return;
}
ui->online->clear();
char caTmp[32];
for (int i = 0; i < pdu->uiMsgLen/32; ++i) {
memcpy(caTmp, (char *)pdu->caMsg+i*32, 32);
ui->online->addItem(caTmp);
}
}
void Online::on_AddFriend_bd_clicked()
{
QListWidgetItem *item = ui->online->currentItem();
if (item == nullptr) {
return;
}
if (strcmp(item->text().toStdString().c_str(),TcpClient::getInstance()->m_strName.toStdString().c_str()) == 0) {
QMessageBox::information(this, "添加好友", "不能添加自己为好友");
return;
}
PDU *pdu = mkPDU(0);
memcpy(pdu->caData, TcpClient::getInstance()->m_strName.toStdString().c_str()
, TcpClient::getInstance()->m_strName.size());
memcpy(pdu->caData+32, item->text().toStdString().c_str()
, item->text().size());
pdu->uiMsgType = ENUM_MSG_TYPE_ADD_FRIEND_REQUEST;
TcpClient::getInstance()->getTcpSocket()->write((char *)pdu,pdu->uiPDULen);
free(pdu);
pdu = NULL;
}