Example #1
0
 public function router($cmd0, $cmd1, $cmd2, $player_id, $arr_param)
 {
     global $arrParam, $arrAuthUser, $logHandler;
     $arrAuthUser['player_id'] = $player_id;
     $arrParam = $arr_param;
     $class = 'S2P_' . $cmd1;
     $include_file = ACTION_PATH . "/S2P/S2P_{$cmd1}.php";
     if (is_file($include_file)) {
         require $include_file;
         try {
             //调用对应指令函数
             $obj = new $class();
             $exec_cmd2 = 'CMD2_' . $cmd2;
             if (ECONOMY_LOG_SWITCH === TRUE) {
                 $logHandler['logger'] = new Com_Logger($cmd0, $cmd1, $cmd2, $player_id);
             }
             call_user_func_array(array($obj, $exec_cmd2), array());
             $protocols = Protocol::get_protocol();
             Protocol::out();
             Statistic::report($cmd0, $cmd1, $cmd2, $arrAuthUser, $arrParam, 1, 'exec fun success', $protocols);
             if (ECONOMY_LOG_SWITCH === TRUE) {
                 $logHandler['logger']->flush_log();
             }
             exit;
         } catch (Exception $e) {
             //有异常
             $msg = json_decode($e->getMessage(), true);
             $error = "Exception: " . $e->getFile() . " line:" . $e->getLine() . " error code " . $msg['error']['code'];
             Statistic::report($cmd0, $cmd1, $cmd2, $arrAuthUser, $arrParam, 0, $error);
             Protocol::input($player_id, 8, 7, 742, array(0 => array($msg['error'])));
             Protocol::out();
             exit;
         }
     }
 }
Example #2
0
 public function dispatch()
 {
     file_put_contents(LOG_PATH . "/dispatch.log", "request:" . var_export($_REQUEST, true) . "\n", FILE_APPEND);
     if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
         $raw_post_data = $GLOBALS['HTTP_RAW_POST_DATA'];
     } else {
         $raw_post_data = file_get_contents("php://input");
         //获取消息体
     }
     //file_put_contents(LOG_PATH."/dispatch.log","raw_post_data:".var_export($raw_post_data,true)."\n",FILE_APPEND);
     //        $raw_post_data = str_replace("\'","\"",trim($raw_post_data,"'"));
     //        file_put_contents(LOG_PATH."/dispatch.log","raw_post_data_so:".var_export($raw_post_data,true)."\n",FILE_APPEND);
     $raw_post_data = json_decode($raw_post_data, true);
     //        file_put_contents(LOG_PATH."/dispatch.log","raw_post_data_json_decode:".var_export($raw_post_data,true)."\n",FILE_APPEND);
     $player_id = $raw_post_data['player_id'];
     $cmd0 = $raw_post_data['cmd0'];
     $cmd1 = $raw_post_data['cmd1'];
     $cmd2 = $raw_post_data['cmd2'];
     if ($cmd2 == 410 || $cmd2 == 413 || $cmd2 == 408) {
         $arrParam = $raw_post_data['params'];
         //            $raw_post_data['params'] = str_replace("\'","\"",trim($raw_post_data['params'],"'"));
         //            $arrParam = json_decode($raw_post_data['params'],true);
         if ($cmd2 == 410) {
             foreach ($arrParam as $key => $val) {
                 if (is_array($val)) {
                     foreach ($val as $k => $v) {
                         if ($v == 940005) {
                             $arrParam[$key][$k] = $player_id;
                         }
                     }
                 }
             }
         } elseif ($cmd2 == 413) {
             foreach ($arrParam as $key => $val) {
                 foreach ($val as $k1 => $v1) {
                     if (is_array($v1)) {
                         foreach ($v1 as $k2 => $v2) {
                             if (is_array($v2)) {
                                 foreach ($v2 as $k3 => $v3) {
                                     if ($v3 == 940005) {
                                         $arrParam[$key][$k1][$k2][$k3] = $player_id;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } elseif ($cmd2 == 408) {
             foreach ($arrParam as $key => $val) {
                 foreach ($val as $k => $v) {
                     foreach ($v as $g => $p) {
                         if ($p == 940005) {
                             $arrParam[$key][$k][$g] = $player_id;
                         }
                     }
                 }
             }
         }
     } else {
         $arrParam = $raw_post_data['params'];
     }
     $routerClass = '';
     if ($cmd0 == 2) {
         //C2P flash到php的指令
         define('UUZU_AUTH', 2);
         $include_file = APP_PATH . "/C2PRouter.php";
         $routerClass = 'C2PRouter';
     } elseif ($cmd0 == 4) {
         //S2P c++到php的指令
         define('UUZU_AUTH', 0);
         $include_file = APP_PATH . "/S2PRouter.php";
         $routerClass = 'S2PRouter';
     } else {
         die('cmd 0 error');
     }
     global $arrCmd;
     $arrCmd['cmd0'] = $cmd0;
     $arrCmd['cmd1'] = $cmd1;
     $arrCmd['cmd2'] = $cmd2;
     Statistic::tick($cmd0, $cmd1, $cmd2);
     $arrUser = array();
     $arrUser['player_id'] = $player_id;
     if (is_file($include_file)) {
         require $include_file;
         try {
             //调用对应指令函数
             $objRouterClass = new $routerClass();
             call_user_func_array(array($objRouterClass, 'router'), array($cmd0, $cmd1, $cmd2, $arrUser['player_id'], $arrParam));
         } catch (Exception $e) {
             //有异常
             Statistic::report($cmd0, $cmd1, $cmd2, $arrUser, $arrParam, 0, 'enter fail');
         }
     } else {
         Statistic::report($cmd0, $cmd1, $cmd2, $arrUser, $arrParam, 0, 'include file not exist');
         exit('include file not exist');
     }
 }