Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Jan 7, 2014
2 parents ff740cc + ce7f090 commit 59163b4
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 40 deletions.
7 changes: 5 additions & 2 deletions config_sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ e = 'e'

[system]
server = tw
loglevel = 1
loglevel = 2
taskname = e
tasker_times = 0
try_factor_times = 20
Expand Down Expand Up @@ -52,7 +52,10 @@ session =

[fairy]

[carddeck]min = 124factor = 124,89,8
[carddeck]
min = 124
factor = 124,89,8

[condition]
fairy_select = fairy.NOT_BATTLED
explore_area = not FAIRY_ALIVE and area.NOT_FINNISHED and area.IS_EVENT
Expand Down
16 changes: 7 additions & 9 deletions maclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
BC_LIMIT_MAX, BC_LIMIT_CURRENT = -2, -1
#SERV_CN, SERV_CN2, SERV_TW = 'cn', 'cn2', 'tw'
# eval dicts
eval_fairy_select = [('LIMIT', 'time_limit'), ('NOT_BATTLED', 'not_battled'), ('.lv', '.fairy.lv'), ('IS_MINE', 'user.id == self.player.id'), ('IS_WAKE_RARE', 'wake_rare'), ('IS_WAKE', 'wake'), ('IS_GUILD', "race_type=='12'"), ('STILL_ALIVE', "self.player.fairy['alive']")]
eval_fairy_select = [('LIMIT', 'time_limit'), ('NOT_BATTLED', 'not_battled'), ('.lv', '.fairy.lv'), ('IS_MINE', 'user.id == self.player.id'), ('IS_WAKE_RARE', 'wake_rare'), ('IS_WAKE', 'wake'), ('IS_GUILD', "fairy.race_type=='12'"), ('STILL_ALIVE', "self.player.fairy['alive']")]
eval_fairy_select_carddeck = [('IS_MINE', 'discoverer_id == self.player.id'), ('IS_WAKE_RARE', 'wake_rare'), ('IS_WAKE', 'wake'), ('STILL_ALIVE', "self.player.fairy['alive']"), ('LIMIT', 'time_limit')]
eval_explore_area = [('IS_EVENT', "area_type=='1'"), ('IS_GUILD', "race_type=='12'"), ('IS_DAILY_EVENT', "id.startswith('5')"), ('NOT_FINNISHED', "prog_area!='100'")]
eval_explore_floor = [('NOT_FINNISHED', 'progress!="100"')]
Expand All @@ -49,13 +49,13 @@
logging = maclient_logging.Logging('logging') # =sys.modules['logging']

def setT(strt):
if not PYTHON3:
strt = strt.decode('utf-8').encode('cp936', 'ignore')
#if not PYTHON3:
# strt = strt.decode('utf-8').encode('cp936', 'ignore')
if sys.platform == 'cli':
import System.Console
System.Console.Title = strt
else:
os.system(convhans('TITLE %s' % strt))
os.system(du8('TITLE %s' % strt).encode(locale.getdefaultlocale()[1] or 'utf-8', 'replace'))

class set_title(threading.Thread):
def __init__(self, maInstance):
Expand Down Expand Up @@ -369,7 +369,7 @@ def tasker(self, taskname = '', cmd = ''):
logging.debug('tasker:%s' % task[0])
task[0] = task[0].lower()
if task[0] in plugin.extra_cmd:
plugin.do_extra_cmd(tasks)
plugin.do_extra_cmd(' '.join(task))
elif task[0] == 'set_card' or task[0] == 'sc':
if task[1] == '':
logging.error('set_card need 1 argument')
Expand Down Expand Up @@ -1733,7 +1733,7 @@ def reward_box(self, rw_type = '12345'):
if nid == []:
logging.info('没有符合筛选的奖励(%d)' % (len(rwds)))
else:
logging.info(strl.rstrip(' , ').replace('--', '&'))
logging.info(maclient_network.htmlescape(strl.rstrip(' , ').replace('--', '&')).replace('\n',' '))
res = self._get_rewards(nid)
if res[0]:
logging.info(res[1])
Expand Down Expand Up @@ -1849,9 +1849,7 @@ def factor_battle(self, minbc = 0, sel_lake = ''):
userlist = ct.body.battle_userlist.user_list.user
except KeyError: # no user found
continue
if len(userlist) == 18: # only 1 user
userlist = [userlist]
for u in userlist:
for u in self.tolist(userlist):
cid = int(u.leader_card.master_card_id)
cost = int(u.cost)
friends = int(u.friends)
Expand Down
44 changes: 23 additions & 21 deletions maclient_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import getpass
# look out for ironpython

