Ejemplo n.º 1
0
def zonemodify(message, user, zone, key, value):
	if name not in zones.get_zones():
		tell(user, "Zone does not exist.")
		return
	zone = zones.get_zones()[zone]
	zone[key] = eval(value)
	tell(user, "Success")
Ejemplo n.º 2
0
	def wrapped_fn(message, user, zone, name, *args):

		zone_original = zone
		zone = zone.strip('"')
		if zone not in get_zones():
			tell(user, "Zone does not exist.")
			print zone
			return
		zone = get_zones()[zone]
		if 'acls' not in zone:
			tell(user, "Sorry, that zone does not appear to support ACLs.\n"
			           "You may need to contact an op to resolve this.")
			return

		if name != 'EVERYONE':
			name = name.lower()
			if name not in all_users() and name not in zone['acls']:
				tell(user, "Warning: %s is not a player known to this server.\n"
				           "If you have made a mistake, type:\n/acls %s clear %s" % (zone_original, name))

		if ADMIN not in zone['acls'].get(user.username, zone['acls']['EVERYONE']) and user.username not in ops():
			tell(user, "You do not have permission to modify ACLs for this zone. "
			           "If you have accidentially locked yourself out, please contact an op for assistance.")
			return

		return fn(message, user, zone, name, *args)
Ejemplo n.º 3
0
def zonedestroy(message, user, name):
	name = name.strip('"')

	try:
		zone = get_zones()[name]
	except KeyError:
		tell(user, "That zone doesn't exist!")
		return
	if not controls_zone(user.username, zone) and not user.username in ops():
		tell(user, "That isn't your zone.")
	get_zones().pop(name)
	tell(user, "Zone deleted.")
Ejemplo n.º 4
0
def zonewoolall(message, user, name):
	yield
	EDGE = 4 # extra blocks beyond edges
	user.morewool = name
	try:
		zone = zones.get_zones()[name]
	except KeyError:
		tell(user, "Bad zone name")
		return
	if zone['bounds_info'][0] == 'cube':
		box = zone['bounds_info'][2:]
		box = zip(*box)
		box = [sorted(axis) for axis in box]
	elif zone['bounds_info'][0] == 'cylinder':
		(x, y, z), r, h = zone['bounds_info'][2:]
		box = ((x-r, x+r), (y, y+h), (z-r, z+r))
	else:
		tell(user, "Unsupported zone type: %s" % zone['bounds_info'][0])
		return
	box = [(int(a)-EDGE, int(b)+1+EDGE) for a,b in box]
	for y in range(*box[1]):
		for x in range(*box[0]):
			yield
			for z in range(*box[2]):
				wool_point(zone, user, (x,y,z))
		complete = float(y-box[1][0])/(box[1][1]-box[1][0])
		if complete < 1:
			tell(user, 'Wooling %s...%.2f%% complete' % (name, 100 * complete))
	tell(user, 'Complete.')
Ejemplo n.º 5
0
def zoneinfo(message, user, name):
	name = name.strip('"')

	try:
		zone = get_zones()[name]
	except KeyError:
		tell(user, "That zone doesn't exist!")
		return
	if not controls_zone(user.username, zone) and not user.username in ops():
		tell(user, "That isn't your zone.")
		return

	keys = ['name','creator','confirmed']
	for key in keys:
		if key in zone:
			tell(user, "%s: %s" % (key, zone[key]))

	keys.append('bounds_info')
	def dim_to_name(dim):
		try:
			return {-1: '(Nether)', 0: '(Overworld)', 1:'(End)'}[dim]
		except KeyError:
			return ""
	def tell_bounds(style, *args, **kwargs):
		indent = kwargs.pop("indent",0)
		indent_str = "__" * indent
		if style == 'cube':
			dim, point1, point2 = args
			tell(user, indent_str + "Cube in dim%d%s from (%.2f,%.2f,%.2f) to (%.2f,%.2f,%.2f)" % ((dim, dim_to_name(dim)) + tuple(point1) + tuple(point2)))
		elif style == 'cylinder':
			dim, base, radius, height = args
			tell(user, indent_str + "Cylinder in dim%d%s from (%.2f,%.2f,%.2f) to radius %.2f and height %.2f" % ((dim, dim_to_name(dim)) + tuple(base) + (radius, height)))
		elif style == 'union':
			tell(user, indent_str + "Union of regions:")
			for more_info in args:
				tell_bounds(*more_info, indent=indent+1)
		else:
			tell(user, indent_str + "Unknown region")
	tell_bounds(*zone['bounds_info'])

	if 'acls' in zone:
		keys.append('acls')
		tell(user, "acls:")
		for name in zone['acls']:
			if name == 'EVERYONE':
				continue
			tell(user, "__%s: %s" % (name, ",".join(zone['acls'][name])))
		tell(user, "__Everyone else: %s" % ",".join(zone['acls']['EVERYONE']))

	for key in zone:
		if key in keys:
			continue
		tell(user, "%s: %s" % (key, zone[key]))
