forked from bmillwood/tremulous-master
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogtdb.py
27 lines (21 loc) · 860 Bytes
/
logtdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# db.py
# Copyright (c) Ben Millwood 2009
# This file is part of the Tremulous Master server.
from contextlib import closing
from os import O_RDWR, O_CREAT
from tdb import Tdb
from time import asctime, gmtime
db_id = 'Using TDB database backend'
def log_client(addr, info):
# TODO: check if flags are necessary
with closing(Tdb('clientStats.tdb',
flags = O_RDWR|O_CREAT)) as database:
version = info['version']
renderer = info['renderer']
if '\"' in version + renderer:
raise ValueError('Invalid character in info string')
database[addr.host] = '"{0}" "{1}"'.format(version, renderer)
def log_gamestat(addr, data):
with closing(Tdb('gameStats.tdb', flags = O_RDWR|O_CREAT)) as database:
key = '{0} {1}'.format(addr.host, asctime(gmtime()))
database[key] = data