def iter_printer(l, sep = '\n'):
cnt = 1
str = ''
for e in l:
str += '%d.%-10s%s' % (cnt, e.strip('\n'), (cnt % 3 and '' or sep))
cnt += 1
return str.decode('utf-8')
# def iter_printer(l, sep = '\n'):
# cnt = 1
# str = ''
# for e in l:
# str += '%d.%-10s%s' % (cnt, e.strip('\n'), (cnt % 3 and '' or sep))
# cnt += 1
# return str.decode('utf-8')

def getTerminalSize():
# http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python
Expand Down Expand Up @@ -121,7 +121,7 @@ def read_proxy(work = 0):
# 进入游戏
# maclient1._dopost('post_token',postdata=ma.encode_param('S=nosessionid&login_id=%s&password=%s&app=and&token=BubYIgiyDYTFUifydHIoIOGBiujgRzrEFUIbIKOHniHIoihoiHasbdhasbdUIUBujhbjhjBJKJBb'%(username,password)),usecookie=True,extraheader={'Cookie2': '$Version=1'})
# 登陆
server = maclient1._read_config('remote', 'maCServer') or 'http://mac.yooooo.us'
#server = maclient1._read_config('remote', 'maCServer') or 'http://mac.yooooo.us'
# auth()
mode = ['普通', '同时在线']
mod = 0
Expand Down Expand Up @@ -194,19 +194,21 @@ def read_proxy(work = 0):
maclient1.login()
mod = (mod + 1) % 2
elif ch == '3':
import maclient_network
cards = maclient_network.decode_param(read_proxy(work = 1))
cdeck = cards.split('&')[0].split('=')[1].strip('%0A').rstrip(',empty')
decks = maclient1._list_option('carddeck')
print(du8('选择卡组,输入卡组名以添加新卡组'))
print(iter_printer(decks))
inp = raw_input("> ")
if inp in [str(i) for i in range(1, len(decks) + 1)]:
name = decks[int(inp) - 1]
else:
name = inp
maclient1._write_config('carddeck', name, cdeck)
print(du8('保存到了%s' % name))
print(du8('此功能已转移至插件carddeck_edit'))
print(du8('请到这里查看详细帮助http://t.cn/8kDOLwV'))
# import maclient_network
# cards = maclient_network.decode_param(read_proxy(work = 1))
# cdeck = cards.split('&')[0].split('=')[1].strip('%0A').rstrip(',empty')
# decks = maclient1._list_option('carddeck')
# print(du8('选择卡组,输入卡组名以添加新卡组'))
# print(iter_printer(decks))
# inp = raw_input("> ")
# if inp in [str(i) for i in range(1, len(decks) + 1)]:
# name = decks[int(inp) - 1]
# else:
# name = inp
# maclient1._write_config('carddeck', name, cdeck)
# print(du8('保存到了%s' % name))
elif ch == '4':
print(du8('依次输入配置名,值\n输入h查看常用配置,输入e退出'))
while True:
Expand Down
17 changes: 16 additions & 1 deletion maclient_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Contributor:
# fffonion <[email protected]>
import os
import re
import sys
import time
import base64
Expand Down Expand Up @@ -148,7 +149,21 @@ def decrypt_file(self, filein, fileout, ext = 'png'):
pass

#ht = httplib2.Http(timeout = 15,proxy_info = httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, "192.168.124.1", 23300))

