From 69da440e548765feff1f46e302a25666b0030e0f Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sat, 27 Feb 2021 18:00:00 -0600 Subject: [PATCH] add invite system --- include/area_data.h | 1 + src/aoclient.cpp | 5 +++++ src/commands.cpp | 50 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/include/area_data.h b/include/area_data.h index cf0994f..e284915 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -43,6 +43,7 @@ class AreaData { int player_count; QString status; QList owners; + QList invited; enum LockStatus { FREE, LOCKED, diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 7ce234d..a4f4da9 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -68,6 +68,11 @@ void AOClient::clientDisconnected() false; server->updateCharsTaken(server->areas[current_area]); } + for (AreaData* area : server->areas) { + area->owners.removeAll(id); + area->invited.removeAll(id); + } + arup(ARUPType::CM, true); } void AOClient::handlePacket(AOPacket packet) diff --git a/src/commands.cpp b/src/commands.cpp index 45eb066..d4f7cd0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -363,10 +363,6 @@ void AOClient::cmdLogout(int argc, QStringList argv) void AOClient::cmdPos(int argc, QStringList argv) { - if (argv[0] != "def" && argv[0] != "hld" && argv[0] != "pro" && argv[0] != "hlp" && argv[0] != "wit" && argv[0] != "jud" && argv[0] != "jur" && argv[0] != "sea") { - sendServerMessage("Invalid position!"); - return; - } pos = argv[0]; sendServerMessage("Position changed to " + pos + "."); } @@ -421,6 +417,7 @@ void AOClient::cmdCM(int argc, QStringList argv) AreaData* area = server->areas[current_area]; if (area->owners.isEmpty()) { area->owners.append(id); + area->invited.append(id); sendServerMessage(sender_name + " is now CM in this area."); // broadcast this! arup(ARUPType::CM, true); } @@ -450,6 +447,7 @@ void AOClient::cmdUnCM(int argc, QStringList argv) { AreaData* area = server->areas[current_area]; int removed = area->owners.removeAll(id); + area->invited.removeAll(id); if (removed == 0) sendServerMessage("You are not a CM in this area."); else { @@ -457,6 +455,50 @@ void AOClient::cmdUnCM(int argc, QStringList argv) arup(ARUPType::CM, true); } } +void AOClient::cmdInvite(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + bool ok; + int invited_id = argv[0].toInt(&ok); + if (!area->owners.contains(id)) { + sendServerMessage("You are not a CM in this area."); + return; + } + else if (!ok) { + sendServerMessage("That does not look like a valid ID."); + return; + } + else if (area->invited.contains(invited_id)) { + sendServerMessage("That ID is already on the invite list."); + return; + } + area->invited.append(invited_id); + sendServerMessage("You invited ID " + argv[0]); +} +void AOClient::cmdUnInvite(int argc, QStringList argv) +{ + AreaData* area = server->areas[current_area]; + bool ok; + int uninvited_id = argv[0].toInt(&ok); + if (!area->owners.contains(id)) { + sendServerMessage("You are not a CM in this area."); + return; + } + else if (!ok) { + sendServerMessage("That does not look like a valid ID."); + return; + } + else if (area->owners.contains(uninvited_id)) { + sendServerMessage("You cannot uninvite a CM!"); + return; + } + else if (!area->invited.contains(uninvited_id)) { + sendServerMessage("That ID is not on the invite list."); + return; + } + area->invited.removeAll(uninvited_id); + sendServerMessage("You uninvited ID " + argv[0]); +} QStringList AOClient::buildAreaList(int area_idx)