admin管理员组文章数量:1567915
2024年3月4日发(作者:)
农场源码(delphi版)
interface
uses
Windows, SysUtils, Classes, StdCtrls, IdBaseComponent, IdComponent, StrUtils, ExtCtrls,
IdTCPConnection, IdTCPClient, IdHTTP, jpeg, IdAuthentication, IdHash,
IdHashMessageDigest,
PublicFunctions, IniFiles, Forms, ComCtrls, SHDocVw, Dialogs, Variants, DateUtils;
const
//QQ校友农场
Const_QQxyHost = '';
//QQ空间农场
Const_QQqzone = '';
//登录用的字符串
Const_PostLoginInfo = 'u=%s&p=%s&verifycode=%s';
Const_PostLoginStr
'&aid=15000102&u1=http%3A%2F%%%3Fmod%3D'+
'login&fp=&h=1&ptredirect=1&ptlang=0&from_ui=1&dumy=1';
=
//操作农场时,IdHTTP Referer 的值 通过GetFlaseVersion得到 IdHTTP Referer的全部字串
Const_Flase_Version = '/happyfarm/module/';
//FarmKey的形式
Const_farmKey = 'farmTime=%d&farmKey=%s';
//读取好友列表
Const_FriendsRefresh = 'refresh=true&farmTime=%d&farmKey=%s';
//自己ID,名字,时间,对方名称,farmKey
Const_Action =
'farmKey=%s&fName=%s&ownerId=%d&farmTime=%d&tName=%s&place=%d';
//Cookie的组成
Const_Cookie = 'Cookie: appTips=1; pt2gguin=%s; uin=%s; skey=%s; ptcz=%s; pvid=%s;
name=%s; schooltype=0; province=11; pst=%d; flv=10.0;';
//升一级加多少经验
CONST_OneLevelNum = 200;
//取FarmKey时,时间延后多少秒
Const_DelayFarmTime = 10;
type
//背包类型 0仓库 1商店 2包裹
TBagsType = (farm_Warehouse, farm_Goods, farm_Bag);
//动作类型 0偷取 1杀虫 2浇水 3除草 4收获
// 5松土 6种植 7全部卖出 8购买种子
// 9查看消息 10所有动作(在PostAction中没有实现义意,不作操作)
TActionType =(Action_scrounge, Action_spraying, Action_water, Action_clearWeed,
Action_harvest, Action_scarify, Action_planting, Action_Sale, Action_SaleAll,
Action_Buy, Action_getAllInfo, Action_ALL_OPP);
var
QQ_Cookie, VerifySession, farmKey, ConnHost,
Cookie_pt2gguin, Cookie_uin, Cookie_skey, Cookie_ptcz,
Cookie_pvid, Cookie_name, FlaseVersion: string;
farmTime, Cookie_pst: int64;
//服务器时间 本地时间 本地时间与服务器的时间差
QQ_ServerTime, Loc_ServerTime, DelayedDpikeInt : integer;
//将本地时间转成QQ服务器时间
function DateTimeToServerTime(aDateTime: TDateTime): integer;
function Preprocess(aPassWord, aVerifyCode:string):string;
//取得Flash版本 通过GetFlaseVersion得到 IdHTTP Referer的全部字串
procedure GetFlaseVersion(var aStr: string);
//取得验证码
function GetVerifyPic(aIdHTTP:TIdHTTP; var aImage: TImage): boolean;
//将汉字转换为unicode码
function AnsiToUnicode(aSubWideChar: PWideChar):string;
//将unicode码转换为汉字
function UnicodeToAnsi(aSubUnicode: string):string;
//提取字符串
function SubString(aInputStr, aStr_L, aStr_R:string):string;
function HashStr2BinStr(Hash: string):string;
function Fmd5(str: string):string;
//以Web形式登录QQ
function LoginQQ(aIdHTTP: TIdHTTP; aUserNameStr, aPasswordStr, aVerifyStr: string; var
aWebStr: string): Boolean;
//登录QQ校友社区
function LoginQQxiaoyou(aIdHTTP: TIdHTTP): Boolean;
//取自己农场数据
function GetMyFarmLandDB(aIdHTTP: TIdHTTP; var aWebStr: string): Boolean;
//取好友列表数据
function GetFriendsListDB(aIdHTTP: TIdHTTP; var aWebStr: string): Boolean;
//取好友农场数据
function GetFriendFarmLandDB(aIdHTTP: TIdHTTP; aUserID: integer; var aWebStr: string):
Boolean;
//计算等级 返回等级
function ResultLevel(aSumExp:integer; var aNowExp, aOutLevelMaxExp: integer): integer;
//分析仓库商店背包数据 aType 0仓库1商店2背包
function PostBagsBD(aIdHTTP:TIdHTTP; var aWebStr: string; aType: TBagsType): boolean;
//动作类型 0偷取 1杀虫 2浇水 3除草 4收获
// 5松土 6种植 7全部卖出 8购买种子
// 9查看消息 10所有动作(在PostAction中没有实现义意,不作操作)
//
//aActionType动作类型 是种植卖出购买种子还是做什么在此赋值
//aOwnerId是自己的UserID 必须为自己的UserID
//aPlace为地块的序号,从0开始 不用时可为0
//aSeedID 为作物种子的aID 种植卖出购买种子时用到 不用时可为0
function PostAction(aIdHTTP: TIdHTTP; var aWebStr: string; aActionType: TActionType;
aOwnerId, aPlace, aSeedID: integer): boolean;
//取得farmKey
function GetfarmKey(aInputTimeInt: Int64; var aFarmTime: int64; var aFarmKey: string): Boolean;
//写日志文件
procedure WriteLog(aQQnum, aLogStr, aAppPah: String);
implementation
//将本地时间转成QQ服务器时间 getTime() 方法傳回從 1970 年 1 月 1 日午夜開始計算的毫秒數
function DateTimeToServerTime(aDateTime: TDateTime): integer;
begin
Result:= DateTimeToUnix(aDateTime)-28800;
end;
//提取字符串
function SubString(aInputStr, aStr_L, aStr_R:string):string;
var
sPosB,sPosE:integer;
Lwhtml,LwCstr_L,LwCstr_R:string;
begin
Result:='';
if Trim(aInputStr)='' then
Exit;
Lwhtml:= LowerCase(aInputStr);
LwCstr_L := LowerCase(aStr_L);
LwCstr_R := LowerCase(aStr_R);
sPosB:= Pos(LwCstr_L, Lwhtml) + Length(LwCstr_L);
sPosE:= PosEx(LwCstr_R, Lwhtml, sPosB);
if (sPosB
Result:=Copy(aInputStr, sPosB, sPosE-sPosB);
end;
function HashStr2BinStr(Hash:string):string;
var
buf:array[0..63] of Char;
i:Integer;
begin
Result:='';
FillChar(buf, SizeOf(buf),0);
SetLength(Result, Round(Length(Hash)/2));
FillChar(Result[1], Length(Result),0);
HexToBin(PChar(Hash), buf,SizeOf(buf));
for i:=0 to Round(Length(Hash)/2)-1 do
Result:= buf;
end;
function Fmd5(str:string):string;
var
md5 : TIdHashMessageDigest5;
longWordRec : T4x4LongWordRecord;
begin
md5 := ;
try
{$IFDEF ID10}
Result:= ringAsHex(str);
{$ELSE}
longWordRec:= lue(str);
Result:= (longWordRec);
{$ENDIF}
finally
;
end;
end;
function md5_3(str:string):string;
begin
Result:= Fmd5(str);
Result:= HashStr2BinStr(Result);
Result:= Fmd5(Result);
Result:= HashStr2BinStr(Result);
Result:= Fmd5(Result);
end;
function Preprocess(aPassWord, aVerifyCode:string):string;
begin
Result:= Fmd5(md5_3(aPassWord) + UpperCase(aVerifyCode));
end;
//取得Flash版本
procedure GetFlaseVersion(var aStr: string);
var
tmpGerVersion: string;
tmpIdHTTP: TIdHTTP;
RespData: TStringStream;
begin
try
RespData:= ('');
tmpIdHTTP:= (Application);
tmpGerVersion:= Const_Flase_Version+'';
(tmpGerVersion, RespData);
tmpGerVersion:= Utf8ToAnsi(ring);
tmpGerVersion:= SubString(tmpGerVersion, 'name="main" url="module/', '"');
if pos('?v=', tmpGerVersion)=0 then
tmpGerVersion:= '?v=57';
aStr:= Const_Flase_Version + tmpGerVersion;
except
end;
;
end;
//取得验证码
function GetVerifyPic(aIdHTTP:TIdHTTP; var aImage: TImage): boolean;
var
ms:TMemoryStream;
pic:TJPEGImage;
begin
Result:=False;
try
ms:=;
try
ders;
;
:= '*/*';
Language:= 'zh-CN';
r:=
'/cgi-bin/login?link_target=blank&appid=15000102';
tType:= 'application/x-www-form-urlencoded';
Encoding:= 'gzip, deflate';
ent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1)';
tion:= 'Keep-Alive';
ontrol:= 'no-cache';
:= '';
:= Format('/getimage?aid=15000102&%0.15f', [Time()]);
:= '';
meout:= 15000;
( Format('/getimage?aid=15000102&%0.15f', [Time()]) ,
ms);
on:=0;
pic:=;
try
omStream(ms);
(pic);
finally
;
end;
QQ_Cookie:= '';
QQ_Cookie:= SubString(, 'Set-Cookie:
verifysession=', ';');
QQ_Cookie:= 'verifysession=' + QQ_Cookie + ';';
VerifySession:= QQ_Cookie;
;
('Cookie:'+QQ_Cookie);
Result:= True;
finally
;
end;
except
end;
end;
//转换
function Str_Gb2UniCode(text: string): String;
var
i,len: Integer;
cur: Integer;
t: String;
ws: WideString;
begin
Result := '';
ws := text;
len := Length(ws);
i := 1;
while i <= len do
begin
cur := Ord(ws[i]);
FmtStr(t,'%4.4X',[cur]);
Result := Result + t;
Inc(i);
end;
end;
//将汉字转换为unicode码
function AnsiToUnicode(aSubWideChar: PWideChar):string;
var
tmpLen, iCount: integer;
begin
Result:= '';
tmpLen:= Length(aSubWideChar);
for iCount:= 1 to tmpLen do
Result:= Result + 'u'+IntToHex(Ord(aSubWideChar[iCount-1]), 2);
end;
//将unicode码转换为汉字
function UnicodeToAnsi(aSubUnicode: string):string;
var
tmpLen, iCount: Integer;
tmpWS: WideString;
begin
tmpWS := '';
iCount := 1;
tmpLen := Length(aSubUnicode);
while iCount <= tmpLen do
try
if (Copy(aSubUnicode, iCount, 1)='')and
(Copy(aSubUnicode, iCount, 2)='u') then //'u7effzqu75d5'
begin
tmpWS := tmpWS + WideChar(StrToInt('$' + Copy(aSubUnicode, iCount+2, 4)));
iCount := iCount+6;
end
else
begin
tmpWS := tmpWS + Copy(aSubUnicode, iCount, 1);
iCount := iCount+1;
end;
except
end;
Result := tmpWS;
end;
//以Web形式登录QQ
function LoginQQ(aIdHTTP: TIdHTTP; aUserNameStr, aPasswordStr, aVerifyStr: string; var
aWebStr: string): Boolean;
var
PostData, RespData: TStringStream;
tmpStr: string;
begin
PostData:= ( Format(Const_PostLoginInfo, [aUserNameStr,
Preprocess(aPasswordStr, aVerifyStr),
aVerifyStr])
+ Const_PostLoginStr);
RespData:= ('');
Result:= False;
aWebStr:= '';
try
meout:= 15000;
:= 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/msword, */*';
tType:= 'application/x-www-form-urlencoded';
:= '';
r:=
'/cgi-bin/login?appid=15000102';
ent:= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1)';
Encoding:= 'gzip, deflate';
:= '/login';
//ders;
['Cookie'] := 'Cookie:'+QQ_Cookie;
('/login', PostData, RespData);
tmpStr:= Utf8ToAnsi(ring);
if pos('如果未能自动跳转,请 target="_top">点击
发表评论