/**
 *  This function displays the proposals the user has not voted on yet. It's displayed on user login
**/
function umc_vote_get_votable($username = false, $web = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_DOMAIN, $vote_ranks, $UMC_USER;
    $out = '';
    if (!$username) {
        $username = $UMC_USER['username'];
        $uuid = $UMC_USER['uuid'];
    } else {
        $uuid = umc_uuid_getone($username, 'uuid');
    }
    if (!$username && !isset($UMC_USER['username'])) {
        XMPP_ERROR_trigger("websend player undidentified");
    }
    $user_lvl = umc_get_userlevel($username);
    $user_lvl_id = $vote_ranks[$user_lvl]['lvl'];
    if ($user_lvl_id < 3) {
        // start voting only for designers
        return;
    }
    $sql = "SELECT proposals.pr_id, proposals.uuid, proposals.date, 60 - DATEDIFF(NOW(), proposals.date) as remainder, UUID.username as username FROM minecraft_srvr.proposals\r\n        LEFT JOIN minecraft_srvr.proposals_votes ON proposals.pr_id=proposals_votes.pr_id AND voter_uuid='{$uuid}'\r\n        LEFT JOIN minecraft_srvr.UUID ON proposals.uuid=UUID.UUID\r\n        WHERE proposals_votes.pr_id IS NULL AND status='voting' ORDER BY proposals.`date` ASC";
    $D = umc_mysql_fetch_all($sql);
    $no_votes = array();
    // echo $sql;
    foreach ($D as $row) {
        $proposal = $row['uuid'];
        $proposal_username = $row['username'];
        $prop_lvl = umc_get_uuid_level($proposal);
        $prop_lvl_id = $vote_ranks[$prop_lvl]['lvl'];
        if ($prop_lvl_id < $user_lvl_id) {
            $days_left = $row['remainder'];
            $no_votes[$proposal_username] = $days_left;
        }
    }
    if (count($no_votes) > 0) {
        if ($web) {
            $out .= "<strong><a href=\"{$UMC_DOMAIN}/vote-for-users/\">Please vote</a>:</strong> (" . count($no_votes) . ") ";
            foreach ($no_votes as $proposee => $days) {
                $out .= "{$proposee}, ";
            }
            $out = rtrim($out, ", ");
            return $out;
        } else {
            umc_header('Your missing votes: (days remaining)', true);
            foreach ($no_votes as $proposee => $days) {
                $out .= "{red}{$proposee} {grey}({$days}){white}, ";
            }
            umc_echo($out, true);
            umc_echo("{gold}Please vote ASAP! Only YOU can determine the future of the server! {$UMC_DOMAIN}/vote-for-users/", true);
            umc_footer(true);
        }
    } else {
        return false;
    }
}
function umc_money_give()
{
    global $UMC_USER;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    if (!isset($args[2])) {
        umc_error('You need to enter the user to give money to!');
    } else {
        if (strtolower($args[2]) == strtolower($player)) {
            umc_error('You cannot give money to yourself!');
        }
    }
    if (!isset($args[3])) {
        umc_error('You need to enter amount of money!');
    } else {
        if ($args[3] <= 0) {
            umc_error('You will need to give more than that!');
        }
    }
    $target = umc_sanitize_input($args[2], 'player');
    $sum = umc_sanitize_input($args[3], 'price');
    $check = umc_money($player, $target, $sum);
    if ($check) {
        umc_error('The transaction failed! Make sure that the target user exists');
    } else {
        umc_echo("You successfully transferred {$sum} Uncs to {$target}");
    }
    // get UUID or target player
    $target_uuid = umc_user2uuid($target);
    // check if the user is online
    if (isset($UMC_USER['player_data'][$target_uuid])) {
        umc_msg_user($target, "You just received {$sum} Uncs from {$player}!");
        umc_echo("The recipient is online, the server sent a notification message.");
    } else {
        // otherwise, send an email
        $title = "You received {$sum} Uncs from {$player}!";
        $message = "Dear {$target},\nyou just received {$sum} Uncs from {$player}.\n" . "The amount in in your account now.\n" . "Use /money check to see your account balance.\n";
        umc_mail_quick_send($title, $message, $target_uuid, false);
        umc_echo("The recipient is currently offline, the server sent a notification email.");
    }
    umc_log('money', 'give', "{$player} gave {$target} {$sum} Uncs");
    umc_money_status();
}
/**
 * Buy XP in-game // function is still working with usernames instead of UUID since
 * the /xp command does not work with UUIDs (yet) *
 *
 * @global type $UMC_USER
 */
function umc_do_buyxp()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $xp_ratio = 1;
    // check to see if player has entered a value of xp to buy
    if (isset($args[2])) {
        // feedback on current xp point values
        $user_xp = $UMC_USER['xp'];
        umc_echo("{white} You started with {$user_xp} experience points.");
        // amount player is trying to spend
        $amount = $args[2];
        // cast argument to type int to sanitise the data
        settype($amount, 'int');
        // amount of xp calculated
        $xp = floor($amount * $xp_ratio);
        // retrieve the players balance to check if they can afford
        $balance = umc_money_check($player);
        if ($xp < 1 || $amount < 1) {
            umc_error("{red}You need to buy at least 1 XP. For {$amount} Uncs you get only {$xp} XP (ratio is {$xp_ratio}!)");
        }
        if ($amount > $balance) {
            umc_error("{red}Sorry, you cannot afford this purchase. You currently have {$balance} uncs.");
        }
        // calculate the total new xp point value
        $new_xp = $user_xp + $xp;
        // apply purchase
        // send the console command to give the player experience
        umc_ws_cmd("exp set {$player} {$new_xp}", 'asConsole');
        // take the purchase amount from players account.
        // take from, give to, positive value
        umc_money($player, false, $amount);
        // announce the purchase to encourage players to consider buying xp
        umc_announce("{gold}{$player}{gray} just bought {purple}{$xp} XP{gray} for{cyan} {$amount} Uncs{gray}!");
        umc_echo("{white} You ended with {$new_xp} experience points.");
        // log the purchase
        umc_log('buyxp', 'buy', "{$player} paid {$amount} for {$xp} XP, going from {$user_xp} to {$new_xp}");
    } else {
        umc_error("{red}You need to specify the amount of Uncs you want to spend. See {yellow}/helpme buyxp");
    }
}
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);
}
Example #5
0
function umc_depositbox_consolidate()
{
    global $UMC_USER;
    $uuid = $UMC_USER['uuid'];
    // find all doupliecate entries
    $sql_doubles = " SELECT count(id) AS counter, item_name, damage, meta\r\n        FROM minecraft_iconomy.deposit\r\n        WHERE recipient_uuid='{$uuid}'\r\n        GROUP BY item_name, damage, meta HAVING COUNT(id) > 1";
    $doubles = umc_mysql_fetch_all($sql_doubles);
    $source_boxes = count($doubles);
    $target_boxes = 0;
    if ($source_boxes > 0) {
        foreach ($doubles as $row) {
            // then we take each entry that is not created by the user and move it to a box created by the user
            $sql_fix = "SELECT * FROM minecraft_iconomy.deposit\r\n                WHERE item_name='{$row['item_name']}'\r\n\t\t    AND damage='{$row['damage']}\r\n\t\t    AND meta='{$row['meta']}\r\n\t\t    AND recipient_uuid='{$uuid}'\r\n\t\t    AND sender_uuid !='{$uuid}';;";
            $fix_data = umc_mysql_fetch_all($sql_fix);
            if (count($fix_data) > 0) {
                $target_boxes++;
                foreach ($fix_data as $fix_row) {
                    umc_db_take_item('deposit', $fix_row['id'], $fix_row['amount'], $uuid);
                    umc_deposit_give_item($uuid, $fix_row['item_name'], $fix_row['damage'], $fix_row['meta'], $fix_row['amount'], $uuid);
                }
            }
        }
    }
    if ($source_boxes > 0) {
        umc_echo("{green}[+]{gray} Found {yellow}{$source_boxes}{gray} items spread over several boxes consolidated them to {$target_boxes} deposit boxes!.");
    } else {
        umc_echo("{yellow}[?]{gray} Unable to consolidate depositbox, no compatible items found.");
    }
}
/**
 * Create a request
 *
 * @global type $UMC_USER
 * @return type
 */
