diff --git a/include/aoclient.h b/include/aoclient.h index 4e928b1..b15115f 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -2,17 +2,25 @@ #define AOCLIENT_H #include +#include +#include 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 diff --git a/include/server.h b/include/server.h index 0a21ecb..0c0c41d 100644 --- a/include/server.h +++ b/include/server.h @@ -33,7 +33,7 @@ private: int port; int ws_port; - QMap clients; + QMap clients; QString partial_packet; bool is_partial; diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 092d0a8..8cc8441 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -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() +{ + +} diff --git a/src/server.cpp b/src/server.cpp index db7581f..9ad941d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -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(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"){