public static function show()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $bet = new Bet($_POST);
         if ($bet->getErrorCount() == 0) {
             //make sure authenticatedUser is set
             $authenticatedUser = array_key_exists('authenticatedUser', $_SESSION) ? $_SESSION['authenticatedUser'] : null;
             if (is_null($authenticatedUser)) {
                 $bet->setError('user', 'USER_NOT_AUTH');
                 BetView::show($bet);
                 return;
             }
             $hockname = $authenticatedUser->getHockName();
             $bet->setUser(strtolower($hockname));
             //game exists check
             $games = GameDB::getGamesBy('id', $bet->getGameID());
             if (empty($games)) {
                 $bet->setError('game', 'NO_GAMEID');
                 BetView::show($bet);
                 return;
             }
             //user already has a bet check
             $game = $games[0];
             $bets = BetDB::getBetsBy('game', $game->getID());
             if (!empty($bets)) {
                 foreach ($bets as $bet) {
                     if (strcmp($bet->getUser(), strtolower($hockname)) == 0) {
                         $bet->setError('game', 'BET_ALREADY');
                         BetView::show($bet);
                         return;
                     }
                 }
             }
             //pending check
             if ($game->getPending() != 1) {
                 $bet->setError('game', 'GAME_NOT_PENDING');
                 BetView::show($bet);
                 return;
             }
             //game time check
             $start = new DateTime($game->getStart());
             $diff = $start->diff($bet->getTime());
             if ($diff->m != 0 || $diff->d != 0 || $diff->h != 0 || $diff->i >= 5) {
                 $bet->setError('game', 'LATE_BET');
                 BetView::show($bet);
                 return;
             }
             //Should be ok to submit bet...
             $id = BetDB::addBet($bet);
             $bet->setBetID($id);
             BetView::show($bet);
             //SimpleEchoView::show($bet);
         } else {
             BetView::show($bet);
         }
     } else {
         // Initial link
         BetView::show(null);
     }
 }
 public static function run()
 {
     $action = array_key_exists('action', $_SESSION) ? $_SESSION['action'] : "";
     $arguments = $_SESSION['arguments'];
     switch ($action) {
         case "all":
             $_SESSION['games'] = GameDB::getAllGames();
             GameView::showAll();
             break;
         default:
     }
 }
 public static function show()
 {
     $arguments = array_key_exists('arguments', $_SESSION) ? $_SESSION['arguments'] : 0;
     $hockusers = HockUserDB::getUsersBy('name', $arguments);
     $hockuser = !empty($hockusers) ? $hockusers[0] : null;
     $webuser = null;
     if (is_null($hockuser)) {
         $hockusers = HockUserDB::getUsersBy('alias', $arguments);
         $hockuser = !empty($hockusers) ? $hockusers[0] : null;
     }
     if (!is_null($hockuser)) {
         $webusers = WebUserDB::getUsersBy('hockName', $hockuser->getUserName());
         if (!empty($webusers)) {
             $webuser = $webusers[0];
         }
     }
     if (!is_null($hockuser)) {
         $teams1 = TeamDB::getTeamsBy('uid1', $hockuser->getUserId());
         $teams2 = TeamDB::getTeamsBy('uid2', $hockuser->getUserId());
         $teams3 = TeamDB::getTeamsBy('uid3', $hockuser->getUserId());
         $allteams = array_merge($teams1, $teams2, $teams3);
         if (!is_null($allteams)) {
             $allgames = array();
             foreach ($allteams as $team) {
                 $game = GameDB::getGamesBy('teamid1', $team->getteamId());
                 $game2 = GameDB::getGamesBy('teamid2', $team->getteamId());
                 if (!empty($game)) {
                     array_push($allgames, $game[0]);
                 }
                 if (!empty($game2)) {
                     array_push($allgames, $game2[0]);
                 }
             }
             if (empty($allgames)) {
                 echo '<p>All games is empty</p>';
                 $_SESSION['allgames'] = null;
             } else {
                 usort($allgames, "UserController::cmp");
                 $_SESSION['allgames'] = $allgames;
             }
         }
         ProfileView::show($webuser, $hockuser);
     } else {
         $_SESSION['allgames'] = null;
         ProfileView::show(null, null);
     }
 }
Exemple #4
0
<?php

require_once 'debug.inc';
require_once 'gamedb.inc';
$db = new GameDB();
$db->initPlayerSession();
$db->commit();
$enc = 'Windows-1252';
//'utf-8';
echo '<' . '?xml version="1.0" encoding="' . $enc . '"?' . '>';
?>
<html>
<head>
    <?php 
Util::printStylesheets('css/main.css');
Util::printScripts('scriptaculous-1.8.2/prototype.js', 'scriptaculous-1.8.2/scriptaculous.js?load=effects,dragdrop', 'javascript/rpc.js', 'javascript/util.js', 'javascript/main.js', 'javascript/debug.js', 'javascript/observerlist.js', 'javascript/animation.js');
?>
</head>
<body onload="init()">
    <script type="text/javascript" language="javascript">
      // <![CDATA[
      var initialState = {
          pieces: <?php 
echo json_encode($db->getPieces());
?>
,
          gameID: <?php 
echo json_encode($db->getGameID());
?>
,
          playerID: <?php 
Exemple #5
0
 public static function updateGame($game)
 {
     // Update a user
     try {
         $db = Database::getDB();
         if (is_null($game) || $game->getErrorCount() > 0) {
             return $game;
         }
         $checkGame = GameDB::getGamesBy('id', $game->getID());
         if (empty($checkGame)) {
             $game->setError('id', 'GAME_DOES_NOT_EXIST');
         }
         if ($game->getErrorCount() > 0) {
             return $game;
         }
         $query = "UPDATE games SET pending = :pending, losereport = :losereport, winreport = :winreport, end = :end\r\n\t    \t\t\t                 WHERE id = :id";
         $statement = $db->prepare($query);
         $statement->bindValue(":id", $game->getID());
         $statement->bindValue(":pending", $game->getPending());
         $statement->bindValue(":losereport", $game->getLoseReport());
         $statement->bindValue(":winreport", $game->getWinReport());
         $statement->bindValue(":end", $game->getEnd());
         $statement->execute();
         $statement->closeCursor();
     } catch (Exception $e) {
         // Not permanent error handling
         $game->setError('id', 'GAME_COULD_NOT_BE_UPDATED');
     }
     return $game;
 }
Exemple #6
0
<?php

/**
 * AJAX entry point.
 */
require_once 'debug.inc';
require_once 'util.inc';
require_once 'gamedb.inc';
function getDispatchTable()
{
    global $db;
    return array('commitBoard' => array($db, 'handleCommitBoard'), 'poll' => array($db, 'handlePoll'), 'helloWorld' => array($db, 'handleHelloWorld'));
}
// TODO: Consider using the raw request body to
// provide your very own RPC call encoding.
//$requestBody = file_get_contents("php://input");
$db = new GameDB();
$db->initPlayerSession();
$dispatchTable = getDispatchTable();
$functionName = Util::getParameter('name');
if (!array_key_exists($functionName, $dispatchTable)) {
    die('Unknown request: "' . htmlspecialchars($functionName) . '"');
}
$encodedArgs = Util::getParameter('args');
$args = json_decode($encodedArgs, true);
if ($args === null) {
    die('Failed parsing: "' . $encodedArgs . '"');
}
$result = call_user_func($dispatchTable[$functionName], $args);
echo json_encode($result);
Exemple #7
0
 public static function showGames()
 {
     $base = array_key_exists('base', $_SESSION) ? $_SESSION['base'] : "";
     //echo '<div class="container">';
     echo '<h1>Bet On These Active Games</h1>';
     //$games = (array_key_exists('activegames', $_SESSION))?$_SESSION['activegames']:array();
     $games = GameDB::getGamesBy('pending', 1);
     if (empty($games)) {
         //echo '</div>';
         return;
     }
     echo '<div class="table-responsive">';
     echo '<table class="table">';
     echo '<thead>';
     echo '<tr>';
     echo '<th>GameID</th>';
     echo '<th>User1</th>';
     echo '<th>User2</th>';
     echo '<th>User3</th>';
     echo '<th>TeamSkill</th>';
     echo '<th>+/-</th>';
     echo '<th>User4</th>';
     echo '<th>User5</th>';
     echo '<th>User6</th>';
     echo '<th>TeamSkill</th>';
     echo '<th>+/-</th>';
     echo '<th>Length</th>';
     echo '</tr>';
     echo '</thead>';
     echo '<tbody>';
     $authenticatedUser = array_key_exists('authenticatedUser', $_SESSION) ? $_SESSION['authenticatedUser'] : null;
     //iterate through all games
     foreach ($games as $game) {
         //If the game is not finished or had a bad/cancel don't show here
         if ($game->getPending() != 1) {
             continue;
         }
         $teams = TeamDB::getTeamsBy('id', $game->getTeamID1());
         if (empty($teams)) {
             break;
         }
         $team1 = $teams[0];
         $teams = TeamDB::getTeamsBy('id', $game->getTeamID2());
         if (empty($teams)) {
             break;
         }
         $team2 = $teams[0];
         if (is_null($team1) || is_null($team2)) {
             break;
         }
         if (!is_null($authenticatedUser)) {
             $bets = BetDB::findBet($game->getID(), $authenticatedUser->getHockName());
             if (!empty($bets)) {
                 continue;
             }
         }
         $worth = GameController::calcWorth($game->getTeamSkill1(), $game->getTeamSkill2());
         //team1
         $user1 = HockUserDB::getUserByID_NameAndHome($team1->getUID1());
         $user2 = HockUserDB::getUserByID_NameAndHome($team1->getUID2());
         $user3 = HockUserDB::getUserByID_NameAndHome($team1->getUID3());
         //team2
         $user4 = HockUserDB::getUserByID_NameAndHome($team2->getUID1());
         $user5 = HockUserDB::getUserByID_NameAndHome($team2->getUID2());
         $user6 = HockUserDB::getUserByID_NameAndHome($team2->getUID3());
         if (empty($user1) || empty($user2) || empty($user3) || empty($user4) || empty($user5) || empty($user6)) {
             break;
         }
         $user1 = $user1[0];
         $user2 = $user2[0];
         $user3 = $user3[0];
         $user4 = $user4[0];
         $user5 = $user5[0];
         $user6 = $user6[0];
         $start = new DateTime($game->getStart());
         $end = new DateTime(date("Y-m-d H:i:s"));
         $length = $end->diff($start);
         $timestr = "";
         if ($length->m != 0) {
             $timestr = $timestr . $length->m . "mo ";
         }
         if ($length->d != 0) {
             $timestr = $timestr . $length->d . "d ";
         }
         if ($length->h != 0) {
             $timestr = $timestr . $length->h . "h ";
         }
         $timestr = $timestr . $length->i . "m " . $length->s . "s";
         echo '<tr class="' . $game->getServer() . '">';
         echo '<td class="' . $game->getServer() . '">' . $game->getID() . '</td>';
         echo '<td class="' . $user1->getHome() . '"><a href="' . $base . '/user/show/' . $user1->getUserName() . '">' . $user1->getUserName() . '</td>';
         echo '<td class="' . $user2->getHome() . '"><a href="' . $base . '/user/show/' . $user2->getUserName() . '">' . $user2->getUserName() . '</td>';
         echo '<td class="' . $user3->getHome() . '"><a href="' . $base . '/user/show/' . $user3->getUserName() . '">' . $user3->getUserName() . '</td>';
         echo '<td>' . $game->getTeamSkill1() . '</td>';
         echo '<td class="edge">+' . $worth[0] . '/-' . $worth[1] . '</td>';
         echo '<td class="' . $user4->getHome() . '"><a href="' . $base . '/user/show/' . $user4->getUserName() . '">' . $user4->getUserName() . '</td>';
         echo '<td class="' . $user5->getHome() . '"><a href="' . $base . '/user/show/' . $user5->getUserName() . '">' . $user5->getUserName() . '</td>';
         echo '<td class="' . $user6->getHome() . '"><a href="' . $base . '/user/show/' . $user6->getUserName() . '">' . $user6->getUserName() . '</td>';
         echo '<td>' . $game->getTeamSkill2() . '</td>';
         echo '<td>+' . $worth[1] . '/-' . $worth[0] . '</td>';
         echo '<td>' . $timestr . '</td>';
         echo '</tr>';
     }
     echo '</tbody>';
     echo '</table>';
     echo '</div>';
     //end table
     //echo '</div>'; //end container
 }
Exemple #8
0
    public static function showGames()
    {
        $base = array_key_exists('base', $_SESSION) ? $_SESSION['base'] : "";
        //echo '<div class="container">';
        echo '<h1>Bet On These Active Games</h1>';
        //$games = (array_key_exists('activegames', $_SESSION))?$_SESSION['activegames']:array();
        $games = GameDB::getGamesBy('pending', 1);
        if (empty($games)) {
            //echo '</div>';
            return;
        }
        echo '<div class="table-responsive">';
        echo '<table class="table">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>GameID</th>';
        echo '<th>User1</th>';
        echo '<th>User2</th>';
        echo '<th>User3</th>';
        echo '<th>TeamSkill</th>';
        echo '<th>+/-</th>';
        echo '<th>User4</th>';
        echo '<th>User5</th>';
        echo '<th>User6</th>';
        echo '<th>TeamSkill</th>';
        echo '<th>+/-</th>';
        echo '<th>Length</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        //iterate through all games
        foreach ($games as $game) {
            //If the game is not finished or had a bad/cancel don't show here
            if ($game->getPending() != 1) {
                continue;
            }
            $teams = TeamDB::getTeamsBy('id', $game->getTeamID1());
            if (empty($teams)) {
                break;
            }
            $team1 = $teams[0];
            $teams = TeamDB::getTeamsBy('id', $game->getTeamID2());
            if (empty($teams)) {
                break;
            }
            $team2 = $teams[0];
            if (is_null($team1) || is_null($team2)) {
                break;
            }
            $worth = GameController::calcWorth($game->getTeamSkill1(), $game->getTeamSkill2());
            //team1
            $user1 = HockUserDB::getUsersBy('id', $team1->getUID1());
            $user2 = HockUserDB::getUsersBy('id', $team1->getUID2());
            $user3 = HockUserDB::getUsersBy('id', $team1->getUID3());
            //team2
            $user4 = HockUserDB::getUsersBy('id', $team2->getUID1());
            $user5 = HockUserDB::getUsersBy('id', $team2->getUID2());
            $user6 = HockUserDB::getUsersBy('id', $team2->getUID3());
            if (empty($user1) || empty($user2) || empty($user3) || empty($user4) || empty($user5) || empty($user6)) {
                break;
            }
            $user1 = $user1[0];
            $user2 = $user2[0];
            $user3 = $user3[0];
            $user4 = $user4[0];
            $user5 = $user5[0];
            $user6 = $user6[0];
            $start = new DateTime($game->getStart());
            $end = new DateTime(date("Y-m-d H:i:s"));
            $length = $start->diff($end);
            echo '<tr class="' . $game->getServer() . '">';
            echo '<td class="' . $game->getServer() . '">' . $game->getID() . '</td>';
            echo '<td class="' . $user1->getHome() . '"><a href="/' . $base . '/user/show/' . $user1->getUserName() . '">' . $user1->getUserName() . '</td>';
            echo '<td class="' . $user2->getHome() . '"><a href="/' . $base . '/user/show/' . $user2->getUserName() . '">' . $user2->getUserName() . '</td>';
            echo '<td class="' . $user3->getHome() . '"><a href="/' . $base . '/user/show/' . $user3->getUserName() . '">' . $user3->getUserName() . '</td>';
            echo '<td>' . $game->getTeamSkill1() . '</td>';
            echo '<td class="edge">+' . $worth[0] . '/-' . $worth[1] . '</td>';
            echo '<td class="' . $user4->getHome() . '"><a href="/' . $base . '/user/show/' . $user4->getUserName() . '">' . $user4->getUserName() . '</td>';
            echo '<td class="' . $user5->getHome() . '"><a href="/' . $base . '/user/show/' . $user5->getUserName() . '">' . $user5->getUserName() . '</td>';
            echo '<td class="' . $user6->getHome() . '"><a href="/' . $base . '/user/show/' . $user6->getUserName() . '">' . $user6->getUserName() . '</td>';
            echo '<td>' . $game->getTeamSkill2() . '</td>';
            echo '<td>+' . $worth[1] . '/-' . $worth[0] . '</td>';
            echo '<td>' . $length->i . 'm ' . $length->s . 's</td>';
            echo '</tr>';
        }
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
        //end table
        //echo '</div>'; //end container
        return;
        ?>
				<h3> Active games </h3>
				(29678)  Team1: Sergio ace lymp (4502) +10/-10    Team2: zoop bizarre staniol (4480)  +10/-10    0:02:56.805000
				<br>
				<h3>Place bet:</h3>
				<form action="bet" method="post">
				Game to bet on: <input type="text" name="game" tabindex="1" <?php 
        if (!is_null($bet)) {
            echo 'value = "' . $bet->getGame() . '"';
        }
        ?>
 required>
				<span class="error">
				   <?php 
        if (!is_null($bet)) {
            echo $bet->getError('game');
        }
        ?>
				</span>
				<br>
				Amount to bet: <input type="text" name="betAmount" tabindex="2" <?php 
        if (!is_null($bet)) {
            echo 'value = "' . $bet->getBetAmount() . '"';
        }
        ?>
 required>
				<span class="error">
				   <?php 
        if (!is_null($bet)) {
            echo $bet->getError('betAmount');
        }
        ?>
				</span>
				<br>
				<input type="submit" value="Submit" tabindex="3">
				</form>
			<?php 
    }
 public static function generateNewGame()
 {
     $users = HockUserDB::getAllUsersNotInGame();
     if (empty($users)) {
         return;
     }
     if (count($users) < 6) {
         echo "<p>Error getting enough users not in a game... " . $e->getMessage() . "</p>";
         return;
     }
     //get random users for game
     shuffle($users);
     $user1 = array_pop($users);
     $user2 = array_pop($users);
     $user3 = array_pop($users);
     $user4 = array_pop($users);
     $user5 = array_pop($users);
     $user6 = array_pop($users);
     $users1 = array($user1, $user2, $user3);
     $users2 = array($user4, $user5, $user6);
     if (empty($users1)) {
         echo '<p>Error getting users1</p>';
         return;
     }
     if (empty($users2)) {
         echo '<p>Error getting users2</p>';
         return;
     }
     //calculate each team's skill
     $skill1 = $user1->getSkill() + $user2->getSkill() + $user3->getSkill();
     $skill2 = $user4->getSkill() + $user5->getSkill() + $user6->getSkill();
     //create new game
     $game = new Game();
     $gameparms = $game->getParameters();
     $gameparms['teamskill1'] = $skill1;
     $gameparms['teamskill2'] = $skill2;
     $gameparms['pending'] = 1;
     $gameparms['start'] = date("Y-m-d H:i:s");
     $gameparms['type'] = 'random';
     $gameparms['server'] = 1;
     $game = new Game($gameparms);
     $gameid = GameDB::addGame($game);
     $game->setGameId($gameid);
     //create team1
     $team1 = new Team();
     $parms = $team1->getParameters();
     $parms['uid1'] = $user1->getUserId();
     $parms['uid2'] = $user2->getUserId();
     $parms['uid3'] = $user3->getUserId();
     $parms['gameId'] = $game->getID();
     $team1 = new Team($parms);
     $teamid1 = TeamDB::addTeam($team1);
     $team1->setteamId($teamid1);
     //create team2
     $team2 = new Team();
     $parms = $team2->getParameters();
     $parms['uid1'] = $user4->getUserId();
     $parms['uid2'] = $user5->getUserId();
     $parms['uid3'] = $user6->getUserId();
     $parms['gameId'] = $game->getID();
     $team2 = new Team($parms);
     $teamid2 = TeamDB::addTeam($team2);
     $team2->setteamId($teamid2);
     //update game with teamid's
     $game->setTeamId1($team1->getteamId());
     $game->setTeamId2($team2->getteamId());
     $gameupdate = GameDB::updateGame($game);
     //update users to show they are in game
     foreach ($users1 as $user) {
         $user->setGameId($game->getID());
         $user->setTeamId($team1->getteamId());
         HockUserDB::updateUser($user);
     }
     foreach ($users2 as $user) {
         $user->setGameId($game->getID());
         $user->setTeamId($team1->getteamId());
         HockUserDB::updateUser($user);
     }
     //Game and teams created and users update...  Done!
 }