comparison orpg/networking/mplay_server_gui.py @ 151:06f10429eedc alpha

Traipse Alpha 'OpenRPG' {091125-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Cleaning up for Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 06:15:49 -0600
parents 8e07c1a2c69b
children b633f4c64aae 81d0bfd5e800
comparison
equal deleted inserted replaced
149:c2caca988a11 151:06f10429eedc
30 from xml.etree.ElementTree import fromstring, tostring, parse 30 from xml.etree.ElementTree import fromstring, tostring, parse
31 31
32 # Constants ###################################### 32 # Constants ######################################
33 SERVER_RUNNING = 1 33 SERVER_RUNNING = 1
34 SERVER_STOPPED = 0 34 SERVER_STOPPED = 0
35 MENU_START_SERVER = wx.NewId() 35
36 MENU_STOP_SERVER = wx.NewId()
37 MENU_EXIT = wx.NewId()
38 MENU_REGISTER_SERVER = wx.NewId()
39 MENU_UNREGISTER_SERVER = wx.NewId()
40 MENU_START_PING_PLAYERS = wx.NewId()
41 MENU_STOP_PING_PLAYERS = wx.NewId()
42 MENU_PING_INTERVAL = wx.NewId()
43 ### Alpha ### 36 ### Alpha ###
44 MENU_MODIFY_BANLIST = wx.NewId() 37 MENU_MODIFY_BANLIST = wx.NewId()
45 ############# 38 #############
46 39
47 # Add our menu id's for our right click popup
48 MENU_PLAYER_BOOT = wx.NewId()
49 ### Alpha ###
50 MENU_ADMIN_BAN = wx.NewId()
51 MENU_BAN_LIST = wx.NewId()
52 MENU_ADMIN_UNBAN = wx.NewId()
53 PLAYER_SHOW_VERSION = wx.NewId()
54 #############
55 MENU_PLAYER_CREATE_ROOM = wx.NewId() 40 MENU_PLAYER_CREATE_ROOM = wx.NewId()
56 MENU_PLAYER_SEND_MESSAGE = wx.NewId()
57 MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId()
58 MENU_PLAYER_SEND_SERVER_MESSAGE = wx.NewId()
59 41
60 # Our new event type that gets posted from one 42 # Our new event type that gets posted from one
61 # thread to another 43 # thread to another
62 wxEVT_LOG_MESSAGE = wx.NewEventType() 44 wxEVT_LOG_MESSAGE = wx.NewEventType()
63 wxEVT_FUNCTION_MESSAGE = wx.NewEventType() 45 wxEVT_FUNCTION_MESSAGE = wx.NewEventType()
95 self.func = func 77 self.func = func
96 self.message = message 78 self.message = message
97 79
98 # ServerConfig Object ############################ 80 # ServerConfig Object ############################
99 class ServerConfig: 81 class ServerConfig:
100 #debug(log=False)
101 """ This class contains configuration 82 """ This class contains configuration
102 setting used to control the server.""" 83 setting used to control the server."""
103 84
104 def __init__(self, owner ): 85 def __init__(self, owner ):
105 """ Loads default configuration settings.""" 86 """ Loads default configuration settings."""
106 validate.config_file("server_ini.xml", "default_server_ini.xml") 87 validate.config_file("server_ini.xml", "default_server_ini.xml")
107 config_xml = parse(dir_struct['user'] + 'server_ini.xml') 88 config_xml = parse(dir_struct['user'] + 'server_ini.xml').getroot()
108 #debug(config_xml, log=False) 89 port = config_xml.find('service').get('port')
109 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') 90 OPENRPG_PORT = 6774 if port == '' else int(port)
110 port = configDom.childNodes[0].childNodes[1].getAttribute('port')
111 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way.
112 self.owner = owner 91 self.owner = owner
113 92
114 def load_xml(self, xml): 93 def load_xml(self, xml):
115 """ Load configuration from XML data. 94 """ Load configuration from XML data.
116 xml (xml) -- xml string to parse """ 95 xml (xml) -- xml string to parse """
132 self.conf = conf 111 self.conf = conf
133 self.serverName = name 112 self.serverName = name
134 self.bootPwd = pwd 113 self.bootPwd = pwd
135 114
136 def log(self, mesg): 115 def log(self, mesg):
137 #debug(log=False)
138 if type(mesg) == types.TupleType: 116 if type(mesg) == types.TupleType:
139 func, msg = mesg 117 func, msg = mesg
140 event = MessageFunctionEvent( func, msg ) 118 event = MessageFunctionEvent( func, msg )
141 else: event = MessageLogEvent( mesg ) 119 else: event = MessageLogEvent( mesg )
142 wx.PostEvent( self.conf.owner, event ) 120 wx.PostEvent( self.conf.owner, event )
143 del event 121 del event
144 122
145 def run(self): 123 def run(self):
146 #debug(log=False)
147 """ Start the server. """ 124 """ Start the server. """
148 self.server = mplay_server(self.log, self.serverName ) 125 self.server = mplay_server(self.log, self.serverName )
149 self.server.initServer(bootPassword=self.bootPwd, reg="No") 126 self.server.initServer(bootPassword=self.bootPwd, reg="No")
150 self.alive = 1 127 self.alive = 1
151 while self.alive: time.sleep(3) 128 while self.alive: time.sleep(3)
152 129
153 def stop(self): 130 def stop(self):
154 #debug(log=False)
155 """ Stop the server. """ 131 """ Stop the server. """
156 self.server.kill_server() 132 self.server.kill_server()
157 self.alive = 0 133 self.alive = 0
158 134
159 # GUI Server ##################################### 135 # GUI Server #####################################
161 # Main = GUI 137 # Main = GUI
162 class Groups(wx.ListCtrl): 138 class Groups(wx.ListCtrl):
163 def __init__(self, parent, main): 139 def __init__(self, parent, main):
164 wx.ListCtrl.__init__(self, parent, -1, wx.DefaultPosition, 140 wx.ListCtrl.__init__(self, parent, -1, wx.DefaultPosition,
165 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES) 141 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES)
142
143 """Not completed. Creates room, delets rooms. Does not track players. Nor does gsclient, ftm."""
144 validate.config_file("server_ini.xml", "default_server_ini.xml" )
145 config_xml = parse(dir_struct["user"] + 'server_ini.xml').getroot()
146 lobbyname = config_xml.get('lobbyname')
147
166 self.main = main 148 self.main = main
167
168 """Not completed. Creates room, delets rooms. Does not track players. Nor does gsclient, ftm."""
169
170 ### Alpha ### Get Lobby Name # Moving to etree.
171 validate.config_file("server_ini.xml", "default_server_ini.xml" )
172 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml')
173 lobbyname = configDom.childNodes[0].getAttribute('lobbyname')
174 #############
175 self.roomList = { 0 : lobbyname } 149 self.roomList = { 0 : lobbyname }
176
177 self.InsertColumn(0, 'Group ID') 150 self.InsertColumn(0, 'Group ID')
178 self.InsertColumn(1, 'Game') 151 self.InsertColumn(1, 'Game')
179 self.InsertColumn(2, 'Players') 152 self.InsertColumn(2, 'Players')
180 self.InsertColumn(3, 'Passworded') 153 self.InsertColumn(3, 'Passworded')
181 self.AddGroup((self.roomList[0], '0', 'Need to Find', 'No')) 154 self.AddGroup((self.roomList[0], '0', '0', 'No'))
182 155
183 def AddGroup(self, data): 156 def AddGroup(self, data):
184 (room, room_id, players, passworded) = data 157 (room, room_id, players, passworded) = data
185 i = self.InsertStringItem(0, str(room_id)) 158 i = self.InsertStringItem(0, str(room_id))
186 self.SetStringItem(i, 1, room) 159 self.SetStringItem(i, 1, room)
189 162
190 def DeleteGroup(self, data): 163 def DeleteGroup(self, data):
191 i = self.FindItem(-1, str(data)) 164 i = self.FindItem(-1, str(data))
192 self.DeleteItem(i) 165 self.DeleteItem(i)
193 166
194 def UpdateRoom(self, data): 167 def UpdateGroup(self, data):
195 (room, room_id, players) = data 168 (room, room_id, players) = data
196 i = self.FindItem( -1, str(room_id)) 169 i = self.FindItem( -1, str(room_id))
197 self.SetStringItem( i, 1, room ) 170 self.SetStringItem( i, 1, room )
198 if players: self.SetStringItem(i, 2, players) 171 if players: self.SetStringItem(i, 2, str(players))
199 ### Need to add room for Password Updates ### 172 ### Need to add room for Password Updates ###
200 173
201 class Connections(wx.ListCtrl): 174 class Connections(wx.ListCtrl):
202 def __init__( self, parent, main ): 175 def __init__( self, parent, main ):
203 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, 176 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition,
204 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES ) 177 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES )
178
179 validate.config_file("server_ini.xml", "default_server_ini.xml" )
180 config_xml = parse(dir_struct["user"] + 'server_ini.xml').getroot()
181 lobbyname = config_xml.get('lobbyname')
182
205 self.main = main 183 self.main = main
206
207 ### Alpha ### Get Lobby Name
208 validate.config_file("server_ini.xml", "default_server_ini.xml" )
209 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml')
210 lobbyname = configDom.childNodes[0].getAttribute('lobbyname')
211 #############
212
213 self.roomList = { 0 : lobbyname } 184 self.roomList = { 0 : lobbyname }
214 self._imageList = wx.ImageList( 16, 16, False ) 185 self._imageList = wx.ImageList( 16, 16, False )
215 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() 186 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap()
216 self._imageList.Add( img ) 187 self._imageList.Add( img )
217 img = wx.Image(dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() 188 img = wx.Image(dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap()
232 self.AutoAjust() 203 self.AutoAjust()
233 204
234 # Build our pop up menu to do cool things with the players in the list 205 # Build our pop up menu to do cool things with the players in the list
235 self.menu = wx.Menu() 206 self.menu = wx.Menu()
236 self.menu.SetTitle( "Player Menu" ) 207 self.menu.SetTitle( "Player Menu" )
237 self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" ) 208 self.menu.Append( 1, "Boot Player" )
238 self.menu.Append( MENU_ADMIN_BAN, 'Ban Player' ) 209 self.menu.Append( 2, 'Ban Player' )
239 self.menu.Append( PLAYER_SHOW_VERSION, "Player Version" ) 210 self.menu.Append( 3, "Player Version" )
240 self.menu.AppendSeparator() 211 self.menu.AppendSeparator()
241 self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" ) 212 self.menu.Append( 4, "Send Player Message" )
242 self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" ) 213 self.menu.Append( 5, "Send Room Message" )
243 self.menu.Append( MENU_PLAYER_SEND_SERVER_MESSAGE, "Broadcast Server Message" ) 214 self.menu.Append( 6, "Broadcast Server Message" )
244 215
245 # Associate our events 216 # Associate our events
246 self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu) 217 self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu)
247 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_BOOT) 218 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=1)
248 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_ADMIN_BAN) 219 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=2)
249 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_MESSAGE) 220 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=4)
250 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_ROOM_MESSAGE) 221 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=5)
251 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_SERVER_MESSAGE) 222 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=6)
252 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=PLAYER_SHOW_VERSION) 223 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=3)
253 224
254 def add(self, player): 225 def add(self, player):
255 i = self.InsertImageStringItem( 0, player["id"], 0 ) 226 i = self.InsertImageStringItem( 0, player["id"], 0 )
256 self.SetStringItem(i, 1, self.stripHtml(player["name"])) 227 self.SetStringItem(i, 1, self.stripHtml(player["name"]))
257 self.SetStringItem(i, 2, "NEW") 228 self.SetStringItem(i, 2, "NEW")
291 try: #Players that turn up Blue are not passing the correct arguments. 262 try: #Players that turn up Blue are not passing the correct arguments.
292 try: 263 try:
293 if player['group_id'] != "0": item.SetTextColour(settings.get_setting(role + "RoleColor")) 264 if player['group_id'] != "0": item.SetTextColour(settings.get_setting(role + "RoleColor"))
294 except KeyError: # Needed because group_id turns into group somewhere. 265 except KeyError: # Needed because group_id turns into group somewhere.
295 if player['group'] != "0": item.SetTextColour(settings.get_setting(role + "RoleColor")) 266 if player['group'] != "0": item.SetTextColour(settings.get_setting(role + "RoleColor"))
296 except: 267 except: item.SetTextColour('BLUE')
297 item.SetTextColour('BLUE')
298 self.SetItem(item) 268 self.SetItem(item)
299 269
300 def update(self, player): 270 def update(self, player):
301 #try: int(player); i = self.FindItemData( -1, int(player) ) 271 #try: int(player); i = self.FindItemData( -1, int(player) )
302 i = self.FindItemData( -1, int(player["id"]) ) 272 i = self.FindItemData( -1, int(player["id"]) )
349 room = str(self.GetItem((int(playerID)-1), 3).GetText()) 319 room = str(self.GetItem((int(playerID)-1), 3).GetText())
350 idList = self.main.server.server.groups 320 idList = self.main.server.server.groups
351 for r in self.roomList: 321 for r in self.roomList:
352 if room == self.roomList[r]: groupID = r 322 if room == self.roomList[r]: groupID = r
353 else: groupID = 0 323 else: groupID = 0
354 if menuItem == MENU_PLAYER_BOOT: 324 if menuItem == 1:
355 print "booting player: ", playerID 325 self.main.server.server.admin_kick( playerID )
356 self.main.server.server.del_player( playerID, groupID ) 326 elif menuItem == 2:
357 self.main.server.server.check_group( playerID, groupID )
358 self.remove( playerID )
359 ### Alpha ###
360 elif menuItem == MENU_ADMIN_BAN:
361 message = 'Banishment' 327 message = 'Banishment'
362 BanMsg = wx.TextEntryDialog( self, "Enter A Message To Send:", 328 BanMsg = wx.TextEntryDialog( self, "Enter A Message To Send:",
363 "Ban Message", message, wx.OK|wx.CANCEL|wx.CENTRE ) 329 "Ban Message", message, wx.OK|wx.CANCEL|wx.CENTRE )
364 if BanMsg.ShowModal() == wx.ID_OK: message = BanMsg.GetValue() 330 if BanMsg.ShowModal() == wx.ID_OK: message = BanMsg.GetValue()
365 else: message = '' 331 else: message = ''
367 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) 333 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
368 if Silent.ShowModal() == wx.ID_YES: silent = 1 334 if Silent.ShowModal() == wx.ID_YES: silent = 1
369 else: silent = 0 335 else: silent = 0
370 self.main.server.server.admin_ban(playerID, message, silent) 336 self.main.server.server.admin_ban(playerID, message, silent)
371 self.remove( playerID ) 337 self.remove( playerID )
372 ############### 338 elif menuItem == 4:
373 elif menuItem == MENU_PLAYER_SEND_MESSAGE:
374 print "send a message..."
375 msg = self.GetMessageInput( "Send a message to player" ) 339 msg = self.GetMessageInput( "Send a message to player" )
376 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) ) 340 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) )
377 #Leave this in for now. 341 #Leave this in for now.
378 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: 342 elif menuItem == 5:
379 print "Send message to room..."
380 msg = self.GetMessageInput( "Send message to room of this player") 343 msg = self.GetMessageInput( "Send message to room of this player")
381 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg ) 344 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg )
382 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: 345 elif menuItem == 6:
383 print "broadcast a message..."
384 msg = self.GetMessageInput( "Broadcast Server Message" ) 346 msg = self.GetMessageInput( "Broadcast Server Message" )
385 # If we got a message back, send it
386 if len(msg): self.main.server.server.broadcast( msg ) 347 if len(msg): self.main.server.server.broadcast( msg )
387 elif menuItem == PLAYER_SHOW_VERSION: 348 elif menuItem == 3:
388 version_string = self.main.server.server.obtain_by_id(playerID, 'client_string') 349 version_string = self.main.server.server.obtain_by_id(playerID, 'client_string')
389 if version_string: wx.MessageBox("Running client version " + version_string,"Version") 350 if version_string: wx.MessageBox("Running client version " + version_string,"Version")
390 else: wx.MessageBox("No client version available for this player", "Version") 351 else: wx.MessageBox("No client version available for this player", "Version")
391 352
392 def GetMessageInput( self, title ): 353 def GetMessageInput( self, title ):
403 if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) 364 if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO )
404 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) 365 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF )
405 self.SetIcon(icon) 366 self.SetIcon(icon)
406 self.serverName = "Server Name" 367 self.serverName = "Server Name"
407 self.bootPwd = "" 368 self.bootPwd = ""
369 self.do_log = True
408 370
409 # Register our events to process -- notice the custom event handler 371 # Register our events to process -- notice the custom event handler
410 self.Bind(wx.EVT_CLOSE, self.OnExit) 372 self.Bind(wx.EVT_CLOSE, self.OnExit)
411 self.Bind(EVT_LOG_MESSAGE, self.OnLogMessage) 373 self.Bind(EVT_LOG_MESSAGE, self.OnLogMessage)
412 self.Bind(EVT_FUNCTION_MESSAGE, self.OnFunctionMessage) 374 self.Bind(EVT_FUNCTION_MESSAGE, self.OnFunctionMessage)
413 375
414 # Creat GUI 376 # Creat GUI
415 self.build_menu() 377 self.build_menu()
416 self.build_body() 378 self.build_body()
417 self.build_status() 379 self.build_status()
418
419 ### Alpha ###
420 # Ban List Dialog
421 self.BanListDialog = BanListDialog(self) 380 self.BanListDialog = BanListDialog(self)
422 #############
423 381
424 # Server Callbacks 382 # Server Callbacks
425 cb = {} 383 cb = {}
426 cb["log"] = self.Log 384 cb["log"] = self.Log
427 cb["connect"] = self.OnConnect ##Fixed!! 385 cb["connect"] = self.OnConnect
428 cb["disconnect"] = self.OnDisconnect 386 cb["disconnect"] = self.OnDisconnect
429 cb["update"] = self.OnUpdatePlayer 387 cb["update"] = self.OnUpdatePlayer
430 cb["data_recv"] = self.OnDataRecv 388 cb["data_recv"] = self.OnDataRecv
431 cb["data_sent"] = self.OnDataSent 389 cb["data_sent"] = self.OnDataSent
432 cb["create_group"] = self.OnCreateGroup 390 cb["create_group"] = self.OnCreateGroup
442 self.total_data_received = 0 400 self.total_data_received = 0
443 self.total_messages_sent = 0 401 self.total_messages_sent = 0
444 self.total_data_sent = 0 402 self.total_data_sent = 0
445 403
446 """ Build GUI """ 404 """ Build GUI """
447
448 def build_menu(self): 405 def build_menu(self):
449 """ Build the GUI menu. """ 406 """ Build the GUI menu. """
450 self.mainMenu = wx.MenuBar() 407 self.mainMenu = wx.MenuBar()
451 408
452 # File Menu 409 # File Menu
453 menu = wx.Menu() 410 menu = wx.Menu()
454 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') 411 menu.Append( 1, 'Start', 'Start server.')
455 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) 412 menu.Append( 2, 'Stop', 'Shutdown server.')
456 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.')
457 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER)
458 menu.AppendSeparator() 413 menu.AppendSeparator()
459 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') 414 menu.Append( 3, 'E&xit', 'Exit application.')
460 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) 415 self.Bind(wx.EVT_MENU, self.OnStart, id=1)
416 self.Bind(wx.EVT_MENU, self.OnStop, id=2)
417 self.Bind(wx.EVT_MENU, self.OnExit, id=3)
461 self.mainMenu.Append(menu, '&Server') 418 self.mainMenu.Append(menu, '&Server')
462 419
463 # Registration Menu 420 # Registration Menu
464 menu = wx.Menu() 421 menu = wx.Menu()
465 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') 422 menu.Append( 4, 'Register', 'Register with OpenRPG server directory.')
466 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) 423 menu.Append( 5, 'Unregister', 'Unregister from OpenRPG server directory.')
467 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.') 424 self.Bind(wx.EVT_MENU, self.OnRegister, id=4)
468 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) 425 self.Bind(wx.EVT_MENU, self.OnUnregister, id=5)
469 self.mainMenu.Append( menu, '&Registration' ) 426 self.mainMenu.Append( menu, '&Registration' )
470 427
471 # Server Configuration Menu 428 # Server Configuration Menu
472 menu = wx.Menu() 429 menu = wx.Menu()
473 menu.Append( MENU_BAN_LIST, 'Ban List', 'Modify Ban List.' ) 430 menu.Append( 6, 'Ban List', 'Modify Ban List.')
474 self.Bind(wx.EVT_MENU, self.ModifyBanList, id=MENU_BAN_LIST) 431 menu.Append(11, 'Zombies', 'Set auto-kick time for zombie clients')
475 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) 432 menu.Append(14, 'Send Size', 'Adjust the send size limit')
476 self.Bind(wx.EVT_MENU, self.PingPlayers, id=MENU_START_PING_PLAYERS) 433 menu.AppendSeparator()
477 menu.Append( MENU_STOP_PING_PLAYERS, 'Stop Ping', 'Stop validating player connections.' ) 434 menu.Append( 7, 'Start Ping', 'Ping players to validate remote connection.' )
478 self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=MENU_STOP_PING_PLAYERS) 435 menu.Append( 8, 'Stop Ping', 'Stop validating player connections.' )
479 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' ) 436 menu.Append( 9, 'Ping Interval', 'Change the ping interval.' )
480 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) 437 menu.AppendSeparator()
438 menu.AppendCheckItem( 10, 'Server Logging', 'Turn on or off the Server GUI Log').Check(self.do_log)
439 menu.AppendCheckItem(12, 'Room Passwords', 'Allow or Deny Room Passwords').Check(False)
440 menu.AppendCheckItem(13, 'Remote Admin', 'Allow or Deny Remote Admin').Check(False)
441 menu.AppendCheckItem(15, 'Remote Kill', 'Allow or Deny Remote Admin Server Kill').Check(False)
442 self.Bind(wx.EVT_MENU, self.ModifyBanList, id=6)
443 self.Bind(wx.EVT_MENU, self.PingPlayers, id=7)
444 self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=8)
445 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=9)
446 self.Bind(wx.EVT_MENU, self.LogToggle, id=10)
481 self.mainMenu.Append( menu, '&Configuration' ) 447 self.mainMenu.Append( menu, '&Configuration' )
482
483 self.SetMenuBar( self.mainMenu ) 448 self.SetMenuBar( self.mainMenu )
484 449
485 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 450 self.mainMenu.Enable( 2, False )
486 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 451 self.mainMenu.Enable( 4, False )
487 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 452 self.mainMenu.Enable( 5, False )
488 453
489 # Disable the ping menu items 454 # Disable the ping menu items
490 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) 455 self.mainMenu.Enable( 7, False )
491 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) 456 self.mainMenu.Enable( 8, False )
492 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) 457 self.mainMenu.Enable( 9, False )
493 458
459 # Disable placeholders
460 self.mainMenu.Enable( 11, False )
461 self.mainMenu.Enable( 14, False )
462 self.mainMenu.Enable( 12, False )
463 self.mainMenu.Enable( 13, False )
464 self.mainMenu.Enable( 15, False )
494 def build_body(self): 465 def build_body(self):
495 """ Create the ViewNotebook and logger. """ 466 """ Create the ViewNotebook and logger. """
496 splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D | wx.SP_3D) 467 splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D | wx.SP_3D)
497 nb = wx.Notebook( splitter, -1 ) 468 nb = wx.Notebook( splitter, -1 )
498 self.conns = Connections(nb, self) 469 self.conns = Connections(nb, self)
499 self.groups = Groups(nb, self) 470 self.groups = Groups(nb, self)
471 self.msgWindow = HTMLMessageWindow( nb )
500 nb.AddPage(self.conns, "Players") 472 nb.AddPage(self.conns, "Players")
501 nb.AddPage(self.groups, 'Rooms') 473 nb.AddPage(self.groups, 'Rooms')
502
503 #Not sure why this is Remarked TaS - Sirebral
504 #nb.AddPage( self.conns, "Rooms" )
505 self.msgWindow = HTMLMessageWindow( nb )
506 nb.AddPage( self.msgWindow, "Messages" ) 474 nb.AddPage( self.msgWindow, "Messages" )
507 475
508 log = wx.TextCtrl(splitter, -1, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL) 476 log = wx.TextCtrl(splitter, -1, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
509 wx.Log.SetActiveTarget( wx.LogTextCtrl(log) ) 477 wx.Log.SetActiveTarget( wx.LogTextCtrl(log) )
510 splitter.SplitHorizontally(nb, log, 400) 478 splitter.SplitHorizontally(nb, log, 400)
533 dlg.ShowModal() 501 dlg.ShowModal()
534 dlg.Destroy() 502 dlg.Destroy()
535 503
536 504
537 # Event handler for out logging event 505 # Event handler for out logging event
506 def LogToggle(self, event):
507 self.do_log = event.IsChecked()
508
538 def OnLogMessage( self, event ): 509 def OnLogMessage( self, event ):
539 self.Log( event.message ) 510 self.Log( event.message )
540 511
541 # Event handler for out logging event 512 # Event handler for out logging event
542 def OnFunctionMessage(self, event): 513 def OnFunctionMessage(self, event):
543 self.callbacks[event.func]( event.message ) 514 self.callbacks[event.func]( event.message )
544 515
545 ### Server Callbacks ##################################### 516 ### Server Callbacks #####################################
546 def Log(self, log): 517 def Log(self, log):
547 wx.LogMessage(str(log)) 518 if self.do_log: wx.LogMessage(str(log))
548 519
549 def OnConnect(self, player): 520 def OnConnect(self, player):
550 self.conns.add(player) 521 self.conns.add(player)
551 522
552 def OnDisconnect(self, id): 523 def OnDisconnect(self, id):
576 (room_id, player) = data 547 (room_id, player) = data
577 self.groups.DeleteGroup(room_id) 548 self.groups.DeleteGroup(room_id)
578 del self.conns.roomList[room_id] 549 del self.conns.roomList[room_id]
579 550
580 def OnJoinGroup(self, data): 551 def OnJoinGroup(self, data):
581 #debug(data)
582 self.conns.updateRoom(data) 552 self.conns.updateRoom(data)
583 553
584 def OnUpdateGroup(self, data): 554 def OnUpdateGroup(self, data):
585 (room, room_id, players) = data 555 (room, room_id, players) = data
586 self.groups.UpdateGroup(data) 556 self.groups.UpdateGroup(data)
594 """ Start server. """ 564 """ Start server. """
595 if self.STATUS == SERVER_STOPPED: 565 if self.STATUS == SERVER_STOPPED:
596 # see if we already have name specified 566 # see if we already have name specified
597 try: 567 try:
598 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) 568 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
599 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') 569 configDoc = parse(dir_struct["user"] + 'server_ini.xml').getroot()
600 configDom.normalize() 570 if configDoc.get("name"): self.serverName = configDoc.get("name")
601 configDoc = configDom.documentElement
602 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name")
603 except: pass 571 except: pass
604 if self.serverName == '': 572 if self.serverName == '':
605 self.serverName = 'Server Name' 573 self.serverName = 'Server Name'
606 serverNameEntry = wx.TextEntryDialog(self, "Please Enter The Server Name You Wish To Use:", 574 serverNameEntry = wx.TextEntryDialog(self, "Please Enter The Server Name You Wish To Use:",
607 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) 575 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE )
608 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() 576 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue()
609 # see if we already have password specified 577 # see if we already have password specified
610 try: 578 try:
611 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) 579 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
612 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') 580 configDoc = parse(dir_struct["user"] + 'server_ini.xml').getroot()
613 configDom.normalize() 581 if configDoc.get("admin"): self.bootPwd = configDoc.get("admin")
614 configDoc = configDom.documentElement 582 elif configDoc.get("boot"): self.bootPwd = configDoc.get("boot")
615 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin")
616 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot")
617 except: pass 583 except: pass
618 if self.bootPwd == '': 584 if self.bootPwd == '':
619 serverPasswordEntry = wx.TextEntryDialog(self, 585 serverPasswordEntry = wx.TextEntryDialog(self,
620 "Please Enter The Server Admin Password:", "Server's Password", 586 "Please Enter The Server Admin Password:", "Server's Password",
621 self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) 587 self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE)
625 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) 591 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd)
626 self.server.start() 592 self.server.start()
627 self.STATUS = SERVER_RUNNING 593 self.STATUS = SERVER_RUNNING
628 self.sb.SetStatusText("Running", 3) 594 self.sb.SetStatusText("Running", 3)
629 self.SetTitle(__appname__ + "- (running) - (unregistered)") 595 self.SetTitle(__appname__ + "- (running) - (unregistered)")
630 self.mainMenu.Enable( MENU_START_SERVER, False ) 596 self.mainMenu.Enable( 1, False )
631 self.mainMenu.Enable( MENU_STOP_SERVER, True ) 597 self.mainMenu.Enable( 2, True )
632 self.mainMenu.Enable( MENU_REGISTER_SERVER, True ) 598 self.mainMenu.Enable( 4, True )
633 wx.EndBusyCursor() 599 wx.EndBusyCursor()
634 else: self.show_error("Server is already running.", "Error Starting Server") 600 else: self.show_error("Server is already running.", "Error Starting Server")
635 601
636 def OnStop(self, event = None): 602 def OnStop(self, event = None):
637 """ Stop server. """ 603 """ Stop server. """
639 self.OnUnregister() 605 self.OnUnregister()
640 self.server.stop() 606 self.server.stop()
641 self.STATUS = SERVER_STOPPED 607 self.STATUS = SERVER_STOPPED
642 self.sb.SetStatusText("Stopped", 3) 608 self.sb.SetStatusText("Stopped", 3)
643 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") 609 self.SetTitle(__appname__ + "- (stopped) - (unregistered)")
644 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 610 self.mainMenu.Enable( 1, True )
645 self.mainMenu.Enable( MENU_START_SERVER, True ) 611 self.mainMenu.Enable( 2, False )
646 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 612 self.mainMenu.Enable( 4, False )
647 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 613 self.mainMenu.Enable( 5, False )
648 self.conns.DeleteAllItems() 614 self.conns.DeleteAllItems()
649 615
650 def OnRegister(self, event = None): 616 def OnRegister(self, event = None):
651 """ Call into mplay_server's register() function. 617 """ Call into mplay_server's register() function.
652 This will begin registerThread(s) to keep server 618 This will begin registerThread(s) to keep server
654 """ 620 """
655 if len( self.serverName ): 621 if len( self.serverName ):
656 wx.BeginBusyCursor() 622 wx.BeginBusyCursor()
657 self.server.server.register(self.serverName) 623 self.server.server.register(self.serverName)
658 self.sb.SetStatusText( ("%s" % (self.serverName)), 4 ) 624 self.sb.SetStatusText( ("%s" % (self.serverName)), 4 )
659 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 625 self.mainMenu.Enable( 4, False )
660 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, True ) 626 self.mainMenu.Enable( 5, True )
661 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 627 #self.mainMenu.Enable( 2, False )
662 self.SetTitle(__appname__ + "- (running) - (registered)") 628 self.SetTitle(__appname__ + "- (running) - (registered)")
663 wx.EndBusyCursor() 629 wx.EndBusyCursor()
664 630
665 def OnUnregister(self, event = None): 631 def OnUnregister(self, event = None):
666 """ Call into mplay_server's unregister() function. 632 """ Call into mplay_server's unregister() function.
669 from all metas 635 from all metas
670 """ 636 """
671 wx.BeginBusyCursor() 637 wx.BeginBusyCursor()
672 self.server.server.unregister() 638 self.server.server.unregister()
673 self.sb.SetStatusText( "Unregistered", 4 ) 639 self.sb.SetStatusText( "Unregistered", 4 )
674 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 640 self.mainMenu.Enable( 5, False )
675 self.mainMenu.Enable( MENU_REGISTER_SERVER, True ) 641 self.mainMenu.Enable( 4, True )
676 self.mainMenu.Enable( MENU_STOP_SERVER, True ) 642 #self.mainMenu.Enable( 2, True )
677 self.SetTitle(__appname__ + "- (running) - (unregistered)") 643 self.SetTitle(__appname__ + "- (running) - (unregistered)")
678 wx.EndBusyCursor() 644 wx.EndBusyCursor()
679 645
680 ### Alpha ###
681 def ModifyBanList(self, event): 646 def ModifyBanList(self, event):
682 if self.BanListDialog.IsShown() == True: self.BanListDialog.Hide() 647 if self.BanListDialog.IsShown() == True: self.BanListDialog.Hide()
683 else: self.BanListDialog.Show() 648 else: self.BanListDialog.Show()
684 #############
685 649
686 def PingPlayers( self, event = None ): 650 def PingPlayers( self, event = None ):
687 "Ping all players that are connected at a periodic interval, detecting dropped connections." 651 "Ping all players that are connected at a periodic interval, detecting dropped connections."
688 wx.BeginBusyCursor() 652 wx.BeginBusyCursor()
689 wx.Yield() 653 wx.Yield()
702 self.ExitConfirmed() 666 self.ExitConfirmed()
703 667
704 def ExitConfirmed(self, event=None): 668 def ExitConfirmed(self, event=None):
705 """ Quit the program. """ 669 """ Quit the program. """
706 self.OnStop() 670 self.OnStop()
707 self.BanListDialog.Destroy() ### Alpha ### 671 self.BanListDialog.Destroy()
708 wx.CallAfter(self.Destroy) 672 wx.CallAfter(self.Destroy)
709 673
710 ### Alpha ###
711 class BanListDialog(wx.Frame): 674 class BanListDialog(wx.Frame):
712 def __init__(self, parent): 675 def __init__(self, parent):
713 super(BanListDialog, self).__init__(parent, -1, "Ban List") 676 super(BanListDialog, self).__init__(parent, -1, "Ban List")
714 icon = wx.Icon(dir_struct["icon"]+'noplayer.gif', wx.BITMAP_TYPE_GIF) 677 icon = wx.Icon(dir_struct["icon"]+'noplayer.gif', wx.BITMAP_TYPE_GIF)
715 self.SetIcon( icon ) 678 self.SetIcon( icon )
724 self.Min(None) 687 self.Min(None)
725 688
726 # Ban List Dialog Pop Up Menu, more can be added 689 # Ban List Dialog Pop Up Menu, more can be added
727 self.menu = wx.Menu() 690 self.menu = wx.Menu()
728 self.menu.SetTitle( "Modify Ban List" ) 691 self.menu.SetTitle( "Modify Ban List" )
729 self.menu.Append( MENU_ADMIN_UNBAN, "Un-Ban Player" ) 692 self.menu.Append( 1, "Un-Ban Player" )
730 693
731 # Even Association 694 # Even Association
732 self.BanList.Bind(wx.EVT_RIGHT_DOWN, self.BanPopupMenu) 695 self.BanList.Bind(wx.EVT_RIGHT_DOWN, self.BanPopupMenu)
733 self.Bind(wx.EVT_MENU, self.BanPopupMenuItem, id=MENU_ADMIN_UNBAN) 696 self.Bind(wx.EVT_MENU, self.BanPopupMenuItem, id=1)
734 697
735 # When we right click, cause our popup menu to appear 698 # When we right click, cause our popup menu to appear
736 def BanPopupMenu( self, event ): 699 def BanPopupMenu( self, event ):
737 pos = wx.Point( event.GetX(), event.GetY() ) 700 pos = wx.Point( event.GetX(), event.GetY() )
738 (item, flag) = self.BanList.HitTest( pos ) 701 (item, flag) = self.BanList.HitTest( pos )
742 705
743 def BanPopupMenuItem( self, event): 706 def BanPopupMenuItem( self, event):
744 menuItem = event.GetId() 707 menuItem = event.GetId()
745 player = str(self.BanList.GetItemData(self.selectedItem)) 708 player = str(self.BanList.GetItemData(self.selectedItem))
746 playerIP = str(self.BanList.GetItem((int(player)), 1).GetText()) 709 playerIP = str(self.BanList.GetItem((int(player)), 1).GetText())
747 if menuItem == MENU_ADMIN_UNBAN: 710 if menuItem == 1:
748 server.admin_unban(playerIP) 711 server.admin_unban(playerIP)
749 self.BanList.DeleteItem(self.BanList.GetItemData(self.selectedItem)) 712 self.BanList.DeleteItem(self.BanList.GetItemData(self.selectedItem))
750 self.BanList.Refresh() 713 self.BanList.Refresh()
751 714
752 def BuildList(self): 715 def BuildList(self):
754 self.BanList.ClearAll() 717 self.BanList.ClearAll()
755 self.BanList.InsertColumn(0, "User Name") 718 self.BanList.InsertColumn(0, "User Name")
756 self.BanList.InsertColumn(1, "IP") 719 self.BanList.InsertColumn(1, "IP")
757 720
758 validate.config_file("ban_list.xml", "default_ban_list.xml" ) 721 validate.config_file("ban_list.xml", "default_ban_list.xml" )
759 configDom = minidom.parse(dir_struct["user"] + 'ban_list.xml') 722 configDom = parse(dir_struct["user"] + 'ban_list.xml').getroot()
760 ban_dict = {} 723 ban_dict = {}
761 for element in configDom.getElementsByTagName('banned'): 724 for element in configDom.findall('banned'):
762 player = element.getAttribute('name').replace("&", "&amp;").replace("<", "&lt;").replace('"', "&quot;").replace(">", "&gt;") 725 player = element.get('name').replace("&", "&amp;").replace("<", "&lt;").replace('"', "&quot;").replace(">", "&gt;")
763 playerIP = element.getAttribute('ip') 726 playerIP = element.get('ip')
764 ban_dict[player] = playerIP 727 ban_dict[player] = playerIP
765 for key in ban_dict: 728 for key in ban_dict:
766 i = self.BanList.InsertImageStringItem( 0, key, 0 ) 729 i = self.BanList.InsertImageStringItem( 0, key, 0 )
767 self.BanList.SetStringItem(i, 1, ban_dict[key]) 730 self.BanList.SetStringItem(i, 1, ban_dict[key])
768 self.BanList.RefreshItem(i) 731 self.BanList.RefreshItem(i)
772 self.BanList.SetColumnWidth(0, -1) 735 self.BanList.SetColumnWidth(0, -1)
773 self.BanList.SetColumnWidth(1, -1) 736 self.BanList.SetColumnWidth(1, -1)
774 self.BanList.Refresh() 737 self.BanList.Refresh()
775 738
776 def Min(self, evt): 739 def Min(self, evt):
740 self.BuildList()
777 self.Hide() 741 self.Hide()
778 ############### 742 ###############
779 743
780 class ServerGUIApp(wx.App): 744 class ServerGUIApp(wx.App):
781 def OnInit(self): 745 def OnInit(self):