Beispiel #1
0
 /**
  * 检查参数签名
  */
 function authSig($request)
 {
     $method = $request['m'];
     $param = $request['p'];
     if ($param['signature']) {
         $signature = $param['signature'];
         unset($param['signature']);
         $keys = array_keys($param);
         sort($keys);
         $s = '';
         foreach ($keys as $key) {
             $value = $param[$key];
             if (is_string($value) || is_numeric($value) || is_bool($value)) {
                 $s .= '&' . $key . '=' . $value;
             }
         }
         $s = substr($s, 1) . $method . P_VERSION . '~@#1xdaf,dmuopamie%%123.';
         $mysig = md5($s);
         if ($mysig != $signature) {
             glog::info("签名不对[{$mysig}]!=[{$signature}], " . json_encode($request), 'sign');
             return array('s' => StatusCode::invalid_siginature, 'msg' => 'invalid signature');
         }
         $timestamp = $param['timestamp'];
         if ($method == 'System.login') {
             // 手机设备时间和服务器时间可能有差异,所以第一次请求 System.login 时不验证时间。
             return false;
         }
         // 1. 对 timestamp 做验证 与 服务器当前时间相差太多的 认为是不合法的请求
         $now = getApp()->now;
         if (abs($now - $timestamp) > 300) {
             $ts1 = date('Y-m-d H:i:s', $now);
             $ts2 = date('Y-m-d H:i:s', $timestamp);
             glog::info("请求时间异常 server[{$ts1}], client[{$ts2}], " . json_encode($request), 'sign');
             return false;
             return array('s' => StatusCode::invalid_request_time, 'msg' => 'invalid timestamp');
         }
         // 2. 记录用户上次调用这个接口的时间戳,如果新的 timestamp <= old_timestamp 则认为是不合法的请求
         $uid = getApp()->getuid();
         $section_id = getApp()->getsec();
         if ($uid && $section_id) {
             if (model_Util::inBlacklist($uid)) {
                 //黑名单访问,禁止
                 glog::info("黑名单中玩家[{$uid}]访问分区[{$section_id}] " . json_encode($request), 'blacklist');
                 return array('s' => StatusCode::invalid_request_time, 'msg' => "uid[{$uid}] is in blacklist");
             }
             try {
                 $redis = DbConfig::getRedis('cache');
                 $timestamp_key = "sig_{$section_id}_{$uid}_{$method}";
                 $old_timestamp = $redis->get($timestamp_key);
                 if (is_numeric($old_timestamp)) {
                     // 手机端网络超时后重试,后台可能会收到两次同样时间戳的请求 所以 $timestamp == $old_timestamp 还是很有可能的
                     if ($timestamp < $old_timestamp) {
                         $ts1 = date('Y-m-d H:i:s', $old_timestamp);
                         $ts2 = date('Y-m-d H:i:s', $timestamp);
                         glog::info("请求时间异常, 上次请求[{$ts1}], 本次请求[{$ts2}], " . json_encode($request), 'sign');
                         return false;
                         return array('s' => StatusCode::outdated_siginature, 'msg' => 'outdated signature', 'debug' => "old_timestamp: {$old_timestamp}");
                     } else {
                         $redis->multi();
                         $redis->set($timestamp_key, $timestamp);
                         $redis->expire($timestamp_key, 360);
                         $redis->exec();
                         return false;
                     }
                 } else {
                     $redis->multi();
                     $redis->set($timestamp_key, $timestamp);
                     $redis->expire($timestamp_key, 360);
                     $redis->exec();
                     return false;
                 }
             } catch (Exception $ex) {
                 error_log("无法连接 cache redis ");
                 return false;
             }
         }
         return false;
     }
     glog::info("没有签名," . json_encode($request), 'sign');
     return array('s' => StatusCode::invalid_siginature, 'msg' => 'no signature');
 }
