changeset 35:ee890f424e16 ornery-orc

Traipse 'OpenRPG' {100505-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Patch-2) http://traipse.assembla.com/wiki/show/traipse/Patch-2 New Features: New Namespace method with two new syntaxes New Namespace Internal is context sensitive, always! New Namespace External is 'as narrow as you make it' New Namespace FutureCheck helps ensure you don't receive an incorrect node New Namespace 2.0 documentation in the User Manual New Namespace plugin, Allows Traipse users to use the Standard syntax !@ :: @! New Mini Library with minis from Devin Knight New PluginDB access for URL2Link plugin New to Forms, they now show their content in Design Mode New to Update Manager, checks Repo for updates on software start New to Mini Lib node, change title in design mode New to Game Tree, never lose a node, appends a number to the end of corrupted trees New to Server GUI, Traipse Suite's Debug Console New Warhammer PC Sheet Updates: Update to White Board layer, uses a pencil image for color button Update to Grid Layer, uses a grid image for color button Update to Chat Window, size of drop down menus Update to default lobby message Update to template Text node Update to 4e PC Sheet node Update to how display names are acquired Update to Server, added some 'Pious' technology Update to features node Fixes: Fix to Server GUI startup errors Fix to Server GUI Rooms tab updating Fix to Chat and Settings if non existant die roller is picked Fix to Dieroller and .open() used with .vs(). Successes are correctly calculated Fix to Alias Lib's Export to Tree, Open, Save features Fix to alias node, now works properly Fix to Splitter node, minor GUI cleanup Fix to Backgrounds not loading through remote loader Fix to Node name errors Fix to rolling dice in chat Whispers Fix to Splitters Sizing issues Fix to URL2Link plugin, modified regex compilation should remove memory leak Fix to mapy.py, a roll back due to zoomed grid issues Fix to whiteboard_handler, Circles work by you clicking the center of the circle Fix to Servers parse_incoming_dom which was outdated and did not respect XML Fix to a broken link in the server welcome message Fix to InterParse and logger requiring traceback Fix to Update Manager Status Bar Fix to failed image and erroneous pop up Fix to Mini Lib node that was preventing use Fix to plugins that parce dice but did not call InterParse Fix to nodes for name changing by double click Fix to Game Tree, node ordering on drag and drop corrected Fix to Game Tree, corrupted error message was not showing Fix to Update Manager, checks for internet connection Fix to Update Manager, Auto Update corrections Fix to Server GUI's broadcast, room, player messaging
author sirebral
date Wed, 05 May 2010 08:55:51 -0500
parents 1fb663829ef6
children d02e9197c066
files orpg/main.py orpg/networking/meta_server_lib.py orpg/networking/mplay_server.py orpg/orpg_version.py orpg/templates/default_metaservers.xml orpg/templates/default_settings.xml orpg/templates/metaservers.cache
diffstat 7 files changed, 79 insertions(+), 187 deletions(-) [+]
line wrap: on
line diff
--- a/orpg/main.py	Tue May 04 10:43:29 2010 -0500
+++ b/orpg/main.py	Wed May 05 08:55:51 2010 -0500
@@ -162,6 +162,11 @@
             settings.add('Tip of the Day', 'tipotday_enabled', '1', '0|1', 'Show Tip of the Day on startup')
             logger.info('New Settings added', True)
             self.TraipseSuiteWarn('debug')
+        if setting == 'Meta Servers':
+            settings.add('Networking', 'MetaServers', 'metaservers.xml', '.xml file', 'Contains a list of Meta Servers')
+            logger.info('New Settings added', True)
+            self.validate.config_file("metaservers.xml","default_metaservers.xml")
+            self.TraipseSuiteWarn('debug')
 
     def get_activeplugins(self):
         try: tmp = self.pluginsFrame.get_activeplugins()
