function ArcadeViewMatch() { global $scripturl, $txt, $db_prefix, $context, $smcFunc, $user_info; if (empty($_REQUEST['match'])) { fatal_lang_error('match_not_found', false); } loadMatch((int) $_REQUEST['match']); // Delete Match if (isset($_REQUEST['delete']) && $context['can_edit_match']) { checkSession('get'); deleteMatch($context['match']['id']); redirectexit('action=arcade;sa=arena'); } elseif (isset($_GET['start']) && $context['can_start_match']) { checkSession('get'); $smcFunc['db_query']('', ' UPDATE {db_prefix}arcade_matches SET num_players = current_players WHERE id_match = {int:match}', array('match' => $context['match']['id'])); matchUpdateStatus($context['match']['id']); redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']); } elseif (isset($_REQUEST['leave']) && ($context['can_leave'] || $context['can_decline'])) { checkSession('get'); // It's starter leaving, delete whole match if ($user_info['id'] == $context['match']['starter']) { deleteMatch($context['match']['id']); redirectexit('action=arcade;sa=arena'); } else { matchRemovePlayers($context['match']['id'], array($user_info['id'])); } redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']); } elseif (isset($_REQUEST['kick']) && !empty($context['match']['players'][$_REQUEST['player']]['can_kick'])) { checkSession('get'); matchRemovePlayers($context['match']['id'], array($_REQUEST['player'])); redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']); } elseif (isset($_REQUEST['join']) && $context['can_join_match']) { checkSession('get'); matchAddPlayers($context['match']['id'], array($user_info['id'] => 1)); redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']); } elseif (isset($_REQUEST['join']) && $context['can_accept']) { checkSession('get'); matchUpdatePlayers($context['match']['id'], array($user_info['id']), 1); redirectexit('action=arcade;sa=viewMatch;match=' . $context['match']['id']); } // Layout loadTemplate('ArcadeArena'); $context['template_layers'][] = 'arcade_arena_view_match'; $context['sub_template'] = 'arcade_arena_view_match'; $context['page_title'] = sprintf($txt['arcade_arena_view_match_title'], $context['match']['name']); // Add Arena to link tree $context['linktree'][] = array('url' => $scripturl . '?action=arcade;sa=arena', 'name' => $txt['arcade_arena']); $context['linktree'][] = array('url' => $scripturl . '?action=arcade;sa=viewMatch;match=' . $context['match']['id'], 'name' => $context['match']['name']); }
function createMatch($matchOptions) { global $smcFunc, $db_prefix, $sourcedir, $scripturl, $user_info, $txt; if (empty($matchOptions['created'])) { $matchOptions['created'] = time(); } if (!isset($matchOptions['private_game'])) { $matchOptions['private_game'] = 0; } if (!isset($matchOptions['starter'])) { $matchOptions['starter'] = $user_info['id']; } if (!empty($matchOptions['extra'])) { $matchOptions['extra'] = serialize($matchOptions['extra']); } else { $matchOptions['extra'] = ''; } $smcFunc['db_insert']('insert', '{db_prefix}arcade_matches', array('name' => 'string', 'id_member' => 'int', 'private_game' => 'int', 'status' => 'int', 'created' => 'int', 'updated' => 'int', 'num_players' => 'int', 'current_players' => 'int', 'num_rounds' => 'int', 'current_round' => 'int', 'match_data' => 'string'), array($matchOptions['name'], $matchOptions['starter'], !empty($matchOptions['private_game']) ? 1 : 0, 0, $matchOptions['created'], 0, $matchOptions['num_players'], 0, $matchOptions['num_rounds'], 0, $matchOptions['extra']), array()); $id_match = $smcFunc['db_insert_id']('{db_prefix}arcade_matches', 'id_match'); $rows = array(); for ($i = 0; $i < $matchOptions['num_rounds']; $i++) { $rows[] = array($id_match, $i + 1, isset($matchOptions['games'][$i]) ? $matchOptions['games'][$i] : 0, 0); } $smcFunc['db_insert']('insert', '{db_prefix}arcade_matches_rounds', array('id_match' => 'int', 'round' => 'int', 'id_game' => 'int', 'status' => 'int'), $rows, array()); unset($rows); if (!empty($matchOptions['players'])) { require_once $sourcedir . '/Subs-Post.php'; $players = array(); foreach ($matchOptions['players'] as $id) { $players[$id] = $id == $matchOptions['starter'] ? 1 : 0; } matchAddPlayers($id_match, $players); } return $id_match; }