get areas working
This commit is contained in:
parent
0c802ee674
commit
ee9ffa7f2a
@ -47,12 +47,16 @@ class AOClient : public QObject {
|
|||||||
void clientDisconnected();
|
void clientDisconnected();
|
||||||
void clientData();
|
void clientData();
|
||||||
void sendPacket(AOPacket packet);
|
void sendPacket(AOPacket packet);
|
||||||
|
void sendPacket(QString header, QStringList contents);
|
||||||
|
void sendPacket(QString header);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Server* server;
|
Server* server;
|
||||||
QTcpSocket* socket;
|
QTcpSocket* socket;
|
||||||
|
|
||||||
void handlePacket(AOPacket packet);
|
void handlePacket(AOPacket packet);
|
||||||
|
void changeArea(int new_area);
|
||||||
|
|
||||||
QString partial_packet;
|
QString partial_packet;
|
||||||
bool is_partial;
|
bool is_partial;
|
||||||
|
@ -70,10 +70,7 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
// Lord forgive me
|
// Lord forgive me
|
||||||
if (packet.header == "HI") {
|
if (packet.header == "HI") {
|
||||||
setHwid(packet.contents[0]);
|
setHwid(packet.contents[0]);
|
||||||
|
sendPacket("ID", {"271828", "akashi", QApplication::applicationVersion()});
|
||||||
AOPacket response(
|
|
||||||
"ID", {"271828", "akashi", QApplication::applicationVersion()});
|
|
||||||
sendPacket(response);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "ID") {
|
else if (packet.header == "ID") {
|
||||||
QSettings config("config.ini", QSettings::IniFormat);
|
QSettings config("config.ini", QSettings::IniFormat);
|
||||||
@ -91,26 +88,20 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
"deskmod", "evidence", "cccc_ic_support",
|
"deskmod", "evidence", "cccc_ic_support",
|
||||||
"arup", "casing_alerts", "modcall_reason",
|
"arup", "casing_alerts", "modcall_reason",
|
||||||
"looping_sfx", "additive", "effects"};
|
"looping_sfx", "additive", "effects"};
|
||||||
AOPacket response_pn(
|
|
||||||
"PN", {QString::number(server->player_count), max_players});
|
sendPacket("PN", {QString::number(server->player_count), max_players});
|
||||||
AOPacket response_fl("FL", feature_list);
|
sendPacket("FL", feature_list);
|
||||||
sendPacket(response_pn);
|
|
||||||
sendPacket(response_fl);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "askchaa") {
|
else if (packet.header == "askchaa") {
|
||||||
// TODO: add user configurable content
|
// TODO: add user configurable content
|
||||||
// For testing purposes, we will just send enough to get things working
|
// For testing purposes, we will just send enough to get things working
|
||||||
AOPacket response(
|
sendPacket("SI", {QString::number(server->characters.length()), "0", QString::number(server->area_names.length() + server->music_list.length())});
|
||||||
"SI", {QString::number(server->characters.length()), "0", QString::number(server->area_names.length() + server->music_list.length())});
|
|
||||||
sendPacket(response);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "RC") {
|
else if (packet.header == "RC") {
|
||||||
AOPacket response("SC", server->characters);
|
sendPacket("SC", server->characters);
|
||||||
sendPacket(response);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "RM") {
|
else if (packet.header == "RM") {
|
||||||
AOPacket response("SM", server->area_names + server->music_list);
|
sendPacket("SM", server->area_names + server->music_list);
|
||||||
sendPacket(response);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "RD") {
|
else if (packet.header == "RD") {
|
||||||
server->player_count++;
|
server->player_count++;
|
||||||
@ -120,12 +111,9 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
QSettings areas_ini("areas.ini", QSettings::IniFormat);
|
QSettings areas_ini("areas.ini", QSettings::IniFormat);
|
||||||
QStringList areas = areas_ini.childGroups();
|
QStringList areas = areas_ini.childGroups();
|
||||||
|
|
||||||
AOPacket response_fa("FA", areas);
|
sendPacket("FA", areas);
|
||||||
AOPacket response_op("OPPASS", {"DEADBEEF"});
|
sendPacket("OPPASS", {"DEADBEEF"});
|
||||||
AOPacket response_done("DONE", {});
|
sendPacket("DONE");
|
||||||
sendPacket(response_fa);
|
|
||||||
sendPacket(response_op);
|
|
||||||
sendPacket(response_done);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "PW") {
|
else if (packet.header == "PW") {
|
||||||
password = packet.contents[0];
|
password = packet.contents[0];
|
||||||
@ -157,8 +145,7 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
server->updateCharsTaken(server->areas.value(current_area));
|
server->updateCharsTaken(server->areas.value(current_area));
|
||||||
AOPacket response_pv("PV", {"271828", "CID", packet.contents[1]});
|
sendPacket("PV", {"271828", "CID", packet.contents[1]});
|
||||||
sendPacket(response_pv);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "MS") {
|
else if (packet.header == "MS") {
|
||||||
// TODO: validate, validate, validate
|
// TODO: validate, validate, validate
|
||||||
@ -173,13 +160,7 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
// Why does this packet exist
|
// Why does this packet exist
|
||||||
// At least Crystal made it useful
|
// At least Crystal made it useful
|
||||||
// It is now used for ping measurement
|
// It is now used for ping measurement
|
||||||
AOPacket response("CHECK", {});
|
sendPacket("CHECK");
|
||||||
sendPacket(response);
|
|
||||||
}
|
|
||||||
else if (packet.header == "whoami") {
|
|
||||||
AOPacket response(
|
|
||||||
"CT", {"Made with love", "by scatterflower and windrammer"});
|
|
||||||
sendPacket(response);
|
|
||||||
}
|
}
|
||||||
else if (packet.header == "MC") {
|
else if (packet.header == "MC") {
|
||||||
// Due to historical reasons, this
|
// Due to historical reasons, this
|
||||||
@ -190,34 +171,21 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
// argument is a valid song
|
// argument is a valid song
|
||||||
QString argument = packet.contents[0];
|
QString argument = packet.contents[0];
|
||||||
|
|
||||||
bool is_song = false;
|
|
||||||
for (QString song : server->music_list) {
|
for (QString song : server->music_list) {
|
||||||
if (song == argument) {
|
if (song == argument) {
|
||||||
is_song = true;
|
// If we have a song, retransmit as-is
|
||||||
break;
|
server->broadcast(packet, current_area);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_song) {
|
for (int i = 0; i < server->area_names.length(); i++) {
|
||||||
// If we have a song, retransmit as-is
|
QString area = server->area_names[i];
|
||||||
server->broadcast(packet, current_area);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_area = false;
|
|
||||||
for (QString area : server->area_names) {
|
|
||||||
if(area == argument) {
|
if(area == argument) {
|
||||||
is_area = true;
|
changeArea(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_area) {
|
|
||||||
// TODO: change area function that resends all area data and sets user stuff
|
|
||||||
// For now, we pretend
|
|
||||||
AOPacket user_message("CT", {"Server", "Changed to area " + argument});
|
|
||||||
sendPacket(user_message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "Unimplemented packet:" << packet.header;
|
qDebug() << "Unimplemented packet:" << packet.header;
|
||||||
@ -225,6 +193,27 @@ void AOClient::handlePacket(AOPacket packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOClient::changeArea(int new_area)
|
||||||
|
{
|
||||||
|
if (current_char != "") {
|
||||||
|
server->areas.value(current_area)->characters_taken[current_char] =
|
||||||
|
false;
|
||||||
|
server->updateCharsTaken(server->areas.value(current_area));
|
||||||
|
}
|
||||||
|
current_area = new_area;
|
||||||
|
// send hp, bn, le, arup
|
||||||
|
if(server->areas.value(current_area)->characters_taken[current_char]) {
|
||||||
|
server->updateCharsTaken(server->areas.value(current_area));
|
||||||
|
current_char = "";
|
||||||
|
sendPacket("DONE");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
server->areas.value(current_area)->characters_taken[current_char] = true;
|
||||||
|
server->updateCharsTaken(server->areas.value(current_area));
|
||||||
|
}
|
||||||
|
sendPacket("CT", {"Server", "You have been moved to area " + server->area_names[current_area], "1"});
|
||||||
|
}
|
||||||
|
|
||||||
void AOClient::sendPacket(AOPacket packet)
|
void AOClient::sendPacket(AOPacket packet)
|
||||||
{
|
{
|
||||||
qDebug() << "Sent packet:" << packet.header << ":" << packet.contents;
|
qDebug() << "Sent packet:" << packet.header << ":" << packet.contents;
|
||||||
@ -232,6 +221,16 @@ void AOClient::sendPacket(AOPacket packet)
|
|||||||
socket->flush();
|
socket->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOClient::sendPacket(QString header, QStringList contents)
|
||||||
|
{
|
||||||
|
sendPacket(AOPacket(header, contents));
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOClient::sendPacket(QString header)
|
||||||
|
{
|
||||||
|
sendPacket(AOPacket(header, {}));
|
||||||
|
}
|
||||||
|
|
||||||
QString AOClient::getHwid() { return hwid; }
|
QString AOClient::getHwid() { return hwid; }
|
||||||
|
|
||||||
void AOClient::setHwid(QString p_hwid)
|
void AOClient::setHwid(QString p_hwid)
|
||||||
|
Loading…
Reference in New Issue
Block a user