diff options
author | Erik Schilling <ablu.erikschilling@gmail.com> | 2014-09-26 18:56:16 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@gmail.com> | 2014-09-26 18:56:16 +0200 |
commit | a93b2573b8b04cf883dff0c75efa3f0630e3e79e (patch) | |
tree | 16044fb18ac1a8cefdec831961206910f20d0b61 | |
parent | aef0bcdbda77b07f6f99e629e0499d7e576b6741 (diff) | |
download | manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.tar.gz manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.tar.bz2 manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.tar.xz manamarket-a93b2573b8b04cf883dff0c75efa3f0630e3e79e.zip |
Added changes done outside of git
Those changes have been done on the server directly without continueing
the git history (or at least since the history i know).
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | being.py | 24 | ||||
-rw-r--r-- | config.py.template | 7 | ||||
-rwxr-xr-x | find-unused-accounts.pl | 28 | ||||
-rwxr-xr-x | main.py | 15 | ||||
-rw-r--r-- | net/packet.py | 2 | ||||
-rw-r--r-- | net/packet_out.py | 24 | ||||
-rw-r--r-- | net/protocol.py | 24 | ||||
-rw-r--r-- | player.py | 26 | ||||
-rw-r--r-- | stats/process_salelog/Readme | 1 | ||||
-rwxr-xr-x | stats/process_salelog/main.py | 59 | ||||
-rwxr-xr-x | stats/process_salelog/main_stat.py | 151 | ||||
-rw-r--r-- | stats/process_salelog/utils.py | 82 | ||||
-rwxr-xr-x | stats/update_sales.sh | 5 | ||||
-rw-r--r-- | tradey.py | 24 | ||||
-rw-r--r-- | utils.py | 27 |
16 files changed, 364 insertions, 138 deletions
@@ -1,6 +1,5 @@ - To get your own copy of tradey: cp config.py.template config.py -cp data_template data/ +cp item.xml data/ cd data git init @@ -1,26 +1,10 @@ #!/usr/bin/python """ -Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> -Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> -This file is part of tradey, a trading bot in The Mana World -see www.themanaworld.org - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Additionally to the GPL, you are *strongly* encouraged to share any modifications -you do on these sources. + This file is part of tradey, a trading bot in the mana world + see www.themanaworld.org """ def job_type(job): diff --git a/config.py.template b/config.py.template index 8cad23e..e55b2f6 100644 --- a/config.py.template +++ b/config.py.template @@ -1,9 +1,8 @@ -#server = "server.themanaworld.org" -server = "caliban.homeip.net" +server = "server.themanaworld.org" port = 6901 account = "" password = "" relist_time = 604800 # Time in seconds before an item needs to be relisted. character = 0 #slot character is in, 0 for first, 1 for second, 2 for third -admin = "Admin <admin@email.com>" -nosell = [833, 3000, 727] # Items which can't be sold - just add the itemid to the list. +admin = "" +#nosell = [] # Items which can't be sold - just add the itemid to the list. diff --git a/find-unused-accounts.pl b/find-unused-accounts.pl new file mode 100755 index 0000000..9667f5a --- /dev/null +++ b/find-unused-accounts.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl +use XML::Simple; +use warnings; +use strict; +use Data::Dumper; + +my $xml = XML::Simple->new(); +my $users = $xml->XMLin("data/user.xml", KeyAttr => {}); +my %l; + +# Snarf through the XML data. Build a hash: +# username => lastuse +# Only for users with no items and no money. +# For some reason last_use is floating point so let's fix that. +foreach my $user (@{$users->{user}}) { + if ($user->{'used_stalls'} == 0 && $user->{'money'} == 0) { + $user->{'last_use'} = 0 unless ($user->{'last_use'}); + $l{ $user->{'name'} } = int($user->{'last_use'}); + } +} + + +print("Last used\t\t\tUsername\n"); +foreach ( sort { $l{$a} cmp $l{$b} || $a cmp $b } keys %l ) { + print gmtime($l{$_}) . "\t$_\n"; +} + + @@ -68,6 +68,9 @@ def process_whisper(nick, msg, mapserv): user = user_tree.get_user(nick) broken_string = msg.split() + if len(broken_string) == 0: + return + if user != -10: if int(user.get("accesslevel")) == -1: # A user who has been blocked for abuse. if int(user.get("used_stalls")) == 0 and int(user.get("money")) == 0: @@ -453,6 +456,9 @@ def process_whisper(nick, msg, mapserv): elif weight + player_node.WEIGHT > player_node.MaxWEIGHT: mapserv.sendall(whisper(nick, "I've not got enough room left to carry those. Please try again later. ")) return + elif ItemDB.item_names[item_id].weight > 10 and amount > 150: + mapserv.sendall(whisper(nick, "Sorry, as each of those items weighs more than 10g you can only add a maximum quantity of 150.")) + return if amount > 1 and ItemDB.getItem(item_id).type != 'equip-ammo' and 'equip' in ItemDB.getItem(item_id).type: mapserv.sendall(whisper(nick, "You can only add one piece of equipment per slot.")) @@ -766,6 +772,7 @@ def main(): shop_broadcaster.mapserv = mapserv # Map server packet loop + print "Entering map packet loop\n"; while True: data = mapserv.recv(2048) if not data: @@ -997,9 +1004,15 @@ def main(): logger.info("Trade item add response: Successfully added item.") if trader_state.item: if trader_state.item.get == 0 and index != 0-inventory_offset: # Make sure the correct item is given! + # index & amount are Always 0 if player_node.inventory[index].itemId != trader_state.item.id or \ amount != trader_state.item.amount: - mapserv.sendall(str(PacketOut(CMSG_TRADE_CANCEL_REQUEST))) + logger.info("Index: %s" % index) + logger.info("P.ItemId: %s" % player_node.inventory[index].itemId) + logger.info("T.ItemId: %s" % trader_state.item.id) + logger.info("P.Amount: %s" % amount) + logger.info("T.Amount: %s" % trader_state.item.amount) + #mapserv.sendall(str(PacketOut(CMSG_TRADE_CANCEL_REQUEST))) # If Trade item add successful - Remove the item from the inventory state. if index != 0-inventory_offset: # If it's not money diff --git a/net/packet.py b/net/packet.py index 52bdf71..16b4f79 100644 --- a/net/packet.py +++ b/net/packet.py @@ -1,5 +1,5 @@ -# The PacketBuffer class has been adapted from source originally released by gnufrk +"""The PacketBuffer class has been adapted from source originally released by gnufrk""" import struct diff --git a/net/packet_out.py b/net/packet_out.py index 79f9917..1d6e2d2 100644 --- a/net/packet_out.py +++ b/net/packet_out.py @@ -1,27 +1,3 @@ -""" -Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> -Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> - -This file is part of tradey, a trading bot in The Mana World -see www.themanaworld.org - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Additionally to the GPL, you are *strongly* encouraged to share any modifications -you do on these sources. -""" - from packet import * from protocol import * diff --git a/net/protocol.py b/net/protocol.py index 8b97542..4a4b74f 100644 --- a/net/protocol.py +++ b/net/protocol.py @@ -1,27 +1,3 @@ -""" -Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> -Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> - -This file is part of tradey, a trading bot in The Mana World -see www.themanaworld.org - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Additionally to the GPL, you are *strongly* encouraged to share any modifications -you do on these sources. -""" - SMSG_LOGIN_DATA = 0x0069 SMSG_CHAR_LOGIN = 0x006b SMSG_CHAR_MAP_INFO = 0x0071 @@ -1,26 +1,10 @@ #!/usr/bin/python """ -Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> -Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> -This file is part of tradey, a trading bot in The Mana World -see www.themanaworld.org - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Additionally to the GPL, you are *strongly* encouraged to share any modifications -you do on these sources. + This file is part of tradey, a trading bot in the mana world + see www.themanaworld.org """ import copy @@ -78,7 +62,7 @@ class Player: total_money += int(user.get('money')) if total_money != self.MONEY: - return "Server and client money out of sync." + return "Server and client money out of sync. Market: %s Player %s" % (total_money, self.MONEY) return 0 diff --git a/stats/process_salelog/Readme b/stats/process_salelog/Readme new file mode 100644 index 0000000..6b80ea7 --- /dev/null +++ b/stats/process_salelog/Readme @@ -0,0 +1 @@ +Usage: python main.py sales.log <output file> diff --git a/stats/process_salelog/main.py b/stats/process_salelog/main.py new file mode 100755 index 0000000..4ad2dd3 --- /dev/null +++ b/stats/process_salelog/main.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +""" + + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + + tradey, a package, which implements an Automated Market Bot for "The Mana World" a 2D MMORPG. + +""" + +import logging +import socket +import sys +import time +import string +import utils +import locale + +ItemDB = utils.ItemDB() + +def main(): + in_file = sys.argv[1] + out_file = sys.argv[2] + locale.setlocale(locale.LC_ALL, '') + + out_obj = open(out_file, 'w') + in_obj = open(in_file, 'r') + + out_obj.write('<html> \n') + out_obj.write('<body> \n') + out_obj.write('<head> \n') + out_obj.write('<title>ManaMarket Sales</title> \n') + out_obj.write('<h2>ManaMarket Sales</h2>') + out_obj.write('<table border="1" cellpadding="5" cellspacing="0"> \n') + out_obj.write('<tr bgcolor="6699FF"> <td>Item Name</td> <td>Amount</td> <td>Price</td> <td>Time</td> </tr>\n') + + sales = in_obj.readlines() + + sale_total = 0 + items_sold = 0 + for line in sales: + line = line.split() + t_time = time.gmtime(float(line[3])) + unit_price = int(line[2])/int(line[1]) + out_obj.write('<tr> <td>'+ItemDB.getItem(int(line[0])).name+'</td> <td>'+locale.format("%d", int(line[1]), grouping=True)+'</td> <td>'+locale.format("%d", unit_price, grouping=True)+'</td> <td>'+time.asctime(t_time)+'</td> </tr>\n') + sale_total += int(line[2]) + items_sold += int(line[1]) + + out_obj.write('</table> \n') + out_obj.write('</br><b>Total sales: '+str(sale_total)+' GP</b> </br>') + out_obj.write('<b>Total number of items sold: '+str(items_sold)+'</b></br>') + out_obj.write('Updated: '+time.asctime(time.gmtime())) + out_obj.write('</body></html> \n') + in_obj.close() + out_obj.close() + + +if __name__ == '__main__': + main() diff --git a/stats/process_salelog/main_stat.py b/stats/process_salelog/main_stat.py new file mode 100755 index 0000000..9ff71d5 --- /dev/null +++ b/stats/process_salelog/main_stat.py @@ -0,0 +1,151 @@ +#!/usr/bin/python +""" + + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + + tradey, a package, which implements an Automated Market Bot for "The Mana World" a 2D MMORPG. + +""" + +import logging +import socket +import sys +import time +import string +import utils +import locale + +class SaleStat: + pass + +ItemDB = utils.ItemDB() + +def main(): + in_file = sys.argv[1] + out_file = sys.argv[2] + locale.setlocale(locale.LC_ALL, '') + + out_obj = open(out_file, 'w') + in_obj = open(in_file, 'r') + + out_obj.write('<html> \n \ + <head> \n \ + <title>ManaMarket Statistics</title> \n \ + <style type="text/css"> \n \ + td, th { border: 1px solid black } \n \ + table {border: 1px solid black} \n \ + </style> \n \ + </head> \n \ + <body> \n \ + <h2> ManaMarket Statistics </h2> \n \ + <table cellpadding="5" cellspacing="0"> \n \ + <tr> \n \ + <th rowspan="2"> Item Name</th> \n \ + <th rowspan="2"> Total Amount Sold</th> \n \ + <th colspan="5">Price</th> \n \ + <th rowspan="2">Last Sold</th> \n \ + </tr> \n \ + <tr> \n \ + <td>Min</td> \n \ + <td>Max</td> \n \ + <td>Average (Week)</td> \n \ + <td>Average (Month)</td> \n \ + <td>Average (Overall)</td> \n \ + </tr> \n ') + + sales = in_obj.readlines() + + sale_dict = {} + + # Put sales date into a dict. + sale_total = 0 + for line in sales: + line = line.split() + item_id = int(line[0]) + name = ItemDB.getItem(int(line[0])).name + amount = int(line[1]) + price = int(line[2]) + t_time = float(line[3]) + sale_total += int(line[2]) + + if item_id not in sale_dict: + sale_dict[item_id] = [] + + sale_dict[item_id].append([amount, price, t_time]) + + str_list = [] + # calculate the stats + for item in sale_dict: + average_week = 0 + average_week_amount = 0 + average_month = 0 + average_month_amount = 0 + average_all_time = 0 + average_all_time_amount = 0 + min_price = 0 + max_price = 0 + last_sold = 0 + + for n in range(len(sale_dict[item])): + + #out_obj.write('<tr>') + + if min_price > sale_dict[item][n][1]/sale_dict[item][n][0] or min_price == 0: + min_price = sale_dict[item][n][1]/sale_dict[item][n][0] + + if max_price < sale_dict[item][n][1]/sale_dict[item][n][0] or max_price == 0: + max_price = sale_dict[item][n][1]/sale_dict[item][n][0] + + if last_sold < sale_dict[item][n][2] or last_sold == 0: + last_sold = sale_dict[item][n][2] + + if (time.time()-sale_dict[item][n][2]) < 7*24*60*60: + average_week_amount += sale_dict[item][n][0] + average_week += sale_dict[item][n][1] + + if (time.time()-sale_dict[item][n][2]) < 30*24*60*60: + average_month_amount += sale_dict[item][n][0] + average_month += sale_dict[item][n][1] + + + average_all_time_amount += sale_dict[item][n][0] + average_all_time += sale_dict[item][n][1] + + average_all_time /= average_all_time_amount + if average_week_amount > 0: + average_week /= average_week_amount + if average_month_amount > 0: + average_month /= average_month_amount + + str_list.append([average_all_time_amount,'<td>'+ItemDB.getItem(item).name+'</td>'+'<td>'+locale.format("%d", average_all_time_amount, grouping=True)+'</td>'+ \ + '<td>'+ locale.format("%d", min_price, grouping=True) +'</td>'+'<td>'+ locale.format("%d", max_price, grouping=True) +'</td>'+'<td>'+ \ + locale.format("%d", average_week, grouping=True) +'</td>'+ '<td>'+ locale.format("%d", average_month, grouping=True) + \ + '</td>'+'<td>'+ locale.format("%d", average_all_time, grouping=True)+'</td>'+'<td>'+ time.asctime(time.gmtime(last_sold)) +'</td>']) + + while len(str_list) > 0: + pos = 0 + max_amount = 0 + for m in range(len(str_list)): + if max_amount < str_list[m][0] or max_amount == 0: + max_amount = str_list[m][0] + pos = m + out_obj.write('<tr>') + out_obj.write(str_list[pos][1]) + str_list.pop(pos) + + + out_obj.write('</tr> \n') + + out_obj.write('</table> \n') + out_obj.write('</br><b>Total sales: '+str(sale_total)+' GP</b> </br>') + out_obj.write('Updated: '+time.asctime(time.gmtime())+'</br>') + out_obj.write('For a detailed page showing all sales '+'<a href="manamarket.html">click here</a>') + + out_obj.write('</body></html> \n') + in_obj.close() + out_obj.close() + + +if __name__ == '__main__': + main() diff --git a/stats/process_salelog/utils.py b/stats/process_salelog/utils.py new file mode 100644 index 0000000..fd4e432 --- /dev/null +++ b/stats/process_salelog/utils.py @@ -0,0 +1,82 @@ +#!/usr/bin/python +""" + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + + This file is part of tradey, a trading bot in the mana world + see www.themanaworld.org +""" +from xml.etree.ElementTree import ElementTree +import time + +class Item: + pass + +# 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)) + +# Remove colors from a message +def remove_colors(msg): + if len(msg) > 2: + for f in range(len(msg)-2): + while (len(msg) > f + 2) and (msg[f] == "#")\ + and (msg[f+1] == "#"): + msg = msg[0:f]+msg[f+3:] + return msg + +# Encode string - used with 4144 shop compatibility. +def encode_str(value, size): + output = '' + base = 94 + start = 33 + while value: + output += chr(value % base + start) + value /= base + + while len(output) < size: + output += chr(start) + + return output + +class ItemDB: + """ + A simple class to look up information from the items.xml file. + """ + def __init__(self): + print "Loading ItemDB" + self.item_names = {} + self.itemdb_file = ElementTree(file="../data/items.xml") + + for item in self.itemdb_file.getroot(): + if item.get('id') > 500: + item_struct = Item() + item_struct.name = item.get('name') + if item.get('weight'): + item_struct.weight = item.get('weight') + if item.get('type'): + item_struct.type = item.get('type') + item_struct.description = item.get('description') + self.item_names[int(item.get('id'))] = item_struct + + def getItem(self, item_id): + return self.item_names[item_id] + + def findId(self, name): + for item_id in self.item_names: + if self.item_names[item_id].name == name: + return item_id + return -10 #Not found + +class ItemLog: + """ Writes all sales to a log file, for later processing.""" + def __init__(self): + self.log_file = 'data/logs/sale.log' + + def add_item(self, item_id, amount, price): + file_node = open(self.log_file, 'a') + file_node.write(str(item_id)+" "+str(amount)+" "+str(price)+" "+str(time.time())+"\n") + file_node.close() + +if __name__ == '__main__': + print "Do not run this file directly. Run main.py" diff --git a/stats/update_sales.sh b/stats/update_sales.sh new file mode 100755 index 0000000..62a4e1e --- /dev/null +++ b/stats/update_sales.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd /home/tmwserver/ManaMarket/stats +python /home/tmwserver/ManaMarket/stats/process_salelog/main.py /home/tmwserver/ManaMarket/data/logs/sale.log /var/www/tmw-homepage/server/manamarket.html +python /home/tmwserver/ManaMarket/stats/process_salelog/main_stat.py /home/tmwserver/ManaMarket/data/logs/sale.log /var/www/tmw-homepage/server/manamarket_stats.html +chmod 644 /var/www/tmw-homepage/server/manamarket.html /var/www/tmw-homepage/server/manamarket_stats.html @@ -1,26 +1,10 @@ #!/usr/bin/python """ -Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> -Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> -This file is part of tradey, a trading bot in The Mana World -see www.themanaworld.org - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Additionally to the GPL, you are *strongly* encouraged to share any modifications -you do on these sources. + This file is part of tradey, a trading bot in the mana world + see www.themanaworld.org """ import time import os @@ -1,26 +1,10 @@ #!/usr/bin/python """ -Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> -Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> + Copyright 2011, Dipesh Amin <yaypunkrock@gmail.com> + Copyright 2011, Stefan Beller <stefanbeller@googlemail.com> -This file is part of tradey, a trading bot in The Mana World -see www.themanaworld.org - -This program is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation; either version 2 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see <http://www.gnu.org/licenses/>. - -Additionally to the GPL, you are *strongly* encouraged to share any modifications -you do on these sources. + This file is part of tradey, a trading bot in the mana world + see www.themanaworld.org """ from xml.etree.ElementTree import ElementTree from player import Item @@ -128,9 +112,10 @@ class Broadcast: def send_broadcast(self): while self.Active: - if (time.time() - self.Timer) > 2 * 60: + if (time.time() - self.Timer) > 60: self.mapserv.sendall(emote(193)) self.Timer = time.time() + #print "shop_broadcast" else: time.sleep(0.1) |