add CMing and document commands
This commit is contained in:
parent
c6758ea337
commit
033d4f93e5
@ -38,7 +38,7 @@ class Server;
|
|||||||
class AOClient : public QObject {
|
class AOClient : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr);
|
AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent = nullptr, int user_id = 0);
|
||||||
~AOClient();
|
~AOClient();
|
||||||
|
|
||||||
QString getHwid();
|
QString getHwid();
|
||||||
@ -46,6 +46,8 @@ class AOClient : public QObject {
|
|||||||
Server* getServer();
|
Server* getServer();
|
||||||
void setHwid(QString p_hwid);
|
void setHwid(QString p_hwid);
|
||||||
|
|
||||||
|
int id;
|
||||||
|
|
||||||
QHostAddress remote_ip;
|
QHostAddress remote_ip;
|
||||||
QString password;
|
QString password;
|
||||||
bool joined;
|
bool joined;
|
||||||
@ -152,28 +154,37 @@ class AOClient : public QObject {
|
|||||||
{"EE", {ACLFlags.value("NONE"), 4, &AOClient::pktEditEvidence}}
|
{"EE", {ACLFlags.value("NONE"), 4, &AOClient::pktEditEvidence}}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Commands
|
//// Commands
|
||||||
void cmdDefault(int argc, QStringList argv);
|
void cmdDefault(int argc, QStringList argv);
|
||||||
|
// Authentication
|
||||||
void cmdLogin(int argc, QStringList argv);
|
void cmdLogin(int argc, QStringList argv);
|
||||||
void cmdGetAreas(int argc, QStringList argv);
|
|
||||||
void cmdGetArea(int argc, QStringList argv);
|
|
||||||
void cmdBan(int argc, QStringList argv);
|
|
||||||
void cmdKick(int argc, QStringList argv);
|
|
||||||
void cmdChangeAuth(int argc, QStringList argv);
|
void cmdChangeAuth(int argc, QStringList argv);
|
||||||
void cmdSetRootPass(int argc, QStringList argv);
|
void cmdSetRootPass(int argc, QStringList argv);
|
||||||
void cmdSetBackground(int argc, QStringList argv);
|
|
||||||
void cmdBgLock(int argc, QStringList argv);
|
|
||||||
void cmdBgUnlock(int argc, QStringList argv);
|
|
||||||
void cmdAddUser(int argc, QStringList argv);
|
void cmdAddUser(int argc, QStringList argv);
|
||||||
void cmdListPerms(int argc, QStringList argv);
|
void cmdListPerms(int argc, QStringList argv);
|
||||||
void cmdAddPerms(int argc, QStringList argv);
|
void cmdAddPerms(int argc, QStringList argv);
|
||||||
void cmdRemovePerms(int argc, QStringList argv);
|
void cmdRemovePerms(int argc, QStringList argv);
|
||||||
void cmdListUsers(int argc, QStringList argv);
|
void cmdListUsers(int argc, QStringList argv);
|
||||||
void cmdLogout(int argc, QStringList argv);
|
void cmdLogout(int argc, QStringList argv);
|
||||||
void cmdPos(int argc, QStringList argv);
|
// Areas
|
||||||
void cmdG(int argc, QStringList argv);
|
void cmdCM(int argc, QStringList argv);
|
||||||
|
void cmdUnCM(int argc, QStringList argv);
|
||||||
|
void cmdGetAreas(int argc, QStringList argv);
|
||||||
|
void cmdGetArea(int argc, QStringList argv);
|
||||||
|
void cmdSetBackground(int argc, QStringList argv);
|
||||||
|
void cmdBgLock(int argc, QStringList argv);
|
||||||
|
void cmdBgUnlock(int argc, QStringList argv);
|
||||||
|
// Moderation
|
||||||
|
void cmdBan(int argc, QStringList argv);
|
||||||
|
void cmdKick(int argc, QStringList argv);
|
||||||
|
// Casing/RP
|
||||||
void cmdNeed(int argc, QStringList argv);
|
void cmdNeed(int argc, QStringList argv);
|
||||||
void cmdFlip(int argc, QStringList argv);
|
void cmdFlip(int argc, QStringList argv);
|
||||||
|
void cmdDoc(int argc, QStringList argv);
|
||||||
|
void cmdClearDoc(int argc, QStringList argv);
|
||||||
|
// Messaging/Client
|
||||||
|
void cmdPos(int argc, QStringList argv);
|
||||||
|
void cmdG(int argc, QStringList argv);
|
||||||
|
|
||||||
// Command helper functions
|
// Command helper functions
|
||||||
QStringList buildAreaList(int area_idx);
|
QStringList buildAreaList(int area_idx);
|
||||||
@ -209,7 +220,11 @@ class AOClient : public QObject {
|
|||||||
{"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}},
|
{"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}},
|
||||||
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
|
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
|
||||||
{"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}},
|
{"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}},
|
||||||
{"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}}
|
{"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}},
|
||||||
|
{"doc", {ACLFlags.value("NONE"), 0, &AOClient::cmdDoc}},
|
||||||
|
{"cleardoc", {ACLFlags.value("NONE"), 0, &AOClient::cmdClearDoc}},
|
||||||
|
{"cm", {ACLFlags.value("NONE"), 0, &AOClient::cmdCM}},
|
||||||
|
{"uncm", {ACLFlags.value("NONE"), 0, &AOClient::cmdUnCM}}
|
||||||
};
|
};
|
||||||
|
|
||||||
QString partial_packet;
|
QString partial_packet;
|
||||||
|
@ -42,13 +42,19 @@ class AreaData {
|
|||||||
QList<Evidence> evidence;
|
QList<Evidence> evidence;
|
||||||
int player_count;
|
int player_count;
|
||||||
QString status;
|
QString status;
|
||||||
QString current_cm;
|
QList<int> owners;
|
||||||
bool locked;
|
enum LockStatus {
|
||||||
|
FREE,
|
||||||
|
LOCKED,
|
||||||
|
SPECTATABLE
|
||||||
|
};
|
||||||
|
LockStatus locked;
|
||||||
QString background;
|
QString background;
|
||||||
bool showname_allowed;
|
bool showname_allowed;
|
||||||
bool locking_allowed;
|
bool locking_allowed;
|
||||||
bool iniswap_allowed;
|
bool iniswap_allowed;
|
||||||
bool bg_locked;
|
bool bg_locked;
|
||||||
|
QString document;
|
||||||
int def_hp;
|
int def_hp;
|
||||||
int pro_hp;
|
int pro_hp;
|
||||||
Logger* logger;
|
Logger* logger;
|
||||||
|
@ -46,6 +46,7 @@ class Server : public QObject {
|
|||||||
|
|
||||||
void start();
|
void start();
|
||||||
AOClient* getClient(QString ipid);
|
AOClient* getClient(QString ipid);
|
||||||
|
AOClient* getClientByID(int id);
|
||||||
void updateCharsTaken(AreaData* area);
|
void updateCharsTaken(AreaData* area);
|
||||||
void broadcast(AOPacket packet, int area_index);
|
void broadcast(AOPacket packet, int area_index);
|
||||||
void broadcast(AOPacket packet);
|
void broadcast(AOPacket packet);
|
||||||
|
@ -17,11 +17,12 @@
|
|||||||
//////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////
|
||||||
#include "include/aoclient.h"
|
#include "include/aoclient.h"
|
||||||
|
|
||||||
AOClient::AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent)
|
AOClient::AOClient(Server* p_server, QTcpSocket* p_socket, QObject* parent, int user_id)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
socket = p_socket;
|
socket = p_socket;
|
||||||
server = p_server;
|
server = p_server;
|
||||||
|
id = user_id;
|
||||||
joined = false;
|
joined = false;
|
||||||
password = "";
|
password = "";
|
||||||
current_area = 0;
|
current_area = 0;
|
||||||
@ -155,7 +156,16 @@ void AOClient::arup(ARUPType type, bool broadcast)
|
|||||||
arup_data.append(area->status);
|
arup_data.append(area->status);
|
||||||
}
|
}
|
||||||
else if (type == ARUPType::CM) {
|
else if (type == ARUPType::CM) {
|
||||||
arup_data.append(area->current_cm);
|
if (area->owners.isEmpty())
|
||||||
|
arup_data.append("FREE");
|
||||||
|
else {
|
||||||
|
QStringList area_owners;
|
||||||
|
for (int owner_id : area->owners) {
|
||||||
|
AOClient* owner = server->getClientByID(owner_id);
|
||||||
|
area_owners.append("[" + QString::number(owner->id) + "] " + owner->current_char);
|
||||||
|
}
|
||||||
|
arup_data.append(area_owners.join(", "));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (type == ARUPType::LOCKED) {
|
else if (type == ARUPType::LOCKED) {
|
||||||
arup_data.append(area->locked ? "LOCKED" : "FREE");
|
arup_data.append(area->locked ? "LOCKED" : "FREE");
|
||||||
|
@ -29,12 +29,12 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index)
|
|||||||
background = areas_ini.value("background", "gs4").toString();
|
background = areas_ini.value("background", "gs4").toString();
|
||||||
areas_ini.endGroup();
|
areas_ini.endGroup();
|
||||||
player_count = 0;
|
player_count = 0;
|
||||||
current_cm = "FREE";
|
locked = FREE;
|
||||||
locked = false;
|
|
||||||
status = "FREE";
|
status = "FREE";
|
||||||
def_hp = 10;
|
def_hp = 10;
|
||||||
pro_hp = 10;
|
pro_hp = 10;
|
||||||
bg_locked = false;
|
bg_locked = false;
|
||||||
|
document = "No document.";
|
||||||
QSettings config_ini("config/config.ini", QSettings::IniFormat);
|
QSettings config_ini("config/config.ini", QSettings::IniFormat);
|
||||||
config_ini.beginGroup("Options");
|
config_ini.beginGroup("Options");
|
||||||
int log_size = config_ini.value("logbuffer", 50).toInt();
|
int log_size = config_ini.value("logbuffer", 50).toInt();
|
||||||
|
@ -394,6 +394,71 @@ void AOClient::cmdFlip(int argc, QStringList argv)
|
|||||||
sendServerMessage(sender_name + " flipped a coin and got " + face + ".");
|
sendServerMessage(sender_name + " flipped a coin and got " + face + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOClient::cmdDoc(int argc, QStringList argv)
|
||||||
|
{
|
||||||
|
QString sender_name = ooc_name;
|
||||||
|
AreaData* area = server->areas[current_area];
|
||||||
|
if (argc == 0) {
|
||||||
|
sendServerMessage("Document: " + area->document);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
area->document = argv.join(" ");
|
||||||
|
sendServerMessage(sender_name + " changed the document."); // broadcast this!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOClient::cmdClearDoc(int argc, QStringList argv)
|
||||||
|
{
|
||||||
|
QString sender_name = ooc_name;
|
||||||
|
AreaData* area = server->areas[current_area];
|
||||||
|
area->document = "No document.";
|
||||||
|
sendServerMessage(sender_name + " cleared the document."); // broadcast this!
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOClient::cmdCM(int argc, QStringList argv)
|
||||||
|
{
|
||||||
|
QString sender_name = ooc_name;
|
||||||
|
AreaData* area = server->areas[current_area];
|
||||||
|
if (area->owners.isEmpty()) {
|
||||||
|
area->owners.append(id);
|
||||||
|
sendServerMessage(sender_name + " is now CM in this area."); // broadcast this!
|
||||||
|
arup(ARUPType::CM, true);
|
||||||
|
}
|
||||||
|
else if (!area->owners.contains(id)) {
|
||||||
|
sendServerMessage("You cannot become a CM in this area.");
|
||||||
|
}
|
||||||
|
else if (argc == 1) {
|
||||||
|
bool ok;
|
||||||
|
AOClient* owner_candidate = server->getClientByID(argv[0].toInt(&ok));
|
||||||
|
if (!ok) {
|
||||||
|
sendServerMessage("That doesn't look like a valid ID.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (owner_candidate == nullptr) {
|
||||||
|
sendServerMessage("Unable to find client with ID " + argv[0] + ".");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
area->owners.append(owner_candidate->id);
|
||||||
|
sendServerMessage(owner_candidate->ooc_name + " is now CM in this area."); // broadcast this!
|
||||||
|
arup(ARUPType::CM, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sendServerMessage("You are already a CM in this area.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void AOClient::cmdUnCM(int argc, QStringList argv)
|
||||||
|
{
|
||||||
|
AreaData* area = server->areas[current_area];
|
||||||
|
int removed = area->owners.removeAll(id);
|
||||||
|
if (removed == 0)
|
||||||
|
sendServerMessage("You are not a CM in this area.");
|
||||||
|
else {
|
||||||
|
sendServerMessage("You are no longer CM in this area.");
|
||||||
|
arup(ARUPType::CM, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList AOClient::buildAreaList(int area_idx)
|
QStringList AOClient::buildAreaList(int area_idx)
|
||||||
{
|
{
|
||||||
QStringList entries;
|
QStringList entries;
|
||||||
@ -403,9 +468,9 @@ QStringList AOClient::buildAreaList(int area_idx)
|
|||||||
entries.append("[" + QString::number(area->player_count) + " users][" + area->status + "]");
|
entries.append("[" + QString::number(area->player_count) + " users][" + area->status + "]");
|
||||||
for (AOClient* client : server->clients) {
|
for (AOClient* client : server->clients) {
|
||||||
if (client->current_area == area_idx && client->joined) {
|
if (client->current_area == area_idx && client->joined) {
|
||||||
QString char_entry = client->current_char;
|
QString char_entry = "[" + QString::number(client->id) + "] " + client->current_char;
|
||||||
if (char_entry == "")
|
if (client->current_char == "")
|
||||||
char_entry = "Spectator";
|
char_entry += "Spectator";
|
||||||
if (authenticated)
|
if (authenticated)
|
||||||
char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
|
char_entry += " (" + client->getIpid() + "): " + client->ooc_name;
|
||||||
entries.append(char_entry);
|
entries.append(char_entry);
|
||||||
|
@ -142,6 +142,7 @@ void AOClient::pktSelectChar(AreaData* area, int argc, QStringList argv, AOPacke
|
|||||||
|
|
||||||
server->updateCharsTaken(area);
|
server->updateCharsTaken(area);
|
||||||
sendPacket("PV", {"271828", "CID", argv[1]});
|
sendPacket("PV", {"271828", "CID", argv[1]});
|
||||||
|
fullArup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket packet)
|
||||||
|
@ -92,7 +92,18 @@ void Server::start()
|
|||||||
void Server::clientConnected()
|
void Server::clientConnected()
|
||||||
{
|
{
|
||||||
QTcpSocket* socket = server->nextPendingConnection();
|
QTcpSocket* socket = server->nextPendingConnection();
|
||||||
AOClient* client = new AOClient(this, socket, this);
|
int user_id;
|
||||||
|
QList<int> user_ids;
|
||||||
|
for (AOClient* client : clients) {
|
||||||
|
user_ids.append(client->id);
|
||||||
|
}
|
||||||
|
for (user_id = 0; user_id <= player_count; user_id++) {
|
||||||
|
if (user_ids.contains(user_id))
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
AOClient* client = new AOClient(this, socket, this, user_id);
|
||||||
if (db_manager->isIPBanned(socket->peerAddress())) {
|
if (db_manager->isIPBanned(socket->peerAddress())) {
|
||||||
AOPacket ban_reason("BD", {db_manager->getBanReason(socket->peerAddress())});
|
AOPacket ban_reason("BD", {db_manager->getBanReason(socket->peerAddress())});
|
||||||
socket->write(ban_reason.toUtf8());
|
socket->write(ban_reason.toUtf8());
|
||||||
@ -156,6 +167,15 @@ AOClient* Server::getClient(QString ipid)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AOClient* Server::getClientByID(int id)
|
||||||
|
{
|
||||||
|
for (AOClient* client : clients) {
|
||||||
|
if (client->id == id)
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
{
|
{
|
||||||
for (AOClient* client : clients) {
|
for (AOClient* client : clients) {
|
||||||
|
Loading…
Reference in New Issue
Block a user