Merge branch 'master' into in1tiate/cming

This commit is contained in:
in1tiate 2021-03-04 05:24:06 -06:00 committed by GitHub
commit f46eeeb94f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 5 deletions

View File

@ -13,4 +13,8 @@ webao_enable=true
webao_port=27017
auth=simple
modpass=changeme
logbuffer=500
logbuffer=500
[Dice]
max_value=100
max_dice=100

View File

@ -85,6 +85,12 @@ class AOClient : public QObject {
LOCKED
};
enum RollType {
ROLL,
ROLLP,
ROLLA
};
void handlePacket(AOPacket packet);
void handleCommand(QString command, int argc, QStringList argv);
void changeArea(int new_area);
@ -188,6 +194,8 @@ class AOClient : public QObject {
// Casing/RP
void cmdNeed(int argc, QStringList argv);
void cmdFlip(int argc, QStringList argv);
void cmdRoll(int argc, QStringList argv);
void cmdRollP(int argc, QStringList argv);
void cmdDoc(int argc, QStringList argv);
void cmdClearDoc(int argc, QStringList argv);
// Messaging/Client
@ -197,6 +205,7 @@ class AOClient : public QObject {
// Command helper functions
QStringList buildAreaList(int area_idx);
int genRand(int min, int max);
void diceThrower(int argc, QStringList argv, RollType Type);
// Command function global variables
bool change_auth_started = false;
@ -229,6 +238,8 @@ class AOClient : public QObject {
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
{"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}},
{"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}},
{"roll", {ACLFlags.value("NONE"), 0, &AOClient::cmdRoll}},
{"rollp", {ACLFlags.value("NONE"), 0, &AOClient::cmdRollP}},
{"doc", {ACLFlags.value("NONE"), 0, &AOClient::cmdDoc}},
{"cleardoc", {ACLFlags.value("NONE"), 0, &AOClient::cmdClearDoc}},
{"cm", {ACLFlags.value("NONE"), 0, &AOClient::cmdCM}},
@ -238,7 +249,6 @@ class AOClient : public QObject {
{"lock", {ACLFlags.value("CM"), 0, &AOClient::cmdLock}},
{"spectatable", {ACLFlags.value("CM"), 0, &AOClient::cmdSpectatable}},
{"unlock", {ACLFlags.value("CM"), 0, &AOClient::cmdUnLock}},
};
QString partial_packet;

View File

@ -51,6 +51,7 @@ class Server : public QObject {
void broadcast(AOPacket packet, int area_index);
void broadcast(AOPacket packet);
QString getServerName();
int getDiceValue(QString value_type);
QVector<AOClient*> clients;

View File

@ -370,8 +370,9 @@ void AOClient::cmdPos(int argc, QStringList argv)
void AOClient::cmdG(int argc, QStringList argv)
{
QString sender_name = ooc_name;
QString sender_area = server->area_names.value(current_area);
QString sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"[G]" + sender_name, sender_message+ "."}));
server->broadcast(AOPacket("CT", {"[" + sender_area + "]" + sender_name, sender_message}));
return;
}
@ -379,7 +380,7 @@ void AOClient::cmdNeed(int argc, QStringList argv)
{
QString sender_area = server->area_names.value(current_area);
QString sender_message = argv.join(" ");
server->broadcast(AOPacket("CT", {"=== Advert ===","[" + sender_area + "] needs " + sender_message+ "."}));
sendServerBroadcast({"=== Advert ===\n[" + sender_area + "] needs " + sender_message+ "."});
}
void AOClient::cmdFlip(int argc, QStringList argv)
@ -390,6 +391,16 @@ void AOClient::cmdFlip(int argc, QStringList argv)
sendServerMessage(sender_name + " flipped a coin and got " + face + ".");
}
void AOClient::cmdRoll(int argc, QStringList argv)
{
diceThrower(argc, argv, RollType::ROLL);
}
void AOClient::cmdRollP(int argc, QStringList argv)
{
diceThrower(argc, argv, RollType::ROLLP);
}
void AOClient::cmdDoc(int argc, QStringList argv)
{
QString sender_name = ooc_name;
@ -447,6 +458,7 @@ void AOClient::cmdCM(int argc, QStringList argv)
sendServerMessage("You are already a CM in this area.");
}
}
void AOClient::cmdUnCM(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
@ -457,6 +469,7 @@ void AOClient::cmdUnCM(int argc, QStringList argv)
if (area->owners.isEmpty())
area->invited.clear();
}
void AOClient::cmdInvite(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
@ -473,6 +486,7 @@ void AOClient::cmdInvite(int argc, QStringList argv)
area->invited.append(invited_id);
sendServerMessage("You invited ID " + argv[0]);
}
void AOClient::cmdUnInvite(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
@ -493,6 +507,7 @@ void AOClient::cmdUnInvite(int argc, QStringList argv)
area->invited.removeAll(uninvited_id);
sendServerMessage("You uninvited ID " + argv[0]);
}
void AOClient::cmdLock(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
@ -509,6 +524,7 @@ void AOClient::cmdLock(int argc, QStringList argv)
}
arup(ARUPType::LOCKED, true);
}
void AOClient::cmdSpectatable(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
@ -525,6 +541,7 @@ void AOClient::cmdSpectatable(int argc, QStringList argv)
}
arup(ARUPType::LOCKED, true);
}
void AOClient::cmdUnLock(int argc, QStringList argv)
{
AreaData* area = server->areas[current_area];
@ -537,7 +554,6 @@ void AOClient::cmdUnLock(int argc, QStringList argv)
arup(ARUPType::LOCKED, true);
}
QStringList AOClient::buildAreaList(int area_idx)
{
QStringList entries;
@ -583,3 +599,61 @@ int AOClient::genRand(int min, int max)
return random_number;
#endif
}
void AOClient::diceThrower(int argc, QStringList argv, RollType type)
{
QString sender_name = ooc_name;
int max_value = server->getDiceValue("max_value");
int max_dice = server->getDiceValue("max_dice");
int bounded_value;
int bounded_amount;
QString dice_results;
if (argc == 0) {
dice_results = QString::number(genRand(1, 6)); // Self-explanatory
}
else if (argc == 1) {
bounded_value = qBound(1, argv[0].toInt(), max_value); // faces, max faces
dice_results = QString::number(genRand(1, bounded_value));
}
else if (argc == 2) {
bounded_value = qBound(1, argv[0].toInt(), max_value); // 1, faces, max faces
bounded_amount = qBound(1, argv[1].toInt(), max_dice); // 1, amount, max amount
for (int i = 1; i <= bounded_amount ; i++) // Loop as multiple dices are thrown
{
QString dice_result = QString::number(genRand(1, bounded_value));
if (i == bounded_amount) {
dice_results = dice_results.append(dice_result);
}
else {
dice_results = dice_results.append(dice_result + ",");
}
}
}
// Switch to change message behaviour, isEmpty check or the entire server crashes due to an out of range issue in the QStringList
switch(type)
{
case ROLL:
if (argv.isEmpty()) {
sendServerMessageArea(sender_name + " rolled " + dice_results + " out of 6");
}
else {
sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value));
}
break;
case ROLLP:
if (argv.isEmpty()) {
sendServerMessage(sender_name + " rolled " + dice_results + " out of 6");
sendServerMessageArea((sender_name + " rolled in secret."));
}
else {
sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value));
sendServerMessageArea((sender_name + " rolled in secret."));
}
break;
case ROLLA:
//Not implemented yet
default : break;
}
}

View File

@ -162,6 +162,16 @@ QString Server::getServerName()
return server_name;
}
int Server::getDiceValue(QString value_type)
{
QSettings settings("config/config.ini", QSettings::IniFormat);
settings.beginGroup("Dice");
int value = settings.value(value_type, "100").toUInt();
settings.endGroup();
return value;
}
AOClient* Server::getClient(QString ipid)
{
for (AOClient* client : clients) {