comparison 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
comparison
equal deleted inserted replaced
65:4840657c23c5 66:c54768cffbd4
32 META_DEBUG = 0 32 META_DEBUG = 0
33 33
34 __version__ = "$Id: meta_server_lib.py,v 1.40 2007/04/04 01:18:42 digitalxero Exp $" 34 __version__ = "$Id: meta_server_lib.py,v 1.40 2007/04/04 01:18:42 digitalxero Exp $"
35 35
36 from orpg.orpg_version import PROTOCOL_VERSION 36 from orpg.orpg_version import PROTOCOL_VERSION
37 from orpg.orpg_xml import * 37 from orpg.orpgCore import *
38 import orpg.dirpath 38 from orpg.dirpath import dir_struct
39 import orpg.tools.validate
40 import urllib 39 import urllib
41 import orpg.minidom 40 import orpg.minidom
42 from threading import * 41 from threading import *
43 import time 42 import time
44 import sys 43 import sys
77 print "Got this string from the Meta at " + path + ":" 76 print "Got this string from the Meta at " + path + ":"
78 print "===============================================" 77 print "==============================================="
79 print data 78 print data
80 print 79 print
81 # build dom 80 # build dom
82 xml_dom = parseXml(data) 81 xml = component.get('xml')
82 xml_dom = xml.parseXml(data)
83 xml_dom = xml_dom._get_documentElement() 83 xml_dom = xml_dom._get_documentElement()
84 return xml_dom 84 return xml_dom
85 85
86 def post_server_data( name, realHostName=None): 86 def post_server_data( name, realHostName=None):
87 # build POST data 87 # build POST data
196 # metas in the list. If a match is found, then use the new values. 196 # metas in the list. If a match is found, then use the new values.
197 for n in node_list: 197 for n in node_list:
198 198
199 # set them from current node 199 # set them from current node
200 200
201 if not n.hasAttribute('name'): 201 if not n.hasAttribute('name'): n.setAttribute('name','NO_NAME_GIVEN')
202 n.setAttribute('name','NO_NAME_GIVEN')
203 name = n.getAttribute('name') 202 name = n.getAttribute('name')
204 if not n.hasAttribute('num_users'): 203 if not n.hasAttribute('num_users'): n.setAttribute('num_users','N/A')
205 n.setAttribute('num_users','N/A')
206 num_users = n.getAttribute('num_users') 204 num_users = n.getAttribute('num_users')
207 if not n.hasAttribute('address'): 205 if not n.hasAttribute('address'): n.setAttribute('address','NO_ADDRESS_GIVEN')
208 n.setAttribute('address','NO_ADDRESS_GIVEN')
209 address = n.getAttribute('address') 206 address = n.getAttribute('address')
210 if not n.hasAttribute('port'): 207 if not n.hasAttribute('port'): n.setAttribute('port','6774')
211 n.setAttribute('port','6774')
212 port = n.getAttribute('port') 208 port = n.getAttribute('port')
213 n.setAttribute('meta',meta) 209 n.setAttribute('meta',meta)
214 end_point = str(address) + ":" + str(port) 210 end_point = str(address) + ":" + str(port)
215 if return_hash.has_key(end_point): 211 if return_hash.has_key(end_point):
216 if META_DEBUG: print "Replacing duplicate server entry at " + end_point 212 if META_DEBUG: print "Replacing duplicate server entry at " + end_point
255 if META_DEBUG: print " Authoritive Meta: "+str(authoritative) 251 if META_DEBUG: print " Authoritive Meta: "+str(authoritative)
256 metas = metaservers[0].getElementsByTagName("meta") # get the list of metas 252 metas = metaservers[0].getElementsByTagName("meta") # get the list of metas
257 if META_DEBUG: print " Meta List ("+str(len(metas))+" servers)" 253 if META_DEBUG: print " Meta List ("+str(len(metas))+" servers)"
258 try: 254 try:
259 metacache_lock.acquire() 255 metacache_lock.acquire()
260 ini = open(orpg.dirpath.dir_struct["user"]+"metaservers.cache","w") 256 ini = open(dir_struct["user"]+"metaservers.cache","w")
261 for meta in metas: 257 for meta in metas:
262 if META_DEBUG: print " Writing: "+str(meta.getAttribute('path')) 258 if META_DEBUG: print " Writing: "+str(meta.getAttribute('path'))
263 ini.write(str(meta.getAttribute('path')) + " " + str(meta.getAttribute('versions')) + "\n") 259 ini.write(str(meta.getAttribute('path')) + " " + str(meta.getAttribute('versions')) + "\n")
264 ini.close() 260 ini.close()
265 finally: 261 finally:
271 def getRawMetaList(): 267 def getRawMetaList():
272 try: 268 try:
273 try: 269 try:
274 metacache_lock.acquire() 270 metacache_lock.acquire()
275 # Read in the metas 271 # Read in the metas
276 orpg.tools.validate.Validate().config_file("metaservers.cache","metaservers.cache") 272 component.get('validate').config_file("metaservers.cache","metaservers.cache")
277 ini = open(orpg.dirpath.dir_struct["user"]+"metaservers.cache","r") 273 ini = open(dir_struct["user"]+"metaservers.cache","r")
278 metas = ini.readlines() 274 metas = ini.readlines()
279 ini.close() 275 ini.close()
280 return metas 276 return metas
281 finally: 277 finally:
282 metacache_lock.release() 278 metacache_lock.release()
355 351
356 def getMetaServerBaseURL(): 352 def getMetaServerBaseURL():
357 # get meta server URL 353 # get meta server URL
358 url = "http://www.openrpg.com/openrpg_servers.php" 354 url = "http://www.openrpg.com/openrpg_servers.php"
359 try: 355 try:
360 orpg.tools.validate.Validate().config_file("settings.xml","default_settings.xml") 356 component.get('validate').config_file("settings.xml","default_settings.xml")
361 ini = open(orpg.dirpath.dir_struct["user"]+"settings.xml","r") 357 ini = open(dir_struct["user"]+"settings.xml","r")
362 txt = ini.read() 358 txt = ini.read()
363 tree = parseXml(txt)._get_documentElement() 359 xml = component.get('xml')
360 tree = xml.parseXml(txt)._get_documentElement()
364 ini.close() 361 ini.close()
365 node_list = tree.getElementsByTagName("MetaServerBaseURL") 362 node_list = tree.getElementsByTagName("MetaServerBaseURL")
366 if node_list: 363 if node_list:
367 url = node_list[0].getAttribute("value") 364 url = node_list[0].getAttribute("value")
368 365