summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDipesh Amin <yaypunkrock@gmail.com>2011-09-03 17:49:56 +0100
committerDipesh Amin <yaypunkrock@gmail.com>2011-09-03 17:49:56 +0100
commit7c730917decf9dd8b78f3269ff3256c542ae442d (patch)
tree6a419624418039681c2a333e9f6cada2628043b1
parent656a56478c3f506b5b3ed113a20b39c94daf329f (diff)
downloadmanamarket-7c730917decf9dd8b78f3269ff3256c542ae442d.tar.gz
manamarket-7c730917decf9dd8b78f3269ff3256c542ae442d.tar.bz2
manamarket-7c730917decf9dd8b78f3269ff3256c542ae442d.tar.xz
manamarket-7c730917decf9dd8b78f3269ff3256c542ae442d.zip
Filter allowed whisper characters to only ones that can be used in names.
Also add some protection for the !money command, if an item_add fails, the trade shouldn't be set as complete.
-rwxr-xr-xmain.py11
-rw-r--r--utils.py2
2 files changed, 11 insertions, 2 deletions
diff --git a/main.py b/main.py
index ccc1b6b..7366a33 100755
--- a/main.py
+++ b/main.py
@@ -38,7 +38,7 @@ sale_tree = tradey.ItemTree()
ItemLog = utils.ItemLog()
def process_whisper(nick, msg, mapserv):
- msg = filter(lambda x: x in string.printable, msg)
+ msg = filter(lambda x: x in utils.allowed_chars, msg)
user = user_tree.get_user(nick)
broken_string = msg.split()
@@ -860,7 +860,6 @@ def main():
mapserv.sendall(trade_add_item(0-inventory_offset, amount))
mapserv.sendall(str(PacketOut(CMSG_TRADE_ADD_COMPLETE)))
mapserv.sendall(str(PacketOut(CMSG_TRADE_OK)))
- trader_state.complete = 1
else:
logging.info("Trade response: Trade cancelled")
@@ -915,6 +914,14 @@ def main():
if index != 0-inventory_offset: # If it's not money
logging.info("Remove item: %s, Amount: %s, Index: %s", ItemDB.getItem(player_node.inventory[index].itemId).name, str(amount),str(index))
player_node.remove_item(index, amount)
+ else:
+ logging.info("Money Added: %s", str(amount))
+ if trader_state.money:
+ amount_added = int(user_tree.get_user(trader_state.money).get('money'))
+ if amount != amount_added:
+ mapserv.sendall(str(PacketOut(CMSG_TRADE_CANCEL_REQUEST)))
+ else:
+ trader_state.complete = 1
elif response == 1:
logging.info("Trade item add response: Failed - player overweight.")
diff --git a/utils.py b/utils.py
index d9d0319..8d66977 100644
--- a/utils.py
+++ b/utils.py
@@ -14,6 +14,8 @@ import mutex
import threading
from net.packet_out import *
+allowed_chars = "abcdefghijklmnoprstquvwxyzABCDEFGHIJKLMNOPRSTQUVWXYZ1234567890-_+=!@$%^&*();'<>,.?/~`|"
+
# Process a recieved ip address.
def parse_ip(a):
return "%s.%s.%s.%s" % ((a % 256),((a >> 8) % 256),((a >> 16) % 256),((a >> 24) % 256))