Mercurial > traipse_dev
comparison orpg/networking/mplay_server_gui.py @ 71:449a8900f9ac ornery-dev
Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author | sirebral |
---|---|
date | Thu, 20 Aug 2009 03:00:39 -0500 |
parents | c54768cffbd4 |
children | d1aff41c031b |
comparison
equal
deleted
inserted
replaced
70:52a5fa913008 | 71:449a8900f9ac |
---|---|
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 from orpg.dirpath import dir_struct |
17 import orpg.systempath | 17 #import orpg.systempath looks old |
18 from orpg.tools.validate import Validate | |
18 from orpg.orpg_wx import * | 19 from orpg.orpg_wx import * |
19 import webbrowser | 20 import webbrowser |
20 from threading import Thread | 21 from threading import Thread |
21 from meta_server_lib import post_server_data, remove_server | 22 from meta_server_lib import post_server_data, remove_server |
22 from mplay_server import mplay_server | 23 from mplay_server import mplay_server |
55 # Utils ########################################## | 56 # Utils ########################################## |
56 def format_bytes(b): | 57 def format_bytes(b): |
57 f = ['b', 'Kb', 'Mb', 'Gb'] | 58 f = ['b', 'Kb', 'Mb', 'Gb'] |
58 i = 0 | 59 i = 0 |
59 while i < 3: | 60 while i < 3: |
60 if b < 1024: | 61 if b < 1024: return str(b) + f[i] |
61 return str(b) + f[i] | 62 else: b = b/1024 |
62 else: | |
63 b = b/1024 | |
64 i += 1 | 63 i += 1 |
65 return str(b) + f[3] | 64 return str(b) + f[3] |
66 | 65 |
67 # wxEVT_LOG_MESSAGE | 66 # wxEVT_LOG_MESSAGE |
68 # MessageLogEvent ############################### | 67 # MessageLogEvent ############################### |
87 setting used to control the server. | 86 setting used to control the server. |
88 """ | 87 """ |
89 | 88 |
90 def __init__(self, owner ): | 89 def __init__(self, owner ): |
91 """ Loads default configuration settings.""" | 90 """ Loads default configuration settings.""" |
92 userPath = dir_struct["user"] | 91 Validate(dir_struct["user"]).config_file("server_ini.xml", "default_server_ini.xml" ) |
93 validate = orpg.tools.validate.Validate(userPath) | 92 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') |
94 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) | |
95 configDom = minidom.parse(userPath + 'server_ini.xml') | |
96 port = configDom.childNodes[0].childNodes[1].getAttribute('port') | 93 port = configDom.childNodes[0].childNodes[1].getAttribute('port') |
97 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way. | 94 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way. |
98 self.owner = owner | 95 self.owner = owner |
99 | 96 |
100 def load_xml(self, xml): | 97 def load_xml(self, xml): |
144 # GUI Server ##################################### | 141 # GUI Server ##################################### |
145 # Parent = notebook | 142 # Parent = notebook |
146 # Main = GUI | 143 # Main = GUI |
147 class Connections(wx.ListCtrl): | 144 class Connections(wx.ListCtrl): |
148 def __init__( self, parent, main ): | 145 def __init__( self, parent, main ): |
149 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES ) | 146 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, |
147 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES ) | |
150 self.main = main | 148 self.main = main |
151 self.roomList = { 0 : "Lobby" } | 149 self.roomList = { 0 : "Lobby" } |
152 self._imageList = wx.ImageList( 16, 16, False ) | 150 self._imageList = wx.ImageList( 16, 16, False ) |
153 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | 151 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() |
154 self._imageList.Add( img ) | 152 self._imageList.Add( img ) |
274 #Leave this in for now. | 272 #Leave this in for now. |
275 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: | 273 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: |
276 print "Send message to room..." | 274 print "Send message to room..." |
277 msg = self.GetMessageInput( "Send message to room of this player") | 275 msg = self.GetMessageInput( "Send message to room of this player") |
278 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg ) | 276 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg ) |
279 | |
280 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: | 277 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: |
281 print "broadcast a message..." | 278 print "broadcast a message..." |
282 msg = self.GetMessageInput( "Broadcast Server Message" ) | 279 msg = self.GetMessageInput( "Broadcast Server Message" ) |
283 # If we got a message back, send it | 280 # If we got a message back, send it |
284 if len(msg): | 281 if len(msg): self.main.server.server.broadcast( msg ) |
285 self.main.server.server.broadcast( msg ) | |
286 | 282 |
287 def GetMessageInput( self, title ): | 283 def GetMessageInput( self, title ): |
288 prompt = "Please enter the message you wish to send:" | 284 prompt = "Please enter the message you wish to send:" |
289 msg = wx.TextEntryDialog(self, prompt, title) | 285 msg = wx.TextEntryDialog(self, prompt, title) |
290 msg.ShowModal() | 286 msg.ShowModal() |
291 msg.Destroy() | 287 msg.Destroy() |
292 return msg.GetValue() | 288 return msg.GetValue() |
293 | 289 |
294 class ServerGUI(wx.Frame): | 290 class ServerGUI(wx.Frame): |
295 STATUS = SERVER_STOPPED | 291 STATUS = SERVER_STOPPED |
296 | |
297 def __init__(self, parent, id, title): | 292 def __init__(self, parent, id, title): |
298 wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) | 293 wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) |
299 if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) | 294 if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) |
300 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) | 295 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) |
301 self.SetIcon(icon) | 296 self.SetIcon(icon) |
331 self.total_messages_received = 0 | 326 self.total_messages_received = 0 |
332 self.total_data_received = 0 | 327 self.total_data_received = 0 |
333 self.total_messages_sent = 0 | 328 self.total_messages_sent = 0 |
334 self.total_data_sent = 0 | 329 self.total_data_sent = 0 |
335 | 330 |
336 ### Build GUI ############################################ | 331 """ Build GUI """ |
337 | 332 |
338 def build_menu(self): | 333 def build_menu(self): |
339 """ Build the GUI menu. """ | 334 """ Build the GUI menu. """ |
340 self.mainMenu = wx.MenuBar() | 335 self.mainMenu = wx.MenuBar() |
336 | |
341 # File Menu | 337 # File Menu |
342 menu = wx.Menu() | 338 menu = wx.Menu() |
343 # Start | |
344 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') | 339 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') |
345 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) | 340 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) |
346 # Stop | |
347 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') | 341 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') |
348 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) | 342 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) |
349 # Exit | |
350 menu.AppendSeparator() | 343 menu.AppendSeparator() |
351 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') | 344 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') |
352 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) | 345 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) |
353 self.mainMenu.Append(menu, '&Server') | 346 self.mainMenu.Append(menu, '&Server') |
347 | |
354 # Registration Menu | 348 # Registration Menu |
355 menu = wx.Menu() | 349 menu = wx.Menu() |
356 # Register | |
357 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') | 350 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') |
358 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) | 351 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) |
359 # Unregister | |
360 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.') | 352 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.') |
361 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) | 353 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) |
362 # Add the registration menu | |
363 self.mainMenu.Append( menu, '&Registration' ) | 354 self.mainMenu.Append( menu, '&Registration' ) |
355 | |
364 # Server Configuration Menu | 356 # Server Configuration Menu |
365 menu = wx.Menu() | 357 menu = wx.Menu() |
366 # Ping Connected Players | |
367 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) | 358 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) |
368 self.Bind(wx.EVT_MENU, self.PingPlayers, id=MENU_START_PING_PLAYERS) | 359 self.Bind(wx.EVT_MENU, self.PingPlayers, id=MENU_START_PING_PLAYERS) |
369 # Stop Pinging Connected Players | |
370 menu.Append( MENU_STOP_PING_PLAYERS, 'Stop Ping', 'Stop validating player connections.' ) | 360 menu.Append( MENU_STOP_PING_PLAYERS, 'Stop Ping', 'Stop validating player connections.' ) |
371 self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=MENU_STOP_PING_PLAYERS) | 361 self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=MENU_STOP_PING_PLAYERS) |
372 # Set Ping Interval | |
373 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' ) | 362 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' ) |
374 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) | 363 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) |
375 self.mainMenu.Append( menu, '&Configuration' ) | 364 self.mainMenu.Append( menu, '&Configuration' ) |
376 # Add the menus to the main menu bar | 365 |
377 self.SetMenuBar( self.mainMenu ) | 366 self.SetMenuBar( self.mainMenu ) |
378 # Disable register, unregister & stop server by default | 367 |
379 self.mainMenu.Enable( MENU_STOP_SERVER, False ) | 368 self.mainMenu.Enable( MENU_STOP_SERVER, False ) |
380 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) | 369 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) |
381 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) | 370 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) |
371 | |
382 # Disable the ping menu items | 372 # Disable the ping menu items |
383 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) | 373 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) |
384 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) | 374 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) |
385 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) | 375 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) |
386 | 376 |
478 def OnStart(self, event = None): | 468 def OnStart(self, event = None): |
479 """ Start server. """ | 469 """ Start server. """ |
480 if self.STATUS == SERVER_STOPPED: | 470 if self.STATUS == SERVER_STOPPED: |
481 # see if we already have name specified | 471 # see if we already have name specified |
482 try: | 472 try: |
483 userPath = dir_struct["user"] | 473 Validate(dir_struct["user"]).config_file( "server_ini.xml", "default_server_ini.xml" ) |
484 validate = orpg.tools.validate.Validate(userPath) | 474 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') |
485 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) | |
486 configDom = minidom.parse(userPath + 'server_ini.xml') | |
487 configDom.normalize() | 475 configDom.normalize() |
488 configDoc = configDom.documentElement | 476 configDoc = configDom.documentElement |
489 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") | 477 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") |
490 except: pass | 478 except: pass |
491 if self.serverName == '': | 479 if self.serverName == '': |
492 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", | 480 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", |
493 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) | 481 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) |
494 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() | 482 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() |
495 # see if we already have password specified | 483 # see if we already have password specified |
496 try: | 484 try: |
497 userPath = dir_struct["user"] | 485 Validate(dir_struct["user"]).config_file( "server_ini.xml", "default_server_ini.xml" ) |
498 validate = orpg.tools.validate.Validate(userPath) | 486 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') |
499 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) | |
500 configDom = minidom.parse(userPath + 'server_ini.xml') | |
501 configDom.normalize() | 487 configDom.normalize() |
502 configDoc = configDom.documentElement | 488 configDoc = configDom.documentElement |
503 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") | 489 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") |
504 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") | 490 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") |
505 except: pass | 491 except: pass |
506 if self.bootPwd == '': | 492 if self.bootPwd == '': |
507 serverPasswordEntry = wx.TextEntryDialog(self, "Please Enter The Server Admin Password:", "Server's Password", self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) | 493 serverPasswordEntry = wx.TextEntryDialog(self, |
494 "Please Enter The Server Admin Password:", "Server's Password", | |
495 self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) | |
508 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() | 496 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() |
509 | |
510 if len(self.serverName): | 497 if len(self.serverName): |
511 wx.BeginBusyCursor() | 498 wx.BeginBusyCursor() |
512 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) | 499 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) |
513 self.server.start() | 500 self.server.start() |
514 self.STATUS = SERVER_RUNNING | 501 self.STATUS = SERVER_RUNNING |
530 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") | 517 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") |
531 self.mainMenu.Enable( MENU_STOP_SERVER, False ) | 518 self.mainMenu.Enable( MENU_STOP_SERVER, False ) |
532 self.mainMenu.Enable( MENU_START_SERVER, True ) | 519 self.mainMenu.Enable( MENU_START_SERVER, True ) |
533 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) | 520 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) |
534 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) | 521 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) |
535 # Delete any items that are still in the player list | |
536 self.conns.DeleteAllItems() | 522 self.conns.DeleteAllItems() |
537 | 523 |
538 def OnRegister(self, event = None): | 524 def OnRegister(self, event = None): |
539 """ Call into mplay_server's register() function. | 525 """ Call into mplay_server's register() function. |
540 This will begin registerThread(s) to keep server | 526 This will begin registerThread(s) to keep server |
602 frame.Raise() | 588 frame.Raise() |
603 self.SetTopWindow(frame) | 589 self.SetTopWindow(frame) |
604 | 590 |
605 class HTMLMessageWindow(wx.html.HtmlWindow): | 591 class HTMLMessageWindow(wx.html.HtmlWindow): |
606 "Widget used to present user to admin messages, in HTML format, to the server administrator" | 592 "Widget used to present user to admin messages, in HTML format, to the server administrator" |
607 | |
608 # Init using the derived from class | 593 # Init using the derived from class |
609 def __init__( self, parent ): | 594 def __init__( self, parent ): |
610 wx.html.HtmlWindow.__init__( self, parent ) | 595 wx.html.HtmlWindow.__init__( self, parent ) |
611 def OnLinkClicked( self, ref ): | 596 def OnLinkClicked( self, ref ): |
612 "Open an external browser to resolve our About box links!!!" | 597 "Open an external browser to resolve our About box links!!!" |