summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDipesh Amin <yaypunkrock@gmail.com>2011-08-22 11:47:40 +0100
committerDipesh Amin <yaypunkrock@gmail.com>2011-08-22 11:47:40 +0100
commit73691da56f541ea1730043d0e654d97414dcb92a (patch)
treef6c1ae24e03b93de33bacce46729d1b26c228664
parent4d1a0ffba73b0c21a6529e9387ade801cb6d2c7b (diff)
downloadmanamarket-73691da56f541ea1730043d0e654d97414dcb92a.tar.gz
manamarket-73691da56f541ea1730043d0e654d97414dcb92a.tar.bz2
manamarket-73691da56f541ea1730043d0e654d97414dcb92a.tar.xz
manamarket-73691da56f541ea1730043d0e654d97414dcb92a.zip
Inventory/Money Check.
-rwxr-xr-xmain.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/main.py b/main.py
index 965b8ce..8659967 100755
--- a/main.py
+++ b/main.py
@@ -801,6 +801,31 @@ def main():
logging.info("Name: %s, Id: %s, Index: %s, Amount: %s.", \
ItemDB.getItem(player_node.inventory[item].itemId).name, \
player_node.inventory[item].itemId, item, player_node.inventory[item].amount)
+
+ # Check the inventory state and the amount of money match the information saved.
+ amount = -1
+ test_node = player_node.inventory
+ for item in test_node:
+ amount = test_node[item].amount
+ for elem in sale_tree.root:
+ if int(elem.get('itemId')) == test_node[item].itemId \
+ and int(elem.get('amount')) >= amount:
+ amount -= int(elem.get('amount'))
+
+ if amount == 0:
+ del test_node[item]
+
+ if amount < 0:
+ logging.info("Server and client inventory out of sync.")
+ exit(0)
+
+ total_money = 0
+ for user in user_tree:
+ total_money += int(user.get('money'))
+
+ if total_money > player_node.MONEY:
+ logging.info("Server and client money out of sync.")
+ exit(0)
elif packet.is_type(SMSG_TRADE_REQUEST):
name = packet.read_string(24)