function umc_do_request()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    // this returns a item_array already
    $item_check = umc_sanitize_input($args[2], 'item');
    if (!$item_check) {
        umc_error("{red}Unknown item ({yellow}{$args['2']}{red}). Try using {yellow}/search{red} to find names.");
    } else {
        XMPP_ERROR_trace("item_check", $item_check);
        $item = umc_goods_get_text($item_check['item_name'], $item_check['type']);
    }
    $item_name = $item['item_name'];
    $type = $item['type'];
    $meta = '';
    $meta_txt = '';
    $do_check = false;
    $pos = array_search('check', $args);
    if ($pos) {
        $do_check = true;
        array_splice($args, $pos, 1);
    }
    // TODO: This should be checking for the item type instead of assuming 0
    //if ($UMC_ITEMS[$type][0]['avail'] == false) {
    //    umc_error("{red}Sorry, this item (ID $type) is unavailable in the game!",true);
    //}
    $sql = "SELECT * FROM minecraft_iconomy.request\r\n        WHERE item_name='{$item_name}' AND damage='{$type}' AND meta='{$meta}' AND uuid='{$uuid}';";
    $sql_data = umc_mysql_fetch_all($sql);
    if (count($sql_data) == 0) {
        $row = false;
    } else {
        $row = $sql_data[0];
    }
    // buy item at same price, check if exists
    if (!isset($args[3])) {
        if ($row) {
            $price = $row['price'];
        } else {
            umc_error("{red}Since you do not have the same item already in the shop you need to specify a price.;");
        }
    } else {
        $price = umc_sanitize_input($args[3], 'price');
    }
    // check if an argument was given for amount.
    $amount = umc_sanitize_input($args[4], 'amount');
    if ($amount == NULL) {
        // buying 0 amount available is not possible
        umc_error("{red}You need to specify an amount, too!;");
    }
    $cost = $price * $amount;
    // if there is an existing row, recalculate price accordingly
    if ($row) {
        // give money back from the original request
        $refund = $row['amount'] * $row['price'];
        // calculate how much this one + the old item amount would cost
        $new_cost = ($amount + $row['amount']) * $price;
        // do the sum for the balance, can be negative
        $cost = $new_cost - $refund;
    }
    $balance = umc_money_check($uuid);
    if ($balance < $cost) {
        umc_error("{red}[!]{gray} Insufficient funds ({white}{$cost}{gray} needed). " . "{purple}[?]{white} Why don't you vote for the server and try again?");
    }
    if ($do_check) {
        if ($row) {
            $sum = $amount + $row['amount'];
            umc_echo("{white}[?]{gray} This would update your existing request to " . "{yellow}{$sum} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each.");
        } else {
            umc_echo("{white}[?]{gray} This would create a new request for " . "{yellow}{$amount} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each.");
        }
        if ($cost > 0) {
            umc_echo("{white}[?]{white} Your account would be charged {cyan}{$cost}{gray} Uncs.");
        } else {
            umc_echo("{white}[?]{white} Your account would be credited {cyan}" . $cost * -1 . "{gray} Uncs.");
        }
        return;
    }
    $sum = 0;
    $posted_id = 0;
    if ($row) {
        // Update existing listing
        $sum = $amount + $row['amount'];
        umc_echo("{green}[+]{gray} You already requested {yellow}" . "{$row['amount']} {$item['full']}{gray}. Adding another {yellow}{$amount}{gray}.");
        $sql = "UPDATE minecraft_iconomy.`request` SET `amount` = amount + '{$amount}', price='{$price}' WHERE id={$row['id']};";
        $rst = umc_mysql_query($sql);
        $posted_id = $row['id'];
    } else {
        // Create a new listing.
        $sum = $amount;
        umc_echo("{green}[+]{gray} You are now requesting {yellow}" . "{$sum} {$item['full']}{gray} in the shop.");
        $sql = "INSERT INTO minecraft_iconomy.`request` (`id` ,`damage` ,`uuid` ,`item_name` ,`price` ,`amount` ,`meta`)\r\n                VALUES (NULL , '{$type}', '{$uuid}', '{$item['item_name']}', '{$price}', '{$amount}', '{$meta}');";
        //XMPP_ERROR_trigger($sql);
        $rst = umc_mysql_query($sql);
        $posted_id = umc_mysql_insert_id();
    }
    if ($cost > 0) {
        umc_echo("{yellow}[\$]{white} Your account has been charged {cyan}{$cost}{gray} Uncs.");
    } else {
        umc_echo("{green}[\$]{white} Your account has been credited {cyan}" . $cost * -1 . "{gray} Uncs.");
    }
    umc_money($player, false, $cost);
    umc_announce("{gold}{$player}{gray} is {red}requesting to buy {yellow}{$sum}{$meta_txt}{green} " . "{$item['full']}{darkgray} @ {cyan}{$price}{gray} each{darkgray}, shop-id {gray}{$posted_id}");
}
function umc_hardcore_score()
{
    $C = umc_hardcore_get_period();
    // query all scores inbetween the two dates
    $sql = "SELECT username, score FROM minecraft_srvr.hardcore\r\n        LEFT JOIN minecraft_srvr.UUID ON hardcore.UUID=UUID.UUID\r\n        WHERE entry_date >= '{$C['start_date']}' AND entry_date < '{$C['end_date']}'\r\n        ORDER BY score DESC;";
    $D = umc_mysql_fetch_all($sql);
    umc_header("Hardcore Game score week {$C['number']}");
    $i = 1;
    foreach ($D as $d) {
        umc_echo("{yellow}{$i} {white}{$d['username']}{gray}: {$d['score']}");
        $i++;
    }
    umc_footer();
}
function umc_sanitize_input(&$value, $type)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $MAX_UNCS = 10000;
    $MIN_UNCS = 1.0E-5;
    if ($type == "price") {
        # Check that this is a number
        # Check that it is greater than zero
        # Check bounds
        if (!is_numeric($value)) {
            umc_error("{red}Invalid amount of uncs ({yellow}{$value}{red}), must be a number.");
        } elseif ($value < $MIN_UNCS) {
            umc_error("{red}Invalid amount of uncs ({yellow}{$value}{red}), must be at least {yellow}{$MIN_UNCS}{red}.");
        } elseif ($value > $MAX_UNCS) {
            umc_error("{red}Invalid amount of uncs ({yellow}{$value}{red}), cannot be more than {yellow}{$MAX_UNCS}{red}.");
        } else {
            return $value;
        }
    }
    if ($type == "amount") {
        if ($value == NULL) {
            // buying all available
            return NULL;
        }
        if (!is_numeric($value)) {
            umc_error("{red}Invalid amount ({yellow}{$value}{red}), must be an integer.");
        } elseif (intval($value) < 1) {
            umc_error("{red}Invalid amount ({yellow}{$value}{red}), must be at least 1.");
        } else {
            return intval(abs($value));
        }
    }
    if ($type == "player") {
        $player = umc_check_user($value);
        if (!$player) {
            umc_error("{red}Invalid player name ({yellow}{$value}{red}), no such player.");
        } else {
            return $player;
        }
    }
    if ($type == "item") {
        // get a list of all possible item names. REquires exact match of the searched item
        $all_names = umc_item_data_get_namelist();
        if (isset($all_names[$value])) {
            return $all_names[$value];
        } else {
            // we searched only for the EXACT item above. We should be looking for possible matches in the
            // search database too.
            global $ITEM_SEARCH;
            if (isset($ITEM_SEARCH[$value])) {
                return $ITEM_SEARCH[$value];
            }
            return false;
        }
    }
    if ($type == "table") {
        if (isset($value[2]) && ($value[2] == 'request' || $value[2] == 'req' || $value[2] == 'r')) {
            return 'request';
        } elseif (isset($value[2]) && ($value[2] == 'offer' || $value[2] == 'off' || $value[2] == 'o')) {
            return 'stock';
        } else {
            array_splice($value, 2, 0, 'offer');
            umc_echo("{yellow}[!]{gray} Didn't specify {yellow}request{gray} or {yellow}offer{gray}, assuming {yellow}offer", true);
            return 'stock';
        }
    }
    if ($type == "lot") {
        $check = !preg_match('/[^A-Za-z0-9_.#\\-$]/', $value);
        if (!$check) {
            umc_error('You need to enter a valid lot name such as "emp_a1"');
        } else {
            return $value;
        }
    }
    if ($type == "meta") {
        $meta_name = umc_parse_meta_input($value);
        if (is_null($meta_name)) {
            umc_error("Unknown Metavalue name: {white}{$value}");
        } else {
            return $meta_nam;
        }
    }
}
Example #9
0
function umc_hunger_format_player_list($prefix, $player_list)
{
    $cnt = 0;
    $list_text = "{$prefix}";
    XMPP_ERROR_trace("check", var_export($player_list, true));
    foreach ($player_list as $status => $player_data) {
        $list_text = "{green}{$status}:{$prefix} ";
        $inner = '';
        foreach ($player_data as $uuid => $player) {
            if ($cnt % 5 == 0 && $cnt > 0) {
                $inner = ";{$prefix}";
            }
            if ($cnt == sizeof($player_list)) {
                $list_text .= " and {$player}";
            } else {
                if ($cnt == 0) {
                    $list_text .= "{$player}";
                } else {
                    $list_text .= ", {$inner}{$player}";
                }
            }
            $cnt++;
        }
    }
    umc_echo($list_text);
}
function umc_skyblock_challenge_serialize_inv()
{
    global $UMC_USER;
    $inv = $UMC_USER['inv'];
    umc_echo("Done!");
}
function umc_contests_join()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    $player = $UMC_USER['username'];
    $debug = true;
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    }
    $id = $args[2];
    umc_pretty_bar("darkblue", "-", "{darkcyan} Joining contest {$id} ");
    if (!is_numeric($id)) {
        umc_error("You have to enter a numeric contest ID ({$id}). See /contest list");
    }
    // find out if the contest is creative or survival
    $sql = "SELECT * FROM minecraft_srvr.contest_contests WHERE id = {$id};";
    $rst = mysql_query($sql);
    $contest = mysql_fetch_array($rst, MYSQL_ASSOC);
    $status = $contest['status'];
    if ($status !== 'active') {
        umc_error("Contest number {$id} is not active. Please chose a different contest!");
    }
    $min = array('aether' => array('x' => -1532, 'z' => -1532, 'y' => 11, 'parent' => 'aet_p1'), 'flatlands' => array('x' => 1028, 'z' => 1028, 'y' => 64, 'parent' => 'flat_b19'));
    $max = array('aether' => array('x' => -1157, 'z' => -1157, 'y' => 255), 'flatlands' => array('x' => 1275, 'z' => 1275, 'y' => 255));
    $gap = 4;
    $type = 'survival';
    $world = 'aether';
    if ($contest['type'] == 'creative') {
        $type = 'creative';
        $world = 'flatlands';
    }
    $parent = $min[$world]['parent'];
    $min_coords = $min[$world];
    $min_x = $min_coords['x'];
    $min_z = $min_coords['z'];
    $min_y = $min_coords['y'];
    if ($debug) {
        umc_echo("Min coords are {$min_x}/{$min_y}/{$min_z}");
    }
    $max_coords = $max[$world];
    $max_x = $max_coords['x'];
    $max_z = $max_coords['z'];
    $max_y = $max_coords['y'];
    if ($debug) {
        umc_echo("MAx coords are {$max_x}/{$max_y}/{$max_z}");
    }
    $user_id = umc_get_worldguard_id('user', strtolower($player));
    $world_id = umc_get_worldguard_id('world', strtolower($world));
    // find out if the user can have additional contest entries in this contest
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        LEFT JOIN minecraft_worldguard.region_players ON region_cuboid.region_id=region_players.region_id\r\n        WHERE world.name='{$world}' AND region.id LIKE 'con_" . $id . "%' AND user_id={$user_id} AND Owner=1\r\n        ORDER BY max_z, max_x";
    $rst = mysql_query($sql);
    $count = mysql_num_rows($rst);
    if ($count >= $contest['max_entries'] && $player != 'uncovery') {
        umc_error("You have reached the max number of entries for this contest!;");
    }
    // find out if a contest lot already exists
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        WHERE world.name='{$world}' AND region.id LIKE 'con%' ORDER BY max_z, max_x";
    $rst = mysql_query($sql);
    $count = mysql_num_rows($rst);
    if ($debug) {
        umc_echo("{$count} entries already entered!");
    }
    $lotnumber = $count + 1;
    $lot = 'con_' . $id . '_' . $lotnumber;
    if ($debug) {
        umc_echo("Trying to create entry {$lot}");
    }
    // how many lots can I fit into the space across?
    $fullwidth = $max_x - $min_x;
    if ($debug) {
        umc_echo("Lot width is {$fullwidth}");
    }
    $single_width = $contest['x'] + $gap;
    if ($debug) {
        umc_echo("One lot (with gap) is {$single_width} wide");
    }
    $width_lots = floor($fullwidth / $single_width);
    if ($debug) {
        umc_echo("Fitting {$width_lots} per line");
    }
    $fulldepth = $max_z - $min_z;
    $single_depth = $contest['z'] + $gap;
    if ($debug) {
        umc_echo("One lot (with gap) is {$single_depth} deep");
    }
    $depth_lots = floor($fulldepth / $single_depth);
    if ($debug) {
        umc_echo("Fitting {$depth_lots} per row");
    }
    $full_lines = floor($count / $width_lots);
    if ($debug) {
        umc_echo("{$full_lines} lines already full");
    }
    $lastline_lots = $count - $full_lines * $width_lots;
    if ($debug) {
        umc_echo("Last line has {$lastline_lots} lots");
    }
    $start_x = $lastline_lots * ($contest['x'] + $gap) + $min_coords['x'];
    $start_z = $full_lines * ($contest['z'] + $gap) + $min_coords['z'];
    $start_y = $min_coords['y'];
    if ($debug) {
        umc_echo("Starting coords are {$start_x}/{$start_y}/{$start_z}");
    }
    $end_x = $start_x + $contest['x'] - 1;
    $end_z = $start_z + $contest['z'] - 1;
    $end_y = $min_coords['y'] + $contest['y'] - 1;
    if ($debug) {
        umc_echo("End coords are {$end_x}/{$end_y}/{$end_z}");
    }
    if ($end_x > $max_x || $end_z > $max_z) {
        umc_error('There is no more space for additional contest entries!;');
    }
    umc_echo("New lot {gold}{$lot}{white} in {gold}{$world}{white} was created at ");
    umc_echo("coordinates {gold}{$start_x}/{$start_y}/{$start_z}{white} - {gold}{$end_x}/{$end_y}/{$end_z}{white};");
    umc_echo("Use {gold}/contest warp {$id} {$lotnumber}{white} to get there.");
    // create insert SQL 	id 	world_id 	type 	priority 	parent
    $ins_region_sql = "INSERT INTO region (id, world_id, type, priority, parent)\r\n        VALUES ('{$lot}', {$world_id}, 'cuboid', 0, '{$parent}');";
    $ins_region_rst = mysql_query($ins_region_sql);
    // insert cuboid region_id 	world_id 	min_x 	min_y 	min_z 	max_x 	max_y 	max_z
    $ins_cuboid_sql = "INSERT INTO region_cuboid (region_id, world_id, min_x, min_y, min_z, max_x, max_y, max_z)\r\n        VALUES ('{$lot}', {$world_id}, {$start_x}, {$start_y}, {$start_z}, {$end_x}, {$end_y}, {$end_z});";
    $ins_cuboid_rst = mysql_query($ins_cuboid_sql);
    // add user to lot as Owner  region_id 	world_id 	user_id 	Owner
    $ins_user_sql = "INSERT INTO region_players (region_id, world_id, user_id, Owner)\r\n        VALUES ('{$lot}', {$world_id}, {$user_id}, 1);";
    $inc_user_rst = mysql_query($ins_user_sql);
    umc_ws_cmd("region load -w {$world}", 'asConsole');
    umc_footer();
}
Example #12
0
/**
 * Reset TS user rights to "Guest" for a specific user
 * This can be done even if the user is not online
 * 
 * @param string $uuid
 * @param boolean $echo
 * @return boolean
 */
