RegionGenerator

From OpenSimulator

Revision as of 16:36, 12 July 2008 by Rich43 (Talk | contribs)

Jump to: navigation, search

Heres a Region Generator in Python

It generates a square piece of land.

It requires the cheetah templating module and python 2.5

#!/usr/bin/python
from Cheetah.Template import Template
import uuid
import os

# START OF CONFIGURATION
s = {}
# Region Configuration
s['regionname'] = "RichieWorld"     # Type the name of your island
s['x'] = [2900,3000]                # From - To x position
s['y'] = [2900,3000]                # From - To y position
# User Configuration
s['firstname'] = "Richie"           # Account firstname
s['lastname'] = "Ward"              # Account lastname
s['useruuid'] = 'your clients uuid goes here'
s['password'] = 'rewrich'           # Account password
# Network Configuration
s['startport'] = 9000               # Port the regions start on
                                    # incrimented by 1 each time
s['internalip'] = "87.98.249.170"   # Server ip
s['externalhost'] = "4rensics.org"  # Domain name or ip of server
                                    # (accessed externally)
# ------------------------------

regionsdir = 'Regions'              # Files created in this directory, created if not found.
# Template
template = """<Root>
<Config sim_UUID="$uuid" sim_name="$regionname" sim_location_x="$x" sim_location_y="$y" internal_ip_address="$s.internalip" internal_ip_port="$port" allow_alternate_ports="false" external_host_name="$s.externalhost" master_avatar_uuid="$s.useruuid" estate_covenant_uuid="00000000-0000-0000-0000-000000000000" master_avatar_first="$s.firstname" master_avatar_last="$s.lastname" master_avatar_pass="$s.password" />
</Root>"""
# END OF CONFIGURATION

def maketemplate(regionname,x,y,port):
    t = Template(template)
    t.s = s
    t.uuid = str(uuid.uuid1())
    t.regionname = regionname
    t.x = x
    t.y = y
    t.port = port
    return str(t)

try:
    os.mkdir(regionsdir)
except OSError:
    pass

counter = 0
for xnum in range(s['x'][0], s['x'][1]):
    for ynum in range(s['y'][0], s['y'][1]):
        counter += 1
        
        if counter == 1:
            regionname = s['regionname']
        else:
            regionname = s['regionname'] + str(counter)
        
        path = os.path.join(regionsdir,"%s.%s.%s.xml" % (regionname, xnum, ynum))
        tmplfile = open(path, 'w')
        tmplfile.write(maketemplate(regionname, xnum, ynum, s['startport'] + (counter - 1)))
        tmplfile.close()
Personal tools
General
About This Wiki