Crossfire Server, Trunk
CFLog.py
Go to the documentation of this file.
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 from time import localtime, strftime, strptime, time
28 
29 import Crossfire
30 from CFDataFile import CFDataFile, CFData
31 
32 TimeFormat = "%a, %d %b %Y %H:%M:%S %Z"
33 
34 class CFLog:
35 
36  def __init__(self):
37  logheader = ['Born', 'IP', 'Last_Login_Date', 'Login_Count', 'Kick_Count'
38  , 'Last_Kick_Date', 'Muzzle_Count', 'Last_Muzzle_Date']
39  self.log = CFData('Player_log', logheader)
40 
41  def create(self, name):
42  date = strftime(TimeFormat, localtime(time()))
43  record={'#': name
44  ,'Born':date
45  ,'IP':'unknown'
46  ,'Last_Login_Date':date
47  ,'Login_Count':0
48  ,'Kick_Count':0
49  ,'Last_Kick_Date':'never'
50  ,'Muzzle_Count':0
51  ,'Last_Muzzle_Date':'never'}
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 = strftime(TimeFormat, localtime(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  self.log.put_record(record)
64 
65  def last_login(self, name):
66  record = self.info(name)
67  try:
68  r = record['Last_Login_Date']
69  return strptime(r, TimeFormat)
70  except ValueError:
71  # If the server time zone changes, then %Z will no longer parse.
72  # Remove the time zone and try again.
73  BackupTimeFormat = "%a, %d %b %Y %H:%M:%S"
74  try:
75  time_no_tz = " ".join(r.split(" ")[:-1])
76  return strptime(time_no_tz, BackupTimeFormat)
77  except Exception as e:
78  Crossfire.Log(Crossfire.LogDebug, "CFLog: Failed to parse time: " + str(e))
79  return None
80  except Exception as e:
81  Crossfire.Log(Crossfire.LogDebug, "CFLog: Failed to parse time: " + str(e))
82  return None
83 
84  def kick_update(self, name):
85  date = strftime(TimeFormat, localtime(time()))
86  record = self.log.get_record(name)
87  record['Kick_Count']=int(record['Kick_Count'])+1
88  record['Last_Kick_Date']=date
89  self.log.put_record(record)
90 
91  def muzzle_update(self, name):
92  date = strftime(TimeFormat, localtime(time()))
93  record = self.log.get_record(name)
94  record['Muzzle_Count']=int(record['Muzzle_Count'])+1
95  record['Last_Muzzle_Date']=date
96  self.log.put_record(record)
97 
98  def info(self, name):
99  if name == '#':
100  return 0
101  record = self.log.get_record(name)
102  if record:
103  return record
104  else:
105  return 0
CFLog.CFLog.info
def info(self, name)
Definition: CFLog.py:98
CFDataFile.CFData
Definition: CFDataFile.py:94
CFLog.CFLog.last_login
def last_login(self, name)
Definition: CFLog.py:65
CFLog.CFLog.kick_update
def kick_update(self, name)
Definition: CFLog.py:84
CFLog.CFLog.__init__
def __init__(self)
Definition: CFLog.py:36
CFLog.CFLog
Definition: CFLog.py:34
CFLog.CFLog.muzzle_update
def muzzle_update(self, name)
Definition: CFLog.py:91
make_face_from_files.str
str
Definition: make_face_from_files.py:24
CFLog.CFLog.remove
def remove(self, name)
Definition: CFLog.py:54
CFLog.CFLog.log
log
Definition: CFLog.py:39
CFLog.CFLog.login_update
def login_update(self, name, ip)
Definition: CFLog.py:57
make_face_from_files.int
int
Definition: make_face_from_files.py:26
CFLog.CFLog.create
def create(self, name)
Definition: CFLog.py:41