function umc_ts_clear_rights($uuid, $echo = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    umc_echo("Trying to remove old permissions:");
    require_once '/home/includes/teamspeak_php/libraries/TeamSpeak3/TeamSpeak3.php';
    global $UMC_TEAMSPEAK;
    // find out the TS id the user has been using from the database
    $check_sql = "SELECT ts_uuid FROM minecraft_srvr.UUID WHERE UUID='{$uuid}';";
    $D = umc_mysql_fetch_all($check_sql);
    if ($D[0]['ts_uuid'] == '') {
        if ($echo) {
            umc_echo("Old Client: No previous TS account detected.");
        }
        return false;
    } else {
        umc_echo("Found old permissions.");
        $ts_uuid = $D[0]['ts_uuid'];
    }
    umc_echo("Connecting to TS server.");
    if (!$UMC_TEAMSPEAK['server']) {
        $UMC_TEAMSPEAK['server'] = TeamSpeak3::factory("serverquery://*****:*****@74.208.45.80:10011/?server_port=9987");
    }
    // find the TS user by that TS UUID
    umc_echo("Searching for you on the TS server.");
    $ts_Clients_match = $UMC_TEAMSPEAK['server']->clientFindDb($ts_uuid, true);
    if (count($ts_Clients_match) > 0) {
        umc_echo("Found user entries on TS server");
        $client_dbid = $ts_Clients_match[0];
        // enumerate all the groups the user is part of
        $servergroups = array_keys($UMC_TEAMSPEAK['server']->clientGetServerGroupsByDbid($client_dbid));
        // remove all servergroups except 8 (Guest)
        umc_echo("Removing all old usergroups:");
        foreach ($servergroups as $sgid) {
            if ($sgid != 8) {
                $UMC_TEAMSPEAK['server']->serverGroupClientDel($sgid, $client_dbid);
                if ($echo) {
                    umc_echo("Old Client: Removing Group " . $UMC_TEAMSPEAK['ts_groups'][$sgid]);
                }
            }
        }
        // also remove TS UUID from DB
        $ins_sql = "UPDATE minecraft_srvr.UUID SET ts_uuid='' WHERE ts_uuid='{$ts_uuid}';";
        umc_mysql_query($ins_sql, true);
        return true;
    } else {
        if ($echo) {
            umc_echo("Old Client: Previous TS UUID was invalid, nothing to do");
        }
        return false;
    }
}
/**
 * Sends an error message to the user
 * Terminates  with a ;
 *
 * @param $message to send
 */
