case 'validate': // // Check if topic and forum still excist // if ( !empty($HTTP_POST_VARS['validate_single_user']) ) { $game_id = $HTTP_POST_VARS['validate_single_user']; } else if ( !empty($HTTP_POST_VARS['validate_game']) ) { $game_id = $HTTP_POST_VARS['validate_game']; } else { die('Hacking attempt'); } $sql = "SELECT topic_id FROM " . GAMES_TABLE . " WHERE game_id = " . $game_id; if ( $result = $db->sql_query($sql) ) { $game_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); $topic_id = $game_info['topic_id']; } else { message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']); } // Check if the topic still excists and if forum is not locked, // so we would know if it is still possible to post a reply $post_reply = TRUE; $sql = "SELECT topic_id, forum_id FROM " . TOPICS_TABLE . " WHERE topic_id = " . $topic_id; if ( $result = $db->sql_query($sql) ) { $topic_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); $sql = "SELECT * FROM " . FORUMS_TABLE . " WHERE forum_id = " . $topic_info['forum_id']; if ( $result = $db->sql_query($sql) ) { $forum_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ( $forum_info['forum_status'] == FORUM_LOCKED ) { $post_reply = 0; } } else { $post_reply = 0; } } else { $post_reply = 0; } // -------------------- // What shall we do? // if ( $valsubm ) { $message = ( !empty($HTTP_POST_VARS['message']) ) ? mysql_real_escape_string($HTTP_POST_VARS['message']) : ''; $winner_id = ( !empty($HTTP_POST_VARS['winner_id']) ) ? $HTTP_POST_VARS['winner_id'] : ''; $sql=''; // When a player is validating if ( !empty($HTTP_POST_VARS['validate_single_user']) && empty($HTTP_POST_VARS['validate_game']) ) { $game_id = $HTTP_POST_VARS['validate_single_user']; $sql = "SELECT player_id, player_b_id, winner_id, winner_b_id FROM " . GAMES_TABLE . " WHERE game_id = " . $game_id; if ( $result = $db->sql_query($sql) ) { $game_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); } else { message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']); } $sql = ''; if ( empty($game_info['winner_id']) && empty($game_info['winner_b_id']) ) { if ( $userdata['user_id'] == $game_info['player_id'] ) { $sql = "UPDATE " . GAMES_TABLE . " SET winner_id = " . $winner_id . ", comment = '" . $message . "' WHERE game_id = " . $game_id; } else if ( $userdata['user_id'] == $game_info['player_b_id'] ) { $sql = "UPDATE " . GAMES_TABLE . " SET winner_b_id = " . $winner_id . ", comment_b = '" . $message . "' WHERE game_id = " . $game_id; } } else if ( empty($game_info['winner_id']) && !empty($game_info['winner_b_id']) ) { if ( $userdata['user_id'] == $game_info['player_id'] ) { $sql = "UPDATE " . GAMES_TABLE . " SET winner_id = " . $winner_id . ", comment = '" . $message . "' WHERE game_id = " . $game_id; } } else if ( !empty($game_info['winner_id']) && empty($game_info['winner_b_id']) ) { if ( $userdata['user_id'] == $game_info['player_b_id'] ) { $sql = "UPDATE " . GAMES_TABLE . " SET winner_b_id = " . $winner_id . ", comment_b = '" . $message . "' WHERE game_id = " . $game_id; } } else { message_die(GENERAL_MESSAGE, $lang['Games_Validated_Yet']); } } // When moderator is validating else if ( !empty($HTTP_POST_VARS['validate_game']) && empty($HTTP_POST_VARS['validate_single_user']) ) { $game_id = $HTTP_POST_VARS['validate_game']; if ( !$is_mod ) { die('Hacking attempt'); } $sql = "UPDATE " . GAMES_TABLE . " SET winner_id = " . $winner_id . ", winner_b_id = " . $winner_id . ", comment = '" . $message . "', comment_b = '" . $message . "' WHERE game_id = " . $game_id; } if ( empty($sql) ) { die('Hacking attempt'); } if (!$db->sql_query($sql, BEGIN_TRANSACTION)) { message_die(GENERAL_ERROR, 'Error in games table update', '', __LINE__, __FILE__, $sql); } // If both winners are validated, end the game (= make reply in topic and change some database stuff) $sql = "SELECT * FROM " . GAMES_TABLE . " WHERE game_id = " . $game_id; if ( $result = $db->sql_query($sql) ) { $game_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); } else { message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']); } if ( $game_info['winner_id'] == $game_info['winner_b_id'] ) { // // Set some vars // $post_data = array(); $post_data['first_post'] = false; $post_data['last_post'] = true; $post_data['has_poll'] = false; $post_data['edit_poll'] = false; $post_data['last_topic'] = false; $bbcode_on = 1; $bbcode_uid = 0; $html_on = 0; $smilies_on = 0; $error_msg = ''; $notify_user = TRUE; $attach_sig = 0; $temp_mode = "reply"; $return_meta = ''; $return_message = $lang['Games_Finished'] . '