--- a/orpg/networking/meta_server_lib.py	Tue May 04 10:43:29 2010 -0500
+++ b/orpg/networking/meta_server_lib.py	Wed May 05 08:55:51 2010 -0500
@@ -29,7 +29,7 @@
 
 
 #added debug flag for meta messages to cut console server spam --Snowdog
-META_DEBUG = 0
+META_DEBUG = False
 
 __version__ = "$Id: meta_server_lib.py,v 1.40 2007/04/04 01:18:42 digitalxero Exp $"
 
@@ -45,14 +45,14 @@
 from urllib import urlopen, urlencode
 from orpg.tools.orpg_log import debug
 
-from xml.etree.ElementTree import Element, fromstring
+from xml.etree.ElementTree import Element, fromstring, parse, tostring
 metacache_lock = RLock()
 
 def get_server_dom(data=None,path=None, string=False):
     # post data at server and get the resulting DOM
-    if path == None:
+    #if path == None:
         # get meta server URI
-        path = getMetaServerBaseURL()
+    #    path = getMetaServerList()
 
     # POST the data
     if META_DEBUG:
@@ -61,9 +61,10 @@
         print "=========================================="
         print data
         print
-    file = urlopen(path, data)
-    data = file.read()
-    file.close()
+    recvdata = urlopen(path, data)
+    etreeEl = parse(recvdata)
+    etreeEl = etreeEl.getroot()
+    data = tostring(etreeEl)
 
     # Remove any leading or trailing data.  This can happen on some satellite connections
     p = re.compile('(<servers>.*?</servers>)',re.DOTALL|re.IGNORECASE)
@@ -77,9 +78,7 @@
         print data
         print
     # build dom