function umc_error($message, $silent = false)
{
    umc_pretty_bar('red', '-', ' ERROR ', 52);
    umc_echo($message, $silent);
    umc_pretty_bar('red', '-', '', 52);
    die('umc_error');
}
Example #14
0
function umc_mail_list()
{
    global $UMC_USER;
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    $folders = array('inbox', 'outbox', 'trash');
    if (isset($args[2]) && !in_array($args[2], $folders)) {
        umc_error("You need to chose one of the folders {green}inbox{white}, {green}outbox{white} or {green}trash{white}");
    }
    if (!isset($args[2])) {
        $folder = "All folders";
        $filter = 'all';
        $no_mail = "You have no emails";
    } else {
        $folder = "Folder " . ucwords($args[2]);
        $filter = $args[2];
        $no_mail = "You have no emails in {$folder}";
    }
    umc_header("Uncovery Mail {$folder}");
    $status_arr = array('all' => "(recipient_uuid='{$uuid}' AND status NOT IN ('deleted_recipient','deleted_both')) OR (sender_uuid='{$uuid}' AND status NOT IN ('deleted_sender','deleted_both'))", 'inbox' => "recipient_uuid='{$uuid}' AND (status='sent' OR status='read')", 'outbox' => "sender_uuid='{$uuid}' AND (status='sent')", 'trash' => "(recipient_uuid='{$uuid}' AND status IN ('deleted_recipient','deleted_both')) OR (sender_uuid='{$uuid}' AND status IN ('deleted_sender','deleted_both'))");
    $sql_filter = $status_arr[$filter];
    $sql = "SELECT * FROM minecraft_srvr.`user_mail` WHERE {$sql_filter} ORDER BY date_time ASC;";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) == 0) {
        umc_echo("No emails in this mailbox");
        umc_footer();
        return;
    }
    foreach ($D as $row) {
        if ($row['sender_uuid'] == $uuid) {
            $recipient = umc_user2uuid($row['recipient_uuid']);
            $wholine = "{red}->{white}{$recipient}";
            if ($row['status'] == 'sent') {
                $folder = 'Outbox';
            } else {
                if (strstr($row['status'], 'deleted')) {
                    $folder = 'Trash';
                } else {
                    if ($row['status'] == 'draft') {
                        $folder = 'Draft';
                    }
                }
            }
        } else {
            $sender = umc_user2uuid($row['sender_uuid']);
            $wholine = "{$sender}{red}->{white}";
            if ($row['status'] == 'read') {
                $folder = 'Inbox';
            } else {
                if (strstr($row['status'], 'deleted')) {
                    $folder = 'Trash';
                } else {
                    if ($row['status'] == 'sent') {
                        $folder = 'Unread';
                    }
                }
            }
        }
        umc_echo("{green}#{$row['msg_id']} {yellow}{$folder}{grey} {$row['date_time']}{white} {$wholine}: {$row['title']}");
    }
    umc_footer();
}
Example #15
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!;";
}
Example #16
0
function umc_show_help($args = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $WS_INIT;
    $player = $UMC_USER['username'];
    $userlevel = umc_get_userlevel($player);
    if ($args) {
        // if show_help is called from another program, we simulate a /help command being issued.
        $args = array_merge(array('call'), $UMC_USER['args']);
    } else {
        $args = $UMC_USER['args'];
    }
    $command = false;
    $command_name = '';
    $plugin_name = '';
    if (isset($args[1])) {
        $command = umc_wsplg_find_command($args[1]);
        $command_name = $args[1];
    }
    // If we have a help query, a command name, but it didn't match any known commands
    if ($args[0] == 'help' && $command_name && !$command) {
        umc_error("{white}Action {green}{$command_name}{white} not recognized, try {yellow}/helpme");
    }
    umc_header('Uncovery Help', true);
    umc_echo("{gray}   <..> = mandatory   [..] = optional   {ro} = request or offer", true);
    $non_commands = array('default', 'events', 'disabled');
    if ($command_name) {
        if (isset($command['help']['title'])) {
            // This is a 'default' listing
            umc_pretty_bar("darkblue", "-", "{darkcyan}" . $command['help']['title'], 52, true);
            umc_echo($command['help']['long'], true);
            foreach ($WS_INIT[$command_name] as $cmd => $cmd_data) {
                if (!in_array($cmd, $non_commands)) {
                    // This command is restricted to a user level or higher
                    if (isset($cmd_data['security']['level']) && $player != 'uncovery') {
                        if (!umc_rank_check($userlevel, $cmd_data['security']['level'])) {
                            continue;
                        }
                    }
                    if (!isset($cmd_data['top']) || !$cmd_data['top']) {
                        $plugin_name = $command_name . ' ';
                    }
                    $command_args = '';
                    if (isset($cmd_data['help']['args'])) {
                        $command_args = "{yellow}" . $cmd_data['help']['args'];
                    }
                    umc_echo("{green}/{$plugin_name}{$cmd} {$command_args}{gray} => {white}" . $cmd_data['help']['short'], true);
                }
            }
        } else {
            if (isset($command)) {
                // sub-command help
                if (!isset($command['top']) || !$command['top']) {
                    $plugin_name = $command_name . ' ';
                }
                $args_str = '';
                if (isset($command['help']['args'])) {
                    $args_str = "{yellow}" . $command['help']['args'];
                }
                umc_echo("{green}/{$plugin_name}{$command_name} {$args_str}{gray} => {white}" . $command['help']['short'], true);
                umc_pretty_bar("darkgray", "-", "", 49, true);
                foreach (split(';', $command['help']['long']) as $line) {
                    if ($line != '') {
                        umc_echo($line, true);
                    }
                }
            } else {
                umc_echo("{white}No help found for command {red}/{$args[1]} {$args[2]}{white}.", true);
                // umc_show_help($args);
                // umc_echo("{white}Try {yellow}/helpme {$args[1]}{white} to see valid commands.", true);
            }
        }
    } else {
        // Show general help.
        foreach ($WS_INIT as $plugin => $cmd_data) {
            // This command is restricted to a user level or higher
            if (isset($cmd_data['default']['security']['level']) && $player != 'uncovery') {
                if (!umc_rank_check($userlevel, $cmd_data['default']['security']['level'])) {
                    continue;
                }
            }
            umc_echo("{green}/{$plugin}{gray} - " . $cmd_data['default']['help']['short'], true);
        }
        umc_echo("{gray}Use {yellow}/helpme <command>{gray} for more details.", true);
    }
    umc_footer(true);
    return true;
}
function umc_ticket_new()
{
    global $WSEND;
    $player = $WSEND['player'];
    $player_email = umc_user_email($player);
    $player_id = umc_user_id($player);
    $devOptions = umc_ticket_options();
    $args = $WSEND['args'];
    if (!isset($args[1])) {
        umc_show_help($args);
    }
    array_shift($args);
    array_shift($args);
    $text = trim(implode(' ', $args));
    if (stristr($text, 'have a problem') || strlen($text) < 8) {
        umc_error("You need to specify the problem better!");
    }
    $sql_text = mysql_real_escape_string($text);
    $wpscst_title = base64_encode(strip_tags($text));
    $wpscst_initial_message = base64_encode($text);
    $wpscst_department = base64_encode(strip_tags('in-game'));
    $sql = "\r\n    INSERT INTO minecraft.`wp_wpscst_tickets` (\r\n        `primkey`, `title`, `initial_message`, `user_id`, `email`, `assigned_to`, `severity`, `resolution`,\r\n        `time_posted`, `last_updated`, `last_staff_reply`, `target_response_time`, `type`) VALUES (\r\n            NULL,\r\n            '{$wpscst_title}',\r\n            '{$wpscst_initial_message}',\r\n            '{$player_id}',\r\n            '{$player_email}',\r\n            '0',\r\n            'Normal',\r\n            'Open',\r\n            '" . current_time('timestamp') . "',\r\n            '" . current_time('timestamp') . "',\r\n            '',\r\n            '2 days',\r\n            '{$wpscst_department}'\r\n        );\r\n    ";
    $rst = mysql_query($sql);
    $lastID = mysql_insert_id();
    // user email
    $to = $player_email;
    // Send this to the ticket creator
    $subject = $devOptions['email_new_ticket_subject'] . " Ticket ID [{$lastID}]";
    $message = $devOptions['email_new_ticket_body'] . "\r\nTicket contents: \r\n{$text}";
    $headers = 'From: ' . $devOptions['email'] . "\r\n" . 'Reply-To: ' . $devOptions['email'] . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
    // admin email
    $to = $devOptions['email'];
    // Send this to the admin^M
    $subject = __("[Uncovery Minecraft] New Ticket from {$player}", 'wpsc-support-tickets');
    $message = __("New Ticket [{$lastID}] from {$player}:\r\n" . $text . "\r\n", 'wpsc-support-tickets') . get_admin_url() . 'admin.php?page=wpscSupportTickets-edit&primkey=' . $lastID . "\r\n" . var_dump($devOptions);
    $headers = 'From: ' . $player_email . "\r\n" . 'Reply-To: ' . $player_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    mail($to, $subject, $message, $headers);
    umc_pretty_bar('red', '-', ' Help Ticket Created ', $width = 52);
    umc_echo('Your question:');
    umc_echo("{yellow}{$text}");
    umc_echo('You also received an email. Please check your inbox.');
    umc_pretty_bar('red', '-', '', $width = 52);
}
function umc_lot_warp()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $userlevel = $UMC_USER['userlevel'];
    $world = $UMC_USER['world'];
    $args = $UMC_USER['args'];
    $allowed_ranks = array('Owner', 'Guest');
    if (!in_array($userlevel, $allowed_ranks)) {
        umc_error("Sorry, this command is only for Guests!");
    }
    $allowed_worlds = array('empire', 'flatlands');
    if (!in_array($world, $allowed_worlds)) {
        umc_error('Sorry, you need to be in the Empire or Flatlands to warp!');
    } else {
        $lot = strtolower(umc_sanitize_input($args[2], 'lot'));
        // the above one fails already if the lot is not a proper lot
        $target_world = umc_get_lot_world($lot);
        if (!in_array($target_world, $allowed_worlds)) {
            umc_error('Sorry, you need to be in the Empire or Flatlands to warp!');
        }
        if ($target_world != $world) {
            umc_error("Sorry, you need to be in {$target_world} to warp to {$lot}!");
        }
    }
    $sql = "SELECT * FROM minecraft_worldguard.world LEFT JOIN minecraft_worldguard.region ON world.id=region.world_id\r\n        LEFT JOIN minecraft_worldguard.region_cuboid ON region.id=region_cuboid.region_id\r\n        WHERE world.name='{$target_world}' AND region.id = '{$lot}' ";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) != 1) {
        umc_error("There was an error teleporting you to your lot, the admin was notified, please wait for it to be fixed!");
    }
    $lots = $D[0];
    $c_x = $lots['min_x'] + 64;
    $c_z = $lots['min_z'] + 64;
    $c_y = 256;
    $cmd = "tppos {$player} {$c_x} {$c_y} {$c_z} 0";
    umc_ws_cmd($cmd, 'asConsole');
    umc_pretty_bar("darkblue", "-", "{darkcyan} Warping to lot {$lot}");
    umc_echo("You are now in the center of lot {$lot}!");
    umc_footer();
}
Example #19
0
function umc_info_settler()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    $players = $UMC_USER['online_players'];
    if (isset($args[2]) && in_array($args[2], $players)) {
        $cmd = "msg {$args[2]} Dear {$args[2]}, welcome to Uncovery Minecraft! " . "You have so far only gotten Guest-status to look around. If you want to start building,; please click here http://bit.ly/1GUDhgg and follow the instructions!";
        umc_ws_cmd($cmd, 'asPlayer');
    } else {
        umc_echo("You have to name an online user to receive the message");
    }
}
function umc_vanity_set()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $userlevel = umc_get_userlevel($player);
    // umc_echo("$userlevel");
    if (!isset($args[2]) || !is_numeric($args[2]) || $args[2] < 1) {
        umc_error("{red}You need to specify a number of days");
    } else {
        if (!isset($args[3])) {
            umc_error("{red}You need to specify the title you want to have. See {yellow}/helpme vanity");
        }
    }
    $days = $args[2];
    $vanity_raw = '';
    // concatenate all into a string
    for ($i = 3; $i < count($args); $i++) {
        $vanity_raw .= " " . $args[$i];
    }
    $vanity = trim($vanity_raw);
    $donator_str = '';
    if (strstr($userlevel, 'DonatorPlus')) {
        $donator_str = '&6++&f';
    } else {
        if (strstr($userlevel, 'Donator')) {
            $donator_str = '&6+&f';
        } else {
            if ($userlevel == 'Owner') {
                $donator_str = '&6++&f';
            }
        }
    }
    $final_title = ' [' . $vanity . '&f]';
    // check for invalid chars
    umc_vanity_sanitize($vanity);
    $quote_array = umc_vanity_quote_title($vanity);
    $total_cost = $quote_array['cost'] * $days;
    $balance = umc_money_check($player);
    if ($quote_array['length'] > 20) {
        umc_error("Your title is too long ({$quote_array['length']} vs. 20 max!");
    }
    if ($total_cost > $balance) {
        umc_error("You do not have enough money to pay for this title for {$days} days. You need {$total_cost} but have only {$balance}!");
    }
    // check if there is a title already set
    $check = umc_vanity_get_title();
    if ($final_title == $check . $donator_str) {
        umc_header("Vanity Title");
        umc_echo("The same title is already set and will be extended by {$days} days!");
    } else {
        if ($check && $final_title != $check . $donator_str) {
            umc_error("You have a different title already set. You need to cancel that one first or set the same one to extend it!");
        } else {
            // no title set yet
            $uuid = umc_user2uuid($player);
            umc_header("Vanity Title");
            umc_echo("No title yet set, setting new one...");
            umc_exec_command("pex user {$uuid} suffix \"{$final_title}{$donator_str}\"", 'asConsole');
        }
    }
    // set timer
    umc_money($player, false, $total_cost);
    umc_timer_set($player, 'custom_title', $days);
    $date_out = umc_timer_get($player, 'custom_title');
    $time_out = $date_out->format('Y-m-d H:i:s');
    $date_today = umc_datetime();
    $interval = $date_today->diff($date_out);
    $days_interval = $interval->days;
    $hours_interval = $interval->h;
    umc_echo("Your title [{$vanity}{white}] will expire on {$time_out} (in {$days_interval} days and {$hours_interval} hours)!");
    umc_echo("Your account has been debited {$total_cost}!");
    umc_log('vanity', 'set', "{$player} paid {$total_cost} for {$vanity} for {$days} days");
    umc_footer(true);
}
function umc_trivia_check()
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    // $args = $UMC_USER['args'];
    $quiz_arr = umc_trivia_get_current_quiz();
    $master = $quiz_arr['master'];
    if (!$quiz_arr) {
        umc_error("There is no active quiz to get answers for. Please start one first.");
    } else {
        if ($player != $master) {
            umc_error("{$master} is running a quiz already, it has to stop first!");
        } else {
            if ($quiz_arr['status'] != 'asked') {
                umc_error("You need to ask the next question before you can get the answers.");
            } else {
                if (!isset($quiz_arr['answers'])) {
                    umc_error("Nobody has answered this question so far");
                }
            }
        }
    }
    umc_header("Trivia Answers Status", true);
    umc_echo("{green}Question:{white} " . $quiz_arr['question']);
    umc_echo("{green}Correct Answer:{white} " . $quiz_arr['answer']);
    umc_footer(true);
    foreach ($quiz_arr['answers'] as $id => $answer) {
        umc_echo("{green}{$id}:{white} " . trim($answer));
    }
    umc_footer(true);
    umc_echo("Pick a correct answer with {green}/trivia solve <No>{white}");
    umc_echo("In case there are 2 correct answers, pick the one higher up.");
    umc_echo("Use {green}/trivia skip{white} in case you did not get any good answers");
    umc_footer(true);
}
/**
 * Reset TS user rights to "Guest" for a specific user
 * This can be done even if the user is not online
 *
 * @param string $uuid
 * @param boolean $echo
 * @return boolean
 */