' . $lang['Games_Corresp_Topic_Not_Excists'] . '

' . sprintf($lang['Games_Click_Played_Games'], '', ''); $topic_type = POST_NORMAL; $username = $userdata['username']; $post_username = $username; $poll_title = ''; $subject = ''; $forum_id = GAMES_FORUM; // Change by both players their currentgame, won, lost and points $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = " . $game_info['player_id']; if ( $result = $db->sql_query($sql) ) { $player_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); } $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = " . $game_info['player_b_id']; if ( $result = $db->sql_query($sql) ) { $player_b_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); } if ( $player_info['user_id'] == $game_info['winner_id'] ) { $games_points = $game_info['player_points_before'] + (( $game_info['player_b_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 ); $games_b_points = $game_info['player_b_points_before'] - (( $game_info['player_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 ); $games_won = $player_info['games_won'] + 1; $games_lost = $player_info['games_lost']; $games_b_won = $player_b_info['games_won']; $games_b_lost = $player_b_info['games_lost'] + 1; } else if ( $player_b_info['user_id'] == $game_info['winner_id'] ) { $games_points = $game_info['player_points_before'] - (( $game_info['player_b_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 ); $games_b_points = $game_info['player_b_points_before'] + (( $game_info['player_points_before'] * $board_config['games_win_lost_percentage'] ) / 100 ); $games_won = $player_info['games_won']; $games_lost = $player_info['games_lost'] + 1; $games_b_won = $player_b_info['games_won'] + 1; $games_b_lost = $player_b_info['games_lost']; } if ( $games_points < $board_config['games_minimum'] ) { $games_points = $board_config['games_minimum']; } if ( $games_b_points < $board_config['games_minimum'] ) { $games_b_points = $board_config['games_minimum']; } $sql = "UPDATE " . USERS_TABLE . " SET games_points = " . $games_points . ", games_won = " . $games_won . ", games_lost = " . $games_lost . ", games_current_game = '-1' WHERE user_id = " . $game_info['player_id']; if (!$db->sql_query($sql, BEGIN_TRANSACTION)) { message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); } $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = " . $game_info['player_id']; if ( $result = $db->sql_query($sql) ) { $player_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); } $sql = "UPDATE " . USERS_TABLE . " SET games_points = " . $games_b_points . ", games_won = " . $games_b_won . ", games_lost = " . $games_b_lost . ", games_current_game = '-1' WHERE user_id = " . $game_info['player_b_id']; if (!$db->sql_query($sql, BEGIN_TRANSACTION)) { message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); } $sql = "SELECT * FROM " . USERS_TABLE . " WHERE user_id = " . $game_info['player_b_id']; if ( $result = $db->sql_query($sql) ) { $player_b_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); } // Reply in the topic of the game if it is still possible if ( $post_reply ) { // use reason of moderator as message if ( !empty($HTTP_POST_VARS['validate_game']) ) { $reason = ( !empty($HTTP_POST_VARS['message']) ) ? $HTTP_POST_VARS['message'] : ''; $message = "[color=green][u]" . $lang['Games_Has_Won'] . "[/u][/color] " . get_games_username($game_info['winner_id']) . "\n\r\n\r[color=green][u]" . $lang['Games_Points_After'] . "[/u][/color]\n\r"; $message .= get_games_username($player_info['user_id']) . ": " . $player_info['games_points'] . " punten,\n\r"; $message .= get_games_username($player_b_info['user_id']) . ": " . $player_b_info['games_points'] . " punten,\n\r"; $message .= "[color=green][u]" . $lang['Games_Comment_Reason'] . "[/u][/color]\n\r" . $reason; } // use combination of comments of both players as message if ( !empty($HTTP_POST_VARS['validate_single_user']) ) { $message = "[color=green][u]" . $lang['Games_Has_Won'] . "[/u][/color] " . get_games_username($game_info['winner_id']) . "\n\r\n\r[color=green][u]" . $lang['Games_Points_After'] . "[/u][/color]\n\r"; $message .= get_games_username($player_info['user_id']) . ": " . $player_info['games_points'] . " punten,\n\r"; $message .= get_games_username($player_b_info['user_id']) . ": " . $player_b_info['games_points'] . " punten,\n\r"; $message .= "[color=green][u]" . $lang['Games_Comment_Challenger'] . "[/u][/color]\n\r" . $game_info['comment'] . "\n\r[color=green][u]" . $lang['Games_Comment_Opponent'] . "[/u][/color]\n\r" . $game_info['comment_b']; } prepare_post($temp_mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $message, $poll_title, $poll_options, $poll_length); if ( $error_msg == '' ) { // First post in topic of the to-validate-game: change subject $sql = "SELECT games_first_post_id, topic_id FROM " . GAMES_TABLE . " WHERE game_id = " . $game_id; if ( $result = $db->sql_query($sql) ) { $game_first_post_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); $game_first_post_id = $game_first_post_info['games_first_post_id']; $topic_id = $game_first_post_info['topic_id']; $sql = "SELECT post_subject FROM " . POSTS_TEXT_TABLE . " WHERE post_id = " . $game_first_post_id; if ( $result = $db->sql_query($sql) ) { $post_first_post_info = $db->sql_fetchrow($result); $db->sql_freeresult($result); $post_first_post_info['post_subject'] = str_replace($lang['Games_Subject_Prefix_Running'], '', $post_first_post_info['post_subject']); $post_first_post_subject = $lang['Games_Subject_Prefix_Played']; $post_first_post_subject .= $post_first_post_info['post_subject']; $sql_1 = "UPDATE " . POSTS_TEXT_TABLE . " SET post_subject = '" . $post_first_post_subject . "' WHERE post_id = " . $game_first_post_id; $sql_2 = "UPDATE " . TOPICS_TABLE . " SET topic_title = '" . $post_first_post_subject . "' WHERE topic_id = " . $topic_id; if (!$db->sql_query($sql_1, BEGIN_TRANSACTION)) { message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); } if (!$db->sql_query($sql_2, END_TRANSACTION)) { message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); } $post_first_post_message = ""; // add_search_words('single', $game_first_post_id, stripslashes($post_first_post_message), stripslashes($post_first_post_subject)); } } submit_post($temp_mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $poll_id, $topic_type, $bbcode_on, $html_on, $smilies_on, $attach_sig, $bbcode_uid, str_replace("\'", "''", $username), str_replace("\'", "''", $subject), str_replace("\'", "''", $message), str_replace("\'", "''", $poll_title), $poll_options, $poll_length); make_post_autom($post_id); $user_id = $userdata['user_id']; update_post_stats($temp_mode, $post_data, $forum_id, $topic_id, $post_id, $user_id); user_notification($temp_mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user); // Change cookies $tracking_topics = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array(); $tracking_forums = ( !empty($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array(); if ( count($tracking_topics) + count($tracking_forums) == 100 && empty($tracking_topics[$topic_id]) ) { asort($tracking_topics); unset($tracking_topics[key($tracking_topics)]); } $tracking_topics[$topic_id] = time(); setcookie($board_config['cookie_name'] . '_t', serialize($tracking_topics), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']); // Show message with link to topic after posting new game $return_meta = ''; $return_message = $lang['Games_Finished'] . '

