class csgo_client (object): def __init__(self, config): self._client = SteamClient() self._client.set_credential_location(config["steam_credential_location"]) self._cs = CSGOClient(self._client) self._ready = False @self._client.on("channel_secured") def send_login(): if self._client.relogin_available: self._client.relogin() @self._client.on("disconnected") def handle_disconnect(): logging.warning("disconnected from steam") if self._client.relogin_available: self._client.reconnect(maxdelay=10) @self._client.on('logged_on') def start_csgo(): logging.info("connecting to csgo") self._cs.launch() @self._cs.on('ready') def gc_ready(): logging.info("connected") self._ready = True self._client.cli_login(username=config["steam_bot_username"], password=config["steam_bot_password"]) while not self._ready: self._client.sleep(0.125) def send(self, *args, **kwargs): self._cs.send(*args, **kwargs) def wait_event(self, *args, **kwargs): return self._cs.wait_event(*args, **kwargs) def get_item_killcount(self, s, a, d): if not self._cs.connection_status == GCConnectionStatus.HAVE_SESSION: logging.warning("not connected to GC") raise ValueError("not connected to gc") self.send(ECsgoGCMsg.EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest, { 'param_s': s, 'param_a': a, 'param_d': d, 'param_m': 0 }) response, = self.wait_event(ECsgoGCMsg.EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse, timeout=2) if response.iteminfo.itemid != a: raise ValueError("mismatched req/rep") return response.iteminfo.killeatervalue
def main(local_mode = True): try: steam_path = SteamDataReader.get_steam_installpath() except: print("Could not find steam install path") sys.exit(1) print("Steam path:",steam_path) if local_mode: steam_data_reader = SteamDataReaderLocal(steam_path) try: steamid = steam_data_reader.get_steam_id() if not steamid.is_valid(): steamid = SteamID(input_steamid()) if not steamid.is_valid(): print("Invalid steam id") sys.exit(2) print("SteamID:",steamid.as_32) except Exception as error: print(error) print("Switch to remote mode") local_mode = False if not local_mode: client = SteamClient() if client.cli_login() != EResult.OK: print("Login Error") sys.exit(3) else: print("Login Success") steam_data_reader = SteamDataReaderRemote(client) steamid = client.steam_id print("SteamID:",steamid.as_32) steam_grid_path = STEAM_GRIDPATH.format(steam_path,steamid.as_32) if not os.path.isdir(steam_grid_path): os.mkdir(steam_grid_path) print("Steam grid path:",steam_grid_path) missing_cover_app_dict = steam_data_reader.get_missing_cover_app_dict(not local_mode) print("Total games missing cover in library:",len(missing_cover_app_dict)) local_cover_appids = {int(file[:len(file)-5]) for file in os.listdir(steam_grid_path) if re.match(r"^\d+p.(png|jpg)$",file)} print("Total local covers found:",len(local_cover_appids)) local_missing_cover_appids = missing_cover_app_dict.keys() - local_cover_appids print("Total missing covers locally:",len(local_missing_cover_appids)) print("Finding covers from steamgriddb.com") local_missing_cover_appids = list(local_missing_cover_appids) local_missing_cover_appids.sort() total_downloaded = asyncio.run(download_covers_temp(local_missing_cover_appids,steam_grid_path,missing_cover_app_dict)) print("Total cover downloaded:",total_downloaded)
def command(): client = SteamClient() client.set_credential_location(settings.STEAM_SENTRY_DIR) for index, username in enumerate(settings.STEAM_USERNAMES): click.echo(f"Logging into Steam as {username}...") client.cli_login(username=username, password=settings.STEAM_PASSWORDS[index]) time.sleep(5) # copy to correct location for `auth-ticket.js` src = os.path.join(settings.STEAM_SENTRY_DIR, f"{username}_sentry.bin") dest = os.path.join(settings.STEAM_SENTRY_DIR, f"sentry.{username}.bin") copy2(src, dest) click.echo("Login successful. Steam Guard should not prompt anymore") client.logout()
room_name = sys.argv[1] room_pass = sys.argv[2] params = sys.argv[3:] players = {} for i in range(0, len(params), 2): player_id = params[i] team = params[i + 1] players[int(player_id)] = {"team": team, "slot": None} @client.on('logged_on') def start_dota(): dota.launch() @dota.on('ready') def on_dota_ready(): manage_lobby(dota, client, room_name, room_pass, players) @dota.on(dota2.features.Lobby.EVENT_LOBBY_CHANGED) def lobby_update(lobby): manage_lobby_players(dota, lobby, players) client.cli_login(username="******", password="******") client.run_forever()
from __future__ import print_function from steam.client import SteamClient from steam.enums import EResult client = SteamClient() print("One-off login recipe") print("-" * 20) result = client.cli_login() if result != EResult.OK: print("Failed to login: %s" % repr(result)) raise SystemExit print("-" * 20) print("Logged on as:", client.user.name) print("Community profile:", client.steam_id.community_url) print("Last logon:", client.user.last_logon) print("Last logoff:", client.user.last_logoff) client.logout()
from steam.client import SteamClient, EMsg from steam.enums import EResult, ECurrencyCode client = SteamClient() @client.on(EMsg.ClientWalletInfoUpdate) def print_balance(msg): bucks, cents = divmod(msg.body.balance64, 100) print("Current balance is {:d}.{:02d} {:s}".format(bucks, cents, ECurrencyCode(msg.body.currency).name )) client.cli_login() client.disconnect()
client = SteamClient() dota = Dota2Client(client) print("hello") @client.on('logged_on') def status_logged(): print('WE ARE LOGGED ON') @dota.on('ready') def do_dota_stuff(): print("the game is ready") client.cli_login() client.run_forever() #start_dota() print('life') @dota.on('my event') def do_stuff(a, b): print "Hey!" dota.on('my event', do_stuff) dota.once('my event', do_stuff) # call do_stuff just one time dota.wait_event('my event') # blocks and returns arguments, if any
def main(): try: steam_path = SteamDataReader.get_steam_installpath() except: print("Could not find steam install path") sys.exit(1) print("Steam path:", steam_path) parser = argparse.ArgumentParser( description= 'Downloads missing covers for new steam UI. Covers are downloaded from steamgriddb.com' ) parser.add_argument('-l', '--local', action='store_true', dest='local_mode', help='Local mode, this is the default operation.') parser.add_argument( '-r', '--remote', action='store_true', dest='remote_mode', help= 'Remote mode, if both local and remote are specified, will try local mode first.' ) parser.add_argument('-m', '--minscore', dest='min_score', type=int, default=None, help='Set min score for a cover to be downloaded.') parser.add_argument( '-s', '--styles', dest='styles', type=str, default=None, help= 'Set styles of cover, can be comma separated list of alternate, blurred, white_logo, material or no_logo.' ) parser.add_argument( '-o', '--overwrite', action='store_true', dest='overwrite', help= 'Overwrite covers that are already present in local steam grid path.') parser.add_argument( '-d', '--delete-local', action='store_true', dest='delete_local', help='Delete local covers for games that already have official ones.') args = parser.parse_args() local_mode = True remote_fallback = True if not args.local_mode and args.remote_mode: local_mode = False elif args.local_mode and not args.remote_mode: remote_fallback = False if local_mode: steam_data_reader = SteamDataReaderLocal(steam_path) try: steamid = steam_data_reader.get_steam_id() if not steamid.is_valid(): steamid = SteamID(input_steamid()) if not steamid.is_valid(): print("Invalid steam id") sys.exit(2) print("SteamID:", steamid.as_32) except Exception as error: print(error) if remote_fallback: print("Switch to remote mode") local_mode = False else: sys.exit(2) if not local_mode: client = SteamClient() if client.cli_login() != EResult.OK: print("Login Error") sys.exit(3) else: print("Login Success") steam_data_reader = SteamDataReaderRemote(client) steamid = client.steam_id print("SteamID:", steamid.as_32) steam_grid_path = STEAM_GRIDPATH.format(steam_path, steamid.as_32) if not os.path.isdir(steam_grid_path): os.mkdir(steam_grid_path) print("Steam grid path:", steam_grid_path) missing_cover_app_dict = steam_data_reader.get_missing_cover_app_dict( not local_mode) print("Total games missing cover in library:", len(missing_cover_app_dict)) local_cover_map = { int(file[:len(file) - 5]): file for file in os.listdir(steam_grid_path) if re.match(r"^\d+p.(png|jpg)$", file) } local_cover_appids = set(local_cover_map.keys()) print("Total local covers found:", len(local_cover_appids)) local_missing_cover_appids = missing_cover_app_dict.keys( ) - local_cover_appids print("Total missing covers locally:", len(local_missing_cover_appids)) if args.overwrite: local_missing_cover_appids = set(missing_cover_app_dict.keys()) if args.delete_local: local_duplicate_cover_appids = local_cover_appids - missing_cover_app_dict.keys( ) print( f'Found {len(local_duplicate_cover_appids)} games already have official covers.' ) for appid in local_duplicate_cover_appids: path = os.path.join(steam_grid_path, local_cover_map[appid]) print(f'Deleting file {path}') os.remove(path) print("Finding covers from steamgriddb.com") local_missing_cover_appids = list(local_missing_cover_appids) local_missing_cover_appids.sort() total_downloaded = asyncio.run( download_covers(local_missing_cover_appids, steam_grid_path, missing_cover_app_dict, args)) print("Total cover downloaded:", total_downloaded)
def run_account(acc): client = SteamClient() client.set_credential_location('creds') cs = CSGOClient(client) profile = gevent.event.Event() matches = gevent.event.Event() events.append(profile) events.append(matches) @client.on('logged_on') def start_csgo(): print("Logged in!") cs.launch() print("Launched CS:GO") @client.on('new_login_key') def key(): print(f"New login key for {acc['username']}!") acc['login_key'] = client.login_key #@client.on(None) #def kek(msgtype, msg=None): # print(msgtype) # print(msg) @client.on(EMsg.ClientVACBanStatus) def vac_status(msg): acc['bans'] = msg.body.numBans @client.on(EMsg.ClientEmailAddrInfo) def email(msg): acc['email'] = msg.body.email_address @client.on(EMsg.ClientAccountInfo) def name(msg): acc['name'] = msg.body.persona_name @client.on(EMsg.ClientWalletInfoUpdate) def name(msg): if msg.body.currency: acc['wallet_balance'] = msg.body.balance64 acc['wallet_balance_delayed'] = msg.body.balance64_delayed acc['wallet_currency'] = msg.body.currency @cs.on('ready') def gc_ready(): print("CS:GO Ready!") cs.request_player_profile(cs.account_id) cs.request_recent_user_games(cs.account_id) print("Requested player profile info") @cs.on('recent_user_games') def got_matches(resp): if len(resp.matches) > 0: acc['last_mm'] = resp.matches[-1].matchtime matches.set() @cs.on('player_profile') def got_profile(response): if response.account_id == cs.account_id: print(f"Got {acc['username']} CS:GO profile!") acc['csgo_profile'] = json.loads(json_format.MessageToJson(response)) #cs.exit() #client.logout() profile.set() # def cleanup(): print(f'Logging in to {acc["username"]}') if 'login_key' not in acc or client.login(acc['username'], login_key=acc['login_key']) != 1: client.cli_login(acc['username'], acc['password'])
from steam.client import SteamClient from steam.steamid import SteamID from csgo.client import CSGOClient from csgo.sharecode import decode client = SteamClient() cs = CSGOClient(client) @client.on('logged_on') def start_csgo(): cs.launch() @cs.on('ready') def gc_ready(): share_code = # https://developer.valvesoftware.com/wiki/Counter-Strike:_Global_Offensive_Access_Match_History, loop until HTTP CODE 202 for the last sharecode, rate limitations apply. decoded = decode(share_code) matchID = decoded['matchid'] outcomeID = decoded['outcomeid'] token = decoded['token'] cs.request_full_match_info(matchID, outcomeID, token) response, = cs.wait_event("full_match_info") print(response) pass client.cli_login(username="", password="") client.run_forever()
def main(local_mode = True): try: steam_path = get_steam_installpath() except: print("Could not find steam install path") sys.exit(1) print("Steam path:",steam_path) local_mode = True if local_mode: try: steamid = SteamID(get_steamid_local(steam_path)) if not steamid.is_valid(): steamid = SteamID(input_steamid()) if not steamid.is_valid(): sys.exit(2) print("SteamID:",steamid.as_32) steam_grid_path = STEAM_GRIDPATH.format(steam_path,steamid.as_32) if not os.path.isdir(steam_grid_path): os.mkdir(steam_grid_path) print("Steam grid path:",steam_grid_path) print("Reading cached appinfo") owned_apps = get_app_details_local(steam_path) print("Total apps in library:",len(owned_apps)) missing_cover_apps = get_missing_cover_apps(owned_apps) missing_cover_appids = set(missing_cover_apps.keys()) except Exception as error: print(error) print("Switch to remote mode") local_mode = False if not local_mode: client = SteamClient() owned_apps = [] if client.cli_login() != EResult.OK: print("Login Error") sys.exit(3) else: print("Login Success") steamid = client.steam_id print("SteamID:",steamid.as_32) steam_grid_path = STEAM_GRIDPATH.format(steam_path,steamid.as_32) if not os.path.isdir(steam_grid_path): os.mkdir(steam_grid_path) print("Steam grid path:",steam_grid_path) owned_packageids = get_owned_packages(client) print("Total packages in library:",len(owned_packageids)) owned_packages = get_package_details(client,owned_packageids) print("Retriving package details") owned_appids = get_appids_from_packages(owned_packages) print("Total apps in library:",len(owned_appids)) if os.path.exists("missingcoverdb.json"): with open("missingcoverdb.json",encoding="utf-8") as f: missing_cover_apps = {int(appid):value for appid,value in json.load(f).items()} print("Loaded database with {} apps missing covers".format(len(missing_cover_apps))) else: print("Getting app details") owned_apps = get_app_details(client,owned_appids) missing_cover_apps = get_missing_cover_apps(owned_apps) client.logout() missing_cover_appids = set(missing_cover_apps.keys()) & set(owned_appids) print("Total games missing cover in library:",len(missing_cover_appids)) local_cover_appids = {int(file[:len(file)-5]) for file in os.listdir(steam_grid_path) if re.match(r"^\d+p.(png|jpg)$",file)} print("Total local covers found:",len(local_cover_appids)) local_missing_cover_appids = missing_cover_appids - local_cover_appids print("Total missing covers locally:",len(local_missing_cover_appids)) print("Finding covers from steamgriddb.com") local_missing_cover_appids = list(local_missing_cover_appids) total_downloaded = download_covers_temp(local_missing_cover_appids,steam_grid_path,missing_cover_apps) print("Total cover downloaded:",total_downloaded)
if __name__ == "__main__": save = questionary.confirm( default=True, message="Save your input to a cache file?").ask() pre_username = load_from_cache('username') pre_password = load_from_cache('password') pre_selected_friends = load_from_cache('selected_friends') username = questionary.text(default=pre_username, message="Your Steam username?").ask() password = questionary.password(default=pre_password, message="Your Steam password?").ask() if save: merge_to_cache({'username': username, 'password': password}) cl = SteamClient() cl.set_credential_location('.') cl.cli_login(username=username, password=password) api = WebAPI(key=fetch_web_api_key(cl)) friends = list( fetch_friends(cl) ) # we need to listify it, to be able to use it twice. TODO: Investigate how to clone generator/iterator? loop = True while loop: pre_selected_friends = load_from_cache('selected_friends') qfriends = list( questionize_friends(deepcopy(friends), pre_selected_friends)) selected_friends = questionary.checkbox('Select friends to compare', choices=qfriends).ask() if save:
def create_steam_session(): client = SteamClient() client.cli_login() return client
dota.practice_lobby_kick(account_id=steam32) if obj.members[i].team == 4: playerslot[9]['slot'] = None if obj.members[i].id == player10: steam32 = converteridto32(player10) if player10time == 'rad': if obj.members[i].team == 0: playerslot[10]['slot'] = obj.members[i].name if obj.members[i].team == 1: playerslot[10]['slot'] = None dota.practice_lobby_kick(account_id=steam32) if obj.members[i].team == 4: playerslot[10]['slot'] = None elif player10time == 'dir': if obj.members[i].team == 1: playerslot[10]['slot'] = obj.members[i].name if obj.members[i].team == 0: playerslot[10]['slot'] = None dota.practice_lobby_kick(account_id=steam32) if obj.members[i].team == 4: playerslot[10]['slot'] = None client.cli_login(username=bot_user, password=bot_pass) client.run_forever()