Mercurial > traipse_dev
annotate orpg/networking/meta_server_lib.py @ 248:1df5912db00c beta tip
Traipse Beta 'OpenRPG' {101205-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 (Closed)
New Features:
New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order
New to Server GUI, can now clear log
New Earthdawn Dieroller
New IronClaw roller, sheet, and image
New ShapeShifter PC Sheet
Updates:
Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence.
Update to Browser Server window. Display rooms with ' " & cleaner
Update to Server. Handles ' " & cleaner
Update to Dieroller. Cleaner, more effecient expression system
Update to Hidden Die plugin, allows for non standard dice rolls
Update to location.py, allows for more portable references when starting Traipse
Update to the Features node
Fixes:
Fix to InterParse that was causing an Infernal Loop with Namespace Internal
Fix to XML data, removed old Minidom and switched to Element Tree
Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread
Fix to Server, removing wxPython dependencies where not needed
Fix to metaservers.xml file not being created
Fix to Single and Double quotes in Whiteboard text
Fix to Background images not showing when using the Image Server
Fix to Duplicate chat names appearing
Fix to Server GUI's logging output
Fix to FNB.COLORFUL_TABS bug
Fix to Gametree for XSLT Sheets
Fix to Gametree for locating gametree files
Fix to Send to Chat from Gametree
Fix to Gametree, renaming and remapping operates correctly
Fix to aliaslib, prevents error caused when SafeHTML is sent None
author | sirebral |
---|---|
date | Sun, 05 Dec 2010 10:53:30 -0600 |
parents | b44dad398833 |
children |
rev | line source |
---|---|
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
1 #!/usr/bin/python2.1 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
2 # Copyright (C) 2000-2001 The OpenRPG Project |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
3 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
4 # openrpg-dev@lists.sourceforge.net |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
5 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
6 # This program is free software; you can redistribute it and/or modify |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
7 # it under the terms of the GNU General Public License as published by |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
8 # the Free Software Foundation; either version 2 of the License, or |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
9 # (at your option) any later version. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
10 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
14 # GNU General Public License for more details. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
15 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
16 # You should have received a copy of the GNU General Public License |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
17 # along with this program; if not, write to the Free Software |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
19 # -- |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
20 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
21 # File: meta_server_lib.py |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
22 # Author: Chris Davis |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
23 # Maintainer: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
24 # Version: |
184 | 25 # $Id: meta_server_lib.py,v Traipse 'Ornery-Orc' prof.ebral Exp $ |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
26 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
27 # Description: A collection of functions to communicate with the meta server. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
28 # |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
29 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
30 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
31 #added debug flag for meta messages to cut console server spam --Snowdog |
236 | 32 META_DEBUG = False |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
33 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
34 __version__ = "$Id: meta_server_lib.py,v 1.40 2007/04/04 01:18:42 digitalxero Exp $" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
35 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
36 from orpg.orpg_version import PROTOCOL_VERSION |
100 | 37 from orpg.orpgCore import component |
38 from orpg.tools.validate import validate | |
39 from orpg.dirpath import dir_struct | |
135 | 40 |
41 import urllib, time, sys, traceback, re | |
42 | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
43 from threading import * |
135 | 44 from random import uniform |
236 | 45 import urllib2 |
135 | 46 from urllib import urlopen, urlencode |
248 | 47 #from orpg.tools.orpg_log import debug |
135 | 48 |
236 | 49 from xml.etree.ElementTree import Element, fromstring, parse, tostring |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
50 metacache_lock = RLock() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
51 |
236 | 52 def get_server_dom(data=None, path=None, string=False): |
53 if path[len(path)-1] != "/": path += '/' | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
54 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
55 # POST the data |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
56 if META_DEBUG: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
57 print |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
58 print "Sending the following POST info to Meta at " + path + ":" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
59 print "==========================================" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
60 print data |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
61 print |
236 | 62 #recvdata = urllib2.Request(path, data) |
63 response = urllib2.urlopen(path, data) | |
64 data = response.read() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
65 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
66 # Remove any leading or trailing data. This can happen on some satellite connections |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
67 p = re.compile('(<servers>.*?</servers>)',re.DOTALL|re.IGNORECASE) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
68 mo = p.search(data) |
100 | 69 if mo: data = mo.group(0) |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
70 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
71 if META_DEBUG: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
72 print |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
73 print "Got this string from the Meta at " + path + ":" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
74 print "===============================================" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
75 print data |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
76 print |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
77 # build dom |
236 | 78 if string: return data |
79 else: return fromstring(data) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
80 |
135 | 81 def post_server_data(name, realHostName=None): |
82 if realHostName: data = urlencode({"server_data[name]":name, | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
83 "server_data[version]":PROTOCOL_VERSION, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
84 "act":"new", |
135 | 85 "REMOTE_ADDR": realHostName }) |
86 # print "Letting meta server decide the hostname to list..." | |
87 else: data = urlencode({"server_data[name]":name, | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
88 "server_data[version]":PROTOCOL_VERSION, |
135 | 89 "act":"new"}) |
236 | 90 path = component.get('settings').get('MetaServerBaseURL') #getMetaServerList() |
135 | 91 etreeEl = get_server_dom(data, path) |
92 return int(etreeEl.get('id')) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
93 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
94 def post_failed_connection(id,meta=None,address=None,port=None): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
95 # For now, turning this off. This needs to be re-vamped for |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
96 # handling multiple Metas. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
97 return 0 |
135 | 98 #data = urlencode({"id":id,"act":"failed"}); |
100 | 99 #xml_dom = get_server_dom(data) |
100 #ret_val = int(xml_dom.getAttribute("return")) | |
101 #return ret_val | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
102 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
103 def remove_server(id): |
135 | 104 data = urlencode({"id":id,"act":"del"}); |
105 etreeEl = get_server_dom(data) | |
106 return int(etreeEl.get("return")) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
107 |
135 | 108 def byStartAttribute(first, second): |
109 # This function is used to easily sort a list of nodes by their start time | |
110 # Ensure there is something to sort with for each | |
111 first_start = int(first.get('start')) or 0 | |
112 second_start = int(second.get('start')) or 0 | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
113 # Return the result of the cmp function on the two strings |
135 | 114 return cmp(first_start, second_start) |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
115 |
135 | 116 def byNameAttribute(first, second): |
117 # This function is used to easily sort a list of nodes by their name attribute | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
118 # Ensure there is something to sort with for each |
135 | 119 first_name = first.get('name') or '' |
120 second_name = second.get('name') or '' | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
121 # Return the result of the cmp function on the two strings |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
122 return cmp(first_name,second_name) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
123 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
124 |
236 | 125 def get_server_list(versions=None, sort_by="start"): |
135 | 126 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) |
236 | 127 #all_metas = getMetaServers(versions, False) # get the list of metas |
128 meta_list = getMetaServerList() | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
129 #all_metas.reverse() # The last one checked will take precedence, so reverse the order |
135 | 130 # so that the top one on the actual list is checked last |
131 return_hash = {} # this will end up with an amalgamated list of servers | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
132 |
236 | 133 for meta in meta_list: # check all of the metas |
100 | 134 #get the server's xml from the current meta |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
135 bad_meta = 0 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
136 #print "Getting server list from " + meta + "..." |
238 | 137 try: meta_path = meta.get('url'); xml_dom = get_server_dom(data, meta_path) |
138 except: | |
139 if meta_path == None: meta_path = 'No URL available' | |
140 bad_meta = 1; print "Trouble getting servers from " +meta_path+ "..." | |
135 | 141 if bad_meta: continue |
142 node_list = xml_dom.findall('server') | |
236 | 143 if len(node_list): |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
144 for n in node_list: |
135 | 145 if not n.get('name'): n.set('name','NO_NAME_GIVEN') |
146 name = n.get('name') | |
147 if not n.get('num_users'): n.set('num_users','N/A') | |
148 num_users = n.get('num_users') | |
149 if not n.get('address'): n.set('address','NO_ADDRESS_GIVEN') | |
150 address = n.get('address') | |
151 if not n.get('port'): n.set('port','6774') | |
152 port = n.get('port') | |
153 n.set('meta',meta) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
154 end_point = str(address) + ":" + str(port) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
155 if return_hash.has_key(end_point): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
156 if META_DEBUG: print "Replacing duplicate server entry at " + end_point |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
157 return_hash[end_point] = n |
135 | 158 server_list = Element('servers') |
159 sort_list = return_hash.values() | |
160 if sort_by == "start": sort_list.sort(byStartAttribute) | |
161 elif sort_by == "name": sort_list.sort(byNameAttribute) | |
162 for n in sort_list: server_list.append(n) | |
163 return server_list | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
164 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
165 ## List Format: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
166 ## <servers> |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
167 ## <server address=? id=? name=? failed_count=? > |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
168 ## </servers> |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
169 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
170 def updateMetaCache(xml_dom): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
171 try: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
172 if META_DEBUG: print "Updating Meta Server Cache" |
135 | 173 metaservers = xml_dom.findall('metaservers') # pull out the metaservers bit |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
174 if len(metaservers) == 0: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
175 cmetalist = getRawMetaList() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
176 xml_dom = get_server_dom(cmetalist[0]) |
135 | 177 metaservers = xml_dom.findall('metaservers') |
178 authoritative = metaservers[0].get('auth') | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
179 if META_DEBUG: print " Authoritive Meta: "+str(authoritative) |
135 | 180 metas = metaservers[0].findall("meta") # get the list of metas |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
181 if META_DEBUG: print " Meta List ("+str(len(metas))+" servers)" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
182 try: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
183 metacache_lock.acquire() |
100 | 184 ini = open(dir_struct["user"]+"metaservers.cache","w") |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
185 for meta in metas: |
135 | 186 if META_DEBUG: print " Writing: "+str(meta.get('path')) |
187 ini.write(str(meta.get('path')) + " " + str(meta.get('versions')) + "\n") | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
188 ini.close() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
189 finally: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
190 metacache_lock.release() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
191 except Exception, e: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
192 if META_DEBUG: traceback.print_exc() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
193 print "Meta Server Lib: UpdateMetaCache(): " + str(e) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
194 |
236 | 195 |
196 def getMetaServerList(): | |
197 # get meta server URL | |
198 meta_list = fromstring(""" | |
199 <metaservers> | |
200 <meta url="http://orpgmeta.appspot.com" versions="1 2" /> | |
201 <meta url="http://traipsemeta.madmathlabs.info" versions="1 2" /> | |
202 </metaservers>""" | |
203 ) | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
204 try: |
236 | 205 component.get('validate').config_file("metaservers.xml","default_metaservers.xml") |
100 | 206 component.get('validate').config_file("settings.xml","default_settings.xml") |
236 | 207 setting = parse(dir_struct["user"]+"settings.xml") |
208 tree = setting.getroot() | |
209 node_list = tree.getiterator("MetaServers") | |
210 if len(node_list) == 0: | |
211 component.get('frame').add_setting('Meta Servers') | |
212 setting = parse(dir_struct["user"]+"settings.xml") | |
213 metas = parse(dir_struct["user"]+'metaservers.xml').getroot() | |
214 else: | |
215 meta = node_list[0].get("value") | |
216 metas = parse(dir_struct["user"]+meta).getroot() | |
217 meta_list = metas.findall('meta') | |
218 return meta_list | |
219 except Exception,e: print e | |
220 return meta_list | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
221 |
100 | 222 """ |
223 Beginning of Class registerThread | |
224 | |
225 A Class to Manage Registration with the Meta2 | |
226 Create an instance and call it's start() method | |
227 if you want to be (and stay) registered. This class | |
228 will take care of registering and re-registering as | |
229 often as necessary to stay in the Meta list. | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
230 |
100 | 231 You may call register() yourself if you wish to change your |
232 server's name. It will immediately update the Meta. There | |
233 is no need to unregister first. | |
234 | |
235 Call unregister() when you no longer want to be registered. | |
236 This will result in the registerThread dying after | |
237 attempting to immediately remove itself from the Meta. | |
238 | |
239 If you need to become registered again after that, you | |
240 must create a new instance of class registerThread. Don't | |
241 just try to call register() on the old, dead thread class. | |
242 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
243 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
244 class registerThread(Thread): |
100 | 245 """ |
246 Originally, I wrote this as a sub-class of wxThread, but | |
247 A) I couldn't get it to import right | |
248 B) I realized that I want this to be used in a server, | |
249 which I don't want needing wxWindows to run! | |
250 | |
251 Because of this fact, there are some methods from wxThread | |
252 that I implemented to minimize changes to the code I had | |
253 just written, i.e. TestDeleteStatus() and Delete() | |
254 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
255 |
135 | 256 def __init__(self, name=None, realHostName=None, num_users="0", |
257 MetaPath=None, port=6774, register_callback=None): | |
258 Thread.__init__(self, name="registerThread") | |
259 self.rlock = RLock() # Re-entrant lock used to make this class thread safe | |
260 self.die_event = Event() # The main loop in run() will wait with timeout on this | |
261 self.name = name or 'Unnamed Server' # Name that the server want's displayed on the Meta | |
262 # But use Unnamed Server if for some crazy reason | |
263 # no name is passed to the constructor | |
264 self.num_users = num_users # the number of users currently on this server | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
265 self.realHostName = realHostName # Name to advertise for connection |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
266 self.id = "0" # id returned from Meta. Defaults to "0", which |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
267 # indicates a new registration. |
135 | 268 self.cookie = "0" # cookie returned from Meta. Defaults to "0", which |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
269 # indicates a new registration. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
270 self.interval = 0 # interval returned from Meta. Is how often to |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
271 # re-register, in minutes. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
272 self.destroy = 0 # Used to flag that this thread should die |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
273 self.port = str(port) |
100 | 274 self.register_callback = register_callback # set a method to call to report result of register |
236 | 275 self.IdAttempts = 0 |
100 | 276 """ |
277 This thread will communicate with one and only one | |
278 Meta. If the Meta in ini.xml is changed after | |
279 instantiation, then this instance must be | |
280 unregistered and a new instance instantiated. | |
281 | |
282 Also, if MetaPath is specified, then use that. Makes | |
283 it easier to have multiple registerThreads going to keep the server registered | |
284 on multiple (compatible) Metas. | |
285 """ | |
236 | 286 if MetaPath == None: self.path = getMetaServerList() # Do this if no Meta specified |
135 | 287 else: self.path = MetaPath |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
288 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
289 def getIdAndCookie(self): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
290 return self.id, self.cookie |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
291 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
292 def TestDeleteStatus(self): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
293 try: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
294 self.rlock.acquire() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
295 return self.die_event.isSet() |
135 | 296 finally: self.rlock.release() |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
297 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
298 def Delete(self): |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
299 try: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
300 self.rlock.acquire() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
301 self.die_event.set() |
135 | 302 finally: self.rlock.release() |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
303 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
304 def run(self): |
100 | 305 """ |
306 This method gets called by Thread implementation | |
307 when self.start() is called to begin the thread's | |
308 execution | |
309 | |
310 We will basically enter a loop that continually | |
311 re-registers this server and sleeps Interval | |
312 minutes until the thread is ordered to die in place | |
313 """ | |
135 | 314 while(not self.TestDeleteStatus()): # Loop while until told to die |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
315 # Otherwise, call thread safe register(). |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
316 self.register(self.name, self.realHostName, self.num_users) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
317 if META_DEBUG: print "Sent Registration Data" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
318 # register() will end up setting the state variables |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
319 # for us, including self.interval. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
320 try: |
135 | 321 self.rlock.acquire() # Serialize access to this state information |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
322 |
135 | 323 if self.interval >= 3: # If the number of minutes is one or greater |
324 self.interval -= 1 # wake up with 30 seconds left to re-register | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
325 else: |
135 | 326 self.interval = .5 # Otherwise, we probably experienced some kind |
327 # of error from the Meta in register(). Sleep | |
328 # for 6 seconds and start from scratch. | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
329 |
135 | 330 finally: self.rlock.release() # no matter what, release the lock |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
331 # Wait interval minutes for a command to die |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
332 die_signal = self.die_event.wait(self.interval*60) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
333 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
334 # If we get past the while loop, it's because we've been asked to die, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
335 # so just let run() end. Once this occurs, the thread is dead and |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
336 # calls to Thread.isAlive() return False. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
337 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
338 def unregister(self): |
100 | 339 """ |
340 This method can (I hope) be called from both within the thread | |
341 and from other threads. It will attempt to unregister this | |
342 server from the Meta database | |
343 When this is either accomplished or has been tried hard enough | |
344 (after which it just makes sense to let the Meta remove the | |
345 entry itself when we don't re-register using this id), | |
346 this method will either cause the thread to immediately die | |
347 (if called from this thread's context) or set the Destroy flag | |
348 (if called from the main thread), a positive test for which will cause | |
349 the code in Entry() to exit() when the thread wakes up and | |
350 checks TestDeleteStatus(). | |
351 lock the critical section. The unlock will | |
352 automatically occur at the end of the function in the finally clause | |
353 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
354 try: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
355 self.rlock.acquire() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
356 if not self.isAlive(): # check to see if this thread is dead |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
357 return 1 # If so, return an error result |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
358 # Do the actual unregistering here |
236 | 359 data = urlencode( { "server_data[id]":self.id, |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
360 "server_data[cookie]":self.cookie, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
361 "server_data[version]":PROTOCOL_VERSION, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
362 "act":"unregister"} ) |
236 | 363 for path in getMetaServerList(): |
364 try: # this POSTS the request and returns the result | |
238 | 365 etreeEl = get_server_dom(data, self.path) |
236 | 366 if etreeEl.get("errmsg") != None: |
238 | 367 print "Error durring unregistration: " +etreeEl.get("errmsg") |
236 | 368 except Exception, e: |
369 if META_DEBUG: print "Problem talking to Meta. Will go ahead and die, letting Meta remove us." | |
370 if META_DEBUG: print e | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
371 # If there's an error, echo it to the console |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
372 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
373 # No special handling is required. If the de-registration worked we're done. If |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
374 # not, then it's because we've already been removed or have a bad cookie. Either |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
375 # way, we can't do anything else, so die. |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
376 self.Delete() # This will cause the registerThread to die in register() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
377 # prep xml_dom for garbage collection |
100 | 378 try: xml_dom.unlink() |
379 except: pass | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
380 return 0 |
100 | 381 finally: self.rlock.release() |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
382 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
383 def register(self, name=None, realHostName=None, num_users=None): |
100 | 384 """ |
385 Designed to handle the registration, both new and | |
386 repeated. | |
387 | |
388 It is intended to be called once every interval | |
389 (or interval - delta) minutes. | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
390 |
100 | 391 lock the critical section. The unlock will |
392 automatically occur at the end of the function in the finally clause | |
393 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
394 try: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
395 self.rlock.acquire() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
396 if not self.isAlive(): # check to see if this thread is dead |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
397 return 1 # If so, return an error result |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
398 |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
399 # Set the server's attibutes, if specified. |
100 | 400 if name: self.name = name |
236 | 401 if num_users != None: |
402 try: self.num_users = len(num_users) | |
403 except: self.num_users = num_users | |
404 else: self.num_users = 0 | |
100 | 405 if realHostName: self.realHostName = realHostName |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
406 # build POST data |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
407 if self.realHostName: |
236 | 408 data = urlencode( { "server_data[id]":self.id, |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
409 "server_data[cookie]":self.cookie, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
410 "server_data[name]":self.name, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
411 "server_data[port]":self.port, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
412 "server_data[version]":PROTOCOL_VERSION, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
413 "server_data[num_users]":self.num_users, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
414 "act":"register", |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
415 "server_data[address]": self.realHostName } ) |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
416 else: |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
417 if META_DEBUG: print "Letting meta server decide the hostname to list..." |
236 | 418 data = urlencode( { "server_data[id]":self.id, |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
419 "server_data[cookie]":self.cookie, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
420 "server_data[name]":self.name, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
421 "server_data[port]":self.port, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
422 "server_data[version]":PROTOCOL_VERSION, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
423 "server_data[num_users]":self.num_users, |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
424 "act":"register"} ) |
135 | 425 try: # this POSTS the request and returns the result |
236 | 426 etreeEl = get_server_dom(data, self.path) |
427 except Exception, e: | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
428 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..." |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
429 if META_DEBUG: print data |
236 | 430 if META_DEBUG: print e |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
431 self.interval = 0 |
100 | 432 """ |
433 If we are in the registerThread thread, then setting interval to 0 | |
434 will end up causing a retry in about 6 seconds (see self.run()) | |
435 If we are in the main thread, then setting interval to 0 will do one | |
436 of two things: | |
437 1) Do the same as if we were in the registerThread | |
438 2) Cause the next, normally scheduled register() call to use the values | |
439 provided in this call. | |
440 | |
441 Which case occurs depends on where the registerThread thread is when | |
442 the main thread calls register(). | |
443 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
444 return 0 # indicates that it was okay to call, not that no errors occurred |
100 | 445 |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
446 # If there is a DOM returned .... |
236 | 447 if etreeEl != None: |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
448 # If there's an error, echo it to the console |
236 | 449 if etreeEl.get("errmsg") != None: |
238 | 450 print "Error durring registration at: " +self.path+ " Error: " +etreeEl.get("errmsg") |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
451 if META_DEBUG: print data |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
452 if META_DEBUG: print |
100 | 453 """ |
454 No special handling is required. If the registration worked, id, cookie, and interval | |
455 can be stored and used for the next time. | |
456 If an error occurred, then the Meta will delete us and we need to re-register as | |
457 a new server. The way to indicate this is with a "0" id and "0" cookie sent to | |
458 the server during the next registration. Since that's what the server returns to | |
459 us on an error anyway, we just store them and the next registration will | |
460 automatically be set up as a new one. | |
461 | |
462 Unless the server calls register() itself in the meantime. Of course, that's okay | |
463 too, because a success on THAT register() call will set up the next one to use | |
464 the issued id and cookie. | |
465 | |
466 The interval is stored unconditionally for similar reasons. If there's an error, | |
467 the interval will be less than 1, and the main thread's while loop will reset it | |
468 to 6 seconds for the next retry. | |
469 Is it wrong to have a method where there's more comments than code? :) | |
470 """ | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
471 try: |
135 | 472 self.interval = int(etreeEl.get("interval")) |
473 self.id = etreeEl.get("id") | |
474 self.cookie = etreeEl.get("cookie") | |
236 | 475 #if etreeEl.get("errmsg") == None: updateMetaCache(xml_dom) |
476 except Exception, e: | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
477 if META_DEBUG: print |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
478 if META_DEBUG: print "OOPS! Is the Meta okay? It should be returning an id, cookie, and interval." |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
479 if META_DEBUG: print "Check to see what it really returned.\n" |
236 | 480 if META_DEBUG: print e |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
481 # Let xml_dom get garbage collected |
135 | 482 try: xml_dom.unlink() |
483 except: pass | |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
484 else: # else if no DOM is returned from get_server_dom() |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
485 print "Error - no DOM constructed from Meta message!" |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
486 return 0 # Let caller know it was okay to call us |
135 | 487 finally: self.rlock.release() |
0
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
488 # End of class registerThread |
4385a7d0efd1
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff
changeset
|
489 ################################################################################ |