Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit 545d2a7

Browse files
committed
Setup a forced max item cap, so people can't accidentally cause server to lag out by giving to many items
1 parent 984c2b5 commit 545d2a7

5 files changed

Lines changed: 18 additions & 11 deletions

File tree

plugins/core/admin_commands_plugin/admin_command_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ def item(self, data):
281281
item_count = item[1]
282282
else:
283283
item_count = 1
284-
give_item_to_player(target_protocol, item_name, item_count)
284+
given = give_item_to_player(target_protocol, item_name, item_count)
285285
target_protocol.send_chat_message(
286286
"%s^green; has given you: ^yellow;%s^green; (count: ^cyan;%s^green;)" % (
287-
self.protocol.player.colored_name(self.config.colors), item_name, item_count))
287+
self.protocol.player.colored_name(self.config.colors), item_name, given))
288288
self.protocol.send_chat_message("Sent ^yellow;%s^green; (count: ^cyan;%s^green;) to %s" % (
289-
item_name, item_count, target_player.colored_name(self.config.colors)))
289+
item_name, given, target_player.colored_name(self.config.colors)))
290290
self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name,
291-
item_count)
291+
given)
292292
else:
293293
self.protocol.send_chat_message("You have to give an item name.")
294294
else:

plugins/fuelgiver/fuelgiver_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ def fuel(self, data):
2828
return
2929
if not 'last_given_fuel' in my_storage or float(my_storage['last_given_fuel']) <= float(time()) - 86400:
3030
my_storage['last_given_fuel'] = str(time())
31-
give_item_to_player(self.protocol, "fillerup", 1)
31+
given = give_item_to_player(self.protocol, "fillerup", 1)
3232
self.protocol.player.storage = my_storage
3333
self.protocol.send_chat_message("You were given a daily fuel supply! Now go explore ;)")
3434
self.logger.info("Gave fuel to %s.", self.protocol.player.name)
3535
else:
36-
self.protocol.send_chat_message("^red;No... -.- Go mining!")
36+
self.protocol.send_chat_message("^red;No... -.- Go mining!")

plugins/new_player_greeter_plugin/new_player_greeter_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def after_world_start(self, data):
2525

2626
def give_items(self):
2727
for item in self.config.plugin_config["items"]:
28-
give_item_to_player(self.protocol, item[0], item[1])
28+
given = give_item_to_player(self.protocol, item[0], item[1])
2929

3030
def send_greetings(self):
31-
self.protocol.send_chat_message(self.config.plugin_config["message"])
31+
self.protocol.send_chat_message(self.config.plugin_config["message"])

plugins/starteritems/starteritems_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def starteritems(self, data):
3434

3535
def give_items(self):
3636
for item in self.config.plugin_config["items"]:
37-
give_item_to_player(self.protocol, item[0], item[1])
37+
given = give_item_to_player(self.protocol, item[0], item[1])
3838

3939
def send_greetings(self):
40-
self.protocol.send_chat_message(self.config.plugin_config["message"])
40+
self.protocol.send_chat_message(self.config.plugin_config["message"])

utility_functions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@
1313

1414

1515
def give_item_to_player(player_protocol, item, count=1):
16-
logger.debug("Giving item %s (count: %s) to %s", item, count, player_protocol.player.name)
16+
logger.debug("Attempting to give item %s (count: %s) to %s", item, count, player_protocol.player.name)
1717
item_count = int(count)
18+
hard_max = 90000
19+
if item_count > hard_max:
20+
logger.warn("Attempted to give more items than the max allowed (%s). Capping amount.", hard_max)
21+
item_count = hard_max
1822
maximum = 1000
23+
given = 0
1924
while item_count > 0:
2025
x = item_count
2126
if x > maximum:
2227
x = maximum
2328
item_packet = build_packet(packets.Packets.GIVE_ITEM, packets.give_item_write(item, x + 1))
2429
player_protocol.transport.write(item_packet)
2530
item_count -= x
31+
given += x
32+
return given
2633

2734

2835
def recursive_dictionary_update(d, u):

0 commit comments

Comments
 (0)