Beispiel #2
0
 /**
  * 血战排行奖励发送
  */
 public function action_bloodyrank()
 {
     $app = app();
     $now = $app->now;
     $last_day = date("Ymd", $now - 86400);
     $section_config = $app->getSectionConfig();
     //繁体、简体都上血战
     $plats = array("appstore", "gamecomb", "ios91", "iosky", "iospp", "iostb", "mix", "qqandroid", "wuxia", "kunlun", "appstoretw", "dev", "winphone", "xp");
     $section_ids = array_keys($section_config);
     $rank_reward_configs = PL_Config_Numeric::get("xuezhan/xuezhanrankreward");
     $zhenrong_hash = array('5' => "五人阵", '6' => "六人阵", '7' => "七人阵", '8' => "八人阵");
     if (P_PLATFORM == "kunlun" || P_PLATFORM == 'appstoretw') {
         $zhenrong_hash = array('5' => "五人陣", '6' => "六人陣", '7' => "七人陣", '8' => "八人陣");
     }
     if (P_PLATFORM == "vietnam") {
         $zhenrong_hash = array('5' => "5 người", '6' => "6 người", '7' => "7 người", '8' => "8 người");
     }
     $cday = 59;
     $hmyredis = model_HeiMuYa::getRedis();
     ob_start();
     $xuezhan_chenghao = PL_Config_Numeric::get("chenghaosetting", "xuezhan_rank");
     $redis = DbConfig::getRedis("lunjian");
     foreach ($section_ids as $sec) {
         $mergesec_info_key = "merge_sec_info_" . $sec;
         $mergeinfo = $hmyredis->get($mergesec_info_key);
         //todo是否合区过
         if (!empty($mergeinfo)) {
             $is_merge_sec = true;
         } else {
             $is_merge_sec = false;
         }
         if (P_PLATFORM == "gamecomb" && $sec == "s1000" || P_PLATFORM == "ios91" && $sec == "s1000") {
             $cday = 63;
         }
         //合区的时间和距离的天数
         $merge_time = $mergeinfo['merge_end_time'];
         $dis_day = floor(($now - $merge_time) / 86400);
         echo "==============   {$sec}:   =================\n\n";
         foreach ($zhenrong_hash as $zhenrongsize => $zhenrongname) {
             $rank_tag = "bloodyrank_{$zhenrongsize}_{$last_day}_{$sec}";
             if ($is_merge_sec == true && $dis_day <= $cday) {
                 $rank_reward_configs = PL_Config_Numeric::get("xuezhan/xuezhanrankrewardhefu");
                 $ranklist = $redis->zrevrange($rank_tag, 0, 39, "withscores");
             } else {
                 $rank_reward_configs = PL_Config_Numeric::get("xuezhan/xuezhanrankreward");
                 $ranklist = $redis->zrevrange($rank_tag, 0, 19, "withscores");
             }
             $current_place = 1;
             foreach ($ranklist as $uid => $score) {
                 $continue_reward = 0;
                 $ready_send_key = "bloodyrank_rsend_{$zhenrongsize}_{$last_day}_{$sec}";
                 $rsend_data = $redis->hget($ready_send_key, $uid);
                 if ($rsend_data) {
                     echo "ready_send,{$uid},{$sec},{$zhenrongsize}\n";
                     continue;
                 }
                 try {
                     $player = new model_Player($uid, $sec);
                     //------
                     if ($current_place == 1) {
                         //check possible
                         $player_d = $player->getFields(array('vip', 'reslimit'));
                         if ($player_d['vip']['lvl'] < 3 && $player_d['reslimit']['count_dizi_4'] < 2 || model_Util::inBlacklist($uid)) {
                             glog::info("{$uid},{$sec},{$score}", 'bloodyrankwarning');
                             //$redis->zadd($rank_tag,-$score,$uid);
                             //model_Util::addBlacklist($uid,"血战数据有疑问,vip{$player_d['vip']['lvl']}, 排$current_place名");
                             $warningcontent = "[{$uid}]血战数据有疑问,vip{$player_d['vip']['lvl']}, 甲弟子数量{$player_d['reslimit']['count_dizi_4']},排{$current_place}名 or 在黑名单中\n";
                             $mtitle = "xuezhan warning:" . P_PLATFORM . ";{$sec}";
                             model_Util::sendemail('op@playcrab.com,genshaomeng@playcrab.com,srgzyq@playcrab.com,wangyucheng@playcrab.com,kf@playcrab.com', $mtitle, $warningcontent);
                             //continue;
                         }
                     }
                     //------
                     $battleinfo = $player->objectGet('base', 'bloodybattle');
                     if (!isset($battleinfo['historyinfo']['last_rank_d'])) {
                         $last_rank_d = date("Ymd", $battleinfo['historyinfo']['start_t']);
                     } else {
                         $last_rank_d = $battleinfo['historyinfo']['last_rank_d'];
                     }
                     $days = (strtotime($last_day) - strtotime($last_rank_d)) / 86400;
                     $battleinfo['historyinfo']['fighting_days'] = $days;
                     $battleinfo['historyinfo']['last_rank_d'] = $last_day;
                     if ($days == 1) {
                         $battleinfo['historyinfo']['continus_rank_days']++;
                     } else {
                         $battleinfo['historyinfo']['continus_rank_days'] = 0;
                     }
                     //连续进榜奖励
                     if (P_PLATFORM != 'gamevil') {
                         //沒有翻譯,韓國
                         $continue_days = $battleinfo['historyinfo']['continus_rank_days'];
                         if ($continue_days > 0 && $continue_days < 5) {
                             $continue_reward = 5;
                         } else {
                             if ($continue_days >= 5) {
                                 $continue_reward = 10;
                             }
                         }
                     }
                     $battleinfo['historyinfo']['last_rank_d'] = $last_day;
                     $player->objectPut('bloodybattle', 'historyinfo', $battleinfo['historyinfo']);
                     //todo add xuezhan rank chenghao, with time
                     foreach ($xuezhan_chenghao as $xuezhan_rank_chenghao) {
                         if ($current_place <= $xuezhan_rank_chenghao['rank']) {
                             break;
                         }
                     }
                     $chenghao = array('tag' => $xuezhan_rank_chenghao['chenghaotag'], 'level' => 1, 'create_t' => $app->now);
                     $player->objectPut("chenghao", $chenghao['tag'], $chenghao);
                     $player->commit();
                     //if($is_merge_sec && $dis_day <= $cday && $current_place > 20){
                     //  $awards = $rank_reward_configs[20]["reward_for_".$zhenrongsize];
                     //}else{
                     $awards = $rank_reward_configs[$current_place]["reward_for_" . $zhenrongsize];
                     //}
                     if ($is_merge_sec && $dis_day <= $cday) {
                         $econtent = "额外奖励20%元宝";
                         foreach ($awards as $ak => $av) {
                             if ($av['tag'] == "gem") {
                                 $awards[$ak]['num'] = $awards[$ak]['num'] + ceil($awards[$ak]['num'] * 0.2);
                             }
                         }
                     }
                     $desc_str = model_Cdkey::descriptItems($awards);
                     $key = uniqid();
                     echo "{$uid}: ";
                     //如果有额外奖励元宝,需要从$awards中减去额外元宝,但是真实增加并不改变
                     //下面获取描述时是没有加进榜前
                     $msg_str = model_Translate::get('tid#xuezhan_reward');
                     eval("\$content = \"{$msg_str}\";");
                     //连续进榜奖励增加
                     if ($continue_reward) {
                         foreach ($awards as $ak => $av) {
                             if ($av['tag'] == "gem") {
                                 $awards[$ak]['num'] += $continue_reward;
                             }
                         }
                     }
                     //进榜奖励在这里拼装描述
                     if ($continue_reward) {
                         $extra_xuezhan_str = model_Translate::get('tid#act_xuezhan_continue_reward');
                         eval("\$extra_xuezhan_str = \"{$extra_xuezhan_str}\";");
                         $content .= $extra_xuezhan_str;
                     }
                     echo $content . "\n";
                     //$now = getApp()->now;
                     $msg = array('key' => $key, 'time' => $now, 'content' => $content, 'type' => 'system');
                     $msg['status'] = 'award';
                     //$awards包含进帮奖励的元宝
                     $cdkey = model_Cdkey::gen($awards, $desc_str, 1, "bloodyrank_{$last_day}_{$sec}");
                     $msg['cdkey'] = $cdkey;
                     model_Chat::sendMsg($msg, $player->uid, 'origin', $sec);
                     if (in_array(P_PLATFORM, $plats)) {
                         //开服活动血战排名奖励 start
                         $flag = 1;
                         //标记活动延后一天发放
                         $config = model_ActivityUtil::getBooldRankBonusData($sec, $flag);
                         //活动开启后推迟一天发放活动奖励  结束后保证发放最后一次活动奖励
                         $config['start_t'] = $config['start_t'] + 86400;
                         $config['end_t'] = $config['end_t'] + 86400;
                         //if(($app->now - $config['start_t']) >= 86400 && ($app->now - $config['end_t']) < 86400){
                         //print_r($config);exit();
                         if ($now > $config['start_t'] && $now < $config['end_t']) {
                             $awards_boold = array();
                             //只发排名前20
                             if ($current_place <= 20) {
                                 if (array_key_exists($current_place, $config['bonus'])) {
                                     $awards_boold = $config['bonus'][$current_place];
                                 } else {
                                     if ($current_place >= 6 && $current_place <= 10) {
                                         $config_key = '6-10';
                                     } elseif ($current_place >= 11 && $current_place <= 15) {
                                         $config_key = '11-15';
                                     } elseif ($current_place >= 16 && $current_place <= 20) {
                                         $config_key = '16-20';
                                     }
                                     $awards_boold = $config['bonus'][$config_key];
                                 }
                             }
                             $rmsg_str = model_Translate::get('tid#bloody_act_rank_award');
                             eval("\$rcontent = \"{$rmsg_str}\";");
                             model_Award::awardToUser($player->uid, $sec, $rcontent, $awards_boold);
                         }
                         //开服活动血战排名奖励 end
                     }
                     $redis->hset($ready_send_key, $uid, $now);
                     $expire_time = strtotime(date("Y-m-d 00:00:00")) + 24 * 60 * 60 * 7;
                     $redis->expireAt($ready_send_key, $expire_time);
                     $current_place++;
                 } catch (Exception $excep) {
                     $ex_msg = $excep->getMessage();
                     $ex_trace_msg = $excep->getTraceAsString();
                     $excep_content = "{$ex_msg}\n{$ex_trace_msg}";
                     $subject = "血战发放出错_" . P_PLATFORM . "_" . $rank_tag . "_" . $uid;
                     model_Util::sendemail('op@playcrab.com,wangyucheng@playcrab.com,srgzyq@playcrab.com,kf@playcrab.com', $subject, $content);
                 }
             }
         }
     }
     // del ranks a week ago
     $last_week = $now - 86400 * 7;
     $last_week_str = date("Ymd", $last_week);
     echo ">>>>>>>>>>>>>>>>>>>>>>>>>delete ranks a week ago<<<<<<<<<<<<<<<<<<<<\n";
     foreach ($section_ids as $sec) {
         echo "==============   {$sec}:   =================\n\n";
         foreach ($zhenrong_hash as $zhenrongsize => $zhenrongname) {
             $rank_tag = "bloodyrank_{$zhenrongsize}_{$last_week_str}_{$sec}";
             $ready_send_key = "bloodyrank_rsend_{$zhenrongsize}_{$last_week_str}_{$sec}";
             if ($redis->del($ready_send_key)) {
                 echo "[delete_rsend] :{$ready_send_key}\n";
             }
             if ($redis->del($rank_tag)) {
                 echo "[delete] :{$rank_tag}\n";
             }
         }
     }
     $output_content = ob_get_contents();
     ob_end_clean();
     echo $output_content;
     $weekday = date("w", strtotime($last_day));
     $file_name = LOG_ROOT . "/bloodyrank.{$weekday}.log";
     file_put_contents($file_name, $output_content);
     $config = getApp()->getActivityConfig("act_kfxuezhan");
     if ($now >= $config['start_t'] + 86400 && $now <= $config['end_t'] + 86400) {
         model_Crontab::kfbloodyrank();
     }
 }