/** * 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; } }
/** * Get all variables of the current user from Wordpress and add it to $UMC_USER */ function umc_wp_get_vars() { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); global $UMC_USERS, $UMC_USER, $UMC_ENV, $user_email, $user_login; if ($UMC_ENV !== 'wordpress') { XMPP_ERROR_trigger("Tried to get wordpress vars, but environment did not match: " . var_export($UMC_ENV, true)); die('umc_wp_get_vars'); } get_currentuserinfo(); if (!isset($user_login) || $user_login == '' || $user_email == '') { $UMC_USER = false; } else { if (!function_exists('umc_get_uuid_level')) { XMPP_ERROR_send_msg("Could not get uuid_level, Env = {$UMC_ENV}"); require_once '/home/minecraft/server/bin/core_include.php'; } $uuid = umc_wp_get_uuid_for_currentuser(); $UMC_USER['ip'] = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_FLAG_IPV4); if (!$uuid) { // we have a guest who is trying to register $UMC_USER['username'] = $user_login; $UMC_USER['email'] = $user_email; $uuid = umc_user2uuid($user_login); $UMC_USER['uuid'] = $uuid; $UMC_USER['userlevel'] = 'Guest'; } else { // there is a logged-in user umc_uuid_check_usernamechange($uuid); $UMC_USER['email'] = $user_email; $UMC_USER['username'] = umc_uuid_getone($uuid, 'username'); $UMC_USER['uuid'] = $uuid; $UMC_USER['userlevel'] = umc_get_uuid_level($uuid); if (strstr($UMC_USER['userlevel'], 'DonatorPlus')) { $UMC_USER['donator'] = 'DonatorPlus'; } else { if (strstr($UMC_USER['userlevel'], 'Donator')) { $UMC_USER['donator'] = 'Donator'; } else { $UMC_USER['donator'] = false; } } } // if we did not get any UUID if (!$uuid) { $UMC_USER['username'] = $user_login; $UMC_USER['uuid'] = false; $UMC_USER['userlevel'] = 'Guest'; } } //$UMC_USERS[$uuid] = new UMC_User($uuid); //$UMC_USERS[$uuid]->set_username($username); //$UMC_USERS[$uuid]->set_userlevel($userlevel); }
/** * return dibs information per world */ function umc_lot_manager_dib_get_number($user, $world) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); $uuid = umc_uuid_getone($user, 'uuid'); $sql = "SELECT lot, reservation_id, action\n FROM minecraft_srvr.lot_reservation\n WHERE uuid='{$uuid}' and world='{$world}';"; $D = umc_mysql_fetch_all($sql); $dibs_arr = array(); foreach ($D as $row) { $dibs_arr[$row['lot']] = array('tile' => umc_user_get_lot_tile($row['lot']), 'action' => $row['action']); } return $dibs_arr; }
function umc_user_get_icon_url($uuid_requested, $update = false) { global $UMC_DOMAIN, $UMC_PATH_MC; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); if (strstr($uuid_requested, ' ')) { return ''; } // make sure it's a uuid $uuid = umc_uuid_getone($uuid_requested, 'uuid'); $path = "{$UMC_PATH_MC}/server/bin/data/user_icons/"; if (!file_exists($path . $uuid . ".png") && $update) { // this tries to download the latest version, otherwise falls back to steve icon // umc_update_usericons($uuid); umc_usericon_get($uuid); } else { if (!file_exists($path . $uuid . ".png") && !$update) { return false; } } $url = "{$UMC_DOMAIN}/websend/user_icons/{$uuid}.png"; return $url; }
function umc_shopmgr_transactions() { $out = "This data only covers the last month, max 100 entries"; $s_get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); $seller_str = ''; $buyer_str = ''; $username = "******"; if (isset($s_get['user'])) { $username = $s_get['user']; $uuid = umc_uuid_getone($username, 'uuid'); $seller_str = "AND seller_uuid = '{$uuid}'"; $buyer_str = "buyer_uuid = '{$uuid}' AND"; } $lastmonth = date("Y-m-d", strtotime("-1 month")); // what did the user sell? $out .= "<h2>Items sold by {$username}</h2>"; $sql = "SELECT CONCAT(item_name,'|', damage, '|', meta) AS item_name, cost AS income, amount, username AS buyer, date\r\n FROM minecraft_iconomy.`transactions`\r\n LEFT JOIN minecraft_srvr.UUID ON buyer_uuid=UUID\r\n WHERE date > '{$lastmonth}' AND cost > 0 {$seller_str}\r\n ORDER BY date DESC\r\n LIMIT 100"; $D1 = umc_mysql_fetch_all($sql); $sort_column = '4, "desc"'; $out .= umc_web_table('shopusers_soldbyplayer', $sort_column, $D1); $out .= "<h2>Items bought by {$username}</h2>"; $sql2 = "SELECT CONCAT(item_name,'|', damage, '|', meta) AS item_name, cost AS expense, amount, username AS seller, date\r\n FROM minecraft_iconomy.`transactions`\r\n LEFT JOIN minecraft_srvr.UUID ON seller_uuid=UUID\r\n WHERE date > '{$lastmonth}' AND cost > 0 AND {$buyer_str} seller_uuid <> 'cancel00-sell-0000-0000-000000000000'\r\n ORDER BY date DESC\r\n LIMIT 100"; $D2 = umc_mysql_fetch_all($sql2); $sort_column2 = '4, "desc"'; $check = umc_web_table('shopplayers_sellers', $sort_column2, $D2); if (!$check) { XMPP_ERROR_trigger("Error creating web_table with SQL {$sql}"); return "Error creating data table. Admin was notified, please wait until it is fixed"; } else { return $out . $check; } }
function umc_mod_unmute() { global $UMC_USER, $UMC_PATH_MC; // umc_echo('Unmuting...'); $player = $UMC_USER['username']; $args = $UMC_USER['args']; if (!isset($args[2])) { umc_show_help($args); die; } else { $user = umc_check_user($args[2]); if (!$user) { XMPP_ERROR_trigger("{$player} tried to un-mute {$user}, but {$user} does not exist!"); umc_error("{red}The user {$args[2]} does not exist! See {yellow}/helpme mod"); } } // umc_echo('checks done... '); $user_uuid = umc_uuid_getone($user); $file = "{$UMC_PATH_MC}/server/bukkit/plugins/Essentials/userdata/" . $user_uuid . ".yml"; $txt = file_get_contents($file); $search = "muted: true"; if (strstr($txt, $search)) { // YAML library is not installed, //$yml = yaml_parse_file($file); //if ($yml['muted'] == 'true') { $uuid = umc_user2uuid($user); umc_ws_cmd("mute {$user}", 'asPlayer'); umc_ws_cmd("pex user {$uuid} timed remove -herochat.*;", 'asConsole'); umc_ws_cmd("pex user {$uuid} timed remove -irc.*;", 'asConsole'); umc_ws_cmd("pex user {$uuid} timed remove -essentials.msg;", 'asConsole'); umc_ws_cmd("pex user {$uuid} timed remove -essentials.me;", 'asConsole'); umc_echo("The user {$user} has been un-muted!"); umc_log('mod', 'un-mute', "{$player} un-muted {$user}"); } else { umc_log('mod', 'un-mute', "{$player} tried to un-mute {$user}, but {$user} was not muted!"); umc_error("User {$user} was not muted!"); } }
/** * 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); }
/** * Handles money transfers * UUID enabled * * @global type $UMC_USER * @param type $source * @param type $target * @param type $amount * @return boolean */ function umc_money($source = false, $target = false, $amount_raw = 0) { global $UMC_ENV; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); if ($source) { $source = umc_check_user($source); } if ($target) { $target = umc_check_user($target); } $amount = abs($amount_raw); if ($source) { // take from someone $source_uuid = umc_uuid_getone($source, 'uuid'); $balance = umc_money_check($source); if ($balance > $amount) { $sql = "UPDATE `minecraft_iconomy`.`mineconomy_accounts`\r\n SET `balance`=`balance`-'{$amount}'\r\n\t\tWHERE `mineconomy_accounts`.`uuid` = '{$source_uuid}';"; umc_mysql_query($sql); } else { if ($UMC_ENV == 'websend') { umc_error("There is not enough money in the account! You need {$amount} but have only {$balance} Uncs."); } } } if ($target) { // give to someone $target_uuid = umc_uuid_getone($target, 'uuid'); $balance = umc_money_check($target); $sql = "UPDATE `minecraft_iconomy`.`mineconomy_accounts`\r\n\t SET `balance` = `balance` + '{$amount}'\r\n WHERE `mineconomy_accounts`.`uuid` = '{$target_uuid}';"; umc_mysql_query($sql); } // logging if (!$target) { $target = "System"; } if (!$source) { $source = "System"; } umc_log('money', 'transfer', "{$amount} was transferred from {$source} to {$target}"); }
/** * Get the hours a user was online * * @param string $user / either user or uuid * @return string/boolean (false if user is not found) */ function umc_get_online_hours($user) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); $uuid = umc_uuid_getone($user, 'uuid'); $sql = "SELECT onlinetime FROM minecraft_srvr.UUID WHERE UUID='{$uuid}';"; $data = umc_mysql_fetch_all($sql); if (count($data) == 0) { return false; } $onlinetime = round($data[0]['onlinetime'] / 60 / 60); return $onlinetime; }
/** * Put an item into the deposit of the recipient * * @param type $recipient * @param type $item_name * @param type $data * @param type $meta * @param type $amount * @param type $sender */ function umc_deposit_give_item($recipient, $item_name, $data, $meta, $amount, $sender) { global $UMC_DATA_ID2NAME, $UMC_DATA; if (is_numeric($item_name)) { $item_name = $UMC_DATA_ID2NAME[$item_name]; } if (!isset($UMC_DATA[$item_name])) { XMPP_ERROR_trigger("Could not deposit item {$item_name} for user {$recipient}!"); } if (is_array($meta) > 0) { $meta = serialize($meta); } else { $meta = ''; } $recipient_uuid = umc_uuid_getone($recipient, 'uuid'); $sender_uuid = umc_uuid_getone($sender, 'uuid'); $sql = "SELECT * FROM minecraft_iconomy.deposit\r\n WHERE item_name='{$item_name}' AND recipient_uuid='{$recipient_uuid}'\r\n AND damage='{$data}' AND meta='{$meta}' AND sender_uuid='{$sender_uuid}';"; $D = umc_mysql_fetch_all($sql); // check first if item already is being sold if (count($D) > 0) { $row = $D[0]; $sql = "UPDATE minecraft_iconomy.`deposit` SET `amount`=amount+{$amount} WHERE `id`={$row['id']} LIMIT 1;"; } else { // create a new deposit box $sql = "INSERT INTO minecraft_iconomy.`deposit` (`damage` ,`sender_uuid` ,`item_name` ,`recipient_uuid` ,`amount` ,`meta`)\r\n VALUES ('{$data}', '{$sender_uuid}', '{$item_name}', '{$recipient_uuid}', '{$amount}', '{$meta}');"; } //umc_echo($sql); umc_mysql_query($sql, true); }
/** * Records a transaction in the database. * * @param type $from * @param type $to * @param type $amount * @param type $value * @param type $item * @param type $type * @param type $meta */ function umc_shop_transaction_record($from, $to, $amount, $value, $item, $type = 0, $meta = '') { global $UMC_DATA_ID2NAME; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); // make sure we have UUIDs $from_uuid = umc_uuid_getone($from, 'uuid'); $to_uuid = umc_uuid_getone($to, 'uuid'); // make sure we have item names if (is_numeric($item)) { $item_name = $UMC_DATA_ID2NAME[$item]; } else { $item_name = $item; } $ins_sql = "INSERT INTO minecraft_iconomy.`transactions` (`damage`, `buyer_uuid`, `seller_uuid`, `item_name`, `cost`, `amount`, `meta`)\r\n VALUES ('{$type}', '{$to_uuid}', '{$from_uuid}', '{$item_name}', '{$value}', '{$amount}', '{$meta}');"; umc_mysql_query($ins_sql, true); }
/** * Updates the amount of lots a user has in the UUID table * if $user = false, update ALL lot counts * * @param type $user */ function umc_uuid_record_lotcount($user = false) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); if ($user) { $uuid = umc_uuid_getone($user, 'uuid'); $lots = umc_user_countlots($uuid); $sql = "UPDATE minecraft_srvr.UUID SET lot_count={$lots} WHERE UUID='{$uuid}';"; umc_mysql_query($sql); } else { } }