Upload files to "/"
This commit is contained in:
161
RecNet.py
Normal file
161
RecNet.py
Normal file
@@ -0,0 +1,161 @@
|
||||
from enum import Enum
|
||||
import httpx
|
||||
import json
|
||||
import dto
|
||||
|
||||
RecNetDomain = "rec.net"
|
||||
|
||||
auth = None
|
||||
refreshToken = None
|
||||
clientSecret = "54oc5C4BH7jpqp42KhChkNZOLP0U3yTx"
|
||||
|
||||
c = httpx.Client(http1=False, http2=True)
|
||||
|
||||
class Service(Enum):
|
||||
Accounts = "accounts"
|
||||
AI = "ai"
|
||||
API = "api"
|
||||
Auth = "auth"
|
||||
BugReporting = "bugreporting"
|
||||
Cards = "cards"
|
||||
CDN = "cdn"
|
||||
Chat = "chat"
|
||||
Clubs = "clubs"
|
||||
CMS = "cms"
|
||||
Commerce = "commerce"
|
||||
Data = "data"
|
||||
DataCollection = "datacollection"
|
||||
Discovery = "discovery"
|
||||
Econ = "econ"
|
||||
GameLogs = "gamelogs"
|
||||
Geo = "geo"
|
||||
Images = "img"
|
||||
Leaderboard = "leaderboard"
|
||||
Link = "link"
|
||||
Lists = "lists"
|
||||
Matchmaking = "match"
|
||||
Moderation = "moderation"
|
||||
Notifications = "notify"
|
||||
PlatformNotifications = "platformnotifications"
|
||||
PlayerSettings = "playersettings"
|
||||
RoomComments = "roomcomments"
|
||||
Rooms = "rooms"
|
||||
Storage = "storage"
|
||||
Strings = "strings"
|
||||
StringsCDN = "strings-cdn"
|
||||
Studio = "studio"
|
||||
Thorn = "thorn"
|
||||
Videos = "videos"
|
||||
WWW = "www"
|
||||
|
||||
class AvatarBodyType(Enum):
|
||||
Bean = 0
|
||||
FB = 1
|
||||
UpgradedBean = 2
|
||||
|
||||
class HTTPMethod(Enum):
|
||||
GET = "GET"
|
||||
HEAD = "HEAD"
|
||||
POST = "POST"
|
||||
PUT = "PUT"
|
||||
DELETE = "DELETE"
|
||||
PATCH = "PATCH"
|
||||
OPTIONS = "OPTIONS"
|
||||
TRACE = "TRACE"
|
||||
CONNECT = "CONNECT"
|
||||
|
||||
class RecNetError(Exception):
|
||||
def __init__(self, message: str):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
def __repr__(self):
|
||||
return f"RecNetError({self.message})"
|
||||
|
||||
def sendRequest(method: HTTPMethod, service: Service, path: str, useAuth=True, json=None, files=None, data=None, https: bool=True):
|
||||
"""
|
||||
Sends an HTTP request to a specified service and path using the given HTTP method.
|
||||
"""
|
||||
global auth, refreshToken
|
||||
if service == Service.CDN or service == Service.Images:
|
||||
useAuth = False
|
||||
scheme = "http"
|
||||
if https:
|
||||
scheme = "https"
|
||||
url = f"{scheme}://{service.value}.{RecNetDomain}/{path}"
|
||||
headers = {
|
||||
"User-Agent": "BestHTTP"
|
||||
}
|
||||
if auth and useAuth:
|
||||
headers.update({
|
||||
"Authorization": f"Bearer {auth}"
|
||||
})
|
||||
req = c.request(method.value, url, headers=headers, json=json, files=files, data=data)
|
||||
if req.status_code == 401:
|
||||
if auth:
|
||||
print("Access token expired, refreshing...")
|
||||
auth = None
|
||||
re = loginWithRefreshToken(refreshToken)
|
||||
if re.error is not None:
|
||||
raise RecNetError(f"Failed to refresh token: {re.error}")
|
||||
auth = re.accessToken
|
||||
refreshToken = re.refreshToken
|
||||
sendRequest(method, service, path, json=json, files=files, data=data, https=https)
|
||||
else:
|
||||
raise RecNetError("Unauthorized: No access token provided.")
|
||||
return req
|
||||
|
||||
def genAuthCode():
|
||||
"""
|
||||
Generates a device authorization code by sending a POST request to the authentication api.
|
||||
|
||||
Returns:
|
||||
dto.DeviceAuthorization: An object containing the device authorization response if successful.
|
||||
None: If the request fails or no response is received.
|
||||
|
||||
Side Effects:
|
||||
Prints an error message to the console if the device authorization response fails.
|
||||
"""
|
||||
payload = {"client_id": "recroom.studio", "client_secret": clientSecret}
|
||||
req = sendRequest(HTTPMethod.POST, Service.Auth, "connect/deviceauthorization", data=payload)
|
||||
if req is not None:
|
||||
return dto.DeviceAuthorization(req.json())
|
||||
else:
|
||||
print("Failed to get device authorization response.")
|
||||
return None
|
||||
|
||||
def loginWithDeviceCode(DeviceCode: str):
|
||||
payload = {"client_id": "recroom.studio", "client_secret": clientSecret, "grant_type": "urn:ietf:params:oauth:grant-type:device_code", "device_code": DeviceCode}
|
||||
req = sendRequest(HTTPMethod.POST, Service.Auth, "connect/token", data=payload)
|
||||
if req is not None:
|
||||
return dto.Login(req.json())
|
||||
else:
|
||||
print("Failed to login.")
|
||||
return None
|
||||
|
||||
def loginWithRefreshToken(refreshToken: str):
|
||||
payload = {"client_id": "recroom.studio", "client_secret": clientSecret, "grant_type": "refresh_token", "refresh_token": refreshToken}
|
||||
req = sendRequest(HTTPMethod.POST, Service.Auth, "connect/token", data=payload)
|
||||
print(refreshToken)
|
||||
if req is not None:
|
||||
return dto.Login(req.json())
|
||||
else:
|
||||
print("Failed to login with refresh token.")
|
||||
return None
|
||||
|
||||
class FileType(Enum):
|
||||
Unknown = 0
|
||||
SubRoomSave = 1
|
||||
Holotar = 2
|
||||
Image = 3
|
||||
Video = 4
|
||||
Invention = 5
|
||||
RoomMetadata = 6
|
||||
|
||||
def upload(fileType: FileType, data: bytes):
|
||||
payload = {'FileType': fileType.value}
|
||||
files = {"File": ("file.bin", data, "application/octet-stream"),}
|
||||
return dto.Upload(sendRequest(HTTPMethod.POST, Service.Storage, "upload", data=payload, files=files).json())
|
||||
32
give.py
Normal file
32
give.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import httpx
|
||||
import json
|
||||
|
||||
|
||||
playerids = []
|
||||
|
||||
gay = ""
|
||||
|
||||
with open(gay) as f:
|
||||
gays = json.load(f)
|
||||
|
||||
datas = []
|
||||
|
||||
for x in playerids:
|
||||
for i in gays:
|
||||
value = {
|
||||
"RoomKeyId": i["RoomKeyId"],
|
||||
"AccountId": x
|
||||
}
|
||||
datas.append(value)
|
||||
|
||||
Authorization = ""
|
||||
|
||||
had = {
|
||||
"Authorization": "Bearer " + Authorization,
|
||||
"User-Agent": "RRStudio",
|
||||
}
|
||||
|
||||
dd = httpx.post("https://econ.rec.net/api/roomkeys/v1/awardbulk", headers=had, json=datas)
|
||||
|
||||
print(dd.status_code)
|
||||
print(dd.text)
|
||||
1
keyinfo.json
Normal file
1
keyinfo.json
Normal file
@@ -0,0 +1 @@
|
||||
[]
|
||||
152
roomcopy.py
Normal file
152
roomcopy.py
Normal file
@@ -0,0 +1,152 @@
|
||||
import RecNet as rn
|
||||
import dto
|
||||
import time
|
||||
import random
|
||||
import jwt
|
||||
import webbrowser
|
||||
import sys
|
||||
|
||||
roomName = None
|
||||
for arg in sys.argv:
|
||||
if arg.startswith("room="):
|
||||
roomName = arg.split("room=")[1]
|
||||
|
||||
if roomName is None:
|
||||
print("Missing required 'room' argument.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
roomReq = rn.sendRequest(rn.HTTPMethod.GET, rn.Service.Rooms, f"rooms?name={roomName}&include=ReplicationDetails")
|
||||
room = dto.Room(roomReq.json())
|
||||
|
||||
#if room.UgcVersion == 2:
|
||||
# print("Sorry, you can't copy UGC Version 2 (R2) rooms; this operation is not supported.")
|
||||
# sys.exit(1)
|
||||
|
||||
#if room.IsDeveloperOwned:
|
||||
# print("Sorry, you can't copy dev rooms")
|
||||
# sys.exit(2)
|
||||
|
||||
|
||||
loggedIn = False
|
||||
testauth = rn.genAuthCode()
|
||||
print(testauth.verificationUriComplete)
|
||||
webbrowser.open(testauth.verificationUriComplete)
|
||||
while not loggedIn:
|
||||
test2 = rn.loginWithDeviceCode(testauth.deviceCode)
|
||||
if test2.accessToken is not None:
|
||||
token = jwt.decode(test2.accessToken, options={"verify_signature": False})
|
||||
#print(token)
|
||||
role = token.get("role")
|
||||
betastudio = False
|
||||
if isinstance(role, list):
|
||||
if "betastudio" in role:
|
||||
betastudio = True
|
||||
elif role == "betastudio":
|
||||
betastudio = True
|
||||
if not betastudio:
|
||||
print("Your account does not have access to Beta Studio.")
|
||||
sys.exit(1)
|
||||
rn.auth = test2.accessToken
|
||||
loggedIn = True
|
||||
break
|
||||
if test2.error != "authorization_pending":
|
||||
print(f"Error: {test2.error}")
|
||||
break
|
||||
time.sleep(testauth.interval)
|
||||
|
||||
#print(test2.accessToken)
|
||||
|
||||
myAccount = rn.sendRequest(rn.HTTPMethod.GET, rn.Service.Accounts, "account/me")
|
||||
myAccount = dto.Account(myAccount.json())
|
||||
randomInt = random.randint(0, 9999)
|
||||
RoomNameC = f"{myAccount.username}s_{room.Name}_{randomInt:04d}"
|
||||
makeRoomPayload = {"name": RoomNameC, "ugcVersion": room.UgcVersion}
|
||||
newRoom = rn.sendRequest(rn.HTTPMethod.POST, rn.Service.Rooms, "rooms/create", data=makeRoomPayload)
|
||||
newRoom = dto.Room(newRoom.json()["value"])
|
||||
updateRoomPayload = {
|
||||
"name": newRoom.Name,
|
||||
"description": room.Description,
|
||||
"accessibility": 0,
|
||||
"supportsScreens": room.SupportsScreens,
|
||||
"supportsWalkVR": room.SupportsWalkVR,
|
||||
"supportsTeleportVr": room.SupportsTeleportVR,
|
||||
"supportsJuniors": room.SupportsJuniors,
|
||||
"cloningAllowed": False,
|
||||
"disableMicAutoMute": room.DisableMicAutoMute,
|
||||
"disableRoomComments": room.DisableRoomComments,
|
||||
"encryptVoiceChat": room.EncryptVoiceChat,
|
||||
}
|
||||
rn.sendRequest(rn.HTTPMethod.PUT, rn.Service.Rooms, f"rooms/{newRoom.RoomId}/modify", data=updateRoomPayload)
|
||||
|
||||
homeSubroom = None
|
||||
for x in room.SubRooms:
|
||||
if x.Name == "Home":
|
||||
homeSubroom = x
|
||||
|
||||
RoomDataM = None
|
||||
if room.DataBlob is not None:
|
||||
print(f"Downloading {room.DataBlob}")
|
||||
meataData = rn.sendRequest(rn.HTTPMethod.GET, rn.Service.CDN, f"room/{room.DataBlob}")
|
||||
print(f"Uploading room meta file")
|
||||
data = rn.upload(rn.FileType.RoomMetadata, meataData.content)
|
||||
print("Done meta file")
|
||||
RoomDataM = {
|
||||
"Filename": data.Filename,
|
||||
"Hash": data.Hash,
|
||||
"OwnershipProof": data.OwnershipProof
|
||||
}
|
||||
|
||||
def updateSubroom(myRoom: dto.Room, mySubroom: dto.Subroom, subroom: dto.Subroom):
|
||||
print(f"Downloading {subroom.CurrentSave.DataBlob}")
|
||||
fileData = rn.sendRequest(rn.HTTPMethod.GET, rn.Service.CDN, f"room/{subroom.CurrentSave.DataBlob}")
|
||||
print(fileData.status_code)
|
||||
print(f"Uploading room file from {room.Name}.{subroom.Name}")
|
||||
data = rn.upload(rn.FileType.SubRoomSave, fileData.content)
|
||||
print(f"Saving {myRoom.Name}.{mySubroom.Name}")
|
||||
savePayload = {
|
||||
"UnityAssetId": None,
|
||||
"UnityAsset": None,
|
||||
"UnitySubAssets": [],
|
||||
"ReferencedUnityAssetIds": subroom.CurrentSave.ReferencedUnityAssetIds,
|
||||
"RoomData": RoomDataM,
|
||||
"SubRoomData": {
|
||||
"Filename": data.Filename,
|
||||
"Hash": data.Hash,
|
||||
"OwnershipProof": data.OwnershipProof
|
||||
},
|
||||
"InventionUsage": "CAE=",
|
||||
"PersistenceVersion": subroom.CurrentSave.PersistenceVersion,
|
||||
"OMVersion": subroom.CurrentSave.OMVersion,
|
||||
"Description": subroom.CurrentSave.Description,
|
||||
"AutoPublish": True,
|
||||
"UgcSubVersion": subroom.CurrentSave.UgcSubVersion
|
||||
}
|
||||
save = rn.sendRequest(rn.HTTPMethod.POST, rn.Service.Rooms, f"rooms/{myRoom.RoomId}/subrooms/{mySubroom.SubRoomId}/data", json=savePayload)
|
||||
print(save)
|
||||
print(f"Done {myRoom.Name}.{mySubroom.Name}")
|
||||
|
||||
|
||||
if homeSubroom:
|
||||
updateSubroom(newRoom, newRoom.SubRooms[0], homeSubroom)
|
||||
|
||||
for x in room.SubRooms:
|
||||
if x.Name == "Home":
|
||||
continue
|
||||
if x.CurrentSave is None:
|
||||
print(f"{room.Name}.{x.Name} has no save")
|
||||
continue
|
||||
makeSubRoomPayload = {"name": x.Name}
|
||||
kklfeef = rn.sendRequest(rn.HTTPMethod.POST, rn.Service.Rooms, f"rooms/{newRoom.RoomId}/subrooms", data=makeSubRoomPayload)
|
||||
print(kklfeef.status_code)
|
||||
dataReq = kklfeef.json()
|
||||
if not dataReq["success"]:
|
||||
print(dataReq["error"])
|
||||
continue
|
||||
subrooms = dataReq["value"]["SubRooms"]
|
||||
subRoom = None
|
||||
for i in subrooms:
|
||||
if i["Name"] == x.Name:
|
||||
subRoom = dto.Subroom(i)
|
||||
break
|
||||
updateSubroom(newRoom, subRoom, x)
|
||||
BIN
yay_rr.zip
Normal file
BIN
yay_rr.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user