Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
2.2 kB
3
Indexable
Never
else if (cmd.substr(0, 9) == "/ecoscan " && perm(peer, DEV)) {
		if (last_scan + 60000 < (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count())
		{
			last_scan = (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count();
		}
		else
		{
			int kiekDar = (last_scan + 60000 - (duration_cast<milliseconds>(system_clock::now().time_since_epoch())).count()) / 1000;
			gamepacket_t amy;
			amy.Insert("OnConsoleMessage");
			amy.Insert("`oSomeone already scanned economy, wait " + to_string(kiekDar) + " seconds before scan!");
			amy.CreatePacket(peer);
			return;
		}
		int targetid = atoi(cmd.substr(9, cmd.length() - 9).c_str());
		vector<pair<string, int>> found;
		string liste = "";
		if (targetid < 0 || targetid > items.size()) return;
		int itemcount = 0, sa = 0;
		for (auto& p : directory_iterator("database/players")) {
			int totco = 0;
			json j;
			ifstream files(p.path(), ifstream::binary);
			if (files.fail() || !files.is_open()) {
				cerr << "error: " << p.path() << endl;
				continue;
			}
			try {
				files >> j;
			}
			catch (const json::parse_error& e) {
				cerr << "ecoscan parse: " << e.what() << endl;
				files.close();
				continue;
			}
			int rank = j["rank"].get<int>();
			string ban = j["b_b"].get<string>();
			if (!ban.empty()) continue;
			string nick = (rank == 0 ? "`o" : r_color(rank));
			nick += j["name"].get<string>();
			for (const auto& get : j["inventory"]) {
				int id = get[0], count = get[1];
				if (id == targetid) totco += count;
			}
			itemcount += totco;
			if (totco > 0 && found.size() < 100) found.push_back(make_pair(nick, totco));
		}

		std::sort(found.begin(), found.end(), [](const auto& a, const auto& b) {
			return a.second > b.second;
			});

		for (const auto a : found) {
			if (sa == found.size() - 1) liste += a.first + " `$(" + to_string(a.second) + ")";
			else liste += a.first + " `$(" + to_string(a.second) + ")`o, ";
			sa++;
		}
		gamepacket_t h;
		h.Insert("OnConsoleMessage");
		h.Insert("`2Economy Scanned: `oFound `$" + to_string(itemcount) + "`o " + items[targetid].name + ": " + liste);
		h.CreatePacket(peer);
		found.clear();
	}
Leave a Comment