comparison orpg/networking/gsclient.py @ 102:905fa5b06d53 alpha

Traipse Alpha 'OpenRPG' {091006-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: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images!
author sirebral
date Tue, 06 Oct 2009 05:42:50 -0500
parents 65c1604e7949
children 15e32ec131cb
comparison
equal deleted inserted replaced
99:a647e0e8f520 102:905fa5b06d53
34 import orpg.tools.orpg_settings 34 import orpg.tools.orpg_settings
35 from orpg.tools.orpg_settings import settings 35 from orpg.tools.orpg_settings import settings
36 import orpg.tools.rgbhex 36 import orpg.tools.rgbhex
37 from orpg.orpgCore import component 37 from orpg.orpgCore import component
38 import traceback 38 import traceback
39 from orpg.tools.validate import validate
40 from xml.etree.ElementTree import ElementTree, Element
41 from xml.etree.ElementTree import fromstring, tostring
39 42
40 gs_host = 1 43 gs_host = 1
41 gs_join = 2 44 gs_join = 2
42 # constants 45 # constants
43
44 LIST_SERVER = wx.NewId()
45 LIST_ROOM = wx.NewId()
46 ADDRESS = wx.NewId()
47 GS_CONNECT = wx.NewId()
48 GS_DISCONNECT = wx.NewId()
49 GS_SERVER_REFRESH = wx.NewId()
50 GS_JOIN = wx.NewId()
51 GS_JOINLOBBY = wx.NewId()
52 GS_CREATE_ROOM = wx.NewId()
53 GS_PWD = wx.NewId()
54 GS_CLOSE = wx.NewId()
55 OR_CLOSE = wx.NewId()
56 46
57 class server_instance: 47 class server_instance:
58 def __init__(self, id, name="[Unknown]", users="0", address="127.0.0.1", port="9557"): 48 def __init__(self, id, name="[Unknown]", users="0", address="127.0.0.1", port="9557"):
59 self.id = id 49 self.id = id
60 self.name = name 50 self.name = name
62 self.addy = address 52 self.addy = address
63 self.port = port 53 self.port = port
64 54
65 def server_instance_compare(x,y): 55 def server_instance_compare(x,y):
66 """compares server insances for list sort""" 56 """compares server insances for list sort"""
57 ### Alpha ### makes changes from core.
67 DEV_SERVER = "OpenRPG DEV" 58 DEV_SERVER = "OpenRPG DEV"
68 xuser = 0 59 xname = x.name
69 yuser = 0 60 xuser = int(x.user)
70 try: xuser = int(x.user) 61 yname = y.name
71 except: pass 62 yuser = int(y.user)
72 try: yuser = int(y.user) 63
73 except: pass 64 who_name = cmp(yname, xname)
65 who_user = cmp(yuser, xuser)
66
74 if x.name.startswith(DEV_SERVER): 67 if x.name.startswith(DEV_SERVER):
75 if y.name.startswith(DEV_SERVER): 68 if y.name.startswith(DEV_SERVER):
76 if x.name > y.name: return 1 69 if not who_name:
77 elif x.name == y.name: 70 return who_user
78 if xuser < yuser: return 1 71 else:
79 elif xuser > yuser: return -1 72 return who_name
80 else: return 0 73 else:
81 else: return -1 74 return -1
82 else: return -1 75
83 elif y.name.startswith(DEV_SERVER): return 1 76 elif y.name.startswith(DEV_SERVER): return 1
84 elif xuser < yuser: return 1 77 elif not who_user:
85 elif xuser == yuser: 78 return who_name
86 if x.name > y.name: return 1 79 else:
87 elif x.name == y.name: return 0 80 return who_user
88 else: return -1
89 else: return -1
90 81
91 def roomCmp(room1, room2): 82 def roomCmp(room1, room2):
92 if int(room1) > int(room2): 83 if int(room1) > int(room2):
93 return 1 84 return 1
94 elif int(room1) < int(room2): 85 elif int(room1) < int(room2):
97 88
98 class game_server_panel(wx.Panel): 89 class game_server_panel(wx.Panel):
99 def __init__(self,parent): 90 def __init__(self,parent):
100 wx.Panel.__init__(self, parent, -1) 91 wx.Panel.__init__(self, parent, -1)
101 self.parent = parent 92 self.parent = parent
102 self.password_manager = component.get('password_manager') # passtool --SD 8/03 93 self.password_manager = component.get('password_manager')
103 self.frame = component.get('frame') 94 self.frame = component.get('frame')
104 self.session = component.get('session') 95 self.session = component.get('session')
105 self.xml = component.get('xml') #Not used?? 96 #self.xml = component.get('xml') #Not used??
106 self.serverNameSet = 0 97 self.serverNameSet = 0
107 self.last_motd = "" 98 self.last_motd = ""
108 self.buttons = {} 99 self.buttons = {}
109 self.texts = {} 100 self.texts = {}
110 self.svrList = [] 101 self.svrList = []
111 self.build_ctrls() 102 self.build_ctrls()
112 self.refresh_server_list() 103 self.refresh_server_list()
113 self.refresh_room_list() 104 self.refresh_room_list()
114 105 self.build_bookmarks() ## Not yet implemented
115 #--------------------------------------------------------- 106 #self.refresh_server_list()
116 # [START] Snowdog: Updated Game Server Window 12/02 107 #self.refresh_room_list()
117 #--------------------------------------------------------- 108
118 def build_ctrls(self): 109 def build_ctrls(self):
119 ## Section Sizers (with frame edges and text captions) 110 ## Section Sizers (with frame edges and text captions)
120 self.box_sizers = {} 111 self.box_sizers = {}
121 self.box_sizers["server"] = wx.StaticBox(self, -1, "Server") 112 self.box_sizers["server"] = wx.StaticBox(self, -1, "Server")
122 self.box_sizers["window"] = wx.StaticBox(self, -1, "Exit" ) 113 self.box_sizers["window"] = wx.StaticBox(self, -1, "Exit" )
131 self.sizers["close"] = wx.StaticBoxSizer(self.box_sizers["window"], wx.HORIZONTAL) 122 self.sizers["close"] = wx.StaticBoxSizer(self.box_sizers["window"], wx.HORIZONTAL)
132 self.sizers["c_room"] = wx.StaticBoxSizer(self.box_sizers["c_room"], wx.VERTICAL) 123 self.sizers["c_room"] = wx.StaticBoxSizer(self.box_sizers["c_room"], wx.VERTICAL)
133 124
134 #Build Server Sizer 125 #Build Server Sizer
135 adder = wx.StaticText(self, -1, "Address:") 126 adder = wx.StaticText(self, -1, "Address:")
136 self.texts["address"] = wx.TextCtrl(self, ADDRESS) 127 self.texts["address"] = wx.TextCtrl(self, wx.ID_ANY)
137 servers = wx.StaticText(self, -1, "Servers:") 128 servers = wx.StaticText(self, -1, "Servers:")
138 self.server_list = wx.ListCtrl(self, LIST_SERVER, style=wx.LC_REPORT | wx.SUNKEN_BORDER ) 129 self.server_list = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.SUNKEN_BORDER )
139 self.server_list.InsertColumn(0, "Players", wx.LIST_FORMAT_LEFT, 0) 130 self.server_list.InsertColumn(0, '', wx.LIST_FORMAT_LEFT, 0)
140 self.server_list.InsertColumn(1, "Name", wx.LIST_FORMAT_LEFT, 0) 131 self.server_list.InsertColumn(1, "Players", wx.LIST_FORMAT_LEFT, 0)
141 self.buttons[GS_CONNECT] = wx.Button(self, GS_CONNECT, "Connect") 132 self.server_list.InsertColumn(2, "Name", wx.LIST_FORMAT_LEFT, 0)
142 self.buttons[GS_SERVER_REFRESH] = wx.Button(self, GS_SERVER_REFRESH, "Refresh") 133 self.buttons['gs_connect'] = wx.Button(self, wx.ID_ANY, "Connect")
143 self.buttons[GS_DISCONNECT] = wx.Button(self, GS_DISCONNECT, "Disconnect") 134 self.buttons['gs_refresh'] = wx.Button(self, wx.ID_ANY, "Refresh")
135 self.buttons['gs_disconnect'] = wx.Button(self, wx.ID_ANY, "Disconnect")
144 self.sizers["svrbtns"] = wx.BoxSizer(wx.HORIZONTAL) 136 self.sizers["svrbtns"] = wx.BoxSizer(wx.HORIZONTAL)
145 self.sizers["svrbtns"].Add(self.buttons[GS_CONNECT], 0, wx.EXPAND) 137 self.sizers["svrbtns"].Add(self.buttons['gs_connect'], 0, wx.EXPAND)
146 self.sizers["svrbtns"].Add(self.buttons[GS_SERVER_REFRESH], 0, wx.EXPAND) 138 self.sizers["svrbtns"].Add(self.buttons['gs_refresh'], 0, wx.EXPAND)
147 self.sizers["svrbtns"].Add(self.buttons[GS_DISCONNECT], 0, wx.EXPAND) 139 self.sizers["svrbtns"].Add(self.buttons['gs_disconnect'], 0, wx.EXPAND)
148 self.sizers["server"].Add(adder, 0, wx.EXPAND) 140 self.sizers["server"].Add(adder, 0, wx.EXPAND)
149 self.sizers["server"].Add(self.texts["address"], 0, wx.EXPAND) 141 self.sizers["server"].Add(self.texts["address"], 0, wx.EXPAND)
150 self.sizers["server"].Add(servers, 0, wx.EXPAND) 142 self.sizers["server"].Add(servers, 0, wx.EXPAND)
151 self.sizers["server"].Add(self.server_list, 1, wx.EXPAND) 143 self.sizers["server"].Add(self.server_list, 1, wx.EXPAND)
152 self.sizers["server"].Add(self.sizers["svrbtns"], 0, wx.EXPAND) 144 self.sizers["server"].Add(self.sizers["svrbtns"], 0, wx.EXPAND)
153 145
154 #Build Rooms Sizer 146 #Build Rooms Sizer
155 self.room_list = wx.ListCtrl(self, LIST_ROOM, style=wx.LC_REPORT | wx.SUNKEN_BORDER) 147 self.room_list = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
156 self.room_list.InsertColumn(0,"Game", wx.LIST_FORMAT_LEFT,-1) 148 self.room_list.InsertColumn(0,"Game", wx.LIST_FORMAT_LEFT,-1)
157 self.room_list.InsertColumn(1,"Players", wx.LIST_FORMAT_LEFT,-1) 149 self.room_list.InsertColumn(1,"Players", wx.LIST_FORMAT_LEFT,-1)
158 self.room_list.InsertColumn(2,"PW", wx.LIST_FORMAT_LEFT,-1) 150 self.room_list.InsertColumn(2,"PW", wx.LIST_FORMAT_LEFT,-1)
159 self.buttons[GS_JOIN] = wx.Button(self, GS_JOIN, "Join Room") 151 self.buttons['gs_join_room'] = wx.Button(self, wx.ID_ANY, "Join Room")
160 self.buttons[GS_JOINLOBBY] = wx.Button(self, GS_JOINLOBBY, "Lobby") 152 self.buttons['gs_join_lobby'] = wx.Button(self, wx.ID_ANY, "Lobby")
161 self.sizers["roombtns"] = wx.BoxSizer(wx.HORIZONTAL) 153 self.sizers["roombtns"] = wx.BoxSizer(wx.HORIZONTAL)
162 self.sizers["roombtns"].Add(self.buttons[GS_JOIN], 0, wx.EXPAND) 154 self.sizers["roombtns"].Add(self.buttons['gs_join_room'], 0, wx.EXPAND)
163 self.sizers["roombtns"].Add(self.buttons[GS_JOINLOBBY], 0, wx.EXPAND) 155 self.sizers["roombtns"].Add(self.buttons['gs_join_lobby'], 0, wx.EXPAND)
164 self.sizers["rooms"].Add(self.room_list, 1, wx.EXPAND) 156 self.sizers["rooms"].Add(self.room_list, 1, wx.EXPAND)
165 self.sizers["rooms"].Add(self.sizers["roombtns"], 0, wx.EXPAND) 157 self.sizers["rooms"].Add(self.sizers["roombtns"], 0, wx.EXPAND)
166 158
167 #Build Close Sizer 159 #Build Close Sizer
168 self.buttons[OR_CLOSE] = wx.Button(self, OR_CLOSE,"Exit OpenRPG") 160 self.buttons['close_orpg'] = wx.Button(self, wx.ID_ANY,"Exit OpenRPG")
169 self.buttons[GS_CLOSE] = wx.Button(self, GS_CLOSE,"Close Window") 161 self.buttons['gs_close'] = wx.Button(self, wx.ID_ANY,"Close Window")
170 self.sizers["close"].Add(self.buttons[OR_CLOSE], 1, wx.ALIGN_CENTER_VERTICAL) 162 self.sizers["close"].Add(self.buttons['close_orpg'], 1, wx.ALIGN_CENTER_VERTICAL)
171 self.sizers["close"].Add(self.buttons[GS_CLOSE], 1, wx.ALIGN_CENTER_VERTICAL) 163 self.sizers["close"].Add(self.buttons['gs_close'], 1, wx.ALIGN_CENTER_VERTICAL)
172 164
173 #Build Create Room Sizer 165 #Build Create Room Sizer
174 rname = wx.StaticText(self,-1, "Room Name:") 166 rname = wx.StaticText(self,-1, "Room Name:")
175 self.texts["room_name"] = wx.TextCtrl(self, -1) 167 self.texts["room_name"] = wx.TextCtrl(self, -1)
176 rpass = wx.StaticText(self,-1, "Password:") 168 rpass = wx.StaticText(self,-1, "Password:")
177 self.buttons[GS_PWD] = wx.CheckBox(self, GS_PWD, "") 169 self.buttons['gs_pwd'] = wx.CheckBox(self, wx.ID_ANY, "")
178 self.texts["room_pwd"] = wx.TextCtrl(self, -1) 170 self.texts["room_pwd"] = wx.TextCtrl(self, -1)
179 self.texts["room_pwd"].Enable(0) 171 self.texts["room_pwd"].Enable(0)
180 pwsizer = wx.BoxSizer(wx.HORIZONTAL) 172 pwsizer = wx.BoxSizer(wx.HORIZONTAL)
181 pwsizer.Add(self.buttons[GS_PWD],0,0) 173 pwsizer.Add(self.buttons['gs_pwd'],0,0)
182 pwsizer.Add(self.texts["room_pwd"], 1, wx.EXPAND) 174 pwsizer.Add(self.texts["room_pwd"], 1, wx.EXPAND)
183 apass = wx.StaticText(self,-1, "Admin Password:") 175 apass = wx.StaticText(self,-1, "Admin Password:")
184 self.texts["room_boot_pwd"] = wx.TextCtrl(self, -1) 176 self.texts["room_boot_pwd"] = wx.TextCtrl(self, -1)
185 minver = wx.StaticText(self,-1, "Minimum Version:") 177 minver = wx.StaticText(self,-1, "Minimum Version:")
186 self.texts["room_min_version"] = wx.TextCtrl(self, -1) 178 self.texts["room_min_version"] = wx.TextCtrl(self, -1)
192 self.sizers["c_room_layout"].Add(apass, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL) 184 self.sizers["c_room_layout"].Add(apass, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
193 self.sizers["c_room_layout"].Add(self.texts["room_boot_pwd"], 0, wx.EXPAND) 185 self.sizers["c_room_layout"].Add(self.texts["room_boot_pwd"], 0, wx.EXPAND)
194 self.sizers["c_room_layout"].Add(minver, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL) 186 self.sizers["c_room_layout"].Add(minver, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL)
195 self.sizers["c_room_layout"].Add(self.texts["room_min_version"], 0, wx.EXPAND) 187 self.sizers["c_room_layout"].Add(self.texts["room_min_version"], 0, wx.EXPAND)
196 self.sizers["c_room_layout"].AddGrowableCol(1) 188 self.sizers["c_room_layout"].AddGrowableCol(1)
197 self.buttons[GS_CREATE_ROOM] = wx.Button(self, GS_CREATE_ROOM, "Create Room") 189 self.buttons['gs_create_room'] = wx.Button(self, wx.ID_ANY, "Create Room")
198 self.sizers["c_room"].Add(self.sizers["c_room_layout"], 1, wx.EXPAND) 190 self.sizers["c_room"].Add(self.sizers["c_room_layout"], 1, wx.EXPAND)
199 self.sizers["c_room"].Add(self.buttons[GS_CREATE_ROOM], 0, wx.EXPAND) 191 self.sizers["c_room"].Add(self.buttons['gs_create_room'], 0, wx.EXPAND)
200 192
201 #Build Main Sizer 193 #Build Main Sizer
202 self.sizers["main"].Add(self.sizers["server"], (0,0), span=(2,1), flag=wx.EXPAND) 194 self.sizers["main"].Add(self.sizers["server"], (0,0), span=(2,1), flag=wx.EXPAND)
203 self.sizers["main"].Add(self.sizers["rooms"], (0,1), flag=wx.EXPAND) 195 self.sizers["main"].Add(self.sizers["rooms"], (0,1), flag=wx.EXPAND)
204 self.sizers["main"].Add(self.sizers["close"], (2,0), flag=wx.EXPAND) 196 self.sizers["main"].Add(self.sizers["close"], (2,0), flag=wx.EXPAND)
209 self.SetSizer(self.sizers["main"]) 201 self.SetSizer(self.sizers["main"])
210 self.SetAutoLayout(True) 202 self.SetAutoLayout(True)
211 self.Fit() 203 self.Fit()
212 204
213 ## Event Handlers 205 ## Event Handlers
214 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_CONNECT) 206 self.Bind(wx.EVT_BUTTON, self.gs_connect, self.buttons['gs_connect'])
215 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_DISCONNECT) 207 self.Bind(wx.EVT_BUTTON, self.gs_disconnect, self.buttons['gs_disconnect'])
216 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_CREATE_ROOM) 208 self.Bind(wx.EVT_BUTTON, self.gs_create_room, self.buttons['gs_create_room'])
217 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_JOIN) 209 self.Bind(wx.EVT_BUTTON, self.gs_join, self.buttons['gs_join_room'])
218 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_JOINLOBBY) 210 self.Bind(wx.EVT_BUTTON, self.gs_join_lobby, self.buttons['gs_join_lobby'])
219 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_SERVER_REFRESH) 211 self.Bind(wx.EVT_BUTTON, self.gs_server_refresh, self.buttons['gs_refresh'])
220 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_CLOSE) 212 self.Bind(wx.EVT_BUTTON, self.gs_close, self.buttons['gs_close'])
221 self.Bind(wx.EVT_BUTTON, self.on_button, id=OR_CLOSE) 213 self.Bind(wx.EVT_BUTTON, self.close_orpg, self.buttons['close_orpg'])
222 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=GS_PWD) 214 self.Bind(wx.EVT_CHECKBOX, self.gs_pwd, self.buttons['gs_pwd'])
223 215
224 # Added double click handlers 5/05 -- Snowdog 216 # Added double click handlers 5/05 -- Snowdog
225 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_server_dbclick, id=LIST_SERVER) 217 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_server_dbclick, self.server_list)
226 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_room_dbclick, id=LIST_ROOM) 218 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_room_dbclick, self.room_list)
227 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_select, id=LIST_ROOM) 219 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_room_select, self.room_list)
228 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_select, id=LIST_SERVER) 220 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_server_select, self.server_list)
229 self.texts['address'].Bind(wx.EVT_SET_FOCUS, self.on_text) 221 self.texts['address'].Bind(wx.EVT_SET_FOCUS, self.on_text)
230 self.set_connected(self.session.is_connected()) 222 self.set_connected(self.session.is_connected())
231 self.cur_room_index = -1 223 self.cur_room_index = -1
232 self.cur_server_index = -1 224 self.cur_server_index = -1
233 self.rmList = {} 225 self.rmList = {}
234 226
235 #--------------------------------------------------------- 227 # Create Book Mark Image List
236 # [END] Snowdog: Updated Game Server Window 12/02 228 self.server_list.Bind(wx.EVT_LEFT_DOWN, self.on_hit)
237 #--------------------------------------------------------- 229 self._imageList = wx.ImageList( 16, 16, False )
238 230 img = wx.Image(dir_struct["icon"]+"add.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
239 #----------------------------------------------------- 231 self._imageList.Add( img )
240 # on_server_dbclick() 232 img = wx.Image(dir_struct["icon"]+"star.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
241 # support for double click selection of server. 233 self._imageList.Add( img )
242 # 5/16/05 -- Snowdog 234 self.server_list.SetImageList( self._imageList, wx.IMAGE_LIST_SMALL )
243 #----------------------------------------------------- 235
236 def build_bookmarks(self):
237 gsm = self.frame.mainmenu.GetMenu(
238 self.frame.mainmenu.FindMenu('Game Server'))
239 self.bookmarks_menu = wx.Menu()
240 validate.config_file('server_bookmarks.xml',
241 'default_server_bookmarks.xml')
242 self.bookmarks = ElementTree()
243 self.bookmarks.parse(dir_struct['user'] + 'server_bookmarks.xml')
244 x = 0
245 for server in self.bookmarks.findall('server'):
246 for svr in self.svrList:
247 name = svr.name
248 if server.get('name') == name: self.server_list.SetItemImage(x, 1)
249 x += 1
250 #self.server_list.SetItemImage( self.server_list.FindItem(0, server.get('name')), 1 )
251 item = wx.MenuItem(self.bookmarks_menu, wx.ID_ANY,
252 server.get('name'), server.get('name'))
253 open_rpg.get_component('frame').Bind(wx.EVT_MENU,
254 self.on_bookmarks_menu, item)
255 self.bookmarks_menu.AppendItem(item)
256 gsm.AppendSubMenu(self.bookmarks_menu, "Bookmarks")
257
258 def on_bookmarks_menu(self, evt):
259 id = evt.GetId()
260 menu = self.bookmarks_menu.FindItemById(id)
261 for server in self.bookmarks.findall('server'):
262 if server.name == menu.GetLabel():
263 address = server.addy
264 self.cur_server_index = 999
265 self.name = server.name
266 if self.session.is_connected():
267 if self.session.host_server == address : return
268 else: self.frame.kill_mplay_session()
269 self.do_connect(address)
270 break
271
272 def bookmark(self, item, flag):
273 name = self.svrList[item].name
274 address = self.svrList[item].addy
275 port = self.svrList[item].port
276 self.server_list.SetItemImage(item, 1)
277
278 for server in self.bookmarks.findall('server'):
279 if server.get('name') == name:
280 self.bookmarks_menu.Remove(
281 self.bookmarks_menu.FindItem(server.get('name')))
282 self.bookmarks.getroot().remove(server)
283 self.server_list.SetItemImage(item, 0)
284 break
285 else:
286 server = Element('server')
287 server.set('name', name)
288 server.set('address', address + ':' + port)
289 self.bookmarks.getroot().append(server)
290 item = wx.MenuItem(self.bookmarks_menu, wx.ID_ANY, name, name)
291 open_rpg.get_component('frame').Bind(wx.EVT_MENU,
292 self.on_bookmarks_menu, item)
293 self.bookmarks_menu.AppendItem(item)
294
295 self.save_bookmarks()
296
297 def save_bookmarks(self):
298 with open(dir_struct['user'] + 'server_bookmarks.xml', 'w') as f:
299 self.bookmarks.write(f)
300
244 def on_server_dbclick(self, evt=None): 301 def on_server_dbclick(self, evt=None):
245 #make sure address is updated just in case list select wasn't done 302 #make sure address is updated just in case list select wasn't done
246 try: 303 try:
247 self.on_select(evt) 304 self.on_select(evt)
248 except: 305 except:
255 else: 312 else:
256 #address differs, disconnect. 313 #address differs, disconnect.
257 self.frame.kill_mplay_session() 314 self.frame.kill_mplay_session()
258 self.do_connect(address) 315 self.do_connect(address)
259 316
260
261 #-----------------------------------------------------
262 # on_room_dbclick()
263 # support for double click selection of server.
264 # 5/16/05 -- Snowdog
265 #-----------------------------------------------------
266
267 def on_room_dbclick(self, evt=None): 317 def on_room_dbclick(self, evt=None):
268 #make sure address is updated just in case list select wasn't done 318 #make sure address is updated just in case list select wasn't done
269 try: 319 try:
270 self.on_select(evt) 320 self.on_select(evt)
271 except: 321 except:
289 pwd = self.password_manager.GetPassword("room", group_id) 339 pwd = self.password_manager.GetPassword("room", group_id)
290 else: 340 else:
291 pwd = "" 341 pwd = ""
292 self.session.send_join_group(group_id, pwd) 342 self.session.send_join_group(group_id, pwd)
293 343
294 344 def on_room_select(self,evt):
295 def on_select(self,evt): 345 self.cur_room_index = evt.m_itemIndex
296 id = evt.GetId() 346
297 if id == LIST_ROOM: 347 def on_hit(self, evt):
298 self.cur_room_index = evt.m_itemIndex 348 pos = wx.Point( evt.GetX(), evt.GetY() )
299 elif id==LIST_SERVER: 349 (item, flag) = self.server_list.HitTest( pos )
300 self.cur_server_index = evt.m_itemIndex 350 ## Item == list[server], flag == (32 = 0 colum, 128 = else) ##
301 self.name = self.svrList[self.cur_server_index].name 351 if flag == 32: self.bookmark(item, flag)
302 address = self.svrList[self.cur_server_index].addy 352 evt.Skip()
303 port = self.svrList[self.cur_server_index].port 353
304 self.texts["address"].SetValue(address+":"+str(port)) 354 def on_server_select(self,evt):
305 self.refresh_room_list() 355 self.cur_server_index = evt.m_itemIndex
356 self.name = self.svrList[self.cur_server_index].name
357 address = self.svrList[self.cur_server_index].addy
358 port = self.svrList[self.cur_server_index].port
359 self.texts["address"].SetValue(address + ":" + str(port))
360 self.refresh_room_list()
306 361
307 def on_text(self,evt): 362 def on_text(self,evt):
308 id = evt.GetId() 363 id = evt.GetId()
309 if (id == ADDRESS) and (self.cur_server_index >= 0): 364 if (id == ADDRESS) and (self.cur_server_index >= 0):
310 #print "ADDRESS id = ", id, "index = ", self.cur_server_index 365 #print "ADDRESS id = ", id, "index = ", self.cur_server_index
324 def del_room(self, data): 379 def del_room(self, data):
325 i = self.room_list.FindItemData(-1, int(data[0])) 380 i = self.room_list.FindItemData(-1, int(data[0]))
326 self.room_list.DeleteItem(i) 381 self.room_list.DeleteItem(i)
327 self.refresh_room_list() 382 self.refresh_room_list()
328 383
329 #---------------------------------------------------------
330 # [START] Snowdog Password/Room Name altering code 12/02
331 #---------------------------------------------------------
332
333 def update_room(self,data): 384 def update_room(self,data):
334
335 #-------------------------------------------------------
336 # Udated 12/02 by Snowdog
337 # allows refresh of all room data not just player counts
338 #-------------------------------------------------------
339 i = self.room_list.FindItemData(-1,int(data[0])) 385 i = self.room_list.FindItemData(-1,int(data[0]))
340 if data[2]=="1" : pwd="yes" 386 if data[2]=="1" : pwd="yes"
341 else: pwd="no" 387 else: pwd="no"
342 self.room_list.SetStringItem(i,0,data[1]) 388 self.room_list.SetStringItem(i,0,data[1])
343 self.room_list.SetStringItem(i,1,data[3]) 389 self.room_list.SetStringItem(i,1,data[3])
344 self.room_list.SetStringItem(i,2,pwd) 390 self.room_list.SetStringItem(i,2,pwd)
345 self.refresh_room_list() 391 self.refresh_room_list()
346 392
347 #---------------------------------------------------------
348 # [END] Snowdog Password/Room Name altering code 12/02
349 #---------------------------------------------------------
350
351 def set_cur_room_text(self,name): 393 def set_cur_room_text(self,name):
352 pass 394 pass
353 #self.texts["cur_room"].SetLabel(name) 395 #self.texts["cur_room"].SetLabel(name)
354 #self.sizers["room"].Layout() 396 #self.sizers["room"].Layout()
355 397
356 def set_lobbybutton(self,allow): 398 def set_lobbybutton(self,allow):
357 self.buttons[GS_JOINLOBBY].Enable(allow) 399 self.buttons['gs_join_lobby'].Enable(allow)
358 400
359 def set_connected(self,connected): 401 def set_connected(self,connected):
360 self.buttons[GS_CONNECT].Enable(not connected) 402 self.buttons['gs_connect'].Enable(not connected)
361 self.buttons[GS_DISCONNECT].Enable(connected) 403 self.buttons['gs_disconnect'].Enable(connected)
362 self.buttons[GS_JOIN].Enable(connected) 404 self.buttons['gs_join_room'].Enable(connected)
363 self.buttons[GS_CREATE_ROOM].Enable(connected) 405 self.buttons['gs_create_room'].Enable(connected)
364 if not connected: 406 if not connected:
365 self.buttons[GS_JOINLOBBY].Enable(connected) 407 self.buttons['gs_join_lobby'].Enable(connected)
366 self.room_list.DeleteAllItems() 408 self.room_list.DeleteAllItems()
367 self.set_cur_room_text("Not Connected!") 409 self.set_cur_room_text("Not Connected!")
368 self.cur_room_index = -1 410 self.cur_room_index = -1
369 self.frame.status.set_connect_status("Not Connected") 411 self.frame.status.set_connect_status("Not Connected")
370 else: 412 else:
371 #data = self.session.get_my_group() 413 #data = self.session.get_my_group()
372 self.frame.status.set_connect_status(self.name) 414 self.frame.status.set_connect_status(self.name)
373 self.set_cur_room_text("Lobby") 415 self.set_cur_room_text("Lobby")
374 416
375 def on_button(self,evt): 417 def gs_connect(self, evt):
376 id = evt.GetId() 418 address = self.texts['address'].GetValue()
377 if id == GS_CONNECT: 419 try:
378 address = self.texts["address"].GetValue() 420 dummy = self.name
379 ### check to see if this is a manual entry vs. list entry. 421 except:
380 try: 422 self.name = `address`
381 dummy = self.name 423 self.do_connect(address)
382 except: 424
383 self.name = `address` 425 def gs_disconnect(self, evt):
384 self.do_connect(address) 426 self.frame.kill_mplay_session()
385 elif id == GS_DISCONNECT: self.frame.kill_mplay_session() 427
386 elif id == GS_CREATE_ROOM: self.do_create_group() 428 def gs_create_room(self, evt):
387 elif id == GS_JOIN: self.do_join_group() 429 self.do_create_group()
388 elif id == GS_JOINLOBBY: self.do_join_lobby() 430
389 elif id == GS_SERVER_REFRESH: self.refresh_server_list() 431 def gs_join(self, evt):
390 elif id == GS_PWD: self.texts["room_pwd"].Enable(evt.Checked()) 432 print 'here'
391 elif id == OR_CLOSE: 433 self.do_join_group()
392 dlg = wx.MessageDialog(self,"Quit OpenRPG?","OpenRPG",wx.YES_NO) 434
393 if dlg.ShowModal() == wx.ID_YES: 435 def gs_join_lobby(self, evt):
394 dlg.Destroy() 436 self.do_join_lobby()
395 self.frame.kill_mplay_session() 437
396 self.frame.closed_confirmed() 438 def gs_server_refresh(self, evt):
397 elif id == GS_CLOSE: 439 self.refresh_server_list()
398 self.parent.OnMB_GameServerBrowseServers() 440
441 def gs_pwd(self, evt):
442 self.texts['room_pwd'].Enable(evt.Checked())
443
444 def close_orpg(self, evt):
445 dlg = wx.MessageDialog(self, 'Quit OpenRPG?', "OpenRPG", wx.YES_NO)
446 if dlg.ShowModal() == wx.ID_YES:
447 dlg.Destroy()
448 self.frame.kill_mplay_session()
449 self.frame.closed_confirmed()
450
451 def gs_close(self, evt):
452 self.parent.OnMB_GameServerBrowseServers()
453
399 454
400 def refresh_room_list(self): 455 def refresh_room_list(self):
401 self.room_list.DeleteAllItems() 456 self.room_list.DeleteAllItems()
402 address = self.texts["address"].GetValue() 457 address = self.texts["address"].GetValue()
403 try: 458 try:
464 519
465 for n in self.svrList: 520 for n in self.svrList:
466 i = self.server_list.GetItemCount() 521 i = self.server_list.GetItemCount()
467 name = n.name 522 name = n.name
468 players = n.user 523 players = n.user
469 self.server_list.InsertStringItem(i,players) 524 self.server_list.InsertImageStringItem(i, '', 0)
470 self.server_list.SetStringItem(i,1,name) 525 self.server_list.SetStringItem(i,1,players)
526 self.server_list.SetStringItem(i,2,name)
471 r,g,b = hex.rgb_tuple(color1) 527 r,g,b = hex.rgb_tuple(color1)
472 svrcolor = wx.Colour(red=r,green=g,blue=b) 528 svrcolor = wx.Colour(red=r,green=g,blue=b)
473 529
474 if players == "0": 530 if players == "0":
475 r,g,b = hex.rgb_tuple(color3) 531 r,g,b = hex.rgb_tuple(color3)
486 self.servers = node_list 542 self.servers = node_list
487 543
488 # No server is currently selected!!! Versus the broken and random 0! 544 # No server is currently selected!!! Versus the broken and random 0!
489 self.cur_server_index = -1 545 self.cur_server_index = -1
490 self.server_list.SetColumnWidth(0, wx.LIST_AUTOSIZE) 546 self.server_list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
491 if self.server_list.GetColumnWidth(0) < 70: self.server_list.SetColumnWidth(0, 70)
492 self.server_list.SetColumnWidth(1, wx.LIST_AUTOSIZE) 547 self.server_list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
548 if self.server_list.GetColumnWidth(1) < 70: self.server_list.SetColumnWidth(1, 70)
549 self.server_list.SetColumnWidth(2, wx.LIST_AUTOSIZE)
493 550
494 if self.serverNameSet == 0: 551 if self.serverNameSet == 0:
495 # Pointless to constantly set the address field to random
496 # server. This way, at least, if someone has their own local
497 # server it can now easily be connected with. Nor do we want
498 # to reset this every time as it would wipe any previously
499 # entered data or even the previously selected server data!
500 # Localhost should probably be used but some systems are ultra/lame
501 # broken about localhost use.
502 self.texts["address"].SetValue("127.0.0.1:6774") 552 self.texts["address"].SetValue("127.0.0.1:6774")
503 self.serverNameSet = 1 553 self.serverNameSet = 1
504 else: 554 else:
505 pass 555 pass
506 556
510 except: 560 except:
511 pass 561 pass
512 except Exception, e: 562 except Exception, e:
513 print "Server List not available." 563 print "Server List not available."
514 traceback.print_exc() 564 traceback.print_exc()
515 565 x = 0
566 try: ### Alpha ###
567 for server in self.bookmarks.findall('server'):
568 for svr in self.svrList:
569 name = svr.name
570 if server.get('name') == name: self.server_list.SetItemImage(x, 1)
571 x += 1
572 except: pass
573
516 def failed_connection(self): 574 def failed_connection(self):
517 if(self.cur_server_index >= 0): 575 if(self.cur_server_index >= 0):
518 id = self.servers[self.cur_server_index].getAttribute('id') 576 id = self.servers[self.cur_server_index].getAttribute('id')
519 meta = self.servers[self.cur_server_index].getAttribute('meta') 577 meta = self.servers[self.cur_server_index].getAttribute('meta')
520 address = self.servers[self.cur_server_index].getAttribute('address') 578 address = self.servers[self.cur_server_index].getAttribute('address')
590 if loc > -1: 648 if loc > -1:
591 b = name[:loc] 649 b = name[:loc]
592 e = name[loc+1:] 650 e = name[loc+1:]
593 name = b + "&#39;" + e 651 name = b + "&#39;" + e
594 oldloc = loc+1 652 oldloc = loc+1
595 if self.buttons[GS_PWD].GetValue(): 653 if self.buttons['gs_pwd'].GetValue():
596 pwd = self.texts["room_pwd"].GetValue() 654 pwd = self.texts["room_pwd"].GetValue()
597 else: 655 else:
598 pwd = "" 656 pwd = ""
599 if name == "": 657 if name == "":
600 wx.MessageBox("Invalid Name","Error"); 658 wx.MessageBox("Invalid Name","Error");