add ipid
This commit is contained in:
parent
5c5e112cbc
commit
14088fccf2
@ -2,17 +2,25 @@
|
||||
#define AOCLIENT_H
|
||||
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
class AOClient
|
||||
{
|
||||
public:
|
||||
AOClient(QString p_remote_ip);
|
||||
AOClient(QHostAddress p_remote_ip);
|
||||
~AOClient();
|
||||
|
||||
QString hdid;
|
||||
QString remote_ip;
|
||||
QString getHwid();
|
||||
void setHwid(QString p_hwid);
|
||||
|
||||
QString getIpid();
|
||||
|
||||
QHostAddress remote_ip;
|
||||
|
||||
private:
|
||||
|
||||
QString hwid;
|
||||
QString ipid;
|
||||
};
|
||||
|
||||
#endif // AOCLIENT_H
|
||||
|
@ -33,7 +33,7 @@ private:
|
||||
int port;
|
||||
int ws_port;
|
||||
|
||||
QMap<QTcpSocket*, AOClient> clients;
|
||||
QMap<QTcpSocket*, AOClient*> clients;
|
||||
QString partial_packet;
|
||||
bool is_partial;
|
||||
|
||||
|
@ -1,6 +1,31 @@
|
||||
#include "include/aoclient.h"
|
||||
|
||||
AOClient::AOClient(QString p_remote_ip)
|
||||
AOClient::AOClient(QHostAddress p_remote_ip)
|
||||
{
|
||||
remote_ip = p_remote_ip;
|
||||
}
|
||||
|
||||
QString AOClient::getHwid(){
|
||||
return hwid;
|
||||
}
|
||||
|
||||
void AOClient::setHwid(QString p_hwid)
|
||||
{
|
||||
hwid = p_hwid;
|
||||
|
||||
QCryptographicHash hash(QCryptographicHash::Md5); // Don't need security, just hashing for uniqueness
|
||||
QString concat_ip_id = remote_ip.toString() + p_hwid;
|
||||
hash.addData(concat_ip_id.toUtf8());
|
||||
|
||||
ipid = hash.result().toHex().right(8);
|
||||
}
|
||||
|
||||
QString AOClient::getIpid()
|
||||
{
|
||||
return ipid;
|
||||
}
|
||||
|
||||
AOClient::~AOClient()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ void Server::start()
|
||||
// The main issue with this is that it will cause problems with bans, ipids, etc
|
||||
// But perhaps this can be negotiated by sending some extra data over?
|
||||
// No idea. I'll wait for long to read this massive comment and DM me on discord
|
||||
//
|
||||
// Upon thinking about this a bit more, I realized basically all of the
|
||||
// communication only happens via QTcpSocket* pointers.
|
||||
// If the Qt WebSocket server gives me QTcpSockets to work with,
|
||||
// then they can all go into the same object. I doubt this is the case, though
|
||||
if(!server->listen(QHostAddress::Any, port))
|
||||
{
|
||||
// TODO: signal server start failed
|
||||
@ -36,7 +41,7 @@ void Server::start()
|
||||
void Server::clientConnected()
|
||||
{
|
||||
QTcpSocket* client = server->nextPendingConnection();
|
||||
AOClient ao_client(client->peerAddress().toString());
|
||||
AOClient* ao_client = new AOClient(client->peerAddress());
|
||||
clients.insert(client, ao_client);
|
||||
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
|
||||
connect(client, SIGNAL(readyRead()), this, SLOT(clientData()));
|
||||
@ -53,6 +58,7 @@ void Server::clientDisconnected()
|
||||
{
|
||||
if(QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())){
|
||||
qDebug() << client->peerAddress() << "disconnected";
|
||||
delete clients.value(client);
|
||||
clients.remove(client);
|
||||
player_count--;
|
||||
}
|
||||
@ -81,6 +87,11 @@ void Server::handlePacket(AOPacket packet, QTcpSocket* socket)
|
||||
{
|
||||
// Lord forgive me
|
||||
if(packet.header == "HI"){
|
||||
AOClient* client = clients.value(socket);
|
||||
qDebug() << packet.contents[0];
|
||||
client->setHwid(packet.contents[0]);
|
||||
qDebug() << client->getIpid();
|
||||
|
||||
AOPacket response("ID", {"271828", "akashi", QApplication::applicationVersion()});
|
||||
socket->write(response.toUtf8());
|
||||
} else if (packet.header == "ID"){
|
||||
|
Loading…
Reference in New Issue
Block a user