comparison 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
comparison
equal deleted inserted replaced
94:118fbe111922 100:7ed4979cc1cf
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 import orpg.dirpath 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, server
23 from xml.dom import minidom 24 from xml.dom import minidom
25 from orpg.orpgCore import component
24 26
25 # Constants ###################################### 27 # Constants ######################################
26 SERVER_RUNNING = 1 28 SERVER_RUNNING = 1
27 SERVER_STOPPED = 0 29 SERVER_STOPPED = 0
28 MENU_START_SERVER = wx.NewId() 30 MENU_START_SERVER = wx.NewId()
31 MENU_REGISTER_SERVER = wx.NewId() 33 MENU_REGISTER_SERVER = wx.NewId()
32 MENU_UNREGISTER_SERVER = wx.NewId() 34 MENU_UNREGISTER_SERVER = wx.NewId()
33 MENU_START_PING_PLAYERS = wx.NewId() 35 MENU_START_PING_PLAYERS = wx.NewId()
34 MENU_STOP_PING_PLAYERS = wx.NewId() 36 MENU_STOP_PING_PLAYERS = wx.NewId()
35 MENU_PING_INTERVAL = wx.NewId() 37 MENU_PING_INTERVAL = wx.NewId()
38 ### Alpha ###
39 MENU_MODIFY_BANLIST = wx.NewId()
40 #############
36 41
37 # Add our menu id's for our right click popup 42 # Add our menu id's for our right click popup
38 MENU_PLAYER_BOOT = wx.NewId() 43 MENU_PLAYER_BOOT = wx.NewId()
44 ### Alpha ###
45 MENU_ADMIN_BAN = wx.NewId()
46 MENU_BAN_LIST = wx.NewId()
47 MENU_ADMIN_UNBAN = wx.NewId()
48 #############
39 MENU_PLAYER_CREATE_ROOM = wx.NewId() 49 MENU_PLAYER_CREATE_ROOM = wx.NewId()
40 MENU_PLAYER_SEND_MESSAGE = wx.NewId() 50 MENU_PLAYER_SEND_MESSAGE = wx.NewId()
41 MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId() 51 MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId()
42 MENU_PLAYER_SEND_SERVER_MESSAGE = wx.NewId() 52 MENU_PLAYER_SEND_SERVER_MESSAGE = wx.NewId()
43 53
55 # Utils ########################################## 65 # Utils ##########################################
56 def format_bytes(b): 66 def format_bytes(b):
57 f = ['b', 'Kb', 'Mb', 'Gb'] 67 f = ['b', 'Kb', 'Mb', 'Gb']
58 i = 0 68 i = 0
59 while i < 3: 69 while i < 3:
60 if b < 1024: 70 if b < 1024: return str(b) + f[i]
61 return str(b) + f[i] 71 else: b = b/1024
62 else:
63 b = b/1024
64 i += 1 72 i += 1
65 return str(b) + f[3] 73 return str(b) + f[3]
66 74
67 # wxEVT_LOG_MESSAGE 75 # wxEVT_LOG_MESSAGE
68 # MessageLogEvent ############################### 76 # MessageLogEvent ###############################
82 self.message = message 90 self.message = message
83 91
84 # ServerConfig Object ############################ 92 # ServerConfig Object ############################
85 class ServerConfig: 93 class ServerConfig:
86 """ This class contains configuration 94 """ This class contains configuration
87 setting used to control the server. 95 setting used to control the server."""
88 """
89 96
90 def __init__(self, owner ): 97 def __init__(self, owner ):
91 """ Loads default configuration settings.""" 98 """ Loads default configuration settings."""
92 userPath = orpg.dirpath.dir_struct["user"] 99 validate.config_file("server_ini.xml", "default_server_ini.xml" )
93 validate = orpg.tools.validate.Validate(userPath) 100 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') 101 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. 102 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way.
98 self.owner = owner 103 self.owner = owner
99 104
100 def load_xml(self, xml): 105 def load_xml(self, xml):
101 """ Load configuration from XML data. 106 """ Load configuration from XML data.
102 xml (xml) -- xml string to parse 107 xml (xml) -- xml string to parse """
103 """
104 pass 108 pass
105 109
106 def save_xml(self): 110 def save_xml(self):
107 """ Returns XML file representing 111 """ Returns XML file representing
108 the active configuration. 112 the active configuration. """
109 """
110 pass 113 pass
111 114
112 # Server Monitor ################################# 115 # Server Monitor #################################
113 116
114 class ServerMonitor(Thread): 117 class ServerMonitor(Thread):
144 # GUI Server ##################################### 147 # GUI Server #####################################
145 # Parent = notebook 148 # Parent = notebook
146 # Main = GUI 149 # Main = GUI
147 class Connections(wx.ListCtrl): 150 class Connections(wx.ListCtrl):
148 def __init__( self, parent, main ): 151 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 ) 152 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition,
153 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES )
150 self.main = main 154 self.main = main
151 self.roomList = { 0 : "Lobby" } 155
156 ### Alpha ### Get Lobby Name
157 validate.config_file("server_ini.xml", "default_server_ini.xml" )
158 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml')
159 lobbyname = configDom.childNodes[0].getAttribute('lobbyname')
160 #############
161
162 self.roomList = { 0 : lobbyname }
152 self._imageList = wx.ImageList( 16, 16, False ) 163 self._imageList = wx.ImageList( 16, 16, False )
153 img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() 164 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap()
154 self._imageList.Add( img ) 165 self._imageList.Add( img )
155 img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() 166 img = wx.Image(dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap()
156 self._imageList.Add( img ) 167 self._imageList.Add( img )
157 self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL ) 168 self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL )
158 169
159 # Set The columns 170 # Set The columns
160 self.InsertColumn(0, "ID") 171 self.InsertColumn(0, "ID")
171 182
172 # Build our pop up menu to do cool things with the players in the list 183 # Build our pop up menu to do cool things with the players in the list
173 self.menu = wx.Menu() 184 self.menu = wx.Menu()
174 self.menu.SetTitle( "Player Menu" ) 185 self.menu.SetTitle( "Player Menu" )
175 self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" ) 186 self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" )
187 self.menu.Append( MENU_ADMIN_BAN, 'Ban Player' )
176 self.menu.AppendSeparator() 188 self.menu.AppendSeparator()
177 self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" ) 189 self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" )
178 self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" ) 190 self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" )
179 self.menu.Append( MENU_PLAYER_SEND_SERVER_MESSAGE, "Broadcast Server Message" ) 191 self.menu.Append( MENU_PLAYER_SEND_SERVER_MESSAGE, "Broadcast Server Message" )
180 192
181 # Associate our events 193 # Associate our events
182 self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu) 194 self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu)
183 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_BOOT) 195 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_BOOT)
196 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_ADMIN_BAN)
184 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_MESSAGE) 197 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_MESSAGE)
185 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_ROOM_MESSAGE) 198 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_ROOM_MESSAGE)
186 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_SERVER_MESSAGE) 199 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_SERVER_MESSAGE)
187 200
188 def add(self, player): 201 def add(self, player):
189 i = self.InsertImageStringItem( 0, player["id"], 0 ) 202 i = self.InsertImageStringItem( 0, player["id"], 0 )
190 self.SetStringItem( i, 1, self.stripHtml( player["name"] ) ) 203 self.SetStringItem( i, 1, self.stripHtml( player["name"] ) )
191 self.SetStringItem( i, 2, "new" ) 204 self.SetStringItem( i, 2, "NEW" )
192 self.SetStringItem( i, 3, self.roomList[0] ) 205 self.SetStringItem( i, 3, self.roomList[0] )
193 self.SetStringItem( i, 4, self.stripHtml( player["version"] ) ) 206 self.SetStringItem( i, 4, self.stripHtml( player["version"] ) )
194 self.SetStringItem( i, 5, self.stripHtml( player["role"] ) ) 207 self.SetStringItem( i, 5, 'Lurker' if self.stripHtml( player["role"] ) == '' else self.stripHtml( player["role"] ))
195 self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) ) 208 self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) )
196 self.SetStringItem (i, 7, "PING" ) 209 self.SetStringItem (i, 7, "PING" )
197 self.SetItemData( i, int(player["id"]) ) 210 self.SetItemData( i, int(player["id"]) )
198 self.AutoAjust() 211 self.AutoAjust()
199 212
216 def update(self, player): 229 def update(self, player):
217 i = self.FindItemData( -1, int(player["id"]) ) 230 i = self.FindItemData( -1, int(player["id"]) )
218 if i > -1: 231 if i > -1:
219 self.SetStringItem(i, 1, self.stripHtml(player["name"])) 232 self.SetStringItem(i, 1, self.stripHtml(player["name"]))
220 self.SetStringItem(i, 2, self.stripHtml(player["status"])) 233 self.SetStringItem(i, 2, self.stripHtml(player["status"]))
234 self.SetStringItem(i, 5, 'Lurker' if self.stripHtml(player["role"]) == '' else self.stripHtml(player["role"]))
221 self.AutoAjust() 235 self.AutoAjust()
222 else: self.add(player) 236 else: self.add(player)
223 237
224 def updateRoom( self, data ): 238 def updateRoom( self, data ):
225 (room, room_id, player) = data 239 (room, room_id, player) = data
226 i = self.FindItemData( -1, int(player) ) 240 i = self.FindItemData( -1, int(player) )
227 if i > 0: self.SetStringItem( i, 3, room ) 241 if player > 0: self.SetStringItem( i, 3, room )
228 self.AutoAjust() 242 self.AutoAjust()
229 243
230 def setPlayerRole( self, id, role ): 244 def setPlayerRole( self, id, role ):
231 i = self.FindItemData( -1, int(id) ) 245 i = self.FindItemData( -1, int(id) )
232 self.SetStringItem( i, 5, role ) 246 self.SetStringItem( i, 5, role )
247 self.AutoAjust
233 248
234 def stripHtml( self, name ): 249 def stripHtml( self, name ):
235 ret_string = "" 250 ret_string = ""
236 x = 0 251 x = 0
237 in_tag = 0 252 in_tag = 0
265 if menuItem == MENU_PLAYER_BOOT: 280 if menuItem == MENU_PLAYER_BOOT:
266 print "booting player: ", playerID 281 print "booting player: ", playerID
267 self.main.server.server.del_player( playerID, groupID ) 282 self.main.server.server.del_player( playerID, groupID )
268 self.main.server.server.check_group( playerID, groupID ) 283 self.main.server.server.check_group( playerID, groupID )
269 self.remove( playerID ) 284 self.remove( playerID )
285 ### Alpha ###
286 elif menuItem == MENU_ADMIN_BAN:
287 message = 'Banishment'
288 BanMsg = wx.TextEntryDialog( self, "Enter A Message To Send:",
289 "Ban Message", message, wx.OK|wx.CANCEL|wx.CENTRE )
290 if BanMsg.ShowModal() == wx.ID_OK: message = BanMsg.GetValue()
291 else: message = ''
292 Silent = wx.MessageDialog(None, 'Silent Ban?', 'Question',
293 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
294 if Silent.ShowModal() == wx.ID_YES: silent = 1
295 else: silent = 0
296 self.main.server.server.admin_ban(playerID, message, silent)
297 self.remove( playerID )
298 ###############
270 elif menuItem == MENU_PLAYER_SEND_MESSAGE: 299 elif menuItem == MENU_PLAYER_SEND_MESSAGE:
271 print "send a message..." 300 print "send a message..."
272 msg = self.GetMessageInput( "Send a message to player" ) 301 msg = self.GetMessageInput( "Send a message to player" )
273 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) ) 302 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) )
274 #Leave this in for now. 303 #Leave this in for now.
275 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: 304 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE:
276 print "Send message to room..." 305 print "Send message to room..."
277 msg = self.GetMessageInput( "Send message to room of this player") 306 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 ) 307 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg )
279
280 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: 308 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE:
281 print "broadcast a message..." 309 print "broadcast a message..."
282 msg = self.GetMessageInput( "Broadcast Server Message" ) 310 msg = self.GetMessageInput( "Broadcast Server Message" )
283 # If we got a message back, send it 311 # If we got a message back, send it
284 if len(msg): 312 if len(msg): self.main.server.server.broadcast( msg )
285 self.main.server.server.broadcast( msg )
286 313
287 def GetMessageInput( self, title ): 314 def GetMessageInput( self, title ):
288 prompt = "Please enter the message you wish to send:" 315 prompt = "Please enter the message you wish to send:"
289 msg = wx.TextEntryDialog(self, prompt, title) 316 msg = wx.TextEntryDialog(self, prompt, title)
290 msg.ShowModal() 317 msg.ShowModal()
291 msg.Destroy() 318 msg.Destroy()
292 return msg.GetValue() 319 return msg.GetValue()
293 320
294 class ServerGUI(wx.Frame): 321 class ServerGUI(wx.Frame):
295 STATUS = SERVER_STOPPED 322 STATUS = SERVER_STOPPED
296
297 def __init__(self, parent, id, title): 323 def __init__(self, parent, id, title):
298 wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) 324 wx.Frame.__init__(self, parent, id, title, size = (760, 560) )
299 if wx.Platform == '__WXMSW__': icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) 325 if wx.Platform == '__WXMSW__': icon = wx.Icon( dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO )
300 else: icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) 326 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF )
301 self.SetIcon(icon) 327 self.SetIcon(icon)
302 self.serverName = "Server Name" 328 self.serverName = "Server Name"
303 self.bootPwd = "" 329 self.bootPwd = ""
304 330
305 # Register our events to process -- notice the custom event handler 331 # Register our events to process -- notice the custom event handler
309 335
310 # Creat GUI 336 # Creat GUI
311 self.build_menu() 337 self.build_menu()
312 self.build_body() 338 self.build_body()
313 self.build_status() 339 self.build_status()
340
341 ### Alpha ###
342 # Ban List Dialog
343 self.BanListDialog = BanListDialog(self)
344 #############
314 345
315 # Server Callbacks 346 # Server Callbacks
316 cb = {} 347 cb = {}
317 cb["log"] = self.Log 348 cb["log"] = self.Log
318 cb["connect"] = self.OnConnect ##Fixed!! 349 cb["connect"] = self.OnConnect ##Fixed!!
331 self.total_messages_received = 0 362 self.total_messages_received = 0
332 self.total_data_received = 0 363 self.total_data_received = 0
333 self.total_messages_sent = 0 364 self.total_messages_sent = 0
334 self.total_data_sent = 0 365 self.total_data_sent = 0
335 366
336 ### Build GUI ############################################ 367 """ Build GUI """
337 368
338 def build_menu(self): 369 def build_menu(self):
339 """ Build the GUI menu. """ 370 """ Build the GUI menu. """
340 self.mainMenu = wx.MenuBar() 371 self.mainMenu = wx.MenuBar()
372
341 # File Menu 373 # File Menu
342 menu = wx.Menu() 374 menu = wx.Menu()
343 # Start
344 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') 375 menu.Append( MENU_START_SERVER, 'Start', 'Start server.')
345 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) 376 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER)
346 # Stop
347 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') 377 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.')
348 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) 378 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER)
349 # Exit
350 menu.AppendSeparator() 379 menu.AppendSeparator()
351 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') 380 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.')
352 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) 381 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT)
353 self.mainMenu.Append(menu, '&Server') 382 self.mainMenu.Append(menu, '&Server')
383
354 # Registration Menu 384 # Registration Menu
355 menu = wx.Menu() 385 menu = wx.Menu()
356 # Register
357 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') 386 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.')
358 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) 387 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.') 388 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.')
361 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) 389 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER)
362 # Add the registration menu
363 self.mainMenu.Append( menu, '&Registration' ) 390 self.mainMenu.Append( menu, '&Registration' )
391
364 # Server Configuration Menu 392 # Server Configuration Menu
365 menu = wx.Menu() 393 menu = wx.Menu()
366 # Ping Connected Players 394 menu.Append( MENU_BAN_LIST, 'Ban List', 'Modify Ban List.' )
395 self.Bind(wx.EVT_MENU, self.ModifyBanList, id=MENU_BAN_LIST)
367 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) 396 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) 397 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.' ) 398 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) 399 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.' ) 400 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' )
374 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) 401 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL)
375 self.mainMenu.Append( menu, '&Configuration' ) 402 self.mainMenu.Append( menu, '&Configuration' )
376 # Add the menus to the main menu bar 403
377 self.SetMenuBar( self.mainMenu ) 404 self.SetMenuBar( self.mainMenu )
378 # Disable register, unregister & stop server by default 405
379 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 406 self.mainMenu.Enable( MENU_STOP_SERVER, False )
380 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 407 self.mainMenu.Enable( MENU_REGISTER_SERVER, False )
381 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 408 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False )
409
382 # Disable the ping menu items 410 # Disable the ping menu items
383 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) 411 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False )
384 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) 412 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False )
385 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) 413 self.mainMenu.Enable( MENU_PING_INTERVAL, False )
386 414
478 def OnStart(self, event = None): 506 def OnStart(self, event = None):
479 """ Start server. """ 507 """ Start server. """
480 if self.STATUS == SERVER_STOPPED: 508 if self.STATUS == SERVER_STOPPED:
481 # see if we already have name specified 509 # see if we already have name specified
482 try: 510 try:
483 userPath = orpg.dirpath.dir_struct["user"]
484 validate = orpg.tools.validate.Validate(userPath)
485 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) 511 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
486 configDom = minidom.parse(userPath + 'server_ini.xml') 512 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml')
487 configDom.normalize() 513 configDom.normalize()
488 configDoc = configDom.documentElement 514 configDoc = configDom.documentElement
489 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") 515 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name")
490 except: pass 516 except: pass
491 if self.serverName == '': 517 if self.serverName == '':
518 self.serverName = 'Server Name'
492 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", 519 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 ) 520 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE )
494 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() 521 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue()
495 # see if we already have password specified 522 # see if we already have password specified
496 try: 523 try:
497 userPath = orpg.dirpath.dir_struct["user"]
498 validate = orpg.tools.validate.Validate(userPath)
499 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) 524 validate.config_file( "server_ini.xml", "default_server_ini.xml" )
500 configDom = minidom.parse(userPath + 'server_ini.xml') 525 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml')
501 configDom.normalize() 526 configDom.normalize()
502 configDoc = configDom.documentElement 527 configDoc = configDom.documentElement
503 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") 528 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin")
504 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") 529 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot")
505 except: pass 530 except: pass
506 if self.bootPwd == '': 531 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) 532 serverPasswordEntry = wx.TextEntryDialog(self,
533 "Please Enter The Server Admin Password:", "Server's Password",
534 self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE)
508 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() 535 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue()
509
510 if len(self.serverName): 536 if len(self.serverName):
511 wx.BeginBusyCursor() 537 wx.BeginBusyCursor()
512 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) 538 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd)
513 self.server.start() 539 self.server.start()
514 self.STATUS = SERVER_RUNNING 540 self.STATUS = SERVER_RUNNING
530 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") 556 self.SetTitle(__appname__ + "- (stopped) - (unregistered)")
531 self.mainMenu.Enable( MENU_STOP_SERVER, False ) 557 self.mainMenu.Enable( MENU_STOP_SERVER, False )
532 self.mainMenu.Enable( MENU_START_SERVER, True ) 558 self.mainMenu.Enable( MENU_START_SERVER, True )
533 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) 559 self.mainMenu.Enable( MENU_REGISTER_SERVER, False )
534 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) 560 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False )
535 # Delete any items that are still in the player list
536 self.conns.DeleteAllItems() 561 self.conns.DeleteAllItems()
537 562
538 def OnRegister(self, event = None): 563 def OnRegister(self, event = None):
539 """ Call into mplay_server's register() function. 564 """ Call into mplay_server's register() function.
540 This will begin registerThread(s) to keep server 565 This will begin registerThread(s) to keep server
563 self.mainMenu.Enable( MENU_REGISTER_SERVER, True ) 588 self.mainMenu.Enable( MENU_REGISTER_SERVER, True )
564 self.mainMenu.Enable( MENU_STOP_SERVER, True ) 589 self.mainMenu.Enable( MENU_STOP_SERVER, True )
565 self.SetTitle(__appname__ + "- (running) - (unregistered)") 590 self.SetTitle(__appname__ + "- (running) - (unregistered)")
566 wx.EndBusyCursor() 591 wx.EndBusyCursor()
567 592
593 ### Alpha ###
594 def ModifyBanList(self, event):
595 if self.BanListDialog.IsShown() == True: self.BanListDialog.Hide()
596 else: self.BanListDialog.Show()
597 #############
598
568 def PingPlayers( self, event = None ): 599 def PingPlayers( self, event = None ):
569 "Ping all players that are connected at a periodic interval, detecting dropped connections." 600 "Ping all players that are connected at a periodic interval, detecting dropped connections."
570 wx.BeginBusyCursor() 601 wx.BeginBusyCursor()
571 wx.Yield() 602 wx.Yield()
572 wx.EndBusyCursor() 603 wx.EndBusyCursor()
578 "Configure the player ping interval. Note that all players are pinged on a single timer." 609 "Configure the player ping interval. Note that all players are pinged on a single timer."
579 610
580 def OnExit(self, event = None): 611 def OnExit(self, event = None):
581 """ Quit the program. """ 612 """ Quit the program. """
582 self.OnStop() 613 self.OnStop()
614 self.BanListDialog.Destroy() ### Alpha ###
583 wx.CallAfter(self.Destroy) 615 wx.CallAfter(self.Destroy)
616
617 ### Alpha ###
618 class BanListDialog(wx.Frame):
619 def __init__(self, parent):
620 super(BanListDialog, self).__init__(parent, -1, "Ban List")
621 icon = wx.Icon(dir_struct["icon"]+'noplayer.gif', wx.BITMAP_TYPE_GIF)
622 self.SetIcon( icon )
623 self.BanList = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES)
624 sizer = wx.BoxSizer(wx.VERTICAL)
625 sizer.Add(self.BanList, 1, wx.EXPAND)
626 self.BuildList()
627 self.SetSizer(sizer)
628 self.SetAutoLayout(True)
629 self.SetSize((300, 175))
630 self.Bind(wx.EVT_CLOSE, self.Min)
631 self.Min(None)
632
633 # Ban List Dialog Pop Up Menu, more can be added
634 self.menu = wx.Menu()
635 self.menu.SetTitle( "Modify Ban List" )
636 self.menu.Append( MENU_ADMIN_UNBAN, "Un-Ban Player" )
637
638 # Even Association
639 self.BanList.Bind(wx.EVT_RIGHT_DOWN, self.BanPopupMenu)
640 self.Bind(wx.EVT_MENU, self.BanPopupMenuItem, id=MENU_ADMIN_UNBAN)
641
642 # When we right click, cause our popup menu to appear
643 def BanPopupMenu( self, event ):
644 pos = wx.Point( event.GetX(), event.GetY() )
645 (item, flag) = self.BanList.HitTest( pos )
646 if item > -1:
647 self.selectedItem = item
648 self.PopupMenu( self.menu, pos )
649
650 def BanPopupMenuItem( self, event):
651 menuItem = event.GetId()
652 player = str(self.BanList.GetItemData(self.selectedItem))
653 playerIP = str(self.BanList.GetItem((int(player)), 1).GetText())
654 if menuItem == MENU_ADMIN_UNBAN:
655 server.admin_unban(playerIP)
656 self.BanList.DeleteItem(self.BanList.GetItemData(self.selectedItem))
657 self.BanList.Refresh()
658
659 def BuildList(self):
660 # Build Dialog Columns
661 self.BanList.ClearAll()
662 self.BanList.InsertColumn(0, "User Name")
663 self.BanList.InsertColumn(1, "IP")
664
665 validate.config_file("ban_list.xml", "default_ban_list.xml" )
666 configDom = minidom.parse(dir_struct["user"] + 'ban_list.xml')
667 ban_dict = {}
668 for element in configDom.getElementsByTagName('banned'):
669 player = element.getAttribute('name').replace("&", "&amp;").replace("<", "&lt;").replace('"', "&quot;").replace(">", "&gt;")
670 playerIP = element.getAttribute('ip')
671 ban_dict[player] = playerIP
672 for key in ban_dict:
673 i = self.BanList.InsertImageStringItem( 0, key, 0 )
674 self.BanList.SetStringItem(i, 1, ban_dict[key])
675 self.BanList.RefreshItem(i)
676 self.AutoAdjust()
677
678 def AutoAdjust(self):
679 self.BanList.SetColumnWidth(0, -1)
680 self.BanList.SetColumnWidth(1, -1)
681 self.BanList.Refresh()
682
683 def Min(self, evt):
684 self.Hide()
685 ###############
584 686
585 class ServerGUIApp(wx.App): 687 class ServerGUIApp(wx.App):
586 def OnInit(self): 688 def OnInit(self):
587 # Make sure our image handlers are loaded before we try to display anything 689 # Make sure our image handlers are loaded before we try to display anything
588 wx.InitAllImageHandlers() 690 wx.InitAllImageHandlers()
589 self.splash = wx.SplashScreen(wx.Bitmap(orpg.dirpath.dir_struct["icon"]+'splash.gif'), 691 self.splash = wx.SplashScreen(wx.Bitmap(dir_struct["icon"]+'splash.gif'),
590 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT, 692 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,
591 2000, 693 2000,
592 None) 694 None)
593 self.splash.Show(True) 695 self.splash.Show(True)
594 wx.Yield() 696 wx.Yield()
602 frame.Raise() 704 frame.Raise()
603 self.SetTopWindow(frame) 705 self.SetTopWindow(frame)
604 706
605 class HTMLMessageWindow(wx.html.HtmlWindow): 707 class HTMLMessageWindow(wx.html.HtmlWindow):
606 "Widget used to present user to admin messages, in HTML format, to the server administrator" 708 "Widget used to present user to admin messages, in HTML format, to the server administrator"
607
608 # Init using the derived from class 709 # Init using the derived from class
609 def __init__( self, parent ): 710 def __init__( self, parent ):
610 wx.html.HtmlWindow.__init__( self, parent ) 711 wx.html.HtmlWindow.__init__( self, parent )
611 def OnLinkClicked( self, ref ): 712 def OnLinkClicked( self, ref ):
612 "Open an external browser to resolve our About box links!!!" 713 "Open an external browser to resolve our About box links!!!"