Mercurial > traipse_dev
comparison 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 |
comparison
equal
deleted
inserted
replaced
95:af6bf998f425 | 96:65c1604e7949 |
---|---|
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 |
31 MENU_REGISTER_SERVER = wx.NewId() | 32 MENU_REGISTER_SERVER = wx.NewId() |
32 MENU_UNREGISTER_SERVER = wx.NewId() | 33 MENU_UNREGISTER_SERVER = wx.NewId() |
33 MENU_START_PING_PLAYERS = wx.NewId() | 34 MENU_START_PING_PLAYERS = wx.NewId() |
34 MENU_STOP_PING_PLAYERS = wx.NewId() | 35 MENU_STOP_PING_PLAYERS = wx.NewId() |
35 MENU_PING_INTERVAL = wx.NewId() | 36 MENU_PING_INTERVAL = wx.NewId() |
37 ### Alpha ### | |
38 MENU_MODIFY_BANLIST = wx.NewId() | |
39 ############# | |
36 | 40 |
37 # Add our menu id's for our right click popup | 41 # Add our menu id's for our right click popup |
38 MENU_PLAYER_BOOT = wx.NewId() | 42 MENU_PLAYER_BOOT = wx.NewId() |
43 ### Alpha ### | |
44 MENU_ADMIN_BAN = wx.NewId() | |
45 ############# | |
39 MENU_PLAYER_CREATE_ROOM = wx.NewId() | 46 MENU_PLAYER_CREATE_ROOM = wx.NewId() |
40 MENU_PLAYER_SEND_MESSAGE = wx.NewId() | 47 MENU_PLAYER_SEND_MESSAGE = wx.NewId() |
41 MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId() | 48 MENU_PLAYER_SEND_ROOM_MESSAGE = wx.NewId() |
42 MENU_PLAYER_SEND_SERVER_MESSAGE = wx.NewId() | 49 MENU_PLAYER_SEND_SERVER_MESSAGE = wx.NewId() |
43 | 50 |
55 # Utils ########################################## | 62 # Utils ########################################## |
56 def format_bytes(b): | 63 def format_bytes(b): |
57 f = ['b', 'Kb', 'Mb', 'Gb'] | 64 f = ['b', 'Kb', 'Mb', 'Gb'] |
58 i = 0 | 65 i = 0 |
59 while i < 3: | 66 while i < 3: |
60 if b < 1024: | 67 if b < 1024: return str(b) + f[i] |
61 return str(b) + f[i] | 68 else: b = b/1024 |
62 else: | |
63 b = b/1024 | |
64 i += 1 | 69 i += 1 |
65 return str(b) + f[3] | 70 return str(b) + f[3] |
66 | 71 |
67 # wxEVT_LOG_MESSAGE | 72 # wxEVT_LOG_MESSAGE |
68 # MessageLogEvent ############################### | 73 # MessageLogEvent ############################### |
82 self.message = message | 87 self.message = message |
83 | 88 |
84 # ServerConfig Object ############################ | 89 # ServerConfig Object ############################ |
85 class ServerConfig: | 90 class ServerConfig: |
86 """ This class contains configuration | 91 """ This class contains configuration |
87 setting used to control the server. | 92 setting used to control the server.""" |
88 """ | |
89 | 93 |
90 def __init__(self, owner ): | 94 def __init__(self, owner ): |
91 """ Loads default configuration settings.""" | 95 """ Loads default configuration settings.""" |
92 userPath = orpg.dirpath.dir_struct["user"] | 96 validate.config_file("server_ini.xml", "default_server_ini.xml" ) |
93 validate = orpg.tools.validate.Validate(userPath) | 97 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') | 98 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. | 99 OPENRPG_PORT = 6774 if port == '' else int(port) #Pretty ugly, but I couldn't find the tag any other way. |
98 self.owner = owner | 100 self.owner = owner |
99 | 101 |
102 ### Early Alpha ### This is prep for the Modify Ban List Dialog, just working out the details. | |
103 validate.config_file("ban_list.xml", "default_ban_list.xml" ) | |
104 configDom = minidom.parse(dir_struct["user"] + 'ban_list.xml') | |
105 ban_dict = {} | |
106 for element in configDom.getElementsByTagName('banned'): | |
107 player = element.getAttribute('name').replace("&", "&").replace("<", "<").replace('"', """).replace(">", ">") | |
108 playerIP = element.getAttribute('ip') | |
109 ban_dict[player] = playerIP | |
110 print ban_dict | |
111 ################### | |
112 | |
100 def load_xml(self, xml): | 113 def load_xml(self, xml): |
101 """ Load configuration from XML data. | 114 """ Load configuration from XML data. |
102 xml (xml) -- xml string to parse | 115 xml (xml) -- xml string to parse """ |
103 """ | |
104 pass | 116 pass |
105 | 117 |
106 def save_xml(self): | 118 def save_xml(self): |
107 """ Returns XML file representing | 119 """ Returns XML file representing |
108 the active configuration. | 120 the active configuration. """ |
109 """ | |
110 pass | 121 pass |
111 | 122 |
112 # Server Monitor ################################# | 123 # Server Monitor ################################# |
113 | 124 |
114 class ServerMonitor(Thread): | 125 class ServerMonitor(Thread): |
144 # GUI Server ##################################### | 155 # GUI Server ##################################### |
145 # Parent = notebook | 156 # Parent = notebook |
146 # Main = GUI | 157 # Main = GUI |
147 class Connections(wx.ListCtrl): | 158 class Connections(wx.ListCtrl): |
148 def __init__( self, parent, main ): | 159 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 ) | 160 wx.ListCtrl.__init__( self, parent, -1, wx.DefaultPosition, |
161 wx.DefaultSize, wx.LC_REPORT|wx.SUNKEN_BORDER|wx.EXPAND|wx.LC_HRULES ) | |
150 self.main = main | 162 self.main = main |
151 self.roomList = { 0 : "Lobby" } | 163 |
164 ### Alpha ### Get Lobby Name | |
165 validate.config_file("server_ini.xml", "default_server_ini.xml" ) | |
166 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') | |
167 lobbyname = configDom.childNodes[0].getAttribute('lobbyname') | |
168 ############# | |
169 | |
170 self.roomList = { 0 : lobbyname } | |
152 self._imageList = wx.ImageList( 16, 16, False ) | 171 self._imageList = wx.ImageList( 16, 16, False ) |
153 img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | 172 img = wx.Image(dir_struct["icon"]+"player.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() |
154 self._imageList.Add( img ) | 173 self._imageList.Add( img ) |
155 img = wx.Image(orpg.dirpath.dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | 174 img = wx.Image(dir_struct["icon"]+"player-whisper.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() |
156 self._imageList.Add( img ) | 175 self._imageList.Add( img ) |
157 self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL ) | 176 self.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL ) |
158 | 177 |
159 # Set The columns | 178 # Set The columns |
160 self.InsertColumn(0, "ID") | 179 self.InsertColumn(0, "ID") |
171 | 190 |
172 # Build our pop up menu to do cool things with the players in the list | 191 # Build our pop up menu to do cool things with the players in the list |
173 self.menu = wx.Menu() | 192 self.menu = wx.Menu() |
174 self.menu.SetTitle( "Player Menu" ) | 193 self.menu.SetTitle( "Player Menu" ) |
175 self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" ) | 194 self.menu.Append( MENU_PLAYER_BOOT, "Boot Player" ) |
195 self.menu.Append( MENU_ADMIN_BAN, 'Ban Player' ) | |
176 self.menu.AppendSeparator() | 196 self.menu.AppendSeparator() |
177 self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" ) | 197 self.menu.Append( MENU_PLAYER_SEND_MESSAGE, "Send Player Message" ) |
178 self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" ) | 198 self.menu.Append( MENU_PLAYER_SEND_ROOM_MESSAGE, "Send Room Message" ) |
179 self.menu.Append( MENU_PLAYER_SEND_SERVER_MESSAGE, "Broadcast Server Message" ) | 199 self.menu.Append( MENU_PLAYER_SEND_SERVER_MESSAGE, "Broadcast Server Message" ) |
180 | 200 |
181 # Associate our events | 201 # Associate our events |
182 self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu) | 202 self.Bind(wx.EVT_RIGHT_DOWN, self.OnPopupMenu) |
183 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_BOOT) | 203 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_BOOT) |
204 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_ADMIN_BAN) | |
184 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_MESSAGE) | 205 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) | 206 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) | 207 self.Bind(wx.EVT_MENU, self.OnPopupMenuItem, id=MENU_PLAYER_SEND_SERVER_MESSAGE) |
187 | 208 |
188 def add(self, player): | 209 def add(self, player): |
189 i = self.InsertImageStringItem( 0, player["id"], 0 ) | 210 i = self.InsertImageStringItem( 0, player["id"], 0 ) |
190 self.SetStringItem( i, 1, self.stripHtml( player["name"] ) ) | 211 self.SetStringItem( i, 1, self.stripHtml( player["name"] ) ) |
191 self.SetStringItem( i, 2, "new" ) | 212 self.SetStringItem( i, 2, "NEW" ) |
192 self.SetStringItem( i, 3, self.roomList[0] ) | 213 self.SetStringItem( i, 3, self.roomList[0] ) |
193 self.SetStringItem( i, 4, self.stripHtml( player["version"] ) ) | 214 self.SetStringItem( i, 4, self.stripHtml( player["version"] ) ) |
194 self.SetStringItem( i, 5, self.stripHtml( player["role"] ) ) | 215 self.SetStringItem( i, 5, 'Lurker' if self.stripHtml( player["role"] ) == '' else self.stripHtml( player["role"] )) |
195 self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) ) | 216 self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) ) |
196 self.SetStringItem (i, 7, "PING" ) | 217 self.SetStringItem (i, 7, "PING" ) |
197 self.SetItemData( i, int(player["id"]) ) | 218 self.SetItemData( i, int(player["id"]) ) |
198 self.AutoAjust() | 219 self.AutoAjust() |
199 | 220 |
216 def update(self, player): | 237 def update(self, player): |
217 i = self.FindItemData( -1, int(player["id"]) ) | 238 i = self.FindItemData( -1, int(player["id"]) ) |
218 if i > -1: | 239 if i > -1: |
219 self.SetStringItem(i, 1, self.stripHtml(player["name"])) | 240 self.SetStringItem(i, 1, self.stripHtml(player["name"])) |
220 self.SetStringItem(i, 2, self.stripHtml(player["status"])) | 241 self.SetStringItem(i, 2, self.stripHtml(player["status"])) |
242 self.SetStringItem(i, 5, 'Lurker' if self.stripHtml(player["role"]) == '' else self.stripHtml(player["role"])) | |
221 self.AutoAjust() | 243 self.AutoAjust() |
222 else: self.add(player) | 244 else: self.add(player) |
223 | 245 |
224 def updateRoom( self, data ): | 246 def updateRoom( self, data ): |
225 (room, room_id, player) = data | 247 (room, room_id, player) = data |
226 i = self.FindItemData( -1, int(player) ) | 248 i = self.FindItemData( -1, int(player) ) |
227 if i > 0: self.SetStringItem( i, 3, room ) | 249 if player > 0: self.SetStringItem( i, 3, room ) |
228 self.AutoAjust() | 250 self.AutoAjust() |
229 | 251 |
230 def setPlayerRole( self, id, role ): | 252 def setPlayerRole( self, id, role ): |
231 i = self.FindItemData( -1, int(id) ) | 253 i = self.FindItemData( -1, int(id) ) |
232 self.SetStringItem( i, 5, role ) | 254 self.SetStringItem( i, 5, role ) |
255 self.AutoAjust | |
233 | 256 |
234 def stripHtml( self, name ): | 257 def stripHtml( self, name ): |
235 ret_string = "" | 258 ret_string = "" |
236 x = 0 | 259 x = 0 |
237 in_tag = 0 | 260 in_tag = 0 |
265 if menuItem == MENU_PLAYER_BOOT: | 288 if menuItem == MENU_PLAYER_BOOT: |
266 print "booting player: ", playerID | 289 print "booting player: ", playerID |
267 self.main.server.server.del_player( playerID, groupID ) | 290 self.main.server.server.del_player( playerID, groupID ) |
268 self.main.server.server.check_group( playerID, groupID ) | 291 self.main.server.server.check_group( playerID, groupID ) |
269 self.remove( playerID ) | 292 self.remove( playerID ) |
293 ### Alpha ### | |
294 elif menuItem == MENU_ADMIN_BAN: | |
295 message = 'Banishment' | |
296 BanMsg = wx.TextEntryDialog( self, "Enter A Message To Send:", | |
297 "Ban Message", message, wx.OK|wx.CANCEL|wx.CENTRE ) | |
298 if BanMsg.ShowModal() == wx.ID_OK: message = BanMsg.GetValue() | |
299 else: message = '' | |
300 Silent = wx.MessageDialog(None, 'Silent Ban?', 'Question', | |
301 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) | |
302 if Silent.ShowModal() == wx.ID_YES: silent = 1 | |
303 else: silent = 0 | |
304 self.main.server.server.admin_ban(playerID, message, silent) | |
305 self.remove( playerID ) | |
306 ############### | |
270 elif menuItem == MENU_PLAYER_SEND_MESSAGE: | 307 elif menuItem == MENU_PLAYER_SEND_MESSAGE: |
271 print "send a message..." | 308 print "send a message..." |
272 msg = self.GetMessageInput( "Send a message to player" ) | 309 msg = self.GetMessageInput( "Send a message to player" ) |
273 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) ) | 310 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) ) |
274 #Leave this in for now. | 311 #Leave this in for now. |
275 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: | 312 elif menuItem == MENU_PLAYER_SEND_ROOM_MESSAGE: |
276 print "Send message to room..." | 313 print "Send message to room..." |
277 msg = self.GetMessageInput( "Send message to room of this player") | 314 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 ) | 315 if len(msg): self.main.server.server.send_to_group('0', str(groupID), msg ) |
279 | |
280 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: | 316 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: |
281 print "broadcast a message..." | 317 print "broadcast a message..." |
282 msg = self.GetMessageInput( "Broadcast Server Message" ) | 318 msg = self.GetMessageInput( "Broadcast Server Message" ) |
283 # If we got a message back, send it | 319 # If we got a message back, send it |
284 if len(msg): | 320 if len(msg): self.main.server.server.broadcast( msg ) |
285 self.main.server.server.broadcast( msg ) | |
286 | 321 |
287 def GetMessageInput( self, title ): | 322 def GetMessageInput( self, title ): |
288 prompt = "Please enter the message you wish to send:" | 323 prompt = "Please enter the message you wish to send:" |
289 msg = wx.TextEntryDialog(self, prompt, title) | 324 msg = wx.TextEntryDialog(self, prompt, title) |
290 msg.ShowModal() | 325 msg.ShowModal() |
291 msg.Destroy() | 326 msg.Destroy() |
292 return msg.GetValue() | 327 return msg.GetValue() |
293 | 328 |
294 class ServerGUI(wx.Frame): | 329 class ServerGUI(wx.Frame): |
295 STATUS = SERVER_STOPPED | 330 STATUS = SERVER_STOPPED |
296 | |
297 def __init__(self, parent, id, title): | 331 def __init__(self, parent, id, title): |
298 wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) | 332 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 ) | 333 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 ) | 334 else: icon = wx.Icon( dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF ) |
301 self.SetIcon(icon) | 335 self.SetIcon(icon) |
302 self.serverName = "Server Name" | 336 self.serverName = "Server Name" |
303 self.bootPwd = "" | 337 self.bootPwd = "" |
304 | 338 |
305 # Register our events to process -- notice the custom event handler | 339 # Register our events to process -- notice the custom event handler |
331 self.total_messages_received = 0 | 365 self.total_messages_received = 0 |
332 self.total_data_received = 0 | 366 self.total_data_received = 0 |
333 self.total_messages_sent = 0 | 367 self.total_messages_sent = 0 |
334 self.total_data_sent = 0 | 368 self.total_data_sent = 0 |
335 | 369 |
336 ### Build GUI ############################################ | 370 """ Build GUI """ |
337 | 371 |
338 def build_menu(self): | 372 def build_menu(self): |
339 """ Build the GUI menu. """ | 373 """ Build the GUI menu. """ |
340 self.mainMenu = wx.MenuBar() | 374 self.mainMenu = wx.MenuBar() |
375 | |
341 # File Menu | 376 # File Menu |
342 menu = wx.Menu() | 377 menu = wx.Menu() |
343 # Start | |
344 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') | 378 menu.Append( MENU_START_SERVER, 'Start', 'Start server.') |
345 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) | 379 self.Bind(wx.EVT_MENU, self.OnStart, id=MENU_START_SERVER) |
346 # Stop | |
347 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') | 380 menu.Append( MENU_STOP_SERVER, 'Stop', 'Shutdown server.') |
348 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) | 381 self.Bind(wx.EVT_MENU, self.OnStop, id=MENU_STOP_SERVER) |
349 # Exit | |
350 menu.AppendSeparator() | 382 menu.AppendSeparator() |
351 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') | 383 menu.Append( MENU_EXIT, 'E&xit', 'Exit application.') |
352 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) | 384 self.Bind(wx.EVT_MENU, self.OnExit, id=MENU_EXIT) |
353 self.mainMenu.Append(menu, '&Server') | 385 self.mainMenu.Append(menu, '&Server') |
386 | |
354 # Registration Menu | 387 # Registration Menu |
355 menu = wx.Menu() | 388 menu = wx.Menu() |
356 # Register | |
357 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') | 389 menu.Append( MENU_REGISTER_SERVER, 'Register', 'Register with OpenRPG server directory.') |
358 self.Bind(wx.EVT_MENU, self.OnRegister, id=MENU_REGISTER_SERVER) | 390 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.') | 391 menu.Append( MENU_UNREGISTER_SERVER, 'Unregister', 'Unregister from OpenRPG server directory.') |
361 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) | 392 self.Bind(wx.EVT_MENU, self.OnUnregister, id=MENU_UNREGISTER_SERVER) |
362 # Add the registration menu | |
363 self.mainMenu.Append( menu, '&Registration' ) | 393 self.mainMenu.Append( menu, '&Registration' ) |
394 | |
364 # Server Configuration Menu | 395 # Server Configuration Menu |
365 menu = wx.Menu() | 396 menu = wx.Menu() |
366 # Ping Connected Players | |
367 menu.Append( MENU_START_PING_PLAYERS, 'Start Ping', 'Ping players to validate remote connection.' ) | 397 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) | 398 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.' ) | 399 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) | 400 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.' ) | 401 menu.Append( MENU_PING_INTERVAL, 'Ping Interval', 'Change the ping interval.' ) |
374 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) | 402 self.Bind(wx.EVT_MENU, self.ConfigPingInterval, id=MENU_PING_INTERVAL) |
375 self.mainMenu.Append( menu, '&Configuration' ) | 403 self.mainMenu.Append( menu, '&Configuration' ) |
376 # Add the menus to the main menu bar | 404 |
377 self.SetMenuBar( self.mainMenu ) | 405 self.SetMenuBar( self.mainMenu ) |
378 # Disable register, unregister & stop server by default | 406 |
379 self.mainMenu.Enable( MENU_STOP_SERVER, False ) | 407 self.mainMenu.Enable( MENU_STOP_SERVER, False ) |
380 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) | 408 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) |
381 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) | 409 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) |
410 | |
382 # Disable the ping menu items | 411 # Disable the ping menu items |
383 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) | 412 self.mainMenu.Enable( MENU_START_PING_PLAYERS, False ) |
384 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) | 413 self.mainMenu.Enable( MENU_STOP_PING_PLAYERS, False ) |
385 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) | 414 self.mainMenu.Enable( MENU_PING_INTERVAL, False ) |
386 | 415 |
478 def OnStart(self, event = None): | 507 def OnStart(self, event = None): |
479 """ Start server. """ | 508 """ Start server. """ |
480 if self.STATUS == SERVER_STOPPED: | 509 if self.STATUS == SERVER_STOPPED: |
481 # see if we already have name specified | 510 # see if we already have name specified |
482 try: | 511 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" ) | 512 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) |
486 configDom = minidom.parse(userPath + 'server_ini.xml') | 513 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') |
487 configDom.normalize() | 514 configDom.normalize() |
488 configDoc = configDom.documentElement | 515 configDoc = configDom.documentElement |
489 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") | 516 if configDoc.hasAttribute("name"): self.serverName = configDoc.getAttribute("name") |
490 except: pass | 517 except: pass |
491 if self.serverName == '': | 518 if self.serverName == '': |
519 self.serverName = 'Server Name' | |
492 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", | 520 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 ) | 521 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) |
494 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() | 522 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue() |
495 # see if we already have password specified | 523 # see if we already have password specified |
496 try: | 524 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" ) | 525 validate.config_file( "server_ini.xml", "default_server_ini.xml" ) |
500 configDom = minidom.parse(userPath + 'server_ini.xml') | 526 configDom = minidom.parse(dir_struct["user"] + 'server_ini.xml') |
501 configDom.normalize() | 527 configDom.normalize() |
502 configDoc = configDom.documentElement | 528 configDoc = configDom.documentElement |
503 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") | 529 if configDoc.hasAttribute("admin"): self.bootPwd = configDoc.getAttribute("admin") |
504 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") | 530 elif configDoc.hasAttribute("boot"): self.bootPwd = configDoc.getAttribute("boot") |
505 except: pass | 531 except: pass |
506 if self.bootPwd == '': | 532 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) | 533 serverPasswordEntry = wx.TextEntryDialog(self, |
534 "Please Enter The Server Admin Password:", "Server's Password", | |
535 self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) | |
508 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() | 536 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue() |
509 | |
510 if len(self.serverName): | 537 if len(self.serverName): |
511 wx.BeginBusyCursor() | 538 wx.BeginBusyCursor() |
512 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) | 539 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) |
513 self.server.start() | 540 self.server.start() |
514 self.STATUS = SERVER_RUNNING | 541 self.STATUS = SERVER_RUNNING |
530 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") | 557 self.SetTitle(__appname__ + "- (stopped) - (unregistered)") |
531 self.mainMenu.Enable( MENU_STOP_SERVER, False ) | 558 self.mainMenu.Enable( MENU_STOP_SERVER, False ) |
532 self.mainMenu.Enable( MENU_START_SERVER, True ) | 559 self.mainMenu.Enable( MENU_START_SERVER, True ) |
533 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) | 560 self.mainMenu.Enable( MENU_REGISTER_SERVER, False ) |
534 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) | 561 self.mainMenu.Enable( MENU_UNREGISTER_SERVER, False ) |
535 # Delete any items that are still in the player list | |
536 self.conns.DeleteAllItems() | 562 self.conns.DeleteAllItems() |
537 | 563 |
538 def OnRegister(self, event = None): | 564 def OnRegister(self, event = None): |
539 """ Call into mplay_server's register() function. | 565 """ Call into mplay_server's register() function. |
540 This will begin registerThread(s) to keep server | 566 This will begin registerThread(s) to keep server |
584 | 610 |
585 class ServerGUIApp(wx.App): | 611 class ServerGUIApp(wx.App): |
586 def OnInit(self): | 612 def OnInit(self): |
587 # Make sure our image handlers are loaded before we try to display anything | 613 # Make sure our image handlers are loaded before we try to display anything |
588 wx.InitAllImageHandlers() | 614 wx.InitAllImageHandlers() |
589 self.splash = wx.SplashScreen(wx.Bitmap(orpg.dirpath.dir_struct["icon"]+'splash.gif'), | 615 self.splash = wx.SplashScreen(wx.Bitmap(dir_struct["icon"]+'splash.gif'), |
590 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT, | 616 wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT, |
591 2000, | 617 2000, |
592 None) | 618 None) |
593 self.splash.Show(True) | 619 self.splash.Show(True) |
594 wx.Yield() | 620 wx.Yield() |
602 frame.Raise() | 628 frame.Raise() |
603 self.SetTopWindow(frame) | 629 self.SetTopWindow(frame) |
604 | 630 |
605 class HTMLMessageWindow(wx.html.HtmlWindow): | 631 class HTMLMessageWindow(wx.html.HtmlWindow): |
606 "Widget used to present user to admin messages, in HTML format, to the server administrator" | 632 "Widget used to present user to admin messages, in HTML format, to the server administrator" |
607 | |
608 # Init using the derived from class | 633 # Init using the derived from class |
609 def __init__( self, parent ): | 634 def __init__( self, parent ): |
610 wx.html.HtmlWindow.__init__( self, parent ) | 635 wx.html.HtmlWindow.__init__( self, parent ) |
611 def OnLinkClicked( self, ref ): | 636 def OnLinkClicked( self, ref ): |
612 "Open an external browser to resolve our About box links!!!" | 637 "Open an external browser to resolve our About box links!!!" |