diff orpg/networking/gsclient.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents c54768cffbd4
children d1aff41c031b
line wrap: on
line diff
--- a/orpg/networking/gsclient.py	Tue Aug 18 20:48:36 2009 -0500
+++ b/orpg/networking/gsclient.py	Thu Aug 20 03:00:39 2009 -0500
@@ -30,9 +30,9 @@
 
 from orpg.dirpath import dir_struct
 from orpg.orpg_windows import *
-#from orpg.orpg_xml import *
 import meta_server_lib
 import orpg.tools.orpg_settings
+from orpg.tools.orpg_settings import settings
 import orpg.tools.rgbhex
 from orpg.orpgCore import component
 import traceback
@@ -99,13 +99,10 @@
     def __init__(self,parent):
         wx.Panel.__init__(self, parent, -1)
         self.parent = parent
-        self.log = component.get('log')
-        self.log.log("Enter game_server_panel", ORPG_DEBUG)
         self.password_manager = component.get('password_manager') # passtool --SD 8/03
         self.frame = component.get('frame')
         self.session = component.get('session')
-        self.settings = component.get('settings')
-        self.xml = component.get('xml')
+        self.xml = component.get('xml') #Not used??
         self.serverNameSet = 0
         self.last_motd = ""
         self.buttons = {}
@@ -114,14 +111,11 @@
         self.build_ctrls()
         self.refresh_server_list()
         self.refresh_room_list()
-        self.log.log("Exit game_server_panel", ORPG_DEBUG)
 
 #---------------------------------------------------------
 # [START] Snowdog: Updated Game Server Window 12/02
 #---------------------------------------------------------
     def build_ctrls(self):
-        self.log.log("Enter game_server_panel->build_ctrls(self)", ORPG_DEBUG)
-
         ## Section Sizers (with frame edges and text captions)
         self.box_sizers = {}
         self.box_sizers["server"] = wx.StaticBox(self, -1, "Server")
@@ -237,7 +231,6 @@
         self.cur_room_index = -1
         self.cur_server_index = -1
         self.rmList = {}
-        self.log.log("Exit game_server_panel->build_ctrls(self)", ORPG_DEBUG)
 
 #---------------------------------------------------------
 # [END] Snowdog: Updated Game Server Window 12/02
@@ -249,8 +242,6 @@
     # 5/16/05 -- Snowdog
     #-----------------------------------------------------
     def on_server_dbclick(self, evt=None):
-        self.log.log("Enter game_server_panel->on_server_dbclick(self, evt)", ORPG_DEBUG)
-
         #make sure address is updated just in case list select wasn't done
         try:
             self.on_select(evt)
@@ -265,7 +256,6 @@
                 #address differs, disconnect.
                 self.frame.kill_mplay_session()
         self.do_connect(address)
-        self.log.log("Exit game_server_panel->on_server_dbclick(self, evt)", ORPG_DEBUG)
 
 
     #-----------------------------------------------------
@@ -275,8 +265,6 @@
     #-----------------------------------------------------
 
     def on_room_dbclick(self, evt=None):
-        self.log.log("Enter game_server_panel->on_room_dbclick(self, evt)", ORPG_DEBUG)
-
         #make sure address is updated just in case list select wasn't done
         try:
             self.on_select(evt)
@@ -302,11 +290,9 @@
             else:
                 pwd = ""
             self.session.send_join_group(group_id, pwd)
-        self.log.log("Exit game_server_panel->on_room_dbclick(self, evt)", ORPG_DEBUG)
 
 
     def on_select(self,evt):
-        self.log.log("Enter game_server_panel->on_select(self,evt)", ORPG_DEBUG)
         id = evt.GetId()
         if id == LIST_ROOM:
             self.cur_room_index = evt.m_itemIndex
@@ -317,19 +303,15 @@
             port = self.svrList[self.cur_server_index].port
             self.texts["address"].SetValue(address+":"+str(port))
             self.refresh_room_list()
-        self.log.log("Exit game_server_panel->on_select(self,evt)", ORPG_DEBUG)
 
     def on_text(self,evt):
