Merge pull request #214 from Salanto/better-packet-targeting
Make it easier to reuse code targeting specific user groups
This commit is contained in:
commit
2b5bccc959
@ -307,6 +307,16 @@ class AOClient : public QObject {
|
|||||||
*/
|
*/
|
||||||
bool m_is_logging_in = false;
|
bool m_is_logging_in = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if the client would be authorised to something based on its necessary permissions.
|
||||||
|
*
|
||||||
|
* @param acl_mask The permissions bitflag that the client's own permissions should be checked against.
|
||||||
|
*
|
||||||
|
* @return True if the client's permissions are high enough for `acl_mask`, or higher than it.
|
||||||
|
* False if the client is missing some permissions.
|
||||||
|
*/
|
||||||
|
bool checkAuth(unsigned long long acl_mask);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
/**
|
/**
|
||||||
* @brief A slot for when the client disconnects from the server.
|
* @brief A slot for when the client disconnects from the server.
|
||||||
@ -433,16 +443,6 @@ class AOClient : public QObject {
|
|||||||
*/
|
*/
|
||||||
void sendServerBroadcast(QString message);
|
void sendServerBroadcast(QString message);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks if the client would be authorised to something based on its necessary permissions.
|
|
||||||
*
|
|
||||||
* @param acl_mask The permissions bitflag that the client's own permissions should be checked against.
|
|
||||||
*
|
|
||||||
* @return True if the client's permissions are high enough for `acl_mask`, or higher than it.
|
|
||||||
* False if the client is missing some permissions.
|
|
||||||
*/
|
|
||||||
bool checkAuth(unsigned long long acl_mask);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Packet headers
|
* @name Packet headers
|
||||||
*
|
*
|
||||||
|
@ -75,6 +75,16 @@ class Server : public QObject {
|
|||||||
*/
|
*/
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enum to specifc different targets to send altered packets to a specific usergroup.
|
||||||
|
*/
|
||||||
|
enum class TARGET_TYPE {
|
||||||
|
AUTHENTICATED,
|
||||||
|
MODCHAT,
|
||||||
|
ADVERT
|
||||||
|
};
|
||||||
|
Q_ENUM(TARGET_TYPE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets a pointer to a client by IPID.
|
* @brief Gets a pointer to a client by IPID.
|
||||||
*
|
*
|
||||||
@ -129,6 +139,26 @@ class Server : public QObject {
|
|||||||
*/
|
*/
|
||||||
void broadcast(AOPacket packet);
|
void broadcast(AOPacket packet);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sends a packet to clients, sends an altered packet to a specific usergroup.
|
||||||
|
*
|
||||||
|
* @param The packet to send to the clients.
|
||||||
|
*
|
||||||
|
* @param ENUM to determine the targets of the altered packet.
|
||||||
|
*/
|
||||||
|
void broadcast(AOPacket packet, TARGET_TYPE target);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sends a packet to clients, sends an altered packet to a specific usergroup.
|
||||||
|
*
|
||||||
|
* @param The packet to send to the clients.
|
||||||
|
*
|
||||||
|
* @param The altered packet to send to the other clients.
|
||||||
|
*
|
||||||
|
* @param ENUM to determine the targets of the altered packet.
|
||||||
|
*/
|
||||||
|
void broadcast(AOPacket packet, AOPacket other_packet, enum TARGET_TYPE target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the character's character ID (= their index in the character list).
|
* @brief Returns the character's character ID (= their index in the character list).
|
||||||
*
|
*
|
||||||
|
@ -71,10 +71,10 @@ void AOClient::cmdG(int argc, QStringList argv)
|
|||||||
QString l_sender_name = m_ooc_name;
|
QString l_sender_name = m_ooc_name;
|
||||||
QString l_sender_area = server->m_area_names.value(m_current_area);
|
QString l_sender_area = server->m_area_names.value(m_current_area);
|
||||||
QString l_sender_message = argv.join(" ");
|
QString l_sender_message = argv.join(" ");
|
||||||
for (AOClient* l_client : qAsConst(server->m_clients)) {
|
//Slightly better readability
|
||||||
if (l_client->m_global_enabled)
|
AOPacket l_packet = AOPacket("CT", {"[G][" + m_ipid + "][" + l_sender_area + "]" + l_sender_name, l_sender_message});
|
||||||
l_client->sendPacket("CT", {"[G][" + l_sender_area + "]" + l_sender_name, l_sender_message});
|
AOPacket l_other_packet = AOPacket("CT", {"[G][" + l_sender_area + "]" + l_sender_name, l_sender_message});
|
||||||
}
|
server->broadcast(l_packet, l_other_packet, Server::TARGET_TYPE::AUTHENTICATED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,11 +84,7 @@ void AOClient::cmdNeed(int argc, QStringList argv)
|
|||||||
|
|
||||||
QString l_sender_area = server->m_area_names.value(m_current_area);
|
QString l_sender_area = server->m_area_names.value(m_current_area);
|
||||||
QString l_sender_message = argv.join(" ");
|
QString l_sender_message = argv.join(" ");
|
||||||
for (AOClient* l_client : qAsConst(server->m_clients)) {
|
server->broadcast(AOPacket("CT",{"=== Advert ===\n[" + l_sender_area + "] needs " + l_sender_message+ "."}),Server::TARGET_TYPE::ADVERT);
|
||||||
if (l_client->m_advert_enabled) {
|
|
||||||
l_client->sendServerMessage({"=== Advert ===\n[" + l_sender_area + "] needs " + l_sender_message+ "."});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOClient::cmdSwitch(int argc, QStringList argv)
|
void AOClient::cmdSwitch(int argc, QStringList argv)
|
||||||
@ -174,11 +170,7 @@ void AOClient::cmdM(int argc, QStringList argv)
|
|||||||
|
|
||||||
QString l_sender_name = m_ooc_name;
|
QString l_sender_name = m_ooc_name;
|
||||||
QString l_sender_message = argv.join(" ");
|
QString l_sender_message = argv.join(" ");
|
||||||
for (AOClient* client : qAsConst(server->m_clients)) {
|
server->broadcast(AOPacket("CT", {"[M]" + l_sender_name, l_sender_message}), Server::TARGET_TYPE::MODCHAT);
|
||||||
if (client->checkAuth(ACLFlags.value("MODCHAT")))
|
|
||||||
client->sendPacket("CT", {"[M]" + l_sender_name, l_sender_message});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOClient::cmdGM(int argc, QStringList argv)
|
void AOClient::cmdGM(int argc, QStringList argv)
|
||||||
@ -188,11 +180,7 @@ void AOClient::cmdGM(int argc, QStringList argv)
|
|||||||
QString l_sender_name = m_ooc_name;
|
QString l_sender_name = m_ooc_name;
|
||||||
QString l_sender_area = server->m_area_names.value(m_current_area);
|
QString l_sender_area = server->m_area_names.value(m_current_area);
|
||||||
QString l_sender_message = argv.join(" ");
|
QString l_sender_message = argv.join(" ");
|
||||||
for (AOClient* l_client : qAsConst(server->m_clients)) {
|
server->broadcast(AOPacket("CT", {"[G][" + l_sender_area + "]" + "["+ l_sender_name+"][M]", l_sender_message}),Server::TARGET_TYPE::MODCHAT);
|
||||||
if (l_client->m_global_enabled) {
|
|
||||||
l_client->sendPacket("CT", {"[G][" + l_sender_area + "]" + "["+ l_sender_name+"][M]", l_sender_message});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOClient::cmdLM(int argc, QStringList argv)
|
void AOClient::cmdLM(int argc, QStringList argv)
|
||||||
|
@ -215,6 +215,44 @@ void Server::broadcast(AOPacket packet)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::broadcast(AOPacket packet, TARGET_TYPE target)
|
||||||
|
{
|
||||||
|
for (AOClient* l_client : qAsConst(m_clients)) {
|
||||||
|
switch (target) {
|
||||||
|
case TARGET_TYPE::MODCHAT:
|
||||||
|
if (l_client->checkAuth(l_client->ACLFlags.value("MODCHAT"))) {
|
||||||
|
l_client->sendPacket(packet);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TARGET_TYPE::ADVERT:
|
||||||
|
if (l_client->m_advert_enabled) {
|
||||||
|
l_client->sendPacket(packet);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Server::broadcast(AOPacket packet, AOPacket other_packet, TARGET_TYPE target)
|
||||||
|
{
|
||||||
|
switch (target) {
|
||||||
|
case TARGET_TYPE::AUTHENTICATED:
|
||||||
|
for (AOClient* client : qAsConst(m_clients)){
|
||||||
|
if (client->m_authenticated) {
|
||||||
|
client->sendPacket(other_packet);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
client->sendPacket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
//Unimplemented, so not handled.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QList<AOClient*> Server::getClientsByIpid(QString ipid)
|
QList<AOClient*> Server::getClientsByIpid(QString ipid)
|
||||||
{
|
{
|
||||||
QList<AOClient*> return_clients;
|
QList<AOClient*> return_clients;
|
||||||
|
@ -43,10 +43,10 @@ void AOClient::addStatement(QStringList packet)
|
|||||||
area->addStatement(c_statement, packet);
|
area->addStatement(c_statement, packet);
|
||||||
area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK);
|
area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sendServerMessage("Unable to add more statements. The maximum amount of statements has been reached.");
|
sendServerMessage("Unable to add more statements. The maximum amount of statements has been reached.");
|
||||||
area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK);
|
area->setTestimonyRecording(AreaData::TestimonyRecording::PLAYBACK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user