Implemented executed commands provider

This commit is contained in:
Pax1601
2023-09-04 12:41:54 +02:00
parent aca1e112d2
commit ede245a37d
13 changed files with 174 additions and 104 deletions

View File

@@ -98,9 +98,11 @@ public:
unsigned int getPriority() { return priority; }
virtual string getString() = 0;
virtual unsigned int getLoad() = 0;
const string getHash() { return hash; }
protected:
unsigned int priority = CommandPriority::LOW;
const string hash = random_string(16);
};
/* Simple low priority move command (from user click) */

View File

@@ -11,9 +11,10 @@ public:
void appendCommand(Command* command);
void execute(lua_State* L);
void handleRequest(string key, json::value value, string username);
void handleRequest(string key, json::value value, string username, json::value& answer);
bool checkSpawnPoints(int spawnPoints, string coalition);
bool isCommandExecuted(string commandHash) { return (find(executedCommandsHashes.begin(), executedCommandsHashes.end(), commandHash) != executedCommandsHashes.end()); }
void setFrameRate(double newFrameRate) { frameRate = newFrameRate; }
void setRestrictSpawns(bool newRestrictSpawns) { restrictSpawns = newRestrictSpawns; }
void setRestrictToCoalition(bool newRestrictToCoalition) { restrictToCoalition = newRestrictToCoalition; }
@@ -35,6 +36,7 @@ public:
private:
list<Command*> commands;
list<string> executedCommandsHashes;
unsigned int load;
double frameRate;

View File

@@ -60,6 +60,7 @@ void Scheduler::execute(lua_State* L)
log("Command '" + commandString + "' executed correctly, current load " + to_string(getLoad()));
load = command->getLoad();
commands.remove(command);
executedCommandsHashes.push_back(command->getHash());
delete command;
return;
}
@@ -134,7 +135,7 @@ bool Scheduler::checkSpawnPoints(int spawnPoints, string coalition)
}
}
void Scheduler::handleRequest(string key, json::value value, string username)
void Scheduler::handleRequest(string key, json::value value, string username, json::value& answer)
{
Command* command = nullptr;
@@ -565,6 +566,7 @@ void Scheduler::handleRequest(string key, json::value value, string username)
{
appendCommand(command);
log("New command appended correctly to stack. Current server load: " + to_string(getLoad()));
answer[L"commandHash"] = json::value(to_wstring(command->getHash()));
}
}

View File

@@ -142,6 +142,9 @@ void Server::handle_get(http_request request)
else
answer[L"mission"][L"commandModeOptions"][L"commandMode"] = json::value(L"Observer");
}
else if (URI.compare(COMMANDS_URI) && query.find(L"commandHash") != query.end()) {
answer[L"commandExectued"] = json::value(scheduler->isCommandExecuted(to_string(query[L"commandHash"])));
}
/* Common data */
answer[L"time"] = json::value::string(to_wstring(ms.count()));
@@ -222,7 +225,7 @@ void Server::handle_put(http_request request)
std::exception_ptr eptr;
try {
scheduler->handleRequest(to_string(key), value, username);
scheduler->handleRequest(to_string(key), value, username, answer);
}
catch (...) {
eptr = std::current_exception(); // capture

View File

@@ -10,5 +10,6 @@
#define AIRBASES_URI "airbases"
#define BULLSEYE_URI "bullseyes"
#define MISSION_URI "mission"
#define COMMANDS_URI "commands"
#define FRAMERATE_TIME_INTERVAL 0.05