' . sprintf($lang['Games_Click_View_Reply'], '', '') . '

' . sprintf($lang['Games_Click_Played_Games'], '', ''); } } // $template->assign_vars(array( // 'META' => $return_meta) // ); message_die(GENERAL_MESSAGE, $return_message); } else { $confirm_meta = ''; $confirm_message = $lang['Games_Validated_Other_Not'] . '

' . sprintf($lang['Games_Click_Return_Games'], '', ''); // $template->assign_vars(array( // 'META' => $confirm_meta) // ); message_die(GENERAL_MESSAGE, $confirm_message); } } else { // // User default entry point // // When a user wants to validate a game if ( !empty($HTTP_POST_VARS['validate_single_user']) && empty($HTTP_POST_VARS['validate_game']) ) { $game_id = $HTTP_POST_VARS['validate_single_user']; $sql = "SELECT * FROM " . GAMES_TABLE . " WHERE game_id = " . $game_id; if ( $result = $db->sql_query($sql) ) { $row = $db->sql_fetchrow($result); $games_player_vs_player = $lang['Games_Subject_part1']; $games_player_vs_player .= $row['game_id']; $games_player_vs_player .= ': '; $games_player_vs_player .= get_games_username($row['player_id']); $games_player_vs_player .= $lang['Games_Subject_part2']; $games_player_vs_player .= get_games_username($row['player_b_id']); $select_winner_list = ''; $message = ''; $hidden_form_fields = ''; $hidden_form_fields .= ''; $db->sql_freeresult($result); } else { message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']); } // // Load template & Set page title & Output page header // $template->set_filenames(array( 'body' => 'games_validate_body.tpl') ); $page_title = $lang['Games_Validate_Title']; include($phpbb_root_path . 'includes/page_header.'.$phpEx); // // Output the data to the template // $template->assign_vars(array( 'COMMENT' => $message, 'L_POST_A' => $games_player_vs_player, 'L_WINNER' => $lang['Games_Select_Winner'], 'L_COMMENT_BODY' => $lang['Games_Comment_Body'], 'L_EMPTY_MESSAGE' => $lang['Games_Validate_Comment_Tip'], 'L_GAMES_COMMENT_TIP' => $lang['Games_Posting_Tip'], 'L_SUBMIT' => $lang['Submit'], 'S_WINNER_SELECT' => $select_winner_list, 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields, 'S_POST_ACTION' => append_sid("games.$phpEx?mode=validate")) ); } // When an moderator wants to validate a game else if ( !empty($HTTP_POST_VARS['validate_game']) && empty($HTTP_POST_VARS['validate_single_user']) ) { $game_id = $HTTP_POST_VARS['validate_game']; $sql = "SELECT * FROM " . GAMES_TABLE . " WHERE game_id = " . $game_id; if ( $result = $db->sql_query($sql) ) { $row = $db->sql_fetchrow($result); $games_player_vs_player = $lang['Games_Subject_part1']; $games_player_vs_player .= $row['game_id']; $games_player_vs_player .= ': '; $games_player_vs_player .= get_games_username($row['player_id']); $games_player_vs_player .= $lang['Games_Subject_part2']; $games_player_vs_player .= get_games_username($row['player_b_id']); $select_winner_list = ''; $message = ''; $hidden_form_fields = ''; $hidden_form_fields .= ''; $db->sql_freeresult($result); } else { message_die(GENERAL_MESSAGE, $lang['Games_Game_Not_Excists']); } // // Load template & Set page title & Output page header // $template->set_filenames(array( 'body' => 'games_validate_mod_body.tpl') ); $page_title = $lang['Games_Validate_Title']; include($phpbb_root_path . 'includes/page_header.'.$phpEx); // // Output the data to the template // $template->assign_vars(array( 'REASON' => $message, 'L_POST_A' => $games_player_vs_player, 'L_WINNER' => $lang['Games_Select_Winner'], 'L_REASON_BODY' => $lang['Games_Reason_Body'], 'L_EMPTY_MESSAGE' => $lang['Games_Validate_Comment_Tip'], 'L_GAMES_REASON_TIP' => $lang['Games_Reason_Tip'], 'L_SUBMIT' => $lang['Submit'], 'S_WINNER_SELECT' => $select_winner_list, 'S_HIDDEN_FORM_FIELDS' => $hidden_form_fields, 'S_POST_ACTION' => append_sid("games.$phpEx?mode=validate")) ); } else { die('Hacking attempt'); } // // Include the html part // $template->pparse('body'); include($phpbb_root_path . 'includes/page_tail.'.$phpEx); } break;