Esempio n. 1
0
 /**
  * read the object information from the db
  */
 private function load($id)
 {
     $db = new DB();
     $sql = "SELECT pa.idgame, pa.action, pa.params, pa.idtable, pa.idplayer, UNIX_TIMESTAMP(pa.timestamp) AS timestamp\n                  FROM poker_actions AS pa \n                 WHERE pa.idaction = '{$id}'";
     $result = $db->query($sql);
     if ($result->length() > 0) {
         // general information
         $this->info = array("action" => $result->action, 'params' => unserialize($result->params), 'player' => $result->idplayer != '' && $result->idplayer != 0 ? PokerPlayer::getInstance($result->idplayer) : false, 'game' => Poker::getInstance($result->idgame), 'table' => PokerTable::getInstance($result->idtable), 'time' => $result->timestamp);
         $this->id = $id;
         return true;
     }
     return false;
 }
Esempio n. 2
0
 /**
  * read the object information from the db
  */
 private function load($id)
 {
     $db = new DB();
     $sql = "SELECT pt.idgame, pt.title, pp.idplayer, pt.d, pt.sb, pt.bb, pt.seats, pt.blind, pt.iduser, pt.idspot\n                  FROM poker_tables AS pt\n             LEFT JOIN poker_players AS pp ON (pp.idtable = pt.idtable AND pp.pactive = 1)\n                 WHERE pt.idtable = '{$id}'\n              ORDER BY pp.position";
     $result = $db->query($sql);
     if ($result->length() > 0) {
         $players = array();
         if ($result->idplayer != '') {
             $prev = false;
             do {
                 $player = PokerPlayer::getInstance($result->idplayer);
                 $player->prev = $prev;
                 if (is_object($prev)) {
                     $prev->next = $player;
                 }
                 $players[$player->position] = $player;
                 $prev = $player;
             } while ($result->next());
             $first = reset($players);
             $first->prev = $prev;
             $prev->next = $first;
         }
         // general information
         $this->info = array("game" => $result->idgame != 0 && $result->idgame != '' ? Poker::getInstance($result->idgame) : FALSE, "spot" => $result->idspot != 0 && $result->idspot != '' ? PokerSpot::getInstance($result->idspot) : FALSE, 'title' => $result->title, 'players' => $players, 'positions' => array('smallblind' => $result->sb, 'bigblind' => $result->bb, 'dealer' => $result->d), 'blinds' => array('big' => 2 * $result->blind, 'small' => $result->blind), 'seats' => $result->seats, 'user' => $result->iduser);
         $this->info['free'] = $this->info['seats'] - count($this->info['players']);
         $this->id = $id;
         return true;
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Build site content depending on requested action.
  */
 protected function buildSite()
 {
     switch ($this->s->action) {
         case 'debug':
             $range = '99+, AQs+, 74s-73s, Th6h, Tc6c, Qh5h, 9s5s, 9c5c, Qh4h, 9d4d, 9h4h, 8s4s, 8c4c, 8d3d, 8h3h, Kc2c, 4d2d, 4s2s, AQo+, Ad4s, Ah4s, As4d, As4h, As4c, Ac4s, Ad3c, Ah3c, As3c, Ac3d, Ac3h, Ac3s, Ad2h, Ad2s, Ad2c, Ah2d, As2d, Ac2d, Jd7s, Jh7s, Js7d, Js7h, 9d6s, 9h6s, 9s6d, 9s6h, 8d6c, 8h6d, 8s6h, 8c6d, 7h5d, 7h5c, 7s5c, 7c5s, 6d5s, 6h5s, 6s5d, 6c5d';
             $content = '<h2>' . $range . '</h2>';
             $range = explode(',', $range);
             $objDeck = new PokerDeck();
             $objDeck->shuffle();
             $range = new PokerRange($range, $objDeck);
             $cards = $range->getRandomPair();
             $content .= '<p>Expanded: ' . implode(', ', $range->range) . '</p>';
             $content .= '<p>Pairs: ' . implode(', ', $range->pairs) . '</p>';
             $content .= '<p>Cards: ' . $cards[0]->shortname() . ' / ' . $cards[1]->shortname() . '</p>';
             parent::buildSite($content);
             break;
         case 'play':
             $tpl = new Template('poker');
             $tables = PokerTable::getAll();
             foreach ($tables as $key => $table) {
                 $table->active = PokerPlayer::getActivePlayer($key) !== FALSE ? TRUE : FALSE;
                 $table->free = $table->seats - count($table->players);
             }
             if (count($tables) == 0) {
                 $content = '<h2>Keine Pokertische vorhanden. <a href="poker/poker_table-list">Pokertisch anlegen</a>?</h2>';
             } else {
                 $tpl->assign('tables', $tables);
                 $tpl->assign('current', '');
                 //current($tables));
                 $content = $tpl->fetch('games.html');
             }
             parent::buildSite($content);
             break;
         case 'show':
             if ($this->s->params[0] != '') {
                 $tpl = new Template('poker');
                 $tpl->assign('idtable', $this->s->params[0]);
                 $content = $tpl->fetch('game.html');
             } else {
                 $content = 'Es wurde kein Pokertisch ausgewählt, der angezeigt werden könnte!';
             }
             parent::buildSite($content, true);
             break;
         case 'save':
             if ($this->s->params[0] == 'table' && $this->s->params[2] != 0) {
                 $new_actions = PokerTable::getTableActions($this->s->params[2], $this->s->params[1]);
                 $actions = $this->getActionLog($new_actions);
             } elseif (is_array($this->s->post['games'])) {
                 $actions = array();
                 foreach ($this->s->post['games'] as $key => $idgame) {
                     $game = Poker::getInstance($idgame);
                     $actions = array_merge($actions, $this->getActionLog($game->actions));
                 }
             }
             if (is_array($actions)) {
                 header("Expires: 0");
                 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                 header("Content-Type: text/plain; charset=utf-8");
                 header("Content-Description: File Transfer");
                 header("Content-Disposition: attachment; filename=poker_log.txt");
                 header("Content-Transfer-Encoding: binary");
                 foreach ($actions as $key => $value) {
                     echo $value . "\r\n";
                 }
             }
             break;
         case 'archive':
             if ($this->s->params[0] == '') {
                 $table = FALSE;
                 $content = '<h2>Spiele für ' . $this->s->user->realname . '</h2><h3>Um die Liste der Spiele auf einem bestimmten Tisch anzuzeigen, wähle „Spiele anzeigen“ in der <a href="poker/poker_table-list">Liste der Tische</a> aus.</h3>';
             } else {
                 $table = PokerTable::getInstance($this->s->params[0]);
                 $content = '<h2>Spiele am Tisch „' . $table->title . '“.</h2>';
             }
             $content .= $this->listGames($table);
             parent::buildSite($content);
             break;
     }
 }