annotate orpg/networking/meta_server_lib.py @ 66:c54768cffbd4 ornery-dev

Traipse Dev 'OpenRPG' {090818-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: *Unstable* This is the first wave of Code Refinement updates. Includes new material from Core Beta; new debugger material (partially implemented), beginnings of switch to etree, TerminalWriter, and a little more. open_rpg has been renamed to component; functioning now as component.get(), component.add(), component.delete(). This version has known bugs, specifically with the gametree and nodes. I think the XML files where not removed during testing of Core and switching back.
author sirebral
date Tue, 18 Aug 2009 06:33:37 -0500
parents 4385a7d0efd1
children 449a8900f9ac
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:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
25 # $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
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
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
32 META_DEBUG = 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
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
37 from orpg.orpgCore import *
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
38 from orpg.dirpath import dir_struct
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
39 import urllib
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
40 import orpg.minidom
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
41 from threading import *
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
42 import time
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
43 import sys
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
44 import random
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
45 import traceback
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
46 import re
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
47
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
48 metacache_lock = RLock()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
49
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
50 def get_server_dom(data=None,path=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
51 # post data at server and get the resulting DOM
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
52
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
53 if path == None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
54 # get meta server URI
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
55 path = getMetaServerBaseURL()
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
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
64 file = urllib.urlopen(path, data)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
65 data = file.read()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
66 file.close()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
67
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
68 # 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
69 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
70 mo = p.search(data)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
71 if mo:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
72 data = mo.group(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
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
81 xml = component.get('xml')
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
82 xml_dom = xml.parseXml(data)
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
83 xml_dom = xml_dom._get_documentElement()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
84 return xml_dom
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
85
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
86 def post_server_data( name, realHostName=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
87 # build POST data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
88 ## data = urllib.urlencode( {"server_data[name]":name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
89 ## "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
90 ## "act":"new"} )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
91 ##
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
92 if realHostName:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
93 data = urllib.urlencode( {"server_data[name]":name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
94 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
95 "act":"new",
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
96 "REMOTE_ADDR": realHostName } )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
97
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
98 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
99 #print "Letting meta server decide the hostname to list..."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
100 data = urllib.urlencode( {"server_data[name]":name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
101 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
102 "act":"new"} )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
103
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
104 xml_dom = get_server_dom( data , "http://openrpg.sf.net/openrpg_servers.php")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
105 ret_val = int( xml_dom.getAttribute( "id" ) )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
106 return ret_val
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
107
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
108 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
109 # 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
110 # handling multiple Metas.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
111 return 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
112 # data = urllib.urlencode({"id":id,"act":"failed"});
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
113 # xml_dom = get_server_dom(data)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
114 # ret_val = int(xml_dom.getAttribute("return"))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
115 # return ret_val
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
116
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
117 def remove_server(id):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
118 data = urllib.urlencode({"id":id,"act":"del"});
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
119 xml_dom = get_server_dom(data)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
120 ret_val = int(xml_dom.getAttribute("return"))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
121 return ret_val
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
122
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
123
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
124 def byStartAttribute(first,second):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
125 # This function is used to easily sort a list of nodes
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
126 # by their start time
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
127
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
128 if first.hasAttribute("start"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
129 first_start = int(first.getAttribute("start"))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
130 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
131 first_start = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
132
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
133 if second.hasAttribute("start"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
134 second_start = int(second.getAttribute("start"))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
135 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
136 second_start = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
137
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
138 # 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
139 return cmp(first_start,second_start)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
140
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
141 def byNameAttribute(first,second):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
142 # This function is used to easily sort a list of nodes
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
143 # by their name attribute
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
144
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
145 # Ensure there is something to sort with for each
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
146
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
147 if first.hasAttribute("name"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
148 first_name = str(first.getAttribute("name")).lower()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
149 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
150 first_name = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
151
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
152 if second.hasAttribute("name"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
153 second_name = str(second.getAttribute("name")).lower()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
154 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
155 second_name = ""
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
156
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
157 # 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
158
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
159 return cmp(first_name,second_name)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
160
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
161
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
162 def get_server_list(versions = None,sort_by="start"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
163 data = urllib.urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
164 all_metas = getMetaServers(versions,1) # get the list of metas
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
165 base_meta = getMetaServerBaseURL()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
166
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
167 #all_metas.reverse() # The last one checked will take precedence, so reverse the order
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
168 # so that the top one on the actual list is checked last
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 return_hash = {} # this will end up with an amalgamated list of servers
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
171
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
172 for meta in all_metas: # check all of the metas
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
173
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
174 # get the server's xml from the current meta
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
175 bad_meta = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
176 #print "Getting server list from " + meta + "..."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
177 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
178 xml_dom = get_server_dom(data=data,path=meta)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
179 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
180 #print "Trouble getting servers from " + meta + "..."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
181 bad_meta = 1
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
182
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
183 if bad_meta:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
184 continue
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
185
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
186 if base_meta == meta:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
187 #print "This is our base meta: " + meta
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
188 updateMetaCache(xml_dom)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
189
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
190 node_list = xml_dom.getElementsByTagName('server')
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
191
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
192 if len(node_list): # if there are entries in the node list
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
193 # otherwise, just loop to next meta
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 # for each node found, we're going to check the nodes from prior
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
196 # metas in the list. If a match is found, then use the new values.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
197 for n in node_list:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
198
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
199 # set them from current node
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
200
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
201 if not n.hasAttribute('name'): n.setAttribute('name','NO_NAME_GIVEN')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
202 name = n.getAttribute('name')
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
203 if not n.hasAttribute('num_users'): n.setAttribute('num_users','N/A')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
204 num_users = n.getAttribute('num_users')
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
205 if not n.hasAttribute('address'): n.setAttribute('address','NO_ADDRESS_GIVEN')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
206 address = n.getAttribute('address')
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
207 if not n.hasAttribute('port'): n.setAttribute('port','6774')
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
208 port = n.getAttribute('port')
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
209 n.setAttribute('meta',meta)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
210 end_point = str(address) + ":" + str(port)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
211 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
212 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
213 return_hash[end_point] = n
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
214
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
215 # At this point, we have an amalgamated list of servers
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
216 # Now, we have to construct a new DOM to pass back.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
217
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
218 # Create a servers element
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
219 return_dom = orpg.minidom.Element("servers")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
220
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
221 # get the nodes stored in return_hash
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
222 return_list = return_hash.values()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
223
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
224 # sort them by their name attribute. Uses byNameAttribute()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
225 # defined above as a comparison function
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
226
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
227 if sort_by == "start":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
228 return_list.sort(byStartAttribute)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
229 elif sort_by == "name":
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
230 return_list.sort(byNameAttribute)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
231
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
232 # Add each node to the DOM
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
233 for n in return_list:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
234 return_dom.appendChild(n)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
235 return return_dom
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
236
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
237 ## List Format:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
238 ## <servers>
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
239 ## <server address=? id=? name=? failed_count=? >
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
240 ## </servers>
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
241
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
242 def updateMetaCache(xml_dom):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
243 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
244 if META_DEBUG: print "Updating Meta Server Cache"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
245 metaservers = xml_dom.getElementsByTagName( 'metaservers' ) # pull out the metaservers bit
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
246 if len(metaservers) == 0:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
247 cmetalist = getRawMetaList()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
248 xml_dom = get_server_dom(cmetalist[0])
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
249 metaservers = xml_dom.getElementsByTagName( 'metaservers' )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
250 authoritative = metaservers[0].getAttribute('auth')
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
251 if META_DEBUG: print " Authoritive Meta: "+str(authoritative)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
252 metas = metaservers[0].getElementsByTagName("meta") # get the list of metas
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
253 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
254 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
255 metacache_lock.acquire()
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
256 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
257 for meta in metas:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
258 if META_DEBUG: print " Writing: "+str(meta.getAttribute('path'))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
259 ini.write(str(meta.getAttribute('path')) + " " + str(meta.getAttribute('versions')) + "\n")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
260 ini.close()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
261 finally:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
262 metacache_lock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
263 except Exception, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
264 if META_DEBUG: traceback.print_exc()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
265 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
266
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
267 def getRawMetaList():
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
268 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
269 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
270 metacache_lock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
271 # Read in the metas
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
272 component.get('validate').config_file("metaservers.cache","metaservers.cache")
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
273 ini = open(dir_struct["user"]+"metaservers.cache","r")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
274 metas = ini.readlines()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
275 ini.close()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
276 return metas
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
277 finally:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
278 metacache_lock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
279 except Exception, e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
280 if META_DEBUG: traceback.print_exc()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
281 print "Meta Server Lib: getRawMetaList(): " + str(e)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
282 return []
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 getMetaServers(versions = None, pick_random=0):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
285 # get meta server URLs as a list
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 # versions is a list of acceptable version numbers.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
288 # A False truth value will use getMetaServerBaseURL()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
289
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
290 # set a default if we have weird reading problems
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
291 # default_url = "http://www.openrpg.com/openrpg_servers.php"
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 meta_names = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
294
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
295 if(versions): # If versions are supplied, then look in metaservers.conf
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
296 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
297 # read in the metas from file
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
298 # format of file is one meta entry per line
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
299 # each entry will be the meta url, followed by one or more version numbers that it
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
300 # handle. Generally, this will be either a 1 for the original Meta format, or
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
301 # 2 for the new one.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
302
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
303 # Read in the metas
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
304 metas = getRawMetaList()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
305 #print str(metas)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
306
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
307 # go through each one to check if it should be returned, based on the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
308 # version numbers allowed.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
309 for meta in metas:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
310
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
311 # split the line on whitespace
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
312 # obviously, your meta servers urls shouldn't contain whitespace. duh.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
313 words = meta.split()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
314
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
315 success = 0 # init success flag for version check
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
316
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
317 for version in versions: # run through each allowed version from caller
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
318 if version in words[1:]: # if the allowed version token was found
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
319 success += 1 # then increment the success indicator
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
320
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
321 if success: # if the meta entry is acceptable to the caller
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
322 meta_names.append(words[0]) # add the entry
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
323 if META_DEBUG: print "adding metaserver " + meta
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
324
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
325 # at this point, we should have at least one name from the cache. If not ...
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
326 if not meta_names:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
327 default_meta = getMetaServerBaseURL() # grab the meta from ini.xml
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
328 meta_names.append(default_meta) # add it to the return list
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
329 # print "Warning!!\nNo valid metaservers cached."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
330 # print "Using meta from MetaServerBaseURL: " + default_meta + "\n"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
331 # if we have more than one and want a random one
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
332 elif pick_random:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
333 if META_DEBUG: print "choosing random meta from: " + str(meta_names)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
334 i = int(random.uniform(0,len(meta_names)))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
335 #meta = meta_names[i]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
336 meta_names = [meta_names[i]]
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
337 if META_DEBUG: print "using: " + str(meta_names)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
338 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
339 if META_DEBUG: print "using all metas: " + str(meta_names)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
340 return meta_names
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
341 except Exception,e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
342 print e
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
343 #print "using default meta server URI: " + default_url
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
344 metas = []
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
345 #metas.append(default_url)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
346 return metas # return an empty list
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
347 else: # otherwise, use MetaServerBaseURL()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
348 url = getMetaServerBaseURL()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
349 meta_names.append(url)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
350 return meta_names
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
351
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
352 def getMetaServerBaseURL():
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
353 # get meta server URL
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
354 url = "http://www.openrpg.com/openrpg_servers.php"
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
355 try:
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
356 component.get('validate').config_file("settings.xml","default_settings.xml")
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
357 ini = open(dir_struct["user"]+"settings.xml","r")
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
358 txt = ini.read()
66
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
359 xml = component.get('xml')
c54768cffbd4 Traipse Dev 'OpenRPG' {090818-00}
sirebral
parents: 0
diff changeset
360 tree = xml.parseXml(txt)._get_documentElement()
0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
361 ini.close()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
362 node_list = tree.getElementsByTagName("MetaServerBaseURL")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
363 if node_list:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
364 url = node_list[0].getAttribute("value")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
365
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
366 # allow tree to be collected
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
367 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
368 tree.unlink()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
369 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
370 pass
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
371
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
372 except Exception,e:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
373 print e
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
374 # print "using meta server URI: " + url
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
375 return url
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 #######################################################################################
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
378 # Beginning of Class registerThread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
379 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
380 # A Class to Manage Registration with the Meta2
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
381 # Create an instance and call it's start() method
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
382 # if you want to be (and stay) registered. This class
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
383 # will take care of registering and re-registering as
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
384 # often as necessary to stay in the Meta list.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
385 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
386 # You may call register() yourself if you wish to change your
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
387 # server's name. It will immediately update the Meta. There
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
388 # is no need to unregister first.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
389 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
390 # Call unregister() when you no longer want to be registered.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
391 # This will result in the registerThread dying after
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
392 # attempting to immediately remove itself from the Meta.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
393 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
394 # If you need to become registered again after that, you
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
395 # must create a new instance of class registerThread. Don't
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
396 # just try to call register() on the old, dead thread class.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
397
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
398
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
399 class registerThread(Thread):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
400 # Originally, I wrote this as a sub-class of wxThread, but
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
401 # A) I couldn't get it to import right
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
402 # B) I realized that I want this to be used in a server,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
403 # which I don't want needing wxWindows to run!
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
404 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
405 # Because of this fact, there are some methods from wxThread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
406 # that I implemented to minimize changes to the code I had
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
407 # just written, i.e. TestDeleteStatus() and Delete()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
408
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
409 def __init__(self,name=None,realHostName=None,num_users = "Hmmm",MetaPath=None,port=6774,register_callback=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
410
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
411 Thread.__init__(self,name="registerThread")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
412 self.rlock = RLock() # Re-entrant lock used to make this class thread safe
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
413 self.die_event = Event() # The main loop in run() will wait with timeout on this
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
414 if name:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
415 self.name = name # Name that the server want's displayed on the Meta
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
416 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
417 self.name = "Unnamed server" # But use this if for some crazy reason no name is
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
418 # passed to the constructor
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
419 self.num_users = num_users # the number of users currently on this server
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
420 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
421 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
422 # indicates a new registration.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
423 self.cookie = "0" # cookie 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
424 # indicates a new registration.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
425 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
426 # re-register, in minutes.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
427 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
428 self.port = str(port)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
429 self.register_callback = register_callback # set a method to call to report result of register
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
430 # This thread will communicate with one and only one
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
431 # Meta. If the Meta in ini.xml is changed after
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
432 # instantiation, then this instance must be
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
433 # unregistered and a new instance instantiated.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
434 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
435 # Also, if MetaPath is specified, then use that. Makes
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
436 # it easier to have multiple registerThreads going to keep the server registered
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
437 # on multiple (compatible) Metas.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
438
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
439 if MetaPath == None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
440 self.path = getMetaServerBaseURL() # Do this if no Meta specified
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
441 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
442 self.path = MetaPath
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
443
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
444 def getIdAndCookie(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
445 return self.id, self.cookie
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
446
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
447 def TestDeleteStatus(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
448 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
449 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
450 return self.die_event.isSet()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
451 finally:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
452 self.rlock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
453
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
454 def Delete(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
455 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
456 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
457 self.die_event.set()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
458 finally:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
459 self.rlock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
460
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
461 def run(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
462 # This method gets called by Thread implementation
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
463 # when self.start() is called to begin the thread's
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
464 # execution
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
465 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
466 # We will basically enter a loop that continually
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
467 # re-registers this server and sleeps Interval
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
468 # minutes until the thread is ordered to die in place
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
469 while(not self.TestDeleteStatus()): # Loop while until told to die
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
470 # Otherwise, call thread safe register().
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
471 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
472 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
473
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
474 # 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
475 # for us, including self.interval.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
476 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
477 self.rlock.acquire() # Serialize access to this state information
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
478
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
479 if self.interval >= 3: # If the number of minutes is one or greater
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
480 self.interval -= 1 # wake up with 30 seconds left to re-register
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
481 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
482 self.interval = .5 # Otherwise, we probably experienced some kind
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
483 # of error from the Meta in register(). Sleep
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
484 # for 6 seconds and start from scratch.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
485
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
486 finally: # no matter what, release the lock
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
487 self.rlock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
488 # 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
489 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
490
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
491 # 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
492 # 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
493 # calls to Thread.isAlive() return False.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
494
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
495 def unregister(self):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
496 # This method can (I hope) be called from both within the thread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
497 # and from other threads. It will attempt to unregister this
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
498 # server from the Meta database
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
499 # When this is either accomplished or has been tried hard enough
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
500 # (after which it just makes sense to let the Meta remove the
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
501 # entry itself when we don't re-register using this id),
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
502 # this method will either cause the thread to immediately die
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
503 # (if called from this thread's context) or set the Destroy flag
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
504 # (if called from the main thread), a positive test for which will cause
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
505 # the code in Entry() to exit() when the thread wakes up and
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
506 # checks TestDeleteStatus().
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
507 # lock the critical section. The unlock will
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
508 # automatically occur at the end of the function in the finally clause
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
509 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
510 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
511 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
512 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
513 # Do the actual unregistering here
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
514 data = urllib.urlencode( {"server_data[id]":self.id,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
515 "server_data[cookie]":self.cookie,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
516 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
517 "act":"unregister"} )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
518 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
519 xml_dom = get_server_dom(data=data, path=self.path) # this POSTS the request and returns the result
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
520 if xml_dom.hasAttribute("errmsg"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
521 print "Error durring unregistration: " + xml_dom.getAttribute("errmsg")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
522 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
523 if META_DEBUG: print "Problem talking to Meta. Will go ahead and die, letting Meta remove us."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
524 # 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
525
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
526 # 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
527 # 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
528 # 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
529 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
530 # prep xml_dom for garbage collection
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
531 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
532 xml_dom.unlink()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
533 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
534 pass
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
535 return 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
536 finally:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
537 self.rlock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
538
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
539 def register(self, name=None, realHostName=None, num_users=None):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
540 # Designed to handle the registration, both new and
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
541 # repeated.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
542 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
543 # It is intended to be called once every interval
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
544 # (or interval - delta) minutes.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
545
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
546 # lock the critical section. The unlock will
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
547 # automatically occur at the end of the function in the finally clause
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
548 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
549 self.rlock.acquire()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
550 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
551 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
552
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
553 # Set the server's attibutes, if specified.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
554 if name:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
555 self.name = name
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
556 if num_users != None:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
557 self.num_users = num_users
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
558 if realHostName:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
559 self.realHostName = realHostName
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
560 # build POST data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
561 if self.realHostName:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
562 data = urllib.urlencode( {"server_data[id]":self.id,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
563 "server_data[cookie]":self.cookie,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
564 "server_data[name]":self.name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
565 "server_data[port]":self.port,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
566 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
567 "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
568 "act":"register",
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
569 "server_data[address]": self.realHostName } )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
570 else:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
571 if META_DEBUG: print "Letting meta server decide the hostname to list..."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
572 data = urllib.urlencode( {"server_data[id]":self.id,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
573 "server_data[cookie]":self.cookie,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
574 "server_data[name]":self.name,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
575 "server_data[port]":self.port,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
576 "server_data[version]":PROTOCOL_VERSION,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
577 "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
578 "act":"register"} )
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
579 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
580 xml_dom = get_server_dom(data=data,path=self.path) # this POSTS the request and returns the result
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
581 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
582 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..."
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
583 if META_DEBUG: print data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
584 if META_DEBUG: print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
585 self.interval = 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
586 # If we are in the registerThread thread, then setting interval to 0
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
587 # will end up causing a retry in about 6 seconds (see self.run())
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
588 # If we are in the main thread, then setting interval to 0 will do one
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
589 # of two things:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
590 # 1) Do the same as if we were in the registerThread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
591 # 2) Cause the next, normally scheduled register() call to use the values
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
592 # provided in this call.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
593 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
594 # Which case occurs depends on where the registerThread thread is when
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
595 # the main thread calls register().
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
596 return 0 # indicates that it was okay to call, not that no errors occurred
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
597 # If there is a DOM returned ....
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
598 if xml_dom:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
599 # 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
600 if xml_dom.hasAttribute("errmsg"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
601 print "Error durring registration: " + xml_dom.getAttribute("errmsg")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
602 if META_DEBUG: print data
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
603 if META_DEBUG: print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
604 # No special handling is required. If the registration worked, id, cookie, and interval
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
605 # can be stored and used for the next time.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
606 # If an error occurred, then the Meta will delete us and we need to re-register as
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
607 # a new server. The way to indicate this is with a "0" id and "0" cookie sent to
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
608 # the server during the next registration. Since that's what the server returns to
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
609 # us on an error anyway, we just store them and the next registration will
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
610 # automatically be set up as a new one.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
611 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
612 # Unless the server calls register() itself in the meantime. Of course, that's okay
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
613 # too, because a success on THAT register() call will set up the next one to use
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
614 # the issued id and cookie.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
615 #
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
616 # The interval is stored unconditionally for similar reasons. If there's an error,
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
617 # the interval will be less than 1, and the main thread's while loop will reset it
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
618 # to 6 seconds for the next retry.
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
619 # Is it wrong to have a method where there's more comments than code? :)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
620 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
621 self.interval = int(xml_dom.getAttribute("interval"))
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
622 self.id = xml_dom.getAttribute("id")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
623 self.cookie = xml_dom.getAttribute("cookie")
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
624 if not xml_dom.hasAttribute("errmsg"):
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
625 updateMetaCache(xml_dom)
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
626 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
627 if META_DEBUG: print
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
628 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
629 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
630 # Let xml_dom get garbage collected
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
631 try:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
632 xml_dom.unlink()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
633 except:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
634 pass
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
635 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
636 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
637 return 0 # Let caller know it was okay to call us
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
638 finally:
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
639 self.rlock.release()
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
640 # End of class registerThread
4385a7d0efd1 Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
sirebral
parents:
diff changeset
641 ################################################################################