-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNodeRunner.cpp
102 lines (86 loc) · 4.25 KB
/
NodeRunner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* LevelAPI - Geometry Dash level cacher with search functionality and more.
Copyright (C) 2023 Sergei Baigerov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "NodeRunner.h"
#include "DatabaseControllerThreads.h"
#include <chrono>
#include <string>
#include <thread>
#include <iostream>
#include <vector>
#include "GDServer.h"
#include "GDServer_BoomlingsLike21.h"
#include "GDServer_BasementLike21.h"
#include "GDServer_BoomlingsLike19.h"
#include "lapi_database.h"
#include "Translation.h"
using namespace LevelAPI::NodeController;
using namespace LevelAPI::DatabaseController;
using namespace LevelAPI::Frontend;
using namespace std::chrono_literals;
void NodeRunner::errorEmptyQueue() {
if(!m_pLinkedNode->m_pPolicy->m_bNoOutput) {
m_nPreviousRequest = NC_NONE;
std::cout << Translation::getByKey("lapi.noderunner.downloader.error.queue.empty", m_pLinkedNode->m_sInternalName) << std::endl;
}
while(true) {
std::this_thread::sleep_for(std::chrono::seconds(2s));
}
}
void NodeRunner::errorReadOnly() {
if(!m_pLinkedNode->m_pPolicy->m_bNoOutput) {
std::cout << Translation::getByKey("lapi.noderunner.readonly", m_pLinkedNode->m_sInternalName) << std::endl;
}
}
void NodeRunner::thread_cacheLevels(NodeRunner *self) {
while(true) {
std::string folder = "database/nodes/" + self->m_pLinkedNode->m_sInternalName + "/levels";
self->m_pLinkedNode->m_vCachedLevels.clear();
for (const auto & entry : std::filesystem::directory_iterator(folder)) {
std::string path = entry.path();
std::string filename = path.substr(path.find_last_of("/\\") + 1);
std::string levelid = filename.substr(filename.find_last_of("_") + 1);
self->m_pLinkedNode->m_vCachedLevels.push_back(std::stoi(levelid));
}
if(!self->m_pLinkedNode->m_pPolicy->m_bNoOutput) {
std::cout << Translation::getByKey("lapi.noderunner.recount.complete", self->m_pLinkedNode->m_sInternalName, self->m_pLinkedNode->m_vCachedLevels.size()) << std::endl;
}
std::this_thread::sleep_for(5s);
}
}
void NodeRunner::task_waitRatelimit(NodeRunner *self, int rate_limit_length) {
if(self->m_pLinkedNode->m_bRateLimitApplied) return;
self->m_pLinkedNode->m_bRateLimitApplied = true;
if(!self->m_pLinkedNode->m_pPolicy->m_bNoOutput) {
std::cout << "[LevelAPI resolver " << self->m_pLinkedNode->m_sInternalName << "] Waiting " << rate_limit_length << "s" << std::endl;
std::cout << Translation::getByKey("lapi.noderunner.resolver.wait.start", self->m_pLinkedNode->m_sInternalName, rate_limit_length) << std::endl;
}
std::this_thread::sleep_for(std::chrono::seconds(rate_limit_length + (int)self->m_pLinkedNode->m_pPolicy->m_nResolverInterval));
if(!self->m_pLinkedNode->m_pPolicy->m_bNoOutput) {
std::cout << "[LevelAPI resolver " << self->m_pLinkedNode->m_sInternalName << "] Rate limit end!" << std::endl;
std::cout << Translation::getByKey("lapi.noderunner.resolver.wait.end", self->m_pLinkedNode->m_sInternalName) << std::endl;
}
self->m_pLinkedNode->m_bRateLimitApplied = false;
return;
}
void NodeRunner::thread_pushRecentTab(NodeRunner *self) {
if(!self->m_pLinkedNode->m_pPolicy->m_bEnableRecentTab) return;
while(true) {
std::this_thread::sleep_for(std::chrono::milliseconds((int)(self->m_pLinkedNode->m_pPolicy->m_nQueueProcessingInterval * 1000)));
if(true) { // self->m_pLinkedNode->m_uQueue->m_vCommandQueue->size() == 0
self->m_pLinkedNode->m_uQueue->m_vCommandQueue.push_back({NC_RECENT, "-"});
self->m_pLinkedNode->m_uQueue->save();
}
}
}