Skip to content

Instantly share code, notes, and snippets.

@rupython
Created May 29, 2021 14:54
Show Gist options
  • Save rupython/b9238deb6701f33a8197f2d84de9f276 to your computer and use it in GitHub Desktop.
Save rupython/b9238deb6701f33a8197f2d84de9f276 to your computer and use it in GitHub Desktop.
From: nwexx
import sys
import importlib
import asyncio
import binascii
from bitstring import BitArray, ConstBitStream
import protocol
import random
import html
import time
from time import mktime
from datetime import datetime
import logging
from aiogram import Bot, Dispatcher, executor, types
API_TOKEN = "1875833362:AAHNYO1jQ_GxcMzkpX5MS4vi_7srhO4D7l8"
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
CLIENT_VERSION = "91.29.0"
APPSUB = "e868543cdf4f9cf753cc119de4529a42" #pnz-city.swf_sub
APPHSH = "6f578b8a7e3c89fcd1669072d4d86fcc" #pnz-city.swf
CFGSUB = "cf249810db222a4b9072fbe6ef9bd7bc" #config_all_ru.zip_sub
CFGHSH = "bb315dae9ce17af4f464948075eb7582" #config_all_ru.zip
@dp.message_handler(commands=['sid'])
async def sid_command(message: types.Message):
text = message.text[4:].strip()
print(text)
await a_bot.joingame(arg)
def get_encrypt_key(key, uid):
uid = "kd&k3*3"
first = bytearray(key.encode())
second = bytearray(uid.encode())
i = 0
while i < len(first):
first[i] = second[i % len(second)] ^ first[i]
i += 1
return first
class AvatariaBot():
def __init__(self):
self.sid = "656248146"
self.token = "c8902d5b73fa55a0059d75ab2c2a4b1b"
self.server = "house"
self.counter = 0
self.checksummed = False
self.compressed = False
self.encrypted = False
self.encrypt_key = None
self.uid = None
self.room = None
self.corruption_counter = 0
async def connect(self, ip, port):
reader, self.writer = await asyncio.open_connection(ip, port)
await self.send([self.server, self.sid,
self.token,
{'apphsh': APPHSH, 'lng': 'ru',
'sid': self.sid,
'cfgsub': CFGSUB, 'lcl': 'ru',
'nk': '', 'rd': 0,
'cfghsh': CFGHSH, 'cty': 0,
'fn': '', 'clvrn': CLIENT_VERSION,
'ctr': 0, 'ln': '',
'rftp': 'unknown', 'gdr': 2,
'bd': '1', 'rfid': '', 'snid': 1, 'pid': 1,
'appsub': APPSUB, 'pht': '',
'v': 4,
'enop': {'brwvs': '86', 'brw': 'Chrome', 'scrs': '1920:1080', 'flvs': '32,0,0', 'osvs': '10', 'os': 'Windows'}}],
type_=1)
buffer = ConstBitStream()
while True:
data = await reader.read(1024)
if not data:
break
data = buffer + ConstBitStream(data)
buffer = ConstBitStream()
while len(data) - data.pos > 32:
length = data.read(32).int
if (len(data) - data.pos) / 8 < length:
data.pos = 0
break
final_data = protocol.processFrame(data.read(length * 8),
False, self.encrypt_key)
await self.process_data(final_data["msg"],
final_data["type"])
if (len(data) - data.pos) / 8 >= 32:
buffer = data
async def send(self, msg, type_=34):
print("CLIENT: ", msg, type_)
self.counter += 1
data = BitArray(f"int:32={self.counter}")
data.append(f"int:8={type_}")
data.append(protocol.encodeArray(msg))
if self.encrypted:
tmp = bytearray(data.bytes)
data = BitArray(protocol.crypt(tmp, self.encrypt_key))
data.insert(self._make_header(data), 0)
self.writer.write(data.bytes)
await self.writer.drain()
async def process_data(self, msg, type_):
print("SERVER: ", msg, type_)
if type_ == 1:
self.uid = msg[0]
self.checksummed = msg[2]
self.encrypted = msg[4]
self.encrypt_key = get_encrypt_key(msg[1], self.uid)
await self.auth_complete()
elif type_ == 16 and msg[1] == self.uid:
if msg[0].startswith("game"):
return
self.room = msg[0]
elif type_ == 17 and msg[1] == self.uid:
if msg[0].startswith("game"):
await asyncio.sleep(0.15)
return
self.room = None
elif type_ == 17 and msg[1] == self.follow_uid:
await self.send([self.gameroom], type_=17)
elif type_ == 34:
await self.on_message(msg)
async def change_room(self, uid):
if self.room:
await self.send([self.room], type_=17)
await self.send([None, "h.gr", {"lid": "house", "gid": uid,
"rid": "livingroom"}])
await self.on_message(msg)
def _make_header(self, msg):
buf = BitArray()
header_length = 1
mask = 0
if self.encrypted:
mask |= (1 << 1)
if self.compressed:
mask |= (1 << 2)
if self.checksummed:
mask |= (1 << 3)
header_length += 4
buf.append(f"int:32={len(msg.hex)//2+header_length}")
buf.append(f"int:8={mask}")
if self.checksummed:
buf.append(f"uint:32={binascii.crc32(msg.bytes) % (1<<32)}")
return buf
async def on_message(self, msg):
if msg[0] == "pl.get":
user_vk = int(msg[1]["clid"])
if not msg[1]["plrs"]:
print("No")
return
plr = msg[1]["plrs"][0]
name = f"{plr['usrinf']['fn']} {plr['usrinf']['ln']}"
last_login = str(datetime.fromtimestamp(plr["ci"]["lvt"]))
role = plr["usrinf"]["rl"]
vip = plr["ci"]["vip"]
sid = plr["usrinf"]["sid"]
rlt = plr["ci"]["cmid"]
if plr["clif"]:
clan_tag = html.escape(plr["clif"]["tg"])
clan_name = html.escape(plr["clif"]["ctl"])
clan_cid = plr["clif"]["cid"]
else:
clan_name = "Нет"
clan_tag = ""
clan_cid = "Клуба нет"
if plr["ci"]["vip"] == "True":
vip = "Активен"
if plr["ci"]["vip"] == "":
print("ok")
else:
format_ = f'UID - {plr["uid"]}\n' \
f'Роль - {role}\n' \
f'UID Супруга - {rlt}\n' \
f'Последний вход - {last_login}\n' \
f'Ник - {html.escape(plr["apprnc"]["n"])}\n' \
f'ВК - https://vk.com/id{sid} ({name})\n' \
f'Клуб - [{clan_tag}] {clan_name}\n' \
f'Ид клуба - {clan_cid} \n' \
f'Опыта - {plr["ci"]["exp"]} \n' \
f'Вип - {vip} \n' \
f'Комфорт - {plr["ci"]["hrt"]}\n' \
f'Имидж - {plr["ci"]["crt"]}\n' \
f'Репутация - {plr["ci"]["rpt"]}'
print(format_)
await bot.send_message(chat_id, format_)
async def joingame(self, arg):
await self.send([None, 'pl.gid', {'uids': ["1"], 'clid': "1"}], type_=34)
async def auth_complete(self):
asyncio.create_task(self.background())
async def background(self):
args = [{'gid': 'p1', 'lid': 'p1'}]
while True:
arg = random.choice(args)
await self.joingame(arg)
await asyncio.sleep(9999999)
async def on_startup(d):
a_bot = AvatariaBot()
asyncio.create_task(a_bot.connect("api.vk.avataria.tortugasocial.com", 8123))
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True, on_startup=on_startup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment