Mercurial > traipse_dev
diff orpg/networking/mplay_server_gui.py @ 100:7ed4979cc1cf beta
Traipse Beta 'OpenRPG' {090925-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:
090925-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.
Fixes Copy for Windows and Linux (finally!!) users.
Fixes incomplete update to Grid and List nodes.
Fixes incomplete update to Chat Commands.
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.
Minor changes to Update Manager's GUI.
Expert recommendation warning added to Revision Update.
Step down compatibility with open_rpg & component added to orpgCore.
Fixes CherryPit misspelling.
Makes Traipse Suite 'Attention' item portable, and executes it on 'Critical' debug notices.
Adds incomplete Shift + Enter to Text Entry, currently creates a 'Critical' warning.
New default Lobby Map, designed for Traipse. Feel free to change it.
Updates to Server GUI:
* Admin can Ban from Backend.
* Admin can Modify Ban List and Un Ban users.
* Server GUI finds your Lobby Name
* New users default as Lurker unless a Role is set
Cleaner TraipseSuiteAttention portability and clean up in Main.
Die Roll Commands addition from Core code allowing Math Ordering with ()'s
New About Dialog. A more uniform About Dialog.
Corrects image loading of duplicate images.
author | sirebral |
---|---|
date | Fri, 25 Sep 2009 20:46:02 -0500 |
parents | 68c7bd272f27 |
children | dcf4fbe09b70 |
line wrap: on
line diff
--- a/orpg/networking/mplay_server_gui.py Sat Sep 19 12:17:06 2009 -0500 +++ b/orpg/networking/mplay_server_gui.py Fri Sep 25 20:46:02 2009 -0500 @@ -13,14 +13,16 @@ import sys import time import types -import orpg.dirpath -import orpg.systempath +from orpg.dirpath import dir_struct +#import orpg.systempath looks old +from orpg.tools.validate import validate from orpg.orpg_wx import * import webbrowser from threading import Thread from meta_server_lib import post_server_data, remove_server -from mplay_server import mplay_server +from mplay_server import mplay_server, server from xml.dom import minidom +from orpg.orpgCore import component # Constants ###################################### SERVER_RUNNING = 1 @@ -33,9 +35,17 @@ MENU_START_PING_PLAYERS = wx.NewId() MENU_STOP_PING_PLAYERS = wx.NewId() MENU_PING_INTERVAL = wx.NewId() +### Alpha ### +MENU_MODIFY_BANLIST = wx.NewId() +############# # Add our menu id's for our right click popup MENU_PLAYER_BOOT = wx.NewId() +### Alpha ### +MENU_ADMIN_BAN = wx.NewId() +MENU_BAN_LIST = wx.NewId() +MENU_ADMIN_UNBAN = wx.NewId() +############# MENU_PLAYER_CREATE_ROOM = wx.NewId() MENU_PLAYER_SEND_MESSAGE = wx.NewId() MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId() @@ -57,10 +67,8 @@ f = ['b', 'Kb', 'Mb', 'Gb'] i = 0 while i < 3: - if b < 1024: - return str(b) + f[i] - else: - b = b/1024 + if b < 1024: return str(b) + f[i] + else: b = b/1024 i += 1 return str(b) + f[3] @@ -84,29 +92,24 @@ # ServerConfig Object ############################ class ServerConfig: """ This class contains configuration - setting used to control the server. - """ + setting used to control the server.""" def __init__(self, owner ): """ Loads default configuration settings.""" - userPath = orpg.dirpath.dir_struct["user"] - validate = orpg.tools.validate.Validate(userPath) - validate.config_file( "server_ini.xml", "default_server_ini.xml" ) - configDom = minidom.parse(userPath + 'server_ini.xml') + validate.config_file("server_ini.xml", "default_server_ini.xml" ) + configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') port = configDom.childNodes[0].childNodes[1].getAttribute('port') OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way. self.owner = owner def load_xml(self, xml): """ Load configuration from XML data. - xml (xml) -- xml string to parse - """ + xml (xml) -- xml string to parse """ pass def save_xml(self): """ Returns XML file representing - the active configuration. - """ + the active configuration. """ pass # Server Monitor ################################# @@ -146,13 +149,21 @@ # Main = GUI class Connections(wx.ListCtrl): def __init__( self, parent, main ): - wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES ) + wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, + wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES ) self.main = main - self.roomList = { 0 : "Lobby" } + + ### Alpha ### Get Lobby Name + validate.config_file("server_ini.xml", "default_server_ini.xml" ) + configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') + lobbyname = configDom.childNodes[0].getAttribute('lobbyname') + ############# + + self.roomList = { 0 : lobbyname } self._imageList = wx.ImageList( 16, 16, False ) - img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() + img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() self._imageList.Add( img ) - img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() + img = wx.Image(dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() self._imageList.Add( img ) self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL ) @@ -173,6 +184,7 @@ self.menu = wx.Menu() self.menu.SetTitle( "Player Menu" ) self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" ) + self.menu.Append( MENU_ADMIN_BAN, 'Ban Player' ) self.menu.AppendSeparator() self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" ) self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" ) @@ -181,6 +193,7 @@ # Associate our events self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu) self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_BOOT) + self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_ADMIN_BAN) self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_MESSAGE) self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_ROOM_MESSAGE) self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_SERVER_MESSAGE) @@ -188,10 +201,10 @@ def add(self, player): i = self.InsertImageStringItem( 0, player["id"], 0 ) self.SetStringItem( i, 1, self.stripHtml( player["name"] ) ) - self.SetStringItem( i, 2, "new" ) + self.SetStringItem( i, 2, "NEW" ) self.SetStringItem( i, 3, self.roomList[0] ) self.SetStringItem( i, 4, self.stripHtml( player["version"] ) ) - self.SetStringItem( i, 5, self.stripHtml( player["role"] ) ) + self.SetStringItem( i, 5, 'Lurker' if self.stripHtml( player["role"] ) == '' else self.stripHtml( player["role"] )) self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) ) self.SetStringItem (i, 7, "PING" ) self.SetItemData( i, int(player["id"]) ) @@ -218,18 +231,20 @@ if i > -1: self.SetStringItem(i, 1, self.stripHtml(player["name"])) self.SetStringItem(i, 2, self.stripHtml(player["status"])) + self.SetStringItem(i, 5, 'Lurker' if self.stripHtml(player["role"]) == '' else self.stripHtml(player["role"])) self.AutoAjust() else: self.add(player) def updateRoom( self, data ): (room, room_id, player) = data i = self.FindItemData( -1, int(player) ) - if i > 0: self.SetStringItem( i, 3, room ) + if player > 0: self.SetStringItem( i, 3, room ) self.AutoAjust() def setPlayerRole( self, id, role ): i = self.FindItemData( -1, int(id) ) self.SetStringItem( i, 5, role ) + self.AutoAjust def stripHtml( self, name ): ret_string = "" @@ -267,6 +282,20 @@ self.main.server.server.del_player( playerID, groupID ) self.main.server.server.check_group( playerID, groupID ) self.remove( playerID ) + ### Alpha ### + elif menuItem == MENU_ADMIN_BAN: + message = 'Banishment' + BanMsg = wx.TextEntryDialog( self, "Enter A Message To Send:", + "Ban Message", message, wx.OK|wx.CANCEL|wx.CENTRE ) + if BanMsg.ShowModal() == wx.ID_OK: message = BanMsg.GetValue() + else: message = '' + Silent = wx.MessageDialog(None, 'Silent Ban?', 'Question', + wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) + if Silent.ShowModal() == wx.ID_YES: silent = 1 + else: silent = 0 + self.main.server.server.admin_ban(playerID, message, silent) + self.remove( playerID ) + ############### elif menuItem == MENU_PLAYER_SEND_MESSAGE: print "send a message..." msg = self.GetMessageInput( "Send a message to player" ) @@ -276,13 +305,11 @@ print "Send message to room..." msg = self.GetMessageInput( "Send message to room of this player") if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg ) - elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: print "broadcast a message..." msg = self.GetMessageInput( "Broadcast Server Message" ) # If we got a message back, send it - if len(msg): - self.main.server.server.broadcast( msg ) + if len(msg): self.main.server.server.broadcast( msg ) def GetMessageInput( self, title ): prompt = "Please enter the message you wish to send:" @@ -293,11 +320,10 @@ class ServerGUI(wx.Frame): STATUS = SERVER_STOPPED - def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) - if wx.Platform == '__WXMSW__': icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) - else: icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) + if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) + else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) self.SetIcon(icon) self.serverName = "Server Name" self.bootPwd = "" @@ -312,6 +338,11 @@ self.build_body() self.build_status() + ### Alpha ### + # Ban List Dialog + self.BanListDialog = BanListDialog(self) + ############# + # Server Callbacks cb = {} cb["log"] = self.Log @@ -333,52 +364,49 @@ self.total_messages_sent = 0 self.total_data_sent = 0 - ### Build GUI ############################################ + """ Build GUI """ def build_menu(self): """ Build the GUI menu. """ self.mainMenu = wx.MenuBar() + # File Menu menu = wx.Menu() - # Start menu.Append( MENU_START_SERVER, 'Start', 'Start server.') self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) - # Stop menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) - # Exit menu.AppendSeparator() menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) self.mainMenu.Append(menu, '&Server') + # Registration Menu menu = wx.Menu() - # Register menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) - # Unregister menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.') self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) - # Add the registration menu self.mainMenu.Append( menu, '&Registration' ) + # Server Configuration Menu menu = wx.Menu() - # Ping Connected Players + menu.Append( MENU_BAN_LIST, 'Ban List', 'Modify Ban List.' ) + self.Bind(wx.EVT_MENU, self.ModifyBanList, id=MENU_BAN_LIST) menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) self.Bind(wx.EVT_MENU, self.PingPlayers, id=MENU_START_PING_PLAYERS) - # Stop Pinging Connected Players menu.Append( MENU_STOP_PING_PLAYERS, 'Stop Ping', 'Stop validating player connections.' ) self.Bind(wx.EVT_MENU, self.StopPingPlayers, id=MENU_STOP_PING_PLAYERS) - # Set Ping Interval menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' ) self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) self.mainMenu.Append( menu, '&Configuration' ) - # Add the menus to the main menu bar + self.SetMenuBar( self.mainMenu ) - # Disable register, unregister & stop server by default + self.mainMenu.Enable( MENU_STOP_SERVER, False ) self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) + # Disable the ping menu items self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) @@ -480,33 +508,31 @@ if self.STATUS == SERVER_STOPPED: # see if we already have name specified try: - userPath = orpg.dirpath.dir_struct["user"] - validate = orpg.tools.validate.Validate(userPath) validate.config_file( "server_ini.xml", "default_server_ini.xml" ) - configDom = minidom.parse(userPath + 'server_ini.xml') + configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') configDom.normalize() configDoc = configDom.documentElement if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") except: pass - if self.serverName == '': + if self.serverName == '': + self.serverName = 'Server Name' serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() # see if we already have password specified try: - userPath = orpg.dirpath.dir_struct["user"] - validate = orpg.tools.validate.Validate(userPath) validate.config_file( "server_ini.xml", "default_server_ini.xml" ) - configDom = minidom.parse(userPath + 'server_ini.xml') + configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') configDom.normalize() configDoc = configDom.documentElement if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") except: pass if self.bootPwd == '': - serverPasswordEntry = wx.TextEntryDialog(self, "Please Enter The Server Admin Password:", "Server's Password", self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) + serverPasswordEntry = wx.TextEntryDialog(self, + "Please Enter The Server Admin Password:", "Server's Password", + self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() - if len(self.serverName): wx.BeginBusyCursor() self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) @@ -532,7 +558,6 @@ self.mainMenu.Enable( MENU_START_SERVER, True ) self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) - # Delete any items that are still in the player list self.conns.DeleteAllItems() def OnRegister(self, event = None): @@ -565,6 +590,12 @@ self.SetTitle(__appname__ + "- (running) - (unregistered)") wx.EndBusyCursor() + ### Alpha ### + def ModifyBanList(self, event): + if self.BanListDialog.IsShown() == True: self.BanListDialog.Hide() + else: self.BanListDialog.Show() + ############# + def PingPlayers( self, event = None ): "Ping all players that are connected at a periodic interval, detecting dropped connections." wx.BeginBusyCursor() @@ -580,13 +611,84 @@ def OnExit(self, event = None): """ Quit the program. """ self.OnStop() + self.BanListDialog.Destroy() ### Alpha ### wx.CallAfter(self.Destroy) +### Alpha ### +class BanListDialog(wx.Frame): + def __init__(self, parent): + super(BanListDialog, self).__init__(parent, -1, "Ban List") + icon = wx.Icon(dir_struct["icon"]+'noplayer.gif', wx.BITMAP_TYPE_GIF) + self.SetIcon( icon ) + self.BanList = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES) + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.Add(self.BanList, 1, wx.EXPAND) + self.BuildList() + self.SetSizer(sizer) + self.SetAutoLayout(True) + self.SetSize((300, 175)) + self.Bind(wx.EVT_CLOSE, self.Min) + self.Min(None) + + # Ban List Dialog Pop Up Menu, more can be added + self.menu = wx.Menu() + self.menu.SetTitle( "Modify Ban List" ) + self.menu.Append( MENU_ADMIN_UNBAN, "Un-Ban Player" ) + + # Even Association + self.BanList.Bind(wx.EVT_RIGHT_DOWN, self.BanPopupMenu) + self.Bind(wx.EVT_MENU, self.BanPopupMenuItem, id=MENU_ADMIN_UNBAN) + + # When we right click, cause our popup menu to appear + def BanPopupMenu( self, event ): + pos = wx.Point( event.GetX(), event.GetY() ) + (item, flag) = self.BanList.HitTest( pos ) + if item > -1: + self.selectedItem = item + self.PopupMenu( self.menu, pos ) + + def BanPopupMenuItem( self, event): + menuItem = event.GetId() + player = str(self.BanList.GetItemData(self.selectedItem)) + playerIP = str(self.BanList.GetItem((int(player)), 1).GetText()) + if menuItem == MENU_ADMIN_UNBAN: + server.admin_unban(playerIP) + self.BanList.DeleteItem(self.BanList.GetItemData(self.selectedItem)) + self.BanList.Refresh() + + def BuildList(self): + # Build Dialog Columns + self.BanList.ClearAll() + self.BanList.InsertColumn(0, "User Name") + self.BanList.InsertColumn(1, "IP") + + validate.config_file("ban_list.xml", "default_ban_list.xml" ) + configDom = minidom.parse(dir_struct["user"] + 'ban_list.xml') + ban_dict = {} + for element in configDom.getElementsByTagName('banned'): + player = element.getAttribute('name').replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">") + playerIP = element.getAttribute('ip') + ban_dict[player] = playerIP + for key in ban_dict: + i = self.BanList.InsertImageStringItem( 0, key, 0 ) + self.BanList.SetStringItem(i, 1, ban_dict[key]) + self.BanList.RefreshItem(i) + self.AutoAdjust() + + def AutoAdjust(self): + self.BanList.SetColumnWidth(0, -1) + self.BanList.SetColumnWidth(1, -1) + self.BanList.Refresh() + + def Min(self, evt): + self.Hide() +############### + class ServerGUIApp(wx.App): def OnInit(self): # Make sure our image handlers are loaded before we try to display anything wx.InitAllImageHandlers() - self.splash = wx.SplashScreen(wx.Bitmap(orpg.dirpath.dir_struct["icon"]+'splash.gif'), + self.splash = wx.SplashScreen(wx.Bitmap(dir_struct["icon"]+'splash.gif'), wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT, 2000, None) @@ -604,7 +706,6 @@ class HTMLMessageWindow(wx.html.HtmlWindow): "Widget used to present user to admin messages, in HTML format, to the server administrator" - # Init using the derived from class def __init__( self, parent ): wx.html.HtmlWindow.__init__( self, parent )