-    etreeEl = data
-    if not string: return fromstring(etreeEl)
-    else: return etreeEl
+    return etreeEl
 
 def post_server_data(name, realHostName=None):
     if realHostName: data = urlencode({"server_data[name]":name,
@@ -90,7 +89,7 @@
     else: data = urlencode({"server_data[name]":name,
                                   "server_data[version]":PROTOCOL_VERSION,
                                   "act":"new"})
-    path = component.get('settings').get('MetaServerBaseURL') #getMetaServerBaseURL()
+    path = component.get('settings').get('MetaServerBaseURL') #getMetaServerList()
     etreeEl = get_server_dom(data, path)
     return int(etreeEl.get('id'))
 
@@ -111,49 +110,38 @@
 def byStartAttribute(first, second):
     #  This function is used to easily sort a list of nodes by their start time
     # Ensure there is something to sort with for each
-
     first_start = int(first.get('start')) or 0
     second_start = int(second.get('start')) or 0
-
     # Return the result of the cmp function on the two strings
     return cmp(first_start, second_start)
 
 def byNameAttribute(first, second):
     #  This function is used to easily sort a list of nodes by their name attribute
     # Ensure there is something to sort with for each
-
     first_name = first.get('name') or ''
     second_name = second.get('name') or ''
-    
     # Return the result of the cmp function on the two strings
     return cmp(first_name,second_name)
 
 
-def get_server_list(versions = None, sort_by="start"):
+def get_server_list(versions=None, sort_by="start"):
     data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
-    all_metas = getMetaServers(versions, 1)  # get the list of metas
-    base_meta = getMetaServerBaseURL()
-
+    #all_metas = getMetaServers(versions, False)  # get the list of metas
+    meta_list = getMetaServerList()
     #all_metas.reverse()  # The last one checked will take precedence, so reverse the order
                           #  so that the top one on the actual list is checked last
     return_hash = {}      # this will end up with an amalgamated list of servers
 
-    for meta in all_metas: # check all of the metas
+    for meta in meta_list: # check all of the metas
         #get the server's xml from the current meta
         bad_meta = 0
         #print "Getting server list from " + meta + "..."
-        try: xml_dom = get_server_dom(data=data, path=meta)
-        except: bad_meta = 1 #print "Trouble getting servers from " + meta + "..."
+        try: xml_dom = get_server_dom(data, meta.get('url'))
+        except: bad_meta = 1; print "Trouble getting servers from " + meta + "..."
         if bad_meta: continue
-        if base_meta == meta: updateMetaCache(xml_dom) #print "This is our base meta: " + meta
         node_list = xml_dom.findall('server')
-        if len(node_list):  # if there are entries in the node list
-                            #  otherwise, just loop to next meta
-
-            #  for each node found, we're going to check the nodes from prior
-            #  metas in the list.  If a match is found, then use the new values.
+        if len(node_list): 
             for n in node_list:
-                # set them from current node
                 if not n.get('name'): n.set('name','NO_NAME_GIVEN')
                 name = n.get('name')
                 if not n.get('num_users'): n.set('num_users','N/A')
@@ -167,22 +155,10 @@
                 if return_hash.has_key(end_point):
                     if META_DEBUG: print "Replacing duplicate server entry at " + end_point
                 return_hash[end_point] = n
-
-    #  At this point, we have an amalgamated list of servers
-    #  Now, we have to construct a new DOM to pass back.
-
-    #  Create a servers element
     server_list = Element('servers')
-
-    #  get the nodes stored in return_hash
     sort_list = return_hash.values()
-
-    #  sort them by their name attribute.  Uses byNameAttribute()
-    #  defined above as a comparison function
     if sort_by == "start": sort_list.sort(byStartAttribute)
     elif sort_by == "name": sort_list.sort(byNameAttribute)
-
-    #  Add each node to the DOM
     for n in sort_list: server_list.append(n)
     return server_list
 
@@ -216,118 +192,24 @@
         if META_DEBUG: traceback.print_exc()
         print "Meta Server Lib: UpdateMetaCache(): " + str(e)
 
-def getRawMetaList(path=None):
-    ### Alpha ### 
-    """This code will allow for a list of metas to be created.  Future developement  will more integrate the list of metas"""
-    if path != None: 
-        metas = []
-        data = urlencode({"version":PROTOCOL_VERSION,"ports":"%"})
-        xml_dom = get_server_dom(data, path)
-        node_list = fromstring(xml_dom).findall('meta_server')
-        if len(node_list):
-             for n in node_list:
-                 metas.append(n.get('path'))
-        return metas
-    try:
-        try:
-            metacache_lock.acquire()
-            #  Read in the metas
-            validate.config_file("metaservers.cache","metaservers.cache")
-            ini = open(dir_struct["user"]+"metaservers.cache","r")
-            metas = ini.readlines()
-            ini.close()
-            return metas
-        finally:
-            metacache_lock.release()
-    except Exception, e:
-        if META_DEBUG: traceback.print_exc()
-        print "Meta Server Lib: getRawMetaList(): " + str(e)
-        return []
 
-def getMetaServers(versions = None, pick_random=0):
-    """
-     get meta server URLs as a list
-      versions is a list of acceptable version numbers.
-        A False truth value will use getMetaServerBaseURL()
-     set a default if we have weird reading problems
-     default_url = "http://www.openrpg.com/openrpg_servers.php"
-    """
-
-    ### Pre Alpha Design ###
-    """ Here is how to handle Multiple Meta servers, and probably the best way to do it.  Create an XML file that contains nodes with the various servers. Users will grab that meta data and have the option to connect to multiple meta servers which will allow them to find all the rooms.  A check box should be used so if one server faile the users can continue without much lag.  When creating a server hosts will need to select a meta to go too.  This should be in the final of Ornery Orc."""
-    meta_names = []
-    if(versions):  #  If versions are supplied, then look in metaservers.conf
-        try:
-            """
-              read in the metas from file
-              format of file is one meta entry per line
-              each entry will be the meta url, followed by one or more version numbers that it
-              handle.  Generally, this will be either a 1 for the original Meta format, or
-              2 for the new one.
-            """
-            #  Read in the metas
-            #Adding a path object will attempt to look for a meta_network.
-            metas = getRawMetaList()
-
-            # go through each one to check if it should be returned, based on the
-            #   version numbers allowed.
-            for meta in metas:
-                # split the line on whitespace
-                #   obviously, your meta servers urls shouldn't contain whitespace.  duh.
-                words = meta.split()
-                success = 0         #  init success flag for version check
-                for version in versions:    # run through each allowed version from caller
-                    if version in words[1:]:  #  if the allowed version token was found
-                        success += 1          #  then increment the success indicator
-                if success:          #  if the meta entry is acceptable to the caller
-                    meta_names.append(words[0])    #  add the entry
-                    if META_DEBUG: print "adding metaserver " + meta
-
-            #  at this point, we should have at least one name from the cache.  If not ...
-            if not meta_names:
-                default_meta = getMetaServerBaseURL()       # grab the meta from ini.xml
-                meta_names.append(default_meta)             # add it to the return list
-            # print "Warning!!\nNo valid metaservers cached."
-            # print "Using meta from MetaServerBaseURL: " + default_meta + "\n"
-            # if we have more than one and want a random one
-            elif pick_random:
-                if META_DEBUG: print "choosing random meta from: " + str(meta_names)
-                i = int(uniform(0,len(meta_names)))
-                #meta = meta_names[i]
-                meta_names = [meta_names[i]]
-                if META_DEBUG: print "using: " + str(meta_names)
-            else:
-                if META_DEBUG: print "using all metas: " + str(meta_names)
-            return meta_names
-        except Exception,e:
-            print e
-            #print "using default meta server URI: " + default_url
-            metas = []
-            #metas.append(default_url)
-            return metas   # return an empty list
-    else:        #  otherwise, use MetaServerBaseURL()
-        url = getMetaServerBaseURL()
-        meta_names.append(url)
-        return meta_names
-
-def getMetaServerBaseURL():
+def getMetaServerList():
     # get meta server URL
     url = "http://orpgmeta.appspot.com/"
     try:
         component.get('validate').config_file("settings.xml","default_settings.xml")
-        ini = open(dir_struct["user"]+"settings.xml","r")
-        txt = ini.read()
-        xml = component.get('xml')
-        tree = xml.parseXml(txt)._get_documentElement()
-        ini.close()
-        node_list = tree.getElementsByTagName("MetaServerBaseURL")
-        if node_list:
-            url = node_list[0].getAttribute("value")
-        print url
-        # allow tree to be collected
-        try: tree.unlink()
-        except: pass
-
+        setting = parse(dir_struct["user"]+"settings.xml")
+        tree = setting.getroot()
+        node_list = tree.getiterator("MetaServers")
+        if len(node_list) == 0:
+            component.get('frame').add_setting('Meta Servers')
+            setting = parse(dir_struct["user"]+"settings.xml")
+            metas = parse(dir_struct["user"]+'metaservers.xml').getroot()
+        else: 
+            meta = node_list[0].get("value")
+            metas = parse(dir_struct["user"]+meta).getroot()
+        meta_list = metas.findall('meta')
+        return meta_list
     except Exception,e:
         print e
     #print "using meta server URI: " + url
@@ -396,7 +278,7 @@
           it easier to have multiple registerThreads going to keep the server registered
           on multiple (compatible) Metas.
         """
-        if MetaPath == None: self.path = getMetaServerBaseURL()  #  Do this if no Meta specified
+        if MetaPath == None: self.path = getMetaServerList()  #  Do this if no Meta specified
         else: self.path = MetaPath
 
     def getIdAndCookie(self):
@@ -469,16 +351,17 @@
             if not self.isAlive():      #  check to see if this thread is dead
                 return 1                #  If so, return an error result
             #  Do the actual unregistering here
-            data = urlencode( {"server_data[id]":self.id,
+            data = urlencode( {         "server_data[id]":self.id,
                                         "server_data[cookie]":self.cookie,
                                         "server_data[version]":PROTOCOL_VERSION,
                                         "act":"unregister"} )
-            try: # this POSTS the request and returns the result
-                xml_dom = get_server_dom(data=data, path=self.path)  
-                if xml_dom.get("errmsg"):
-                    print "Error durring unregistration:  " + xml_dom.get("errmsg")
-            except:
-                if META_DEBUG: print "Problem talking to Meta.  Will go ahead and die, letting Meta remove us."
+            for path in getMetaServerList():
+                try: # this POSTS the request and returns the result
+                    etreeEl = get_server_dom(data, path.get('url'))
+                    if xml_dom.get("errmsg"):
+                        print "Error durring unregistration:  " + xml_dom.get("errmsg")
+                except:
+                    if META_DEBUG: print "Problem talking to Meta.  Will go ahead and die, letting Meta remove us."
             #  If there's an error, echo it to the console
 
             #  No special handling is required.  If the de-registration worked we're done.  If
@@ -513,7 +396,7 @@
             if realHostName: self.realHostName = realHostName
             # build POST data
             if self.realHostName:
-                data = urlencode( {"server_data[id]":self.id,
+                data = urlencode( {     "server_data[id]":self.id,
                                         "server_data[cookie]":self.cookie,
                                         "server_data[name]":self.name,
                                         "server_data[port]":self.port,
@@ -523,36 +406,37 @@
                                         "server_data[address]": self.realHostName } )
             else:
                 if META_DEBUG:  print "Letting meta server decide the hostname to list..."
-                data = urlencode( {"server_data[id]":self.id,
+                data = urlencode( {     "server_data[id]":self.id,
                                         "server_data[cookie]":self.cookie,
                                         "server_data[name]":self.name,
                                         "server_data[port]":self.port,
                                         "server_data[version]":PROTOCOL_VERSION,
                                         "server_data[num_users]":self.num_users,
                                         "act":"register"} )
-            try: # this POSTS the request and returns the result
-                etreeEl = get_server_dom(data=data, path=self.path)
-            except:
-                if META_DEBUG: print "Problem talking to server.  Setting interval for retry ..."
-                if META_DEBUG: print data
-                if META_DEBUG: print
-                self.interval = 0
-                """
-                  If we are in the registerThread thread, then setting interval to 0
-                  will end up causing a retry in about 6 seconds (see self.run())
-                  If we are in the main thread, then setting interval to 0 will do one
-                  of two things:
-                  1)  Do the same as if we were in the registerThread
-                  2)  Cause the next, normally scheduled register() call to use the values
-                      provided in this call.
-                
-                  Which case occurs depends on where the registerThread thread is when
-                  the main thread calls register().
-                """
-                return 0  # indicates that it was okay to call, not that no errors occurred
+            for path in getMetaServerList():
+                try: # this POSTS the request and returns the result
+                    etreeEl = get_server_dom(data, path.get('url'))
+                except:
+                    if META_DEBUG: print "Problem talking to server.  Setting interval for retry ..."
+                    if META_DEBUG: print data
+                    if META_DEBUG: print
+                    self.interval = 0
+                    """
+                      If we are in the registerThread thread, then setting interval to 0
+                      will end up causing a retry in about 6 seconds (see self.run())
+                      If we are in the main thread, then setting interval to 0 will do one
+                      of two things:
+                      1)  Do the same as if we were in the registerThread
+                      2)  Cause the next, normally scheduled register() call to use the values
+                          provided in this call.
+                    
+                      Which case occurs depends on where the registerThread thread is when
+                      the main thread calls register().
+                    """
+                    return 0  # indicates that it was okay to call, not that no errors occurred
 
             #  If there is a DOM returned ....
-            if etreeEl:
+            if etreeEl != None:
                 #  If there's an error, echo it to the console
                 if etreeEl.get("errmsg"):
                     print "Error durring registration:  " + etreeEl.get("errmsg")
@@ -580,7 +464,7 @@
                     self.interval = int(etreeEl.get("interval"))
                     self.id = etreeEl.get("id")
                     self.cookie = etreeEl.get("cookie")
-                    if not etreeEl.get("errmsg"): updateMetaCache(xml_dom)
+                    #if etreeEl.get("errmsg") == None: updateMetaCache(xml_dom)
                 except:
                     if META_DEBUG: print
                     if META_DEBUG: print "OOPS!  Is the Meta okay?  It should be returning an id, cookie, and interval."
--- a/orpg/networking/mplay_server.py	Tue May 04 10:43:29 2010 -0500
+++ b/orpg/networking/mplay_server.py	Wed May 05 08:55:51 2010 -0500
@@ -616,7 +616,7 @@
 
     def register_callback(instance, xml_dom = None, source=None):
         if xml_dom:    # if we get something
-            if source == getMetaServerBaseURL():    # if the source of this DOM is the authoritative meta
+            if source == getMetaServerList():    # if the source of this DOM is the authoritative meta
                 try:
                     metacache_lock.acquire()
                     curlist = getRawMetaList()      #  read the raw meta cache lines into a list
@@ -672,10 +672,10 @@
         else: num_players = 0
 
         #  request only Meta servers compatible with version 2
-        metalist = getMetaServers(versions=["2"])
+        metalist = getMetaServerList()
         if self.show_meta_messages != 0:
             self.log_msg("Found these valid metas:")
-            for meta in metalist: self.log_msg("Meta:" + meta)
+            for meta in metalist: self.log_msg("Meta:" + meta.get('url'))
 
         """
         #  Go through the list and see if there is already a running register
