in craft-server-image/server.py [0:0]
def on_block(self, client, x, y, z, w):
#log('on_block','x='+str(x)+' y='+str(y)+' z='+str(z)+' w='+str(w))
x, y, z, w = map(int, (x, y, z, w))
p, q = chunked(x), chunked(z)
previous = self.get_block(x, y, z)
message = None
if AUTH_REQUIRED and client.user_id is None:
message = 'Only logged in users are allowed to build.'
elif y <= 0 or y > 255:
message = 'Invalid block coordinates.'
elif w not in ALLOWED_ITEMS:
message = 'That item is not allowed.'
elif w and previous:
message = 'Cannot create blocks in a non-empty space.'
elif not w and not previous:
message = 'That space is already empty.'
elif previous in INDESTRUCTIBLE_ITEMS:
message = 'Cannot destroy that type of block.'
if message is not None:
client.send(BLOCK, p, q, x, y, z, previous)
client.send(REDRAW, p, q)
client.send(TALK, message)
return
query = (
'insert into block_history (timestamp, user_id, x, y, z, w) '
'values (:timestamp, :user_id, :x, :y, :z, :w);'
)
if RECORD_HISTORY:
self.execute(query, dict(timestamp=time.time(),
user_id=client.user_id, x=x, y=y, z=z, w=w))
query = (
'insert or replace into block (p, q, x, y, z, w) '
'values (:p, :q, :x, :y, :z, :w);'
)
#log('about to insert ',str(p)+' '+str(q)+' '+str(x)+' '+str(y)+' '+str(z)+' '+str(w))
self.execute(query, dict(p=p, q=q, x=x, y=y, z=z, w=w))
self.send_block(client, p, q, x, y, z, w)
sql_parameters = [
{'name':'p', 'value':{'doubleValue': p}},
{'name':'q', 'value':{'doubleValue': q}},
{'name':'x', 'value':{'doubleValue': x}},
{'name':'y', 'value':{'doubleValue': y}},
{'name':'z', 'value':{'doubleValue': z}},
{'name':'w', 'value':{'doubleValue': w}},
]
sql = 'insert into block (p, q, x, y, z, w) values (:p, :q, :x, :y, :z, :w) on conflict on constraint unique_block_pqxyz do UPDATE SET w = :w'
response = execute_rds_statement(sql, sql_parameters)
#log('rds_response_on_block',response)
for dx in range(-1, 2):
for dz in range(-1, 2):
if dx == 0 and dz == 0:
continue
if dx and chunked(x + dx) == p:
continue
if dz and chunked(z + dz) == q:
continue
np, nq = p + dx, q + dz
self.execute(query, dict(p=np, q=nq, x=x, y=y, z=z, w=-w))
self.send_block(client, np, nq, x, y, z, -w)
if w == 0:
query = (
'delete from sign where '
'x = :x and y = :y and z = :z;'
)
sql = 'delete from sign where x = :x and y = :y and z = :z'
response = execute_rds_statement(sql, sql_parameters)
#log('rds_response_on_delete_sign',response)
self.execute(query, dict(x=x, y=y, z=z))
query = (
'update light set w = 0 where '
'x = :x and y = :y and z = :z;'
)
sql = 'update light set w = 0 where x = :x and y = :y and z = :z'
response = execute_rds_statement(sql, sql_parameters)
#log('rds_response_on_update_light',response)
self.execute(query, dict(x=x, y=y, z=z))