function umc_ts_clear_rights($uuid, $echo = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    umc_echo("Trying to remove old permissions:");
    global $UMC_TEAMSPEAK;
    // find out the TS id the user has been using from the database
    $check_sql = "SELECT ts_uuid FROM minecraft_srvr.UUID WHERE UUID='{$uuid}';";
    $D = umc_mysql_fetch_all($check_sql);
    if ($D[0]['ts_uuid'] == '') {
        if ($echo) {
            umc_echo("Old Client: No previous TS account detected.");
        }
        return false;
    } else {
        umc_echo("Found old permissions.");
        $ts_uuid = $D[0]['ts_uuid'];
    }
    XMPP_ERROR_trace("ts_uuid", $ts_uuid);
    umc_echo("Connecting to TS server.");
    umc_ts_connect(true);
    // find the TS user by that TS UUID
    umc_echo("Searching for you on the TS server.");
    try {
        $ts_Clients_match = $UMC_TEAMSPEAK['server']->clientFindDb($ts_uuid, true);
    } catch (TeamSpeak3_Exception $e) {
        XMPP_ERROR_trace("Error ", $e->getCode() . ": " . $e->getMessage());
        $ts_Clients_match = 0;
    }
    if (count($ts_Clients_match) > 0) {
        XMPP_ERROR_trace("ts_Clients_match", $ts_Clients_match);
        umc_echo("Found user entries on TS server");
        $client_dbid = $ts_Clients_match[0];
        // enumerate all the groups the user is part of
        $servergroups = array_keys($UMC_TEAMSPEAK['server']->clientGetServerGroupsByDbid($client_dbid));
        XMPP_ERROR_trace("servergroups", $servergroups);
        // remove all servergroups except 8 (Guest)
        umc_echo("Removing all old usergroups:");
        foreach ($servergroups as $sgid) {
            if ($sgid != 8) {
                XMPP_ERROR_trace("Deleting group", $sgid);
                $UMC_TEAMSPEAK['server']->serverGroupClientDel($sgid, $client_dbid);
                if ($echo) {
                    umc_echo("Old Client: Removing Group " . $UMC_TEAMSPEAK['ts_groups'][$sgid]);
                }
            }
        }
        // also remove TS UUID from DB
        $ins_sql = "UPDATE minecraft_srvr.UUID SET ts_uuid='' WHERE ts_uuid='{$ts_uuid}';";
        XMPP_ERROR_trace("removing uuid from DB", $ts_uuid);
        umc_mysql_query($ins_sql, true);
        return true;
    } else {
        XMPP_ERROR_trace("Prev UUID not found");
        if ($echo) {
            umc_echo("Old Client: Previous TS UUID was invalid, nothing to do");
        }
        return false;
    }
}
Example #23
0
function umc_mod_blockcheck_check_inv($count)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER, $UMC_DATA;
    $inv = $UMC_USER['inv'];
    $error = false;
    $inv_count = count($inv);
    if ($inv_count < 36) {
        $error = true;
        umc_echo("Not all items were given ({$inv_count}), checking for errors!");
    } else {
        umc_echo("All items handed over, please check for valid items!");
    }
    foreach ($inv as $slot => $I) {
        // iterate inventory and check if every item exists and if one was skipped (i.e. do we have an empty slot?)
        $item_name = $I['item_name'];
        if (!isset($UMC_DATA[$item_name])) {
            umc_echo("Chould not find Inv slot {$slot} item!");
            $error = true;
        }
    }
    if (!$error) {
        umc_echo("Please continue with number {$count}!");
    }
}
Example #24
0
function umc_story_show()
{
    global $UMC_USER, $UMC_COLORS;
    $username = $UMC_USER['username'];
    $uuid = $UMC_USER['uuid'];
    $args = $UMC_USER['args'];
    $mode = $UMC_USER['mode'];
    $world = $UMC_USER['world'];
    if (!isset($args[2])) {
        umc_error("You have to enter a story code!");
    } else {
        $code = $args[2];
    }
    if (strpos($code, '?')) {
        umc_error('Your code is incomplete! Please replace the ? with the code that you received at the last station!');
    }
    if (strlen($code) != 5) {
        umc_error('Your code needs to have 5 letters!');
    }
    $sql = "SELECT * FROM minecraft_iconomy.story WHERE code='{$code}';";
    $D = umc_mysql_fetch_all($sql);
    $disallowed_items = array(0, 8, 9, 10, 11, 34, 36, 43, 51, 52, 55, 26, 59, 60, 63, 64, 68, 71, 75, 78, 83, 90, 92, 93, 94, 95, 97, 99, 100, 104, 105, 115, 117, 118, 119, 120, 122);
    $out = '';
    if (count($D) > 0) {
        $row = $D[0];
        $story = stripslashes($row['story']);
        $title = stripslashes($row['storyline']);
        $warp = stripslashes($row['warp']);
        if ($row['forcesurvival'] == -1 && $mode == 'CREATIVE') {
            umc_ws_cmd("gamemode survival {$username};", 'asConsole');
        }
        if ($row['clear_inv'] == -1 && ($world == 'city' || $world == 'flatlands')) {
            umc_ws_cmd("ci {$username};", 'asConsole');
        }
        $items = stripslashes($row['items']);
        if (strlen($items) > 0 && ($world == 'city' || $world == 'flatlands')) {
            $items = explode(";", $items);
            if (count($items) > 0) {
                foreach ($items as $item) {
                    $data = explode(':', $item);
                    if (count($data) == 3 && !in_array($data[0], $disallowed_items)) {
                        if (is_numeric($data[0]) && is_numeric($data[1]) && is_numeric($data[2])) {
                            umc_ws_cmd("give {$username} {$data[0]}:{$data[1]} {$data[2]};", 'asConsole');
                        }
                    }
                }
            }
        }
        if (strlen($warp) > 0 && $world == 'city') {
            $warp = "story_" . $warp;
            umc_ws_cmd("warp {$warp} {$username};", 'asConsole');
        }
        $uuid = $row['uuid'];
        $creator_name = umc_user2uuid($uuid);
        // check for duplicate entries
        $sql = "SELECT * FROM minecraft_iconomy.story_users WHERE `uuid`='{$uuid}' and `story_id`='{$row['id']}';";
        $D3 = umc_mysql_fetch_all($sql);
        $count = count($D3);
        if ($count == 0) {
            $sql = "INSERT INTO minecraft_iconomy.story_users (`uuid`, `story_id`) VALUES ('{$uuid}', '{$row['id']}');";
            umc_mysql_query($sql, true);
        }
        $pages = explode("[BR]", $story);
        $pagecount = count($pages);
        if (isset($args[2]) && is_numeric($args[2]) && isset($pages[$args[2] - 1])) {
            $page = $args[2];
        } else {
            $page = 1;
        }
        $arr_page = $page - 1;
        $this_page_raw = $pages[$arr_page];
        $search = array('[player]', "\n");
        $replace = array($username, ';');
        foreach ($UMC_COLORS as $colorcode => $data) {
            foreach ($data['names'] as $color_name) {
                $search[] = "[" . $color_name . "]";
                $replace[] = "&" . $colorcode;
            }
        }
        $this_page = str_replace($search, $replace, $this_page_raw);
        $out = "{white}----------------- {green}Story Page ({$page}/{$pagecount}): {white}-----------------;" . "{yellow}{$title} {white}by {$creator_name};" . $this_page;
        if (count($pages) > $page) {
            $nextpage = $page + 1;
            $out .= "{white}------- {green}Please type /ws story {$code} {$nextpage} to read on! {white}--------;";
        } else {
            $out .= ";-----------------------------------------------------;";
        }
    } else {
        $out .= "The story code could not be found!";
    }
    $lines = explode(";", $out);
    foreach ($lines as $line) {
        umc_echo($line, true);
    }
}
function umc_bottomkarma()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $sql = "SELECT SUM(karma) as sum_karma, receivers.username as receiver_name FROM minecraft_srvr.karma\r\n        LEFT JOIN minecraft_srvr.UUID as senders ON sender_uuid=senders.UUID\r\n        LEFT JOIN minecraft_srvr.UUID as receivers ON receiver_uuid=receivers.UUID\r\n        WHERE senders.lot_count > 0 AND receivers.lot_count > 0\r\n        GROUP BY receivers.username\r\n        HAVING sum(karma) < 0\r\n        ORDER BY sum(karma) ASC LIMIT 0,10";
    $D = umc_mysql_fetch_all($sql);
    umc_echo("Bottom ten Karma users:");
    umc_echo("-∞     =>    Uncovery");
    foreach ($D as $row) {
        $sum_karma = $row['sum_karma'];
        $receiver = $row['receiver_name'];
        if (!umc_user_is_banned($receiver)) {
            umc_echo("{$sum_karma}    =>    {$receiver}");
        }
    }
}
function umc_home_list()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    global $UMC_USER;
    $sql = "SELECT * FROM minecraft_srvr.homes WHERE uuid='{$UMC_USER['uuid']}' ORDER BY world, name;";
    $D = umc_mysql_fetch_all($sql);
    $count = count($D);
    umc_header("Your home list ({$count} homes)");
    $homes = array();
    foreach ($D as $d) {
        $world = $d['world'];
        $name = $d['name'];
        $homes[$world][] = $name;
    }
    foreach ($homes as $world => $worldhomes) {
        $out = "{red}{$world}: {white}" . implode("{red},{white} ", $worldhomes);
        umc_echo($out);
    }
    umc_footer();
}
/**
 * Add items to a user inventory. If cancel=true, we check if the current user is owner of the goods
 *
 * @global type $UMC_USER
 * @param type $id
 * @param type $amount
 * @param type $table
 * @param boolean $cancel
 * @param type $to_deposit
 * @param string $uuid
 * @return string
 */
