From 9985b7daf8ad24733eb437f0cf950a22a1d297d2 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 17:43:20 -0600 Subject: [PATCH] fix bounds checking, add /play --- include/aoclient.h | 3 +++ include/server.h | 1 + src/commands.cpp | 7 ++++++- src/packets.cpp | 5 +++-- src/server.cpp | 10 ++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index b169633..9184346 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -57,6 +57,7 @@ class AOClient : public QObject { bool authenticated = false; QString moderator_name = ""; QString ooc_name = ""; + QString showname = ""; QMap ACLFlags { {"NONE", 0ULL}, @@ -196,6 +197,7 @@ class AOClient : public QObject { void cmdBan(int argc, QStringList argv); void cmdKick(int argc, QStringList argv); // Casing/RP + void cmdPlay(int argc, QStringList argv); void cmdNeed(int argc, QStringList argv); void cmdFlip(int argc, QStringList argv); void cmdRoll(int argc, QStringList argv); @@ -257,6 +259,7 @@ class AOClient : public QObject { {"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}}, {"timer", {ACLFlags.value("CM"), 0, &AOClient::cmdTimer}}, {"area", {ACLFlags.value("NONE"), 1, &AOClient::cmdArea}}, + {"play", {ACLFlags.value("CM"), 1, &AOClient::cmdPlay}}, }; QString partial_packet; diff --git a/include/server.h b/include/server.h index ae7db9c..152fc37 100644 --- a/include/server.h +++ b/include/server.h @@ -53,6 +53,7 @@ class Server : public QObject { void broadcast(AOPacket packet); QString getServerName(); int getDiceValue(QString value_type); + int getCharID(QString char_name); QVector clients; diff --git a/src/commands.cpp b/src/commands.cpp index 58847c9..4488160 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -641,13 +641,18 @@ void AOClient::cmdArea(int argc, QStringList argv) { bool ok; int new_area = argv[0].toInt(&ok); - if (!ok || new_area > server->areas.size() || new_area < 0) { + if (!ok || new_area >= server->areas.size() || new_area < 0) { sendServerMessage("That does not look like a valid area ID."); return; } changeArea(new_area); } +void AOClient::cmdPlay(int argc, QStringList argv) +{ + sendPacket("MC", {argv.join(" "), QString::number(server->getCharID(current_char)), showname, "1", "0"}); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index 39d9997..c8b7ebc 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -454,8 +454,9 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) // 2.6 packet extensions if (incoming_args.length() > 15) { // showname - QString showname = dezalgo(incoming_args[15].toString().trimmed()); - args.append(showname); + QString incoming_showname = dezalgo(incoming_args[15].toString().trimmed()); + args.append(incoming_showname); + showname = incoming_showname; // other char id // things get a bit hairy here diff --git a/src/server.cpp b/src/server.cpp index b9acff4..29194da 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -191,6 +191,16 @@ AOClient* Server::getClientByID(int id) return nullptr; } +int Server::getCharID(QString char_name) +{ + for (QString character : characters) { + if (character == char_name) { + return characters.indexOf(character); + } + } + return -1; // character does not exist +} + Server::~Server() { for (AOClient* client : clients) {