Exemplo n.º 1
0
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();
}
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);
}
Exemplo n.º 3
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!;";
}
Exemplo n.º 4
0
function umc_mail_check($uuid = false)
{
    $user_filter = '';
    $check = false;
    if ($uuid) {
        $user_filter = " AND recipient_uuid='{$uuid}'";
    }
    $sql = "SELECT * FROM minecraft_srvr.user_mail WHERE status='sent'{$user_filter};";
    $D = umc_mysql_fetch_all($sql);
    $mails = array();
    foreach ($D as $row) {
        $user_uuid = $row['recipient_uuid'];
        $id = $row['msg_id'];
        $title = $row['title'];
        $mails[$user_uuid][$id] = array('sender_uuid' => $row['sender_uuid'], 'title' => stripslashes($title));
    }
    foreach ($mails as $uuid => $data) {
        $user = umc_user2uuid($uuid);
        $count = count($data);
        $check = umc_msg_user($user, "You have {$count} new mail(s):");
        if (!$check) {
            continue;
        }
        foreach ($data as $id => $mail) {
            umc_msg_user($user, "{green}ID:{white} {$id} {green}From: {white}{$user}{green}:{white}{$mail['title']}");
            $check = true;
        }
    }
    return $check;
}
Exemplo n.º 5
0
function umc_do_sell_internal($from_deposit = false)
{
    global $UMC_USER;
    $player = $UMC_USER['username'];
    $args = $UMC_USER['args'];
    $uuid = $UMC_USER['uuid'];
    if (!isset($args[2]) || !is_numeric($args[2])) {
        umc_error("{red}You need a valid shop_id to sell to a requester. Use {yellow}/find request ...;");
        umc_error("{red}Maybe you meant {yellow}/offer{red}, for posting an offer for sale in the shop.;");
    }
    $do_check = false;
    $pos = array_search('check', $args);
    if ($pos) {
        $do_check = true;
        array_splice($args, $pos, 1);
    }
    $id = $args[2];
    $sql_request = "SELECT * FROM minecraft_iconomy.request WHERE id='{$id}' LIMIT 1;";
    $request_data = umc_mysql_fetch_all($sql_request);
    if (count($request_data) == 0) {
        umc_error("{red}The shop-id {white}{$id}{red} could not be found. Please use {yellow}/find{red} and{yellow} /shophelp sell;");
    }
    $request = $request_data[0];
    $request_item = umc_goods_get_text($request['item_name'], $request['damage'], $request['meta']);
    if ($request['uuid'] == $uuid && $player != 'uncovery') {
        umc_error("{red}You cannot fulfill your own requests. Use {yellow}/cancel r <id>{red} instead!;");
    }
    // do we sell items from deposit?
    if ($from_deposit) {
        $depot_id = $args[3];
        array_splice($args, 3, 1);
        $sql = "SELECT * from minecraft_iconomy.deposit WHERE recipient_uuid='{$uuid}' and id='{$depot_id}'";
        $D = umc_mysql_fetch_all($sql);
        if (count($D) < 1) {
            umc_error("You have no such deposit ID");
        }
        $depot_row = $D[0];
        $inv = $depot_row['amount'];
        $depot_item = umc_goods_get_text($depot_row['item_name'], $depot_row['damage'], $depot_row['meta']);
        if ($depot_item != $request_item) {
            //umc_echo("{green}$type:$data {gray} => {red}".$check_inv[$item_slot]['id'].":".$check_inv[$item_slot]['data']);
            umc_error("{red}The item in deposit-id {white}{$depot_id}{red} doesn't match request {white}{$id}{red}.");
        }
    } else {
        $item_slot = $UMC_USER['current_item'];
        $check_inv = $UMC_USER['inv'];
        if (!isset($check_inv[$item_slot])) {
            umc_error("{red}You need to hold the item you want to sell!;");
        }
        $inv_item = umc_goods_get_text($check_inv[$item_slot]['id'], $check_inv[$item_slot]['data'], $check_inv[$item_slot]['meta']);
        if ($inv_item != $request_item) {
            //umc_error_longmsg("Sell failed");
            //umc_echo("{green}$type:$data {gray} => {red}".$check_inv[$item_slot]['id'].":".$check_inv[$item_slot]['data']);
            umc_error("{red}The item you're holding doesn't match request id {white}{$id}{red}.");
        }
    }
    if (!isset($args[3])) {
        umc_echo("{yellow}[!]{gray} You did not enter an amount. Attempting to sell all.");
        $amount = false;
    } else {
        $args[3] = intval($args[3]);
        $amount = umc_sanitize_input($args[3], 'amount');
    }
    if (!$amount) {
        // sell as much as possible
        $amount = $request['amount'];
    }
    if ($amount > $request['amount']) {
        umc_error("{red}That's too much, the request is only for {yellow}{$request['amount']}{red} pieces.");
    }
    if (!$from_deposit) {
        $inv = umc_check_inventory($request_item['item_name'], $request_item['type'], $request_item['meta']);
        if ($inv == 0) {
            umc_error("{red}You don't have any of the requested item.");
        }
    }
    if ($inv < $amount) {
        umc_echo("{yellow}[!]{gray} Not enough for entire request.  Selling as much as possible.");
        $amount = $inv;
    }
    $recipient_uuid = $request['uuid'];
    $recipient = umc_user2uuid($recipient_uuid);
    if ($do_check) {
        umc_echo("{white}[?]{gray} This would sell {yellow}{$amount} {$request_item['full']}{darkgray} for {cyan}{$request['price']}{gray} each to {gold}{$recipient}");
        $sum = $amount * $request['price'];
        umc_echo("{white}[?]{gray} Your account would be credited {cyan}{$sum}{gray} Uncs.");
        return;
    }
    umc_echo("{green}[+] {gray}Selling {yellow}{$amount} {$request_item['full']}{darkgray} for {cyan}{$request['price']}{gray} each to {gold}{$recipient}");
    if ($from_deposit) {
        umc_db_take_item('deposit', $depot_id, $amount, $uuid);
    } else {
        umc_clear_inv($request_item['item_name'], $request_item['type'], $amount, $request_item['meta']);
    }
    $sum = $amount * $request['price'];
    umc_money(false, $player, $sum);
    umc_echo("{green}[\$]{gray} Your account has been credited {cyan}{$sum}{gray} Uncs.");
    $sql = "SELECT * FROM minecraft_iconomy.deposit\r\n        WHERE item_name='{$request_item['item_name']}'\r\n\t    AND recipient_uuid='{$request['uuid']}'\r\n            AND damage='{$request_item['type']}'\r\n\t    AND meta='{$request_item['meta']}'\r\n\t    AND sender_uuid='shop0000-0000-0000-0000-000000000000';";
    $D = umc_mysql_fetch_all($sql);
    // check first if item already is in the recipient's deposit
    if (count($D) > 0) {
        $update_row = $D[0];
        umc_echo("{green}[+]{gray} There is already {$request_item['full']}{gray} in the deposit for {gold}{$recipient}{gray}, adding {yellow}{$amount}{gray}.");
        $sql = "UPDATE minecraft_iconomy.`deposit` SET `amount`=amount+'{$amount}' WHERE `id`={$update_row['id']} LIMIT 1;";
    } else {
        // create a new deposit box
        umc_echo("{green}[+]{gray} Depositing {yellow} {$amount} {$request_item['full']}{gray} for {gold}{$recipient}");
        $sql = "INSERT INTO minecraft_iconomy.`deposit` (`damage` ,`sender_uuid` ,`item_name` ,`recipient_uuid` ,`amount` ,`meta`)\r\n            VALUES ('{$request_item['type']}', 'shop0000-0000-0000-0000-000000000000', '{$request_item['item_name']}', '{$recipient_uuid}', '{$amount}', '{$request_item['meta']}');";
    }
    umc_mysql_query($sql, true);
    if ($amount < $request['amount']) {
        // Update existing listing
        $sql = "UPDATE minecraft_iconomy.`request` SET `amount`=amount-'{$amount}' WHERE id={$request['id']} LIMIT 1;";
        umc_mysql_query($sql, true);
        //umc_echo("{purple}".$sql);
        //umc_echo("{red}".mysql_error());
    } else {
        // Delete the listing entirely
        $sql = "DELETE FROM minecraft_iconomy.`request` WHERE id={$request['id']}";
        umc_mysql_query($sql, true);
        //umc_echo("{red}".mysql_error());
    }
    // record transaction
    umc_shop_transaction_record($uuid, $request['uuid'], $amount, $sum, $request_item['item_name'], $request_item['type'], $request_item['meta']);
    // message recipient
    $msg = "{$player} sold you {$amount} {$request_item['full']} per your request, check your /depotlist!;";
    umc_msg_user($recipient, $msg);
    // record logfile
    umc_log('shop', 'sell_on_request', "{$player} sold {$amount} of {$request_item['full_clean']} to {$recipient} (ID: {$request['id']})");
}