annotate 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
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:
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
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
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
37 from orpg.orpgCore import component
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
38 from orpg.tools.validate import validate
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
39 from orpg.dirpath import dir_struct
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
40
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
41 import urllib, time, sys, traceback, re
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
42
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
43 from threading import *
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
44 from random import uniform
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
45 from urllib import urlopen, urlencode
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
46 from orpg.tools.orpg_log import debug
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
47
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
48 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
49 metacache_lock = RLock()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
50
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
51 def get_server_dom(data=None,path=None, string=False):
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
52 # post data at server and get the resulting DOM
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
53 #if path == None:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
54 # get meta server URI
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
55 # path = getMetaServerList()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
56
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
57 # POST the data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
58 if META_DEBUG:
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 "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
61 print "=========================================="
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
62 print data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
63 print
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
64 recvdata = urlopen(path, data)
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
65 etreeEl = parse(recvdata)
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
66 etreeEl = etreeEl.getroot()
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
67 data = tostring(etreeEl)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
68
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
69 # 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
70 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
71 mo = p.search(data)
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
72 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
73
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
74 if META_DEBUG:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
75 print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
76 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
77 print "==============================================="
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
78 print data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
79 print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
80 # build dom
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
81 return etreeEl
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
82
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
83 def post_server_data(name, realHostName=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
84 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
85 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
86 "act":"new",
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
87 "REMOTE_ADDR": realHostName })
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
88 # print "Letting meta server decide the hostname to list..."
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
89 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
90 "server_data[version]":PROTOCOL_VERSION,
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
91 "act":"new"})
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
92 path = component.get('settings').get('MetaServerBaseURL') #getMetaServerList()
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
93 etreeEl = get_server_dom(data, path)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
94 return int(etreeEl.get('id'))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
95
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
96 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
97 # 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
98 # handling multiple Metas.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
99 return 0
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
100 #data = urlencode({"id":id,"act":"failed"});
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
101 #xml_dom = get_server_dom(data)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
102 #ret_val = int(xml_dom.getAttribute("return"))
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
103 #return ret_val
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
104
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
105 def remove_server(id):
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
106 data = urlencode({"id":id,"act":"del"});
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
107 etreeEl = get_server_dom(data)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
108 return int(etreeEl.get("return"))
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
109
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
110 def byStartAttribute(first, second):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
111 # This function is used to easily sort a list of nodes by their start time
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
112 # Ensure there is something to sort with for each
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
113 first_start = int(first.get('start')) or 0
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
114 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
115 # Return the result of the cmp function on the two strings
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
116 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
117
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
118 def byNameAttribute(first, second):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
119 # 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
120 # Ensure there is something to sort with for each
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
121 first_name = first.get('name') or ''
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
122 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
123 # 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
124 return cmp(first_name,second_name)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
125
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
126
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
127 def get_server_list(versions=None, sort_by="start"):
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
128 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
129 #all_metas = getMetaServers(versions, False) # get the list of metas
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
130 meta_list = getMetaServerList()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
131 #all_metas.reverse() # The last one checked will take precedence, so reverse the order
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
132 # so that the top one on the actual list is checked last
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
133 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
134
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
135 for meta in meta_list: # check all of the metas
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
136 #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
137 bad_meta = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
138 #print "Getting server list from " + meta + "..."
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
139 try: xml_dom = get_server_dom(data, meta.get('url'))
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
140 except: bad_meta = 1; print "Trouble getting servers from " + meta + "..."
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
141 if bad_meta: continue
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
142 node_list = xml_dom.findall('server')
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
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:
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
145 if not n.get('name'): n.set('name','NO_NAME_GIVEN')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
146 name = n.get('name')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
147 if not n.get('num_users'): n.set('num_users','N/A')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
148 num_users = n.get('num_users')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
149 if not n.get('address'): n.set('address','NO_ADDRESS_GIVEN')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
150 address = n.get('address')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
151 if not n.get('port'): n.set('port','6774')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
152 port = n.get('port')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
158 server_list = Element('servers')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
159 sort_list = return_hash.values()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
160 if sort_by == "start": sort_list.sort(byStartAttribute)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
161 elif sort_by == "name": sort_list.sort(byNameAttribute)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
162 for n in sort_list: server_list.append(n)
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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"
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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])
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
177 metaservers = xml_dom.findall('metaservers')
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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)
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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()
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
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:
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
186 if META_DEBUG: print " Writing: "+str(meta.get('path'))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
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
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
195
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
196 def getMetaServerList():
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
197 # get meta server URL
30
8e77f169f324 Traipse 'OpenRPG' {100219-00}
sirebral
parents: 28
diff changeset
198 url = "http://orpgmeta.appspot.com/"
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
199 try:
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
200 component.get('validate').config_file("settings.xml","default_settings.xml")
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
201 setting = parse(dir_struct["user"]+"settings.xml")
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
202 tree = setting.getroot()
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
203 node_list = tree.getiterator("MetaServers")
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
204 if len(node_list) == 0:
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
205 component.get('frame').add_setting('Meta Servers')
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
206 setting = parse(dir_struct["user"]+"settings.xml")
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
207 metas = parse(dir_struct["user"]+'metaservers.xml').getroot()
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
208 else:
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
209 meta = node_list[0].get("value")
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
210 metas = parse(dir_struct["user"]+meta).getroot()
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
211 meta_list = metas.findall('meta')
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
212 return meta_list
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
213 except Exception,e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
214 print e
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
215 #print "using meta server URI: " + url
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
216 return url
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
217
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
218 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
219 Beginning of Class registerThread
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
220
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
221 A Class to Manage Registration with the Meta2
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
222 Create an instance and call it's start() method
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
223 if you want to be (and stay) registered. This class
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
224 will take care of registering and re-registering as
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
225 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
226
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
227 You may call register() yourself if you wish to change your
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
228 server's name. It will immediately update the Meta. There
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
229 is no need to unregister first.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
230
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
231 Call unregister() when you no longer want to be registered.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
232 This will result in the registerThread dying after
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
233 attempting to immediately remove itself from the Meta.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
234
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
235 If you need to become registered again after that, you
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
236 must create a new instance of class registerThread. Don't
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
237 just try to call register() on the old, dead thread class.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
238 """
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
239
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
240 class registerThread(Thread):
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
241 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
242 Originally, I wrote this as a sub-class of wxThread, but
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
243 A) I couldn't get it to import right
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
244 B) I realized that I want this to be used in a server,
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
245 which I don't want needing wxWindows to run!
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
246
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
247 Because of this fact, there are some methods from wxThread
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
248 that I implemented to minimize changes to the code I had
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
249 just written, i.e. TestDeleteStatus() and Delete()
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
250 """
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
251
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
252 def __init__(self, name=None, realHostName=None, num_users="0",
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
253 MetaPath=None, port=6774, register_callback=None):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
254 Thread.__init__(self, name="registerThread")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
255 self.rlock = RLock() # Re-entrant lock used to make this class thread safe
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
256 self.die_event = Event() # The main loop in run() will wait with timeout on this
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
257 self.name = name or 'Unnamed Server' # Name that the server want's displayed on the Meta
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
258 # But use Unnamed Server if for some crazy reason
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
259 # no name is passed to the constructor
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
260 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
261 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
262 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
263 # indicates a new registration.
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
264 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
265 # indicates a new registration.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
266 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
267 # re-register, in minutes.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
268 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
269 self.port = str(port)
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
270 self.register_callback = register_callback # set a method to call to report result of register
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
271 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
272 This thread will communicate with one and only one
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
273 Meta. If the Meta in ini.xml is changed after
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
274 instantiation, then this instance must be
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
275 unregistered and a new instance instantiated.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
276
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
277 Also, if MetaPath is specified, then use that. Makes
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
278 it easier to have multiple registerThreads going to keep the server registered
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
279 on multiple (compatible) Metas.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
280 """
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
281 if MetaPath == None: self.path = getMetaServerList() # Do this if no Meta specified
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
282 else: self.path = MetaPath
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
283
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
284 def getIdAndCookie(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
285 return self.id, self.cookie
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
286
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
287 def TestDeleteStatus(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
288 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
289 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
290 return self.die_event.isSet()
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
291 finally: self.rlock.release()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
292
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
293 def Delete(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
294 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
295 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
296 self.die_event.set()
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
297 finally: self.rlock.release()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
298
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
299 def run(self):
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
300 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
301 This method gets called by Thread implementation
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
302 when self.start() is called to begin the thread's
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
303 execution
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
304
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
305 We will basically enter a loop that continually
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
306 re-registers this server and sleeps Interval
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
307 minutes until the thread is ordered to die in place
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
308 """
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
309 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
310 # Otherwise, call thread safe register().
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
311 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
312 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
313 # 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
314 # for us, including self.interval.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
315 try:
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
316 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
317
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
318 if self.interval >= 3: # If the number of minutes is one or greater
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
319 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
320 else:
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
321 self.interval = .5 # Otherwise, we probably experienced some kind
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
322 # of error from the Meta in register(). Sleep
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
323 # 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
324
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
325 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
326 # 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
327 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
328
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
329 # 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
330 # 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
331 # calls to Thread.isAlive() return False.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
332
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
333 def unregister(self):
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
334 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
335 This method can (I hope) be called from both within the thread
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
336 and from other threads. It will attempt to unregister this
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
337 server from the Meta database
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
338 When this is either accomplished or has been tried hard enough
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
339 (after which it just makes sense to let the Meta remove the
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
340 entry itself when we don't re-register using this id),
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
341 this method will either cause the thread to immediately die
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
342 (if called from this thread's context) or set the Destroy flag
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
343 (if called from the main thread), a positive test for which will cause
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
344 the code in Entry() to exit() when the thread wakes up and
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
345 checks TestDeleteStatus().
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
346 lock the critical section. The unlock will
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
347 automatically occur at the end of the function in the finally clause
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
348 """
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
349 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
350 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
351 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
352 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
353 # Do the actual unregistering here
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
354 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
355 "server_data[cookie]":self.cookie,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
356 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
357 "act":"unregister"} )
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
358 for path in getMetaServerList():
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
359 try: # this POSTS the request and returns the result
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
360 etreeEl = get_server_dom(data, path.get('url'))
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
361 if xml_dom.get("errmsg"):
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
362 print "Error durring unregistration: " + xml_dom.get("errmsg")
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
363 except:
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
364 if META_DEBUG: print "Problem talking to Meta. Will go ahead and die, letting Meta remove us."
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
365 # 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
366
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
367 # 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
368 # 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
369 # 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
370 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
371 # prep xml_dom for garbage collection
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
372 try: xml_dom.unlink()
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
373 except: pass
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
374 return 0
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
375 finally: self.rlock.release()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
376
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
377 def register(self, name=None, realHostName=None, num_users=None):
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
378 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
379 Designed to handle the registration, both new and
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
380 repeated.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
381
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
382 It is intended to be called once every interval
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
383 (or interval - delta) minutes.
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
384
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
385 lock the critical section. The unlock will
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
386 automatically occur at the end of the function in the finally clause
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
387 """
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
388 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
389 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
390 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
391 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
392
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
393 # Set the server's attibutes, if specified.
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
394 if name: self.name = name
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
395 if num_users != None: self.num_users = num_users
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
396 if realHostName: self.realHostName = realHostName
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
397 # build POST data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
398 if self.realHostName:
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
399 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
400 "server_data[cookie]":self.cookie,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
401 "server_data[name]":self.name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
402 "server_data[port]":self.port,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
403 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
404 "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
405 "act":"register",
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
406 "server_data[address]": self.realHostName } )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
407 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
408 if META_DEBUG: print "Letting meta server decide the hostname to list..."
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
409 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
410 "server_data[cookie]":self.cookie,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
411 "server_data[name]":self.name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
412 "server_data[port]":self.port,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
413 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
414 "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
415 "act":"register"} )
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
416 for path in getMetaServerList():
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
417 try: # this POSTS the request and returns the result
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
418 etreeEl = get_server_dom(data, path.get('url'))
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
419 except:
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
420 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..."
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
421 if META_DEBUG: print data
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
422 if META_DEBUG: print
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
423 self.interval = 0
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
424 """
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
425 If we are in the registerThread thread, then setting interval to 0
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
426 will end up causing a retry in about 6 seconds (see self.run())
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
427 If we are in the main thread, then setting interval to 0 will do one
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
428 of two things:
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
429 1) Do the same as if we were in the registerThread
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
430 2) Cause the next, normally scheduled register() call to use the values
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
431 provided in this call.
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
432
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
433 Which case occurs depends on where the registerThread thread is when
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
434 the main thread calls register().
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
435 """
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
436 return 0 # indicates that it was okay to call, not that no errors occurred
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
437
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
438 # If there is a DOM returned ....
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
439 if etreeEl != None:
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
440 # If there's an error, echo it to the console
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
441 if etreeEl.get("errmsg"):
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
442 print "Error durring registration: " + etreeEl.get("errmsg")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
443 if META_DEBUG: print data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
444 if META_DEBUG: print
18
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
445 """
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
446 No special handling is required. If the registration worked, id, cookie, and interval
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
447 can be stored and used for the next time.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
448 If an error occurred, then the Meta will delete us and we need to re-register as
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
449 a new server. The way to indicate this is with a "0" id and "0" cookie sent to
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
450 the server during the next registration. Since that's what the server returns to
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
451 us on an error anyway, we just store them and the next registration will
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
452 automatically be set up as a new one.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
453
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
454 Unless the server calls register() itself in the meantime. Of course, that's okay
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
455 too, because a success on THAT register() call will set up the next one to use
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
456 the issued id and cookie.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
457
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
458 The interval is stored unconditionally for similar reasons. If there's an error,
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
459 the interval will be less than 1, and the main thread's while loop will reset it
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
460 to 6 seconds for the next retry.
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
461 Is it wrong to have a method where there's more comments than code? :)
97265586402b Traipse 'OpenRPG' {090827-00}
sirebral
parents: 0
diff changeset
462 """
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
463 try:
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
464 self.interval = int(etreeEl.get("interval"))
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
465 self.id = etreeEl.get("id")
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
466 self.cookie = etreeEl.get("cookie")
35
ee890f424e16 Traipse 'OpenRPG' {100505-00}
sirebral
parents: 30
diff changeset
467 #if etreeEl.get("errmsg") == None: updateMetaCache(xml_dom)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
468 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
469 if META_DEBUG: print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
470 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
471 if META_DEBUG: print "Check to see what it really returned.\n"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
472 # Let xml_dom get garbage collected
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
473 try: xml_dom.unlink()
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
474 except: pass
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
475 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
476 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
477 return 0 # Let caller know it was okay to call us
28
ff154cf3350c Traipse 'OpenRPG' {100203-00}
sirebral
parents: 18
diff changeset
478 finally: self.rlock.release()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
479 # End of class registerThread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
480 ################################################################################