def htmlescape(htmlstr):
def replc(match):
# self._print match.group(0),match.group(1),match.group(2)
dict = {'amp':'&', 'nbsp':' ', 'quot':'"', 'lt':'<', 'gt':'>', 'copy':'©', 'reg':'®'}
# dict+={'∀':'forall','∂':'part','∃':'exist','∅':'empty','∇':'nabla','∈':'isin','∉':'notin','∋':'ni','∏':'prod','∑':'sum','−':'minus','∗':'lowast','√':'radic','∝':'prop','∞':'infin','∠':'ang','∧':'and','∨':'or','∩':'cap','∪':'cup','∫':'int','∴':'there4','∼':'sim','≅':'cong','≈':'asymp','≠':'ne','≡':'equiv','≤':'le','≥':'ge','⊂':'sub','⊃':'sup','⊄':'nsub','⊆':'sube','⊇':'supe','⊕':'oplus','⊗':'otimes','⊥':'perp','⋅':'sdot','Α':'Alpha','Β':'Beta','Γ':'Gamma','Δ':'Delta','Ε':'Epsilon','Ζ':'Zeta','Η':'Eta','Θ':'Theta','Ι':'Iota','Κ':'Kappa','Λ':'Lambda','Μ':'Mu','Ν':'Nu','Ξ':'Xi','Ο':'Omicron','Π':'Pi','Ρ':'Rho','Σ':'Sigma','Τ':'Tau','Υ':'Upsilon','Φ':'Phi','Χ':'Chi','Ψ':'Psi','Ω':'Omega','α':'alpha','β':'beta','γ':'gamma','δ':'delta','ε':'epsilon','ζ':'zeta','η':'eta','θ':'theta','ι':'iota','κ':'kappa','λ':'lambda','μ':'mu','ν':'nu','ξ':'xi','ο':'omicron','π':'pi','ρ':'rho','ς':'sigmaf','σ':'sigma','τ':'tau','υ':'upsilon','φ':'phi','χ':'chi','ψ':'psi','ω':'omega','ϑ':'thetasym','ϒ':'upsih','ϖ':'piv','Œ':'OElig','œ':'oelig','Š':'Scaron','š':'scaron','Ÿ':'Yuml','ƒ':'fnof','ˆ':'circ','˜':'tilde',' ':'ensp',' ':'emsp',' ':'thinsp','‌':'zwnj','‍':'zwj','‎':'lrm','‏':'rlm','–':'ndash','—':'mdash','‘':'lsquo','’':'rsquo','‚':'sbquo','“':'ldquo','”':'rdquo','„':'bdquo','†':'dagger','‡':'Dagger','•':'bull','…':'hellip','‰':'permil','′':'prime','″':'Prime','‹':'lsaquo','›':'rsaquo','‾':'oline','€':'euro','™':'trade','←':'larr','↑':'uarr','→':'rarr','↓':'darr','↔':'harr','↵':'crarr','⌈':'lceil','⌉':'rceil','⌊':'lfloor','⌋':'rfloor','◊':'loz','♠':'spades','♣':'clubs','♥':'hearts','♦':'diams'}
if match.groups > 2:
if match.group(1) == '#':
if match.group(2).startswith('x'):#xD, xA
return unichr(int(match.group(2)[1:],16))
else:
return unichr(int(match.group(2)))
else:
return dict.get(match.group(2), '?')
htmlre = re.compile("&(#?)(\d{1,5}|\w{1,8}|[a-z]+);")
return htmlre.sub(replc, htmlstr)

class poster():
def __init__(self, loc, logger, ua):
Expand Down
125 changes: 125 additions & 0 deletions plugins/carddeck_edit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# coding:utf-8
from _prototype import plugin_prototype
import sys
import os
import re
from cross_platform import *
from xml2dict import XML2Dict
# start meta
__plugin_name__ = 'scratch carddeck from REAL client'
__author = 'fffonion'
__version__ = 0.2
hooks = {}
extra_cmd = {'scratch_carddeck':'scratch_carddeck', 'scc':'scratch_carddeck','check_debug':'check_debug','cd':'check_debug',
'read_decks':'read_decks','rd':'read_decks'}
# end meta
def tolist(obj):
if not isinstance(obj, list):
return [obj]
else:
return obj

def iter_printer(l, sep = '\n'):
cnt = 1
str = ''
for e in l:
str += '%d.%-10s%s' % (cnt, e.strip('\n'), (cnt % 3 and '' or sep))
cnt += 1
return str.decode('utf-8')

def read_decks(plugin_vals):
def do(*args):
get=lambda x:XML2Dict().fromstring(x).response.body.roundtable_edit.deck_cards
poster=plugin_vals['poster']
pcard=plugin_vals['player'].card
cf=plugin_vals['cf']
list_option=cf.options
for i in range(1,4,1):
print(du8('卡组%d:'%i))
C=get(poster.post('roundtable/edit', postdata = 'move=1%s'%(i>1 and '&deck_id=%s'%i or ''))[1]).rstrip(',empty').split(',')
CL=tolist(C)
print(du8('\n'.join(['|'.join(map(
lambda x:' %-12s' % pcard.db[pcard.sid(x).master_card_id][0],
C[i:min(i + 3, len(CL))]
)) for i in range(0, len(CL), 3)])))
decks = list_option('carddeck')
print(du8('\n选择卡组,输入卡组名以添加新卡组,按回车跳过'))
print(iter_printer(decks))
inp = raw_input("> ")
if inp == "":
continue
elif inp in [str(i) for i in range(1, len(decks) + 1)]:
name = decks[int(inp) - 1]
else:
name = inp
write_config('carddeck', name, C)
print(du8('保存到了%s' % name))
#poster.post('roundtable/edit', postdata = 'move=1&deck_id=1')
return do