-        self.log.log("Enter game_server_panel->on_text(self,evt)", ORPG_DEBUG)
         id = evt.GetId()
         if (id == ADDRESS) and (self.cur_server_index >= 0):
             #print "ADDRESS id = ", id, "index = ", self.cur_server_index
             self.cur_server_index = -1
         evt.Skip()
-        self.log.log("Exit game_server_panel->on_text(self,evt)", ORPG_DEBUG)
 
     def add_room(self,data):
-        self.log.log("Enter game_server_panel->add_room(self,data)", ORPG_DEBUG)
         i = self.room_list.GetItemCount()
         if (data[2]=="1") or (data[2]=="True"): pwd="yes"
         else: pwd="no"
@@ -338,21 +320,17 @@
         self.room_list.SetStringItem(i,2,pwd)
         self.room_list.SetItemData(i,int(data[0]))
         self.refresh_room_list()
-        self.log.log("Exit game_server_panel->add_room(self,data)", ORPG_DEBUG)
 
     def del_room(self, data):
-        self.log.log("Enter game_server_panel->del_room(self, data)", ORPG_DEBUG)
         i = self.room_list.FindItemData(-1, int(data[0]))
         self.room_list.DeleteItem(i)
         self.refresh_room_list()
-        self.log.log("Exit game_server_panel->del_room(self, data)", ORPG_DEBUG)
 
 #---------------------------------------------------------
 # [START] Snowdog Password/Room Name altering code 12/02
 #---------------------------------------------------------
 
     def update_room(self,data):
-        self.log.log("Enter game_server_panel->update_room(self,data)", ORPG_DEBUG)
 
         #-------------------------------------------------------
         # Udated 12/02 by Snowdog
@@ -365,7 +343,6 @@
         self.room_list.SetStringItem(i,1,data[3])
         self.room_list.SetStringItem(i,2,pwd)
         self.refresh_room_list()
-        self.log.log("Exit game_server_panel->update_room(self,data)", ORPG_DEBUG)
 
 #---------------------------------------------------------
 # [END] Snowdog Password/Room Name altering code 12/02
@@ -377,12 +354,9 @@
         #self.sizers["room"].Layout()
 
     def set_lobbybutton(self,allow):
-        self.log.log("Enter game_server_panel->set_lobbybutton(self,allow)", ORPG_DEBUG)
         self.buttons[GS_JOINLOBBY].Enable(allow)
-        self.log.log("Exit game_server_panel->set_lobbybutton(self,allow)", ORPG_DEBUG)
 
     def set_connected(self,connected):
-        self.log.log("Enter game_server_panel->set_connected(self,connected)", ORPG_DEBUG)
         self.buttons[GS_CONNECT].Enable(not connected)
         self.buttons[GS_DISCONNECT].Enable(connected)
         self.buttons[GS_JOIN].Enable(connected)
@@ -397,10 +371,8 @@
             #data = self.session.get_my_group()
             self.frame.status.set_connect_status(self.name)
             self.set_cur_room_text("Lobby")
-        self.log.log("Exit game_server_panel->set_connected(self,connected)", ORPG_DEBUG)
 
     def on_button(self,evt):
-        self.log.log("Enter game_server_panel->son_button(self,evt)", ORPG_DEBUG)
         id = evt.GetId()
         if id == GS_CONNECT:
             address = self.texts["address"].GetValue()
@@ -410,18 +382,12 @@
             except:
                 self.name = `address`
             self.do_connect(address)
-        elif id == GS_DISCONNECT:
-            self.frame.kill_mplay_session()
-        elif id == GS_CREATE_ROOM:
-            self.do_create_group()
-        elif id == GS_JOIN:
-            self.do_join_group()
-        elif id == GS_JOINLOBBY:
-            self.do_join_lobby()
-        elif id == GS_SERVER_REFRESH:
-            self.refresh_server_list()
-        elif id == GS_PWD:
-            self.texts["room_pwd"].Enable(evt.Checked())
+        elif id == GS_DISCONNECT: self.frame.kill_mplay_session()
+        elif id == GS_CREATE_ROOM: self.do_create_group()
+        elif id == GS_JOIN: self.do_join_group()
+        elif id == GS_JOINLOBBY: self.do_join_lobby()
+        elif id == GS_SERVER_REFRESH: self.refresh_server_list()
+        elif id == GS_PWD: self.texts["room_pwd"].Enable(evt.Checked())
         elif id == OR_CLOSE:
             dlg = wx.MessageDialog(self,"Quit OpenRPG?","OpenRPG",wx.YES_NO)
             if dlg.ShowModal() == wx.ID_YES:
