Mercurial > traipse
comparison orpg/networking/meta_server_lib.py @ 35:ee890f424e16 ornery-orc
Traipse 'OpenRPG' {100505-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 (Patch-2)
http://traipse.assembla.com/wiki/show/traipse/Patch-2
New Features:
New Namespace method with two new syntaxes
New Namespace Internal is context sensitive, always!
New Namespace External is 'as narrow as you make it'
New Namespace FutureCheck helps ensure you don't receive an incorrect node
New Namespace 2.0 documentation in the User Manual
New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @!
New Mini Library with minis from Devin Knight
New PluginDB access for URL2Link plugin
New to Forms, they now show their content in Design Mode
New to Update Manager, checks Repo for updates on software start
New to Mini Lib node, change title in design mode
New to Game Tree, never lose a node, appends a number to the end of corrupted trees
New to Server GUI, Traipse Suite's Debug Console
New Warhammer PC Sheet
Updates:
Update to White Board layer, uses a pencil image for color button
Update to Grid Layer, uses a grid image for color button
Update to Chat Window, size of drop down menus
Update to default lobby message
Update to template Text node
Update to 4e PC Sheet node
Update to how display names are acquired
Update to Server, added some 'Pious' technology
Update to features node
Fixes:
Fix to Server GUI startup errors
Fix to Server GUI Rooms tab updating
Fix to Chat and Settings if non existant die roller is picked
Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated
Fix to Alias Lib's Export to Tree, Open, Save features
Fix to alias node, now works properly
Fix to Splitter node, minor GUI cleanup
Fix to Backgrounds not loading through remote loader
Fix to Node name errors
Fix to rolling dice in chat Whispers
Fix to Splitters Sizing issues
Fix to URL2Link plugin, modified regex compilation should remove memory leak
Fix to mapy.py, a roll back due to zoomed grid issues
Fix to whiteboard_handler, Circles work by you clicking the center of the circle
Fix to Servers parse_incoming_dom which was outdated and did not respect XML
Fix to a broken link in the server welcome message
Fix to InterParse and logger requiring traceback
Fix to Update Manager Status Bar
Fix to failed image and erroneous pop up
Fix to Mini Lib node that was preventing use
Fix to plugins that parce dice but did not call InterParse
Fix to nodes for name changing by double click
Fix to Game Tree, node ordering on drag and drop corrected
Fix to Game Tree, corrupted error message was not showing
Fix to Update Manager, checks for internet connection
Fix to Update Manager, Auto Update corrections
Fix to Server GUI's broadcast, room, player messaging
author | sirebral |
---|---|
date | Wed, 05 May 2010 08:55:51 -0500 |
parents | 8e77f169f324 |
children | d02e9197c066 |
comparison
equal
deleted
inserted
replaced
34:1fb663829ef6 | 35:ee890f424e16 |
---|---|
27 # Description: A collection of functions to communicate with the meta server. | 27 # Description: A collection of functions to communicate with the meta server. |
28 # | 28 # |
29 | 29 |
30 | 30 |
31 #added debug flag for meta messages to cut console server spam --Snowdog | 31 #added debug flag for meta messages to cut console server spam --Snowdog |
32 META_DEBUG = 0 | 32 META_DEBUG = False |
33 | 33 |
34 __version__ = "$Id: meta_server_lib.py,v 1.40 2007/04/04 01:18:42 digitalxero Exp $" | 34 __version__ = "$Id: meta_server_lib.py,v 1.40 2007/04/04 01:18:42 digitalxero Exp $" |
35 | 35 |
36 from orpg.orpg_version import PROTOCOL_VERSION | 36 from orpg.orpg_version import PROTOCOL_VERSION |
37 from orpg.orpgCore import component | 37 from orpg.orpgCore import component |
43 from threading import * | 43 from threading import * |
44 from random import uniform | 44 from random import uniform |
45 from urllib import urlopen, urlencode | 45 from urllib import urlopen, urlencode |
46 from orpg.tools.orpg_log import debug | 46 from orpg.tools.orpg_log import debug |
47 | 47 |
48 from xml.etree.ElementTree import Element, fromstring | 48 from xml.etree.ElementTree import Element, fromstring, parse, tostring |
49 metacache_lock = RLock() | 49 metacache_lock = RLock() |
50 | 50 |
51 def get_server_dom(data=None,path=None, string=False): | 51 def get_server_dom(data=None,path=None, string=False): |
52 # post data at server and get the resulting DOM | 52 # post data at server and get the resulting DOM |
53 if path == None: | 53 #if path == None: |
54 # get meta server URI | 54 # get meta server URI |
55 path = getMetaServerBaseURL() | 55 # path = getMetaServerList() |
56 | 56 |
57 # POST the data | 57 # POST the data |
58 if META_DEBUG: | 58 if META_DEBUG: |
59 print | 59 print |
60 print "Sending the following POST info to Meta at " + path + ":" | 60 print "Sending the following POST info to Meta at " + path + ":" |
61 print "==========================================" | 61 print "==========================================" |
62 print data | 62 print data |
63 print | 63 print |
64 file = urlopen(path, data) | 64 recvdata = urlopen(path, data) |
65 data = file.read() | 65 etreeEl = parse(recvdata) |
66 file.close() | 66 etreeEl = etreeEl.getroot() |
67 data = tostring(etreeEl) | |
67 | 68 |
68 # Remove any leading or trailing data. This can happen on some satellite connections | 69 # Remove any leading or trailing data. This can happen on some satellite connections |
69 p = re.compile('(<servers>.*?</servers>)',re.DOTALL|re.IGNORECASE) | 70 p = re.compile('(<servers>.*?</servers>)',re.DOTALL|re.IGNORECASE) |
70 mo = p.search(data) | 71 mo = p.search(data) |
71 if mo: data = mo.group(0) | 72 if mo: data = mo.group(0) |
75 print "Got this string from the Meta at " + path + ":" | 76 print "Got this string from the Meta at " + path + ":" |
76 print "===============================================" | 77 print "===============================================" |
77 print data | 78 print data |
78 print | 79 print |
79 # build dom | 80 # build dom |
80 etreeEl = data | 81 return etreeEl |
81 if not string: return fromstring(etreeEl) | |
82 else: return etreeEl | |
83 | 82 |
84 def post_server_data(name, realHostName=None): | 83 def post_server_data(name, realHostName=None): |
85 if realHostName: data = urlencode({"server_data[name]":name, | 84 if realHostName: data = urlencode({"server_data[name]":name, |
86 "server_data[version]":PROTOCOL_VERSION, | 85 "server_data[version]":PROTOCOL_VERSION, |
87 "act":"new", | 86 "act":"new", |
88 "REMOTE_ADDR": realHostName }) | 87 "REMOTE_ADDR": realHostName }) |
89 # print "Letting meta server decide the hostname to list..." | 88 # print "Letting meta server decide the hostname to list..." |
90 else: data = urlencode({"server_data[name]":name, | 89 else: data = urlencode({"server_data[name]":name, |
91 "server_data[version]":PROTOCOL_VERSION, | 90 "server_data[version]":PROTOCOL_VERSION, |
92 "act":"new"}) | 91 "act":"new"}) |
93 path = component.get('settings').get('MetaServerBaseURL') #getMetaServerBaseURL() | 92 path = component.get('settings').get('MetaServerBaseURL') #getMetaServerList() |
94 etreeEl = get_server_dom(data, path) | 93 etreeEl = get_server_dom(data, path) |
95 return int(etreeEl.get('id')) | 94 return int(etreeEl.get('id')) |
96 | 95 |
97 def post_failed_connection(id,meta=None,address=None,port=None): | 96 def post_failed_connection(id,meta=None,address=None,port=None): |
98 # For now, turning this off. This needs to be re-vamped for | 97 # For now, turning this off. This needs to be re-vamped for |
109 return int(etreeEl.get("return")) | 108 return int(etreeEl.get("return")) |
110 | 109 |
111 def byStartAttribute(first, second): | 110 def byStartAttribute(first, second): |
112 # This function is used to easily sort a list of nodes by their start time | 111 # This function is used to easily sort a list of nodes by their start time |
113 # Ensure there is something to sort with for each | 112 # Ensure there is something to sort with for each |
114 | |
115 first_start = int(first.get('start')) or 0 | 113 first_start = int(first.get('start')) or 0 |
116 second_start = int(second.get('start')) or 0 | 114 second_start = int(second.get('start')) or 0 |
117 | |
118 # Return the result of the cmp function on the two strings | 115 # Return the result of the cmp function on the two strings |
119 return cmp(first_start, second_start) | 116 return cmp(first_start, second_start) |
120 | 117 |
121 def byNameAttribute(first, second): | 118 def byNameAttribute(first, second): |
122 # This function is used to easily sort a list of nodes by their name attribute | 119 # This function is used to easily sort a list of nodes by their name attribute |
123 # Ensure there is something to sort with for each | 120 # Ensure there is something to sort with for each |
124 | |
125 first_name = first.get('name') or '' | 121 first_name = first.get('name') or '' |
126 second_name = second.get('name') or '' | 122 second_name = second.get('name') or '' |
127 | |
128 # Return the result of the cmp function on the two strings | 123 # Return the result of the cmp function on the two strings |
129 return cmp(first_name,second_name) | 124 return cmp(first_name,second_name) |
130 | 125 |
131 | 126 |
132 def get_server_list(versions = None, sort_by="start"): | 127 def get_server_list(versions=None, sort_by="start"): |
133 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) | 128 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) |
134 all_metas = getMetaServers(versions, 1) # get the list of metas | 129 #all_metas = getMetaServers(versions, False) # get the list of metas |
135 base_meta = getMetaServerBaseURL() | 130 meta_list = getMetaServerList() |
136 | |
137 #all_metas.reverse() # The last one checked will take precedence, so reverse the order | 131 #all_metas.reverse() # The last one checked will take precedence, so reverse the order |
138 # so that the top one on the actual list is checked last | 132 # so that the top one on the actual list is checked last |
139 return_hash = {} # this will end up with an amalgamated list of servers | 133 return_hash = {} # this will end up with an amalgamated list of servers |
140 | 134 |
141 for meta in all_metas: # check all of the metas | 135 for meta in meta_list: # check all of the metas |
142 #get the server's xml from the current meta | 136 #get the server's xml from the current meta |
143 bad_meta = 0 | 137 bad_meta = 0 |
144 #print "Getting server list from " + meta + "..." | 138 #print "Getting server list from " + meta + "..." |
145 try: xml_dom = get_server_dom(data=data, path=meta) | 139 try: xml_dom = get_server_dom(data, meta.get('url')) |
146 except: bad_meta = 1 #print "Trouble getting servers from " + meta + "..." | 140 except: bad_meta = 1; print "Trouble getting servers from " + meta + "..." |
147 if bad_meta: continue | 141 if bad_meta: continue |
148 if base_meta == meta: updateMetaCache(xml_dom) #print "This is our base meta: " + meta | |
149 node_list = xml_dom.findall('server') | 142 node_list = xml_dom.findall('server') |
150 if len(node_list): # if there are entries in the node list | 143 if len(node_list): |
151 # otherwise, just loop to next meta | |
152 | |
153 # for each node found, we're going to check the nodes from prior | |
154 # metas in the list. If a match is found, then use the new values. | |
155 for n in node_list: | 144 for n in node_list: |
156 # set them from current node | |
157 if not n.get('name'): n.set('name','NO_NAME_GIVEN') | 145 if not n.get('name'): n.set('name','NO_NAME_GIVEN') |
158 name = n.get('name') | 146 name = n.get('name') |
159 if not n.get('num_users'): n.set('num_users','N/A') | 147 if not n.get('num_users'): n.set('num_users','N/A') |
160 num_users = n.get('num_users') | 148 num_users = n.get('num_users') |
161 if not n.get('address'): n.set('address','NO_ADDRESS_GIVEN') | 149 if not n.get('address'): n.set('address','NO_ADDRESS_GIVEN') |
165 n.set('meta',meta) | 153 n.set('meta',meta) |
166 end_point = str(address) + ":" + str(port) | 154 end_point = str(address) + ":" + str(port) |
167 if return_hash.has_key(end_point): | 155 if return_hash.has_key(end_point): |
168 if META_DEBUG: print "Replacing duplicate server entry at " + end_point | 156 if META_DEBUG: print "Replacing duplicate server entry at " + end_point |
169 return_hash[end_point] = n | 157 return_hash[end_point] = n |
170 | |
171 # At this point, we have an amalgamated list of servers | |
172 # Now, we have to construct a new DOM to pass back. | |
173 | |
174 # Create a servers element | |
175 server_list = Element('servers') | 158 server_list = Element('servers') |
176 | |
177 # get the nodes stored in return_hash | |
178 sort_list = return_hash.values() | 159 sort_list = return_hash.values() |
179 | |
180 # sort them by their name attribute. Uses byNameAttribute() | |
181 # defined above as a comparison function | |
182 if sort_by == "start": sort_list.sort(byStartAttribute) | 160 if sort_by == "start": sort_list.sort(byStartAttribute) |
183 elif sort_by == "name": sort_list.sort(byNameAttribute) | 161 elif sort_by == "name": sort_list.sort(byNameAttribute) |
184 | |
185 # Add each node to the DOM | |
186 for n in sort_list: server_list.append(n) | 162 for n in sort_list: server_list.append(n) |
187 return server_list | 163 return server_list |
188 | 164 |
189 ## List Format: | 165 ## List Format: |
190 ## <servers> | 166 ## <servers> |
214 metacache_lock.release() | 190 metacache_lock.release() |
215 except Exception, e: | 191 except Exception, e: |
216 if META_DEBUG: traceback.print_exc() | 192 if META_DEBUG: traceback.print_exc() |
217 print "Meta Server Lib: UpdateMetaCache(): " + str(e) | 193 print "Meta Server Lib: UpdateMetaCache(): " + str(e) |
218 | 194 |
219 def getRawMetaList(path=None): | 195 |
220 ### Alpha ### | 196 def getMetaServerList(): |
221 """This code will allow for a list of metas to be created. Future developement will more integrate the list of metas""" | |
222 if path != None: | |
223 metas = [] | |
224 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) | |
225 xml_dom = get_server_dom(data, path) | |
226 node_list = fromstring(xml_dom).findall('meta_server') | |
227 if len(node_list): | |
228 for n in node_list: | |
229 metas.append(n.get('path')) | |
230 return metas | |
231 try: | |
232 try: | |
233 metacache_lock.acquire() | |
234 # Read in the metas | |
235 validate.config_file("metaservers.cache","metaservers.cache") | |
236 ini = open(dir_struct["user"]+"metaservers.cache","r") | |
237 metas = ini.readlines() | |
238 ini.close() | |
239 return metas | |
240 finally: | |
241 metacache_lock.release() | |
242 except Exception, e: | |
243 if META_DEBUG: traceback.print_exc() | |
244 print "Meta Server Lib: getRawMetaList(): " + str(e) | |
245 return [] | |
246 | |
247 def getMetaServers(versions = None, pick_random=0): | |
248 """ | |
249 get meta server URLs as a list | |
250 versions is a list of acceptable version numbers. | |
251 A False truth value will use getMetaServerBaseURL() | |
252 set a default if we have weird reading problems | |
253 default_url = "http://www.openrpg.com/openrpg_servers.php" | |
254 """ | |
255 | |
256 ### Pre Alpha Design ### | |
257 """ Here is how to handle Multiple Meta servers, and probably the best way to do it. Create an XML file that contains nodes with the various servers. Users will grab that meta data and have the option to connect to multiple meta servers which will allow them to find all the rooms. A check box should be used so if one server faile the users can continue without much lag. When creating a server hosts will need to select a meta to go too. This should be in the final of Ornery Orc.""" | |
258 meta_names = [] | |
259 if(versions): # If versions are supplied, then look in metaservers.conf | |
260 try: | |
261 """ | |
262 read in the metas from file | |
263 format of file is one meta entry per line | |
264 each entry will be the meta url, followed by one or more version numbers that it | |
265 handle. Generally, this will be either a 1 for the original Meta format, or | |
266 2 for the new one. | |
267 """ | |
268 # Read in the metas | |
269 #Adding a path object will attempt to look for a meta_network. | |
270 metas = getRawMetaList() | |
271 | |
272 # go through each one to check if it should be returned, based on the | |
273 # version numbers allowed. | |
274 for meta in metas: | |
275 # split the line on whitespace | |
276 # obviously, your meta servers urls shouldn't contain whitespace. duh. | |
277 words = meta.split() | |
278 success = 0 # init success flag for version check | |
279 for version in versions: # run through each allowed version from caller | |
280 if version in words[1:]: # if the allowed version token was found | |
281 success += 1 # then increment the success indicator | |
282 if success: # if the meta entry is acceptable to the caller | |
283 meta_names.append(words[0]) # add the entry | |
284 if META_DEBUG: print "adding metaserver " + meta | |
285 | |
286 # at this point, we should have at least one name from the cache. If not ... | |
287 if not meta_names: | |
288 default_meta = getMetaServerBaseURL() # grab the meta from ini.xml | |
289 meta_names.append(default_meta) # add it to the return list | |
290 # print "Warning!!\nNo valid metaservers cached." | |
291 # print "Using meta from MetaServerBaseURL: " + default_meta + "\n" | |
292 # if we have more than one and want a random one | |
293 elif pick_random: | |
294 if META_DEBUG: print "choosing random meta from: " + str(meta_names) | |
295 i = int(uniform(0,len(meta_names))) | |
296 #meta = meta_names[i] | |
297 meta_names = [meta_names[i]] | |
298 if META_DEBUG: print "using: " + str(meta_names) | |
299 else: | |
300 if META_DEBUG: print "using all metas: " + str(meta_names) | |
301 return meta_names | |
302 except Exception,e: | |
303 print e | |
304 #print "using default meta server URI: " + default_url | |
305 metas = [] | |
306 #metas.append(default_url) | |
307 return metas # return an empty list | |
308 else: # otherwise, use MetaServerBaseURL() | |
309 url = getMetaServerBaseURL() | |
310 meta_names.append(url) | |
311 return meta_names | |
312 | |
313 def getMetaServerBaseURL(): | |
314 # get meta server URL | 197 # get meta server URL |
315 url = "http://orpgmeta.appspot.com/" | 198 url = "http://orpgmeta.appspot.com/" |
316 try: | 199 try: |
317 component.get('validate').config_file("settings.xml","default_settings.xml") | 200 component.get('validate').config_file("settings.xml","default_settings.xml") |
318 ini = open(dir_struct["user"]+"settings.xml","r") | 201 setting = parse(dir_struct["user"]+"settings.xml") |
319 txt = ini.read() | 202 tree = setting.getroot() |
320 xml = component.get('xml') | 203 node_list = tree.getiterator("MetaServers") |
321 tree = xml.parseXml(txt)._get_documentElement() | 204 if len(node_list) == 0: |
322 ini.close() | 205 component.get('frame').add_setting('Meta Servers') |
323 node_list = tree.getElementsByTagName("MetaServerBaseURL") | 206 setting = parse(dir_struct["user"]+"settings.xml") |
324 if node_list: | 207 metas = parse(dir_struct["user"]+'metaservers.xml').getroot() |
325 url = node_list[0].getAttribute("value") | 208 else: |
326 print url | 209 meta = node_list[0].get("value") |
327 # allow tree to be collected | 210 metas = parse(dir_struct["user"]+meta).getroot() |
328 try: tree.unlink() | 211 meta_list = metas.findall('meta') |
329 except: pass | 212 return meta_list |
330 | |
331 except Exception,e: | 213 except Exception,e: |
332 print e | 214 print e |
333 #print "using meta server URI: " + url | 215 #print "using meta server URI: " + url |
334 return url | 216 return url |
335 | 217 |
394 | 276 |
395 Also, if MetaPath is specified, then use that. Makes | 277 Also, if MetaPath is specified, then use that. Makes |
396 it easier to have multiple registerThreads going to keep the server registered | 278 it easier to have multiple registerThreads going to keep the server registered |
397 on multiple (compatible) Metas. | 279 on multiple (compatible) Metas. |
398 """ | 280 """ |
399 if MetaPath == None: self.path = getMetaServerBaseURL() # Do this if no Meta specified | 281 if MetaPath == None: self.path = getMetaServerList() # Do this if no Meta specified |
400 else: self.path = MetaPath | 282 else: self.path = MetaPath |
401 | 283 |
402 def getIdAndCookie(self): | 284 def getIdAndCookie(self): |
403 return self.id, self.cookie | 285 return self.id, self.cookie |
404 | 286 |
467 try: | 349 try: |
468 self.rlock.acquire() | 350 self.rlock.acquire() |
469 if not self.isAlive(): # check to see if this thread is dead | 351 if not self.isAlive(): # check to see if this thread is dead |
470 return 1 # If so, return an error result | 352 return 1 # If so, return an error result |
471 # Do the actual unregistering here | 353 # Do the actual unregistering here |
472 data = urlencode( {"server_data[id]":self.id, | 354 data = urlencode( { "server_data[id]":self.id, |
473 "server_data[cookie]":self.cookie, | 355 "server_data[cookie]":self.cookie, |
474 "server_data[version]":PROTOCOL_VERSION, | 356 "server_data[version]":PROTOCOL_VERSION, |
475 "act":"unregister"} ) | 357 "act":"unregister"} ) |
476 try: # this POSTS the request and returns the result | 358 for path in getMetaServerList(): |
477 xml_dom = get_server_dom(data=data, path=self.path) | 359 try: # this POSTS the request and returns the result |
478 if xml_dom.get("errmsg"): | 360 etreeEl = get_server_dom(data, path.get('url')) |
479 print "Error durring unregistration: " + xml_dom.get("errmsg") | 361 if xml_dom.get("errmsg"): |
480 except: | 362 print "Error durring unregistration: " + xml_dom.get("errmsg") |
481 if META_DEBUG: print "Problem talking to Meta. Will go ahead and die, letting Meta remove us." | 363 except: |
364 if META_DEBUG: print "Problem talking to Meta. Will go ahead and die, letting Meta remove us." | |
482 # If there's an error, echo it to the console | 365 # If there's an error, echo it to the console |
483 | 366 |
484 # No special handling is required. If the de-registration worked we're done. If | 367 # No special handling is required. If the de-registration worked we're done. If |
485 # not, then it's because we've already been removed or have a bad cookie. Either | 368 # not, then it's because we've already been removed or have a bad cookie. Either |
486 # way, we can't do anything else, so die. | 369 # way, we can't do anything else, so die. |
511 if name: self.name = name | 394 if name: self.name = name |
512 if num_users != None: self.num_users = num_users | 395 if num_users != None: self.num_users = num_users |
513 if realHostName: self.realHostName = realHostName | 396 if realHostName: self.realHostName = realHostName |
514 # build POST data | 397 # build POST data |
515 if self.realHostName: | 398 if self.realHostName: |
516 data = urlencode( {"server_data[id]":self.id, | 399 data = urlencode( { "server_data[id]":self.id, |
517 "server_data[cookie]":self.cookie, | 400 "server_data[cookie]":self.cookie, |
518 "server_data[name]":self.name, | 401 "server_data[name]":self.name, |
519 "server_data[port]":self.port, | 402 "server_data[port]":self.port, |
520 "server_data[version]":PROTOCOL_VERSION, | 403 "server_data[version]":PROTOCOL_VERSION, |
521 "server_data[num_users]":self.num_users, | 404 "server_data[num_users]":self.num_users, |
522 "act":"register", | 405 "act":"register", |
523 "server_data[address]": self.realHostName } ) | 406 "server_data[address]": self.realHostName } ) |
524 else: | 407 else: |
525 if META_DEBUG: print "Letting meta server decide the hostname to list..." | 408 if META_DEBUG: print "Letting meta server decide the hostname to list..." |
526 data = urlencode( {"server_data[id]":self.id, | 409 data = urlencode( { "server_data[id]":self.id, |
527 "server_data[cookie]":self.cookie, | 410 "server_data[cookie]":self.cookie, |
528 "server_data[name]":self.name, | 411 "server_data[name]":self.name, |
529 "server_data[port]":self.port, | 412 "server_data[port]":self.port, |
530 "server_data[version]":PROTOCOL_VERSION, | 413 "server_data[version]":PROTOCOL_VERSION, |
531 "server_data[num_users]":self.num_users, | 414 "server_data[num_users]":self.num_users, |
532 "act":"register"} ) | 415 "act":"register"} ) |
533 try: # this POSTS the request and returns the result | 416 for path in getMetaServerList(): |
534 etreeEl = get_server_dom(data=data, path=self.path) | 417 try: # this POSTS the request and returns the result |
535 except: | 418 etreeEl = get_server_dom(data, path.get('url')) |
536 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..." | 419 except: |
537 if META_DEBUG: print data | 420 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..." |
538 if META_DEBUG: print | 421 if META_DEBUG: print data |
539 self.interval = 0 | 422 if META_DEBUG: print |
540 """ | 423 self.interval = 0 |
541 If we are in the registerThread thread, then setting interval to 0 | 424 """ |
542 will end up causing a retry in about 6 seconds (see self.run()) | 425 If we are in the registerThread thread, then setting interval to 0 |
543 If we are in the main thread, then setting interval to 0 will do one | 426 will end up causing a retry in about 6 seconds (see self.run()) |
544 of two things: | 427 If we are in the main thread, then setting interval to 0 will do one |
545 1) Do the same as if we were in the registerThread | 428 of two things: |
546 2) Cause the next, normally scheduled register() call to use the values | 429 1) Do the same as if we were in the registerThread |
547 provided in this call. | 430 2) Cause the next, normally scheduled register() call to use the values |
548 | 431 provided in this call. |
549 Which case occurs depends on where the registerThread thread is when | 432 |
550 the main thread calls register(). | 433 Which case occurs depends on where the registerThread thread is when |
551 """ | 434 the main thread calls register(). |
552 return 0 # indicates that it was okay to call, not that no errors occurred | 435 """ |
436 return 0 # indicates that it was okay to call, not that no errors occurred | |
553 | 437 |
554 # If there is a DOM returned .... | 438 # If there is a DOM returned .... |
555 if etreeEl: | 439 if etreeEl != None: |
556 # If there's an error, echo it to the console | 440 # If there's an error, echo it to the console |
557 if etreeEl.get("errmsg"): | 441 if etreeEl.get("errmsg"): |
558 print "Error durring registration: " + etreeEl.get("errmsg") | 442 print "Error durring registration: " + etreeEl.get("errmsg") |
559 if META_DEBUG: print data | 443 if META_DEBUG: print data |
560 if META_DEBUG: print | 444 if META_DEBUG: print |
578 """ | 462 """ |
579 try: | 463 try: |
580 self.interval = int(etreeEl.get("interval")) | 464 self.interval = int(etreeEl.get("interval")) |
581 self.id = etreeEl.get("id") | 465 self.id = etreeEl.get("id") |
582 self.cookie = etreeEl.get("cookie") | 466 self.cookie = etreeEl.get("cookie") |
583 if not etreeEl.get("errmsg"): updateMetaCache(xml_dom) | 467 #if etreeEl.get("errmsg") == None: updateMetaCache(xml_dom) |
584 except: | 468 except: |
585 if META_DEBUG: print | 469 if META_DEBUG: print |
586 if META_DEBUG: print "OOPS! Is the Meta okay? It should be returning an id, cookie, and interval." | 470 if META_DEBUG: print "OOPS! Is the Meta okay? It should be returning an id, cookie, and interval." |
587 if META_DEBUG: print "Check to see what it really returned.\n" | 471 if META_DEBUG: print "Check to see what it really returned.\n" |
588 # Let xml_dom get garbage collected | 472 # Let xml_dom get garbage collected |