示例#1
0
 public function main()
 {
     //        $this->params = array(
     //            'a' => "user\\login",
     //            'p' => array(
     //                'uid' => 1,
     //                'params' => array(),
     //            ),
     //        );
     if (!$this->uid) {
         throw new common\error('错误的用户登陆');
     }
     $uInfo = $this->userModel->getUserById($this->uid);
     if (!$uInfo) {
         $initUserConfig = ZConfig::getField('init', 'user');
         $d = array('id' => $this->uid, 'coin' => $initUserConfig['coin'], 'created' => time());
         $this->userModel->addUser($d);
     }
     $uConnectInfo = $this->connection->get($this->uid);
     if (!$uConnectInfo) {
         $this->connection->add($this->uid, $this->fd);
         $this->connection->addFd($this->fd, $this->uid);
     } else {
         common\connection::close($uConnectInfo['fd']);
         $this->connection->add($this->uid, $this->fd);
         $this->connection->addFd($this->fd, $this->uid);
     }
     //        common\connection::sendOne($this->fd,'login', 'test send one');
     //        common\connection::sendToChannel('login', 'test send all');
     $this->data = array('global' => array('serverTime' => time(), 'nextRoundTime' => common\game::getNextRunTime(), 'currentRound' => common\game::getRuncount()), 'positionList' => common\game::getPositionList(), 'user' => $uInfo ? $uInfo : $d, 'map' => ZConfig::get('map'), 'item' => ZConfig::get('item'));
 }
示例#2
0
 public function main()
 {
     //        $this->params = array(
     //            'a' => "user\\ante",
     //            'p' => array(
     //                'uid' => 1,
     //                'params' => array(
     //                    'ante' => 'apple',
     //                    'type' => 1   //1:1 2:100
     //                ),
     //            ),
     //        );
     $this->checkLogin();
     //
     $nextRunTime = common\game::getNextRunTime();
     if (time() > $nextRunTime) {
         throw new common\error('非法押注.');
     }
     $anteName = $this->params['ante'];
     if (isset($this->params['type'])) {
         $anteType = intval($this->params['type']);
         if ($anteType == 1) {
             $anteRate = 1;
         } elseif ($anteType == 2) {
             $anteRate = 100;
         } else {
             $anteRate = ZConfig::getField('init', 'anteRate');
         }
     } else {
         $anteRate = ZConfig::getField('init', 'anteRate');
     }
     $currentGamecount = common\game::getRuncount();
     //check coin
     $userInfo = $this->userModel->getUserById($this->uid);
     $leftCoin = $userInfo['coin'] - $anteRate;
     if ($leftCoin < 0) {
         throw new common\error('押注不够.');
     }
     //        $this->userModel->updUserById($this->uid, array('coin' => $leftCoin));
     $returnDate = 0;
     if (!($userAnte = $this->useranteModel->getAnteByUidGamecount($this->uid, $currentGamecount))) {
         $_d = array('uid' => $this->uid, $anteName => $anteRate, 'gameCount' => $currentGamecount, 'created' => time());
         $this->useranteModel->addAnte($_d);
         $returnDate = $anteRate;
     } else {
         $val = $userAnte[$anteName] + $anteRate;
         if ($val > 999) {
             throw new common\error('最大押注为999.');
         }
         //update
         $_d = array($anteName => $val);
         $this->useranteModel->updAnteById($userAnte['id'], $_d, $userAnte);
         $returnDate = $_d[$anteName];
     }
     $this->userModel->updUserById($this->uid, array('coin' => $leftCoin));
     $this->data = array($anteName => $returnDate, 'coin' => $leftCoin);
     common\game::sendCurrentAnte();
 }
示例#3
0
 public function main()
 {
     //        $this->params = array(
     //            'a' => "user\\ante",
     //            'p' => array(
     //                'uid' => 1,
     //                'params' => array(
     //                ),
     //            ),
     //        );
     $this->checkLogin();
     $currentGamecount = common\game::getRuncount() - 1;
     //获取前面一次押注
     if (!($userAnte = $this->useranteModel->getAnteByUidGamecount($this->uid, $currentGamecount))) {
         throw new common\error('还未押注不能比大小');
     }
     $this->useranteModel->updAnteDiceById($userAnte['id'], $userAnte);
     $anteDiceCount = !empty($userAnte['anteDice']) ? $userAnte['anteDice'] + 1 : 1;
     //deal rate
     if ($anteDiceCount == 1) {
         $winRate = 50;
     }
     if ($anteDiceCount == 2) {
         $winRate = 40;
     }
     if ($anteDiceCount == 3) {
         $winRate = 30;
     }
     if ($anteDiceCount == 4) {
         $winRate = 20;
     }
     if ($anteDiceCount == 5) {
         $winRate = 10;
     }
     srand((double) microtime() * 1000000);
     $randval = rand(0, 100);
     if ($randval > $winRate) {
         //lost
         $this->data['result'] = 'lose';
         $this->data['getScore'] = 0;
         $this->userModel->updUserCoinById($this->uid, array('coin' => -$userAnte['score']));
         $packet = array('inPacket' => $userAnte['score'], 'outPacket' => 0);
     } else {
         //win
         $this->data['result'] = 'win';
         $this->data['getScore'] = $userAnte['score'] + $userAnte['score'] * ($anteDiceCount * 2 - 1);
         if ($anteDiceCount == 1) {
             $this->userModel->updUserCoinById($this->uid, array('coin' => $this->data['getScore'] - $userAnte['score']));
             $packet = array('inPacket' => 0, 'outPacket' => -abs($this->data['getScore'] - $userAnte['score']));
         } else {
             $this->userModel->updUserCoinById($this->uid, array('coin' => $this->data['getScore']));
             $packet = array('inPacket' => 0, 'outPacket' => -abs($this->data['getScore']));
         }
     }
     common\game::setInpacket($packet);
     $this->data['coin'] = $this->userModel->getUserById($this->uid)['coin'];
 }
示例#4
0
 public function onTimer()
 {
     $params = func_get_args();
     //$serv = $paramet_s[0];
     $interval = $params[1];
     //ms
     switch ($interval) {
         case 1000:
             //rungame
             $count = common\game::getRuncount();
             Debug::log("check execute game round[{$count}]\n");
             $nextRunTime = common\game::getNextRunTime();
             if ($nextRunTime == time()) {
                 //get pre round data
                 common\game::run();
                 $count = common\game::getRuncount();
                 Debug::log("calculate round[{$count}] data to client over.\n");
                 common\game::setRuncount();
                 $count = common\game::getRuncount();
                 Debug::log("begin game round[{$count}]\n");
             }
             break;
         case 10000:
             $list = common\connection::online();
             $onlineUsers = count($list);
             Debug::debug("{$interval} ms online users[{$onlineUsers}].\n");
             print_r($list);
             break;
     }
 }