@@ -430,10 +396,8 @@
                 self.frame.closed_confirmed()
         elif id == GS_CLOSE:
             self.parent.OnMB_GameServerBrowseServers()
-        self.log.log("Exit game_server_panel->son_button(self,evt)", ORPG_DEBUG)
 
     def refresh_room_list(self):
-        self.log.log("Enter game_server_panel->refresh_room_list(self)", ORPG_DEBUG)
         self.room_list.DeleteAllItems()
         address = self.texts["address"].GetValue()
         try:
@@ -458,31 +422,24 @@
             self.colorize_group_list(groups)
             self.room_list.SortItems(roomCmp)
             wx.CallAfter(self.autosizeRooms)
-        self.log.log("Exit game_server_panel->refresh_room_list(self)", ORPG_DEBUG)
 
     def autosizeRooms(self):
-        self.log.log("Enter game_server_panel->autosizeRooms(self)", ORPG_DEBUG)
         self.room_list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
-        #self.room_list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
-        #self.room_list.SetColumnWidth(2, wx.LIST_AUTOSIZE)
         if self.room_list.GetColumnWidth(0) < 70: self.room_list.SetColumnWidth(0, 70)
         if self.room_list.GetColumnWidth(1) < 70: self.room_list.SetColumnWidth(1, 70)
         if self.room_list.GetColumnWidth(2) < 50: self.room_list.SetColumnWidth(2, 50)
-        self.log.log("Exit game_server_panel->autosizeRooms(self)", ORPG_DEBUG)
 
     def refresh_server_list(self):
-        self.log.log("Enter game_server_panel->refresh_server_list(self)", ORPG_DEBUG)
-
         try:
             self.svrList = []
             self.server_list.DeleteAllItems()
             xml_dom = meta_server_lib.get_server_list(["2"]);
             node_list = xml_dom.getElementsByTagName('server')
             hex = orpg.tools.rgbhex.RGBHex()
-            color1 = self.settings.get_setting("RoomColor_Active")
-            color2 = self.settings.get_setting("RoomColor_Locked")
-            color3 = self.settings.get_setting("RoomColor_Empty")
-            color4 = self.settings.get_setting("RoomColor_Lobby")
+            color1 = settings.get_setting("RoomColor_Active")
+            color2 = settings.get_setting("RoomColor_Locked")
+            color3 = settings.get_setting("RoomColor_Empty")
+            color4 = settings.get_setting("RoomColor_Lobby")
 
             if len(node_list):
                 length = len(node_list)
@@ -490,7 +447,9 @@
                 partLength = 1.0/length
                 for n in node_list:
                     if n.hasAttribute('id') and n.hasAttribute('name') and n.hasAttribute('num_users') and n.hasAttribute('address') and n.hasAttribute('port'):
-                        self.svrList.append( server_instance(n.getAttribute('id'),n.getAttribute('name'), n.getAttribute('num_users'), n.getAttribute('address'),n.getAttribute('port')))
+                        self.svrList.append(server_instance(n.getAttribute('id'), n.getAttribute('name'), 
+                                            n.getAttribute('num_users'), n.getAttribute('address'), 
+                                            n.getAttribute('port')))
                         address = n.getAttribute('address') + ':' + n.getAttribute('port')
                         self.rmList[address] = []
                         rooms = n.getElementsByTagName('room')
@@ -553,10 +512,8 @@
         except Exception, e:
             print "Server List not available."
             traceback.print_exc()
-        self.log.log("Exit game_server_panel->refresh_server_list(self)", ORPG_DEBUG)
 
     def failed_connection(self):
-        self.log.log("Enter game_server_panel->failed_connection(self)", ORPG_DEBUG)
         if(self.cur_server_index >= 0):
             id = self.servers[self.cur_server_index].getAttribute('id')
             meta = self.servers[self.cur_server_index].getAttribute('meta')
