-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnamesniper.js
More file actions
299 lines (276 loc) · 9.31 KB
/
namesniper.js
File metadata and controls
299 lines (276 loc) · 9.31 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
const mineflayer = require('mineflayer');
const mojang = require('mojang-api');
const fs = require('fs');
const path = require('path');
// --- New variable to track Anti-AFK state ---
let antiAFKActive = false;
let sniperInterval = null;
let sniperBot = null;
let lastUsername = null;
let monitoring = false;
let userStopped = false; // Flag to track if the user manually stopped the bot
let currentTargetUuid = null; // Currently tracked account's UUID
// Helper: Generate a random password
function generateRandomPassword(length = 10) {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let password = '';
for (let i = 0; i < length; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
// Using mojang-api to fetch the profile for a given UUID and resolve its name.
function getNameForUuid(uuid) {
return new Promise((resolve, reject) => {
mojang.profile(uuid, (err, res) => {
if (err || !res || !res.name) {
reject(err || "No name returned");
} else {
resolve(res.name);
}
});
});
}
// Returns the path to oguserstore.txt in C:\BlocksMC_TrackerData
function getStoreFilePath() {
const dataDir = 'C:\\BlocksMC_TrackerData';
if (!fs.existsSync(dataDir)) {
fs.mkdirSync(dataDir, { recursive: true });
}
const filePath = path.join(dataDir, 'oguserstore.txt');
if (!fs.existsSync(filePath)) {
fs.writeFileSync(filePath, '{}', 'utf8');
}
return filePath;
}
// Reads and parses the store file.
function readUserOGStore() {
const filePath = getStoreFilePath();
try {
const data = fs.readFileSync(filePath, 'utf8');
return data ? JSON.parse(data) : {};
} catch (e) {
console.error('Error parsing oguserstore.txt:', e);
return {};
}
}
// Updates or creates the store entry for a targetUuid with Username, Password, and status.
function updateUserOGStore(targetUuid, username, password, status) {
const filePath = getStoreFilePath();
const store = readUserOGStore();
store[targetUuid] = { Username: username, Password: password, status: status };
try {
fs.writeFileSync(filePath, JSON.stringify(store, null, 2));
} catch (e) {
console.error('Error writing to oguserstore.txt:', e);
}
}
// Retrieves stored data for a targetUuid.
function getStoredData(targetUuid) {
const store = readUserOGStore();
return store[targetUuid] || null;
}
// Helper: Update all entries with status "Currently checking" to "Stopped".
function updateAllCurrentlyCheckingToStopped() {
const filePath = getStoreFilePath();
const store = readUserOGStore();
let updated = false;
for (const uuid in store) {
if (store[uuid].status === "Currently checking") {
store[uuid].status = "Stopped";
updated = true;
}
}
if (updated) {
try {
fs.writeFileSync(filePath, JSON.stringify(store, null, 2));
} catch (e) {
console.error('Error updating oguserstore.txt:', e);
}
}
}
// Anti-AFK: cycles pressing forward then back using a flag.
function startAntiAFK(bot) {
antiAFKActive = true;
function cycle() {
if (!bot || !antiAFKActive) return;
bot.setControlState('forward', true);
setTimeout(() => {
bot.setControlState('forward', false);
bot.setControlState('back', true);
setTimeout(() => {
bot.setControlState('back', false);
cycle();
}, 4000);
}, 200);
}
cycle();
}
// New function to stop Anti-AFK.
function stopAntiAFK(bot) {
antiAFKActive = false;
if (bot) {
bot.setControlState('forward', false);
bot.setControlState('back', false);
}
}
// Update activateAntiAFK to check if anti-AFK is already active.
function activateAntiAFK(callback) {
if (sniperBot) {
if (!antiAFKActive) {
startAntiAFK(sniperBot);
callback({ type: 'info', message: 'Anti-AFK mode activated.' });
} else {
callback({ type: 'info', message: 'Anti-AFK mode is already active.' });
}
} else {
callback({ type: 'error', message: 'No active bot found.' });
}
}
// New function to disable Anti-AFK.
function disableAntiAFK(callback) {
if (sniperBot) {
if (antiAFKActive) {
stopAntiAFK(sniperBot);
callback({ type: 'info', message: 'Anti-AFK mode disabled.' });
} else {
callback({ type: 'info', message: 'Anti-AFK mode is already disabled.' });
}
} else {
callback({ type: 'error', message: 'No active bot found.' });
}
}
// Launches the bot to claim the new username.
function launchClaimerBot(targetUuid, newUsername, callback) {
const stored = getStoredData(targetUuid);
let password, command;
if (stored && stored.Password) {
password = stored.Password;
command = `/login ${password}`;
} else {
password = generateRandomPassword();
if (stored && stored.Username) {
updateUserOGStore(targetUuid, stored.Username, password, "Currently checking");
} else {
updateUserOGStore(targetUuid, newUsername, password, "Currently checking");
}
command = `/login ${password}`;
}
sniperBot = mineflayer.createBot({
host: 'play.blocksmc.com',
port: 25565,
username: newUsername,
version: '1.8.9',
auth: 'offline'
});
sniperBot.once('spawn', () => {
sniperBot._client.write('chat', { message: command });
updateUserOGStore(targetUuid, newUsername, password, "Claimed account");
lastUsername = newUsername;
callback({ type: 'claimed', message: `Claimed account for ${newUsername}` });
if (sniperInterval) {
clearInterval(sniperInterval);
sniperInterval = null;
}
// Automatically start Anti-AFK mode
startAntiAFK(sniperBot);
});
sniperBot.on('end', () => {
if (monitoring && !userStopped) {
callback({ type: 'alert', message: 'Bot disconnected. Attempting to reconnect...' });
setTimeout(() => {
launchClaimerBot(targetUuid, newUsername, callback);
}, 5000);
}
});
sniperBot.on('error', (err) => {
console.error('Bot error:', err);
if (!userStopped) {
callback({ type: 'error', message: 'Failed to claim. Try again later.' });
}
});
}
// Starts tracking the provided targetUuid.
function startSniper(targetUuid, callback) {
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (!uuidRegex.test(targetUuid)) {
monitoring = false;
currentTargetUuid = null;
updateAllCurrentlyCheckingToStopped();
callback({ type: 'error', message: 'Invalid UUID. Please provide a valid UUID.' });
return;
}
if (monitoring) {
callback({ type: 'info', message: 'Bot is already tracking this UUID.' });
return;
}
monitoring = true;
userStopped = false;
currentTargetUuid = targetUuid;
const stored = getStoredData(targetUuid);
if (stored && stored.Username) {
lastUsername = stored.Username;
if (!stored.Password) {
const newPassword = generateRandomPassword();
updateUserOGStore(targetUuid, lastUsername, newPassword, "Currently checking");
}
callback({ type: 'info', message: 'Monitoring started. Currently checking account: ' + lastUsername });
} else {
getNameForUuid(targetUuid)
.then(username => {
lastUsername = username;
const randomPassword = generateRandomPassword();
updateUserOGStore(targetUuid, username, randomPassword, "Currently checking");
callback({ type: 'info', message: 'Monitoring started. Currently checking account: ' + username });
})
.catch(err => {
callback({ type: 'error', message: 'Error retrieving username for UUID: ' + err });
});
}
sniperInterval = setInterval(() => {
getNameForUuid(targetUuid)
.then(currentUsername => {
console.log("Pinged Mojang API: resolved username is: " + currentUsername);
const storedData = getStoredData(targetUuid);
const oldUsername = (storedData && storedData.Username) ? storedData.Username : lastUsername;
if (currentUsername !== oldUsername) {
callback({ type: 'alert', message: `Detected username change from ${oldUsername} to ${currentUsername}. Attempting to claim immediately...` });
clearInterval(sniperInterval);
sniperInterval = null;
launchClaimerBot(targetUuid, currentUsername, callback);
}
})
.catch(err => {
console.error('Error checking username:', err);
});
}, 15000);
}
// Stops the tracking bot and marks the target as stopped.
function stopSniper(callback) {
userStopped = true;
if (sniperInterval) {
clearInterval(sniperInterval);
sniperInterval = null;
monitoring = false;
}
if (sniperBot) {
sniperBot.quit();
sniperBot = null;
}
if (currentTargetUuid) {
const stored = getStoredData(currentTargetUuid);
if (stored) {
updateUserOGStore(currentTargetUuid, stored.Username, stored.Password, "Stopped");
}
}
callback({ type: 'info', message: 'Name Claimer Bot stopped. STOP TRACKING' });
currentTargetUuid = null;
}
module.exports = {
startSniper,
stopSniper,
readUserOGStore,
updateAllCurrentlyCheckingToStopped,
activateAntiAFK,
disableAntiAFK
};