Ejemplo n.º 6
0
def zonewool(message, user, name):
	user.morewool = name
	try:
		zone = zones.get_zones()[name]
	except KeyError:
		tell(user, "Bad zone name")
		return
	base = [int(axis) for axis in user.position]
	for x in range(base[0]-5, base[0]+5):
		for y in range(base[1]-10, base[1]):
			for z in range(base[2]-5, base[2]+5):
				wool_point(zone, user, (x,y,z))
	tell(user, "Complete.")
Ejemplo n.º 7
0
def from_name(user, name):
	if name in get_zones():
		tell(user, "That name is already in use.")
		return ROOT_MENU

	return (
		"The new zone will be called %s.\n"
		"Please pick a basic shape for the new zone.\n" % name,
		[
			("Cube", lambda u,v: from_cube(u, v, name)),
			("Cylinder", lambda u,v: from_cyl(u, v, name))
		],
		exit_menu
	)
Ejemplo n.º 8
0
    def create_zones(self):
        """Create all gaming zones."""
        screen_x = self.config.getint('screen', 'size_x')
        offset_card_total = self.config.getint('board', 'offset_card_total')
        offset_card_open = self.config.getint('board', 'offset_card_open')
        offset_cols = self.config.getint('board', 'offset_cols')
        offset_card = (offset_card_total, offset_card_open)

        self.zones = []
        left = 0
        top = 0
        for index, zone in enumerate(get_zones()):
            self.zones.append(
                zone(left, top, (self.card_x, self.card_y), offset_card,
                     offset_cols))
            if 0 == index:
                left += 2 * offset_cols + self.card_x + 51 * offset_card_total
            elif 1 == index:
                width = 11 * offset_cols + 10 * self.card_x + 10 * 6 * offset_card_total
                left = (screen_x - width) // 2
                top = 2 * offset_cols + self.card_y + 51 * offset_card_total
Ejemplo n.º 9
0
def zonelist(message, user):
	for zone in get_zones().values():
		if controls_zone(user.username, zone):
			tell(user, zone['name'] + (" (unconfirmed)" if not zone.get('confirmed',True) else ""))
Ejemplo n.º 10
0
def zonenew(message, user, name, args):
	name = name.strip('"')

	if name in get_zones():
		tell(user, "Name already taken.")
		return

	if args.startswith("json "):
		try:
			data = loads(args[5:])
		except Exception:
			tell(user, "Bad json.")
			return

		def validate_point(data):
			if type(data) != list:
				raise ValueError()
			if len(data) != 3:
				raise ValueError()
			if not all(type(x) in (int, float) for x in data):
				raise ValueError()

		def validate_info(data):
			if type(data) != list:
				raise ValueError()
			style = data[0]
			if style == 'cube':
				dim, point1, point2 = data[1:]
				if type(dim) != int or dim not in (-1,0,1):
					raise ValueError()
				validate_point(point1)
				validate_point(point2)
			elif style == 'cylinder':
				dim, base, radius, height = data[1:]
				if type(dim) != int or dim not in (-1,0,1):
					raise ValueError()
				if not validate_point(base):
					raise ValueError()
				if type(radius) not in (int, float) or radius <= 0:
					raise ValueError()
				if type(height) not in (int, float) or height <= 0:
					raise ValueError()
			elif style == 'union':
				[validate_info(x) for x in data[1:]]
			else:
				raise ValueError()

		try:
			validate_info(data)
		except ValueError:
			tell(user, "Invalid JSON, see /help json for schema.")
			return

		zone = new_zone(name, data, user.username)

	else:
		args = filter(None, args.split())
		style = args.pop(0)
		try:
			dim = int(args.pop(0))
			if dim not in (-1,0,1):
				raise ValueError()
			args = [float(arg) for arg in args]
			if style == 'cube':
				if len(args) != 6:
					raise ValueError()
				point1 = args[:3]
				point2 = args[3:]
				zone = new_zone(name, ('cube',dim,point1,point2), user.username)
			elif style == 'cylinder':
				if len(args) != 5:
					raise ValueError()
				base = args[:3]
				radius, height = args[3:]
				if radius <= 0 or height <= 0:
					raise ValueError()
				zone = new_zone(name, ('cylinder',dim,base,radius,height), user.username)
			else:
				raise ValueError			
		except ValueError:
			tell(user, "Bad args.")
			return

	if zone is None:
		tell(user, "Unknown error while creating zone")
	else:
		tell(user, "Success. Remember that you still need an op to confirm the zone.")
Ejemplo n.º 11
0
def zoneconfirm(message, user, name):
	if name not in zones.get_zones():
		tell(user, "Zone does not exist.")
		return
	zones.get_zones()[name]['confirmed'] = True
	tell(user, "Success")