#๐Ÿ”’ Feedback on game script detecting matches between active connection and database?

4 messages ยท Page 1 of 1 (latest)

zealous epoch
#

So I have script as part of my backend for a game. On occasion, I may have a user who is not registered but is still able to connect to my server.

What this script does is that it first looks through all active connections line by line, some of which may include an id. So if it finds the id, the server then compares it to a list of registered users. After looping once through all registered users and it finds no matches, the server kicks the player. Otherwise if a match is found, the server continues on to the next line in the connection list.

Is there a better way to write this? I am open to feedback. It works generally, but I find it janky to use found variable to make the determination whether there is a match or not. By default, it is false so unless there is a match, the server will kick the user.

def kickUnknown():
    connLines = os.popen('sudo docker exec game --traffic').readlines()
    for connLine in connLines:
        conn = re.findall("\d+[abc]\d+", connLine)
        if len(conn) > 0:
            certLines = os.popen('sudo docker exec game --regClients').readlines()
            found = False
            for certLine in certLines:
                if certLine.__contains__(conn[0]):
                    print('match b/w db and conn list')
                    found = True
            if found == True:
                # conn found in registered db, do nothing
            elif found == False:
                id = re.findall("(?<=')[^']+(?=')", connLine)
                if len(id) > 0:
                    res = os.popen("sudo docker exec game --kick --id " + "'" + id[0] + "'")
                    print('kicked unregistered user:' + conn[0])
gaunt copperBOT
#

@zealous epoch

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gaunt copperBOT
#

@zealous epoch

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.