Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# type out of bound
self.assertFalse(SteamID(1, EType.Max).is_valid())
# universe out of bound
self.assertFalse(SteamID(1, universe=EUniverse.Max).is_valid())
# individual
self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=0).is_valid())
self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=1).is_valid())
self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=2).is_valid())
self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=3).is_valid())
self.assertTrue(SteamID(123, EType.Individual, EUniverse.Public, instance=4).is_valid())
self.assertFalse(SteamID(123, EType.Individual, EUniverse.Public, instance=5).is_valid())
self.assertFalse(SteamID(123, EType.Individual, EUniverse.Public, instance=333).is_valid())
# clan
self.assertTrue(SteamID(1, EType.Clan, EUniverse.Public, instance=0).is_valid())
self.assertFalse(SteamID(1, EType.Clan, EUniverse.Public, instance=1).is_valid())
self.assertFalse(SteamID(1, EType.Clan, EUniverse.Public, instance=1234).is_valid())
s = SteamID(123, type=EType.Clan, universe=EUniverse.Public, instance=333)
self.assertFalse(s.is_valid())
def test_as_steam2(self):
self.assertEqual(SteamID('STEAM_0:1:4').as_steam2, 'STEAM_1:1:4')
self.assertEqual(SteamID('STEAM_1:1:4').as_steam2, 'STEAM_1:1:4')
self.assertEqual(SteamID('STEAM_0:0:4').as_steam2, 'STEAM_1:0:4')
self.assertEqual(SteamID('STEAM_1:0:4').as_steam2, 'STEAM_1:0:4')
self.assertEqual(SteamID('STEAM_4:0:4').as_steam2, 'STEAM_4:0:4')
self.assertEqual(SteamID('STEAM_4:1:4').as_steam2, 'STEAM_4:1:4')
def test_kwarg_type(self):
with self.assertRaises(KeyError):
SteamID(id=5, type="doesn't exist")
with self.assertRaises(ValueError):
SteamID(id=5, type=99999999)
with self.assertRaises(KeyError):
SteamID(id=5, type=None)
self.assertEqual(SteamID(id=5, type=1).type, EType.Individual)
self.assertEqual(SteamID(id=5, type='Individual').type, EType.Individual)
self.assertEqual(SteamID(id=5, type='AnonUser').type, EType.AnonUser)
def test_as_steam3(self):
self.assertEqual(SteamID('[U:1:1234]').as_steam3, '[U:1:1234]')
self.assertEqual(SteamID('[U:1:1234:56]').as_steam3, '[U:1:1234:56]')
self.assertEqual(SteamID('[g:1:4]').as_steam3, '[g:1:4]')
self.assertEqual(SteamID('[A:1:1234:567]').as_steam3, '[A:1:1234:567]')
self.assertEqual(SteamID('[G:1:1234:567]').as_steam3, '[G:1:1234]')
self.assertEqual(SteamID('[T:1:1234]').as_steam3, '[T:1:1234]')
self.assertEqual(SteamID('[c:1:1234]').as_steam3, '[c:1:1234]')
self.assertEqual(SteamID('[L:1:1234]').as_steam3, '[L:1:1234]')
def test_args_only(self):
self.compare(SteamID(1, 2),
[1, 2, 0, 0])
self.compare(SteamID(1, 2, 3),
[1, 2, 3, 0])
self.compare(SteamID(1, 2, 3, 4),
[1, 2, 3, 4])
def test_as_steam3(self):
self.assertEqual(SteamID('[U:1:1234]').as_steam3, '[U:1:1234]')
self.assertEqual(SteamID('[U:1:1234:56]').as_steam3, '[U:1:1234:56]')
self.assertEqual(SteamID('[g:1:4]').as_steam3, '[g:1:4]')
self.assertEqual(SteamID('[A:1:1234:567]').as_steam3, '[A:1:1234:567]')
self.assertEqual(SteamID('[G:1:1234:567]').as_steam3, '[G:1:1234]')
self.assertEqual(SteamID('[T:1:1234]').as_steam3, '[T:1:1234]')
self.assertEqual(SteamID('[c:1:1234]').as_steam3, '[c:1:1234]')
self.assertEqual(SteamID('[L:1:1234]').as_steam3, '[L:1:1234]')
def _handle_add_friend_result(self, message):
eresult = EResult(message.body.eresult)
steam_id = SteamID(message.body.steam_id_added)
self.emit(self.EVENT_FRIEND_ADD_RESULT, eresult, steam_id)
},
timeout=20,
)
if resp is None:
return None
if resp.header.eresult != EResult.OK:
raise SteamError(resp.header.error_message, resp.header.eresult)
resp = proto_to_dict(resp.body)
if not resp:
return []
else:
for server in resp['servers']:
server['steamid'] = SteamID(server['steamid'])
return resp['servers']
self._finalize_login(resp)
return self.session
else:
if resp.get('captcha_needed', False):
self.captcha_gid = resp['captcha_gid']
self.captcha_code = ''
if resp.get('clear_password_field', False):
self.password = ''
raise CaptchaRequiredLoginIncorrect(resp['message'])
else:
raise CaptchaRequired(resp['message'])
elif resp.get('emailauth_needed', False):
self.steam_id = SteamID(resp['emailsteamid'])
raise EmailCodeRequired(resp['message'])
elif resp.get('requires_twofactor', False):
raise TwoFactorCodeRequired(resp['message'])
else:
self.password = ''
raise LoginIncorrect(resp['message'])
steamclient.login(username, password, auth_code=code)
Codes are required every time a user logins if sentry is not setup.
See :meth:`set_credential_location`
"""
self._LOG.debug("Attempting login")
eresult = self._pre_login()
if eresult != EResult.OK:
return eresult
self.username = username
message = MsgProto(EMsg.ClientLogon)
message.header.steamid = SteamID(type='Individual', universe='Public')
message.body.protocol_version = 65580
message.body.client_package_version = 1561159470
message.body.client_os_type = EOSType.Windows10
message.body.client_language = "english"
message.body.should_remember_password = True
message.body.supports_rate_limit_response = True
message.body.chat_mode = self.chat_mode
if login_id is None:
message.body.obfuscated_private_ip.v4 = ip_to_int(self.connection.local_address) ^ 0xF00DBAAD
else:
message.body.obfuscated_private_ip.v4 = login_id
message.body.account_name = username
if login_key: