芭芭农场自动脚本_农场游戏源码

芭芭农场自动脚本_农场游戏源码特此声明:此版本校内开心农场外挂由python语言编写,运行平台为linux。本代码是修改网络上流传的源码而成,本人贴出此代码没有任何利益想法,只当学习交流之用,并感谢源码开发者!#!/usr/bin/envpython#encoding:utf-8#2009-8-21升级后importurllib,urllib2,cookielibimporttime,zlib,r

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
特此声明:此版本校内开心农场外挂由python语言编写,运行平台为linux。本代码是修改网络上流传的源码而成,本人贴出此代码没有任何利益想法,只当学习交流之用,并感谢源码开发者!

#!/usr/bin/env python

#encoding: utf-8

#2009-8-21 升级后

import urllib,urllib2,cookielib

import time,zlib,re,md5

import cStringIO,gzip

import json

import pickle

import thread,sys,os

class Farm:

        debug=False

        status={} #self’s farm status

        friends={} #list of friends

        shop={} #information of seeds

        bag={} #背包

        uid=0 #user id

        autoweed=True #自动除草

        autonorm=True #自动杀虫

        autowater=True #自动浇水

        autofert=True #自动施肥

        autoplant=True #自动种植

        autosteal=True #自动收获

        #创建Cookie

        def __init__(self):

                cj=cookielib.LWPCookieJar()

                opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

                opener.addheaders=[(‘User-agent’,’Opera/9.23′)]

                urllib2.install_opener(opener)

        # 请求网页的工具函数,直接返回网页内容

        def req(self,url,body=()):

                if len(body)==0:

                        req=urllib2.Request(url)

                else:

                        req=urllib2.Request(url,urllib.urlencode(body))

                while True:

                        try:

                                raw=urllib2.urlopen(req)

                                break

                        except:

                                print ‘ReqError
url:%s’ % url

                                pass

           

                if self.debug: #输出调试信息

                        print url

                        print body

                return raw.read()

        def param(self): # build params farmKey and farmTime

                farmTime=str(time.time())[0:10]

                farmKey=md5.md5(farmTime+’15l3h4kh’).hexdigest()

                return (farmKey, farmTime)

        # 登录校内网 获取校内网到开心网的链接地址,并取得Cookie

        def login(self, email, password):

                url=”
http://passport.renren.com/PLogin.do

                body=((“email”,email),(“password”,password))

                ret=self.req(url, body)

                uids=re.findall(‘http\:\/\/renren\.com\/profile\.do\?id\=(\d+)’,ret)

                if len(uids)>0:

                        self.uid=uids[0]

                else:

                       print ret

                # build cookie to faminutes

                url=’http://apps.renren.com/happyfarm?origin=103′

                url=re.findall(‘iframe_canvas” src=”([^”]+)”‘,self.req(url))[0]

                url=url.replace(‘?’,’/?’).replace(‘&’,’&’) # fuck url, it lacks a ‘/’

                raw=self.req(url)

                # read current status

                url=’http://xn.hf.fminutes.com/api.php?mod=user&act=run&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                self.status=json.read(self.req(url))

        # 获取所有好友

        def listFriends(self):

                url=”
http://xn.hf.fminutes.com/api.php?mod=friend&farmKey=%s&farmTime=%s&inuId=” % self.param()

                self.friends=json.read(self.req(url))

        # 获取某好友信息

        def showFriend(self,fid):

                url=’http://xn.hf.fminutes.com/api.php?mod=user&act=run&flag=1&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:fid}

                return json.read(self.req(url,body))

        # 浇水 fid: 用户ID place:土地编号

        def water(self,fid,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=water&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:fid,’place’:place}

                return json.read(self.req(url,body))

        # 除草 fid:用户ID place:土地编号

        def clearWeed(self,fid,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=clearWeed&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:fid,’place’:place}

                return json.read(self.req(url,body))

        # 杀虫 fid:用户ID place: 土地编号

        def spraying(self,fid,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=spraying&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:fid,’tId’:0,’place’:place}

                return json.read(self.req(url,body))

        # 获取商店列表

        def scanShop(self):

                url=’http://xn.hf.fminutes.com/api.php?mod=shop&act=getShopInfo&type=1&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                print url

                self.shop=json.read(self.req(url))

                return self.shop

        # 查看自己购买的物品

        def getBag(self):

                url=’http://xn.hf.fminutes.com/api.php?mod=Package&act=getPackageInfo&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                self.bag=json.read(self.req(url))

                return self.bag

        # 翻土

        def scarity(self,fid,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=scarify&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:fid,’place’:place}

                return json.read(self.req(url,body))

        # 种植 cid: 种子编号 uid: 用户编号 place: 土地编号

        def plant(self,cid,uid,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=planting&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘cId’:cid,’ownerId’:uid,’place’:place}

                return json.read(self.req(url,body))

        # 施肥

        def fert(self,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=fertilize&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:self.uid,’tId’:1,’place’:place}

                return json.read(self.req(url,body))

        # 某好友的果实成熟时间列表

        def find(self,fid):

                self.scanShop()

                url=’http://xn.hf.fminutes.com/api.php?mod=user&act=run&flag=1&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:fid}

                ret=json.read(self.req(url,body))

                lands=ret[‘farmlandStatus’]

                result={}

                i=0

                for land in lands:

                        seeds=[x for x in self.shop[‘1’] if x[‘cId’]==land[‘a’]]

                        if len(seeds) == 1:

                                durtime=int(seeds[0][‘growthCycle’])+land[‘q’]

                                if durtime > time.time():#尚未成熟

                                        result[i]=’%s:\t%s’ % (seeds[0][‘cName’],str(durtime));

                                else:#已经成熟

                                        if 1==land[‘n’]: #已经偷过

                                                pass

                                        else:#

                                                result[i]=’%s:\tReady’ % seeds[0][‘cName’]

                        i+=1

                return result

        # 偷好友的果子 fid:好友编号 place:土地编号

        def steal(self,fid,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=scrounge&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={“ownerId”:fid,”place”:place}

                return json.read(self.req(url,body))

        def harvest(self,place):

                url=’http://xn.hf.fminutes.com/api.php?mod=farmlandstatus&act=harvest&farmKey=%s&farmTime=%s&inuId=’ % self.param()

                body={‘ownerId’:self.uid,’place’:place}

                return json.read(self.req(url,body))

   

        # 查找果实列表

        def autofind(self):

                self.listFriends()

                result={}

                for f in farm.friends: #输出所有好友

                        result[f[‘userId’]]=farm.find(f[‘userId’])

                return result

        # 升级

        def moneyGo(self,n=1):

                for i in range(n):

                        print i

                        self.scarity(self.uid,0)

                        self.plant(2,self.uid,0)

        # 自动运行 默认最小间隔20分钟

        def autorun(self,interval=20*60):

                if len(self.friends)==0:

                        self.listFriends()

                if len(self.shop)==0:

                        self.scanShop()

                self.bag=self.getBag() #背包

                ret={} #下次运行时间

  print self.friends[‘data’]

                for friend in self.friends[‘data’]:

                        print (time.ctime()+friend[‘userName’]).encode(‘utf-8’)

                        lands=self.showFriend(friend[‘userId’])[‘farmlandStatus’]

                        i=-1

                        for land in lands:#每块地

                                i+=1

                                s=[x for x in self.shop[‘1’] if x[‘cId’]==land[‘a’]]

                                if len(s)==0:#空地

                                        print u’\t%d\t空地’.encode(‘utf-8’) % i

                                if len(s)==1:#不是空地

                                        durtime=land[‘q’]+int(s[0][‘growthCycle’])

                                        if durtime < time.time(): #已经成熟

                                                if friend[‘userId’]==self.uid: #自己的地,收获

                                                        if land[‘b’]==6: #成熟

                                                                self.harvest(i)

                                                                stealed=u’收获’

                                                        elif land[‘b’]==7: #已经收获

                                                                stealed=u’已收’

                                                        else:

                                                                stealed=u’未知’

                                                        if self.autoplant: #自动种植

                                                                if land[‘b’] == 6 and land[‘j’]==s[0][‘maturingTime’] or land[‘b’]==7:

                                                                        self.scarity(self.uid,i) #翻地

                                                                        for seed in self.bag[‘1’]: #种值 if seed[‘type’]==1:

                                                                                        self.plant(seed[‘cId’],self.uid,i)

                                                                                        stealed+=u’已种’

                                                                                        self.getBag()

                                                                                        break

                                                else:#别人的地

                                                        if 1==land[‘n’]:

                                                                stealed=u’偷过’

                                                        elif land[‘b’]==7:

                                                                stealed=u’已收’

                                                        elif land[‘m’]==land[‘l’]:

                                                                stealed=u’偷光’

                                                        elif self.autosteal: #偷

                                                                temp=self.steal(friend[‘userId’],i)

                                                                if temp.has_key(‘harvest’):

                                                                    stealed=u’偷得%d’ % temp[‘harvest’]

                                                                elif temp[‘direction’]==”:

                                                                    print temp

                                                                else:

                                                                    print temp

                                                                    raise Exception

                                        else: #未成熟

                                                if (durtime-int(time.time())) < interval:#开新线程偷

                                                        print ‘set Thread %s’ % time.ctime(durtime)

                                                        if friend[‘userId’]==self.uid:

                                                                temp = -1

                                                        else:

                                                                temp = friend[‘userId’]

                                                        thread.start_new_thread(threadSteal,

                                                                        (self,durtime,temp,i))

                                                if not ret.has_key(friend[‘userId’]) or ret[friend[‘userId’]] > durtime:

                                                        ret[friend[‘userId’]]=durtime

                                                stealed=time.ctime(durtime)

                                                if friend[‘userId’]==self.uid and self.autofert: #自动施肥

                                                        temp=(int(time.time())-land[‘q’])/(int(s[0][‘growthCycle’])/5)-land[‘o’]

                                                        if not temp < 0:

                                                                temp=self.fert(i)

                                                                if temp.has_key(‘direction’):

                                                                        stealed+=temp[‘direction’]

                                                                else:

                                                                        stealed+=u’施肥’

                                        if land[‘f’] > 0:

                                                weed=str(land[‘f’])+u’草,已除’

                                                while self.autoweed and land[‘f’]>0:

                                                        self.clearWeed(friend[‘userId’],i)

                                                        land[‘f’]-=1

                                        else:

                                                weed=”

                                        if land[‘h’]==0:

                                                han=u’干旱,已浇水’

                                                if self.autowater:

                                                        self.water(friend[‘userId’],i)

                                        else:

                                                han=”

                                        if land[‘t’]>0 or land[‘g’]>0:

                                                if self.autonorm:

                                                        while land[‘g’]>0: #杀小虫

                                                                self.spraying(friend[‘userId’],i)

                                                                land[‘g’]-=1

                                                                norm=u’捉虫1′

                                                        if land[‘t’] > 0:  #杀大虫

                                                                self.spraying(friend[‘userId’],i)

                                                                norm=u’杀虫1/%d’ % land[‘t’]

                                        else:

                                                norm=”

                                        temp=u’\t%d\t%s\t%s\t%s\t%s\t%s’ % (

                                                        i,

                                                        s[0][‘cName’],

                                                        stealed,

                                                        weed,

                                                        han,

                                                        norm)

                                        print temp.encode(‘utf-8’)

                return ret.values()

#在时间T自动去偷

def threadSteal(farm, T, fid, place):

        time.sleep(T-int(time.time())+2)

        if fid==-1:

                temp=farm.harvest(place)

        else:

                temp=farm.steal(fid,place)

        if temp.has_key(‘harvest’):

                print u’Thread 偷得 %d at %s:%d’.encode(‘utf-8’) % (temp[‘harvest’],fid,place)

        else:

                print u’Thread Failed %s at %s:%d’.encode(‘utf-8’) % (temp,fid,place)

if __name__==’__main__’:

        farm = Farm()

        farm.debug= True

        running  = True

        interval=20*60

       

        print u’请输入校内网用户邮箱:’.encode(‘utf-8’)

        email=sys.stdin.readline()

        print u’请输入密码:’.encode(‘utf-8’)

        password=sys.stdin.readline()

        farm.login(email[0:len(email)-1],password[0:len(password)-1])

        while running:

                farm.autorun(interval=interval) #自动运行

                print u’进入自动运行模式(Y/N)?’

                autorun = sys.stdin.read(1);

                print autorun

                if autorun == ‘Y’ or autorun == ‘y’:

                    print u’%s等待下次运行:%d分钟后’.encode(‘utf-8’) % (time.ctime(),interval/60)

                    sys.stdout.flush()

                    time.sleep(interval)

                elif autorun == ‘N’ or autorun == ‘n’:

                    running = False

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/194577.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • tcp/ip和tcp协议(路由选择协议)

    一图看完本文一、计算机网络体系结构分层计算机网络体系结构分层计算机网络体系结构分层不难看出,TCP/IP与OSI在分层模块上稍有区别。OSI参考模型注重“通信协议必要的功能是什么”,而TCP/IP则更强调“在计算机上实现协议应该开发哪种程序”。二、TCP/IP基础1.TCP/IP的具体含义从字面意义上讲,有人可能会认为…

    2022年4月10日
    61
  • linux杀掉mysql进程_linux杀死pid进程

    linux杀掉mysql进程_linux杀死pid进程使用“ps-e|grepmysql”命令,查看mysql程序的对应的pid号。使用“kill-9进程号”命令,可以结束掉mysqld_safe进程。使用”killallmysqld”命令,可以杀掉所有已mysqld命名的进程。…

    2022年9月1日
    4
  • 用java web实现聊天室_java web实现简单聊天室「建议收藏」

    用java web实现聊天室_java web实现简单聊天室「建议收藏」目标servlet、jsp实现简单聊天室,用户通过浏览器登录后进入聊天室,可发送消息进行群聊,点击聊天信息框中的用户名可实现拍一拍功能。基础知识数据的存取setAttribute/getAttributerequest请求对象:有效时间短ServletContext上下文对象:一直存在于服务器,存储公有、共享数据Session会话对象:独立网站默认页面一般是index.jsp实现思路1….

    2022年6月22日
    42
  • directshow使用说明_Process Monitor

    directshow使用说明_Process Monitor1.关于DirectShow1.1、介绍DirectX是微软公司开发的一套基于Windows平台的编程接口(API);它能出色地完成高速的实时动画渲染、交互式音乐和环境音效、高效多媒体数据处理等一般API很难完成的任务。DirectShow是DirectX大家族中的一位成员。DirectX的家族成员很多,而且各有各的本领,就如DirectDraw和Direct3D负责二维图形图像/三维动画加速、DirectMusic和DirectSound负责交互式音乐/环境音效处理一样,DirectShow为

    2022年10月12日
    2
  • 静态分析工具之-AXMLPrinter2.jar的使用方法

    静态分析工具之-AXMLPrinter2.jar的使用方法

    2021年10月1日
    38
  • java全局变量引起的并发问题「建议收藏」

    java全局变量引起的并发问题「建议收藏」最近刚完成了一个短彩信群发平台的开发工作,系统采用springmvc+hibernate+jdbctemplate+mysql架构。其中遇见许多问题,闲暇之余记录下来以避免在后续项目中再犯同样的错误。先看下面小段代码,一个controller,一个service。       controller.java代码:    ……..    @Autowired

    2022年8月21日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号