[SCRIPT] Player Logger

Intended for use on live public servers.
16 posts Page 1 of 2 First unread post
gamemaster77
Deuce
Posts: 3
Joined: Fri Feb 22, 2013 9:33 pm


This script will log every logon and disconnect to the server to find who is on between a time range or at a specific time. Useful for build servers or any other servers where someone did something wrong at a certain time and you need to find who was online. The command /findusers will return all of the players online paired with their ips during the interval you specify. The logs are also saved at server exit and loaded at server start. You must CTRL-C exit the server for the log to save at the end, however. I might also update it during the future to include who a player is logged in as if they're logged in (only at a specific point though. It cant work during intervals because people can login, leave, come back and login multiple times during a range)
Code: Select all
#-------------------------------------------------------------------------------
# Name:        Player Logger
# Purpose:     Logs when players are on and off the server. Can find what
#              players were on the server during a specific time interval by
#              using /findusers timeinterval1 timeinterval2 day month year
#              Each time interval should be in the form hour:minute:second
#              If the intervals are the same it finds the users logged on at
#              that point in time. If day, month, or year is left out it will
#              use the current day, month, or year at the time the command is
#              used. Logs are saved on disconnect to the file specified at the
#              beginning of this script.
#
#              WARNING: YOU MUST CTRL-C EXIT THE SERVER FOR THE LOG TO SAVE. IT
#              WILL NOT SAVE IF YOU JUST EXIT THE WINDOW
#
# Author:      Gamemaster77
#-------------------------------------------------------------------------------
Here's an example (defaults to current, day, month, and year):
/findusers 10:00:00 10:10:00
(jacksmack => 45.83.74.140) , (dan => 123.56.11.100) were logged on
Attachments
logger.py
(7.08 KiB) Downloaded 313 times
Bux Xray
3 Years of Ace of Spades
3 Years of Ace of Spades
Posts: 218
Joined: Sat Aug 24, 2013 9:07 am


Game...nice
do you use it at Build4yourlife?
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


maybe a simple database would be better for storing this stuff?
Kuma
Scripter
Scripter
Posts: 758
Joined: Fri Mar 22, 2013 10:05 am


I think search by name and ip should be added.
gamemaster77
Deuce
Posts: 3
Joined: Fri Feb 22, 2013 9:33 pm


learn_more wrote:
maybe a simple database would be better for storing this stuff?
Well I tried looking into shelve to write these to a file as they go along. It said that it is sometimes tricky to use with mutable python objects, and I store them in one big nested dictionary right now. So I just figured I'd just save it at the end because I haven't done much with other databases.
Kuma wrote:
I think search by name and ip should be added.
I should be able to add that pretty easily. It cycles through names and ips already when it searches.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


For a *simple* file database
Code: Select all
def save_database(di):
    f=open("file.txt","w")
    f.write(str(di) )
    f.close() 

def load_database():
    f=open("file.txt","r")
    di=f.read() 
    F.close()
    try:
        return eval(di)
    except Exception(error):
        print error
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


bad idea to use eval on user input (usernames = user input)
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


He said it is in dictionary format; what I am suggesting is opening a dictionary from a file and then change it, then write it back to the file. Villa, stored dictionary. At no point do you Eval any usernames
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


>>return eval(di)
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


di should be a string of a dictionary
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


rakiru
Coder
Coder
Posts: 1349
Joined: Sun Nov 11, 2012 12:26 pm


I'd suggest SQLite or similar too, but if you want to just save the dict to a flat file and load it again, use json or pickle, definitely not eval.
thepolm3
Scripter
Scripter
Posts: 424
Joined: Sat Feb 16, 2013 10:49 pm


*simple*
It's obviously not the best method at all. I'd agree that using sql or json would be better
learn_more
Coder
Coder
Posts: 891
Joined: Sun Mar 24, 2013 9:59 pm


thepolm3 wrote:
*simple*
It's obviously not the best method at all. I'd agree that using sql or json would be better
in this case i would prefer not over the simple method.
rakiru
Coder
Coder
Posts: 1349
Joined: Sun Nov 11, 2012 12:26 pm


json/pickle would be just as simple though:
Code: Select all
import json

def save_database(db):
    with open("db.json", "w") as fp:
        json.dump(db, fp)

def load_database():
    with open("db.json", "r") as fp:
        return json.load(fp)
Code: Select all
import cPickle as pickle

def save_database(db):
    with open("db.pickle", "wb") as fp:
        pickle.dump(db, fp)

def load_database():
    with open("db.pickle", "rb") as fp:
        return pickle.load(fp)
Going a little further than the pickle module, you could use shelve. After that, SQLite would be the thing to use.
16 posts Page 1 of 2 First unread post
Return to “Completed Releases”

Who is online

Users browsing this forum: No registered users and 0 guests