public function getView($params, $synchrone) { $form = new Form($this->fields, $params); $title = ''; if ($form->isSubmitting() && Tools::isEmpty($form->getErrors())) { $access_key = isset($params['access_key']) && !empty($params['access_key']) ? Tools::saltHash($params['access_key']) : 'NULL'; // Create Game $game = Game::create(F::i('Session')->getMid(), $params['name'], $access_key); Tools::redirect('?action=wait_game&game=' . $game->g_id); } else { // Generate form $view = View::setFile('formular', View::HTML_FILE); $errors = $form->getErrors(); // Errors in the filling if (!empty($errors)) { $view->setSwitch('form_errors', TRUE); foreach ($errors as $field => $error) { $view->setGroupValues('form_errors', array('error' => F::i('Lang')->getKey('error_' . $field . '_' . $error))); } } $view->setValue('form', $form->getHTML(F::i('Lang')->getKey('Create'), '#', 'POST', 'tabbed_form')); $title = F::i('Lang')->getKey('title_new_game'); } return parent::setBody($view, $title); }
public function doAddGame($data, Form $form) { $game = Game::create(); $game->ScoreTeamOne = $data['ScoreTeamOne']; $game->ScoreTeamTwo = $data['ScoreTeamTwo']; $game->write(); $redirectLink = $this->Link() . '?success=1'; return $this->redirect($redirectLink); }
/** * Store a newly created game in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Game::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } Game::create($data); return Redirect::route('games.index'); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('games', function (Blueprint $table) { $table->increments('id'); $table->integer('winner_id')->unsigned()->index(); $table->foreign('winner_id')->references('id')->on('users')->onDelete('cascade'); $table->integer('status'); $table->integer('items'); $table->float('price'); $table->timestamp('started_at'); $table->timestamp('finished_at'); $table->json('won_items'); $table->integer('status_prize'); $table->string('rand_number'); $table->timestamps(); }); $rand_number = "0." . mt_rand(100000000, 999999999) . mt_rand(100000000, 999999999); Game::create(['rand_number' => $rand_number]); }
/** * Attempts to save a game * * @return Game|null */ protected function addGame($form) { $siteConfig = SiteConfig::current_site_config(); $member = Member::currentUser(); $params = $this->request->allParams(); $fields = $form->Fields(); $id = $fields->dataFieldByName('ID')->Value(); $game = Game::get()->byID($id); if (!$game) { $game = Game::create(); } $form->saveInto($game); $game->FacilitatorID = $game->FacilitatorID ? $game->FacilitatorID : $member->ID; $game->ParentID = $siteConfig->CurrentEventID; try { $game->write(); } catch (ValidationException $e) { $form->sessionMessage($e->getResult()->message(), 'bad'); return; } return $game; }
public function run() { $faker = Faker::create(); $characters = Character::all()->toArray(); $isk = PrizeType::where('name', '=', 'isk')->firstOrFail(); // Completed foreach (range(1, 20) as $index) { $initiator = $faker->randomElement($characters); $winner = $faker->randomElement($characters); $seats = $faker->numberBetween(4, 12); $game = Game::create(['prize_type_id' => $isk->id, 'initiator_id' => $initiator['id'], 'winner_id' => $winner['id'], 'seats' => $seats, 'buy_in' => $faker->randomFloat(2, 10000, 50000000), 'deleted_at' => new DateTime()]); $fulfilled = $index < 15 ? true : false; $this->createPayout($game, $fulfilled); $this->putPlayersInSeats($game, $seats, $initiator, $winner); } // In Progress foreach (range(1, 5) as $index) { $initiator = $faker->randomElement($characters); $seats = $faker->numberBetween(4, 12); $numberOfPlayers = $faker->numberBetween(0, $seats); $game = Game::create(['prize_type_id' => $isk->id, 'initiator_id' => $initiator['id'], 'seats' => $seats, 'buy_in' => $faker->numberBetween(10000, 100000000) . 00]); $this->putPlayersInSeats($game, $numberOfPlayers, $initiator); } }
require_once MB_ROOT . '/source/Game.class.php'; if (false) { $debug = array(); $debug['tid'] = '1'; $debug['result'] = 'success'; $debug['from'] = 'return'; $debug['type'] = 'wechat'; $this->payResult($debug); exit; } $user = $this->auth(); $id = $_GPC['actid']; $id = intval($id); $a = new Activity(); $activity = $a->getOne($id); if (empty($activity) || $activity['type'] != 'game') { exit('访问错误'); } $g = new Game(); $order = array(); $order['activity'] = $activity['actid']; $order['uid'] = $user['uid']; $tid = $g->create($order); if (is_error($tid)) { exit('访问错误'); } $trade = array(); $trade['tid'] = $tid; $trade['title'] = "购买{$activity['tag']['label']} x1"; $trade['fee'] = $activity['tag']['price']; $this->pay($trade);
public function create_object($data) { if (empty($data['victor'])) { $data['victor'] = 0; } else { $data['victor'] = Agent::mapper()->create_object(array('id' => $data['victor'], 'alias' => $data['victor_agent_alias'])); unset($data['victor_alias']); } $game = Game::create($data, True); $game->attach_mapper('Kill', Kill::mapper()->attach_storage(\Core\Storage::container()->get_storage('Kill'))); $game->attach_mapper('Agent', Agent::mapper()->attach_storage(\Core\Storage::container()->get_storage('Agent'))); foreach (array('start_date', 'end_date') as $f) { $game[$f] = new \DateTime($game[$f]); } $game->invite_only = (int) $data['invite_only']; $now = new \DateTime(); if ($game->start_date > $now) { $game['joinable'] = True; $game['active'] = False; $game['state'] = 0; } else { if ($game->start_date < $now && $now < $game->end_date) { $game['joinable'] = False; $game['active'] = True; $game['state'] = 1; } else { $game['joinable'] = False; $game['active'] = False; $game['state'] = 2; } } return $game; }
public function run() { DB::table('game')->delete(); //8e Game::create(array('team1_id' => 1, 'team2_id' => 6, 'stage_id' => 4, 'team1_tmp_name' => '1A', 'team2_tmp_name' => '2B', 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1403971200))); Game::create(array('team1_id' => 9, 'team2_id' => 15, 'stage_id' => 4, 'team1_tmp_name' => '1C', 'team2_tmp_name' => '2D', 'stage_game_num' => 2, 'date' => DateTime::createFromFormat('U', 1403985600))); Game::create(array('team1_id' => 17, 'team2_id' => 22, 'stage_id' => 4, 'team1_tmp_name' => '1B', 'team2_tmp_name' => '2A', 'stage_game_num' => 3, 'date' => DateTime::createFromFormat('U', 1404144000))); Game::create(array('team1_id' => 25, 'team2_id' => 32, 'stage_id' => 4, 'team1_tmp_name' => '1D', 'team2_tmp_name' => '2C', 'stage_game_num' => 4, 'date' => DateTime::createFromFormat('U', 1404158400))); Game::create(array('team1_id' => 5, 'team2_id' => 2, 'stage_id' => 4, 'team1_tmp_name' => '1E', 'team2_tmp_name' => '2F', 'stage_game_num' => 5, 'date' => DateTime::createFromFormat('U', 1404057600))); Game::create(array('team1_id' => 13, 'team2_id' => 12, 'stage_id' => 4, 'team1_tmp_name' => '1G', 'team2_tmp_name' => '2H', 'stage_game_num' => 6, 'date' => DateTime::createFromFormat('U', 1404072000))); Game::create(array('team1_id' => 21, 'team2_id' => 19, 'stage_id' => 4, 'team1_tmp_name' => '1F', 'team2_tmp_name' => '2E', 'stage_game_num' => 7, 'date' => DateTime::createFromFormat('U', 1404230400))); Game::create(array('team1_id' => 29, 'team2_id' => 26, 'stage_id' => 4, 'team1_tmp_name' => '1H', 'team2_tmp_name' => '2G', 'stage_game_num' => 8, 'date' => DateTime::createFromFormat('U', 1404244800))); //Quarts Game::create(array('stage_id' => 3, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1404504000))); Game::create(array('stage_id' => 3, 'stage_game_num' => 2, 'date' => DateTime::createFromFormat('U', 1404489600))); Game::create(array('stage_id' => 3, 'stage_game_num' => 3, 'date' => DateTime::createFromFormat('U', 1404576000))); Game::create(array('stage_id' => 3, 'stage_game_num' => 4, 'date' => DateTime::createFromFormat('U', 1404576000))); //Demi Game::create(array('stage_id' => 2, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1404849600))); Game::create(array('stage_id' => 2, 'stage_game_num' => 2, 'date' => DateTime::createFromFormat('U', 1404936000))); //Finale Game::create(array('stage_id' => 1, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1405278000))); //Petite Finale Game::create(array('stage_id' => 5, 'stage_game_num' => 1, 'date' => DateTime::createFromFormat('U', 1405195200))); }
public function v14() { // Regenerate cache Cache::clear(false); /* * API */ // Copy bridge secret key to API private key $bridge = json_decode($this->Setting->getOption('bridge')); if (!empty($bridge) && $bridge->enabled && !empty($bridge->secret)) { $api = array(); $api['enabled'] = 0; $api['privateKey'] = $bridge->secret; $this->Setting->setOption('api', json_encode($api)); // Disable bridge to make use users update their bridge plugin $bridgeSettings = array(); $bridgeSettings['enabled'] = 0; $bridgeSettings['url'] = $bridge->url; $this->Setting->setOption('bridge', json_encode($bridgeSettings)); $this->Session->setFlash(__('Bridge has been disabled ! Be sure to use an updated version of your bridge plugin for MushRaider 1.4. If you don\'t you\'re gonna have a bad time !'), 'flash_important', array(), 'important'); } /* * Import */ // Add absolute path to games's logo field to prepare import functionallity App::uses('Game', 'Model'); $GameModel = new Game(); $params = array(); $params['recursive'] = -1; $params['fields'] = array('id', 'logo'); if ($games = $GameModel->find('all', $params)) { foreach ($games as $game) { if (!empty($game['Game']['logo']) && strpos($game['Game']['logo'], '/files/') === false) { $toUpdate = array(); $toUpdate['id'] = $game['Game']['id']; $toUpdate['logo'] = '/files/logos/' . $game['Game']['logo']; $GameModel->create(); $GameModel->save($toUpdate); } } } /* * Roles permissions */ // Add roles permissions $rolesPermissions = array(array('title' => __('Full permissions'), 'alias' => 'full_permissions', 'description' => __('Like Chuck Norris, he can do anything. This overwrite every permissions')), array('title' => __('Limited admin access'), 'alias' => 'limited_admin', 'description' => __('Like Robin, he can do some things but not all (like driving the batmobile or change user role)')), array('title' => __('Can manage events'), 'alias' => 'manage_events', 'description' => __('Can create, edit and delete events. Can also manage the roster for each events')), array('title' => __('Can create templates'), 'alias' => 'create_templates', 'description' => __('Can create events templates')), array('title' => __('Can create reports'), 'alias' => 'create_reports', 'description' => __('Can create events reports'))); App::uses('RolePermission', 'Model'); $RolePermissionModel = new RolePermission(); foreach ($rolesPermissions as $rolesPermission) { $RolePermissionModel->create(); $RolePermissionModel->save($rolesPermission); } // Add new roles permissions to existing roles App::uses('Role', 'Model'); $RoleModel = new Role(); App::uses('RolePermissionRole', 'Model'); $RolePermissionRoleModel = new RolePermissionRole(); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('admin'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('full_permissions'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('limited_admin'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('manage_events'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_templates'))); $RolePermissionRoleModel->__add(array('role_id' => $RoleModel->getIdByAlias('officer'), 'role_permission_id' => $RolePermissionModel->getIdByAlias('create_reports'))); }
<?php require_once '../game.php'; $strategy = $_GET['strategy']; $ships = $_GET['ships']; try { $game = new Game(); $game->create($strategy, $ships); echo json_encode(["response" => true, "pid" => $game->getPlayerID()]); } catch (GameException $e) { echo json_encode(["response" => false, "reason" => $e->getMessage()]); }
require_once 'includes/inc.global.php'; // this has nothing to do with creating a game // but I'm running it here to prevent long load // times on other pages where it would be ran more often GamePlayer::delete_inactive(Settings::read('expire_users')); Game::delete_inactive(Settings::read('expire_games')); Game::delete_finished(Settings::read('expire_finished_games')); $Game = new Game(); if (isset($_POST['create'])) { // make sure this user is not full if ($GLOBALS['Player']->max_games && $GLOBALS['Player']->max_games <= $GLOBALS['Player']->current_games) { Flash::store('You have reached your maximum allowed games !'); } test_token(); try { $game_id = $Game->create(); Flash::store('Game Created Successfully'); } catch (MyException $e) { Flash::store('Game Creation FAILED !', false); } } $color_selection = ''; foreach ($Game->get_avail_colors() as $color) { $color_selection .= '<option class="' . strtolower(substr($color, 0, 3)) . '">' . ucfirst($color) . '</option>'; } $meta['title'] = 'Create Game'; $meta['head_data'] = ' <script type="text/javascript" src="scripts/create.js"></script> '; $hints = array('Create a game by filling out your desired game options.', '<span class="highlight">WARNING!</span><br />Games will be deleted after ' . Settings::read('expire_games') . ' days of inactivity.'); // make sure this user is not full
} if (isset($_REQUEST['team1'])) { $team1 = $_REQUEST['team1']; } else { header("HTTP/1.0 400 Bad Request"); print "Missing team1"; exit; } if (isset($_REQUEST['team2'])) { $team2 = $_REQUEST['team2']; } else { header("HTTP/1.0 400 Bad Request"); print "Missing team2"; exit; } $new_game = Game::create($date, $team1, $team2); if ($new_game == null) { header("HTTP/1.0 500 Server Error"); print "Cannot create a new game"; exit; } header("Content-type: application/json"); print $new_game->getJSON(); exit; } else { if ($path_components[1] != "") { $gid = $path_components[1]; $type = null; $first = null; $last = null; $team = null;
public function run($args) { $this->server = new Websocket(); $this->games = array(); $that = $this; // for use in the closures $this->server->bind('open', function ($client_id) use($that) { $ip = long2ip($that->server->wsClients[$client_id][6]); $that->output('+ ' . $ip . ' (' . $client_id . ') connected', 'green'); }); $this->server->bind('message', function ($client_id, $msg, $msg_length, $binary) use($that) { $ip = long2ip($that->server->wsClients[$client_id][6]); if ($msg_length == 0) { $that->server->wsClose($client_id); return; } $action = json_decode($msg); switch ($action->event) { case 'login': $username = str_replace(" ", "", trim($action->data->player_name)); $bad_usernames = array('system', 'admin', 'root'); if (in_array($username, $bad_usernames)) { $that->send_to_one($client_id, 'login_error', array('msg' => 'That is an invalid username')); } elseif (substr($username, 0, 1) == '@') { $that->send_to_one($client_id, 'login_error', array('msg' => 'Twitter users are not yet implemented')); } elseif (strlen($username) < 2 || strlen($username) > 15) { $that->send_to_one($client_id, 'login_error', array('msg' => 'Username must be 2-15 characters in length')); } else { // Check if username is taken // and build players array to send as user_list on the front end $taken = false; $players = array(); foreach ($that->server->wsClients as $id => $client) { $name = $client[12]->name; if ($name == $username) { $taken = true; break; } if ($name != NULL) { $players[] = array('name' => $name); } } if ($taken) { $that->send_to_one($client_id, 'login_error', array('msg' => 'That username is already in use')); } else { $players[] = array('name' => $username, 'client_id' => $client_id); $that->server->wsClients[$client_id][12]->name = $username; $that->output('+ ' . $ip . ' (' . $client_id . ') identified as ' . $username, 'green'); $that->send_to_one($client_id, 'login_success', array('msg' => true)); if (count($that->games) > 0) { $games_send = array(); foreach ($that->games as $key => $game) { if ($game->state == 'WAITING') { $games_send[] = array('id' => $game->id, 'started_by' => $game->started_by); } } $that->send_to_one($client_id, 'games_list', $games_send); } // tell all players that this person is here $that->send_to_all('lobby_chat', array('from' => 'system', 'msg' => $username . ' joined')); $that->send_to_all('user_list', $players); } } break; case 'lobby_chat': // TODO: add admin commands here...general commands too (uptime, etc) $that->send_to_all('lobby_chat', array('from' => $that->server->wsClients[$client_id][12]->name, 'msg' => HTML::entities($action->data->msg))); break; case 'create_game': if (!$that->server->wsClients[$client_id][12]->started_game) { $g = new Game(); $g->create($that->server->wsClients[$client_id][12]->name); $g->add_player($that->server->wsClients[$client_id][12], 0); $that->games[$g->id] = $g; $that->send_game_list(); $that->output('+ Game ' . $g->id . ' created!', 'green'); $that->send_to_all('lobby_chat', array('from' => 'system', 'msg' => $g->started_by . ' started a new game!')); } else { $that->send_to_one('lobby_chat', array('from' => 'system', 'msg' => 'You already have an open game!')); } break; case 'join_game': $game_id = $action->data->game; $g = $that->games[$game_id]; $player_1 = $g->get_player_by_seat(0); if ($player_1->name == $that->server->wsClients[$client_id][12]->name) { $that->send_to_one($client_id, 'lobby_chat', array('from' => 'system', 'msg' => 'You are not allowed to join your own game')); } else { $g->add_player($that->server->wsClients[$client_id][12], 1); $that->send_to_game($g, 'open_table', array('table_id' => $g->id, 'table_name' => $g->started_by . "'s Tournament")); $g->game_log = array(); $g->start(); $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => $g->game_log)); $g->game_log = array(); $that->render_game($g, true); $that->games[$game_id] = $g; $that->send_game_list(); $that->output('+ Game ' . $g->id . ' started!', 'white', true, 'green'); } break; case 'game_chat': $game_id = $action->data->game_id; $g = $that->games[$game_id]; // TODO: add admin commands here...general commands too (uptime, etc) if ($g->started_by == $that->server->wsClients[$client_id][12]->name) { // allow admin commands from the game owner if (substr($action->data->msg, 0, 6) == '/admin') { // do admin stuff $task = explode(' ', $action->data->msg); $task = $task[1]; switch ($task) { case 'pause': $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => array('The tournament owner has paused this tournament'))); $that->output('+ Game ' . $g->id . ' paused', 'white', true, 'yellow'); $that->render_game($g, false, 0); $g->paused_at = time(); $g->status = 'PAUSED'; break; case 'resume': $new_level_up = $g->blind_level_up + (time() - $g->paused_at); $g->blind_level_up = $new_level_up; $g->status = 'RUNNING'; $that->render_game($g, false, true); $that->output('+ Game ' . $g->id . ' resumed', 'white', true, 'green'); $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => array('The tournament owner has resumed this tournament!'))); break; } break; } } $that->send_to_game($g, 'game_chat', array('game_id' => $action->data->game_id, 'from' => $that->server->wsClients[$client_id][12]->name, 'msg' => HTML::entities($action->data->msg))); break; case 'fold': case 'check': case 'call': case 'raise': $game_id = $action->data->game_id; $g = $that->games[$game_id]; if ($g->get_player_seat_by_client_id($client_id) == $g->current_turn && $g->state == 'RUNNING') { switch ($action->event) { case 'fold': $g->fold($g->get_player_by_client_id($client_id)); $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => array($g->get_player_by_client_id($client_id)->name . ' folds'))); break; case 'check': $g->check($g->get_player_by_client_id($client_id)); $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => array($g->get_player_by_client_id($client_id)->name . ' checks'))); break; case 'call': $call_amt = $g->get_top_bet() - $g->get_player_by_client_id($client_id)->games[$g->id]['cur_stake']; $g->call($g->get_player_by_client_id($client_id)); $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => array($g->get_player_by_client_id($client_id)->name . ' calls $' . $call_amt))); break; case 'raise': $replace = array('Bet $', 'Raise $'); $raise_amt = str_replace($replace, '', $action->data->raise_amt); $all_in = ''; if ($raise_amt == 'ALLIN') { $all_in = ' and is ALL IN!'; $raise_amt = $g->get_player_by_client_id($client_id)->games[$g->id]['balance']; } $g->raise($g->get_player_by_client_id($client_id), $raise_amt); $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => array($g->get_player_by_client_id($client_id)->name . ' raises $' . $raise_amt . $all_in))); break; } $g->start_new_hand = false; if ($g->check_for_all_in_call()) { // TODO: slow roll flop, turn, river as necessary with cards exposed if ($g->community_cards->count() < 3) { $g->deal_community_cards(3); $g->game_log[] = '<b>- Dealing Flop: </b> ' . $g->render_flop(); } if ($g->community_cards->count() < 4) { $g->deal_community_cards(1); $g->game_log[] = '<b>- Dealing Turn: </b> ' . $g->render_turn(); } if ($g->community_cards->count() < 5) { $g->deal_community_cards(1); $g->game_log[] = '<b>- Dealing River: </b> ' . $g->render_river(); } // reveal all cards $i = 0; foreach ($g->players as $player) { $alt_seat = $i == 0 ? 1 : 0; $render = array('game_id' => $g->id, 'game-' . $g->id . '-player_cards' => Render::player_cards($g, '', $player), 'game-' . $g->id . '-player_text' => Render::player_text($g, '', $player), 'game-' . $g->id . '-opponent_cards' => Render::player_cards($g, '', $g->players[$alt_seat]), 'game-' . $g->id . '-opponent_text' => Render::player_text($g, '', $g->players[$alt_seat]), 'game-' . $g->id . '-community_cards' => Render::community_cards($g), 'game-' . $g->id . '-pot' => '<b>Pot: $' . $g->get_pot_value() . '</b>'); $that->send_to_one($player->client_id, 'game_render', $render); $that->send_to_one($player->client_id, 'game_showdown', array('game_id' => $g->id, 'showdown' => true)); $i++; } $g->finish_hand(); if (!$g->game_over) { $g->start_new_hand = true; $g->new_hand(); } else { $that->send_to_game($g, 'end_of_game', array('game_id' => $g->id, 'end_of_game' => true)); $g->game_log[] = '<b>** TOURNAMENT COMPLETE **</b>'; } } elseif ($g->betting_round > 1 && $g->community_cards->count() < 3) { $g->current_turn = $g->dealer == 0 ? 1 : 0; $g->deal_community_cards(3); $g->game_log[] = '<b>- Dealing Flop: </b>' . $g->render_flop(); } elseif ($g->betting_round > 2 && $g->community_cards->count() < 4) { $g->current_turn = $g->dealer == 0 ? 1 : 0; $g->deal_community_cards(1); $g->game_log[] = '<b>- Dealing Turn: </b>' . $g->render_turn(); } elseif ($g->betting_round > 3 && $g->community_cards->count() < 5) { $g->current_turn = $g->dealer == 0 ? 1 : 0; $g->deal_community_cards(1); $g->game_log[] = '<b>- Dealing River: </b>' . $g->render_river(); } elseif ($g->is_hand_over()) { $g->start_new_hand = true; // reveal all cards...IF players in hand > 1 if ($g->count_players_in_hand() > 1) { $i = 0; foreach ($g->players as $player) { $alt_seat = $i == 0 ? 1 : 0; $render = array('game_id' => $g->id, 'game-' . $g->id . '-player_cards' => Render::player_cards($g, '', $player), 'game-' . $g->id . '-player_text' => Render::player_text($g, '', $player), 'game-' . $g->id . '-opponent_cards' => Render::player_cards($g, '', $g->players[$alt_seat]), 'game-' . $g->id . '-opponent_text' => Render::player_text($g, '', $g->players[$alt_seat]), 'game-' . $g->id . '-community_cards' => Render::community_cards($g), 'game-' . $g->id . '-pot' => '<b>Pot: $' . $g->get_pot_value() . '</b>'); $that->send_to_one($player->client_id, 'game_render', $render); $that->send_to_one($player->client_id, 'game_showdown', array('game_id' => $g->id, 'showdown' => true)); $i++; } } $g->finish_hand(); if (!$g->game_over) { $g->new_hand(); } else { $that->send_to_game($g, 'end_of_game', array('game_id' => $g->id, 'end_of_game' => true)); $g->game_log[] = '<b>** TOURNAMENT COMPLETE **</b>'; } } // send game log and render (?) $that->send_to_game($g, 'game_log', array('game_id' => $g->id, 'msgs' => $g->game_log)); if (!$g->game_over) { $i = 0; foreach ($g->players as $player) { $alt_seat = $i == 0 ? 1 : 0; if ($g->start_new_hand) { $that->send_to_one($player->client_id, 'game_log', array('game_id' => $g->id, 'msgs' => array('<b>You were dealt:</b> ' . Render::player_cards($g, $i, $player)))); } $render = array('game_id' => $g->id, 'game-' . $g->id . '-player_cards' => Render::player_cards($g, '', $player), 'game-' . $g->id . '-player_text' => Render::player_text($g, '', $player), 'game-' . $g->id . '-opponent_cards' => Render::player_cards($g, $alt_seat), 'game-' . $g->id . '-opponent_text' => Render::player_text($g, '', $g->players[$alt_seat]), 'game-' . $g->id . '-community_cards' => Render::community_cards($g), 'game-' . $g->id . '-pot' => '<b>Pot: $' . $g->get_pot_value() . '</b>'); if ($g->current_turn == $i) { $render['game-' . $g->id . '-game_controls'] = Render::game_actions($g, $player); } $that->send_to_one($player->client_id, 'game_render', $render); $i++; } } $g->start_new_hand = false; $g->game_log = array(); } else { // TODO: throw error to user that it is either not their turn yet or the game isn't in status RUNNING } break; } }); $this->server->bind('close', function ($client_id, $status) use($that) { $ip = long2ip($that->server->wsClients[$client_id][6]); $that->output('- ' . $ip . ' (' . $client_id . ') disconnected', 'red'); if ($that->server->wsClients[$client_id][12]->name) { $that->send_to_all('lobby_chat', array('from' => 'system', 'msg' => $that->server->wsClients[$client_id][12]->name . ' left')); } }); // START 'ER UP! $this->output('**************************************', 'light_purple', false); $this->output('* Laravel Websocket Poker *', 'light_purple', false); $this->output('* Version: Pre-ALPHA *', 'light_purple', false); $this->output('**************************************', 'light_purple', false); $this->output('** Server started', 'white', true, 'green'); $this->server->wsStartServer(Config::get('application.lwp_server_ip'), Config::get('application.lwp_server_port')); }
if ($result != null) { header("Content-type: application/json"); print $result->getJSON(); exit; } else { header("HTTP/1.0 400 Bad Request"); print "Username is already taken"; exit; } } if ($path_components[1] == "game") { $name = $path_components[2]; $aiName = $path_components[3]; $playerScore = $path_components[4]; $aiScore = $path_components[5]; $playerId = Player::findByUserName($name)->getID(); $aiId = Ai::findByName($aiName)->getID(); $result = Game::create($playerId, $aiId, $playerScore, $aiScore); if ($result != null) { header("Content-type: application/json"); print $result->getJSON(); exit; } else { header("HTTP/1.0 404 Bad Request"); print "Something went wrong"; exit; } } } } }