comparison orpg/networking/mplay_server_gui.py @ 27:a571772a45c7 traipse_dev

Minor house cleaning in the mplay_server_gui. Getting ready to push this to stable.
author sirebral
date Fri, 31 Jul 2009 13:51:54 -0500
parents c97c641a76fd
children c7f04d3c76f5
comparison
equal deleted inserted replaced
26:65c5cb9be59c 27:a571772a45c7
89 """ 89 """
90 90
91 def __init__(self, owner ): 91 def __init__(self, owner ):
92 """ Loads default configuration settings. 92 """ Loads default configuration settings.
93 """ 93 """
94 OPENRPG_PORT = 9775 94 OPENRPG_PORT = 9557
95 self.owner = owner 95 self.owner = owner
96 96
97 def load_xml(self, xml): 97 def load_xml(self, xml):
98 """ Load configuration from XML data. 98 """ Load configuration from XML data.
99 xml (xml) -- xml string to parse 99 xml (xml) -- xml string to parse
120 120
121 def log(self, mesg): 121 def log(self, mesg):
122 if type(mesg) == types.TupleType: 122 if type(mesg) == types.TupleType:
123 func, msg = mesg 123 func, msg = mesg
124 event = MessageFunctionEvent( func, msg ) 124 event = MessageFunctionEvent( func, msg )
125 else: 125 else: event = MessageLogEvent( mesg )
126 event = MessageLogEvent( mesg )
127 wx.PostEvent( self.conf.owner, event ) 126 wx.PostEvent( self.conf.owner, event )
128 del event 127 del event
129 128
130 def run(self): 129 def run(self):
131 """ Start the server. """ 130 """ Start the server. """
132 self.server = mplay_server(self.log, self.serverName ) 131 self.server = mplay_server(self.log, self.serverName )
133 self.server.initServer(bootPassword=self.bootPwd, reg="No") 132 self.server.initServer(bootPassword=self.bootPwd, reg="No")
134 self.alive = 1 133 self.alive = 1
135 while self.alive: 134 while self.alive: time.sleep(3)
136 time.sleep(3)
137 135
138 def stop(self): 136 def stop(self):
139 """ Stop the server. """ 137 """ Stop the server. """
140 self.server.kill_server() 138 self.server.kill_server()
141 self.alive = 0 139 self.alive = 0
188 self.SetStringItem( i, 1, self.stripHtml( player["name"] ) ) 186 self.SetStringItem( i, 1, self.stripHtml( player["name"] ) )
189 self.SetStringItem( i, 2, self.stripHtml( player["status"] ) ) 187 self.SetStringItem( i, 2, self.stripHtml( player["status"] ) )
190 self.SetStringItem( i, 3, "ROOM" ) 188 self.SetStringItem( i, 3, "ROOM" )
191 self.SetStringItem( i, 4, self.stripHtml( player["version"] ) ) 189 self.SetStringItem( i, 4, self.stripHtml( player["version"] ) )
192 self.SetStringItem( i, 5, self.stripHtml( player["role"] ) ) 190 self.SetStringItem( i, 5, self.stripHtml( player["role"] ) )
193 self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) ) 191 self.SetStringItem( i, 6, self.stripHtml( player["ip"] ) )
194 self.SetStringItem (i, 7, "PING" ) 192 self.SetStringItem (i, 7, "PING" )
195 self.SetItemData( i, int(player["id"]) ) 193 self.SetItemData( i, int(player["id"]) )
196 self.AutoAjust() 194 self.AutoAjust()
197 195
198 def remove(self, id): 196 def remove(self, id):
199 i = self.FindItemData( -1, int(id) ) 197 i = self.FindItemData( -1, int(id) )
205 self.SetColumnWidth(1, -1) 203 self.SetColumnWidth(1, -1)
206 self.SetColumnWidth(2, -1) 204 self.SetColumnWidth(2, -1)
207 self.SetColumnWidth(3, -1) 205 self.SetColumnWidth(3, -1)
208 self.SetColumnWidth(4, -1) 206 self.SetColumnWidth(4, -1)
209 self.SetColumnWidth(5, -1) 207 self.SetColumnWidth(5, -1)
210 self.SetColumnWidth(6, -1) 208 self.SetColumnWidth(6, -1)
211 self.SetColumnWidth(7, -1) 209 self.SetColumnWidth(7, -1)
212 self.Refresh() 210 self.Refresh()
213 211
214 def update(self, player): 212 def update(self, player):
215 i = self.FindItemData( -1, int(player["id"]) ) 213 i = self.FindItemData( -1, int(player["id"]) )
216 if i > -1: 214 if i > -1:
217 self.SetStringItem(i, 1, player["name"]) 215 self.SetStringItem(i, 1, player["name"])
218 self.SetStringItem(i, 2, self.stripHtml( player["status"] ) ) 216 self.SetStringItem(i, 2, self.stripHtml( player["status"] ) )
219 self.AutoAjust() 217 self.AutoAjust()
220 else: 218 else: self.add(player)
221 self.add(player)
222 219
223 def updateRoom( self, data ): 220 def updateRoom( self, data ):
224 (from_id, id) = data 221 (from_id, id) = data
225 i = self.FindItemData( -1, int(from_id) ) 222 i = self.FindItemData( -1, int(from_id) )
226 self.SetStringItem( i, 3, self.roomList[id] ) 223 self.SetStringItem( i, 3, self.roomList[id] )
235 ret_string = "" 232 ret_string = ""
236 x = 0 233 x = 0
237 in_tag = 0 234 in_tag = 0
238 for x in range( len(name) ): 235 for x in range( len(name) ):
239 if name[x] == "<" or name[x] == ">" or in_tag == 1 : 236 if name[x] == "<" or name[x] == ">" or in_tag == 1 :
240 if name[x] == "<" : 237 if name[x] == "<": in_tag = 1
241 in_tag = 1 238 elif name[x] == ">": in_tag = 0
242 elif name[x] == ">" : 239 else: pass
243 in_tag = 0 240 else: ret_string = ret_string + name[x]
244 else :
245 pass
246 else :
247 ret_string = ret_string + name[x]
248 return ret_string 241 return ret_string
249 242
250 # When we right click, cause our popup menu to appear 243 # When we right click, cause our popup menu to appear
251 def OnPopupMenu( self, event ): 244 def OnPopupMenu( self, event ):
252 pos = wx.Point( event.GetX(), event.GetY() ) 245 pos = wx.Point( event.GetX(), event.GetY() )
269 self.main.server.server.check_group( playerID, groupID ) 262 self.main.server.server.check_group( playerID, groupID )
270 self.remove( playerID ) 263 self.remove( playerID )
271 elif menuItem == MENU_PLAYER_SEND_MESSAGE: 264 elif menuItem == MENU_PLAYER_SEND_MESSAGE:
272 print "send a message..." 265 print "send a message..."
273 msg = self.GetMessageInput( "Send a message to player" ) 266 msg = self.GetMessageInput( "Send a message to player" )
274 if len(msg): 267 if len(msg): self.main.server.server.send( msg, playerID, str(groupID) )
275 self.main.server.server.send( msg, playerID, str(groupID) ) 268 #Leave this in for now.
276 # Leave this in for now. 269 #elif menuItem == MENU_PLAYER_SEND_TO_ROOM:
277 # elif menuItem == MENU_PLAYER_SEND_TO_ROOM: 270 # print "Send message to room..."
278 # print "Send message to room..." 271 # msg = self.GetMessageInput( "Send message to room of this player")
279 # msg = self.GetMessageInput( "Send message to room of this player") 272 # if len(msg):
280 # if len(msg): 273 # self.main.server.server.send_to_group( 0, GroupID, msg )
281 # self.main.server.server.send_to_group( 0, GroupID, msg )
282 274
283 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE: 275 elif menuItem == MENU_PLAYER_SEND_SERVER_MESSAGE:
284 print "broadcast a message..." 276 print "broadcast a message..."
285 msg = self.GetMessageInput( "Broadcast Server Message" ) 277 msg = self.GetMessageInput( "Broadcast Server Message" )
286 # If we got a message back, send it 278 # If we got a message back, send it
297 class ServerGUI(wx.Frame): 289 class ServerGUI(wx.Frame):
298 STATUS = SERVER_STOPPED 290 STATUS = SERVER_STOPPED
299 291
300 def __init__(self, parent, id, title): 292 def __init__(self, parent, id, title):
301 wx.Frame.__init__(self, parent, id, title, size = (760, 560) ) 293 wx.Frame.__init__(self, parent, id, title, size = (760, 560) )
302 if wx.Platform == '__WXMSW__': 294 if wx.Platform == '__WXMSW__': icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO )
303 icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'WAmisc9.ico', wx.BITMAP_TYPE_ICO ) 295 else: icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF )
304 else:
305 icon = wx.Icon( orpg.dirpath.dir_struct["icon"]+'connect.gif', wx.BITMAP_TYPE_GIF )
306 self.SetIcon(icon) 296 self.SetIcon(icon)
307 self.serverName = "Server Name" 297 self.serverName = "Server Name"
308 self.bootPwd = "" 298 self.bootPwd = ""
309 299
310 # Register our events to process -- notice the custom event handler 300 # Register our events to process -- notice the custom event handler
393 """ Create the ViewNotebook and logger. """ 383 """ Create the ViewNotebook and logger. """
394 splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D | wx.SP_3D) 384 splitter = wx.SplitterWindow(self, -1, style=wx.NO_3D | wx.SP_3D)
395 nb = wx.Notebook( splitter, -1 ) 385 nb = wx.Notebook( splitter, -1 )
396 self.conns = Connections( nb, self ) 386 self.conns = Connections( nb, self )
397 nb.AddPage( self.conns, "Players" ) 387 nb.AddPage( self.conns, "Players" )
398 #Not sure why this is Remarked TaS - Sirebral 388
389 #Not sure why this is Remarked TaS - Sirebral
399 #nb.AddPage( self.conns, "Rooms" ) 390 #nb.AddPage( self.conns, "Rooms" )
400 #self.msgWindow = HTMLMessageWindow( nb ) 391 #self.msgWindow = HTMLMessageWindow( nb )
401 #nb.AddPage( self.msgWindow, "Messages" ) 392 #nb.AddPage( self.msgWindow, "Messages" )
402 393
403 log = wx.TextCtrl(splitter, -1, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL) 394 log = wx.TextCtrl(splitter, -1, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
461 self.sb.SetStatusText("Recv: %s (%d)" % (format_bytes(self.total_data_received), self.total_messages_received), 2) 452 self.sb.SetStatusText("Recv: %s (%d)" % (format_bytes(self.total_data_received), self.total_messages_received), 2)
462 453
463 def OnCreateGroup( self, data ): 454 def OnCreateGroup( self, data ):
464 print "room list: ", self.conns.roomList 455 print "room list: ", self.conns.roomList
465 self.conns.roomList[id] = name 456 self.conns.roomList[id] = name
466 (id, name) = data 457 (id, name) = data
467 print "room list: ", self.conns.roomList 458 print "room list: ", self.conns.roomList
468 459
469 def OnDeleteGroup( self, data ): 460 def OnDeleteGroup( self, data ):
470 (from_id, id) = data 461 (from_id, id) = data
471 # del self.conns.roomList[id] 462 #del self.conns.roomList[id]
472 print "OnDeleteGroup room list: ", self.conns.roomList, id 463 print "OnDeleteGroup room list: ", self.conns.roomList, id
473 464
474 def OnJoinGroup( self, data ): 465 def OnJoinGroup( self, data ):
475 self.conns.updateRoom( data ) 466 self.conns.updateRoom( data )
476 467
482 def OnStart(self, event = None): 473 def OnStart(self, event = None):
483 """ Start server. """ 474 """ Start server. """
484 if self.STATUS == SERVER_STOPPED: 475 if self.STATUS == SERVER_STOPPED:
485 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:", 476 serverNameEntry = wx.TextEntryDialog( self, "Please Enter The Server Name You Wish To Use:",
486 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE ) 477 "Server's Name", self.serverName, wx.OK|wx.CANCEL|wx.CENTRE )
487 if serverNameEntry.ShowModal() == wx.ID_OK: 478 if serverNameEntry.ShowModal() == wx.ID_OK: self.serverName = serverNameEntry.GetValue()
488 self.serverName = serverNameEntry.GetValue()
489 serverPasswordEntry = wx.TextEntryDialog(self, "Please Enter The Server Admin Password:", 479 serverPasswordEntry = wx.TextEntryDialog(self, "Please Enter The Server Admin Password:",
490 "Server's Password", self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE) 480 "Server's Password", self.bootPwd, wx.OK|wx.CANCEL|wx.CENTRE)
491 if serverPasswordEntry.ShowModal() == wx.ID_OK: 481 if serverPasswordEntry.ShowModal() == wx.ID_OK: self.bootPwd = serverPasswordEntry.GetValue()
492 self.bootPwd = serverPasswordEntry.GetValue()
493 if len(self.serverName): 482 if len(self.serverName):
494 wx.BeginBusyCursor() 483 wx.BeginBusyCursor()
495 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd) 484 self.server = ServerMonitor(self.callbacks, self.conf, self.serverName, self.bootPwd)
496 self.server.start() 485 self.server.start()
497 self.STATUS = SERVER_RUNNING 486 self.STATUS = SERVER_RUNNING
499 self.SetTitle(__appname__ + "- (running) - (unregistered)") 488 self.SetTitle(__appname__ + "- (running) - (unregistered)")
500 self.mainMenu.Enable( MENU_START_SERVER, False ) 489 self.mainMenu.Enable( MENU_START_SERVER, False )
501 self.mainMenu.Enable( MENU_STOP_SERVER, True ) 490 self.mainMenu.Enable( MENU_STOP_SERVER, True )
502 self.mainMenu.Enable( MENU_REGISTER_SERVER, True ) 491 self.mainMenu.Enable( MENU_REGISTER_SERVER, True )
503 wx.EndBusyCursor() 492 wx.EndBusyCursor()
504 else: 493 else: self.show_error("Server is already running.", "Error Starting Server")
505 self.show_error("Server is already running.", "Error Starting Server")
506 494
507 def OnStop(self, event = None): 495 def OnStop(self, event = None):
508 """ Stop server. """ 496 """ Stop server. """
509 if self.STATUS == SERVER_RUNNING: 497 if self.STATUS == SERVER_RUNNING:
510 self.OnUnregister() 498 self.OnUnregister()