function umc_checkout_goods($id, $amount, $table = 'stock', $cancel = false, $to_deposit = false, $uuid = false)
{
    global $UMC_USER, $UMC_ENV;
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if (!$uuid) {
        $player = $UMC_USER['username'];
        $uuid = $UMC_USER['uuid'];
    } else {
        $player = umc_user2uuid($uuid);
    }
    if (!is_numeric($id)) {
        umc_error('{red}Invalid ID. Please use {yellow}/shophelp;');
    }
    // the fact that the source is also a condition prevents people to cancel other users' items.
    if ($table == 'stock') {
        if ($cancel) {
            $sql = "SELECT * FROM minecraft_iconomy.stock WHERE uuid='{$uuid}' AND id='{$id}' LIMIT 1;";
        } else {
            $sql = "SELECT * FROM minecraft_iconomy.stock WHERE id='{$id}' LIMIT 1;";
        }
    } else {
        if ($table == 'deposit') {
            $sql = "SELECT * FROM minecraft_iconomy.deposit WHERE (sender_uuid='{$uuid}' OR recipient_uuid='{$uuid}') AND id='{$id}' LIMIT 1;";
        }
    }
    $D = umc_mysql_fetch_all($sql);
    if (count($D) == 0) {
        umc_error("{red}Id {white}{$id}{red} not found! Please try again.;");
    } else {
        $row = $D[0];
        $item = umc_goods_get_text($row['item_name'], $row['damage'], $row['meta']);
        $meta_cmd = $meta = '';
        if ($row['meta'] != '') {
            $meta_arr = unserialize($row['meta']);
            if (!is_array($meta_arr)) {
                XMPP_ERROR_trigger("Could not get Meta Data array for {$table} id {$id}: " . var_export($row, true));
            }
            if ($row['item_name'] == "banner") {
                $meta_cmd = umc_banner_get_data($meta_arr);
            } else {
                foreach ($meta_arr as $type => $lvl) {
                    $meta_cmd .= " {$type}:{$lvl}";
                }
            }
        }
        // handle unlimited items
        $unlimited = false;
        if ($row['amount'] == -1) {
            $row['amount'] = $amount;
            $unlimited = true;
        }
        //umc_echo('There were ' . $row['amount'] . " pieces of " . $item['item_name'] . "$meta_txt stored.");
        // determine withdrawal amount
        if (is_numeric($amount) && $amount <= $row['amount']) {
            $sellamount = $amount;
        } else {
            if ($amount == 'max') {
                // withdraw all
                $sellamount = $row['amount'];
                //umc_echo("You are withdrawing all ($sellamount) {$item['name']}$meta_txt");
            } else {
                if (is_numeric($amount) && $amount > $row['amount']) {
                    umc_echo("{yellow}[!]{gray} Available amount ({yellow}{$row['amount']}{gray}) less than amount specified ({yellow}{$amount}{gray})");
                    $sellamount = $row['amount'];
                } else {
                    umc_error("{red}Amount {white}'{$amount}'{red} is not numeric;");
                }
            }
        }
        if ($table != 'stock') {
            umc_echo("{green}[+]{gray} You are withdrawing {yellow} {$amount} {gray} of {$item['full']}{gray}.");
        }
        if ($table == 'stock') {
            $cost = $sellamount * $row['price'];
            if ($cancel) {
                $target = $uuid;
                $source = 'cancel00-sell-0000-0000-000000000000';
            } else {
                $target = $uuid;
                $source = $row['uuid'];
            }
        } else {
            if ($table == 'deposit') {
                if ($row['recipient_uuid'] == $uuid) {
                    $cancel = true;
                }
                $cost = 0;
                if ($cancel) {
                    $target = $uuid;
                    $source = 'cancel00-depo-0000-0000-000000000000';
                } else {
                    $target = $row['recipient_uuid'];
                    $source = $row['sender_uuid'];
                }
            }
        }
        if (!$to_deposit) {
            umc_check_space($sellamount, $item['item_name'], $item['type']);
            // the in-game command does not understand item_names yet
            umc_ws_cmd("give {$player} {$item['item_name']}:{$item['type']} {$sellamount}{$meta_cmd};", 'asConsole');
            umc_log('inventory', 'give', "{$player} received {$item['full_clean']} {$sellamount}");
        } else {
            umc_deposit_give_item($target, $item['item_name'], $item['type'], $meta, $sellamount, $source);
            umc_log('inventory', 'give_deposit', "{$player} recived in deposit {$item['full_clean']} {$sellamount}");
        }
        //umc_echo("./give $player {$item['id']}:{$item['type']} $sellamount$meta_cmd");
        // check status
        umc_shop_transaction_record($source, $target, $sellamount, $cost, $item['item_name'], $item['type'], $meta);
        if ($unlimited) {
            return "unlimited";
        }
        // fix the stock levels
        $amount_left = umc_db_take_item($table, $id, $sellamount, $source);
        if ($UMC_ENV == 'websend') {
            if ($amount_left == 0) {
                umc_echo("{green}[+]{gray} No more {green}{$item['full']}{gray} now in stock.");
            } else {
                umc_echo("{green}[+]{yellow} {$amount_left}{green} {$item['full']}{gray} remaining in stock.");
            }
        }
        return $amount_left;
    }
}
Example #28
0
function umc_home_list()
{
    global $UMC_USER;
    $sql = "SELECT * FROM minecraft_srvr.homes WHERE uuid='{$UMC_USER['uuid']}' ORDER BY world, name;";
    $D = umc_mysql_fetch_all($sql);
    $count = count($D);
    umc_header("Your home list ({$count} homes)");
    $cur_world = false;
    $out = '';
    $worldhomes = array();
    foreach ($D as $d) {
        if ($d['world'] != $cur_world) {
            if ($cur_world) {
                $out .= implode(", ", $worldhomes);
                umc_echo($out);
            }
            $out = "{red}{$d['world']}:{white} ";
            $worldhomes = array();
        }
        $worldhomes[] = $d['name'];
        $cur_world = $d['world'];
    }
    umc_footer();
}