Python Forum
How can I stop the script when I run the game on my own computer?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I stop the script when I run the game on my own computer?
#1
hi friends i am trying to make a steam hour bot. I'm running this bot on my ubuntu system like this on "screen -S idle python3 xxx.py" . What I want to do is to close the screen when I enter a game on my computer, I want the bot to close itself.. The code I use is below.

import logging
from steam.client import SteamClient
from steam.enums import EResult
from steam.enums import EFriendRelationship, EPersonaState, EChatEntryType
from steam.client import user
# setup logging
logging.basicConfig(format="%(asctime)s | %(message)s", level=logging.INFO)
LOG = logging.getLogger()

client = SteamClient()
client.set_credential_location(".")  # where to store sentry files and other stuff
server_ip=client.current_server_addr
@client.on("error")
def handle_error(result):
    LOG.info("Logon result: %s", repr(result))

@client.on("channel_secured")
def send_login():
    if client.relogin_available:
        client.relogin()

@client.on("connected")
def handle_connected():
    LOG.info("Connected to %s", client.current_server_addr)
@client.on("reconnect")
def handle_reconnect(delay):
    LOG.info("Out...")
    LOG.info("Reconnect in %ds...", delay)
    client.logout()
    raise SystemExit

@client.on("disconnected")
def handle_disconnect():
    LOG.info("Disconnected.")
    client.disconnect()


    if client.relogin_available:
        LOG.info("Reconnecting...")
        client.reconnect(maxdelay=30)


@client.on("logged_on")
def handle_after_logon():
    LOG.info("-"*30)
    LOG.info("Logged on as: %s", client.user.name)
    LOG.info("Community profile: %s", client.steam_id.community_url)
    LOG.info("Last logon: %s", client.user.last_logon)
    LOG.info("Last logoff: %s", client.user.last_logoff)
    LOG.info("-"*30)
    LOG.info("Press ^C to exit")


# main bit
LOG.info("Persistent logon recipe")
LOG.info("-"*30)

try:
    result = client.cli_login("username","password")
    if result != EResult.OK:
        LOG.info("Failed to login: %s" % repr(result))
        raise SystemExit

    else:
        client.get_web_session("English")
        client.games_played([730])
        client.change_status(persona_state=EPersonaState.Online, player_name='xxx')
        client.run_forever()

except KeyboardInterrupt:
    if client.connected:
        LOG.info("Logout")
        client.logout()
library documentation i use; https://steam.readthedocs.io/en/latest/a...l_location
When I enter the game from steam on my own computer, it catches my connection and continues to scirpt I want it to close.
Reply
#2
A really crude way if nothing else works would be
import os, signal
os.kill(os.getpid(), signal.SIGKILL)
Reply
#3
(Jun-19-2020, 08:23 AM)Gribouillis Wrote: A really crude way if nothing else works would be
import os, signal
os.kill(os.getpid(), signal.SIGKILL)

first of all thank you for your answer. I did not know that the PID number was received like this. I'm writing 20 lines of code to get the PID number lol. I want to do as you say, but I cannot check that you have logged in from another place. if I can control it, everything will be resolved.
if result.LoggedInElsewhere:
        client.logout()

I tried this way, but for some reason it connects directly and the connection is broken.


Screen shot when I connect with python.
Image

When I connect from my own computer, the bot does not close and shows my connection.
Image
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Button to stop while loop from another script Absolutewind 5 819 Sep-25-2023, 11:20 PM
Last Post: deanhystad
  non-stop ping script kucingkembar 1 1,321 Aug-23-2022, 06:29 AM
Last Post: menator01
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,533 Sep-27-2021, 05:40 PM
Last Post: rondon442
  how to stop and start a script for 30 seconds laspaul 9 7,516 Jan-16-2020, 02:13 PM
Last Post: laspaul
  win10 Service(script) start and stop hwa_rang098tkd 0 2,430 Jun-21-2018, 07:42 PM
Last Post: hwa_rang098tkd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020