Exemple #1
0
/**
 * Parse the donation result and automatically record it in the database
 * Uses Paypal IDN https://developer.paypal.com/docs/classic/products/instant-payment-notification/
 * 
 * @global type $UMC_SETTING
 * @return type
 */
function umc_process_donation()
{
    global $UMC_USER, $UMC_DONATION;
    // only continue for logged-in users
    if (!$UMC_USER) {
        return;
    }
    $username = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    XMPP_ERROR_trigger("Donation Process form was accessed!");
    // Read POST data
    // reading posted data directly from $_POST causes serialization
    // issues with array data in POST. Reading raw POST data from input stream instead.
    $raw_post_data = file_get_contents('php://input');
    $raw_post_array = explode('&', $raw_post_data);
    $myPost = array();
    foreach ($raw_post_array as $keyval) {
        $keyval = explode('=', $keyval);
        if (count($keyval) == 2) {
            $myPost[$keyval[0]] = urldecode($keyval[1]);
        }
    }
    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    if (function_exists('get_magic_quotes_gpc')) {
        $get_magic_quotes_exists = true;
    }
    foreach ($myPost as $key => $value) {
        if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
            $value = urlencode(stripslashes($value));
        } else {
            $value = urlencode($value);
        }
        $req .= "&{$key}={$value}";
    }
    // Post IPN data back to PayPal to validate the IPN data is genuine
    // Without this step anyone can fake IPN data
    $ch = curl_init($UMC_DONATION['paypal_url']);
    if ($ch == FALSE) {
        return FALSE;
    }
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    // curl_setopt($ch, CURLOPT_HEADER, 1);
    // curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    // CONFIG: Optional proxy configuration
    //curl_setopt($ch, CURLOPT_PROXY, $proxy);
    //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
    // Set TCP timeout to 30 seconds
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
    // CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
    // of the certificate as shown below. Ensure the file is readable by the webserver.
    // This is mandatory for some environments.
    curl_setopt($ch, CURLOPT_CAINFO, $UMC_DONATION['cert_path']);
    $res_raw = curl_exec($ch);
    if (curl_errno($ch) != 0) {
        XMPP_ERROR_trace("Can't connect to PayPal to validate IPN message: ", curl_error($ch));
        curl_close($ch);
        exit;
    } else {
        // Log the entire HTTP response if debug is switched on.
        XMPP_ERROR_trace("HTTP request of validation request:", curl_getinfo($ch, CURLINFO_HEADER_OUT) . " for IPN payload: REQuest: {$req} \n\n RESponse: {$res_raw}");
        curl_close($ch);
    }
    // Inspect IPN validation result and act accordingly
    // Split response headers and payload, a better way for strcmp
    $tokens = explode("\r\n\r\n", trim($res_raw));
    $res = trim(end($tokens));
    if (strcmp($res, "VERIFIED") == 0) {
        // ok, it's verfiied, get the POST variables and then continue.
        $s_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
        XMPP_ERROR_trace("Verified IPN result: {$res} " . PHP_EOL);
    } else {
        if (strcmp($res, "INVALID") == 0) {
            // verficiation failed, request assistance
            XMPP_ERROR_trigger("Invalid IPN result: {$res}");
            return "There was an issue verifying your payment. Please contact an admin at minecraft@uncovery.me to resolve this issue";
        }
    }
    // process payment
    $firstname = $s_post['first_name'];
    $lastname = $s_post['last_name'];
    $itemname = $s_post['item_name'];
    $amount = $s_post['payment_gross'];
    echo "<p><h3>Thank you for your purchase!</h3></p>";
    echo "<b>Payment Details</b><br>\n";
    echo "<li>Name: {$firstname} {$lastname}</li>\n";
    echo "<li>Item: {$itemname}</li>\n";
    echo "<li>Amount: {$amount}</li>\n";
    echo "Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br> " . "You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> " . "to view details of this transaction.<br>";
    // list of verifiable entries:
    // OK check whether the payment_status is Completed
    // TODO check that txn_id has not been previously processed
    // OK check that receiver_email is your PayPal email
    // TODO check that payment_amount/payment_currency are correct
    // assign posted variables to local variables
    $verify_entries = array('payment_status' => 'Completed', 'business' => $UMC_DONATION['business_email'], 'option_selection2' => false, 'payer_email' => false, 'payment_gross' => false, 'payment_fee' => false, 'txn_id' => false, 'option_selection3' => false);
    $is_ok = true;
    $sql_vals = array();
    foreach ($verify_entries as $entry => $value) {
        if ($value && $s_post[$entry] != $value) {
            $is_ok = false;
            XMPP_ERROR_trace("WRONG ENTRY: {$entry}", "Should be '{$value}', is '{$s_post[$entry]}'");
        } else {
            // if the array value = false, just store the value in SQL
            $sql_vals[$entry] = umc_mysql_real_escape_string($s_post[$entry]);
        }
    }
    // add the entry to the database
    if ($is_ok) {
        $date = umc_mysql_real_escape_string(date('Y-m-d'));
        $final_value = umc_mysql_real_escape_string($s_post['payment_gross'] - $s_post['payment_fee']);
        $sql = "INSERT INTO minecraft_srvr.donations (`amount`, `uuid`, `email`, `date`, `txn_id`)\r\n            VALUES ({$final_value}, {$sql_vals['option_selection3']}, {$sql_vals['payer_email']}, {$date}, {$sql_vals['txn_id']})";
        umc_mysql_query($sql, true);
        XMPP_ERROR_trigger("Donation SQL executed!");
        $subject = "[Uncovery Minecraft] Donation activated!";
        $headers = "From: minecraft@uncovery.me" . "\r\n" . "Reply-To: minecraft@uncovery.me" . "\r\n" . 'X-Mailer: PHP/' . phpversion();
        $recipient_text = '';
        if ($uuid != $s_post['option_selection3']) {
            $rec_username = umc_uuid_getone($s_post['option_selection3'], 'username');
            $recipient_text = "The donation to be in benefit of {$rec_username}, as you asked.";
        }
        $mailtext = "Dear {$username}, \r\n\r\nWe have just received and activated your donation. Thanks a lot for contributing to Uncovery Minecraft!\r\n" . "After substracting PayPal fees, the donation value is {$final_value} USD. {$recipient_text}\r\n" . "Your userlevel will be updated as soon as you login to the server next time. You can also check it on the frontpage of the website.\r\n" . "Thanks again, and have fun building your dream!\r\n\r\nSee you around,\r\nUncovery";
    } else {
        XMPP_ERROR_trigger("Not all values correct for donation!");
        $mailtext = "Dear {$username}, \r\n\r\nWe have just received your donation. Thanks a lot for contributing to Uncovery Minecraft!\r\n" . "After substracting PayPal fees, the donation value is {$final_value} USD. {$recipient_text}\r\n" . "Your userlevel will be updated as soon as we processed your donation. You can also check it on the frontpage of the website.\r\n" . "Thanks again, and have fun building your dream!\r\n\r\nSee you around,\r\nUncovery";
        mail("*****@*****.**", "Donation failed!", $mailtext, $headers);
    }
    mail($s_post['payer_email'], $subject, $mailtext, $headers);
}
function umc_lottery()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $lottery, $ENCH_ITEMS;
    $user_input = $UMC_USER['args'][2];
    // check if there is a valid user on the server before applying the vote.
    $user = umc_check_user($user_input);
    if (!$user) {
        umc_log("lottery", "voting", "user {$user} does not exist");
        return false;
    }
    // get the voting players uuid
    $uuid = umc_user2uuid($user);
    // give reinforcing feedback - set subtitle (not displayed)
    $subtitle = 'title ' . $user . ' subtitle {text:"Thanks for your vote!",color:gold}';
    umc_ws_cmd($subtitle, 'asConsole');
    // display the feedback - displays subtitle AND title
    $title = 'title ' . $user . ' title {text:"+100 Uncs",color:gold}';
    umc_ws_cmd($title, 'asConsole');
    // allow uncovery to test chance rolls for debugging purposes
    $chance = false;
    if ($user == 'uncovery' && isset($UMC_USER['args'][5])) {
        $chance = $UMC_USER['args'][5];
    }
    // get the roll array based on chance
    $roll = umc_lottery_roll_dice($chance);
    // umc_echo(umc_ws_vardump($roll));
    // define the rewards and item more legibly
    $item = $roll['item'];
    $luck = $roll['luck'];
    $prize = $lottery[$item];
    //echo "type = {$prize['type']}<br>;";
    //echo "complete chance: $chance<br>;";
    //var_dump($prize);
    // get the metadata if required for the item
    if (isset($prize['detail'])) {
        $detail = $prize['detail'];
    }
    $type = $prize['type'];
    // always give 100 uncs irrespective of roll.
    umc_money(false, $user, 100);
    // instantiate block variables
    $given_block_data = 0;
    $given_block_type = 0;
    //var_dump($prize);
    // based on item type, give reward to the player
    switch ($type) {
        case 'item':
            umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'additional_home':
            $newname = 'lottery' . "_" . umc_random_code_gen(4);
            umc_home_add($uuid, $newname, true);
            $item_txt = "an addtional home!!";
            break;
        case 'random_unc':
            $luck2 = mt_rand(1, 500);
            umc_money(false, $user, $luck2);
            $item_txt = "{$luck2} Uncs";
            break;
        case 'random_potion':
            $luck2 = mt_rand(0, 63);
            umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_ench':
            // pick which enchantment
            $rand_ench = array_rand($ENCH_ITEMS);
            $ench_arr = $ENCH_ITEMS[$rand_ench];
            //pick which item to enchant
            $rand_item = array_rand($ench_arr['items']);
            $rand_item_id = $ench_arr['items'][$rand_item];
            // pick level of enchantment
            $lvl_luck = mt_rand(1, $ench_arr['max']);
            //echo "$item $ench_txt $lvl_luck";
            $item_ench_arr = array($rand_ench => $lvl_luck);
            $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr);
            $item_name = $item['item_name'];
            $full = $item['full'];
            umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery');
            $item_txt = "a " . $full;
            break;
        case 'random_pet':
            // same as blocks below but only 1 always
            umc_echo($type);
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "a " . $item['full'];
            break;
        case 'random_common':
        case 'random_ore':
        case 'random_manuf':
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $luck3 = mt_rand(1, 64);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "{$luck3} " . $item['full'];
            break;
    }
    if ($user != 'uncovery') {
        // testing only
        $item_nocolor = umc_ws_color_remove($item_txt);
        umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole');
        umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})");
        $userlevel = umc_get_userlevel($user);
        if (in_array($userlevel, array('Settler', 'Guest'))) {
            $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!";
            umc_msg_user($user, $msg);
        }
    } else {
        umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!");
    }
    // add vote to the database
    $service_raw = strtolower($UMC_USER['args'][3]);
    // fix service
    $search = array('http://www.', 'https://www.', 'http://', 'https://');
    $service = umc_mysql_real_escape_string(str_replace($search, '', $service_raw));
    // sql log
    $sql_reward = umc_mysql_real_escape_string($type);
    $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]);
    $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`, `roll_value`, `reward`)\r\n        VALUES ('{$uuid}', NOW(), {$service}, {$ip}, {$luck}, {$sql_reward});";
    umc_mysql_query($sql, true);
}
function umc_user_email($username)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $username_quoted = umc_mysql_real_escape_string($username);
    $sql = "SELECT user_email FROM minecraft.wp_users WHERE display_name={$username_quoted} LIMIT 1;";
    $data = umc_mysql_fetch_all($sql);
    if (count($data) > 0) {
        return $data[0]['user_email'];
    } else {
        return false;
    }
}
function umc_home_import()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // global $UMC_USER;
    // we automatically import old homes for all players on login, but only once
    // include spyc to parse YAML https://github.com/mustangostang/spyc
    require_once '/home/includes/spyc/Spyc.php';
    $users = umc_get_active_members();
    foreach ($users as $uuid => $username) {
        $path = '/home/minecraft/server/bukkit/plugins/Essentials/userdata/' . $uuid . ".yml";
        $A = Spyc::YAMLLoad($path);
        $existing_count = umc_home_count(false, $uuid);
        if ($existing_count > 0) {
            continue;
        }
        if (!isset($A['homes'])) {
            continue;
        }
        $count = count($A['homes']);
        if ($count == 0) {
            continue;
        }
        $H = $A['homes'];
        // iterate homes and import them
        foreach ($H as $home_name => $h) {
            $name = umc_mysql_real_escape_string($home_name);
            // XMPP_ERROR_trigger($h);
            $sql = "INSERT INTO minecraft_srvr.`homes`(`name`, `uuid`, `world`, `x`, `y`, `z`, `yaw`) VALUES " . "({$name},'{$uuid}','{$h['world']}','{$h['x']}','{$h['y']}','{$h['z']}','{$h['yaw']}');";
            umc_mysql_query($sql, true);
        }
        umc_log('home', 'import', "{$uuid}/{$username} {$count} homes have been imported!");
    }
}
/**
 * Get a UUID from the wp_username
 *
 * @param string $uuid
 * @return string
 */
function umc_wp_get_uuid_for_currentuser()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $current_user = wp_get_current_user();
    $username = $current_user->display_name;
    if ($username == '') {
        // we have a guest, get UUID from system instead
        return false;
    }
    $username_sql = umc_mysql_real_escape_string($username);
    $sql = "SELECT meta_value as uuid FROM minecraft.wp_usermeta\r\n        LEFT JOIN minecraft.wp_users ON ID=user_id\r\n        WHERE display_name={$username_sql} AND meta_key ='minecraft_uuid' LIMIT 1;";
    $data = umc_mysql_fetch_all($sql);
    if (count($data) == 0) {
        return false;
    }
    $out = strtolower($data[0]['uuid']);
    return $out;
}
Exemple #6
0
function umc_log_chat_import()
{
    global $UMC_PATH_MC;
    $pattern_path = "{$UMC_PATH_MC}/server/bukkit/plugins/Herochat/logs/*";
    $files = umc_glob_recursive($pattern_path);
    $pattern_line = '/([0-9.]{10} [0-9:]{8})( \\[[A-Z]\\])? ?\\*? ?(\\[Trivia\\]|[_0-9a-zA-Z]*)( -> ([_0-9a-zA-Z]*|)?)?(.*: )?(.*)/';
    $target_path = '/disk2/backup/log/minecraft';
    // erase the file
    foreach ($files as $file) {
        $text_arr = file($file);
        // get the first text
        $sql = "INSERT INTO `minecraft_log`.`chat_log` (`timestamp`, `source`, `target`, `text`, `raw`) VALUES \n";
        if (count($text_arr) == 0) {
            continue;
        }
        foreach ($text_arr as $line) {
            $match = array();
            $raw = umc_mysql_real_escape_string(trim($line));
            preg_match($pattern_line, $line, $match);
            // $raw = bzcompress($match[0]);
            $time = $match[1];
            $source = trim($match[3]);
            $target = trim($match[4]);
            if (strlen($match[2]) > 0) {
                $target = trim($match[2]);
            } else {
                if (strlen($match[5]) > 0) {
                    $target = trim($match[5]);
                }
            }
            $text = trim($match[7]);
            $text_sql = umc_mysql_real_escape_string($text);
            if (strlen($time) > 0) {
                $sql .= "('{$time}', '{$source}', '{$target}', {$text_sql}, {$raw}),";
            }
        }
        $ins = substr($sql, 0, -1) . ";";
        $date_today = umc_datetime();
        $today = $date_today->format('Y|m|d|H|i');
        $date_parts = explode("|", $today);
        $year = $date_parts[0];
        $month = $date_parts[1];
        $day = $date_parts[2];
        $hour = $date_parts[3];
        $min = $date_parts[3];
        umc_mysql_query($ins, true);
        $file = "{$year}-{$month}-{$day}_{$hour}_{$min}_chat_log.tar.bz2";
        rename($file, "{$target_path}/{$year}/{$month}/{$file}");
    }
}
Exemple #7
0
function umc_story_admin()
{
    global $UMC_USER;
    if (!$UMC_USER) {
        die('You need to be online to use this!');
    }
    if (!isset($UMC_USER['uuid'])) {
        XMPP_ERROR_trigger("UUID not set");
    }
    $uuid = $UMC_USER['uuid'];
    $story = 'Please enter text here';
    $pass = umc_get_code();
    $action_text = "Add a new entry";
    $action_code = "add";
    $title = "Insert a title";
    $survival = 0;
    $items = '';
    $warp = '';
    $clear_inv = 0;
    if (isset($_POST['delete'])) {
        $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
        $sql = "DELETE FROM minecraft_iconomy.story WHERE uuid='{$uuid}' AND code={$code};";
        $rst = umc_mysql_query($sql);
    } else {
        if (isset($_POST['add'])) {
            $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
            $warp = umc_mysql_real_escape_string(strip_tags($_POST['warp']));
            $save_story = umc_mysql_real_escape_string(strip_tags($_POST['story']));
            $save_title = umc_mysql_real_escape_string(strip_tags($_POST['storyline']));
            $save_items = umc_mysql_real_escape_string(strip_tags($_POST['items']));
            $save_survival = 0;
            if (isset($_POST['survival'])) {
                $save_survival = -1;
            }
            $save_clear_inv = 0;
            if (isset($_POST['clear_inv'])) {
                $save_clear_inv = -1;
            }
            if ($save_story != 'Please enter text here') {
                $sql2_raw = "INSERT INTO minecraft_iconomy.story (`uuid`, `story`, `code`, `storyline`, `forcesurvival`, `items`, `clear_inv`, `warp`)\r\n                VALUES ('{$uuid}', {$save_story}, {$code}, {$save_title}, '{$save_survival}', {$save_items}, '{$save_clear_inv}', {$warp})";
                $sql2 = str_replace('&', '_', $sql2_raw);
                // this removes strings that can be abused by the minimap
                umc_mysql_query($sql2);
            }
        } else {
            if (isset($_POST['edit'])) {
                $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
                $sql = "SELECT * FROM minecraft_iconomy.story WHERE uuid='{$uuid}' AND code={$code};";
                $D = umc_mysql_fetch_all($sql);
                if (count($D) > 0) {
                    $row = $D[0];
                    $story = stripslashes(strip_tags($row['story']));
                    $pass = $row['code'];
                    $warp = $row['warp'];
                    $action_text = "Edit story and save";
                    $action_code = "update";
                    $title = $row['storyline'];
                    $survival = $row['forcesurvival'];
                    $items = $row['items'];
                    $clear_inv = $row['clear_inv'];
                }
            } else {
                if (isset($_POST['update'])) {
                    $code = umc_mysql_real_escape_string(strip_tags($_POST['storycode']));
                    $save_story = umc_mysql_real_escape_string(strip_tags($_POST['story']));
                    $save_title = umc_mysql_real_escape_string(strip_tags($_POST['storyline']));
                    $save_items = umc_mysql_real_escape_string(strip_tags($_POST['items']));
                    $save_survival = 0;
                    if (isset($_POST['survival'])) {
                        $save_survival = -1;
                    }
                    $warp = '';
                    if (isset($_POST['warp'])) {
                        $warp = umc_mysql_real_escape_string(strip_tags($_POST['warp']));
                    }
                    $save_clear_inv = 0;
                    if (isset($_POST['clear_inv'])) {
                        $save_clear_inv = -1;
                    }
                    $sql = "UPDATE minecraft_iconomy.story\r\n\t    SET story= {$save_story},\r\n\t\tstoryline={$save_title},\r\n\t\twarp={$warp},\r\n\t\tforcesurvival='{$save_survival}',\r\n            \t`items`={$save_items},\r\n\t\t`clear_inv`='{$save_clear_inv}'\r\n            WHERE uuid='{$uuid}' and code={$code};";
                    $sql = str_replace('&', '_', $sql);
                    // this removes strings that can be abused by the minimap
                    umc_mysql_query($sql, true);
                }
            }
        }
    }
    $sql = "SELECT * FROM minecraft_iconomy.story WHERE uuid='{$uuid}' ORDER BY storyline, id;";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) > 0) {
        echo "<table><tr><td style=\"padding:3px;\"><strong>Storyline</strong></td><td style=\"padding:3px;\"><strong>Survival?<br>Clear Inv?</strong></td><td style=\"padding:3px;\"><strong>Code</strong></td>" . "<td style=\"padding:3px;\"><strong>Hits</strong></td>" . "<td style=\"padding:3px;\"><strong>Story & items</strong></td><td style=\"padding:3px;\"><strong>Actions</strong></td></tr>\n";
        foreach ($D as $row) {
            $count_sql = "SELECT count(uuid) as counter FROM minecraft_iconomy.story_users WHERE story_id='{$row['id']} GROUP BY story_id';";
            $D = umc_mysql_fetch_all($count_sql);
            $count_row = $D[0];
            $hitcount = $count_row['counter'];
            $story_short = substr($row['story'], 0, 50) . '...';
            $txt_survival = 'No';
            if ($row['forcesurvival'] == -1) {
                $txt_survival = 'Yes';
            }
            $txt_clear_inv = 'No';
            if ($row['clear_inv'] == -1) {
                $txt_clear_inv = 'Yes';
            }
            if (strlen($row['items']) > 0) {
                $story_short = $story_short . "<br><strong>Items:</strong>" . $row['items'];
            }
            $buttons = "<form action=\"#result\" method=\"post\"><input type=\"submit\" name=\"edit\" class=\"button-primary\"value=\"Edit\"/> " . "<input type=\"submit\" name=\"delete\" class=\"button-primary\"value=\"Delete\"/><input type=\"hidden\" name=\"storycode\" value=\"{$row['code']}\"></form>";
            echo "<tr><td>{$row['storyline']}</td><td>{$txt_survival} / {$txt_clear_inv}</td><td>{$row['code']}</td><td>{$hitcount}</td><td>{$story_short}</td><td>{$buttons}</td></tr>\n";
        }
        echo "</table>";
    }
    // add new content form
    $surv_checked = '';
    if ($survival == -1) {
        $surv_checked = ' checked="checked"';
    }
    $inv_checked = '';
    if ($clear_inv == -1) {
        $inv_checked = ' checked="checked"';
    }
    $out = "<hr><a name=\"result\">{$action_text}:</a><form action=\"#result\" method=\"post\">\n" . "<strong>Your story code: {$pass}</strong><br>" . "Title: <input type=\"text\" name=\"storyline\" value=\"{$title}\"> Force Survival mode? <input type=\"checkbox\" name=\"survival\" value=\"survival\"{$surv_checked}/>" . " Clear inventory? <input type=\"checkbox\" name=\"clear_inv\" value=\"clear_inv\"{$inv_checked}/> (city & flatlands only)<br>" . "Give items: <input type=\"text\" name=\"items\" value=\"{$items}\"> (Format: item_id:damage:amount;... city & flatlands only)<br>" . "Warp to point: <input type=\"text\" name=\"warp\" value=\"{$warp}\"> (Format: 'story_yourwarp'; Ask Uncovery to create a warp point for you, only works in city. Do not include the story_ here)<br>" . "<textarea rows=\"10\" name=\"story\">{$story}</textarea>" . "<input type=\"hidden\" name=\"storycode\" value=\"{$pass}\">" . "<input type=\"submit\" name=\"{$action_code}\" id=\"wp-submit\" class=\"button-primary\" " . "value=\"Save\" tabindex=\"100\" /></form>\n\n";
    echo $out;
}
function umc_ts_authorize()
{
    global $UMC_USER, $UMC_TEAMSPEAK;
    // include libraries
    require_once '/home/uncovery/teamspeak_php/libraries/TeamSpeak3/TeamSpeak3.php';
    // connect to server
    if (!$UMC_TEAMSPEAK['server']) {
        $UMC_TEAMSPEAK['server'] = TeamSpeak3::factory("serverquery://*****:*****@74.208.45.80:10011/?server_port=9987");
    }
    // get client by name
    $uuid = $UMC_USER['uuid'];
    $userlevel = $UMC_USER['userlevel'];
    $username = $UMC_USER['username'];
    // get required servergroup
    foreach ($UMC_TEAMSPEAK['user_groups'] as $g_id => $usergroups) {
        if (in_array($userlevel, $usergroups)) {
            $target_group = $g_id;
            break;
        }
    }
    // first, we see if there is a current user logged in
    $ts_Client = false;
    umc_header();
    // first, we clean out old clients that are registered with minecraft
    umc_ts_clear_rights($uuid, true);
    // then, we try to find a new user on the TS server to give rights to
    umc_echo("Your TS level is " . $UMC_TEAMSPEAK['ts_groups'][$target_group]);
    umc_echo("Looking for user {$username} in TS...");
    $found = 0;
    foreach ($UMC_TEAMSPEAK['server']->clientList() as $ts_Client) {
        if ($ts_Client["client_nickname"] == $username) {
            $found++;
        }
    }
    if ($found == 0) {
        umc_echo("You need to logon to Teamspeak with the EXACT same username (\"{$username}\")");
        umc_echo("Once you did that, please try again");
        umc_footer();
        return false;
    } else {
        if ($found > 1) {
            umc_echo("There are 2 users with the same username (\"{$username}\") online.");
            umc_echo("Process halted. Make sure you are the only one with the correct username");
            umc_echo("If there is someone else hogging your username, please send in a /ticket");
            umc_footer();
            return false;
        }
    }
    // we have a user
    umc_echo("Found TS user " . $ts_Client["client_nickname"]);
    $ts_dbid = $ts_Client["client_database_id"];
    // remove all groups
    $servergroups = array_keys($UMC_TEAMSPEAK['server']->clientGetServerGroupsByDbid($ts_dbid));
    foreach ($servergroups as $sgid) {
        umc_echo($ts_Client["client_nickname"] . " is member of group " . $UMC_TEAMSPEAK['ts_groups'][$sgid]);
        if ($sgid != $target_group && $sgid != 8) {
            umc_echo("Removing usergroup {$sgid}...");
            $UMC_TEAMSPEAK['server']->serverGroupClientDel($sgid, $ts_dbid);
            // remove user from group
        } else {
            if ($sgid == $target_group) {
                umc_echo("Not removing usergroup {$sgid}...");
                $target_group = false;
            }
        }
    }
    // add the proper group
    if ($target_group) {
        // add target group of required
        umc_echo("Adding you to group " . $UMC_TEAMSPEAK['ts_groups'][$target_group]);
        $ts_Client->addServerGroup($target_group);
    }
    // get UUID
    $target_ts_uuid = $ts_Client["client_unique_identifier"];
    $ts_uuid = umc_mysql_real_escape_string($target_ts_uuid);
    $ins_sql = "UPDATE minecraft_srvr.UUID SET ts_uuid={$ts_uuid} WHERE UUID='{$uuid}';";
    umc_mysql_query($ins_sql, true);
    umc_echo("Adding TS ID {$ts_uuid} to database");
    umc_footer("Done!");
}
function umc_trivia_answer()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $quiz_arr = umc_trivia_get_current_quiz();
    $quiz_id = $quiz_arr['id'];
    $question_no = $quiz_arr['question_no'];
    $master = $quiz_arr['master'];
    $balance = umc_money_check($player);
    $price = $quiz_arr['price'];
    if (!$quiz_arr) {
        umc_error("There is no active quiz to answer questions for. Please start one first.");
    } else {
        if ($player == $master) {
            umc_error("You cannot answer your own question!");
        } else {
            if (!$quiz_arr['question_no']) {
                umc_error("There is no question asked for the current trivia yet. Please wait!");
            } else {
                if ($quiz_arr['status'] != 'asked') {
                    umc_error("The last question was closed already. Please wait for the next one to be asked!");
                } else {
                    if (!isset($args[2])) {
                        umc_error("You have to provide an answer!");
                    } else {
                        if (!$balance || $balance < $price) {
                            umc_error("Answering costs {$price} Uncs, but you do not have that much money!");
                        } else {
                            if (count($quiz_arr['users']) > 0 && in_array($player, $quiz_arr['users'])) {
                                umc_error("You have already answered that question!");
                            }
                        }
                    }
                }
            }
        }
    }
    $answer_raw = '';
    for ($i = 2; $i < count($args); $i++) {
        $answer_raw .= " " . $args[$i];
    }
    $answer = trim($answer_raw);
    umc_header("Trivia Quiz No.{$quiz_id} Question No.{$question_no}");
    umc_echo("You answer: {$answer}");
    umc_echo("Thanks for answering! Your account was debited {$price} Uncs!");
    umc_footer(true);
    // register answer
    umc_money($player, false, $price);
    $answer_str = umc_mysql_real_escape_string($answer);
    $sql = "INSERT INTO minecraft_quiz.quiz_answers (quiz_id, question_id, answer_text, username, time, result)\r\n        VALUES ({$quiz_arr['id']}, {$quiz_arr['question_id']}, {$answer_str}, '{$player}', NOW(), 'wrong');";
    umc_mysql_query($sql);
    // message the quizmaster
    umc_exec_command("----------------- New Trivia Answer -----------------", 'toPlayer', $master);
    umc_exec_command("\"{$answer}\"", 'toPlayer', $master);
    umc_exec_command("To display all current answers, use /trivia check", 'toPlayer', $master);
    umc_exec_command("--------------------------------------------------", 'toPlayer', $master);
    umc_log('trivia', 'answer', "{$player} answered trivia {$quiz_id} question id {$quiz_arr['question_id']}");
}
Exemple #10
0
function umc_mail_send_backend($recipient_uuid, $sender_uuid, $message_raw, $subject_raw, $action, $msg_id = false)
{
    $recipient = umc_mysql_real_escape_string($recipient_uuid);
    $sender = umc_mysql_real_escape_string($sender_uuid);
    $message = umc_mysql_real_escape_string($message_raw);
    $subject = umc_mysql_real_escape_string($subject_raw);
    $status = 'draft';
    if ($action == 'Send') {
        $status = 'sent';
    }
    if (isset($msg_id)) {
        $sql = "UPDATE minecraft_srvr.user_mail\r\n            SET `sender_uuid`={$sender}, `recipient_uuid`={$recipient}, `title`={$subject}, `message`={$message}, `status`='{$status}', `date_time`=NOW()\r\n            WHERE msg_id={$msg_id};";
    } else {
        $sql = "INSERT INTO minecraft_srvr.user_mail (`sender_uuid`, `recipient_uuid`, `title`, `message`, `status`, `date_time`)\r\n            VALUES ({$sender},{$recipient},{$subject},{$message},'{$status}', NOW());";
    }
    umc_mysql_query($sql, true);
    if ($action == 'Send') {
        $mail_id = umc_mysql_insert_id();
        umc_mail_send_alert($mail_id);
    }
}
Exemple #11
0
function umc_lottery()
{
    //  umc_error_notify("User $user, $chance (umc_lottery)");
    global $UMC_USER, $lottery, $ENCH_ITEMS;
    $user_input = $UMC_USER['args'][2];
    $user = umc_check_user($user_input);
    if (!$user) {
        umc_log("lottery", "voting", "user {$user} does not exist");
        return false;
    }
    $uuid = umc_user2uuid($user);
    $chance = false;
    if ($user == 'uncovery' && isset($UMC_USER['args'][3])) {
        $chance = $UMC_USER['args'][3];
    }
    $roll = umc_lottery_roll_dice($chance);
    // umc_echo(umc_ws_vardump($roll));
    $item = $roll['item'];
    $luck = $roll['luck'];
    $prize = $lottery[$item];
    //echo "type = {$prize['type']}<br>;";
    //echo "complete chance: $chance<br>;";
    //var_dump($prize);
    if (isset($prize['detail'])) {
        $detail = $prize['detail'];
    }
    $type = $prize['type'];
    // always give 100 uncs
    umc_money(false, $user, 100);
    $given_block_data = 0;
    $given_block_type = 0;
    //var_dump($prize);
    switch ($type) {
        case 'item':
            umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_unc':
            $luck2 = mt_rand(1, 500);
            umc_money(false, $user, $luck2);
            $item_txt = "{$luck2} Uncs";
            break;
        case 'random_potion':
            $luck2 = mt_rand(0, 63);
            umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery');
            $item_txt = $prize['txt'];
            break;
        case 'random_ench':
            // pick which enchantment
            $rand_ench = array_rand($ENCH_ITEMS);
            $ench_arr = $ENCH_ITEMS[$rand_ench];
            //pick which item to enchant
            $rand_item = array_rand($ench_arr['items']);
            $rand_item_id = $ench_arr['items'][$rand_item];
            // pick level of enchantment
            $lvl_luck = mt_rand(1, $ench_arr['max']);
            //echo "$item $ench_txt $lvl_luck";
            $item_ench_arr = array($rand_ench => $lvl_luck);
            $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr);
            $item_name = $item['item_name'];
            $full = $item['full'];
            umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery');
            $item_txt = "a " . $full;
            break;
        case 'random_pet':
            // same as blocks below but only 1 always
            umc_echo($type);
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "a " . $item['full'];
            break;
        case 'random_common':
        case 'random_ore':
        case 'random_manuf':
            $block = $prize['blocks'];
            $luck2 = mt_rand(0, count($prize['blocks']) - 1);
            $luck3 = mt_rand(1, 64);
            $given_block = explode(":", $block[$luck2]);
            $given_block_type = $given_block[0];
            $given_block_data = $given_block[1];
            umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery');
            $item = umc_goods_get_text($given_block_type, $given_block_data);
            $item_txt = "{$luck3} " . $item['full'];
            break;
    }
    if ($user != 'uncovery') {
        // testing only
        $item_nocolor = umc_ws_color_remove($item_txt);
        umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole');
        umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})");
        $userlevel = umc_get_userlevel($user);
        if (in_array($userlevel, array('Settler', 'Guest'))) {
            $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!";
            umc_msg_user($user, $msg);
        }
    } else {
        umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!");
    }
    // add vote to the database
    $service = umc_mysql_real_escape_string($UMC_USER['args'][3]);
    $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]);
    $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`)\r\n        VALUES ('{$uuid}', NOW(), {$service}, {$ip});";
    umc_mysql_query($sql, true);
    // echo "$user voted for the server and got $item_txt!;";
}
function umc_ts_authorize()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $UMC_TEAMSPEAK;
    umc_ts_connect();
    // get client by name
    $uuid = $UMC_USER['uuid'];
    $userlevel = $UMC_USER['userlevel'];
    $username = strtolower($UMC_USER['username']);
    // get required servergroup
    foreach ($UMC_TEAMSPEAK['user_groups'] as $g_id => $usergroups) {
        if (in_array($userlevel, $usergroups)) {
            $target_group = $g_id;
            break;
        }
    }
    XMPP_ERROR_trace("target group", $target_group);
    umc_header();
    // first, we clean out old clients that are registered with minecraft
    umc_ts_clear_rights($uuid, true);
    XMPP_ERROR_trace("Done clearing old rights");
    // then, we try to find a new user on the TS server to give rights to
    umc_echo("Your TS level is " . $UMC_TEAMSPEAK['ts_groups'][$target_group]);
    XMPP_ERROR_trace("User TS level is ", $UMC_TEAMSPEAK['ts_groups'][$target_group]);
    umc_echo("Looking for user {$username} in TS...");
    $users = umc_ts_list_users();
    $found = 0;
    // iterate all users to make sure that there are not 2 with the same nickname
    foreach ($users as $user) {
        XMPP_ERROR_trace("comparing user {$username} to ", $user);
        if ($user == $username) {
            $found++;
            XMPP_ERROR_trace("found user ", $user);
        }
    }
    XMPP_ERROR_trace("found no if users: ", $found);
    if ($found == 0) {
        umc_echo("You need to logon to Teamspeak with the EXACT same username (\"{$username}\")");
        umc_echo("Once you did that, please try again");
        umc_footer();
        return false;
    } else {
        if ($found > 1) {
            umc_echo("There are 2 users with the same username (\"{$username}\") online.");
            umc_echo("Process halted. Make sure you are the only one with the correct username");
            umc_echo("If there is someone else hogging your username, please send in a /ticket");
            umc_footer();
            return false;
        }
    }
    // we have a user
    $ts_Client = $UMC_TEAMSPEAK['server']->clientGetByName($username);
    $ts_dbid = $ts_Client["client_database_id"];
    // remove all groups
    $servergroups = array_keys($UMC_TEAMSPEAK['server']->clientGetServerGroupsByDbid($ts_dbid));
    foreach ($servergroups as $sgid) {
        umc_echo($ts_Client["client_nickname"] . " is member of group " . $UMC_TEAMSPEAK['ts_groups'][$sgid]);
        if ($sgid != $target_group && $sgid != 8) {
            umc_echo("Removing usergroup {$sgid}...");
            $UMC_TEAMSPEAK['server']->serverGroupClientDel($sgid, $ts_dbid);
            // remove user from group
        } else {
            if ($sgid == $target_group) {
                umc_echo("Not removing usergroup {$sgid}...");
                $target_group = false;
            }
        }
    }
    // add the proper group
    if ($target_group) {
        // add target group of required
        umc_echo("Adding you to group " . $UMC_TEAMSPEAK['ts_groups'][$target_group]);
        $ts_Client->addServerGroup($target_group);
    }
    // get UUID
    $target_ts_uuid = $ts_Client["client_unique_identifier"];
    $ts_uuid = umc_mysql_real_escape_string($target_ts_uuid);
    $ins_sql = "UPDATE minecraft_srvr.UUID SET ts_uuid={$ts_uuid} WHERE UUID='{$uuid}';";
    umc_mysql_query($ins_sql, true);
    umc_echo("Adding TS ID {$ts_uuid} to database");
    umc_footer("Done!");
}
Exemple #13
0
function umc_home_import()
{
    global $UMC_USER;
    // we automatically import old homes for all players on login, but only once
    $existing_count = umc_home_count();
    if ($existing_count > 0) {
        return;
    }
    // include spyc to parse YAML https://github.com/mustangostang/spyc
    require_once '/home/includes/spyc/Spyc.php';
    $path = '/home/minecraft/server/bukkit/plugins/Essentials/userdata/' . $UMC_USER['uuid'] . ".yml";
    $A = Spyc::YAMLLoad($path);
    if (!isset($A['homes']) || count($A['homes']) == 0) {
        return;
    }
    $H = $A['homes'];
    // iterate homes and import them
    foreach ($H as $home_name => $h) {
        $name = umc_mysql_real_escape_string($home_name);
        // XMPP_ERROR_trigger($h);
        $sql = "INSERT INTO minecraft_srvr.`homes`(`name`, `uuid`, `world`, `x`, `y`, `z`, `yaw`) VALUES " . "({$name},'{$UMC_USER['uuid']}','{$h['world']}','{$h['x']}','{$h['y']}','{$h['z']}','{$h['yaw']}');";
        umc_mysql_query($sql, true);
    }
    umc_log('homes', 'import', "{$UMC_USER['uuid']}/{$UMC_USER['username']}homes have been imported!");
}
/**
 * get a userid or username from wordpress database
 *
 * @param type $query
 */
function umc_uuid_get_from_uuid_table($query)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $str_query = strtolower($query);
    $query_sql = umc_mysql_real_escape_string(strtolower($str_query));
    if (strlen($query) < 17) {
        $sel_field = 'UUID';
        $where_field = 'username';
        // get a UUID
    } else {
        $sel_field = 'username';
        $where_field = 'UUID';
    }
    // look in the wordpress database
    $sql = "SELECT {$sel_field} as output FROM minecraft_srvr.UUID\r\n        WHERE {$where_field}={$query_sql}\r\n\tLIMIT 1;";
    $data = umc_mysql_fetch_all($sql);
    if (count($data) == 1) {
        return $data[0]['output'];
    } else {
        return false;
    }
}