Mercurial > traipse_dev
diff orpg/networking/mplay_server_gui.py @ 96:65c1604e7949 alpha
Traipse Alpha 'OpenRPG' {090924-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:
Update forwards to the 090909-02 Server code that now works.
New default Lobby Map, designed for Traipse. Feel free to change it.
Updates to Server GUI:
* Admin can Ban from Backend.
* Prework to modify Ban List in back end.
* Server GUI finds your Lobby Name
* New users default as Lurker unless a Role is set
New Addition to Chat Die Roll commands. Math Ordering. Ex. [(X+Y)dZ]. Currently does pairs only, no nesting either.
Cleaner TraipseSuiteAttention portability and clean up in Main (Beta!)
author | sirebral |
---|---|
date | Thu, 24 Sep 2009 02:05:08 -0500 |
parents | d1aff41c031b |
children | 95b5281e8d34 |
line wrap: on
line diff
--- a/orpg/networking/mplay_server_gui.py Sat Sep 19 12:19:17 2009 -0500 +++ b/orpg/networking/mplay_server_gui.py Thu Sep 24 02:05:08 2009 -0500 @@ -13,8 +13,9 @@ 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 @@ -33,9 +34,15 @@ 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_PLAYER_CREATE_ROOM = wx.NewId() MENU_PLAYER_SEND_MESSAGE = wx.NewId() MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId() @@ -57,10 +64,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 +89,35 @@ # 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 + ### Early Alpha ### This is prep for the Modify Ban List Dialog, just working out the details. + 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 + print ban_dict + ################### + 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 +157,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 +192,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 +201,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 +209,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 +239,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 +290,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 +313,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 +328,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 = "" @@ -333,52 +367,47 @@ 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_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 +509,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 +559,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): @@ -586,7 +612,7 @@ 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 +630,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 )