From 530e792c3c97ae25b5277d8a4742316a788d9c22 Mon Sep 17 00:00:00 2001 From: Ishigh1 Date: Fri, 24 Nov 2023 17:42:22 +0100 Subject: [PATCH] Core: Floor and ceil in datastorage (#2448) --- MultiServer.py | 13 +++++++++---- docs/network protocol.md | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/MultiServer.py b/MultiServer.py index 8be8d641324a..bd9d2446af65 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -10,6 +10,7 @@ import inspect import itertools import logging +import math import operator import pickle import random @@ -67,21 +68,25 @@ def update_dict(dictionary, entries): # functions callable on storable data on the server by clients modify_functions = { + # generic: + "replace": lambda old, new: new, + "default": lambda old, new: old, + # numeric: "add": operator.add, # add together two objects, using python's "+" operator (works on strings and lists as append) "mul": operator.mul, + "pow": operator.pow, "mod": operator.mod, + "floor": lambda value, _: math.floor(value), + "ceil": lambda value, _: math.ceil(value), "max": max, "min": min, - "replace": lambda old, new: new, - "default": lambda old, new: old, - "pow": operator.pow, # bitwise: "xor": operator.xor, "or": operator.or_, "and": operator.and_, "left_shift": operator.lshift, "right_shift": operator.rshift, - # lists/dicts + # lists/dicts: "remove": remove_from_list, "pop": pop_from_container, "update": update_dict, diff --git a/docs/network protocol.md b/docs/network protocol.md index d461cebce1ec..c17cc74a8ac7 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -415,6 +415,8 @@ The following operations can be applied to a datastorage key | mul | Multiplies the current value of the key by `value`. | | pow | Multiplies the current value of the key to the power of `value`. | | mod | Sets the current value of the key to the remainder after division by `value`. | +| floor | Floors the current value (`value` is ignored). | +| ceil | Ceils the current value (`value` is ignored). | | max | Sets the current value of the key to `value` if `value` is bigger. | | min | Sets the current value of the key to `value` if `value` is lower. | | and | Applies a bitwise AND to the current value of the key with `value`. |