--- a/orpg/orpg_version.py	Tue May 04 10:43:29 2010 -0500
+++ b/orpg/orpg_version.py	Wed May 05 08:55:51 2010 -0500
@@ -4,7 +4,7 @@
 #BUILD NUMBER FORMAT: "YYMMDD-##" where ## is the incremental daily build index (if needed)
 DISTRO = "Traipse"
 DIS_VER = "Ornery Orc"
-BUILD = "100504-00"
+BUILD = "100505-00"
 
 # This version is for network capability.
 PROTOCOL_VERSION = "1.2"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/orpg/templates/default_metaservers.xml	Wed May 05 08:55:51 2010 -0500
@@ -0,0 +1,4 @@
+<metaservers>
+    <meta url="http://orpgmeta.appspot.com" versions="1 2" />
+    <meta url="http://traipsemeta.madmathlabs.info" versions="1 2" />
+</metaservers>
--- a/orpg/templates/default_settings.xml	Tue May 04 10:43:29 2010 -0500
+++ b/orpg/templates/default_settings.xml	Wed May 05 08:55:51 2010 -0500
@@ -2,9 +2,9 @@
     <tab name="General" type="tab">
         <tab name="Networking" type="grid">
             <Heartbeat options="bool" value="1" help="This sends a message to the server to keep alive your connection when idle." />
-            <MetaServerBaseURL help="This is the URL that contains the server list." options="URL" value="http://orpgmeta.appspot.com/"/>
+            <MetaServers help="Contains a list of Meta Servers" options=".xml file" value="metaservers.xml"/>
             <ImageServerBaseURL help="This is the URL that contains the server list." options="URL" value="http://openrpg.digitalxero.net/imgupload/index.php"/>
-            <LocalorRemote help="Decide to load files locally or remotely. CherryPy must be running for local files." options="Local | Remote" value="Local"/>
+            <LocalorRemote help="Decide to load files locally or remotely. CherryPy must be running for local files." options="Local | Remote" value="Remote"/>
         </tab>
         <tab name="Sound" type="grid">
             <UnixSoundPlayer help="This is the path to the executable used by unix clients to play sounds." options="path to executable" value=""/>
--- a/orpg/templates/metaservers.cache	Tue May 04 10:43:29 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://orpgmeta.appspot.com 1 2