This repository has been archived by the owner on Apr 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
zoneserver.py
227 lines (152 loc) · 6.18 KB
/
zoneserver.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Copyright (C) 2004-2007 Prairie Games, Inc
# Please see LICENSE.TXT for details
import imp
import os
import sys
from traceback import format_exc,print_exc,print_stack
try:
RUNNING = True
def main_is_frozen():
return (hasattr(sys, "frozen") or # new py2exe
hasattr(sys, "importers") # old py2exe
or imp.is_frozen("__main__")) # tools/freeze
if main_is_frozen():
#maindir = get_main_dir()
if sys.platform[:6] == 'darwin':
#need to go up three folders
os.chdir("../../../mom")
maindir = os.getcwd()
else:
os.chdir("../common")
maindir = os.getcwd()
sys.path.append(maindir)
import pytorque
try:
import win32api,win32process
except ImportError:
win32api = win32process = None
USE_WX = "-wx" in sys.argv
if sys.platform == 'win32' and not USE_WX:
from twisted.internet.iocpreactor import install
else:
import wx
from twisted.internet.wxreactor import install
install()
from twisted.internet import reactor
if USE_WX:
REACTOR = None
class RedirectText:
def __init__(self, ctrl):
self.out = ctrl
def write(self, string):
self.out.WriteText(string)
class MainPanel(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self,parent,id)
sizer = wx.BoxSizer(wx.VERTICAL)
output = wx.TextCtrl(self,-1,"",size=(512,384), \
style=wx.TE_MULTILINE|wx.TE_READONLY)
sys.stdout = RedirectText(output)
sys.stderr = sys.stdout
sizer.Add(output, 0, wx.ALIGN_CENTRE|wx.ALL|wx.EXPAND,5)
self.SetSizer(sizer)
sizer.Fit(self)
class MainFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self,parent,-1,title,size=wx.Size(512, 384), \
style=wx.CAPTION|wx.MINIMIZE_BOX|wx.SYSTEM_MENU| \
wx.TAB_TRAVERSAL|wx.CLOSE_BOX)
menu = wx.Menu()
menu.Append(wx.ID_EXIT,"E&xit","Terminate the program")
menuBar = wx.MenuBar()
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
wx.EVT_MENU(self, wx.ID_EXIT,self.DoExit)
try:
mp = MainPanel(self,-1)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(mp,0,wx.ALIGN_CENTRE|wx.ALL|wx.EXPAND,0)
self.SetSizer(sizer)
sizer.Fit(self)
except:
print_exc()
return
def DoExit(self, event):
global RUNNING
RUNNING = False
class GMApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
frame = MainFrame(None,-1,"Zone Server")
frame.Centre()
frame.Show(1)
self.mainFrame = frame
return True
app = GMApp()
def SetupProcessors(cluster):
if sys.platform != "win32":
return
handle = win32api.GetCurrentProcess()
processMask,systemMask = win32process.GetProcessAffinityMask(handle)
ht = False
if systemMask & 8:
#we're going to count this as a hyperthreaded system
#as we don't currently have any servers with > 2 physical cpu
ht = True
if cluster == 0:
mask = 3 if ht else 1
elif cluster == 1:
mask = 12 if ht else 2
else:
mask = 1
print "Setting Processor Affinity Mask to",mask
win32process.SetProcessAffinityMask(handle,mask)
if not main_is_frozen() and sys.platform == "win32":
os.chdir(os.path.dirname(sys.argv[0]))
from mud.gamesettings import *
from mud.world.core import CoreSettings
sys.argv.append("-game")
sys.argv.append(GAMEROOT)
pytorque.Init(len(sys.argv),sys.argv)
if USE_WX:
reactor.registerWxApp(app)
DYNAMIC = '-dynamic' in sys.argv
CLUSTER = 0
for arg in sys.argv:
if arg.startswith("-cluster="):
CLUSTER = int(arg[9:])
SetupProcessors(CLUSTER)
from mud.simulation.simmind import NumPlayersInZone
from mud.world.core import CoreSettings
from tgenative import TGEGetGlobal,TGESetGlobal
QUARANTINE = 0
PRIORITY = 1
TGESetGlobal("$Server::DedicatedSleeping",False)
while pytorque.Tick() and RUNNING:
num = NumPlayersInZone()
win32api.Sleep(1)
if False:
if not num:
if PRIORITY:
TGESetGlobal("$Server::DedicatedSleeping",True)
PRIORITY = 0
win32process.SetPriorityClass( \
win32process.GetCurrentProcess(), \
win32process.IDLE_PRIORITY_CLASS)
else:
win32api.Sleep(2000)
elif not PRIORITY:
TGESetGlobal("$Server::DedicatedSleeping",False)
PRIORITY = 1
win32process.SetPriorityClass(win32process.GetCurrentProcess(), \
win32process.NORMAL_PRIORITY_CLASS)
if not RUNNING:
sys.exit()
if win32process != None:
win32process.SetPriorityClass(win32process.GetCurrentProcess(), \
win32process.NORMAL_PRIORITY_CLASS)
pytorque.Shutdown()
except:
print_stack()
print format_exc()
raw_input("Press Enter to terminate")