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')); }
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(); }
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; } }