comparison orpg/networking/mplay_server_gui.py @ 90:d1aff41c031b alpha

Traipse Alpha 'OpenRPG' {090919-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: 00: Adds menu changes to draw attention to important updates, errors, or other events. (image info coming soon) Traipse URL is not included in the repos tab and is set as default. 01: Fixes Copy for Windows and Linux (finally!!) users. Fixes incomplete update to Grid and List nodes. Fixes incomplete update to Chat Commands. 02: Fixes problems with Remote Image Upload. Fixes Drop and Drag of Minis to Map. CherryPy can now use any image in the webfiles/ folder and sub-folders. CherryPy can now Drop and Drag Minis to the Map. 03: Minor changes to Update Manager's GUI. Expert recommendation warning added to Revision Update. Step down compatibility with open_rpg & component added to orpgCore. 19-00: Better backwards compatibility in orpgCore. Using majority of 'Grumpy' network folder to correct server lag.
author sirebral
date Sat, 19 Sep 2009 06:45:21 -0500
parents 449a8900f9ac
children 65c1604e7949 7ed4979cc1cf
comparison
equal deleted inserted replaced
89:b84e0799fed2 90:d1aff41c031b
11 11
12 import os 12 import os
13 import sys 13 import sys
14 import time 14 import time
15 import types 15 import types
16 from orpg.dirpath import dir_struct 16 import orpg.dirpath
17 #import orpg.systempath looks old 17 import orpg.systempath
18 from orpg.tools.validate import Validate
19 from orpg.orpg_wx import * 18 from orpg.orpg_wx import *
20 import webbrowser 19 import webbrowser
21 from threading import Thread 20 from threading import Thread
22 from meta_server_lib import post_server_data, remove_server 21 from meta_server_lib import post_server_data, remove_server
23 from mplay_server import mplay_server 22 from mplay_server import mplay_server
56 # Utils ########################################## 55 # Utils ##########################################
57 def format_bytes(b): 56 def format_bytes(b):
58 f = ['b', 'Kb', 'Mb', 'Gb'] 57 f = ['b', 'Kb', 'Mb', 'Gb']
59 i = 0 58 i = 0
60 while i < 3: 59 while i < 3:
61 if b < 1024: return str(b) + f[i] 60 if b < 1024:
62 else: b = b/1024 61 return str(b) + f[i]
62 else:
63 b = b/1024
63 i += 1 64 i += 1
64 return str(b) + f[3] 65 return str(b) + f[3]
65 66
66 # wxEVT_LOG_MESSAGE 67 # wxEVT_LOG_MESSAGE
67 # MessageLogEvent ############################### 68 # MessageLogEvent ###############################
86 setting used to control the server. 87 setting used to control the server.
87 """ 88 """
88 89
89 def __init__(self, owner ): 90 def __init__(self, owner ):
90 """ Loads default configuration settings.""" 91 """ Loads default configuration settings."""
91 Validate(dir_struct["user"]).config_file("server_ini.xml", "default_server_ini.xml" ) 92 userPath = orpg.dirpath.dir_struct["user"]
92 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') 93 validate = orpg.tools.validate.Validate(userPath)
94 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
95 configDom = minidom.parse(userPath + 'server_ini.xml')
93 port = configDom.childNodes[0].childNodes[1].getAttribute('port') 96 port = configDom.childNodes[0].childNodes[1].getAttribute('port')
94 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way. 97 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way.
95 self.owner = owner 98 self.owner = owner
96 99
97 def load_xml(self, xml): 100 def load_xml(self, xml):
141 # GUI Server ##################################### 144 # GUI Server #####################################
142 # Parent = notebook 145 # Parent = notebook
143 # Main = GUI 146 # Main = GUI
144 class Connections(wx.ListCtrl): 147 class Connections(wx.ListCtrl):
145 def __init__( self, parent, main ): 148 def __init__( self, parent, main ):
146 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, 149 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES )
147 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES )
148 self.main = main 150 self.main = main
149 self.roomList = { 0 : "Lobby" } 151 self.roomList = { 0 : "Lobby" }
150 self._imageList = wx.ImageList( 16, 16, False ) 152 self._imageList = wx.ImageList( 16, 16, False )
151 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() 153 img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap()
152 self._imageList.Add( img ) 154 self._imageList.Add( img )
153 img = wx.Image(dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() 155 img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap()
154 self._imageList.Add( img ) 156 self._imageList.Add( img )
155 self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL ) 157 self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL )
156 158
157 # Set The columns 159 # Set The columns
158 self.InsertColumn(0, "ID") 160 self.InsertColumn(0, "ID")
272 #Leave this in for now. 274 #Leave this in for now.
273 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: 275 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE:
274 print "Send message to room..." 276 print "Send message to room..."
275 msg = self.GetMessageInput( "Send message to room of this player") 277 msg = self.GetMessageInput( "Send message to room of this player")
276 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg ) 278 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg )
279
277 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: 280 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE:
278 print "broadcast a message..." 281 print "broadcast a message..."
279 msg = self.GetMessageInput( "Broadcast Server Message" ) 282 msg = self.GetMessageInput( "Broadcast Server Message" )
280 # If we got a message back, send it 283 # If we got a message back, send it
281 if len(msg): self.main.server.server.broadcast( msg ) 284 if len(msg):
285 self.main.server.server.broadcast( msg )
282 286
283 def GetMessageInput( self, title ): 287 def GetMessageInput( self, title ):
284 prompt = "Please enter the message you wish to send:" 288 prompt = "Please enter the message you wish to send:"
285 msg = wx.TextEntryDialog(self, prompt, title) 289 msg = wx.TextEntryDialog(self, prompt, title)
286 msg.ShowModal() 290 msg.ShowModal()
287 msg.Destroy() 291 msg.Destroy()
288 return msg.GetValue() 292 return msg.GetValue()
289 293
290 class ServerGUI(wx.Frame): 294 class ServerGUI(wx.Frame):
291 STATUS = SERVER_STOPPED 295 STATUS = SERVER_STOPPED
296
292 def __init__(self, parent, id, title): 297 def __init__(self, parent, id, title):
293 wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) 298 wx.Frame.__init__(self, parent, id, title, size = (760, 560) )
294 if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) 299 if wx.Platform == '__WXMSW__': icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO )
295 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) 300 else: icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF )
296 self.SetIcon(icon) 301 self.SetIcon(icon)
297 self.serverName = "Server Name" 302 self.serverName = "Server Name"
298 self.bootPwd = "" 303 self.bootPwd = ""
299 304
300 # Register our events to process -- notice the custom event handler 305 # Register our events to process -- notice the custom event handler
326 self.total_messages_received = 0 331 self.total_messages_received = 0
327 self.total_data_received = 0 332 self.total_data_received = 0
328 self.total_messages_sent = 0 333 self.total_messages_sent = 0
329 self.total_data_sent = 0 334 self.total_data_sent = 0
330 335
331 """ Build GUI """ 336 ### Build GUI ############################################
332 337
333 def build_menu(self): 338 def build_menu(self):
334 """ Build the GUI menu. """ 339 """ Build the GUI menu. """
335 self.mainMenu = wx.MenuBar() 340 self.mainMenu = wx.MenuBar()
336
337 # File Menu 341 # File Menu
338 menu = wx.Menu() 342 menu = wx.Menu()
343 # Start
339 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') 344 menu.Append( MENU_START_SERVER, 'Start', 'Start server.')
340 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) 345 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER)
346 # Stop
341 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') 347 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.')
342 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) 348 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER)
349 # Exit
343 menu.AppendSeparator() 350 menu.AppendSeparator()
344 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') 351 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.')
345 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) 352 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT)
346 self.mainMenu.Append(menu, '&Server') 353 self.mainMenu.Append(menu, '&Server')
347
348 # Registration Menu 354 # Registration Menu
349 menu = wx.Menu() 355 menu = wx.Menu()
356 # Register
350 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') 357 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.')
351 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) 358 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER)
359 # Unregister
352 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.') 360 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.')
353 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) 361 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER)
362 # Add the registration menu
354 self.mainMenu.Append( menu, '&Registration' ) 363 self.mainMenu.Append( menu, '&Registration' )
355
356 # Server Configuration Menu 364 # Server Configuration Menu
357 menu = wx.Menu() 365 menu = wx.Menu()
366 # Ping Connected Players
358 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) 367 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' )
359 self.Bind(wx.EVT_MENU, self.PingPlayers, id=MENU_START_PING_PLAYERS) 368 self.Bind(wx.EVT_MENU, self.PingPlayers, id=MENU_START_PING_PLAYERS)
369 # Stop Pinging Connected Players
360 menu.Append( MENU_STOP_PING_PLAYERS, 'Stop Ping', 'Stop validating player connections.' ) 370 menu.Append( MENU_STOP_PING_PLAYERS, 'Stop Ping', 'Stop validating player connections.' )
361 self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=MENU_STOP_PING_PLAYERS) 371 self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=MENU_STOP_PING_PLAYERS)
372 # Set Ping Interval
362 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' ) 373 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' )
363 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) 374 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL)
364 self.mainMenu.Append( menu, '&Configuration' ) 375 self.mainMenu.Append( menu, '&Configuration' )
365 376 # Add the menus to the main menu bar
366 self.SetMenuBar( self.mainMenu ) 377 self.SetMenuBar( self.mainMenu )
367 378 # Disable register, unregister & stop server by default
368 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 379 self.mainMenu.Enable( MENU_STOP_SERVER, False )
369 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 380 self.mainMenu.Enable( MENU_REGISTER_SERVER, False )
370 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 381 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False )
371
372 # Disable the ping menu items 382 # Disable the ping menu items
373 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) 383 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False )
374 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) 384 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False )
375 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) 385 self.mainMenu.Enable( MENU_PING_INTERVAL, False )
376 386
468 def OnStart(self, event = None): 478 def OnStart(self, event = None):
469 """ Start server. """ 479 """ Start server. """
470 if self.STATUS == SERVER_STOPPED: 480 if self.STATUS == SERVER_STOPPED:
471 # see if we already have name specified 481 # see if we already have name specified
472 try: 482 try:
473 Validate(dir_struct["user"]).config_file( "server_ini.xml", "default_server_ini.xml" ) 483 userPath = orpg.dirpath.dir_struct["user"]
474 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') 484 validate = orpg.tools.validate.Validate(userPath)
485 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
486 configDom = minidom.parse(userPath + 'server_ini.xml')
475 configDom.normalize() 487 configDom.normalize()
476 configDoc = configDom.documentElement 488 configDoc = configDom.documentElement
477 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") 489 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name")
478 except: pass 490 except: pass
479 if self.serverName == '': 491 if self.serverName == '':
480 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", 492 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:",
481 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) 493 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE )
482 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() 494 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue()
483 # see if we already have password specified 495 # see if we already have password specified
484 try: 496 try:
485 Validate(dir_struct["user"]).config_file( "server_ini.xml", "default_server_ini.xml" ) 497 userPath = orpg.dirpath.dir_struct["user"]
486 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') 498 validate = orpg.tools.validate.Validate(userPath)
499 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
500 configDom = minidom.parse(userPath + 'server_ini.xml')
487 configDom.normalize() 501 configDom.normalize()
488 configDoc = configDom.documentElement 502 configDoc = configDom.documentElement
489 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") 503 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin")
490 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") 504 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot")
491 except: pass 505 except: pass
492 if self.bootPwd == '': 506 if self.bootPwd == '':
493 serverPasswordEntry = wx.TextEntryDialog(self, 507 serverPasswordEntry = wx.TextEntryDialog(self, "Please Enter The Server Admin Password:", "Server's Password", self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE)
494 "Please Enter The Server Admin Password:", "Server's Password",
495 self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE)
496 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() 508 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue()
509
497 if len(self.serverName): 510 if len(self.serverName):
498 wx.BeginBusyCursor() 511 wx.BeginBusyCursor()
499 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) 512 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd)
500 self.server.start() 513 self.server.start()
501 self.STATUS = SERVER_RUNNING 514 self.STATUS = SERVER_RUNNING
517 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") 530 self.SetTitle(__appname__ + "- (stopped) - (unregistered)")
518 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 531 self.mainMenu.Enable( MENU_STOP_SERVER, False )
519 self.mainMenu.Enable( MENU_START_SERVER, True ) 532 self.mainMenu.Enable( MENU_START_SERVER, True )
520 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 533 self.mainMenu.Enable( MENU_REGISTER_SERVER, False )
521 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 534 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False )
535 # Delete any items that are still in the player list
522 self.conns.DeleteAllItems() 536 self.conns.DeleteAllItems()
523 537
524 def OnRegister(self, event = None): 538 def OnRegister(self, event = None):
525 """ Call into mplay_server's register() function. 539 """ Call into mplay_server's register() function.
526 This will begin registerThread(s) to keep server 540 This will begin registerThread(s) to keep server
570 584
571 class ServerGUIApp(wx.App): 585 class ServerGUIApp(wx.App):
572 def OnInit(self): 586 def OnInit(self):
573 # Make sure our image handlers are loaded before we try to display anything 587 # Make sure our image handlers are loaded before we try to display anything
574 wx.InitAllImageHandlers() 588 wx.InitAllImageHandlers()
575 self.splash = wx.SplashScreen(wx.Bitmap(dir_struct["icon"]+'splash.gif'), 589 self.splash = wx.SplashScreen(wx.Bitmap(orpg.dirpath.dir_struct["icon"]+'splash.gif'),
576 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT, 590 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,
577 2000, 591 2000,
578 None) 592 None)
579 self.splash.Show(True) 593 self.splash.Show(True)
580 wx.Yield() 594 wx.Yield()
588 frame.Raise() 602 frame.Raise()
589 self.SetTopWindow(frame) 603 self.SetTopWindow(frame)
590 604
591 class HTMLMessageWindow(wx.html.HtmlWindow): 605 class HTMLMessageWindow(wx.html.HtmlWindow):
592 "Widget used to present user to admin messages, in HTML format, to the server administrator" 606 "Widget used to present user to admin messages, in HTML format, to the server administrator"
607
593 # Init using the derived from class 608 # Init using the derived from class
594 def __init__( self, parent ): 609 def __init__( self, parent ):
595 wx.html.HtmlWindow.__init__( self, parent ) 610 wx.html.HtmlWindow.__init__( self, parent )
596 def OnLinkClicked( self, ref ): 611 def OnLinkClicked( self, ref ):
597 "Open an external browser to resolve our About box links!!!" 612 "Open an external browser to resolve our About box links!!!"