@@ -566,10 +523,8 @@
             #  was removed.  If it was, refresh the display
             if(meta_server_lib.post_failed_connection(id,meta=meta,address=address,port=port)):
                 self.refresh_server_list()
-        self.log.log("Exit game_server_panel->failed_connection(self)", ORPG_DEBUG)
 
     def do_connect(self, address):
-        self.log.log("Enter game_server_panel->do_connect(self, address)", ORPG_DEBUG)
         chat = component.get('chat')
         chat.InfoPost("Locating server at " + address + "...")
         if self.session.connect(address):
@@ -577,17 +532,13 @@
         else:
             chat.SystemPost("Failed to connect to game server...")
             self.failed_connection()
-        self.log.log("Exit game_server_panel->do_connect(self, address)", ORPG_DEBUG)
 
     def do_join_lobby(self):
-        self.log.log("Enter game_server_panel->do_join_lobby(self)", ORPG_DEBUG)
         self.cur_room_index = 0
         self.session.send_join_group("0","")
         self.set_lobbybutton(0);
-        self.log.log("Exit game_server_panel->do_join_lobby(self)", ORPG_DEBUG)
 
     def do_join_group(self):
-        self.log.log("Enter game_server_panel->do_join_group(self)", ORPG_DEBUG)
         if self.cur_room_index >= 0:
             if self.cur_room_index != 0:
                 self.set_lobbybutton(1);
@@ -606,10 +557,8 @@
                 pwd = ""
             if pwd != None: #pwd==None means the user clicked "Cancel"
                 self.session.send_join_group(group_id,pwd)
-        self.log.log("Exit game_server_panel->do_join_group(self)", ORPG_DEBUG)
 
     def do_create_group(self):
-        self.log.log("Enter game_server_panel->do_create_group(self)", ORPG_DEBUG)
         name = self.texts["room_name"].GetValue()
         boot_pwd = self.texts["room_boot_pwd"].GetValue()
         minversion = self.texts["room_min_version"].GetValue()
@@ -654,7 +603,6 @@
             self.session.send( msg )
             self.session.send_create_group(name,pwd,boot_pwd,minversion)
             self.set_lobbybutton(1); #enable the Lobby quickbutton
-        self.log.log("Exit game_server_panel->do_create_group(self)", ORPG_DEBUG)
 
 
 #---------------------------------------------------------
@@ -676,39 +624,31 @@
 
 
     def colorize_group_list(self, groups):
-        self.log.log("Enter game_server_panel->colorize_group_list(self, groups)", ORPG_DEBUG)
-
         try:
             hex = orpg.tools.rgbhex.RGBHex()
-#            activ = self.settings.get_setting("RoomColor_Active")
-#            lockt = self.settings.get_setting("RoomColor_Locked")
-#            empty = self.settings.get_setting("RoomColor_Empty")
-#            lobby = self.settings.get_setting("RoomColor_Lobby")
-#renamed colors - TaS sirebral
 
             for gr in groups:
                 item_list_location = self.room_list.FindItemData(-1,int(gr[0]))
                 if item_list_location != -1:
                     item = self.room_list.GetItem(item_list_location)
                     if gr[0] == "0":
-#                        active_state = lobby
-			r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Lobby"))
+
+			r,g,b = hex.rgb_tuple(settings.get_setting("RoomColor_Lobby"))
                     elif gr[3] <> "0":
-#                        active_state = activ
+
                         if gr[2] == "True" or gr[2] == "1":
-#                           active_state = lockt
-			   r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Locked"))
+
+			   r,g,b = hex.rgb_tuple(settings.get_setting("RoomColor_Locked"))
 			else:
-#			   active_state = activ
-			   r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Active"))
+
+			   r,g,b = hex.rgb_tuple(settings.get_setting("RoomColor_Active"))
                     else:
-#                        active_state = empty
-			r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Empty"))
+
+			r,g,b = hex.rgb_tuple(settings.get_setting("RoomColor_Empty"))
                         
-#                    r,g,b = hex.rgb_tuple(active_state)
+
 		    color = wx.Colour(red=r,green=g,blue=b)
                     item.SetTextColour(color)
                     self.room_list.SetItem(item)
         except:
             traceback.print_exc()
-        self.log.log("Exit game_server_panel->colorize_group_list(self, groups)", ORPG_DEBUG)