def scratch_carddeck(plugin_vals):
def do(*args):
cf=plugin_vals['cf']
list_option=cf.options
def write_config(sec, key, val):
if not cf.has_section(sec):
cf.add_section(sec)
cf.set(sec, key, val)
f = open(plugin_vals['configfile'], "w")
cf.write(f)
f.flush()
print(du8('注意:你必须使用修改版的odex文件才能截获卡组信息!\n你可以输入check_debug或cd来检查修改是否生效。\n你也可以使用更简单的read_decks来读取卡组'))
#check adb existence, wait for device
print(du8('=======请将手机连接电脑,别忘了打开USB调试,关闭电脑上的各种助手和豆荚'))
if os.system('adb wait-for-device')==1:
print(du8('未能运行adb,请去谷歌/度娘下载之-w-'))
return False
#clear buffer
os.system('adb logcat -c')
#suppress all but D/CJH
#btw CJH is...what?
logcat=os.popen('adb logcat CJH:D *:S')
print(du8('=======Good!'))
print(du8('请设置一次卡组,并保存\n你可以按Ctrl+C退出'))
while(1):
try:
line=logcat.readline()
C=re.findall('([\d|empty]+,[\d|empty]+,[\d|empty]+,[\d|empty]+,[\d|empty]+,[\d|empty]+,'
'[\d|empty]+,[\d|empty]+,[\d|empty]+,[\d|empty]+,[\d|empty]+,[\d|empty]+)',line)
if C!=[]:
decks = list_option('carddeck')
print(du8('\n选择卡组,输入卡组名以添加新卡组'))
print(iter_printer(decks))
inp = raw_input("> ")
if inp == "":
continue
elif inp in [str(i) for i in range(1, len(decks) + 1)]:
name = decks[int(inp) - 1]
else:
name = inp
write_config('carddeck', name, C[0].rstrip(',empty'))
print(du8('保存到了%s' % name))
else:
continue
except KeyboardInterrupt:
break
print(du8('请设置一次卡组,并保存\n你可以按Ctrl+C退出'))

return do

def check_debug(plugin_vals):
def do(*args):
print(du8('等待设备连接'))
os.system('adb wait-for-device')
os.system('adb logcat -c')
print(du8('请在游戏中随意执行一个操作。\n如果一直未能显示测试通过,请到这里查看详细帮助\nhttps://github.com/fffonion/MAClient/wiki/carddeck_edit'))
logcat=os.popen('adb logcat CJH:D *:S')
while(1):
try:
line=logcat.readline()
except KeyboardInterrupt:
break
if line.startswith('D/CJH'):
print(du8('测试通过!现在你可以输入scratch_carddeck或scc来抓取卡组了\n请按Ctrl+C退出'))
return
return do
8 changes: 4 additions & 4 deletions plugins/reg_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ def do(*args):
time.sleep(2.123123)
po.post('tutorial/next', postdata = 'S=%s&step=%s' % (po.cookie, 7025))
time.sleep(3.123123)
po.post('tutorial/next', postdata = 'S=%s&step=%s' % (po.cookie, 8000))
time.sleep(1.232131)
resp, ct = po.post('tutorial/next', postdata = 'S=%s&step=%s' % (po.cookie, 8000))
# httplib2 doesn't follow redirection in POSTs
resp, ct = httplib2.Http().request(maclient_network.serv[loc] + 'mainmenu?fl=1', headers = GET_header)
if len(ct) > 10000:
#resp, ct = httplib2.Http().request(maclient_network.serv[loc] + 'mainmenu?fl=1', headers = GET_header)
if len(ct) > 8000:
cnt += 1
print('Success. (%d done)' % cnt)
else:
print('Error occured.')
time.sleep(2.232131)
if raw_input('exit?(y/n)') == 'y':
print("Please relogin(rl) to refresh your playerdata!")
break
return do
# po.post('tutorial/next?step=100&resume_flg=1')
Expand Down
7 changes: 4 additions & 3 deletions plugins/web_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import _winreg as winreg
import gzip
import socket
import urllib

# start meta
__plugin_name__ = 'web broswer helper'
__author = 'fffonion'
__version__ = 0.2
__version__ = 0.3
hooks = {}
extra_cmd = {'web':'start_webproxy', 'w':'start_webproxy'}
# end meta
Expand Down Expand Up @@ -79,8 +80,8 @@ def disable_proxy():
winreg.SetValueEx(INTERNET_SETTINGS, 'ProxyEnable', 0, winreg.REG_DWORD, 0)
# winreg.DeleteKey(INTERNET_SETTINGS, 'ProxyOverride')
# winreg.DeleteKey(INTERNET_SETTINGS, 'ProxyServer')
# start simplest proxy
opener = urllib2.build_opener(urllib2.ProxyHandler({})) # force no proxy
# opener
opener = urllib2.build_opener(urllib2.ProxyHandler(urllib.getproxies()))
class Proxy(BaseHTTPRequestHandler):
def do_HDL(self):
req = urllib2.Request(self.path, headers = headers)
Expand Down

0 comments on commit 59163b4

Please sign in to comment.