1 |
# CFLog.py - CFLog class |
2 |
# |
3 |
# Copyright (C) 2002 Joris Bontje |
4 |
# |
5 |
# This program is free software; you can redistribute it and/or modify |
6 |
# it under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 2 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# This program is distributed in the hope that it will be useful, |
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with this program; if not, write to the Free Software |
17 |
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 |
# |
19 |
# The author can be reached via e-mail at jbontje@suespammers.org |
20 |
# |
21 |
|
22 |
# Updated to use new path functions in CFPython -Todd Mitchell |
23 |
# |
24 |
# Updated to add new fields and functions (kick, muzzle) |
25 |
# and rewritten to use plain text file storage (CFDataFile) instead of shelve. |
26 |
|
27 |
|
28 |
import Crossfire |
29 |
|
30 |
from time import localtime, strftime, time |
31 |
from CFDataFile import CFDataFile, CFData |
32 |
|
33 |
class CFLog: |
34 |
|
35 |
def __init__(self): |
36 |
logheader = ['Born', 'IP', 'Last_Login_Date', 'Login_Count', 'Kick_Count' |
37 |
, 'Last_Kick_Date', 'Muzzle_Count', 'Last_Muzzle_Date', 'Last_Logout_Date'] |
38 |
self.log = CFData('Player_log', logheader) |
39 |
|
40 |
def create(self, name): |
41 |
date = time() |
42 |
record={'#': name |
43 |
,'Born':date |
44 |
,'IP':'unknown' |
45 |
,'Last_Login_Date':date |
46 |
,'Login_Count':0 |
47 |
,'Kick_Count':0 |
48 |
,'Last_Kick_Date':'never' |
49 |
,'Muzzle_Count':0 |
50 |
,'Last_Muzzle_Date':'never' |
51 |
,'Last_Logout_Date':0} |
52 |
self.log.put_record(record) |
53 |
|
54 |
def remove(self, name): |
55 |
self.log.remove_record(name) |
56 |
|
57 |
def login_update(self, name, ip): |
58 |
date = time() |
59 |
record = self.log.get_record(name) |
60 |
record['IP']=ip |
61 |
record['Last_Login_Date']=date |
62 |
record['Login_Count']=int(record['Login_Count'])+1 |
63 |
record['Last_Logout_Date']=0 |
64 |
self.log.put_record(record) |
65 |
|
66 |
def logout_update(self, name): |
67 |
date = time() |
68 |
record = self.log.get_record(name) |
69 |
record['Last_Logout_Date']=date |
70 |
self.log.put_record(record) |
71 |
|
72 |
def kick_update(self, name): |
73 |
date = time() |
74 |
record = self.log.get_record(name) |
75 |
record['Kick_Count']=int(record['Kick_Count'])+1 |
76 |
record['Last_Kick_Date']=date |
77 |
self.log.put_record(record) |
78 |
|
79 |
def muzzle_update(self, name): |
80 |
date = time() |
81 |
record = self.log.get_record(name) |
82 |
record['Muzzle_Count']=int(record['Muzzle_Count'])+1 |
83 |
record['Last_Muzzle_Date']=date |
84 |
self.log.put_record(record) |
85 |
|
86 |
def info(self, name): |
87 |
if name == '#': |
88 |
return 0 |
89 |
record = self.log.get_record(name) |
90 |
if record: |
91 |
return record |
92 |
else: |
93 |
return 0 |