Beispiel #1
0
def tell(user, message, prefix=""):
    """Send a server message to user.
	Note: Splits multiline messages. See prefix, below.
	Optional args:
		prefix: Add given prefix to every line sent, eg '<server>: '.
	"""
    message = unicode(message)

    reverse = dict([(y, x) for x, y in packet_names.items()])
    for line in message.split("\n"):
        packet = Packet()
        packet.ident = reverse["Chat message"]
        packet.direction = SERVER_TO_CLIENT
        packet.data = {"text": line}
        send_packet(packet, user, False)
Beispiel #2
0
def on_packet(packet, user, to_server):
	if not to_server:
		return packet

	# ENTRY
	if packet.name() in ('Player position', 'Player position & look') and not check_acls(ENTRY, user):
		tell(user, "You are not allowed to enter here.", delay=0.2, lock=("acl-entry-lock",user))
		new_stance = packet.data['stance'] - packet.data['y'] + user.position_old[1]
		packet.data['x'], packet.data['y'], packet.data['z'] = user.position_old
		packet.data['stance'] = new_stance
		back_packet = Packet()
		back_packet.ident = 0x0B # Player position
		back_packet.direction = SERVER_TO_CLIENT
		back_packet.data['x'] = packet.data['x']
		back_packet.data['y'] = packet.data['y']
		back_packet.data['z'] = packet.data['z']
		back_packet.data['stance'] = packet.data['stance']
		back_packet.data['on_ground'] = packet.data['on_ground']
		send_packet(back_packet, user, False)
		return packet

	# MODIFY (block digging)
	if packet.name() == 'Player digging' and packet.data['status'] == 0:
		position = (packet.data['x'], packet.data['y'], packet.data['z'])
		if not check_acls(MODIFY, user, position):
			tell(user, "You are not allowed to dig here.")
			return []

	# MODIFY/INTERACT (block placement)
	if packet.name() == 'Player block placement' and not all(packet.data[key] == -1 for key in ('x','y','z','direction')):
		position = add_direction((packet.data['x'], packet.data['y'], packet.data['z']), packet.data['direction'])
		if packet.data['slot']['id'] in INTERACT_IDS:
			if not check_acls(INTERACT, user, position):
				tell(user, "You are not allowed to interact with things here.")
				return []
		else:
			if not check_acls(MODIFY, user, position):
				tell(user, "You are not allowed to place blocks here.")

				# For now, we tell the client that the block in the indicated direction is empty.
				# This should work almost all the time and is by far the easiest option.
				back_packet = Packet()
				back_packet.ident = 0x35 # Block change
				back_packet.direction = SERVER_TO_CLIENT
				back_packet.data['x'], back_packet.data['y'], back_packet.data['z'] = position
				back_packet.data['id'] = 0
				back_packet.data['metadata'] = 0
				send_packet(back_packet, user, False)

				# We also invalidate the packet rather than drop it, so the server auto-corrects the client's inventory
				packet.data['x'] += 100

	return packet