Example #1
0
 public function onReceive($server, $clientId, $fromId, $data)
 {
     $data = Yaaf::unpackAll($data);
     SysLog::notice(__METHOD__ . " fd = {$clientId}  fromId = {$fromId} data = " . print_r($data, true), __CLASS__);
     $info = $server->connection_info($clientId, $fromId);
     //yaaf 协议 路由
     $req = YaafHelper::yaafReqHandle($data);
     SysLog::info(__METHOD__ . print_r($req, true), __CLASS__);
     //路由失败 直接返回错误
     if ($req['r'] === YaafHelper::YAAF_ERROR_CMD) {
         //todo 协议搞成yaaf
         $yaaf_data = Yaaf::packHeader() . Yaaf::packBody(array('errCode' => -1, 'errMsg' => 'not found class'));
         $server->sendto($info['remote_ip'], $info['remote_port'], $yaaf_data);
         return;
     }
     $class = $req['route']['controller'] . 'Controller';
     $fun = 'action' . $req['route']['action'];
     //判断类是否存在
     if (!class_exists($class) || !method_exists($class, $fun)) {
         SysLog::error(__METHOD__ . print_r($req, true), __CLASS__);
         $yaaf_data = Yaaf::packHeader() . Yaaf::packBody(array('errCode' => -1, 'errMsg' => 'not found class'));
         $server->sendto($info['remote_ip'], $info['remote_port'], $yaaf_data);
         return;
     }
     $obj = new $class($this->server, array('request' => $data, 'info' => $info), $clientId);
     //代入参数
     $server->scheduler->newTask($obj->doFun($fun));
     $server->scheduler->run();
 }