function umc_depositbox_check() { //XMPP_ERROR_trace(__FUNCTION__, func_get_args()); global $UMC_USER, $UMC_SETTING; $count = umc_depositbox_count(); $cost = umc_depositbox_calc_costs($count + 1); $userlevel = $UMC_USER['userlevel']; $max_deposits = $UMC_SETTING['deposits']['max'][$userlevel]; $bank = umc_money_check($UMC_USER['uuid']); // output the return values to the chat window umc_header("Checking Depositbox Status"); umc_echo("You currently have {$count} item deposit boxes."); umc_echo("Your maximum number of boxes available for purchase is {$max_deposits}."); umc_echo("The cost to purchase your next box is {$cost} Uncs."); umc_echo("You currently have {$bank} Uncs."); umc_footer(); }
function umc_shopmgr_main() { global $UMC_USER, $UMC_DOMAIN; // $s_post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); $s_get = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); if (!$UMC_USER) { return "You have to be logged in to see this!"; } if (!isset($s_get['page'])) { $sel_page = 'deposit'; } else { $sel_page = $s_get['page']; } $out = ''; if (!$UMC_USER) { return "<strong>You need to be <a href=\"{$UMC_DOMAIN}/wp-login.php\">logged in</a></strong> to see this!\n"; } else { $username = $UMC_USER['username']; $userlevel = $UMC_USER['userlevel']; } $balance = number_format(umc_money_check($username), 2, ".", "'"); $out .= "Welcome {$username} ({$userlevel})! You currently have {$balance} Uncs.<br>"; $pages = array('deposit' => "shopmgr_show_deposit", 'goods' => "shopmgr_items", 'offers' => "shopmgr_offers", 'requests' => "shopmgr_requests", 'users' => "shopmgr_transactions", 'statistics' => "shopmgr_stats", 'deposit_help' => "shopmgr_show_help_deposit", 'shop_help' => "shopmgr_show_help_shop"); $out .= '<ul class="lot_tabs">' . "\n"; foreach ($pages as $page => $function) { $page_name = umc_pretty_name($page); if ($page == $sel_page) { $out .= "<li class=\"active_world\">{$page_name}</li>"; } else { $out .= "<li><a href=\"?page={$page}\">{$page_name}</a></li>"; } } $out .= "</ul><br>"; $out .= "<div class=\"formbox\"><form class=\"lotform\">"; $function = 'umc_' . $pages[$sel_page]; if (function_exists($function)) { $out .= $function(); } else { XMPP_ERROR_trigger("Shop manager function {$function} for {$sel_page} invalid!"); echo "Page {$function} for {$sel_page} not found!"; } $out .= "</form></div>"; return $out; }
/** * 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"); } }
/** * Check if a user can have a lot or not, also check for money requirements * * @param type $user * @param type $new_lot * @return boolean|string\ */ function umc_lot_manager_check_before_assign($user, $new_lot) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); // get username $username = umc_uuid_getone($user, 'username'); // validate input and check if lot is free // find world & sanitize $world = umc_get_lot_world($new_lot); $userlevel = umc_get_userlevel($username); if (!$world) { XMPP_ERROR_send_msg("Guest {$username} tried to get lot {$new_lot}, but world could not be found! (umc_assign_new_lot)"); $result = array('result' => false, 'text' => "The lot you chose is invalid!", 'cost' => false); return $result; } $cost = umc_get_lot_costs($new_lot); // guests need to get either an empire or flatlands lot $guest_worlds = array('empire', 'flatlands'); if ($userlevel == 'Guest' && !in_array($world, $guest_worlds)) { XMPP_ERROR_send_msg("Guest {$username} tried to get lot {$new_lot} in {$world} (umc_assign_new_lot)"); $result = array('result' => false, 'text' => "You can only get lots in Empire & Flatlands as Guest!", 'cost' => $cost); return $result; } $userlots = umc_get_lot_number($username, $world); // check costs if ($cost) { // see if the user has enough money $balance = umc_money_check($username); if ($balance < $cost) { XMPP_ERROR_send_msg("User {$username} did not have enough money to get {$new_lot} (umc_assign_new_lot)"); $result = array('result' => false, 'text' => "You do not have enough money to get this lot!", 'cost' => $cost); return $result; } } //check if user has approriate kingdom lot if ($world == 'draftlands') { $draft_lots = array(); $king_lots = umc_get_lot_number($username, 'kingdom'); $king_lots_list = $king_lots['lot_list']; foreach ($king_lots_list as $king_lot) { $draft_lots[] = str_replace('king', 'draft', $king_lot); } if (!in_array($new_lot, $draft_lots)) { $result = array('result' => false, 'text' => "You need to own the same kingdom lot!", 'cost' => $cost); return $result; } } // check if the lot is owned already by someone $occupied_check = umc_check_lot_owner($new_lot, false); if ($occupied_check) { XMPP_ERROR_send_msg("User {$username} tried to get {$new_lot} but someone else owns it! (umc_assign_new_lot)"); $result = array('result' => false, 'text' => "This lot is owned by someone else already!", 'cost' => $cost); return $result; } // check if user has lots free if (isset($userlots['lot_list'][$new_lot])) { XMPP_ERROR_send_msg("User {$username} tried to get {$new_lot} but is an owner already! (umc_assign_new_lot)"); $result = array('result' => false, 'text' => "You own this lot already!", 'cost' => $cost); return $result; } else { if ($userlots['avail_lots'] > 0) { // user can get the lot! umc_log("lot_manager", "assign_new_lot", "{$username} was added as owner to lot {$new_lot}"); $result = array('result' => true, 'text' => "You are now proud owner of lot {$new_lot} in {$world}!", 'cost' => $cost); XMPP_ERROR_send_msg("User {$username} tried to get {$new_lot} and is approved! (umc_assign_new_lot)"); return $result; } else { XMPP_ERROR_send_msg("User {$username} did not have avialable lots free to get {$new_lot} (umc_assign_new_lot) " . var_export($userlots, true)); $result = array('result' => false, 'text' => "You do not have enough available lots in this world!", 'cost' => $cost); return $result; } } }
function umc_hunger_trophy() { global $UMC_USER, $HUNGER; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); $args = $UMC_USER['args']; $player = $UMC_USER['username']; $uuid = $UMC_USER['uuid']; $game_id = isset($args[2]) ? $args[2] + 0 : null; if (!$game_id) { umc_error("[Hunger] {red}You must specify a [game-id] for which you were the winner."); } $victim = strtolower(umc_sanitize_input($args[3], 'player')); $victim_uuid = umc_user2uuid($victim); $sql_games = "SELECT *, timediff(NOW(),end) as age FROM minecraft_iconomy.hunger_games WHERE id = {$game_id}"; $rst_games = umc_mysql_query($sql_games); if (mysql_num_rows($rst_games) > 0) { $game = umc_mysql_fetch_array($rst_games); } if (!$game) { umc_error("[Hunger] {red}No such game with game-id {yellow}{$game_id}"); } if ($game['winner'] != $uuid) { umc_error("[Hunger] {red}You were not the winner of game-id {yellow}{$game_id}{red}."); } if ($game['trophy_claimed'] == 'y') { umc_error("[Hunger] {red}You already claimed a trophy for game-id {yellow}{$game_id}{red}."); } if ($game['age'] > '24:00:00') { // umc_error("{red}That game ended more than 24 hours ago, the corpses are too rotten."); } if ($victim_uuid == $uuid) { umc_error("[Hunger] {red}You can't claim your own head. Weirdo."); } umc_echo("finding players of game {$game_id}..."); $HUNGER = umc_hunger_find_players($game_id); $players = $HUNGER['old_game'][$game_id]['players']; if (!in_array($victim, $players)) { umc_error("[Hunger] {red}{gold}{$victim}{red} was not vanquished in that game."); } umc_echo("checking your account balance...."); $balance = umc_money_check($player); if ($balance < $HUNGER['trophy_cost']) { umc_error("[Hunger] {red}You can't afford a trophy, they cost {green}{$HUNGER['trophy_cost']} Uncs"); } umc_echo("Account is fine..."); $item_slot = $UMC_USER['current_item']; if ($item_slot != 0 || isset($UMC_USER['inv'][$item_slot])) { umc_error("[Hunger] {red}You have to pick first hotbar slot, and it has to be empty."); } umc_echo("[Hunger] all good, taking trophy..."); #-- All good, do the work! $sql = "UPDATE minecraft_iconomy.hunger_games SET trophy_claimed = 'y' WHERE id = {$game_id}"; umc_mysql_query($sql, true); umc_echo("[Hunger] charging {$HUNGER['trophy_cost']}..."); umc_money($player, false, $HUNGER['trophy_cost']); umc_echo("[Hunger] {yellow}[\$]{gray} You have been charged {yellow}{$HUNGER['trophy_cost']}{gray} uncs."); umc_echo("[Hunger] getting head..."); // umc_ws_cmd("give $player 397:3 1","asConsole"); umc_ws_cmd("ph spawn {$victim} {$player}", "asConsole"); umc_echo("[Hunger] {purple}Enjoy this small memento of your victory!"); umc_log('hunger', 'trophy', "{$player} got the head of {$victim}"); }
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); }
/** * this checks if the user exists, and creats it if not. returns the amount in the account. * @global type $UMC_ENV * @param type $user * @return int */ function umc_money_check($user) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); if ($user == '') { XMPP_ERROR_trigger("Failed to get account status for empty user!"); } // check if the user has an acoount if (strlen($user) <= 17) { $uuid = umc_user2uuid($user); } else { $uuid = $user; $user = umc_user2uuid($uuid); if ($user == '') { XMPP_ERROR_trigger("Failed to get username for {$uuid}!"); die; } } $sql = "SELECT balance FROM `minecraft_iconomy`.`mineconomy_accounts` WHERE uuid='{$uuid}';"; $data = umc_mysql_fetch_all($sql); // has account to receive, return value if (count($data) > 0) { // get amount return $data[0]['balance']; } else { if (count($data) == 0) { // create account // check if there is a user entry but no UUID $sql2 = "SELECT balance FROM `minecraft_iconomy`.`mineconomy_accounts` WHERE account='{$user}';"; $data2 = umc_mysql_fetch_all($sql2); if (count($data2) == 1) { // yes, add the UUID $fix_sql = "UPDATE `minecraft_iconomy`.`mineconomy_accounts`\r\n\t\t SET uuid='{$uuid}'\r\n WHERE account='{$user}';"; umc_mysql_query($fix_sql, true); // try again return umc_money_check($user); } else { // insert row $sql3 = "INSERT INTO `minecraft_iconomy`.`mineconomy_accounts` (`uuid`, `account`, `balance`)\r\n VALUES ('{$uuid}', '{$user}', '100');"; umc_mysql_query($sql3, true); return 0; } } } }
function umc_user_directory() { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); // list all users $username_get = filter_input(INPUT_GET, 'u', FILTER_SANITIZE_STRING); if (!is_null($username_get)) { $O = array(); $wordpress_id = umc_user_get_wordpress_id($username_get); $username = strtolower(umc_check_user($username_get)); if (!$wordpress_id) { return "User does not exist!"; } $uuid = umc_user2uuid($username); // check if the user is active $count_lots = umc_user_countlots($uuid); if ($count_lots == 0) { return "User is not active!"; } // user icon $O['User'] = get_avatar($wordpress_id, $size = '96') . "<p><strong>Username:</strong> {$username}</p>\n" . "<p><strong>UUID:</strong> {$uuid}</p>\n"; $previous_names = umc_uuid_username_history($uuid); if ($previous_names) { $O['User'] .= "<p><strong>Usernames History:</strong> {$previous_names}</p>\n"; } // is user banned? if (umc_user_is_banned($uuid)) { $O['User'] .= "<p><strong>User is BANNED!</strong></p>\n"; return; } // get userlevel $level = umc_get_uuid_level($uuid); $karma = umc_getkarma($uuid, true); $money = umc_money_check($uuid); $O['User'] .= "<p><strong>Level:</strong> {$level}</p>\n" . "<p><strong>Karma:</strong> {$karma}</p>\n" . "<p><strong>Money:</strong> {$money} Uncs</p>\n"; // get lots $lots = umc_user_getlots($uuid); foreach ($lots as $data) { $world = ucwords($data['world']); $combined_worlds = array('Empire', 'Flatlands', 'Skyblock'); if (in_array($world, $combined_worlds)) { $world = 'Small lots'; } if (!isset($O[$world])) { $O[$world] = ''; } $O[$world] .= $data['image']; } $donator_level = umc_users_donators($uuid); if ($donator_level > 12) { $donator_str = 'More than 1 year'; } else { if ($donator_level) { $donator_level_rounded = round($donator_level, 1); $donator_str = "{$donator_level_rounded} Months"; } else { $donator_str = "Not a donator"; } } $O['User'] .= "<p><strong>Donations remaining:</strong> {$donator_str}</p>\n"; // get member since $online_time = umc_get_lot_owner_age('days', $uuid); if ($online_time) { $lastlogin = $online_time[$uuid]['lastlogin']['days']; $firstlogin = $online_time[$uuid]['firstlogin']['days']; $O['User'] .= "<p><strong>Member since:</strong> {$firstlogin} days</p>\n" . "<p><strong>Offline since:</strong> {$lastlogin} days</p>\n"; } // get user bio $sql = "SELECT meta_value FROM minecraft.wp_users\r\n LEFT JOIN minecraft.wp_usermeta ON wp_users.ID = wp_usermeta.user_id\r\n WHERE display_name='{$username}' AND meta_key='description';"; $D = umc_mysql_fetch_all($sql); if (count($D) > 0) { $row = $D[0]; $O['User'] .= "<p><strong>Bio:</strong> " . $row['meta_value'] . "</p>\n"; } // comments $sql2 = "SELECT comment_date, comment_author, id, comment_id, post_title FROM minecraft.wp_comments\r\n LEFT JOIN minecraft.wp_posts ON comment_post_id=id\r\n WHERE comment_author = '{$username}' AND comment_approved='1' AND id <> 'NULL'\r\n ORDER BY comment_date DESC"; $D2 = umc_mysql_fetch_all($sql2); if (count($D2) > 0) { $O['Comments'] = "<strong>Comments:</strong> (" . count($D2) . ")\n<ul>\n"; foreach ($D2 as $row) { $O['Comments'] .= "<li>" . $row['comment_date'] . " on <a href=\"/index.php?p=" . $row['id'] . "#comment-" . $row['comment_id'] . "\">" . $row['post_title'] . "</a></li>\n"; } $O['Comments'] .= "</ul>\n"; } //forum posts $sql3 = "SELECT wpp.id AS id, wpp.post_title AS title, wpp.post_date AS date,\r\n\t\twpp.post_parent AS parent, wpp.post_type AS type, parent.post_title AS parent_title\r\n FROM minecraft.wp_posts AS wpp\r\n\t LEFT JOIN minecraft.wp_users ON wpp.post_author=wp_users.id\r\n\t LEFT JOIN minecraft.wp_posts AS parent ON parent.id=wpp.post_parent\r\n\t WHERE wp_users.display_name='{$username}'\r\n\t\tAND (wpp.post_type='reply' OR wpp.post_type='topic')\r\n\t\tAND wpp.post_status='publish'\r\n\t ORDER BY wpp.post_date DESC"; $D3 = umc_mysql_fetch_all($sql3); // echo $sql; if (count($D3) > 0) { $O['Forum'] = "<strong>Forum Posts:</strong> (" . count($D3) . ")\n<ul>\n"; foreach ($D3 as $row) { $date = $row['date']; if ($row['type'] == 'reply') { $link = $row['parent'] . "#post-" . $row['id']; $title = $row['parent_title']; } else { $link = $row['id']; $title = $row['title']; } $O['Forum'] .= "<li>{$date} on <a href=\"/index.php?p={$link}\">{$title}</a></li>\n"; } $O['Forum'] .= "</ul>\n"; } echo umc_jquery_tabs($O); } else { // $bans = umc_get_banned_users(); //var_dump($bans); $out = "<script type=\"text/javascript\" src=\"/admin/js/jquery.dataTables.min.js\"></script>\n" . "<script type=\"text/javascript\">\n" . 'jQuery(document).ready(function() {jQuery' . "('#shoptable_users').dataTable( {\"order\": [[ 2, \"desc\" ]],\"paging\": false,\"ordering\": true,\"info\": true} );;} );\n" . "</script>\n" . "This table only tracks online time since 2013-11-20.<br>" . '<table id="shoptable_users"><thead>' . "<th>Username</th>" . "<th>Level</th>" . "<th>Registered days</th>" . "<th>Offline days</th>" . "<th>Lots</th>" . "<th>Online min/day</th>" . "<th>Online hrs</th>" . "</thead>\n<tbody>\n"; $sql = "SELECT username, DATEDIFF(NOW(),firstlogin) as registered_since, parent as userlevel, count(owner) as lot_count, onlinetime, DATEDIFF(NOW(), lastlogin) as days_offline\r\n FROM minecraft_srvr.UUID\r\n LEFT JOIN minecraft_srvr.permissions_inheritance ON UUID.uuid=child\r\n LEFT JOIN minecraft_worldguard.user ON UUID.uuid = user.uuid\r\n LEFT JOIN minecraft_worldguard.region_players ON user.id=region_players.user_id\r\n WHERE owner = 1 AND firstlogin >'0000-00-00 00:00:00' AND username <> '_abandoned_'\r\n GROUP BY username, owner\r\n ORDER BY firstlogin"; $rst = umc_mysql_query($sql); $now = time(); // or your date as well $your_date = strtotime("2013-11-20"); $datediff = $now - $your_date; $alt_days = floor($datediff / (60 * 60 * 24)); while ($row = umc_mysql_fetch_array($rst)) { $days_offline = $row['days_offline']; $settler_levels = array('Settler', 'SettlerDonator', 'SettlerDonatorPlus'); if (in_array($row['userlevel'], $settler_levels) && $row['onlinetime'] >= 60) { umc_promote_citizen(strtolower($row['username']), $row['userlevel']); } if ($row['registered_since'] - $days_offline > 1) { if ($alt_days < $row['registered_since']) { // people who are not in the lb-players database should not be listed, they are too old if ($alt_days - $days_offline == 0) { continue; } $avg_online = floor($row['onlinetime'] / 60 / $alt_days); } else { $avg_online = floor($row['onlinetime'] / 60 / $row['registered_since']); } } else { $avg_online = 0; } $online_total = round($row['onlinetime'] / 60 / 60); $icon_url = umc_user_get_icon_url($row['username']); $out .= "<tr>" . "<td><img title='{$row['username']}' src='{$icon_url}' alt=\"{$row['username']}\"> <a href=\"?u={$row['username']}\">{$row['username']}</a></td>" . "<td>{$row['userlevel']}</td>" . "<td class='numeric_td'>{$row['registered_since']}</td>" . "<td class='numeric_td'>{$days_offline}</td>" . "<td class='numeric_td'>{$row['lot_count']}</td>" . "<td class='numeric_td'>{$avg_online}</td>" . "<td class='numeric_td'>{$online_total}</td>" . "</tr>\n"; } $out .= "</tbody>\n</table>\n"; echo $out; } }
function umc_home_sell() { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); global $UMC_USER; $args = $UMC_USER['args']; $count = umc_home_count(); $cost = umc_home_calc_costs($count) / 2; if (!isset($args[2])) { umc_error("{red}You need to specify which home you wish to sell"); } else { $name = umc_mysql_real_escape_string(trim($args[2])); $name_check = umc_home_count($name); if ($name_check == 0) { umc_error("{red}You do not have a home with that name!"); } } umc_money(false, $UMC_USER['uuid'], $cost); $bank = umc_money_check($UMC_USER['uuid']); $newcount = $count - 1; $sql = "DELETE FROM minecraft_srvr.`homes` WHERE uuid='{$UMC_USER['uuid']}' AND name={$name};"; umc_mysql_query($sql, true); umc_header("Selling a home"); umc_echo("You currently have {$count} homes, selling one."); umc_echo("This home sell earns you {$cost} Uncs! You now have {$bank} Uncs in your account."); umc_echo("Your home slot has been sold successfully sold, you now have {$newcount} homes."); umc_footer(); umc_log('home', 'sell', "{$UMC_USER['uuid']}/{$UMC_USER['username']} sold the home called {$args[2]}!"); }
function umc_trivia_answer() { global $UMC_USER; $player = $UMC_USER['username']; $args = $UMC_USER['args']; $quiz_arr = umc_trivia_get_current_quiz(); $quiz_id = $quiz_arr['id']; $question_no = $quiz_arr['question_no']; $master = $quiz_arr['master']; $balance = umc_money_check($player); $price = $quiz_arr['price']; if (!$quiz_arr) { umc_error("There is no active quiz to answer questions for. Please start one first."); } else { if ($player == $master) { umc_error("You cannot answer your own question!"); } else { if (!$quiz_arr['question_no']) { umc_error("There is no question asked for the current trivia yet. Please wait!"); } else { if ($quiz_arr['status'] != 'asked') { umc_error("The last question was closed already. Please wait for the next one to be asked!"); } else { if (!isset($args[2])) { umc_error("You have to provide an answer!"); } else { if (!$balance || $balance < $price) { umc_error("Answering costs {$price} Uncs, but you do not have that much money!"); } else { if (count($quiz_arr['users']) > 0 && in_array($player, $quiz_arr['users'])) { umc_error("You have already answered that question!"); } } } } } } } $answer_raw = ''; for ($i = 2; $i < count($args); $i++) { $answer_raw .= " " . $args[$i]; } $answer = trim($answer_raw); umc_header("Trivia Quiz No.{$quiz_id} Question No.{$question_no}"); umc_echo("You answer: {$answer}"); umc_echo("Thanks for answering! Your account was debited {$price} Uncs!"); umc_footer(true); // register answer umc_money($player, false, $price); $answer_str = umc_mysql_real_escape_string($answer); $sql = "INSERT INTO minecraft_quiz.quiz_answers (quiz_id, question_id, answer_text, username, time, result)\r\n VALUES ({$quiz_arr['id']}, {$quiz_arr['question_id']}, {$answer_str}, '{$player}', NOW(), 'wrong');"; umc_mysql_query($sql); // message the quizmaster umc_exec_command("----------------- New Trivia Answer -----------------", 'toPlayer', $master); umc_exec_command("\"{$answer}\"", 'toPlayer', $master); umc_exec_command("To display all current answers, use /trivia check", 'toPlayer', $master); umc_exec_command("--------------------------------------------------", 'toPlayer', $master); umc_log('trivia', 'answer', "{$player} answered trivia {$quiz_id} question id {$quiz_arr['question_id']}"); }
/** * 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}"); }