Major update 2 / login
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
// Runs first; everything here is available to all other modules.
|
||||
// ================================================================
|
||||
|
||||
const uw = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
|
||||
const uw = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
|
||||
const BASE_URL = 'https://grepo.haunter-pets.top';
|
||||
|
||||
// Read the clan key injected by the Loader before eval()
|
||||
const CLAN_KEY = window.__GRC_CLAN_KEY || '';
|
||||
|
||||
// Returns a random integer between min and max (inclusive)
|
||||
function randInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
@@ -29,3 +32,12 @@ function log(msg) {
|
||||
function sleep(ms) {
|
||||
return new Promise(r => setTimeout(r, ms));
|
||||
}
|
||||
|
||||
// Wrapper around fetch() that automatically injects the X-Clan-Key header
|
||||
// on every request. Use this instead of fetch() everywhere in the bot.
|
||||
function apiFetch(url, options) {
|
||||
options = options || {};
|
||||
options.headers = options.headers || {};
|
||||
options.headers['X-Clan-Key'] = CLAN_KEY;
|
||||
return fetch(url, options);
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@ function pushState() {
|
||||
if (paused) return;
|
||||
try {
|
||||
const payload = gatherState();
|
||||
fetch(`${BASE_URL}/api/state`, {
|
||||
apiFetch(`${BASE_URL}/api/state`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
@@ -236,7 +236,7 @@ if (uw.$) {
|
||||
|
||||
// ---- Report command result back to relay -----------------------------
|
||||
function reportResult(cmdId, status, message) {
|
||||
fetch(`${BASE_URL}/api/commands/${cmdId}/result`, {
|
||||
apiFetch(`${BASE_URL}/api/commands/${cmdId}/result`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status, message })
|
||||
|
||||
@@ -8,7 +8,7 @@ let captchaActive = false;
|
||||
function reportCaptcha(detected) {
|
||||
const player_id = uw.Game?.player_id;
|
||||
if (!player_id) return;
|
||||
fetch(`${BASE_URL}/api/captcha/alert?player_id=${player_id}`, {
|
||||
apiFetch(`${BASE_URL}/api/captcha/alert?player_id=${player_id}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ detected })
|
||||
|
||||
@@ -10,7 +10,7 @@ async function pollAndExecute() {
|
||||
|
||||
let cmdData;
|
||||
try {
|
||||
const res = await fetch(`${BASE_URL}/api/commands/pending?player_id=${player_id}`);
|
||||
const res = await apiFetch(`${BASE_URL}/api/commands/pending?player_id=${player_id}`);
|
||||
cmdData = await res.json();
|
||||
} catch (e) {
|
||||
log(`Poll failed: ${e}`);
|
||||
@@ -114,7 +114,7 @@ async function pollAndExecute() {
|
||||
if (allFull) {
|
||||
log('⚠️ Auto-farm: ALL warehouses are full (>95%) — skipping loot this cycle');
|
||||
try {
|
||||
await fetch(`${BASE_URL}/api/farm_status?player_id=${uw.Game.player_id}`, {
|
||||
await apiFetch(`${BASE_URL}/api/farm_status?player_id=${uw.Game.player_id}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ warehouse_full: true })
|
||||
@@ -122,7 +122,7 @@ async function pollAndExecute() {
|
||||
} catch (e) {}
|
||||
} else if (claimedAny) {
|
||||
try {
|
||||
await fetch(`${BASE_URL}/api/farm_status?player_id=${uw.Game.player_id}`, {
|
||||
await apiFetch(`${BASE_URL}/api/farm_status?player_id=${uw.Game.player_id}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ warehouse_full: false })
|
||||
|
||||
Reference in New Issue
Block a user