Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.6 kB
0
Indexable
Never
#include <unordered_map>
#include <chrono>
#include <ctime>

std::unordered_map<std::string, int> playerLocks;
int sayi = 0;
std::time_t lastUpdateTime = std::time(nullptr);

// Son güncelleme zamanını kontrol et
std::time_t currentTime = std::time(nullptr);
bool shouldUpdate = (currentTime - lastUpdateTime) >= 3600;  // 3600 saniye = 1 saat

if (shouldUpdate) {
    // Verileri güncelleme işlemini gerçekleştir
    for (const auto& p : std::filesystem::directory_iterator("players")) {
        json j;
        std::ifstream files(p.path());
        files >> j;

        int level = j["level"];
        if (level < 25) continue;

        std::string name = j["name"];
        int lock = j["opc"] / 2 + j["gems"] / 20000 + j["bpoi"] / 500;
        
        json inventory = j["inv"].get<json>();
        for (const auto& item : inventory) {
            int itemid = item["i"].get<int>();
            int itemcount = item["c"].get<int>();
            if (itemid == 242) {
                lock += itemcount;
            }
            if (itemid == 1796) {
                lock += itemcount * 100;
            }
            if (itemid == 7188) {
                lock += itemcount * 10000;
            }
        }

        playerLocks[name] = lock;
    }

    // Son güncelleme zamanını güncelle
    lastUpdateTime = std::time(nullptr);
} else {
    // Eğer 60 dakika dolmamışsa, eski verileri yükle
    std::ifstream oldDataFile("player_locks.txt");
    if (oldDataFile) {
        std::string playerName;
        int lock;
        while (oldDataFile >> playerName >> lock) {
            playerLocks[playerName] = lock;
        }
        oldDataFile.close();
    }
}

std::vector<std::pair<std::string, int>> players(playerLocks.begin(), playerLocks.end());
std::partial_sort(players.begin(), players.begin() + 100, players.end(),
    [](const std::pair<std::string, int>& a, const std::pair<std::string, int>& b) {
        return a.second > b.second;
    });

std::string btn = "";
for (const std::pair<std::string, int>& player : players) {
    if (sayi < 100) {
        btn += "\nadd_button|leader_" + player.first + "|`##" + std::to_string(sayi + 1) + " `w" + player.first + "|";
        sayi++;
    }
}

gamepacket_t k;
k.Insert("OnDialogRequest");
k.Insert("\nadd_label_with_icon|big|`wLeaderboard|left|394|\nadd_spacer|small|\nadd_smalltext|`1Note: Requirement is minimum 25 level!|\nadd_textbox|`oTop 100 Richest Players of Voidtopia:|\nadd_spacer|small|" + btn + "\nadd_spacer|\nadd_button|kk|Close|\nadd_quick_exit|");
k.CreatePacket(peer);

// Güncellenen veya eski verileri kullanarak işlemi tamamla