Created
October 20, 2023 07:26
-
-
Save cetteup/c8a47917176477d4c38bb9512a6d3b0e to your computer and use it in GitHub Desktop.
FESL add and login as persona
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from urllib.parse import quote | |
from pybfbc2stats import Platform, FeslClient, SecureConnection, TheaterClient | |
from pybfbc2stats.constants import FeslTransmissionType | |
from pybfbc2stats.packet import FeslPacket | |
def main(): | |
client = FeslClient('', '', Platform.pc, track_steps=False) | |
client.connection = SecureConnection( | |
'beach-ps3.fesl.ea.com', | |
18231, | |
FeslPacket, | |
client.connection.timeout | |
) | |
client.client_string = b'beach-ps3' | |
client.hello() | |
# Login via email | |
email = b'ea_acount_email' | |
password = b'ea_account_password' | |
tid = client.get_transaction_id() | |
packet = FeslPacket.build( | |
b'acct', | |
b'TXN=NuLogin\nreturnEncryptedInfo=0\n' | |
b'nuid=' + email + b'\npassword=' + password + b'\nmacAddr=$000000000000', | |
FeslTransmissionType.SinglePacketRequest, | |
tid | |
) | |
# Alternatively login via acount name | |
# username = b'ea_acount_username' | |
# password = b'ea_account_password' | |
# tid = client.get_transaction_id() | |
# packet = FeslPacket.build( | |
# b'acct', | |
# b'TXN=Login\nreturnEncryptedInfo=0\n' | |
# b'name=' + username + b'\npassword=' + password + b'\nmacAddr=$000000000000', | |
# FeslTransmissionType.SinglePacketRequest, | |
# tid | |
# ) | |
client.connection.write(packet) | |
client.wrapped_read(tid) | |
# Check for existing personas | |
tid = client.get_transaction_id() | |
packet = FeslPacket.build( | |
b'acct', | |
b'TXN=NuGetPersonas', | |
FeslTransmissionType.SinglePacketRequest, | |
tid | |
) | |
client.connection.write(packet) | |
response = client.wrapped_read(tid) | |
personas, *_ = client.parse_str_list_response(response.get_data(), b'personas.') | |
# Add new persona | |
persona_name = b'name_of_persona_to_create' | |
tid = client.get_transaction_id() | |
packet = FeslPacket.build( | |
b'acct', | |
b'TXN=NuAddPersona\nname=' + persona_name, | |
FeslTransmissionType.SinglePacketRequest, | |
tid | |
) | |
client.connection.write(packet) | |
client.wrapped_read(tid) | |
# Check if persona was created | |
tid = client.get_transaction_id() | |
packet = FeslPacket.build( | |
b'acct', | |
b'TXN=NuGetPersonas', | |
FeslTransmissionType.SinglePacketRequest, | |
tid | |
) | |
client.connection.write(packet) | |
response = client.wrapped_read(tid) | |
personas, *_ = client.parse_str_list_response(response.get_data(), b'personas.') | |
# Login as persona | |
tid = client.get_transaction_id() | |
packet = FeslPacket.build( | |
b'acct', | |
b'TXN=NuLoginPersona\nname=' + persona_name, | |
FeslTransmissionType.SinglePacketRequest, | |
tid | |
) | |
client.connection.write(packet) | |
response = client.wrapped_read(tid) | |
parsed = client.parse_simple_response(response) | |
hostname, port = client.get_theater_details() | |
client.logout() | |
client.connection.close() | |
# Verify that Theater now shows persona name as logged in | |
try: | |
with TheaterClient(hostname, port, parsed['lkey'], Platform.ps3) as theaterClient: | |
theaterClient.client_string = b'beach-ps3' | |
theaterClient.authenticate() | |
except Exception as e: | |
print(e) | |
pass | |
if __name__ == '__main__': | |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)-8s %(message)s') | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment