Mercurial > traipse_dev
comparison orpg/networking/meta_server_lib.py @ 124:8827271fbe1b alpha
Traipse Alpha 'OpenRPG' {091001-01}
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 (Cleaning up for Beta)
Added Bookmarks
Fix to Remote Admin Commands
Minor fix to text based Server
Fix to Pretty Print, from Core
Fix to Splitter Nodes not being created
Fix to massive amounts of images loading, from Core
Added 'boot' command to remote admin
Added confirmation window for sent nodes
Minor changes to allow for portability to an OpenSUSE linux OS
Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG
Zoom Mouse plugin added
Images added to Plugin UI
Switching to Element Tree
Map efficiency, from FlexiRPG
Added Status Bar to Update Manager
default_manifest.xml renamed to default_upmana.xml
Cleaner clode for saved repositories
New TrueDebug Class in orpg_log (See documentation for usage)
Mercurial's hgweb folder is ported to upmana
Happy Halloween!
author | sirebral |
---|---|
date | Sun, 01 Nov 2009 11:36:14 -0600 |
parents | 36919b8a3ef9 |
children | 06f10429eedc |
comparison
equal
deleted
inserted
replaced
123:174658f839c0 | 124:8827271fbe1b |
---|---|
35 | 35 |
36 from orpg.orpg_version import PROTOCOL_VERSION | 36 from orpg.orpg_version import PROTOCOL_VERSION |
37 from orpg.orpgCore import component | 37 from orpg.orpgCore import component |
38 from orpg.tools.validate import validate | 38 from orpg.tools.validate import validate |
39 from orpg.dirpath import dir_struct | 39 from orpg.dirpath import dir_struct |
40 import urllib | 40 |
41 import orpg.minidom | 41 import urllib, time, sys, traceback, re |
42 #import orpg.minidom | |
43 | |
42 from threading import * | 44 from threading import * |
43 import time | 45 from random import uniform |
44 import sys | 46 from urllib import urlopen, urlencode |
45 import random | 47 from orpg.tools.orpg_log import debug |
46 import traceback | |
47 import re | |
48 | 48 |
49 from xml.etree.ElementTree import Element, fromstring | 49 from xml.etree.ElementTree import Element, fromstring |
50 | 50 |
51 metacache_lock = RLock() | 51 metacache_lock = RLock() |
52 | 52 |
53 def get_server_dom(data=None,path=None): | 53 def get_server_dom(data=None,path=None, string=False): |
54 # post data at server and get the resulting DOM | 54 # post data at server and get the resulting DOM |
55 | 55 #debug() |
56 if path == None: | 56 if path == None: |
57 # get meta server URI | 57 # get meta server URI |
58 path = getMetaServerBaseURL() | 58 path = getMetaServerBaseURL() |
59 | 59 |
60 # POST the data | 60 # POST the data |
62 print | 62 print |
63 print "Sending the following POST info to Meta at " + path + ":" | 63 print "Sending the following POST info to Meta at " + path + ":" |
64 print "==========================================" | 64 print "==========================================" |
65 print data | 65 print data |
66 print | 66 print |
67 file = urllib.urlopen(path, data) | 67 file = urlopen(path, data) |
68 data = file.read() | 68 data = file.read() |
69 file.close() | 69 file.close() |
70 | 70 |
71 # Remove any leading or trailing data. This can happen on some satellite connections | 71 # Remove any leading or trailing data. This can happen on some satellite connections |
72 p = re.compile('(<servers>.*?</servers>)',re.DOTALL|re.IGNORECASE) | 72 p = re.compile('(<servers>.*?</servers>)',re.DOTALL|re.IGNORECASE) |
79 print "===============================================" | 79 print "===============================================" |
80 print data | 80 print data |
81 print | 81 print |
82 # build dom | 82 # build dom |
83 etreeEl = data | 83 etreeEl = data |
84 return etreeEl | 84 if not string: return fromstring(etreeEl) |
85 else: return etreeEl | |
85 | 86 |
86 def post_server_data(name, realHostName=None): | 87 def post_server_data(name, realHostName=None): |
87 if realHostName: data = urllib.urlencode({"server_data[name]":name, | 88 #debug() |
89 if realHostName: data = urlencode({"server_data[name]":name, | |
88 "server_data[version]":PROTOCOL_VERSION, | 90 "server_data[version]":PROTOCOL_VERSION, |
89 "act":"new", | 91 "act":"new", |
90 "REMOTE_ADDR": realHostName }) | 92 "REMOTE_ADDR": realHostName }) |
91 # print "Letting meta server decide the hostname to list..." | 93 # print "Letting meta server decide the hostname to list..." |
92 else: data = urllib.urlencode({"server_data[name]":name, | 94 else: data = urlencode({"server_data[name]":name, |
93 "server_data[version]":PROTOCOL_VERSION, | 95 "server_data[version]":PROTOCOL_VERSION, |
94 "act":"new"}) | 96 "act":"new"}) |
95 path = component.get('settings').get('MetaServerBaseURL') #getMetaServerBaseURL() | 97 path = component.get('settings').get('MetaServerBaseURL') #getMetaServerBaseURL() |
96 etreeEl = get_server_dom(data, path) | 98 etreeEl = get_server_dom(data, path) |
97 return int(etreeEl.get('id')) | 99 return int(etreeEl.get('id')) |
98 | 100 |
99 def post_failed_connection(id,meta=None,address=None,port=None): | 101 def post_failed_connection(id,meta=None,address=None,port=None): |
102 #debug((meta, address, port)) | |
100 # For now, turning this off. This needs to be re-vamped for | 103 # For now, turning this off. This needs to be re-vamped for |
101 # handling multiple Metas. | 104 # handling multiple Metas. |
102 return 0 | 105 return 0 |
103 #data = urllib.urlencode({"id":id,"act":"failed"}); | 106 #data = urlencode({"id":id,"act":"failed"}); |
104 #xml_dom = get_server_dom(data) | 107 #xml_dom = get_server_dom(data) |
105 #ret_val = int(xml_dom.getAttribute("return")) | 108 #ret_val = int(xml_dom.getAttribute("return")) |
106 #return ret_val | 109 #return ret_val |
107 | 110 |
108 def remove_server(id): | 111 def remove_server(id): |
109 data = urllib.urlencode({"id":id,"act":"del"}); | 112 #debug(id) |
113 data = urlencode({"id":id,"act":"del"}); | |
110 etreeEl = get_server_dom(data) | 114 etreeEl = get_server_dom(data) |
111 return int(etreeEl.get("return")) | 115 return int(etreeEl.get("return")) |
112 | 116 |
113 def byStartAttribute(first, second): | 117 def byStartAttribute(first, second): |
114 # This function is used to easily sort a list of nodes by their start time | 118 # This function is used to easily sort a list of nodes by their start time |
130 # Return the result of the cmp function on the two strings | 134 # Return the result of the cmp function on the two strings |
131 return cmp(first_name,second_name) | 135 return cmp(first_name,second_name) |
132 | 136 |
133 | 137 |
134 def get_server_list(versions = None, sort_by="start"): | 138 def get_server_list(versions = None, sort_by="start"): |
135 data = urllib.urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) | 139 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) |
136 all_metas = getMetaServers(versions, 1) # get the list of metas | 140 all_metas = getMetaServers(versions, 1) # get the list of metas |
137 base_meta = getMetaServerBaseURL() | 141 base_meta = getMetaServerBaseURL() |
138 | 142 |
139 #all_metas.reverse() # The last one checked will take precedence, so reverse the order | 143 #all_metas.reverse() # The last one checked will take precedence, so reverse the order |
140 # so that the top one on the actual list is checked last | 144 # so that the top one on the actual list is checked last |
146 #print "Getting server list from " + meta + "..." | 150 #print "Getting server list from " + meta + "..." |
147 try: xml_dom = get_server_dom(data=data, path=meta) | 151 try: xml_dom = get_server_dom(data=data, path=meta) |
148 except: bad_meta = 1 #print "Trouble getting servers from " + meta + "..." | 152 except: bad_meta = 1 #print "Trouble getting servers from " + meta + "..." |
149 if bad_meta: continue | 153 if bad_meta: continue |
150 if base_meta == meta: updateMetaCache(xml_dom) #print "This is our base meta: " + meta | 154 if base_meta == meta: updateMetaCache(xml_dom) #print "This is our base meta: " + meta |
151 node_list = fromstring(xml_dom).findall('server') | 155 node_list = xml_dom.findall('server') |
152 if len(node_list): # if there are entries in the node list | 156 if len(node_list): # if there are entries in the node list |
153 # otherwise, just loop to next meta | 157 # otherwise, just loop to next meta |
154 | 158 |
155 # for each node found, we're going to check the nodes from prior | 159 # for each node found, we're going to check the nodes from prior |
156 # metas in the list. If a match is found, then use the new values. | 160 # metas in the list. If a match is found, then use the new values. |
221 def getRawMetaList(path=None): | 225 def getRawMetaList(path=None): |
222 ### Alpha ### | 226 ### Alpha ### |
223 """This code will allow for a list of metas to be created. Future developement will more integrate the list of metas""" | 227 """This code will allow for a list of metas to be created. Future developement will more integrate the list of metas""" |
224 if path != None: | 228 if path != None: |
225 metas = [] | 229 metas = [] |
226 data = urllib.urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) | 230 data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"}) |
227 xml_dom = get_server_dom(data, path) | 231 xml_dom = get_server_dom(data, path) |
228 node_list = fromstring(xml_dom).findall('meta_server') | 232 node_list = fromstring(xml_dom).findall('meta_server') |
229 if len(node_list): | 233 if len(node_list): |
230 for n in node_list: | 234 for n in node_list: |
231 metas.append(n.get('path')) | 235 metas.append(n.get('path')) |
292 # print "Warning!!\nNo valid metaservers cached." | 296 # print "Warning!!\nNo valid metaservers cached." |
293 # print "Using meta from MetaServerBaseURL: " + default_meta + "\n" | 297 # print "Using meta from MetaServerBaseURL: " + default_meta + "\n" |
294 # if we have more than one and want a random one | 298 # if we have more than one and want a random one |
295 elif pick_random: | 299 elif pick_random: |
296 if META_DEBUG: print "choosing random meta from: " + str(meta_names) | 300 if META_DEBUG: print "choosing random meta from: " + str(meta_names) |
297 i = int(random.uniform(0,len(meta_names))) | 301 i = int(uniform(0,len(meta_names))) |
298 #meta = meta_names[i] | 302 #meta = meta_names[i] |
299 meta_names = [meta_names[i]] | 303 meta_names = [meta_names[i]] |
300 if META_DEBUG: print "using: " + str(meta_names) | 304 if META_DEBUG: print "using: " + str(meta_names) |
301 else: | 305 else: |
302 if META_DEBUG: print "using all metas: " + str(meta_names) | 306 if META_DEBUG: print "using all metas: " + str(meta_names) |
468 try: | 472 try: |
469 self.rlock.acquire() | 473 self.rlock.acquire() |
470 if not self.isAlive(): # check to see if this thread is dead | 474 if not self.isAlive(): # check to see if this thread is dead |
471 return 1 # If so, return an error result | 475 return 1 # If so, return an error result |
472 # Do the actual unregistering here | 476 # Do the actual unregistering here |
473 data = urllib.urlencode( {"server_data[id]":self.id, | 477 data = urlencode( {"server_data[id]":self.id, |
474 "server_data[cookie]":self.cookie, | 478 "server_data[cookie]":self.cookie, |
475 "server_data[version]":PROTOCOL_VERSION, | 479 "server_data[version]":PROTOCOL_VERSION, |
476 "act":"unregister"} ) | 480 "act":"unregister"} ) |
477 try: # this POSTS the request and returns the result | 481 try: # this POSTS the request and returns the result |
478 xml_dom = get_server_dom(data=data, path=self.path) | 482 xml_dom = get_server_dom(data=data, path=self.path) |
491 except: pass | 495 except: pass |
492 return 0 | 496 return 0 |
493 finally: self.rlock.release() | 497 finally: self.rlock.release() |
494 | 498 |
495 def register(self, name=None, realHostName=None, num_users=None): | 499 def register(self, name=None, realHostName=None, num_users=None): |
500 #debug((name, realHostName, num_users)) | |
496 """ | 501 """ |
497 Designed to handle the registration, both new and | 502 Designed to handle the registration, both new and |
498 repeated. | 503 repeated. |
499 | 504 |
500 It is intended to be called once every interval | 505 It is intended to be called once every interval |
512 if name: self.name = name | 517 if name: self.name = name |
513 if num_users != None: self.num_users = num_users | 518 if num_users != None: self.num_users = num_users |
514 if realHostName: self.realHostName = realHostName | 519 if realHostName: self.realHostName = realHostName |
515 # build POST data | 520 # build POST data |
516 if self.realHostName: | 521 if self.realHostName: |
517 data = urllib.urlencode( {"server_data[id]":self.id, | 522 data = urlencode( {"server_data[id]":self.id, |
518 "server_data[cookie]":self.cookie, | 523 "server_data[cookie]":self.cookie, |
519 "server_data[name]":self.name, | 524 "server_data[name]":self.name, |
520 "server_data[port]":self.port, | 525 "server_data[port]":self.port, |
521 "server_data[version]":PROTOCOL_VERSION, | 526 "server_data[version]":PROTOCOL_VERSION, |
522 "server_data[num_users]":self.num_users, | 527 "server_data[num_users]":self.num_users, |
523 "act":"register", | 528 "act":"register", |
524 "server_data[address]": self.realHostName } ) | 529 "server_data[address]": self.realHostName } ) |
525 else: | 530 else: |
526 if META_DEBUG: print "Letting meta server decide the hostname to list..." | 531 if META_DEBUG: print "Letting meta server decide the hostname to list..." |
527 data = urllib.urlencode( {"server_data[id]":self.id, | 532 data = urlencode( {"server_data[id]":self.id, |
528 "server_data[cookie]":self.cookie, | 533 "server_data[cookie]":self.cookie, |
529 "server_data[name]":self.name, | 534 "server_data[name]":self.name, |
530 "server_data[port]":self.port, | 535 "server_data[port]":self.port, |
531 "server_data[version]":PROTOCOL_VERSION, | 536 "server_data[version]":PROTOCOL_VERSION, |
532 "server_data[num_users]":self.num_users, | 537 "server_data[num_users]":self.num_users, |
533 "act":"register"} ) | 538 "act":"register"} ) |
534 try: # this POSTS the request and returns the result | 539 try: # this POSTS the request and returns the result |
535 etreeEl = get_server_dom(data=data, path=self.path) | 540 etreeEl = get_server_dom(data=data, path=self.path) |
541 #debug(etreeEl) | |
536 except: | 542 except: |
537 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..." | 543 if META_DEBUG: print "Problem talking to server. Setting interval for retry ..." |
538 if META_DEBUG: print data | 544 if META_DEBUG: print data |
539 if META_DEBUG: print | 545 if META_DEBUG: print |
540 self.interval = 0 | 546 self.interval = 0 |
552 """ | 558 """ |
553 return 0 # indicates that it was okay to call, not that no errors occurred | 559 return 0 # indicates that it was okay to call, not that no errors occurred |
554 | 560 |
555 # If there is a DOM returned .... | 561 # If there is a DOM returned .... |
556 if etreeEl: | 562 if etreeEl: |
563 #debug(etreeEl) | |
557 # If there's an error, echo it to the console | 564 # If there's an error, echo it to the console |
558 if etreeEl.get("errmsg"): | 565 if etreeEl.get("errmsg"): |
559 print "Error durring registration: " + etreeEl.get("errmsg") | 566 print "Error durring registration: " + etreeEl.get("errmsg") |
560 if META_DEBUG: print data | 567 if META_DEBUG: print data |
561 if META_DEBUG: print | 568 if META_DEBUG: print |