implement handshake
This commit is contained in:
parent
355ebe9d13
commit
5c5e112cbc
@ -6,7 +6,10 @@
|
|||||||
class AOClient
|
class AOClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AOClient();
|
AOClient(QString p_remote_ip);
|
||||||
|
|
||||||
|
QString hdid;
|
||||||
|
QString remote_ip;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#include "include/aopacket.h"
|
#include "include/aopacket.h"
|
||||||
#include "include/aoclient.h"
|
#include "include/aoclient.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSettings>
|
||||||
#include <QTcpServer>
|
#include <QTcpServer>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
@ -24,6 +26,8 @@ public slots:
|
|||||||
void clientData();
|
void clientData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void handlePacket(AOPacket packet, QTcpSocket* socket);
|
||||||
|
|
||||||
QTcpServer* server;
|
QTcpServer* server;
|
||||||
|
|
||||||
int port;
|
int port;
|
||||||
@ -32,6 +36,8 @@ private:
|
|||||||
QMap<QTcpSocket*, AOClient> clients;
|
QMap<QTcpSocket*, AOClient> clients;
|
||||||
QString partial_packet;
|
QString partial_packet;
|
||||||
bool is_partial;
|
bool is_partial;
|
||||||
|
|
||||||
|
int player_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SERVER_H
|
#endif // SERVER_H
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include "include/aoclient.h"
|
#include "include/aoclient.h"
|
||||||
|
|
||||||
AOClient::AOClient()
|
AOClient::AOClient(QString p_remote_ip)
|
||||||
{
|
{
|
||||||
|
remote_ip = p_remote_ip;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,10 @@ AOPacket::AOPacket(QString p_packet)
|
|||||||
packet_contents.removeFirst();
|
packet_contents.removeFirst();
|
||||||
if(packet_contents[0] == "48E0")
|
if(packet_contents[0] == "48E0")
|
||||||
header = "HI";
|
header = "HI";
|
||||||
|
else if(packet_contents[0] == "493F")
|
||||||
|
header = "ID";
|
||||||
|
else
|
||||||
|
header = packet_contents[0]; // If no known decryption exists, just leave the packet as-is
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header = packet_contents[0];
|
header = packet_contents[0];
|
||||||
|
@ -8,6 +8,8 @@ Server::Server(int p_port, int p_ws_port, QObject* parent)
|
|||||||
|
|
||||||
port = p_port;
|
port = p_port;
|
||||||
ws_port = p_ws_port;
|
ws_port = p_ws_port;
|
||||||
|
|
||||||
|
player_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::start()
|
void Server::start()
|
||||||
@ -34,7 +36,7 @@ void Server::start()
|
|||||||
void Server::clientConnected()
|
void Server::clientConnected()
|
||||||
{
|
{
|
||||||
QTcpSocket* client = server->nextPendingConnection();
|
QTcpSocket* client = server->nextPendingConnection();
|
||||||
AOClient ao_client;
|
AOClient ao_client(client->peerAddress().toString());
|
||||||
clients.insert(client, ao_client);
|
clients.insert(client, ao_client);
|
||||||
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
|
connect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
|
||||||
connect(client, SIGNAL(readyRead()), this, SLOT(clientData()));
|
connect(client, SIGNAL(readyRead()), this, SLOT(clientData()));
|
||||||
@ -43,6 +45,8 @@ void Server::clientConnected()
|
|||||||
client->write(decryptor.toUtf8());
|
client->write(decryptor.toUtf8());
|
||||||
|
|
||||||
qDebug() << client->peerAddress().toString() << "connected";
|
qDebug() << client->peerAddress().toString() << "connected";
|
||||||
|
// TODO: only increment this once someone actually enters the coutroom
|
||||||
|
player_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::clientDisconnected()
|
void Server::clientDisconnected()
|
||||||
@ -50,11 +54,13 @@ void Server::clientDisconnected()
|
|||||||
if(QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())){
|
if(QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())){
|
||||||
qDebug() << client->peerAddress() << "disconnected";
|
qDebug() << client->peerAddress() << "disconnected";
|
||||||
clients.remove(client);
|
clients.remove(client);
|
||||||
|
player_count--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::clientData()
|
void Server::clientData()
|
||||||
{
|
{
|
||||||
|
// TODO: deal with more than one packet on wire
|
||||||
if(QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())){
|
if(QTcpSocket* client = dynamic_cast<QTcpSocket*>(sender())){
|
||||||
QString data = QString::fromUtf8(client->readAll());
|
QString data = QString::fromUtf8(client->readAll());
|
||||||
qDebug() << "From" << client->peerAddress() << ":" << data;
|
qDebug() << "From" << client->peerAddress() << ":" << data;
|
||||||
@ -67,5 +73,31 @@ void Server::clientData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
AOPacket packet(data);
|
AOPacket packet(data);
|
||||||
|
handlePacket(packet, client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::handlePacket(AOPacket packet, QTcpSocket* socket)
|
||||||
|
{
|
||||||
|
// Lord forgive me
|
||||||
|
if(packet.header == "HI"){
|
||||||
|
AOPacket response("ID", {"271828", "akashi", QApplication::applicationVersion()});
|
||||||
|
socket->write(response.toUtf8());
|
||||||
|
} else if (packet.header == "ID"){
|
||||||
|
QSettings config("config.ini", QSettings::IniFormat);
|
||||||
|
config.beginGroup("Options");
|
||||||
|
QString max_players = config.value("max_players").toString();
|
||||||
|
config.endGroup();
|
||||||
|
|
||||||
|
QStringList feature_list = {"noencryption"};
|
||||||
|
|
||||||
|
AOPacket response_pn("PN", {QString::number(player_count), max_players});
|
||||||
|
AOPacket response_fl("FL", feature_list);
|
||||||
|
socket->write(response_pn.toUtf8());
|
||||||
|
socket->write(response_fl.toUtf8());
|
||||||
|
} else {
|
||||||
|
qDebug() << "Unimplemented packet:" << packet.header;
|
||||||
|
qDebug() << packet.contents;
|
||||||
|
}
|
||||||
|
socket->flush();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user