diff --git a/include/aoclient.h b/include/aoclient.h index 9184346..6b96979 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -97,6 +97,7 @@ class AOClient : public QObject { void handlePacket(AOPacket packet); void handleCommand(QString command, int argc, QStringList argv); void changeArea(int new_area); + void changeCharacter(int char_id); void arup(ARUPType type, bool broadcast); void fullArup(); void sendServerMessage(QString message); @@ -190,6 +191,7 @@ class AOClient : public QObject { void cmdGetAreas(int argc, QStringList argv); void cmdGetArea(int argc, QStringList argv); void cmdArea(int argc, QStringList argv); + void cmdAreaKick(int argc, QStringList argv); void cmdSetBackground(int argc, QStringList argv); void cmdBgLock(int argc, QStringList argv); void cmdBgUnlock(int argc, QStringList argv); @@ -207,6 +209,8 @@ class AOClient : public QObject { void cmdTimer(int argc, QStringList argv); // Messaging/Client void cmdPos(int argc, QStringList argv); + void cmdSwitch(int argc, QStringList argv); + void cmdRandomChar(int argc, QStringList argv); void cmdG(int argc, QStringList argv); // Command helper functions @@ -260,6 +264,9 @@ class AOClient : public QObject { {"timer", {ACLFlags.value("CM"), 0, &AOClient::cmdTimer}}, {"area", {ACLFlags.value("NONE"), 1, &AOClient::cmdArea}}, {"play", {ACLFlags.value("CM"), 1, &AOClient::cmdPlay}}, + {"areakick", {ACLFlags.value("CM"), 1, &AOClient::cmdAreaKick}}, + {"randomchar", {ACLFlags.value("NONE"), 0, &AOClient::cmdRandomChar}}, + {"switch", {ACLFlags.value("NONE"), 1, &AOClient::cmdSwitch}}, }; QString partial_packet; diff --git a/src/aoclient.cpp b/src/aoclient.cpp index 7d3a90c..5a7f3ac 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -145,6 +145,54 @@ void AOClient::changeArea(int new_area) sendServerMessage("Area " + server->area_names[current_area] + " is spectate-only; to chat IC you will need to be invited by the CM."); } +void AOClient::changeCharacter(int char_id) +{ + AreaData* area = server->areas[current_area]; + + if (current_char != "") { + area->characters_taken[current_char] = false; + } + + if(char_id > server->characters.length()) + return; + + if (char_id >= 0) { + QString char_selected = server->characters[char_id]; + bool taken = area->characters_taken.value(char_selected); + if (taken || char_selected == "") + return; + + area->characters_taken[char_selected] = true; + current_char = char_selected; + } + else { + current_char = ""; + } + + pos = ""; + + server->updateCharsTaken(area); + sendPacket("PV", {QString::number(id), "CID", QString::number(char_id)}); + fullArup(); + if (server->timer->isActive()) { + sendPacket("TI", {QString::number(0), QString::number(2)}); + sendPacket("TI", {QString::number(0), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(server->timer->remainingTime())))}); + } + else { + sendPacket("TI", {QString::number(0), QString::number(3)}); + } + for (QTimer* timer : area->timers) { + int timer_id = area->timers.indexOf(timer) + 1; + if (timer->isActive()) { + sendPacket("TI", {QString::number(timer_id), QString::number(2)}); + sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))}); + } + else { + sendPacket("TI", {QString::number(timer_id), QString::number(3)}); + } + } +} + void AOClient::handleCommand(QString command, int argc, QStringList argv) { CommandInfo info = commands.value(command, {false, -1, &AOClient::cmdDefault}); diff --git a/src/commands.cpp b/src/commands.cpp index 4488160..0590ba1 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -653,6 +653,35 @@ void AOClient::cmdPlay(int argc, QStringList argv) sendPacket("MC", {argv.join(" "), QString::number(server->getCharID(current_char)), showname, "1", "0"}); } +void AOClient::cmdAreaKick(int argc, QStringList argv) +{ + bool ok; + int idx = argv[0].toInt(&ok); + if (!ok) { + sendServerMessage("That does not look like a valid ID."); + return; + } + AOClient* client_to_kick = server->getClientByID(idx); + client_to_kick->changeArea(0); + sendServerMessage("Client " + argv[0] + " kicked back to area 0."); +} + +void AOClient::cmdSwitch(int argc, QStringList argv) +{ + int char_id = server->getCharID(argv.join(" ")); + if (char_id == -1) { + sendServerMessage("That does not look like a valid character."); + return; + } + changeCharacter(char_id); +} + +void AOClient::cmdRandomChar(int argc, QStringList argv) +{ + int char_id = genRand(0, server->characters.size() - 1); + changeCharacter(char_id); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index c8b7ebc..4d6c727 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -118,48 +118,7 @@ void AOClient::pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacke return; } - if (current_char != "") { - area->characters_taken[current_char] = false; - } - - if(char_id > server->characters.length()) - return; - - if (char_id >= 0) { - QString char_selected = server->characters[char_id]; - bool taken = area->characters_taken.value(char_selected); - if (taken || char_selected == "") - return; - - area->characters_taken[char_selected] = true; - current_char = char_selected; - } - else { - current_char = ""; - } - - pos = ""; - - server->updateCharsTaken(area); - sendPacket("PV", {QString::number(id), "CID", argv[1]}); - fullArup(); - if (server->timer->isActive()) { - sendPacket("TI", {QString::number(0), QString::number(2)}); - sendPacket("TI", {QString::number(0), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(server->timer->remainingTime())))}); - } - else { - sendPacket("TI", {QString::number(0), QString::number(3)}); - } - for (QTimer* timer : area->timers) { - int timer_id = area->timers.indexOf(timer) + 1; - if (timer->isActive()) { - sendPacket("TI", {QString::number(timer_id), QString::number(2)}); - sendPacket("TI", {QString::number(timer_id), QString::number(0), QString::number(QTime(0,0).msecsTo(QTime(0,0).addMSecs(timer->remainingTime())))}); - } - else { - sendPacket("TI", {QString::number(timer_id), QString::number(3)}); - } - } + changeCharacter(char_id); } void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet) diff --git a/src/server.cpp b/src/server.cpp index 29194da..bbe7fc5 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -194,8 +194,8 @@ AOClient* Server::getClientByID(int id) int Server::getCharID(QString char_name) { for (QString character : characters) { - if (character == char_name) { - return characters.indexOf(character); + if (character.toLower() == char_name.toLower()) { + return characters.indexOf(QRegExp(character, Qt::CaseInsensitive)); } } return -1; // character does not exist