$bet_items2[$bi['bi_id']] = $bi['bi_description' . $suffix]; // assign bi_id as key and bi_description as value $bi_id_of_winner = $bi['bi_winner'] ? $bi['bi_id'] : $bi_id_of_winner; } $info_per_bet_item = getInfoPerBetItem($all_bets); // get placed coins, bet users, and ratio $user_may_earn = getUserMayEarn($info_per_bet_item, $game['g_houseCom']); // if game is already closed if ($game['g_isClosed']) { $is_closed = true; $display_uri = $user_bettings ? "?q=yourgame&cat={$game_cat}&sort=time" : "?q=results&cat={$game_cat}&sort=time"; $notice .= $lang[254]; // "This game already closed" $notice_display = "block"; $notice_class = "gameclosed"; $user_bettings = getUserBets($game_id, $user_id); $user_won = checkUserWon($user_id, $game_id); $top_winners = getTopWinners($info_per_bet_item, $bet_items2, $bi_id_of_winner); // get maximum of 10 top winners if ($user_won) { //$user_won_after_commission = $user_won - ($user_won * ($game['g_houseCom'] / 100)); $user_congratulations_text = str_replace('$COIN_VARIABLE', $user_won_after_commission, $lang[257]); } } // if game has ended but not yet closed or judged if (time() > $game['g_schedTo'] and !$game['g_isClosed']) { $display_uri = $user_bettings ? "?q=yourgame&cat={$game_cat}&sort=time" : "?q=results&cat={$game_cat}&sort=time"; $notice = $lang[556]; $notice_display = "block"; $notice_class = "judgement"; } else {
$bool = false; $game_id = isset($_POST['gi']) ? $_POST['gi'] : 0; $bi_id = isset($_POST['wi']) ? $_POST['wi'] : 0; // winning item $coin_div = isset($_POST['div']) ? $_POST['div'] : 0; // commission $is_cancel = isset($_POST['cancel']) ? $_POST['cancel'] : 0; // cancel this game $house_com = isset($_POST['hc']) ? $_POST['hc'] : 0; // house commission $total_bet_amt = isset($_POST['tc']) ? $_POST['tc'] : 0; // total coins bet for this game if ($is_cancel != 'false') { // cancel the game; return bets cancelGame($game_id); $user_bets = getUserBets($game_id); // get all user bets from this game $bool = returnUserBets($user_bets, $game_id, true); // insert to coin_deals table and update users' COIN. true means it's cancelled } else { // close the game; process winners closeGame($game_id); // close this game setBetItemWinner($bi_id); // bet_item db table setUserBetWinners($game_id, $bi_id); // tag the winners in user_bets db table $winners = getUserBetWinners($game_id, $bi_id); // get all user bets that won from this game //$total_bet_amt = returnUserBets($winners); // return users' bets and update users' coins $house_com_amt = $house_com / 100 * $total_bet_amt;
function checkAndActOnAllSameBets($f_arrTable) { $arrBets = getUserBets(); if (1 == count($arrBets)) { // Only one player left $fTotalPot = db_select_one(TABLE_BETS . ' b, ' . TABLE_POOLS . ' po', 'SUM(bet)', 'b.pool_id = po.id AND po.table_id = ' . TABLE_ID); $iUserId = key($arrBets); db_update(TABLE_PLAYERS, 'balance = balance+' . $iUserId . ', last_action = \'Won ' . (double) $fTotalPot . '\' due to fold', 'table_id = ' . TABLE_ID . ' AND user_id = ' . $iUserId); db_update(TABLE_TABLES, 'state = 0', 'id = ' . TABLE_ID); return true; } $iReady = db_count(TABLE_PLAYERS, 'table_id = ' . TABLE_ID . ' AND in_or_out = \'in\''); if ($iReady == count($arrBets) && 1 == count(array_flip($arrBets))) { if (6 === (int) $f_arrTable['state']) { // Showdown $fTotalPot = db_select_one(TABLE_BETS . ' b, ' . TABLE_POOLS . ' po', 'SUM(bet)', 'b.pool_id = po.id AND po.table_id = ' . TABLE_ID); $arrPubCards = array(new Card($f_arrTable['public_card_1']), new Card($f_arrTable['public_card_2']), new Card($f_arrTable['public_card_3']), new Card($f_arrTable['public_card_4']), new Card($f_arrTable['public_card_5'])); $arrWinners = array(); $fMaxScore = 0.0; foreach ($arrBets as $iUserId => $b) { $p = db_select(TABLE_PLAYERS, 'table_id = ' . TABLE_ID . ' AND user_id = ' . $iUserId); $arrPrivCards = array(new Card($p[0]['private_card_1']), new Card($p[0]['private_card_2'])); $fScore = pokertexasholdem::score(array_merge($arrPubCards, $arrPrivCards)); if ($fScore > (double) $fMaxScore) { $fMaxScore = $fScore; $arrWinners = array(); } if ((double) $fScore === (double) $fMaxScore) { $arrWinners[] = $iUserId; } } $fUserWinnings = floor($fTotalPot * 100 / count($arrWinners)) / 100; db_update(TABLE_PLAYERS, 'balance = balance+' . $fUserWinnings . ', last_action = \'Won [' . $fUserWinnings . '] with a [' . pokertexasholdem::readable_hand($fMaxScore) . ']\'', 'table_id = ' . TABLE_ID . ' AND user_id IN (' . implode(',', $arrWinners) . ')'); db_update(TABLE_TABLES, 'state = 0', 'id = ' . TABLE_ID); return true; } db_update(TABLE_PLAYERS, 'ready_for_next_round = \'0\'', 'table_id = ' . TABLE_ID); $f_arrTable['current_seat'] = $f_arrTable['dealer_seat']; saveNextSeat($f_arrTable, 'state+1'); return true; } return false; }