Mercurial > traipse_dev
comparison orpg/networking/gsclient.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | f3d8101211c4 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: gsclient.py | |
21 # Author: Chris Davis | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: gsclient.py,v 1.53 2007/10/25 21:49:34 digitalxero Exp $ | |
25 # | |
26 # Description: The file contains code for the game server browser | |
27 # | |
28 | |
29 __version__ = "$Id: gsclient.py,v 1.53 2007/10/25 21:49:34 digitalxero Exp $" | |
30 | |
31 import orpg.dirpath | |
32 from orpg.orpg_windows import * | |
33 from orpg.orpg_xml import * | |
34 import meta_server_lib | |
35 import orpg.tools.orpg_settings | |
36 import orpg.tools.rgbhex | |
37 from orpg.orpgCore import open_rpg | |
38 import traceback | |
39 | |
40 gs_host = 1 | |
41 gs_join = 2 | |
42 # 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 | |
57 class server_instance: | |
58 def __init__(self, id, name="[Unknown]", users="0", address="127.0.0.1", port="9557"): | |
59 self.id = id | |
60 self.name = name | |
61 self.user = users | |
62 self.addy = address | |
63 self.port = port | |
64 | |
65 def server_instance_compare(x,y): | |
66 """compares server insances for list sort""" | |
67 DEV_SERVER = "OpenRPG DEV" | |
68 xuser = 0 | |
69 yuser = 0 | |
70 try: xuser = int(x.user) | |
71 except: pass | |
72 try: yuser = int(y.user) | |
73 except: pass | |
74 if x.name.startswith(DEV_SERVER): | |
75 if y.name.startswith(DEV_SERVER): | |
76 if x.name > y.name: return 1 | |
77 elif x.name == y.name: | |
78 if xuser < yuser: return 1 | |
79 elif xuser > yuser: return -1 | |
80 else: return 0 | |
81 else: return -1 | |
82 else: return -1 | |
83 elif y.name.startswith(DEV_SERVER): return 1 | |
84 elif xuser < yuser: return 1 | |
85 elif xuser == yuser: | |
86 if x.name > y.name: return 1 | |
87 elif x.name == y.name: return 0 | |
88 else: return -1 | |
89 else: return -1 | |
90 | |
91 def roomCmp(room1, room2): | |
92 if int(room1) > int(room2): | |
93 return 1 | |
94 elif int(room1) < int(room2): | |
95 return -1 | |
96 return 0 | |
97 | |
98 class game_server_panel(wx.Panel): | |
99 def __init__(self,parent): | |
100 wx.Panel.__init__(self, parent, -1) | |
101 self.parent = parent | |
102 self.log = open_rpg.get_component('log') | |
103 self.log.log("Enter game_server_panel", ORPG_DEBUG) | |
104 self.password_manager = open_rpg.get_component('password_manager') # passtool --SD 8/03 | |
105 self.frame = open_rpg.get_component('frame') | |
106 self.session = open_rpg.get_component('session') | |
107 self.settings = open_rpg.get_component('settings') | |
108 self.xml = open_rpg.get_component('xml') | |
109 self.serverNameSet = 0 | |
110 self.last_motd = "" | |
111 self.buttons = {} | |
112 self.texts = {} | |
113 self.svrList = [] | |
114 self.build_ctrls() | |
115 self.refresh_server_list() | |
116 self.refresh_room_list() | |
117 self.log.log("Exit game_server_panel", ORPG_DEBUG) | |
118 | |
119 #--------------------------------------------------------- | |
120 # [START] Snowdog: Updated Game Server Window 12/02 | |
121 #--------------------------------------------------------- | |
122 def build_ctrls(self): | |
123 self.log.log("Enter game_server_panel->build_ctrls(self)", ORPG_DEBUG) | |
124 | |
125 ## Section Sizers (with frame edges and text captions) | |
126 self.box_sizers = {} | |
127 self.box_sizers["server"] = wx.StaticBox(self, -1, "Server") | |
128 self.box_sizers["window"] = wx.StaticBox(self, -1, "Exit" ) | |
129 self.box_sizers["room"] = wx.StaticBox(self, -1, "Rooms") | |
130 self.box_sizers["c_room"] = wx.StaticBox(self, -1, "Create Room") | |
131 | |
132 ## Layout Sizers | |
133 self.sizers = {} | |
134 self.sizers["main"] = wx.GridBagSizer(hgap=1, vgap=1) | |
135 self.sizers["server"] = wx.StaticBoxSizer(self.box_sizers["server"], wx.VERTICAL) | |
136 self.sizers["rooms"] = wx.StaticBoxSizer(self.box_sizers["room"], wx.VERTICAL) | |
137 self.sizers["close"] = wx.StaticBoxSizer(self.box_sizers["window"], wx.HORIZONTAL) | |
138 self.sizers["c_room"] = wx.StaticBoxSizer(self.box_sizers["c_room"], wx.VERTICAL) | |
139 | |
140 #Build Server Sizer | |
141 adder = wx.StaticText(self, -1, "Address:") | |
142 self.texts["address"] = wx.TextCtrl(self, ADDRESS) | |
143 servers = wx.StaticText(self, -1, "Servers:") | |
144 self.server_list = wx.ListCtrl(self, LIST_SERVER, style=wx.LC_REPORT | wx.SUNKEN_BORDER ) | |
145 self.server_list.InsertColumn(0, "Players", wx.LIST_FORMAT_LEFT, 0) | |
146 self.server_list.InsertColumn(1, "Name", wx.LIST_FORMAT_LEFT, 0) | |
147 self.buttons[GS_CONNECT] = wx.Button(self, GS_CONNECT, "Connect") | |
148 self.buttons[GS_SERVER_REFRESH] = wx.Button(self, GS_SERVER_REFRESH, "Refresh") | |
149 self.buttons[GS_DISCONNECT] = wx.Button(self, GS_DISCONNECT, "Disconnect") | |
150 self.sizers["svrbtns"] = wx.BoxSizer(wx.HORIZONTAL) | |
151 self.sizers["svrbtns"].Add(self.buttons[GS_CONNECT], 0, wx.EXPAND) | |
152 self.sizers["svrbtns"].Add(self.buttons[GS_SERVER_REFRESH], 0, wx.EXPAND) | |
153 self.sizers["svrbtns"].Add(self.buttons[GS_DISCONNECT], 0, wx.EXPAND) | |
154 self.sizers["server"].Add(adder, 0, wx.EXPAND) | |
155 self.sizers["server"].Add(self.texts["address"], 0, wx.EXPAND) | |
156 self.sizers["server"].Add(servers, 0, wx.EXPAND) | |
157 self.sizers["server"].Add(self.server_list, 1, wx.EXPAND) | |
158 self.sizers["server"].Add(self.sizers["svrbtns"], 0, wx.EXPAND) | |
159 | |
160 #Build Rooms Sizer | |
161 self.room_list = wx.ListCtrl(self, LIST_ROOM, style=wx.LC_REPORT | wx.SUNKEN_BORDER) | |
162 self.room_list.InsertColumn(0,"Game", wx.LIST_FORMAT_LEFT,0) | |
163 self.room_list.InsertColumn(1,"Players", wx.LIST_FORMAT_LEFT,0) | |
164 self.room_list.InsertColumn(2,"PW", wx.LIST_FORMAT_LEFT,0) | |
165 self.buttons[GS_JOIN] = wx.Button(self, GS_JOIN, "Join Room") | |
166 self.buttons[GS_JOINLOBBY] = wx.Button(self, GS_JOINLOBBY, "Lobby") | |
167 self.sizers["roombtns"] = wx.BoxSizer(wx.HORIZONTAL) | |
168 self.sizers["roombtns"].Add(self.buttons[GS_JOIN], 0, wx.EXPAND) | |
169 self.sizers["roombtns"].Add(self.buttons[GS_JOINLOBBY], 0, wx.EXPAND) | |
170 self.sizers["rooms"].Add(self.room_list, 1, wx.EXPAND) | |
171 self.sizers["rooms"].Add(self.sizers["roombtns"], 0, wx.EXPAND) | |
172 | |
173 #Build Close Sizer | |
174 self.buttons[OR_CLOSE] = wx.Button(self, OR_CLOSE,"Exit OpenRPG") | |
175 self.buttons[GS_CLOSE] = wx.Button(self, GS_CLOSE,"Close Window") | |
176 self.sizers["close"].Add(self.buttons[OR_CLOSE], 1, wx.ALIGN_CENTER_VERTICAL) | |
177 self.sizers["close"].Add(self.buttons[GS_CLOSE], 1, wx.ALIGN_CENTER_VERTICAL) | |
178 | |
179 #Build Create Room Sizer | |
180 rname = wx.StaticText(self,-1, "Room Name:") | |
181 self.texts["room_name"] = wx.TextCtrl(self, -1) | |
182 rpass = wx.StaticText(self,-1, "Password:") | |
183 self.buttons[GS_PWD] = wx.CheckBox(self, GS_PWD, "") | |
184 self.texts["room_pwd"] = wx.TextCtrl(self, -1) | |
185 self.texts["room_pwd"].Enable(0) | |
186 pwsizer = wx.BoxSizer(wx.HORIZONTAL) | |
187 pwsizer.Add(self.buttons[GS_PWD],0,0) | |
188 pwsizer.Add(self.texts["room_pwd"], 1, wx.EXPAND) | |
189 apass = wx.StaticText(self,-1, "Admin Password:") | |
190 self.texts["room_boot_pwd"] = wx.TextCtrl(self, -1) | |
191 minver = wx.StaticText(self,-1, "Minimum Version:") | |
192 self.texts["room_min_version"] = wx.TextCtrl(self, -1) | |
193 self.sizers["c_room_layout"] = wx.FlexGridSizer(rows=8, cols=2, hgap=1, vgap=1) | |
194 self.sizers["c_room_layout"].Add(rname, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL) | |
195 self.sizers["c_room_layout"].Add(self.texts["room_name"], 0, wx.EXPAND) | |
196 self.sizers["c_room_layout"].Add(rpass, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL) | |
197 self.sizers["c_room_layout"].Add(pwsizer, 0, wx.EXPAND) | |
198 self.sizers["c_room_layout"].Add(apass, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL) | |
199 self.sizers["c_room_layout"].Add(self.texts["room_boot_pwd"], 0, wx.EXPAND) | |
200 self.sizers["c_room_layout"].Add(minver, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL) | |
201 self.sizers["c_room_layout"].Add(self.texts["room_min_version"], 0, wx.EXPAND) | |
202 self.sizers["c_room_layout"].AddGrowableCol(1) | |
203 self.buttons[GS_CREATE_ROOM] = wx.Button(self, GS_CREATE_ROOM, "Create Room") | |
204 self.sizers["c_room"].Add(self.sizers["c_room_layout"], 1, wx.EXPAND) | |
205 self.sizers["c_room"].Add(self.buttons[GS_CREATE_ROOM], 0, wx.EXPAND) | |
206 | |
207 #Build Main Sizer | |
208 self.sizers["main"].Add(self.sizers["server"], (0,0), span=(2,1), flag=wx.EXPAND) | |
209 self.sizers["main"].Add(self.sizers["rooms"], (0,1), flag=wx.EXPAND) | |
210 self.sizers["main"].Add(self.sizers["close"], (2,0), flag=wx.EXPAND) | |
211 self.sizers["main"].Add(self.sizers["c_room"], (1,1), span=(2,1), flag=wx.EXPAND) | |
212 self.sizers["main"].AddGrowableCol(0) | |
213 self.sizers["main"].AddGrowableCol(1) | |
214 self.sizers["main"].AddGrowableRow(0) | |
215 self.SetSizer(self.sizers["main"]) | |
216 self.SetAutoLayout(True) | |
217 self.Fit() | |
218 | |
219 ## Event Handlers | |
220 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_CONNECT) | |
221 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_DISCONNECT) | |
222 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_CREATE_ROOM) | |
223 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_JOIN) | |
224 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_JOINLOBBY) | |
225 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_SERVER_REFRESH) | |
226 self.Bind(wx.EVT_BUTTON, self.on_button, id=GS_CLOSE) | |
227 self.Bind(wx.EVT_BUTTON, self.on_button, id=OR_CLOSE) | |
228 self.Bind(wx.EVT_CHECKBOX, self.on_button, id=GS_PWD) | |
229 | |
230 # Added double click handlers 5/05 -- Snowdog | |
231 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_server_dbclick, id=LIST_SERVER) | |
232 self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_room_dbclick, id=LIST_ROOM) | |
233 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_select, id=LIST_ROOM) | |
234 self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_select, id=LIST_SERVER) | |
235 self.texts['address'].Bind(wx.EVT_SET_FOCUS, self.on_text) | |
236 self.set_connected(self.session.is_connected()) | |
237 self.cur_room_index = -1 | |
238 self.cur_server_index = -1 | |
239 self.rmList = {} | |
240 self.log.log("Exit game_server_panel->build_ctrls(self)", ORPG_DEBUG) | |
241 | |
242 #--------------------------------------------------------- | |
243 # [END] Snowdog: Updated Game Server Window 12/02 | |
244 #--------------------------------------------------------- | |
245 | |
246 | |
247 #----------------------------------------------------- | |
248 # on_server_dbclick() | |
249 # support for double click selection of server. | |
250 # 5/16/05 -- Snowdog | |
251 #----------------------------------------------------- | |
252 def on_server_dbclick(self, evt=None): | |
253 self.log.log("Enter game_server_panel->on_server_dbclick(self, evt)", ORPG_DEBUG) | |
254 | |
255 #make sure address is updated just in case list select wasn't done | |
256 try: | |
257 self.on_select(evt) | |
258 except: | |
259 pass | |
260 address = self.texts["address"].GetValue() | |
261 if self.session.is_connected(): | |
262 if self.session.host_server == address : | |
263 #currently connected to address. Do nothing. | |
264 return | |
265 else: | |
266 #address differs, disconnect. | |
267 self.frame.kill_mplay_session() | |
268 self.do_connect(address) | |
269 self.log.log("Exit game_server_panel->on_server_dbclick(self, evt)", ORPG_DEBUG) | |
270 | |
271 | |
272 #----------------------------------------------------- | |
273 # on_room_dbclick() | |
274 # support for double click selection of server. | |
275 # 5/16/05 -- Snowdog | |
276 #----------------------------------------------------- | |
277 | |
278 def on_room_dbclick(self, evt=None): | |
279 self.log.log("Enter game_server_panel->on_room_dbclick(self, evt)", ORPG_DEBUG) | |
280 | |
281 #make sure address is updated just in case list select wasn't done | |
282 try: | |
283 self.on_select(evt) | |
284 except: | |
285 pass | |
286 group_id = str(self.room_list.GetItemData(self.cur_room_index)) | |
287 | |
288 if self.NoGroups: | |
289 self.NoGroups = False | |
290 self.session.group_id = group_id | |
291 self.on_server_dbclick() | |
292 return | |
293 | |
294 if self.cur_room_index >= 0: | |
295 if self.cur_room_index != 0: | |
296 self.set_lobbybutton(1); | |
297 else: | |
298 self.set_lobbybutton(0); | |
299 group = self.session.get_group_info(group_id) | |
300 pwd = "" | |
301 if (group[2] == "True") or (group[2] == "1"): | |
302 pwd = self.password_manager.GetPassword("room", group_id) | |
303 else: | |
304 pwd = "" | |
305 self.session.send_join_group(group_id, pwd) | |
306 self.log.log("Exit game_server_panel->on_room_dbclick(self, evt)", ORPG_DEBUG) | |
307 | |
308 | |
309 def on_select(self,evt): | |
310 self.log.log("Enter game_server_panel->on_select(self,evt)", ORPG_DEBUG) | |
311 id = evt.GetId() | |
312 if id == LIST_ROOM: | |
313 self.cur_room_index = evt.m_itemIndex | |
314 elif id==LIST_SERVER: | |
315 self.cur_server_index = evt.m_itemIndex | |
316 self.name = self.svrList[self.cur_server_index].name | |
317 address = self.svrList[self.cur_server_index].addy | |
318 port = self.svrList[self.cur_server_index].port | |
319 self.texts["address"].SetValue(address+":"+str(port)) | |
320 self.refresh_room_list() | |
321 self.log.log("Exit game_server_panel->on_select(self,evt)", ORPG_DEBUG) | |
322 | |
323 def on_text(self,evt): | |
324 self.log.log("Enter game_server_panel->on_text(self,evt)", ORPG_DEBUG) | |
325 id = evt.GetId() | |
326 if (id == ADDRESS) and (self.cur_server_index >= 0): | |
327 #print "ADDRESS id = ", id, "index = ", self.cur_server_index | |
328 self.cur_server_index = -1 | |
329 evt.Skip() | |
330 self.log.log("Exit game_server_panel->on_text(self,evt)", ORPG_DEBUG) | |
331 | |
332 def add_room(self,data): | |
333 self.log.log("Enter game_server_panel->add_room(self,data)", ORPG_DEBUG) | |
334 i = self.room_list.GetItemCount() | |
335 if (data[2]=="1") or (data[2]=="True"): pwd="yes" | |
336 else: pwd="no" | |
337 self.room_list.InsertStringItem(i,data[1]) | |
338 self.room_list.SetStringItem(i,1,data[3]) | |
339 self.room_list.SetStringItem(i,2,pwd) | |
340 self.room_list.SetItemData(i,int(data[0])) | |
341 self.refresh_room_list() | |
342 self.log.log("Exit game_server_panel->add_room(self,data)", ORPG_DEBUG) | |
343 | |
344 def del_room(self, data): | |
345 self.log.log("Enter game_server_panel->del_room(self, data)", ORPG_DEBUG) | |
346 i = self.room_list.FindItemData(-1, int(data[0])) | |
347 self.room_list.DeleteItem(i) | |
348 self.refresh_room_list() | |
349 self.log.log("Exit game_server_panel->del_room(self, data)", ORPG_DEBUG) | |
350 | |
351 #--------------------------------------------------------- | |
352 # [START] Snowdog Password/Room Name altering code 12/02 | |
353 #--------------------------------------------------------- | |
354 | |
355 def update_room(self,data): | |
356 self.log.log("Enter game_server_panel->update_room(self,data)", ORPG_DEBUG) | |
357 | |
358 #------------------------------------------------------- | |
359 # Udated 12/02 by Snowdog | |
360 # allows refresh of all room data not just player counts | |
361 #------------------------------------------------------- | |
362 i = self.room_list.FindItemData(-1,int(data[0])) | |
363 if data[2]=="1" : pwd="yes" | |
364 else: pwd="no" | |
365 self.room_list.SetStringItem(i,0,data[1]) | |
366 self.room_list.SetStringItem(i,1,data[3]) | |
367 self.room_list.SetStringItem(i,2,pwd) | |
368 self.refresh_room_list() | |
369 self.log.log("Exit game_server_panel->update_room(self,data)", ORPG_DEBUG) | |
370 | |
371 #--------------------------------------------------------- | |
372 # [END] Snowdog Password/Room Name altering code 12/02 | |
373 #--------------------------------------------------------- | |
374 | |
375 def set_cur_room_text(self,name): | |
376 pass | |
377 #self.texts["cur_room"].SetLabel(name) | |
378 #self.sizers["room"].Layout() | |
379 | |
380 def set_lobbybutton(self,allow): | |
381 self.log.log("Enter game_server_panel->set_lobbybutton(self,allow)", ORPG_DEBUG) | |
382 self.buttons[GS_JOINLOBBY].Enable(allow) | |
383 self.log.log("Exit game_server_panel->set_lobbybutton(self,allow)", ORPG_DEBUG) | |
384 | |
385 def set_connected(self,connected): | |
386 self.log.log("Enter game_server_panel->set_connected(self,connected)", ORPG_DEBUG) | |
387 self.buttons[GS_CONNECT].Enable(not connected) | |
388 self.buttons[GS_DISCONNECT].Enable(connected) | |
389 self.buttons[GS_JOIN].Enable(connected) | |
390 self.buttons[GS_CREATE_ROOM].Enable(connected) | |
391 if not connected: | |
392 self.buttons[GS_JOINLOBBY].Enable(connected) | |
393 self.room_list.DeleteAllItems() | |
394 self.set_cur_room_text("Not Connected!") | |
395 self.cur_room_index = -1 | |
396 self.frame.status.set_connect_status("Not Connected") | |
397 else: | |
398 #data = self.session.get_my_group() | |
399 self.frame.status.set_connect_status(self.name) | |
400 self.set_cur_room_text("Lobby") | |
401 self.log.log("Exit game_server_panel->set_connected(self,connected)", ORPG_DEBUG) | |
402 | |
403 def on_button(self,evt): | |
404 self.log.log("Enter game_server_panel->son_button(self,evt)", ORPG_DEBUG) | |
405 id = evt.GetId() | |
406 if id == GS_CONNECT: | |
407 address = self.texts["address"].GetValue() | |
408 ### check to see if this is a manual entry vs. list entry. | |
409 try: | |
410 dummy = self.name | |
411 except: | |
412 self.name = `address` | |
413 self.do_connect(address) | |
414 elif id == GS_DISCONNECT: | |
415 self.frame.kill_mplay_session() | |
416 elif id == GS_CREATE_ROOM: | |
417 self.do_create_group() | |
418 elif id == GS_JOIN: | |
419 self.do_join_group() | |
420 elif id == GS_JOINLOBBY: | |
421 self.do_join_lobby() | |
422 elif id == GS_SERVER_REFRESH: | |
423 self.refresh_server_list() | |
424 elif id == GS_PWD: | |
425 self.texts["room_pwd"].Enable(evt.Checked()) | |
426 elif id == OR_CLOSE: | |
427 dlg = wx.MessageDialog(self,"Quit OpenRPG?","OpenRPG",wx.YES_NO) | |
428 if dlg.ShowModal() == wx.ID_YES: | |
429 dlg.Destroy() | |
430 self.frame.kill_mplay_session() | |
431 self.frame.closed_confirmed() | |
432 elif id == GS_CLOSE: | |
433 self.parent.OnMB_GameServerBrowseServers() | |
434 self.log.log("Exit game_server_panel->son_button(self,evt)", ORPG_DEBUG) | |
435 | |
436 def refresh_room_list(self): | |
437 self.log.log("Enter game_server_panel->refresh_room_list(self)", ORPG_DEBUG) | |
438 self.room_list.DeleteAllItems() | |
439 address = self.texts["address"].GetValue() | |
440 try: | |
441 cadder = self.session.host_server | |
442 except: | |
443 cadder = '' | |
444 if self.rmList.has_key(address) and len(self.rmList[address]) > 0 and cadder != address: | |
445 groups = self.rmList[address] | |
446 self.NoGroups = True | |
447 else: | |
448 self.NoGroups = False | |
449 groups = self.session.get_groups() | |
450 for g in groups: | |
451 i = self.room_list.GetItemCount() | |
452 if (g[2]=="True") or (g[2]=="1") : pwd="yes" | |
453 else: pwd="no" | |
454 self.room_list.InsertStringItem(i, g[1]) | |
455 self.room_list.SetStringItem(i, 1, g[3]) | |
456 self.room_list.SetStringItem(i, 2, pwd) | |
457 self.room_list.SetItemData(i, int(g[0])) | |
458 if self.room_list.GetItemCount() > 0: | |
459 self.colorize_group_list(groups) | |
460 self.room_list.SortItems(roomCmp) | |
461 wx.CallAfter(self.autosizeRooms) | |
462 self.log.log("Exit game_server_panel->refresh_room_list(self)", ORPG_DEBUG) | |
463 | |
464 def autosizeRooms(self): | |
465 self.log.log("Enter game_server_panel->autosizeRooms(self)", ORPG_DEBUG) | |
466 self.room_list.SetColumnWidth(0, wx.LIST_AUTOSIZE) | |
467 self.room_list.SetColumnWidth(1, wx.LIST_AUTOSIZE) | |
468 self.room_list.SetColumnWidth(2, wx.LIST_AUTOSIZE) | |
469 self.log.log("Exit game_server_panel->autosizeRooms(self)", ORPG_DEBUG) | |
470 | |
471 def refresh_server_list(self): | |
472 self.log.log("Enter game_server_panel->refresh_server_list(self)", ORPG_DEBUG) | |
473 | |
474 try: | |
475 self.svrList = [] | |
476 self.server_list.DeleteAllItems() | |
477 xml_dom = meta_server_lib.get_server_list(["2"]); | |
478 node_list = xml_dom.getElementsByTagName('server') | |
479 hex = orpg.tools.rgbhex.RGBHex() | |
480 color1 = self.settings.get_setting("RoomColor_Active") | |
481 color2 = self.settings.get_setting("RoomColor_Locked") | |
482 color3 = self.settings.get_setting("RoomColor_Empty") | |
483 color4 = self.settings.get_setting("RoomColor_Lobby") | |
484 | |
485 if len(node_list): | |
486 length = len(node_list) | |
487 part = 0 | |
488 partLength = 1.0/length | |
489 for n in node_list: | |
490 if n.hasAttribute('id') and n.hasAttribute('name') and n.hasAttribute('num_users') and n.hasAttribute('address') and n.hasAttribute('port'): | |
491 self.svrList.append( server_instance(n.getAttribute('id'),n.getAttribute('name'), n.getAttribute('num_users'), n.getAttribute('address'),n.getAttribute('port'))) | |
492 address = n.getAttribute('address') + ':' + n.getAttribute('port') | |
493 self.rmList[address] = [] | |
494 rooms = n.getElementsByTagName('room') | |
495 | |
496 for room in rooms: | |
497 pwd = room.getAttribute("pwd") | |
498 id = room.getAttribute("id") | |
499 name = room.getAttribute("name") | |
500 nump = room.getAttribute("num_users") | |
501 self.rmList[address].append((id, name, pwd, nump)) | |
502 self.svrList.sort(server_instance_compare) | |
503 | |
504 for n in self.svrList: | |
505 i = self.server_list.GetItemCount() | |
506 name = n.name | |
507 players = n.user | |
508 self.server_list.InsertStringItem(i,players) | |
509 self.server_list.SetStringItem(i,1,name) | |
510 r,g,b = hex.rgb_tuple(color1) | |
511 svrcolor = wx.Colour(red=r,green=g,blue=b) | |
512 | |
513 if players == "0": | |
514 r,g,b = hex.rgb_tuple(color3) | |
515 svrcolor = wx.Colour(red=r,green=g,blue=b) | |
516 | |
517 if n.name.startswith("OpenRPG DEV"): | |
518 r,g,b = hex.rgb_tuple(color2) | |
519 svrcolor = wx.Colour(red=r,green=g,blue=b) | |
520 | |
521 item = self.server_list.GetItem(i) | |
522 item.SetTextColour(svrcolor) | |
523 self.server_list.SetItem(item) | |
524 part += partLength | |
525 self.servers = node_list | |
526 | |
527 # No server is currently selected!!! Versus the broken and random 0! | |
528 self.cur_server_index = -1 | |
529 self.server_list.SetColumnWidth(0, wx.LIST_AUTOSIZE) | |
530 self.server_list.SetColumnWidth(1, wx.LIST_AUTOSIZE) | |
531 | |
532 if self.serverNameSet == 0: | |
533 # Pointless to constantly set the address field to random | |
534 # server. This way, at least, if someone has their own local | |
535 # server it can now easily be connected with. Nor do we want | |
536 # to reset this every time as it would wipe any previously | |
537 # entered data or even the previously selected server data! | |
538 # Localhost should probably be used but some systems are ultra/lame | |
539 # broken about localhost use. | |
540 self.texts["address"].SetValue("127.0.0.1:6774") | |
541 self.serverNameSet = 1 | |
542 else: | |
543 pass | |
544 | |
545 # Allow xml_dom to be collected | |
546 try: | |
547 xml_dom.unlink() | |
548 except: | |
549 pass | |
550 except Exception, e: | |
551 print "Server List not available." | |
552 traceback.print_exc() | |
553 self.log.log("Exit game_server_panel->refresh_server_list(self)", ORPG_DEBUG) | |
554 | |
555 def failed_connection(self): | |
556 self.log.log("Enter game_server_panel->failed_connection(self)", ORPG_DEBUG) | |
557 if(self.cur_server_index >= 0): | |
558 id = self.servers[self.cur_server_index].getAttribute('id') | |
559 meta = self.servers[self.cur_server_index].getAttribute('meta') | |
560 address = self.servers[self.cur_server_index].getAttribute('address') | |
561 port = self.servers[self.cur_server_index].getAttribute('port') | |
562 # post_failed_connection will return a non-zero if the server | |
563 # was removed. If it was, refresh the display | |
564 if(meta_server_lib.post_failed_connection(id,meta=meta,address=address,port=port)): | |
565 self.refresh_server_list() | |
566 self.log.log("Exit game_server_panel->failed_connection(self)", ORPG_DEBUG) | |
567 | |
568 def do_connect(self, address): | |
569 self.log.log("Enter game_server_panel->do_connect(self, address)", ORPG_DEBUG) | |
570 chat = open_rpg.get_component('chat') | |
571 chat.InfoPost("Locating server at " + address + "...") | |
572 if self.session.connect(address): | |
573 self.frame.start_timer() | |
574 else: | |
575 chat.SystemPost("Failed to connect to game server...") | |
576 self.failed_connection() | |
577 self.log.log("Exit game_server_panel->do_connect(self, address)", ORPG_DEBUG) | |
578 | |
579 def do_join_lobby(self): | |
580 self.log.log("Enter game_server_panel->do_join_lobby(self)", ORPG_DEBUG) | |
581 self.cur_room_index = 0 | |
582 self.session.send_join_group("0","") | |
583 self.set_lobbybutton(0); | |
584 self.log.log("Exit game_server_panel->do_join_lobby(self)", ORPG_DEBUG) | |
585 | |
586 def do_join_group(self): | |
587 self.log.log("Enter game_server_panel->do_join_group(self)", ORPG_DEBUG) | |
588 if self.cur_room_index >= 0: | |
589 if self.cur_room_index != 0: | |
590 self.set_lobbybutton(1); | |
591 else: | |
592 self.set_lobbybutton(0); | |
593 group_id = str(self.room_list.GetItemData(self.cur_room_index)) | |
594 group = self.session.get_group_info(group_id) | |
595 pwd = "" | |
596 if (group[2] == "True") or (group[2] == "1"): | |
597 pwd = self.password_manager.GetPassword("room", group_id) | |
598 #dlg = wx.TextEntryDialog(self,"Password?","Join Private Room") | |
599 #if dlg.ShowModal() == wx.ID_OK: | |
600 # pwd = dlg.GetValue() | |
601 #dlg.Destroy() | |
602 else: | |
603 pwd = "" | |
604 if pwd != None: #pwd==None means the user clicked "Cancel" | |
605 self.session.send_join_group(group_id,pwd) | |
606 self.log.log("Exit game_server_panel->do_join_group(self)", ORPG_DEBUG) | |
607 | |
608 def do_create_group(self): | |
609 self.log.log("Enter game_server_panel->do_create_group(self)", ORPG_DEBUG) | |
610 name = self.texts["room_name"].GetValue() | |
611 boot_pwd = self.texts["room_boot_pwd"].GetValue() | |
612 minversion = self.texts["room_min_version"].GetValue() | |
613 # | |
614 # Check for & in name. We want to allow this becaus of its common use in D&D. | |
615 # | |
616 loc = name.find("&") | |
617 oldloc=0 | |
618 while loc > -1: | |
619 loc = name.find("&",oldloc) | |
620 if loc > -1: | |
621 b = name[:loc] | |
622 e = name[loc+1:] | |
623 name = b + "&" + e | |
624 oldloc = loc+1 | |
625 loc = name.find('"') | |
626 oldloc=0 | |
627 while loc > -1: | |
628 loc = name.find('"',oldloc) | |
629 if loc > -1: | |
630 b = name[:loc] | |
631 e = name[loc+1:] | |
632 name = b + ""e;" + e | |
633 oldloc = loc+1 | |
634 loc = name.find("'") | |
635 oldloc=0 | |
636 while loc > -1: | |
637 loc = name.find("'",oldloc) | |
638 if loc > -1: | |
639 b = name[:loc] | |
640 e = name[loc+1:] | |
641 name = b + "'" + e | |
642 oldloc = loc+1 | |
643 if self.buttons[GS_PWD].GetValue(): | |
644 pwd = self.texts["room_pwd"].GetValue() | |
645 else: | |
646 pwd = "" | |
647 if name == "": | |
648 wx.MessageBox("Invalid Name","Error"); | |
649 else: | |
650 msg = "%s is creating room \'%s.\'" % (self.session.name, name) | |
651 self.session.send( msg ) | |
652 self.session.send_create_group(name,pwd,boot_pwd,minversion) | |
653 self.set_lobbybutton(1); #enable the Lobby quickbutton | |
654 self.log.log("Exit game_server_panel->do_create_group(self)", ORPG_DEBUG) | |
655 | |
656 | |
657 #--------------------------------------------------------- | |
658 # [START] Snowdog: Updated Game Server Window 12/02 | |
659 #--------------------------------------------------------- | |
660 | |
661 def on_size(self,evt): | |
662 # set column widths for room list | |
663 | |
664 | |
665 # set column widths for server list | |
666 pass | |
667 | |
668 | |
669 | |
670 #--------------------------------------------------------- | |
671 # [END] Snowdog: Updated Game Server Window 12/02 | |
672 #--------------------------------------------------------- | |
673 | |
674 | |
675 def colorize_group_list(self, groups): | |
676 self.log.log("Enter game_server_panel->colorize_group_list(self, groups)", ORPG_DEBUG) | |
677 | |
678 try: | |
679 hex = orpg.tools.rgbhex.RGBHex() | |
680 # activ = self.settings.get_setting("RoomColor_Active") | |
681 # lockt = self.settings.get_setting("RoomColor_Locked") | |
682 # empty = self.settings.get_setting("RoomColor_Empty") | |
683 # lobby = self.settings.get_setting("RoomColor_Lobby") | |
684 #renamed colors - TaS sirebral | |
685 | |
686 for gr in groups: | |
687 item_list_location = self.room_list.FindItemData(-1,int(gr[0])) | |
688 if item_list_location != -1: | |
689 item = self.room_list.GetItem(item_list_location) | |
690 if gr[0] == "0": | |
691 # active_state = lobby | |
692 r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Lobby")) | |
693 elif gr[3] <> "0": | |
694 # active_state = activ | |
695 if gr[2] == "True" or gr[2] == "1": | |
696 # active_state = lockt | |
697 r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Locked")) | |
698 else: | |
699 # active_state = activ | |
700 r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Active")) | |
701 else: | |
702 # active_state = empty | |
703 r,g,b = hex.rgb_tuple(self.settings.get_setting("RoomColor_Empty")) | |
704 | |
705 # r,g,b = hex.rgb_tuple(active_state) | |
706 color = wx.Colour(red=r,green=g,blue=b) | |
707 item.SetTextColour(color) | |
708 self.room_list.SetItem(item) | |
709 except: | |
710 traceback.print_exc() | |
711 self.log.log("Exit game_server_panel->colorize_group_list(self, groups)", ORPG_DEBUG) |