Community forums

scan for online players

# 1
29 Feb 2016 14:20
I wrote a little python3 script to scan for online users on your server.

Just take a look at the code it is not too hard to understand.
# 2
29 Feb 2016 14:21
#!/usr/bin/python3

import urllib.request as req

def scan_for_id(url,id):
        f = req.urlopen(url)
        text = f.read()
        text = text.decode("utf-8")
        return "playerdbid="+id in text

def scan_for_alias_by_id(url,id):
        f = req.urlopen(url)
        text = f.read()
        text = text.decode("utf-8")
        if( "playerdbid="+id in text):
                textlines = text.split("\n")
                for lineno,line in enumerate(textlines):
                        if("playerdbid="+id in line):
                                 next_line = textlines[lineno + 1]
                                 return next_line[:next_line.index("<")].strip()
        return ""

if __name__ == "__main__":
        import os, time
        PLID = "24031"
        PL_NAME = "seppl" # the usual name
        MY_ADDR = "your email here"
        __SEND_EMAIL = False
        if __SEND_EMAIL:
                while(1):
                        if(scan_for_id("http://drunknoobs.com/game-server",PLID)):
                                f = open("urt_sent.tx","w")
                                f.write("player '{}' is online (ID: {})\n".format(PL_NAME,PLID))

                                f.close()
                                os.system("mail {} < urt_sent.tx".format(MY_ADDR))
                                os.unlink("urt_sent.tx")
                                time.sleep(60)
        else:
                print(scan_for_id("http://drunknoobs.com/game-server",PLID))
                print(scan_for_alias_by_id("http://drunknoobs.com/game-server",PLID))


# 3
29 Feb 2016 14:24
What is the purpose of this? We already have code that does this (Your code parses our code for the information)
# 4
29 Feb 2016 14:25 | Last edit: 29 Feb 2016 14:28
I know. it is a frontend for your private machine.

So you are notified, if one of your friends is online.

Btw: currently your webserver does not display the online players. (I do not know why) so it does not work.
# 5
29 Feb 2016 14:59 | Last edit: 29 Feb 2016 15:01
The script that shows the online players is called in from another server, so if that server is down then online players or banned players are not shown. If the other server is up, then it works fine.

You cant expect something to work if the connection between two servers is interrupted or down. That's like expecting to be able to access the internet without a connection.
# 6
29 Feb 2016 18:23
I just metioned it, as my script relies on the data that was missing. So if you would have been testing it, it would have failed.
Powered by Kunena Forum