-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathguest_checker.py
More file actions
350 lines (288 loc) · 11.8 KB
/
Copy pathguest_checker.py
File metadata and controls
350 lines (288 loc) · 11.8 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/usr/bin/env python3
"""
Guest Account Checker - Standalone Tool
Scans all guest accounts, checks which are alive/dead/banned,
and gets their level, likes, nickname, clan, region.
This is SEPARATE from the level bot. It only checks account status.
Usage:
python guest_checker.py # check all accounts
python guest_checker.py --db guests.db # specific db
python guest_checker.py --json guests.json # specific json
"""
import os
import sys
import json
import sqlite3
import asyncio
import argparse
from datetime import datetime
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, PROJECT_ROOT)
class C:
R = "\033[0m"
B = "\033[1m"
D = "\033[2m"
R1 = "\033[91m"
G = "\033[92m"
Y = "\033[93m"
CY = "\033[96m"
W = "\033[97m"
# ── Load accounts from all sources ──────────────────────
def load_all_accounts():
"""Load guest accounts from all sources, deduplicated."""
accounts = {} # uid -> {"password": ..., "source": [...], "name": ...}
# Source 1: data/guests.json
guests_json = os.path.join(PROJECT_ROOT, "data", "guests.json")
if os.path.exists(guests_json):
with open(guests_json) as f:
try:
guests = json.load(f)
for g in guests:
uid = g.get("uid", "")
pwd = g.get("password", "")
name = g.get("name", "")
if uid and pwd:
if uid not in accounts:
accounts[uid] = {"password": pwd, "sources": [], "name": name}
accounts[uid]["sources"].append("guests.json")
if name and not accounts[uid].get("name"):
accounts[uid]["name"] = name
except Exception as e:
print(f" {C.R1}Error reading guests.json: {e}{C.R}")
# Source 2: data/guests.db (SQLite)
guests_db = os.path.join(PROJECT_ROOT, "data", "guests.db")
if os.path.exists(guests_db):
try:
conn = sqlite3.connect(guests_db)
cursor = conn.cursor()
cursor.execute("SELECT uid, password, nickname, health_status FROM guests")
for row in cursor.fetchall():
uid, pwd, nick, health = row
if uid and pwd:
if uid not in accounts:
accounts[uid] = {"password": pwd, "sources": [], "name": nick or ""}
accounts[uid]["sources"].append(f"guests.db({health})")
if nick and not accounts[uid].get("name"):
accounts[uid]["name"] = nick
conn.close()
except Exception as e:
print(f" {C.R1}Error reading guests.db: {e}{C.R}")
# Source 3: data/level_accounts.json
level_json = os.path.join(PROJECT_ROOT, "data", "level_accounts.json")
if os.path.exists(level_json):
with open(level_json) as f:
try:
data = json.load(f)
for uid, pwd in data.items():
if uid and pwd:
if uid not in accounts:
accounts[uid] = {"password": pwd, "sources": [], "name": ""}
accounts[uid]["sources"].append("level_accounts.json")
except Exception as e:
print(f" {C.R1}Error reading level_accounts.json: {e}{C.R}")
return accounts
# ── Check a single account ──────────────────────────────
async def check_account(http, uid, password, name=""):
"""Check a single guest account. Returns a dict with all info."""
result = {
"uid": uid,
"name": name or "",
"password": password,
"oauth_status": "UNKNOWN",
"ban_status": "UNKNOWN",
"ban_reason": "",
"nickname": "Unknown",
"level": 0,
"exp": 0,
"likes": 0,
"rank": 0,
"region": "Unknown",
"clan_name": "None",
"clan_level": 0,
"release_version": "Unknown",
"checked_at": datetime.now().isoformat(),
}
from src.level.auth import LevelAuth
auth = LevelAuth(http)
# Step 1: OAuth (works even when game servers are down)
oauth = await auth.guest_token(uid, password, retries=2)
if not oauth:
result["oauth_status"] = "DEAD"
result["ban_status"] = "DEAD"
result["ban_reason"] = "OAuth failed - account deleted or password invalid"
return result
access_token, open_id = oauth
result["oauth_status"] = "ALIVE"
# Step 2: MajorLogin (only works when game servers are up)
login = await auth.major_login(access_token, open_id, retries=2)
if login and not login.get("error"):
result["ban_status"] = "CLEAR"
jwt_token = login["token"]
# Step 3: Player Info
try:
from src.level.guest_info import GuestInfo
info = GuestInfo(http)
player_data = await info._get_player_personal_show(uid, jwt_token)
if player_data:
info._parse_info(result, player_data, uid)
except Exception as e:
result["ban_reason"] = f"Player info error: {e}"
else:
last_status = login.get("last_status", 0) if isinstance(login, dict) else 0
if last_status == 503:
result["ban_status"] = "SERVER_DOWN"
result["ban_reason"] = "Garena servers down (503) - not a ban"
elif last_status in (400, 401, 403):
result["ban_status"] = "BANNED"
result["ban_reason"] = f"Account banned (HTTP {last_status})"
else:
result["ban_status"] = "UNKNOWN"
result["ban_reason"] = f"MajorLogin failed (HTTP {last_status})"
return result
# ── Main check loop ────────────────────────────────────
async def check_all_accounts(accounts, concurrent=3):
"""Check all accounts with limited concurrency."""
import httpx
async def check_one(http, uid, data, idx, total):
result = await check_account(http, uid, data["password"], data.get("name", ""))
# Print live progress
status = result["ban_status"]
if status == "CLEAR":
icon = f"{C.G}OK{C.R}"
extra = f"Lv{result['level']} {result['likes']}likes {result['nickname']}"
elif status == "SERVER_DOWN":
icon = f"{C.Y}SVR{C.R}"
extra = f"{C.D}oauth=alive, servers down{C.R}"
elif status == "BANNED":
icon = f"{C.R1}BAN{C.R}"
extra = f"{C.D}{result['ban_reason']}{C.R}"
elif status == "DEAD":
icon = f"{C.R1}DEAD{C.R}"
extra = f"{C.D}account deleted{C.R}"
else:
icon = f"{C.Y}??{C.R}"
extra = f"{C.D}{result['ban_reason']}{C.R}"
print(f" [{idx}/{total}] {uid:15s} {icon} {extra}")
return result
total = len(accounts)
print(f"\n {C.B}Checking {total} accounts...{C.R}")
print(f" {C.D}(OAuth works even if game servers are down){C.R}\n")
# Create shared HTTP client
http = httpx.AsyncClient(verify=False, follow_redirects=True)
# Process with limited concurrency
semaphore = asyncio.Semaphore(concurrent)
results = []
async def limited_check(uid, data, idx):
async with semaphore:
return await check_one(http, uid, data, idx, total)
tasks = []
for i, (uid, data) in enumerate(accounts.items(), 1):
tasks.append(limited_check(uid, data, i))
results = await asyncio.gather(*tasks)
await http.aclose()
return results
# ── Report ─────────────────────────────────────────────
def print_report(results):
"""Print a summary table of all accounts."""
print()
print(f" {C.CY}========================================{C.R}")
print(f" {C.B} GUEST ACCOUNT REPORT{C.R}")
print(f" {C.CY}========================================{C.R}")
print()
# Header
print(f" {'UID':15s} {'STATUS':8s} {'NICK':12s} {'LVL':>4s} {'LIKES':>5s} {'REGION':6s} {'CLAN':12s}")
print(f" {'-'*15} {'-'*8} {'-'*12} {'-'*4} {'-'*5} {'-'*6} {'-'*12}")
alive = 0
dead = 0
banned = 0
server_down = 0
unknown = 0
for r in results:
status = r["ban_status"]
if status == "CLEAR":
sc = C.G
alive += 1
elif status == "DEAD":
sc = C.R1
dead += 1
elif status == "BANNED":
sc = C.R1
banned += 1
elif status == "SERVER_DOWN":
sc = C.Y
server_down += 1
else:
sc = C.Y
unknown += 1
nick = (r["nickname"] or "?")[:12]
clan = (r["clan_name"] or "None")[:12]
print(f" {r['uid']:15s} {sc}{status:8s}{C.R} {nick:12s} {r['level']:4d} {r['likes']:5d} {r['region']:6s} {clan:12s}")
print()
print(f" {C.CY}----------------------------------------{C.R}")
print(f" {C.B}Summary:{C.R}")
print(f" {C.G}Alive: {alive}{C.R}")
if server_down:
print(f" {C.Y}Server Down: {server_down}{C.R}")
if banned:
print(f" {C.R1}Banned: {banned}{C.R}")
if dead:
print(f" {C.R1}Dead: {dead}{C.R}")
if unknown:
print(f" {C.Y}Unknown: {unknown}{C.R}")
print(f" {C.B}Total: {len(results)}{C.R}")
print(f" {C.CY}========================================{C.R}")
print()
def save_report(results):
"""Save report to JSON file."""
report_file = os.path.join(PROJECT_ROOT, "data", "guest_report.json")
# Clean up for JSON
clean = []
for r in results:
c = dict(r)
clean.append(c)
summary = {
"generated_at": datetime.now().isoformat(),
"total_accounts": len(results),
"alive": sum(1 for r in results if r["ban_status"] == "CLEAR"),
"dead": sum(1 for r in results if r["ban_status"] == "DEAD"),
"banned": sum(1 for r in results if r["ban_status"] == "BANNED"),
"server_down": sum(1 for r in results if r["ban_status"] == "SERVER_DOWN"),
"unknown": sum(1 for r in results if r["ban_status"] == "UNKNOWN"),
"accounts": clean,
}
with open(report_file, "w") as f:
json.dump(summary, f, indent=2)
print(f" {C.G}Report saved to: data/guest_report.json{C.R}")
print()
# ── Main ────────────────────────────────────────────────
def main():
print()
print(f" {C.CY}{C.B}========================================{C.R}")
print(f" {C.CY}{C.B} GUEST ACCOUNT CHECKER v1.0 {C.R}")
print(f" {C.CY}{C.B}========================================{C.R}")
print()
# Load all accounts
accounts = load_all_accounts()
if not accounts:
print(f" {C.R1}No guest accounts found!{C.R}")
print(f" {C.D}Put accounts in data/guests.json or data/level_accounts.json{C.R}")
return
print(f" Found {len(accounts)} accounts:")
for uid, data in accounts.items():
srcs = ", ".join(data["sources"])
name = data.get("name", "")
print(f" {C.D}{uid:15s} {C.W}{name:12s} {C.D}({srcs}){C.R}")
print()
# Run checks
results = asyncio.run(check_all_accounts(accounts))
# Print report
print_report(results)
# Save
save_report(results)
print(f" {C.D}Done!{C.R}")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print(f"\n\n {C.Y}Interrupted.{C.R}\n")
sys.exit(0)