Merge pull request #8 from Salanto/Rolling-Rocks
Add two roll command, fix minor formatting on prior commands
This commit is contained in:
commit
02bb2c2d25
@ -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
|
@ -82,12 +82,20 @@ 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);
|
||||
void arup(ARUPType type, bool broadcast);
|
||||
void fullArup();
|
||||
void sendServerMessage(QString message);
|
||||
void sendServerMessageArea(QString message);
|
||||
void sendServerBroadcast(QString message);
|
||||
bool checkAuth(unsigned long long acl_mask);
|
||||
|
||||
// Packet headers
|
||||
@ -174,10 +182,13 @@ class AOClient : public QObject {
|
||||
void cmdG(int argc, QStringList argv);
|
||||
void cmdNeed(int argc, QStringList argv);
|
||||
void cmdFlip(int argc, QStringList argv);
|
||||
void cmdRoll(int argc, QStringList argv);
|
||||
void cmdRollP(int argc, QStringList argv);
|
||||
|
||||
// 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;
|
||||
@ -209,7 +220,10 @@ class AOClient : public QObject {
|
||||
{"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}},
|
||||
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
|
||||
{"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}},
|
||||
{"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}}
|
||||
{"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}},
|
||||
{"roll", {ACLFlags.value("NONE"), 0, &AOClient::cmdRoll}},
|
||||
{"rollp", {ACLFlags.value("NONE"), 0, &AOClient::cmdRollP}}
|
||||
|
||||
};
|
||||
|
||||
QString partial_packet;
|
||||
|
@ -49,6 +49,8 @@ class Server : public QObject {
|
||||
void updateCharsTaken(AreaData* area);
|
||||
void broadcast(AOPacket packet, int area_index);
|
||||
void broadcast(AOPacket packet);
|
||||
QString getServerName();
|
||||
int getDiceValue(QString value_type);
|
||||
|
||||
QVector<AOClient*> clients;
|
||||
|
||||
@ -59,6 +61,7 @@ class Server : public QObject {
|
||||
QStringList music_list;
|
||||
QStringList backgrounds;
|
||||
DBManager* db_manager;
|
||||
QString server_name;
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -216,7 +216,17 @@ void AOClient::setHwid(QString p_hwid)
|
||||
|
||||
void AOClient::sendServerMessage(QString message)
|
||||
{
|
||||
sendPacket("CT", {"Server", message, "1"});
|
||||
sendPacket("CT", {server->getServerName(), message, "1"});
|
||||
}
|
||||
|
||||
void AOClient::sendServerMessageArea(QString message)
|
||||
{
|
||||
server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"}), current_area);
|
||||
}
|
||||
|
||||
void AOClient::sendServerBroadcast(QString message)
|
||||
{
|
||||
server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"}));
|
||||
}
|
||||
|
||||
bool AOClient::checkAuth(unsigned long long acl_mask)
|
||||
|
@ -374,8 +374,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;
|
||||
}
|
||||
|
||||
@ -383,7 +384,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)
|
||||
@ -394,6 +395,17 @@ 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);
|
||||
}
|
||||
|
||||
QStringList AOClient::buildAreaList(int area_idx)
|
||||
{
|
||||
QStringList entries;
|
||||
@ -426,3 +438,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;
|
||||
}
|
||||
}
|
||||
|
@ -147,6 +147,24 @@ void Server::broadcast(AOPacket packet)
|
||||
}
|
||||
}
|
||||
|
||||
QString Server::getServerName()
|
||||
{
|
||||
QSettings settings("config/config.ini", QSettings::IniFormat);
|
||||
settings.beginGroup("Options");
|
||||
QString server_name = settings.value("server_name", "Akashi").toString();
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user