Add testimony loading and saving
This commit is contained in:
parent
466089ad84
commit
3c5659af22
4
bin/storage/testimony/sample.txt
Normal file
4
bin/storage/testimony/sample.txt
Normal file
@ -0,0 +1,4 @@
|
||||
1#-#Hobo_Phoenix#hobo-normal#~~\n-- Sample Recording --#wit#1#0#22#1#0#0#0#0#3##-1#0#0#0<and>0#0#0#0#0#0#-^(b)hobo-normal^(a)hobo-normal^#-^(b)hobo-normal^(a)hobo-normal^#-^(b)hobo-normal^(a)hobo-normal^#0#||
|
||||
1#-#Hobo_Phoenix#hobo-normal#This is a sample recording to test the loading and saving of testimonies.#wit#1#0#22#1#0#0#0#0#1##-1#0#0#0<and>0#0#0#0#0#0#-^(b)hobo-normal^(a)hobo-normal^#-^(b)hobo-normal^(a)hobo-normal^#-^(b)hobo-normal^(a)hobo-normal^#0#||
|
||||
1#-#Hobo_Phoenix#hobo-bigeyed#If you are reading this your server supports testimony loading correctly.#wit#1#0#22#1#0#0#0#0#1##-1#0#0#0<and>0#0#0#0#0#0#-^(b)hobo-bigeyed^(a)hobo-bigeyed^#-^(b)hobo-bigeyed^(a)hobo-bigeyed^#-^(b)hobo-bigeyed^(a)hobo-bigeyed^#0#||
|
||||
1#-#Hobo_Phoenix#hobo-bigeyed#There is nothing else to be read here.#wit#1#0#22#1#0#0#0#0#1##-1#0#0#0<and>0#0#0#0#0#0#-^(b)hobo-bigeyed^(a)hobo-bigeyed^#-^(b)hobo-bigeyed^(a)hobo-bigeyed^#-^(b)hobo-bigeyed^(a)hobo-bigeyed^#0#||
|
@ -219,6 +219,7 @@ class AOClient : public QObject {
|
||||
{"ANNOUNCE", 1ULL << 8 },
|
||||
{"MODCHAT", 1ULL << 9 },
|
||||
{"MUTE", 1ULL << 10},
|
||||
{"SAVETEST", 1ULL << 11},
|
||||
{"SUPER", ~0ULL },
|
||||
};
|
||||
|
||||
@ -254,6 +255,10 @@ class AOClient : public QObject {
|
||||
*/
|
||||
QTimer* afk_timer;
|
||||
|
||||
/**
|
||||
* @brief Temporary client permission if client is allowed to save a testimony to server storage.
|
||||
*/
|
||||
bool testimony_saving = false;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
@ -1143,6 +1148,16 @@ class AOClient : public QObject {
|
||||
*/
|
||||
void cmdAllowIniswap(int argc, QStringList argv);
|
||||
|
||||
/**
|
||||
* @brief Grants a client the temporary permission to save a testimony.
|
||||
*
|
||||
* @details ClientID as the target of permission
|
||||
*
|
||||
* @iscommand
|
||||
*
|
||||
*/
|
||||
void cmdPermitSaving(int argc, QStringList argv);
|
||||
|
||||
///@}
|
||||
|
||||
/**
|
||||
@ -1533,6 +1548,24 @@ class AOClient : public QObject {
|
||||
*/
|
||||
void cmdAddStatement(int argc, QStringList argv);
|
||||
|
||||
/**
|
||||
* @brief Saves a testimony recording to the servers storage.
|
||||
*
|
||||
* @details Saves a titled text file which contains the edited packets into a text file.
|
||||
*
|
||||
*/
|
||||
void cmdSaveTestimony(int argc, QStringList argv);
|
||||
|
||||
/**
|
||||
* @brief Loads testimony for the testimony replay
|
||||
*
|
||||
* @details Loads a titled text file which contains the edited packets to be loaded into the QVector.
|
||||
* Unlike manually adding statements during testifying there is no size validation as the only
|
||||
* way to create files is saving them.
|
||||
*
|
||||
*/
|
||||
void cmdLoadTestimony(int argc, QStringList argv);
|
||||
|
||||
///@}
|
||||
|
||||
/**
|
||||
@ -1850,6 +1883,9 @@ class AOClient : public QObject {
|
||||
{"allowiniswap", {ACLFlags.value("CM"), 0, &AOClient::cmdAllowIniswap}},
|
||||
{"allow_iniswap", {ACLFlags.value("CM"), 0, &AOClient::cmdAllowIniswap}},
|
||||
{"afk", {ACLFlags.value("NONE"), 0, &AOClient::cmdAfk}},
|
||||
{"savetestimony", {ACLFlags.value("NONE"), 1, &AOClient::cmdSaveTestimony}},
|
||||
{"loadtestimony", {ACLFlags.value("CM"), 1, &AOClient::cmdLoadTestimony}},
|
||||
{"permitsaving", {ACLFlags.value("MODCHAT"), 1, &AOClient::cmdPermitSaving}},
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -153,6 +153,7 @@ void AOClient::cmdPauseTestimony(int argc, QStringList argv)
|
||||
{
|
||||
AreaData* area = server->areas[current_area];
|
||||
area->test_rec = AreaData::TestimonyRecording::STOPPED;
|
||||
server->broadcast(AOPacket("RT",{"testimony1"}), current_area);
|
||||
sendServerMessage("Testimony has been stopped.");
|
||||
}
|
||||
|
||||
@ -165,3 +166,77 @@ void AOClient::cmdAddStatement(int argc, QStringList argv)
|
||||
else
|
||||
sendServerMessage("Unable to add anymore statements. Please remove any unused ones.");
|
||||
}
|
||||
|
||||
void AOClient::cmdSaveTestimony(int argc, QStringList argv)
|
||||
{
|
||||
bool permission_found = false;
|
||||
if (checkAuth(ACLFlags.value("SAVETEST")))
|
||||
permission_found = true;
|
||||
|
||||
if (testimony_saving == true)
|
||||
permission_found = true;
|
||||
|
||||
if (permission_found) {
|
||||
AreaData* area = server->areas[current_area];
|
||||
if (area->testimony.size() -1 <= 0) {
|
||||
sendServerMessage("Can't save an empty testimony.");
|
||||
return;
|
||||
}
|
||||
|
||||
QDir dir_testimony("storage/testimony");
|
||||
if (!dir_testimony.exists()) {
|
||||
dir_testimony.mkpath(".");
|
||||
}
|
||||
|
||||
QString testimony_name = argv[0].trimmed().toLower().replace("..",""); // :)
|
||||
QFile file("storage/testimony/" + testimony_name + ".txt");
|
||||
if (file.exists()) {
|
||||
sendServerMessage("Unable to save testimony. Testimony name already exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
if(file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||
for (int i = 0; i <= area->testimony.size() -1; i++)
|
||||
{
|
||||
out << area->testimony.at(i).join("#") << "\n";
|
||||
}
|
||||
sendServerMessage("Testimony saved. To load it use /loadtestimony " + testimony_name);
|
||||
testimony_saving = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendServerMessage("You don't have permission to save a testimony. Please contact a moderator for permission.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AOClient::cmdLoadTestimony(int argc, QStringList argv)
|
||||
{
|
||||
AreaData* area = server->areas[current_area];
|
||||
QDir dir_testimony("storage/testimony");
|
||||
if (!dir_testimony.exists()) {
|
||||
sendServerMessage("Unable to load testimonies. Testimony storage not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
QString testimony_name = argv[0].trimmed().toLower().replace("..",""); // :)
|
||||
QFile file("storage/testimony/" + testimony_name + ".txt");
|
||||
if (!file.exists()) {
|
||||
sendServerMessage("Unable to load testimony. Testimony name not found.");
|
||||
return;
|
||||
}
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
sendServerMessage("Unable to load testimony. Permission denied.");
|
||||
return;
|
||||
}
|
||||
|
||||
clearTestimony();
|
||||
QTextStream in(&file);
|
||||
while (!in.atEnd()) {
|
||||
QString line = in.readLine();
|
||||
QStringList packet = line.split("#");
|
||||
area->testimony.append(packet);
|
||||
}
|
||||
sendServerMessage("Testimony loaded successfully. Use /examine to start playback.");
|
||||
}
|
||||
|
@ -402,3 +402,13 @@ void AOClient::cmdAllowIniswap(int argc, QStringList argv)
|
||||
QString state = area->iniswap_allowed ? "allowed." : "disallowed.";
|
||||
sendServerMessage("Iniswapping in this area is now " + state);
|
||||
}
|
||||
|
||||
void AOClient::cmdPermitSaving(int argc, QStringList argv)
|
||||
{
|
||||
AOClient* client = server->getClientByID(argv[0].toInt());
|
||||
if (client == nullptr) {
|
||||
sendServerMessage("Invalid ID.");
|
||||
return;
|
||||
}
|
||||
client->testimony_saving = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user