forked from BattlefieldRedux/StatsPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
160 lines (134 loc) · 4.03 KB
/
__init__.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import host
import sys
from time import localtime, strftime
from bf2.Timer import Timer
from BF2StatisticsConfig import stats_enable, debug_enable, debug_log_path
class GameStatus:
Playing = 1
EndGame = 2
PreGame = 3
Paused = 4
RestartServer = 5
NotConnected = 6
playerManager = None
objectManager = None
triggerManager = None
gameLogic = None
serverSettings = None
# ------------------------------------------------------------------------------
# omero 2005-11-19
# ------------------------------------------------------------------------------
# CONFIGURATION SECTION
# ------------------------------------------------------------------------------
# To enable/disable printing of debug messages in (all) python modules
# ------------------------------------------------------------------------------
g_debug = debug_enable
# set up singletons
import bf2.PlayerManager
import bf2.ObjectManager
import bf2.TriggerManager
import bf2.GameLogic
playerManager = bf2.PlayerManager.PlayerManager()
objectManager = bf2.ObjectManager.ObjectManager()
triggerManager = bf2.TriggerManager.TriggerManager()
gameLogic = bf2.GameLogic.GameLogic()
serverSettings = bf2.GameLogic.ServerSettings()
# these are for wrapping purposes when converting c++ pointers into python objects
playerConvFunc = playerManager.getPlayerByIndex
class fake_stream:
"""Implements stdout and stderr on top of BF2's log"""
def __init__(self, name):
self.name = name
self.buf = ''
def write(self, str):
if len(str) == 0: return
self.buf += str
if str[-1] == '\n':
host.log(self.name + ': ' + self.buf[0:-1])
self.buf = ''
def flush(self): pass
def close(self): pass
class fake_stream2:
"""Implements stdout and stderr on top of BF2's log"""
def __init__(self, name):
self.buf = [str(name), ': ']
def write(self, str):
if len(str) == 0: return
if str[-1] != '\n':
self.buf.append (str)
else:
self.buf.append (str[0:-1])
host.log("".join (self.buf))
self.buf = []
def flush(self): pass
def close(self): pass
def init_module():
# set up stdout and stderr to map to the host's logging function
# ---------------------------------------------------
sys.stdout = fake_stream('stdout')
sys.stderr = fake_stream('stderr')
# omero, 2005-11-19
# comment out the above lines and
# uncomment the following for python looging to gui
# ---------------------------------------------------
# NOTE 1: Requires that gui_log.pyw is present in
# <gameserver installation path>/python/bf2
#
# NOTE 2: gui_log.pyw MUST be started
# BEFORE gameserver
# ---------------------------------------------------
#import gui_log
# Added by Chump - for bf2statistics stats
logtime = str(strftime("%Y%m%d", localtime()))
log = file(debug_log_path + '/bf2game_' + logtime + '.log', 'a')
sys.stdout = log
sys.stderr = log
print "=============================================="
print " BF2 Logging Started: %s" % str(strftime("%x %X", localtime()))
print "=============================================="
import game.scoringCommon
game.scoringCommon.init()
try:
import bf2.stats.stats
except ImportError:
print "Official stats module not found."
else:
bf2.stats.stats.init()
try:
import bf2.stats.endofround
except ImportError:
print "Endofround module not found."
else:
bf2.stats.endofround.init()
# Don't load snapshot or medals if we aren't enabling stats!
if stats_enable:
try:
import bf2.stats.snapshot
except ImportError:
print "Snapshot module not found."
else:
bf2.stats.snapshot.init()
try:
import bf2.stats.medals
except ImportError:
print "Medal awarding module not found."
else:
bf2.stats.medals.init()
try:
import bf2.stats.unlocks
except ImportError:
print "Unlock awarding module not found."
else:
bf2.stats.unlocks.init()
try:
import bf2.stats.fragalyzer_log
except ImportError:
print "Fragalyzer log module not found."
else:
bf2.stats.fragalyzer_log.init()
try:
import bf2.VerifyPlayer
except ImportError:
print "VerifyPlayer module not found."
else:
bf2.VerifyPlayer.init()