示例#1
0
 public function onWorkerStop()
 {
     $params = func_get_args();
     $worker_id = $params[1];
     Debug::debug("WorkerStop[{$worker_id}]|pid=" . posix_getpid() . ".\n");
 }
示例#2
0
 public function main()
 {
     //---------------------------------------------------
     echo "Debug test:\n";
     Debug::log("debug log\n");
     Debug::info("debug info\n");
     Debug::debug("debug debug\n");
     Debug::error("debug error\n");
     Debug::error('debug error', 'aa', 'bb', 'cc');
     //pdo.php ping() 就是在执行sql的时候,失败的话,检查一下状态码。进行重连
     //---------------------------------------------------
     echo "\n\nDB option:\n";
     $user = $this->testModel->getAll();
     echo "get userMode one record.\n";
     print_r($user[0]);
     //---------------------------------------------------
     //fd opt
     echo "\n\nfd and connection option:\n";
     $uid = 10000;
     $uinfo = $this->connection->get($uid);
     if ($uinfo) {
         echo "already exist user.\n";
         print_r($uinfo);
     } else {
         echo "new add user.\n";
         $this->connection->add($uid, $this->fd);
         $this->connection->addFd($this->fd, $uid);
         print_r($this->connection->get($uid));
     }
     common\connection::sendOne($this->fd, 1, 'test send me');
     echo "send me sucess.\n";
     common\connection::sendToChannel(1, 'test send all');
     echo "send all sucess.\n";
     //加入到room1
     $this->connection->addChannel($uid, 'ROOM1');
     common\connection::sendToChannel(1, 'test send ROOM1', 'ROOM1');
     echo "send all room1.\n";
     //---------------------------------------------------
     echo "\n\ncache option:\n";
     $userinfo = array('id' => $uid, 'name' => 'ansen', 'sex' => 2);
     $this->cache->set('c_uid_' . $uid, json_encode($userinfo));
     echo "cache set userinfo sucess.\n";
     echo "get cache userinfo.\n";
     print_r(json_decode($this->cache->get('c_uid_' . $uid), true));
     //---------------------------------------------------
     echo "\n\nrank option:\n";
     $this->rankCache->addRank($rankType = 'global', $key = 'global_u1', $score = 1000, $length = 5);
     $this->rankCache->addRank($rankType = 'global', $key = 'global_u2', $score = 2000, $length = 5);
     $this->rankCache->addRank($rankType = 'global', $key = 'global_u3', $score = 500, $length = 5);
     $this->rankCache->addRank($rankType = 'global', $key = 'global_u4', $score = 100, $length = 5);
     $this->rankCache->addRank($rankType = 'global', $key = 'global_u5', $score = 6000, $length = 5);
     echo "add rank u1 u2 u3 u4 u5 over.\n";
     echo "get rank1:\n";
     $list1 = $this->rankCache->getRank($rankType = 'global', $start = 0, $limit = 100, $score = true, $desc = 0);
     print_r($list1);
     echo "get rank by score:\n";
     $list2 = $this->rankCache->getRankByScore($rankType = 'global', $start = 200, $end = 2000, $scores = true, $offset = 0, $count = 0);
     print_r($list2);
     echo "get rank by key(global_u3): 第";
     //排名第几
     echo $this->rankCache->getRankByKey($rankType = 'global', $key = 'global_u3', $desc = 0) . "位\n\n\n";
     //---------------------------------------------------
     echo "\n\ncd option:\n";
     $this->cdModel->addCd(10000, 'ansen');
     $this->cdModel->updCd(10000, 'ansen', array('cdCount' => 1, 'cdTimeStamp' => 234234));
     $cd = $this->cdModel->getCd(10000, 'ansen');
     print_r($cd);
     echo "get user keep login days:";
     echo $this->cdModel->getKeepLoginDays(10000);
     echo " days\n";
     //---------------------------------------------------
     //        echo "\n\nreids store struct option:\n";
     //        $username = '******';
     //        $password = '******';
     //
     //        $userid = $this->cache->increment("global:nextUserId");
     //        $this->cache->set("username:$username:id", $userid);
     //        $this->cache->set("uid:$userid:username", $username);
     //        $this->cache->set("uid:$userid:password", $password);
     //        //设置此用户密钥
     //        $authcookie = md5(time());
     //        $this->cache->set("uid:$userid:auth", md5(time()));
     //        $this->cache->set("auth:$authcookie", $userid);
     return 'finish action.';
 }
示例#3
0
 public static function run()
 {
     //get reward
     $reward = self::getReward();
     Debug::debug("get reward:\n");
     print_r($reward);
     //get next run time
     $reward['nextRunTime'] = self::setGameNextRunTime($reward['animationTime']);
     if (in_array($reward['name'], self::$gameTypes)) {
         if ($reward['name'] == 'dsy') {
             $reward['position'] = array(15, 19, 7);
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameDSY();
         }
         if ($reward['name'] == 'dhc') {
             $map = ZConfig::get('map');
             $point = rand(0, 23);
             //22
             $val1 = $point;
             $val2 = isset($map[$val1 + 1]) ? $val1 + 1 : 0;
             $val3 = isset($map[$val2 + 1]) ? $val2 + 1 : 0;
             $val4 = isset($map[$val3 + 1]) ? $val3 + 1 : 0;
             $val5 = isset($map[$val4 + 1]) ? $val4 + 1 : 0;
             $val6 = isset($map[$val5 + 1]) ? $val5 + 1 : 0;
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameDHC($val1, $val2, $val3, $val4, $val5, $val6);
         }
         if ($reward['name'] == 'xhc') {
             $map = ZConfig::get('map');
             $point = rand(0, 23);
             $val1 = isset($map[$point - 1]) ? $point - 1 : 23;
             $val2 = $point;
             $val3 = isset($map[$point + 1]) ? $point + 1 : 0;
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameXHC($val1, $val2, $val3);
         }
         if ($reward['name'] == 'dmg') {
             $randval1 = rand(0, 3);
             $randval2 = rand(4, 7);
             $randval3 = rand(8, 11);
             $randval4 = rand(12, 15);
             $randval5 = rand(16, 19);
             $randval6 = rand(20, 23);
             $reward['position'] = array($randval1, $randval2, $randval3, $randval4, $randval5, $randval6);
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameDMG($randval1, $randval2, $randval3, $randval4, $randval5, $randval6);
         }
         if ($reward['name'] == 'mtx') {
             $randval1 = rand(0, 6);
             $randval2 = rand(7, 15);
             $randval3 = rand(16, 23);
             $reward['position'] = array($randval1, $randval2, $randval3);
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameMTX($randval1, $randval2, $randval3);
         }
         if ($reward['name'] == 'xsy') {
             $reward['position'] = array(1, 6, 12);
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameXSY();
         }
         if ($reward['name'] == 'xsx') {
             //set reward position
             $reward['position'] = array(4, 10, 16, 22);
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameXSX();
         }
         if ($reward['name'] == 'null') {
             common\connection::sendToChannel(self::$CMDsendReward, $reward);
             self::gameNULL();
         }
     } else {
         //default
         //send reward to all
         common\connection::sendToChannel(self::$CMDsendReward, $reward);
         //结算
         self::getScoreTypeDefault($reward);
         //纪录当前的position 最多10 盘
         self::setPostionList($reward['position']);
     }
     //结算packet
     $Packet = self::getCurrentRoundInOutPacket();
     self::setInpacket($Packet);
 }