目前,网上流行的QQ本地农场,本地开心农场,全部是PHP开发,有个PWSNS是.net开发,但是不开源,对于其他平台的程序来说,只能看着PHP程序使用,自己就没有办法吗?
那么多ASP,ASP.NET网站,没有办法?? 当然不是. 请看我对于php农场和其他语言的调研. 以下展示代码全部是Jscript [ASP]代码,部分方法基于
PHP本地农场的代码,大量使用了 键值对 的array 例如:
# 道具类型参数
$Toolstype = array(
"30001" => array("tId" => 1,"tName" => "普通化肥","price" => 400,"FBPrice" => 0,"YFBPrice" => 0,"timeLimit" => 0,"type" => 3,"effect" => 3600,"depict" => "每个阶段只能使用一次,减少该阶段成长时间1小时。","saleOut" => false),
"30002" => array("tId" => 2,"tName" => "高速化肥","price" => 0,"FBPrice" => 4,"YFBPrice" => 3,"timeLimit" => 0,"type" => 3,"effect" => 9000,"depict" => "每个阶段只能使用一次,减少该阶段成长时间2.5小时。","saleOut" => false),
"30003" => array("tId" => 3,"tName" => "极速化肥","price" => 0,"FBPrice" => 10,"YFBPrice" => 8,"timeLimit" => 0,"type" => 3,"effect" => 19800,"depict" => "每个阶段只能使用一次,减少该阶段成长时间5.5小时。","saleOut" => false),
"40001" => array("tId" => 1,"tName" => "狗","price" => "1000","FBPrice" => "0","YFBPrice" => "0","timeLimit" => 0,"type" => 4,"effect" => "","depict" => "可能抓住摘取果实的好友,罚的金币归主人所有。没有狗粮,狗不会抓人","saleOut" => false),
"40003" => array("tId" => 3,"tName" => "苏格兰牧羊犬","price" => "5000","FBPrice" => "0","YFBPrice" => "0","timeLimit" => 0,"type" => 4,"effect" => "","depict" => "可能抓住摘取果实的好友。牧羊犬比普通狗提高50%抓坏人的概率","saleOut" => false),
"9001" => array("tId" => 9001,"tName" => "普通狗粮","price" => 0,"FBPrice" => 4,"YFBPrice" => 3,"timeLimit" => 0,"type" => 909090,"effect" => "","depict" => "每购买1天普通狗粮,1天内狗会在一定几率下抓住摘取果实的好友","saleOut" => false),
"9002" => array("tId" => 9002,"tName" => "狗粮5送2礼包","price" => 0,"FBPrice" => 20,"YFBPrice" => 15,"timeLimit" => 0,"type" => 909090,"effect" => "","depict" => "一次性购买5天狗粮,可额外获赠2天狗粮,让狗狗为你看守农场一周","saleOut" => false)
);
那么翻译成JScript [或者叫 JSON 的形式] 是什么呢? 是对象:
代码
// 道具类型参数
$Toolstype = {
"30001" : {"tId" : 1,"tName" : "普通化肥","price" : 400,"FBPrice" : 0,"YFBPrice" : 0,"timeLimit" : 0,"type" : 3,"effect" : 3600,"depict" : "每个阶段只能使用一次,减少该阶段成长时间1小时。","saleOut" : false},
"30002" : {"tId" : 2,"tName" : "高速化肥","price" : 0,"FBPrice" : 4,"YFBPrice" : 3,"timeLimit" : 0,"type" : 3,"effect" : 9000,"depict" : "每个阶段只能使用一次,减少该阶段成长时间2.5小时。","saleOut" : false},
"30003" : {"tId" : 3,"tName" : "极速化肥","price" : 0,"FBPrice" : 10,"YFBPrice" : 8,"timeLimit" : 0,"type" : 3,"effect" : 19800,"depict" : "每个阶段只能使用一次,减少该阶段成长时间5.5小时。","saleOut" : false},
"40001" : {"tId" : 1,"tName" : "狗","price" : "1000","FBPrice" : "0","YFBPrice" : "0","timeLimit" : 0,"type" : 4,"effect" : "","depict" : "可能抓住摘取果实的好友,罚的金币归主人所有。没有狗粮,狗不会抓人","saleOut" : false},
"40003" : {"tId" : 3,"tName" : "苏格兰牧羊犬","price" : "5000","FBPrice" : "0","YFBPrice" : "0","timeLimit" : 0,"type" : 4,"effect" : "","depict" : "可能抓住摘取果实的好友。牧羊犬比普通狗提高50%抓坏人的概率","saleOut" : false},
"9001" : {"tId" : 9001,"tName" : "普通狗粮","price" : 0,"FBPrice" : 4,"YFBPrice" : 3,"timeLimit" : 0,"type" : 909090,"effect" : "","depict" : "每购买1天普通狗粮,1天内狗会在一定几率下抓住摘取果实的好友","saleOut" : false},
"9002" : {"tId" : 9002,"tName" : "狗粮5送2礼包","price" : 0,"FBPrice" : 20,"YFBPrice" : 15,"timeLimit" : 0,"type" : 909090,"effect" : "","depict" : "一次性购买5天狗粮,可额外获赠2天狗粮,让狗狗为你看守农场一周","saleOut" : false}
};
熟悉js的人,看出来了,对象就是键值对的组合.
里面还使用了大量的遍历对象的操作 foreach:
//装饰参数
$decorative = qf_decode($list[0]['decorative']);
foreach($decorative as $itemtype => $value) {
foreach($value as $key => $value1) {
if($value1['status'] == 1) {
if($_QFG['timestamp'] < $value1['validtime'] || $value1['validtime'] == 1) {
$decorative_echo[$itemtype]['itemId'] = $key;
} else {
unset($decorative[$itemtype][$key]);
$isUpdate = 1;
$decorative[$itemtype][$itemtype]['status'] = 1;
$decorative_echo[$itemtype]['itemId'] = $itemtype;
}
} else {
if($value1['validtime'] != 1 && $_QFG['timestamp'] >= $value1['validtime']) {
unset($decorative[$itemtype][$key]);
$isUpdate = 1;
}
}
}
}
这样的操作对于JScript来说,也很好应对 for .. in :
代码
//装饰参数
$decorative = qf_decode($list[0]["decorative"]);
var $decorative_echo={};
for(var $itemtype in $decorative ) {
var $value=$decorative[$itemtype];
$itemtype = parseInt($itemtype);
for( $key in $value) {
$value1 = $value[$key];
$key = parseInt($key);
if($value1["status"] == 1) {
if( timestamp < $value1["validtime"] || $value1["validtime"] == 1) {
$decorative_echo[$itemtype ] = {"itemId" :$key};
} else {
$decorative.splice($decorative[$itemtype][$key]);
$isUpdate = 1;
$decorative[$itemtype][$itemtype]["status"] = 1;
$decorative_echo[$itemtype ] = {"itemId" :$itemtype};
}
} else {
if($value1["validtime"] != 1 && $_QFG["timestamp"] >= $value1["validtime"]) {
$decorative.splice($decorative[$itemtype][$key]);
$isUpdate = 1;
}
}
}
}
php代码: 提示信息,他是组装字符串
代码
使用JScript翻译过来,可以直接使用json形式
//提示信息
if((int)$vip1['valid'] > $_QFG['timestamp']) {
$vipquantity = 2;
$levelup_arr = '{"title":"升级奖励","direction":"这么快就升级到' . $levelups[$levelup_exp]['level'] . '级了啊?真是神速,奖励你' . $levelups[$levelup_exp]['eDesc'] . ',快到背包里看看吧。","item":[{"eType":"' . $levelups[$levelup_exp]['eType'] . '","eParam":"' . $levelups[$levelup_exp]['eParam'] . '","eNum":"' . $levelups[$levelup_exp]['eNum'] . '"}],"level":' . $levelups[$levelup_exp]['level'] . ',"vipItem":[{"eType":"' . $levelups[$levelup_exp]['eType'] . '","eParam":"' . $levelups[$levelup_exp]['eParam'] . '","eNum":"' . $levelups[$levelup_exp]['eNum'] . '"}],"vipText":"你是VIP用户,还可额外再获赠以下奖励:"}';
} else{
$vipquantity = 1;
$levelup_arr = '{"title":"升级奖励","direction":"这么快就升级到' . $levelups[$levelup_exp]['level'] . '级了啊?真是神速,奖励你' . $levelups[$levelup_exp]['eDesc'] . ',快到背包里看看吧。","item":[{"eType":"' . $levelups[$levelup_exp]['eType'] . '","eParam":"' . $levelups[$levelup_exp]['eParam'] . '","eNum":"' . $levelups[$levelup_exp]['eNum'] . '"}],"level":' . $levelups[$levelup_exp]['level'] . '}';
}
代码
//提示信息
if(parseInt($vip1["valid"]) > timestamp ) {
$vipquantity = 2;
$levelup_arr = {"title":"升级奖励","direction":"这么快就升级到" + $levelups[$levelup_exp]["level"] + "级了啊?真是神速,奖励你" + $levelups[$levelup_exp]["eDesc"]+ ",快到背包里看看吧。","item":[{"eType": $levelups[$levelup_exp]["eType"] ,"eParam": $levelups[$levelup_exp]["eParam"] ,"eNum": $levelups[$levelup_exp]["eNum"] }],"level": $levelups[$levelup_exp]["level"] ,"vipItem":[{"eType": $levelups[$levelup_exp]["eType"] ,"eParam": $levelups[$levelup_exp]["eParam"] ,"eNum": $levelups[$levelup_exp]["eNum"] }],"vipText":"你是VIP用户,还可额外再获赠以下奖励:"};
} else{
$vipquantity = 1;
$levelup_arr = {"title":"升级奖励","direction":"这么快就升级到" + $levelups[$levelup_exp]["level"] + "级了啊?真是神速,奖励你"+ $levelups[$levelup_exp]["eDesc"] +",快到背包里看看吧。","item":[{"eType": $levelups[$levelup_exp]["eType"] ,"eParam": $levelups[$levelup_exp]["eParam"] ,"eNum": $levelups[$levelup_exp]["eNum"] }],"level": $levelups[$levelup_exp]["level"] };
}
来看一个具体的数据库转换成对象[php中数组,jscript中的json对象]
我使用了Smart ASP 后的代码:
代码
/*
获取某人信息
@uid 用户id
@tofriend 好友信息 == 查看别人的农场
@return
*/
getAll:function(uid,tofriend){
var sql = "SELECT C.money,C.username,C.uid,C.yb,C.vip,C.pf,C.tianqi,N.Status,N.reclaim,N.nc_e,N.exp,N.taskid,N.badnum,N.dog,N.decorative,N.activeItem,N.healthMode FROM uchome_qqfarm_config C Left JOIN uchome_qqfarm_nc N ON N.uid=C.uid where C.uid=?";
if(tofriend){
sql = "SELECT C.uid,C.username,C.money,C.pf,C.yb,N.Status,N.reclaim,N.exp,N.taskid,N.badnum,N.dog,N.decorative,N.activeItem,N.healthMode FROM uchome_qqfarm_config C Left JOIN uchome_qqfarm_nc N ON N.uid=C.uid where C.uid=?";
}
var db=getconn();
var params = [
db.createParam("uid", "int",uid, 11)
];
db.connect();
var rs = db.executeReader(sql,params);
var list = new Array();
list= db.rsToJson(rs);
db.close();
return list;
}
我相信,用Jscript开发这个是xx有可能的. ASP.net也可以使用json库进行开发.我以前也进行过尝试,比起这种原生支持json语法的环境,还是稍嫌麻烦了一点.
{zh1}贴一段 用户进入农场时候的请求 mod=user&act=run
代码
<%
function user_run(){
// 访问自己和别人农场
var ownerId = Request.QueryString("ownerId"),$toFriend=false;
var timestamp = SessionCache.val("timestamp");
var uid = SessionCache.val("uid");
if(ownerId >0 && uid != ownerId) {
$toFriend = true;
$uId = parseInt(ownerId);
}else{
$uId = uid;
}
var $list = FramInfo.getAll($uId,$toFriend);
//健康模式
$isUpdate = 0;
$healthMode = qf_decode($list[0]['healthMode']);
if( timestamp > $healthMode["endTime"]) {
$set = 0;
$valid = 0;
$canClose = 1;
if($healthMode["valid"] != 0) {
$isUpdate = 1;
$healthMode["beginTime"] = 0;
$healthMode["endTime"] = 0;
$healthMode["set"] = 0;
$healthMode["valid"] = 0;
$healthMode["canClose"] = 1;
$healthMode["date"] = "1970-01-01|1970-01-07";
}
} else if( timestamp < $healthMode["beginTime"] && $healthMode["beginTime"] != 0) {
$set = 1;
$valid = 0;
$canClose = 1;
} else {
$set = 1;
$valid = 1;
$canClose = 0;
}
if($isUpdate == 1) { //更新
JHFarm.updateHealthMode(uid,$healthMode);
$isUpdate = 0;
}
//农田参数
$Status = qf_decode($list[0]["Status"]);
for( var $key=0 ;$key< $Status.length ;$key++) {
//修复可能的错误
if($key >= $list[0]["reclaim"]) {
$Status.splice($Status[$key]);
$isUpdate = 1;
continue;
}
//更新作物状态
if($Status[$key]["a"] != 0) {
$a = $Status[$key]["a"];
$q = $Status[$key]["q"];
$k = $Status[$key]["k"];
$p = eval($Status[$key]["p"]);
$zuowutime = timestamp - $q;
if($zuowutime >= $cropstype[$a]["growthCycle"] && $k == 0 && $q != 0) {
$b = 6;
$c = 0;
$d = 0;
$e = 1;
$f = 0;
$g = 0;
$h = 1;
$k = $cropstype[$a]["output"];
$cnt = 0; //
for ($pk in $p) {
$pv = $p[$pk];
if($pv == 1 || $pv == 2) {
$cnt += Math.ceil(( timestamp - $pk) / 300) + 1;
} else if($pv == 3) {
$cnt += Math.ceil(( timestamp - $pk) / 300) * 2 + 2;
}
}
if($cnt > 50) {
$cnt = 50;
}
$k = Math.ceil($k * (100 - $cnt) / 100);
$l = Math.floor($k * 0.6);
$m = $k;
$Status[$key]["b"] = $b;
$Status[$key]["c"] = $c;
$Status[$key]["d"] = $d;
$Status[$key]["e"] = $e;
$Status[$key]["f"] = $f;
$Status[$key]["g"] = $g;
$Status[$key]["h"] = $h;
$Status[$key]["k"] = $k;
$Status[$key]["l"] = $l;
$Status[$key]["m"] = $m;
$isUpdate = 1;
}
}
}
if($isUpdate == 1) {
JHFarm.updateFarmStatus(uid,$Status);
$isUpdate = 0;
}
//装饰参数
$decorative = qf_decode($list[0]["decorative"]);
var $decorative_echo={};
for(var $itemtype in $decorative ) {
var $value=$decorative[$itemtype];
$itemtype = parseInt($itemtype);
for( $key in $value) {
$value1 = $value[$key];
$key = parseInt($key);
if($value1["status"] == 1) {
if( timestamp < $value1["validtime"] || $value1["validtime"] == 1) {
$decorative_echo[$itemtype ] = {"itemId" :$key};
} else {
$decorative.splice($decorative[$itemtype][$key]);
$isUpdate = 1;
$decorative[$itemtype][$itemtype]["status"] = 1;
$decorative_echo[$itemtype ] = {"itemId" :$itemtype};
}
} else {
if($value1["validtime"] != 1 && $_QFG["timestamp"] >= $value1["validtime"]) {
$decorative.splice($decorative[$itemtype][$key]);
$isUpdate = 1;
}
}
}
}
if($isUpdate == 1) {
JHFarm.updateDecorative(uid,$decorative);
$isUpdate = 0;
}
//狗狗参数
var $dog = qf_decode($list[0]["dog"]);
$dog["dogId"] = 0;
$dog["isHungry"] = 0;
if($_QFG["timestamp"] > $dog["dogFeedTime"]) {
$dog["isHungry"] = 1;
} else {
$dog["isHungry"] = 0;
}
if($dog) {
var $mydog = eval($dog["dogs"]);
for ($key in $mydog ) {
$value = $mydog[$key];
$key = parseInt($key);
if($value["status"] == 1) {
$decorative_echo["8"] = {"itemId" :80000 + $key};
$dog["dogId"] = $key;
}
}
}
//广告牌
if($list[0]["activeItem"] > 0) {
$decorative_echo["9"] = {"itemId" :$list[0]["activeItem"]};
}
//新手任务
$taskid = "";
$welcome = 0;
if($list[0]["taskid"] < 12) {
$taskid = {taskId: $list[0]["taskid"] ,taskFlag:1} ;
}
if($list[0]["taskid"] == 0) {
$taskid = { taskId:1,taskFlag:1 };
$welcome=1;
}
//返回信息
if($toFriend) {
Response.Write($.json.stringift({"a":0,"c":0,"dog": $dogstr ,"exp": $list[0]['exp'] ,"farmlandStatus": $Status ,"items": $decorative_echo ,"user":{"healthMode":{"beginTime": $healthMode['beginTime'] ,"canClose": $canClose ,"date":" $healthMode['date'] ","endTime": $healthMode['endTime'] ,"serverTime": $_QFG['timestamp'] ,"set": $set ,"time":" $healthMode['time'] ","valid": $valid },"pf": $list[0]['pf'] }}));
} else {
//使坏次数
$canbad = $list[0]["badnum"];
var db = getconn();
db.connect();
//消费提示
$isread = db.executeScalar("SELECT COUNT(*) FROM "+ getTName("qqfarm_nclogs") +" WHERE uid ="+ uid +" and isread = 0");
$a = $isread ? 1 : 0;
//留言提示
$isread =db.executeScalar("SELECT COUNT(*) FROM "+ getTName("qqfarm_message") +" WHERE toID ="+ uid+" and isread = 0");
db.close();
$c = $isread ? 1 : 0;
//天气
$tqq = "雨天";
if($list[0]["tianqi"] == 1) {
$tqq = "晴天";
}
//VIP状态
$vip = qf_decode($list[0]["vip"]);
//NPC任务参数
//if($_QSC["missionName"]) {
// include_once("source/nc/mission/{$_QSC["missionName"]}_vars.php");
//}
//$missionTime =$mission["PrepareTime"] ? strtotime($mission["PrepareTime"]) : $_QFG["timestamp"];
//输出信息
var result ;
try{
result ={
"farmlandStatus": $Status ,
"items": $decorative_echo ,
"exp": $list[0]["exp"] ,
"charm":0,
"dog": $dog ,
"weather":{"weatherDesc": $tqq , "weatherId": $list[0]["tianqi"] },
"serverTime":{"time": timestamp },
"user":{
"canbad": $canbad ,
"exp": $list[0]["exp"] ,
"headPic": qf_getheadPic(uid, "small") ,
"healthMode":{"beginTime": $healthMode["beginTime"] ,
"canClose": $canClose ,
"date": $healthMode["date"] ,
"endTime": $healthMode["endTime"] ,
"serverTime": $_QFG["timestamp"] ,
"set": $set ,
"time": $healthMode["time"] ,
"valid": $valid },
"missionTime": $_QFG["timestamp"], // $missionTime ,
"money": $list[0]["money"] ,
"pf": $list[0]["pf"] ,
"uId": $_QFG["uid"] ,
"userName": $list[0]["username"]
},
"a": $a ,
"c": $c ,
"cacheControl":{"diy":3,"seed":11,"tool":1},
"d": parseInt($vip["rsign"]==undefined?0:$vip["rsign"]) ,
"b":1,
"e": $list[0]["nc_e"] ,
"taskid" :$taskid,
"welcome" : $welcome
};
}catch(e){
debugger
throw e;
}
// debugger
Response.Write($.json.stringify(result));
// Response.Write("<br/>");
// Response.Write("<br/>");
// Response.Write("<br/>");
// Response.Write("<br/>");
// Response.Write("{\"farmlandStatus\":[{\"a\":2,\"b\":6,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":2,\"o\":0,\"p\":[],\"q\":1269011495,\"r\":1251351720,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":3,\"f\":1,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":2,\"o\":0,\"p\":[],\"q\":1269033095,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":3,\"f\":0,\"g\":0,\"h\":0,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":2,\"o\":0,\"p\":[],\"q\":1269033095,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":3,\"f\":0,\"g\":2,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":2,\"o\":0,\"p\":[],\"q\":1269022295,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":7,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":2,\"o\":0,\"p\":[],\"q\":0,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0},{\"a\":2,\"b\":7,\"f\":0,\"g\":0,\"h\":1,\"i\":[],\"j\":0,\"k\":16,\"l\":9,\"m\":16,\"n\":2,\"o\":0,\"p\":[],\"q\":0,\"r\":1251351725,\"s\":0,\"t\":0,\"u\":0}],\"items\":{\"1\":{\"itemId\":1},\"2\":{\"itemId\":2},\"3\":{\"itemId\":3},\"4\":{\"itemId\":4}},\"exp\":0,\"charm\":0,\"dog\":{\"dogId\":0,\"dogFeedTime\":0,\"dogUnWorkTime\":0},\"top\":\"\",\"weather\":{\"weatherId\":1},\"serverTime\":{\"time\":1269047534},\"user\":{\"uId\":\"2\",\"userName\":\"jxfsuda\",\"money\":0,\"FB\":\"0\",\"exp\":0,\"charm\":0,\"headPic\":\"/images/noavatar_small.gif\"},\"a\":0,\"c\":0,\"b\":0,\"task\":{\"taskId\":1,\"taskFlag\":1},\"welcome\":1}");
}
}
%>