/**
 * Removes an item from stock or deposit; does not record the transaction
 *
 * @param type $table
 * @param type $id
 * @param type $amount
 * @param type $player
 * @return int
 */
function umc_db_take_item($table, $id, $amount, $player)
{
    // $uuid = umc_uuid_getone($player, 'uuid');
    $D = umc_mysql_fetch_all("SELECT amount FROM minecraft_iconomy.{$table} WHERE id='{$id}';");
    $amount_row = $D[0];
    $newstock = $amount_row['amount'] - $amount;
    if ($table == 'stock') {
        if ($newstock == 0) {
            $sql = "DELETE FROM minecraft_iconomy.stock WHERE id='{$id}';";
            umc_log('shop', 'stock_adjust', "Cleared all content from stock for ID {$id} by withdrawing {$amount_row['amount']}");
        } else {
            $sql = "UPDATE minecraft_iconomy.stock SET amount={$newstock} WHERE id='{$id}';";
            umc_log('shop', 'stock_adjust', "Changed stock level for ID {$id} from {$amount_row['amount']} to {$newstock}");
        }
    } else {
        // take from deposit
        if ($newstock == 0) {
            $sql = "DELETE FROM minecraft_iconomy.deposit WHERE id='{$id}';";
            umc_log('shop', 'deposit_adjust', "Cleared all content from deposit for ID {$id} by withdrawing {$amount_row['amount']}");
        } else {
            $sql = "UPDATE minecraft_iconomy.deposit SET amount={$newstock} WHERE id='{$id}';";
            umc_log('shop', 'deposit_adjust', "Changed deposit level for ID {$id} from {$amount_row['amount']} to {$newstock}");
        }
    }
    umc_mysql_query($sql, true);
    // check stock levels
    $sql = "SELECT * FROM minecraft_iconomy.{$table} WHERE id={$id};";
    $D2 = umc_mysql_fetch_all($sql);
    if (count($D2)) {
        return $D2[0]['amount'];
    } else {
        return 0;
    }
}
function umc_contests_status()
{
    global $UMC_SETTING;
    $status_arr = array('voting', 'active');
    $out = '<ul>';
    foreach ($status_arr as $status) {
        $sql = "SELECT title, id from 'minecraft_srvr.contest_contests WHERE status='{$status}' ORDER by id ASC;";
        $D = umc_mysql_fetch_all($sql);
        if (count($D) > 0) {
            $title = ucfirst("{$status}:");
            $out .= "<li><strong>{$title}</strong>";
            $out .= "<ul>";
            foreach ($D as $row) {
                $link = $UMC_SETTING['path']['url'] . "/contestsmanager/?action=show_contest&type=" . $row['id'];
                $out .= "<li><a href=\"{$link}\">{$row['title']}</a></li>";
            }
            $out .= "</ul></li>";
        }
    }
    $out .= "</ul>";
    echo $out;
}
function umc_ticket_close()
{
    global $WSEND;
    $player = $WSEND['player'];
    $player_id = umc_user_id($player);
    $args = $WSEND['args'];
    if (!isset($args[1]) && !isset($args[2])) {
        umc_show_help($args);
        die;
    }
    $key = intval($args[2]);
    if (!is_numeric($key)) {
        umc_error("Invalid ticket ID");
    }
    $sql = "SELECT * FROM minecraft.wp_wpscst_tickets WHERE user_id={$player_id} AND resolution LIKE 'Open' AND primkey='{$key}';";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) == 0) {
        umc_error("Ticket ID {$key} not found!");
    }
    $sql2 = "UPDATE minecraft.`wp_wpscst_tickets` SET `resolution` = 'Closed' WHERE `primkey`={$key};";
    umc_mysql_fetch_all($sql2);
    umc_echo("Ticket ID {$key} was successfully closed!");
}
示例#4
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;
    }
}
/**
 * shows a graphic of the shop trading volume in pieces and values over time
 */
function umc_shopmgr_stats()
{
    global $UMC_DOMAIN;
    $sql = "SELECT DATE_FORMAT(`date`,'%Y-%u') AS week, SUM(amount) AS amount, SUM(cost) AS value\r\n        FROM minecraft_iconomy.transactions\r\n        WHERE date>'2012-03-00 00:00:00'\r\n\t    AND seller_uuid NOT LIKE 'cancel%'\r\n\t    AND buyer_uuid NOT LIKE 'cancel%'\r\n\tGROUP BY week;";
    $D = umc_mysql_fetch_all($sql);
    //$maxval_amount = 0;
    //$maxval_value = 0;
    //$minval = 0;
    $ydata = array();
    $lines = array('Amount', 'Value');
    $out = "<script type='text/javascript' src=\"{$UMC_DOMAIN}/admin/js/amcharts.js\"></script>\n" . "<script type='text/javascript' src=\"{$UMC_DOMAIN}/admin/js/serial.js\"></script>\n" . "<div id=\"chartdiv\" style=\"width: 100%; height: 362px;\"></div>\n" . "<script type='text/javascript'>//<![CDATA[\n" . "var chart;\n" . "var chartData = [\n";
    //
    foreach ($D as $row) {
        //$maxval_amount = max($maxval_amount, $row['amount']);
        //$maxval_value = max($maxval_value, $row['value']);
        $date = $row['week'];
        $ydata[$date]['Amount'] = $row['amount'];
        $ydata[$date]['Value'] = round($row['value']);
    }
    foreach ($ydata as $date => $date_sites) {
        $out .= "{\"date\": \"{$date}\",";
        foreach ($date_sites as $date_site => $count) {
            $out .= "\"{$date_site}\": {$count},";
        }
        $out .= "},\n";
    }
    $out .= "];\n";
    $out .= 'AmCharts.ready(function () {
    // SERIAL CHART
    chart = new AmCharts.AmSerialChart();
    chart.pathToImages = "http://www.amcharts.com/lib/3/images/";
    chart.dataProvider = chartData;
    chart.marginTop = 10;
    chart.categoryField = "date";

    // AXES
    // Category
    var categoryAxis = chart.categoryAxis;
    categoryAxis.gridAlpha = 0.07;
    categoryAxis.axisColor = "#DADADA";
    categoryAxis.startOnAxis = true;

    // Value
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.id = "Amount";
    valueAxis.gridAlpha = 0.07;
    valueAxis.title = "Amount";
    valueAxis.position = "left";
    chart.addValueAxis(valueAxis);

    // Amount
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.id = "Value";
    valueAxis.gridAlpha = 0.07;
    valueAxis.title = "Value";
    valueAxis.position = "right";
    chart.addValueAxis(valueAxis);';
    foreach ($lines as $line) {
        if ($line == 'Value') {
            $index = 'Uncs';
        } else {
            $index = 'Units';
        }
        $out .= "var graph = new AmCharts.AmGraph();\r\n        graph.valueAxis = \"{$line}\"\r\n        graph.type = \"line\";\r\n        graph.hidden = false;\r\n        graph.title = \"{$line}\";\r\n        graph.valueField = \"{$line}\";\r\n        graph.lineAlpha = 1;\r\n        graph.fillAlphas = 0.6; // setting fillAlphas to > 0 value makes it area graph\r\n        graph.balloonText = \"<span style=\\'font-size:12px; color:#000000;\\'><b>[[value]]</b> {$index}</span>\";\r\n        chart.addGraph(graph);";
    }
    $out .= '// LEGEND
        var legend = new AmCharts.AmLegend();
        legend.position = "top";
        legend.valueText = "[[value]]";
        legend.valueWidth = 100;
        legend.valueAlign = "left";
        legend.equalWidths = false;
        legend.periodValueText = "total: [[value.sum]]"; // this is displayed when mouse is not over the chart.
        chart.addLegend(legend);

        // CURSOR
        var chartCursor = new AmCharts.ChartCursor();
        chartCursor.cursorAlpha = 0;
        chart.addChartCursor(chartCursor);

        // SCROLLBAR
        var chartScrollbar = new AmCharts.ChartScrollbar();
        chartScrollbar.color = "#FFFFFF";
        chart.addChartScrollbar(chartScrollbar);

        // WRITE
        chart.write("chartdiv");
        });
        //]]></script>';
    return $out;
}
/**
 * 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;
    }
}
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}");
        }
    }
}
示例#8
0
function umc_mod_warp_lot()
{
    global $UMC_USER;
    $args = $UMC_USER['args'];
    if (!isset($args[2])) {
        umc_show_help($args);
        die;
    }
    $lot = strtolower($args[2]);
    $world = umc_get_lot_world($lot);
    $playerworld = $UMC_USER['world'];
    if ($world != $playerworld) {
        umc_ws_cmd("mv tp {$world}", 'asPlayer');
    }
    $sql = "SELECT min_x, min_z FROM minecraft_worldguard.`region_cuboid` WHERE region_id='{$lot}';";
    $D = umc_mysql_fetch_all($sql);
    $row = $D[0];
    $x = $row['min_x'];
    $z = $row['min_z'];
    $y = 70;
    umc_ws_cmd("tppos {$x} {$y} {$z} 135", 'asPlayer');
}
示例#9
0
/**
 * returns likely accounts shared by UUIDs
 * 
 */
function umc_web_usercheck()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $tables = array('Same IP' => 'last_ip', 'Same Browser' => 'browser_id', 'Same TeamSpeak' => 'ts_uuid');
    $out = '';
    foreach ($tables as $table_name => $crit_field) {
        $sql = "SELECT {$crit_field} FROM minecraft_srvr.UUID WHERE {$crit_field} <> '' " . "GROUP BY {$crit_field} HAVING count({$crit_field}) > 1 ORDER BY count({$crit_field}) DESC, onlinetime DESC";
        $L = umc_mysql_fetch_all($sql);
        $out_arr = array();
        foreach ($L as $l) {
            $line_sql = "SELECT username, userlevel, lot_count, onlinetime, INET_NTOA(last_ip) as ip, " . "CONCAT(browser_id, '<br>', ts_uuid) AS 'Browser & TS ID' " . "FROM minecraft_srvr.UUID WHERE {$crit_field} = '{$l[$crit_field]}'" . "ORDER BY onlinetime DESC";
            $D = umc_mysql_fetch_all($line_sql);
            foreach ($D as $d) {
                $out_arr[] = $d;
            }
        }
        $out .= umc_web_table($table_name, 0, $out_arr, "<h2>{$table_name}</h2>");
    }
    return $out;
}
示例#10
0
function umc_donation_level($user, $debug = false)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $U = umc_uuid_getboth($user);
    $uuid = $U['uuid'];
    $username = $U['username'];
    $debug_txt = '';
    global $UMC_SETTING;
    $date_now = new DateTime("now");
    $sql = "SELECT amount, date FROM minecraft_srvr.donations WHERE uuid='{$uuid}';";
    $level = umc_get_uuid_level($uuid);
    if ($level == 'Owner') {
        return false;
    }
    $D = umc_mysql_fetch_all($sql);
    // if there are 0 donations, user should not be changes
    if (count($D) == 0 && strstr($level, "Donator")) {
        XMPP_ERROR_trigger("User {$username} ({$uuid}) never donated but has a donator level ({$level})");
    } else {
        if (count($D) == 0) {
            $debug_txt .= "{$username} ({$uuid}) does not have any donations\n";
            return;
        }
    }
    $debug_txt .= "Checking donation upgrade of user {$username}, current UserLevel: {$level}\n";
    $donation_level = 0;
    // go through all donations and find out how much is still active
    foreach ($D as $row) {
        $date_donation = new DateTime($row['date']);
        $interval = $date_donation->diff($date_now);
        $years = $interval->format('%y');
        $months = $interval->format('%m');
        $donation_term = $years * 12 + $months;
        $donation_leftover = $row['amount'] - $donation_term;
        if ($donation_leftover < 0) {
            $donation_leftover = 0;
            // do not create negative carryforward
        }
        $donation_level = $donation_level + $donation_leftover;
        $debug_txt .= "Amount donated {$row['amount']} {$years} years {$months} m ago = {$donation_term} months ago, {$donation_leftover} leftover, level: {$donation_level}\n";
    }
    $donation_level_rounded = ceil($donation_level);
    // get userlevel and check if demotion / promotion is needed
    $debug_txt .= "user {$username} ({$uuid}) has donation level of {$donation_level_rounded}, now is {$level}\n";
    // current userlevel
    $ranks_lvl = array_flip($UMC_SETTING['ranks']);
    $cur_lvl = $ranks_lvl[$level];
    // get current promotion level
    if (strpos($level, 'DonatorPlus')) {
        $current = 2;
    } else {
        if (strpos($level, 'Donator')) {
            $current = 1;
        } else {
            $current = 0;
        }
    }
    // get future promotion level
    if (count($D) == 0) {
        // this never happens since it's excluded above
        $future = 0;
    } else {
        if ($donation_level_rounded >= 1) {
            $future = 2;
        } else {
            if ($donation_level_rounded < 1) {
                $future = 1;
            }
        }
    }
    $debug_txt .= "future = {$future}, current = {$current}\n";
    $change = $future - $current;
    if ($change == 0) {
        $debug_txt .= "User has right level, nothing to do\n";
        return false;
        // bail if no change needed
    } else {
        // we have a change in level, let's get an error report
        $debug = true;
    }
    $debug_txt .= "User will change {$change} levels\n";
    // get currect rank index
    $debug_txt .= "Current Rank index = {$cur_lvl}\n";
    // calculate base level
    $base_lvl = $cur_lvl - $current;
    $debug_txt .= "User base level = {$base_lvl}\n";
    $new_lvl = $base_lvl + $future;
    if ($new_lvl == $cur_lvl) {
        XMPP_ERROR_send_msg("Donations upgrade: Nothing to do, CHECK this should have bailed earlier!");
        return false;
    }
    $new_rank = $UMC_SETTING['ranks'][$new_lvl];
    $debug_txt .= "User {$username} upgraded from {$level} to {$new_rank}\n";
    umc_exec_command("pex user {$uuid} group set {$new_rank}");
    umc_log('Donations', 'User Level de/promotion', "User {$username} upgraded from {$level} to {$new_rank}");
    if ($debug) {
        XMPP_ERROR_send_msg($debug_txt);
    }
    return $donation_level_rounded;
    // . "($donation_level $current - $future - $change)";
}
示例#11
0
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();
}
示例#12
0
function umc_get_code()
{
    $chars = "abcdefghijkmnopqrstuvwxyz023456789";
    srand((double) microtime() * 1000000);
    $i = 0;
    $pass = '';
    while ($i <= 4) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    $sql = "SELECT * FROM minecraft_iconomy.story WHERE code='{$pass}';";
    $D3 = umc_mysql_fetch_all($sql);
    $count = count($D3);
    if ($count > 0) {
        umc_get_code();
    }
    return $pass;
}
示例#13
0
function umc_web_userstats()
{
    global $UMC_DOMAIN, $UMC_SETTING;
    $sql = 'SELECT count(UUID) as count, SUBSTRING(userlevel,1,1) as level, DATE_FORMAT(firstlogin, "%Y-%u") as date FROM minecraft_srvr.UUID WHERE firstlogin > 0 GROUP BY SUBSTRING(userlevel,1,1), DATE_FORMAT(firstlogin,"%Y-%u")';
    $D = umc_mysql_fetch_all($sql);
    $X = array();
    foreach ($D as $row) {
        if ($row['level'] == 'G') {
            $level = 'Guest';
        } else {
            $level = 'Settler';
        }
        $X[$row['date']][$level] = $row['count'];
    }
    $out = '<h2>User stats:</h2>';
    //$maxval = 0;
    //$minval = 0;
    $out .= "\n<script type='text/javascript' src=\"{$UMC_DOMAIN}/admin/js/amcharts.js\"></script>\n" . "<script type='text/javascript' src=\"{$UMC_DOMAIN}/admin/js/serial.js\"></script>\n" . "<div id=\"chartdiv\" style=\"width: 100%; height: 362px;\"></div>\n" . "<script type='text/javascript'>//<![CDATA[\n" . "var chart;\n" . "var chartData = [\n";
    foreach ($X as $date => $data_set) {
        $out .= "{\"date\": \"{$date}\", ";
        foreach ($data_set as $date_site => $count) {
            $out .= "\"{$date_site}\": {$count},";
        }
        $out .= "},\n";
    }
    $out .= "];\n";
    $out .= 'AmCharts.ready(function () {
    // SERIAL CHART
    chart = new AmCharts.AmSerialChart();
    chart.pathToImages = "http://www.amcharts.com/lib/3/images/";
    chart.dataProvider = chartData;
    chart.marginTop = 10;
    chart.categoryField = "date";

    // AXES
    // Category
    var categoryAxis = chart.categoryAxis;
    categoryAxis.gridAlpha = 0.07;
    categoryAxis.axisColor = "#DADADA";
    categoryAxis.startOnAxis = true;

    // Value
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.stackType = "regular"; // this line makes the chart "stacked"
    valueAxis.gridAlpha = 0.07;
    valueAxis.title = "Sign-ons";
    chart.addValueAxis(valueAxis);';
    $levels = array('Guest', 'Settler');
    // $UMC_SETTING['ranks'];
    foreach ($levels as $level) {
        $out .= "\nvar graph = new AmCharts.AmGraph();\n            graph.type = \"line\";\n            graph.hidden = false;\n            graph.title = \"{$level}\";\n            graph.valueField = \"{$level}\";\n            graph.lineAlpha = 1;\n            graph.fillAlphas = 0.6; // setting fillAlphas to > 0 value makes it area graph\n            graph.balloonText = \"<span style=\\'font-size:12px; color:#000000;\\'>{$level}: <b>[[value]]</b></span>\";\n            chart.addGraph(graph);\n";
    }
    $out .= '// LEGEND
        var legend = new AmCharts.AmLegend();
        legend.position = "top";
        legend.valueText = "[[value]]";
        legend.valueWidth = 100;
        legend.valueAlign = "left";
        legend.equalWidths = false;
        legend.periodValueText = "total: [[value.sum]]"; // this is displayed when mouse is not over the chart.
        chart.addLegend(legend);

        // CURSOR
        var chartCursor = new AmCharts.ChartCursor();
        chartCursor.cursorAlpha = 0;
        chart.addChartCursor(chartCursor);

        // SCROLLBAR
        var chartScrollbar = new AmCharts.ChartScrollbar();
        chartScrollbar.color = "#FFFFFF";
        chart.addChartScrollbar(chartScrollbar);

        // WRITE
        chart.write("chartdiv");
        });
        //]]></script>';
    return $out;
}
示例#14
0
function umc_log_kill_display()
{
    global $UMC_USER, $UMC_DOMAIN;
    $out = '';
    $line_limit = 1000;
    if (!$UMC_USER) {
        $out = "Please <a href=\"{$UMC_DOMAIN}/wp-login.php\">login</a>!";
        return $out;
    }
    $userlevel = $UMC_USER['userlevel'];
    $admins = array('Owner', 'Elder', 'ElderDonator', 'ElderDonatorPlus');
    if (!in_array($userlevel, $admins)) {
        return "This page is admin-only!";
    }
    $worlds = array('empire', 'kingdom');
    $usernames = umc_logblock_get_usernames();
    $post_world = filter_input(INPUT_POST, 'world', FILTER_SANITIZE_STRING);
    $post_killer = filter_input(INPUT_POST, 'killer', FILTER_SANITIZE_STRING);
    $post_lot = filter_input(INPUT_POST, 'lot', FILTER_SANITIZE_STRING);
    $post_line = filter_input(INPUT_POST, 'line', FILTER_SANITIZE_STRING);
    // world filter
    if (isset($post_world)) {
        if (!in_array($post_world, $worlds)) {
            $out .= "<h2>World cannot be found!</h2>";
        }
    } else {
        $post_world = 'empire';
    }
    $world_filter = "lb-{$post_world}-kills";
    // lot filter
    $lots = umc_logblock_get_lots($post_world);
    $lot_filter = '';
    if (isset($post_lot) && $post_lot != 'none') {
        if (!in_array($post_lot, $lots)) {
            $out .= "<h2>Lot cannot be found!</h2>";
        } else {
            $lot_filter = umc_logblock_get_coord_filter_from_lot($post_lot);
        }
    } else {
        $post_lot = '';
    }
    // user filter
    $killer_filter = '';
    if (isset($post_killer) && $post_killer != 'none') {
        if (in_array($post_killer, $usernames)) {
            $killer_filter = "AND killers.playername='{$post_killer}'";
        } else {
            $out .= "<h2>Killer cannot be found!</h2>";
        }
    }
    // line filter
    if (!isset($post_line)) {
        $post_line = 0;
    }
    $count_sql = '';
    if (isset($_POST['today'])) {
        $count_sql = "SELECT count(id) as counter FROM `minecraft_log`.`{$world_filter}`\r\n            WHERE date=CURRENT_DATE() {$lot_filter};";
    } else {
        $count_sql = "SELECT count(id) as counter, playername as killer FROM `minecraft_log`.`{$world_filter}`\r\n            LEFT JOIN `minecraft_log`.`lb-players` as killers ON `{$world_filter}`.`killer`=`killers`.`playerid`\r\n            WHERE 1 {$killer_filter} {$lot_filter};";
    }
    // echo $count_sql;
    $D = umc_mysql_fetch_all($count_sql);
    $num_rows = $D[0]['counter'];
    // make a dropdown for the line to start in for pagination
    $lines = array();
    $line = 0;
    while ($line <= $num_rows - $line_limit) {
        $line += $line_limit;
        $max_limit = min($line + $line_limit - 1, $num_rows);
        $lines[$line] = $max_limit;
    }
    $badmobs = '(33,138,1114,1115,1117,1123,1126,1128,1129,1131,1136,1930)';
    if (isset($_POST['today'])) {
        $sql = "SELECT id, date, weapon, x,y,z, victims.playername AS victim, killers.playername AS killer FROM `minecraft_log`.`{$world_filter}`\r\n            LEFT JOIN `minecraft_log`.`lb-players` as victims ON `{$world_filter}`.`victim`=`victims`.`playerid`\r\n            LEFT JOIN `minecraft_log`.`lb-players` as killers ON `{$world_filter}`.`killer`=`killers`.`playerid`\r\n            WHERE date=CURRENT_DATE() AND killers.playerid NOT IN {$badmobs} AND victims.playerid NOT IN {$badmobs} {$lot_filter}\r\n            ORDER BY `date` DESC LIMIT {$post_line},{$line_limit};";
    } else {
        $sql = "SELECT id, date, weapon, x,z,y, victims.playername AS victim, killers.playername AS killer FROM `minecraft_log`.`{$world_filter}`\r\n            LEFT JOIN `minecraft_log`.`lb-players` as victims ON `{$world_filter}`.`victim`=`victims`.`playerid`\r\n            LEFT JOIN `minecraft_log`.`lb-players` as killers ON `{$world_filter}`.`killer`=`killers`.`playerid`\r\n            WHERE killers.playerid NOT IN {$badmobs} AND victims.playerid NOT IN {$badmobs} {$killer_filter} {$lot_filter}\r\n            ORDER BY `id` DESC LIMIT {$post_line},{$line_limit};";
    }
    $out .= "<form action=\"\" method=\"post\">\n" . "World: <select name=\"world\">";
    $selected = array();
    $selected[$post_world] = " selected=\"selected\"";
    foreach ($worlds as $one_world) {
        $sel_str = '';
        if (isset($selected[$one_world])) {
            $sel_str = $selected[$one_world];
        }
        $out .= "<option value=\"{$one_world}\"{$sel_str}>{$one_world}</option>";
    }
    $out .= "</select> Lot: <select name=\"lot\"><option value=\"none\">All</option>";
    $selected = array();
    $selected[$post_lot] = " selected=\"selected\"";
    foreach ($lots as $one_lot) {
        $sel_str = '';
        if (isset($selected[$one_lot])) {
            $sel_str = $selected[$one_lot];
        }
        $out .= "<option value=\"{$one_lot}\"{$sel_str}>{$one_lot}</option>";
    }
    $out .= "</select> Killer: <select name=\"killer\"><option value=\"none\">All</option>";
    $selected = array();
    $selected[$post_killer] = " selected=\"selected\"";
    foreach ($usernames as $one_username) {
        $sel_str = '';
        if (isset($selected[$one_username])) {
            $sel_str = $selected[$one_username];
        }
        $out .= "<option value=\"{$one_username}\"{$sel_str}>{$one_username}</option>";
    }
    $out .= "</select> Line: <select name=\"line\"><option value=\"0\">0 -> 999</option>";
    $selected = array();
    $selected[$post_line] = " selected=\"selected\"";
    foreach ($lines as $one_line => $next_line) {
        $sel_str = '';
        if (isset($selected[$one_line])) {
            $sel_str = $selected[$one_line];
        }
        $out .= "<option value=\"{$one_line}\"{$sel_str}>{$one_line} -> {$next_line}</option>";
    }
    $out .= "</select><input type=\"submit\" name=\"proposebutton\" value=\"Check\">" . "<input type=\"submit\" name=\"today\" value=\"Today only\"></form>";
    $out .= "<table style=\"font-size:80%\" class=\"log_table\">\n<tr><th>ID</th><th>Date</th><th>Time</th><th>Killer</th><th>Weapon</th><th>Victim</th><th>Lot</th><th>Coordinates</th></tr>\n";
    $yesterday = '';
    $D = umc_mysql_fetch_all($sql);
    foreach ($D as $row) {
        $row_style = '';
        $date_arr = explode(" ", $row['date']);
        if ($yesterday != $date_arr[0]) {
            $row_style = ' style="background-color:#CCCCCC;"';
        }
        $one_lot = umc_logblock_get_lot_from_coord($post_world, $row['x'], $row['z']);
        $weapon = $remove_item = umc_logores_item_name($row['weapon']);
        $killer = $row['killer'];
        if ($killer == 'Arrow') {
            $weapon = $killer;
            $killer = '?';
        }
        $out .= "<tr{$row_style}><td>{$row['id']}</td><td>{$date_arr[0]}</td><td>{$date_arr[1]}</td><td>{$killer}</td><td>{$weapon}</td><td>{$row['victim']}</td><td>{$one_lot}</td><td>{$row['x']} / {$row['y']} / {$row['z']}</td></tr>";
        $yesterday = $date_arr[0];
    }
    $out .= "</table>\n";
    return $out;
}
function umc_trivia_webstats()
{
    $out = '<table>';
    $quiz_sql = "SELECT * FROM minecraft_quiz.quizzes WHERE end <> '' ORDER BY start DESC;";
    $D = umc_mysql_fetch_all($quiz_sql);
    foreach ($D as $quiz_row) {
        $quiz_id = $quiz_row['quiz_id'];
        $master = $quiz_row['master'];
        $quiz_start = $quiz_row['start'];
        $quiz_end = $quiz_row['end'];
        $winner = $quiz_row['winner'];
        $points = $quiz_row['points'];
        $prize = $quiz_row['points'];
        $out .= "<tr style=\"background-color:#99CCFF;\"><td>Quiz No.{$quiz_id}, Quizmaster: {$master}</td><td>Start: {$quiz_start}</td></tr>";
        $out .= "<tr><td colspan=2>Winner: {$winner} with {$points} points won {$prize} Uncs each</tr>";
        $datetime = umc_datetime($quiz_start);
        $seconds = umc_timer_raw_diff($datetime);
        $days = $seconds / 60 / 60 / 24;
        if ($days > 3) {
            continue;
        }
        $question_sql = "SELECT question_no, question, answer, quiz_questions.question_id FROM minecraft_quiz.quiz_questions\r\n            LEFT JOIN minecraft_quiz.catalogue ON quiz_questions.question_id = catalogue.question_id\r\n            WHERE quiz_id = {$quiz_id} ORDER BY question_no;";
        $Q = umc_mysql_fetch_all($question_sql);
        foreach ($Q as $question_row) {
            $question_no = $question_row['question_no'];
            $question_id = $question_row['question_id'];
            $question = $question_row['question'];
            $answer = $question_row['answer'];
            $out .= "<tr style=\"font-size:70%; background-color:#99FFCC;\"><td style=\"padding-left:40px\">Q. No.{$question_no}: {$question}</td><td>A.: {$answer}</td></tr>";
            $answer_sql = "SELECT * FROM minecraft_quiz.quiz_answers WHERE quiz_id={$quiz_id} AND question_id={$question_id} ORDER BY answer_id;";
            $A = umc_mysql_fetch_all($answer_sql);
            $out .= "<tr style=\"font-size:70%;\"><td style=\"padding-left:80px\" colspan=2>";
            foreach ($A as $answer_row) {
                $answer_id = $answer_row['answer_id'];
                $user_answer = $answer_row['answer_text'];
                $username = $answer_row['username'];
                $result = $answer_row['result'];
                $style = "style=\"margin-right:10px;\"";
                if ($result == 'right') {
                    $style = " style=\"color:green; margin-right:10px;\"";
                }
                $out .= "<span {$style}>{$answer_id} ({$username}): {$user_answer}</span>";
            }
            $out .= "</td></tr>";
        }
    }
    $out .= "</table>";
    return $out;
}
function umc_skyblock_web_display_table($sub_id)
{
    $sql = "SELECT * FROM minecraft_quiz.block_challenges WHERE sub_challenge={$sub_id} ORDER BY challenge_id";
    $D = umc_mysql_fetch_all($sql);
    $out = '';
    if (count($D) == 0) {
        return false;
    }
    $padding = ' colspan=2';
    $tab = '';
    if ($sub_id > 0) {
        $padding = '';
        $tab = '<td style="width:50px"></td>';
    }
    foreach ($D as $row) {
        if ($row['win_conditions'] == NULL) {
            $winning = 'No Winning conditions, open game';
        } else {
            $winning = umc_skyblock_inv_to_desc($row['win_conditions']);
        }
        if ($sub_id == 0) {
            $out .= "<tr style=\"background-color:#99ccff; font-weight:bold;\">{$tab}<td style=\"white-space:nowrap;\">{$row['challenge_id']}: {$row['name']}</td><td{$padding}>{$row['desc']}</td></tr>\n";
            $inventory = umc_skyblock_inv_to_desc($row['inventory']);
            $out .= "<tr style=\"font-size:70%;\"><td><strong>Starting Inventory:</strong></td><td{$padding}>{$inventory}</td></tr>\n";
            $out .= "<tr style=\"font-size:70%;\">{$tab}<td><strong>Winning items:</strong></td><td{$padding}>{$winning}</td></tr>\n";
        } else {
            $out .= "<tr style=\"font-size:70%;\"><td><strong>Name: {$row['name']}</strong></td><td><strong>Winning items:</strong> {$winning}</td></tr>\n";
        }
        $id = $row['challenge_id'];
        $sub_challenge = umc_skyblock_web_display_table($id);
        if ($sub_challenge) {
            $out .= "<tr style=\"background-color:#C2E0FF; font-size:90%;\"><td>Sub-challenges:</td><td style=\"font-size:70%\">(continue to above challenge until you get all below targets!)</td></tr>" . $sub_challenge;
        }
    }
    return $out;
}
/**
 * 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;
            }
        }
    }
}
/**
 * Get a UUID from the wp_username
 *
 * @param string $uuid
 * @return string
 */
function umc_wp_get_uuid_for_currentuser()
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    $current_user = wp_get_current_user();
    $username = $current_user->display_name;
    if ($username == '') {
        // we have a guest, get UUID from system instead
        return false;
    }
    $username_sql = umc_mysql_real_escape_string($username);
    $sql = "SELECT meta_value as uuid FROM minecraft.wp_usermeta\r\n        LEFT JOIN minecraft.wp_users ON ID=user_id\r\n        WHERE display_name={$username_sql} AND meta_key ='minecraft_uuid' LIMIT 1;";
    $data = umc_mysql_fetch_all($sql);
    if (count($data) == 0) {
        return false;
    }
    $out = strtolower($data[0]['uuid']);
    return $out;
}
示例#19
0
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();
}
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();
}
/**
 * Count the amount of time a user has failed the settler test
 *
 * @param string $username
 * @return int amount of fails
 */
function umc_settler_get_fails($username)
{
    $sql = "SELECT count(log_id) as counter FROM minecraft_log.`universal_log` WHERE action='step_1_fail' AND username='******';";
    $data = umc_mysql_fetch_all($sql);
    if (count($data) > 0) {
        $count = $data[0]['counter'];
        return $count;
    } else {
        return 0;
    }
}
function umc_lottery_web_stats()
{
    global $UMC_DOMAIN;
    // get a timestamp 6 months ago
    $old_date = date("Y-m-d H:i:s", strtotime("-6 months"));
    $yesterday = date("Y-m-d H:i:s", strtotime("-1 day"));
    $sql = "SELECT count( vote_id ) AS vote_count, website, DATE_FORMAT(`datetime`,'%Y-%m-%d') AS date\r\n        FROM minecraft_log.votes_log\r\n        WHERE website <> 'minecraftservers' AND datetime > '{$old_date}' AND datetime < '{$yesterday}'\r\n        GROUP BY website, DAY( `datetime` ),MONTH( `datetime` ), YEAR( `datetime` )\r\n        ORDER BY YEAR( `datetime` ) , MONTH( `datetime` ), DAY( `datetime` ) ";
    $D = umc_mysql_fetch_all($sql);
    $out = '<h2>Voting stats for the last 6 months:</h2>';
    $maxval = 0;
    $minval = 0;
    $legend = array();
    $ydata = array();
    $sites = array();
    $out .= "\n<script type='text/javascript' src=\"{$UMC_DOMAIN}/admin/js/amcharts.js\"></script>\n" . "<script type='text/javascript' src=\"{$UMC_DOMAIN}/admin/js/serial.js\"></script>\n" . "<div id=\"chartdiv\" style=\"width: 100%; height: 362px;\"></div>\n" . "<script type='text/javascript'>//<![CDATA[\n" . "var chart;\n" . "var chartData = [\n";
    //
    foreach ($D as $row) {
        $maxval = max($maxval, $row['vote_count']);
        $minval = min($minval, $row['vote_count']);
        $date = $row['date'];
        $legend[$date] = $date;
        if ($row['website'] == 'mcsl') {
            $site = 'minecraft-server-list.com';
        } else {
            $site = $row['website'];
        }
        $sites[$site] = $site;
        $ydata[$date][$site] = $row['vote_count'];
    }
    foreach ($ydata as $date => $date_sites) {
        $out .= "{\"date\": \"{$date}\",";
        foreach ($date_sites as $date_site => $count) {
            $out .= "\"{$date_site}\": {$count},";
        }
        $out .= "},\n";
    }
    $out .= "];\n";
    $out .= 'AmCharts.ready(function () {
    // SERIAL CHART
    chart = new AmCharts.AmSerialChart();
    chart.pathToImages = "http://www.amcharts.com/lib/3/images/";
    chart.dataProvider = chartData;
    chart.marginTop = 10;
    chart.categoryField = "date";

    // AXES
    // Category
    var categoryAxis = chart.categoryAxis;
    categoryAxis.gridAlpha = 0.07;
    categoryAxis.axisColor = "#DADADA";
    categoryAxis.startOnAxis = true;

    // Value
    var valueAxis = new AmCharts.ValueAxis();
    valueAxis.stackType = "regular"; // this line makes the chart "stacked"
    valueAxis.gridAlpha = 0.07;
    valueAxis.title = "Votes";
    chart.addValueAxis(valueAxis);';
    foreach ($sites as $site) {
        $out .= "var graph = new AmCharts.AmGraph();\r\n        graph.type = \"line\";\r\n        graph.hidden = false;\r\n        graph.title = \"{$site}\";\r\n        graph.valueField = \"{$site}\";\r\n        graph.lineAlpha = 1;\r\n        graph.fillAlphas = 0.6; // setting fillAlphas to > 0 value makes it area graph\r\n        graph.balloonText = \"<span style=\\'font-size:12px; color:#000000;\\'>{$site}: <b>[[value]]</b></span>\";\r\n        chart.addGraph(graph);";
    }
    $out .= '// LEGEND
        var legend = new AmCharts.AmLegend();
        legend.position = "top";
        legend.valueText = "[[value]]";
        legend.valueWidth = 100;
        legend.valueAlign = "left";
        legend.equalWidths = false;
        legend.periodValueText = "total: [[value.sum]]"; // this is displayed when mouse is not over the chart.
        chart.addLegend(legend);

        // CURSOR
        var chartCursor = new AmCharts.ChartCursor();
        chartCursor.cursorAlpha = 0;
        chart.addChartCursor(chartCursor);

        // SCROLLBAR
        var chartScrollbar = new AmCharts.ChartScrollbar();
        chartScrollbar.color = "#FFFFFF";
        chart.addChartScrollbar(chartScrollbar);

        // WRITE
        chart.write("chartdiv");
        });
        //]]></script>';
    return $out;
}
function umc_vanity_web()
{
    $sql = "SELECT name, value, username\r\n            FROM minecraft_srvr.permissions\r\n            LEFT JOIN minecraft_srvr.UUID ON name=UUID\r\n            WHERE permission='suffix' AND value NOT LIKE \"\" AND type=1\r\n            ORDER BY name;";
    $D = umc_mysql_fetch_all($sql);
    $out = "<table>\n<tr><th>No.</th><th>Username</th><th>Title</th></tr>\n";
    $count = 0;
    foreach ($D as $row) {
        $user = $row['username'];
        $count++;
        $title = $row['value'];
        $title_formatted = umc_mc_color_to_html("{$title}");
        $out .= "<tr><td>{$count}</td><td style=\"font-weight:bold;\">{$user}</td><td style=\"text-shadow:2px 2px #000; color:#fff; background-color:#777; padding:4px;\">{$title_formatted}</td></tr>\n";
    }
    $out .= "</table>\n";
    return $out;
}
示例#24
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.");
    }
}
示例#25
0
/**
 * tries to find a location far out that was not used as a hunger game before
 * this will also create the warp point in essentials
 *
 * @return array('x' => $center_x, 'z' => $center_z)
 */
function umc_hunger_find_random_location()
{
    // 30 Mio is the MC hard limit
    $min_val = 1000;
    $max_val = 30000000 - 2000;
    //we take the max and some margin
    // find a center
    $center_x = rand($min_val, $max_val);
    $center_z = rand($min_val, $max_val);
    // which quarter of the map?
    $dir_x = rand(0, 1);
    if ($dir_x == 0) {
        $center_x = $center_x * -1;
    }
    $dir_z = rand(0, 1);
    if ($dir_z == 0) {
        $center_z = $center_z * -1;
    }
    // check if a game existed on that location
    $sql = "SELECT id FROM minecraft_iconomy.hunger_games\r\n        WHERE x > ({$center_x} - 500)\r\n\t    AND x < ({$center_x} + 500)\r\n\t    AND z < ({$center_z} + 500)\r\n\t    AND z > ({$center_z} - 500);";
    $data = umc_mysql_fetch_all($sql);
    // too close, try again
    if (count($data) > 0) {
        umc_log('hunger', 'found_location_fail', "Found alrady existing location X: {$center_x} Z: {$center_z} - retrying");
        XMPP_ERROR_trigger("hunger rejected location X: {$center_x} Z: {$center_z}, trying again");
        return umc_hunger_find_random_location();
    } else {
        XMPP_ERROR_send_msg("hunger Found location X: {$center_x} Z: {$center_z}");
        // update warp point
        $text = "yaw: 0.0\nname: hunger\npitch: 0.0\nz: {$center_z}\ny: 250\nworld: hunger\nx: {$center_x}";
        $filename = '/home/minecraft/server/bukkit/plugins/Essentials/warps/hunger.yml';
        file_put_contents($filename, $text);
        // reload essentials
        umc_ws_cmd('ess reload', 'asConsole');
        return array('x' => $center_x, 'z' => $center_z);
    }
}
示例#26
0
function umc_timer_get($user, $type)
{
    // check if a timer is set
    $sql = "SELECT time_out FROM minecraft_srvr.timers WHERE username='******' AND type='{$type}';";
    $D = umc_mysql_fetch_all($sql);
    if (count($D) > 0) {
        // no, check if timed out
        $date_now = umc_datetime();
        // substract the current day
        $date_row = umc_datetime($D[0]['time_out']);
        // difference in seconds ofr check
        $diff = $date_row->getTimestamp() - $date_now->getTimestamp();
        if ($diff > 0) {
            return $date_row;
        } else {
            $sql_del = "DELETE FROM minecraft_srvr.timers WHERE username='******' AND type='{$type}';";
            umc_log('timer', 'removed', "{$type} timer for {$user}");
            umc_mysql_query($sql_del, true);
            return false;
        }
    } else {
        return false;
        // no such timer set
    }
}
示例#27
0
function umc_create_cuboids()
{
    //echo "Starting Map generation<br>";
    // are we enlarging an existing map?
    $enlarge = true;
    $maxval = 2176 + 4 * 272;
    // define future map size here
    $enlarge_by = 4;
    $blocksize = 272;
    $worldname = "draftlands";
    $lot_prefix = 'draft';
    $version = '0';
    // lot version
    // editing stop
    $divider = $maxval / $blocksize * 2;
    $startchar = 64;
    $startcol = 1;
    $new_regions = array();
    $old_regions = array();
    $world_id = umc_get_worldguard_id('world', strtolower($worldname));
    if ($enlarge) {
        // get existing lots, users, flags
        $region_sql = "SELECT * FROM minecraft_worldguard.region\r\n                LEFT JOIN minecraft_worldguard.region_cuboid ON id=region_id\r\n                WHERE id LIKE '{$lot_prefix}%';";
        $D = umc_mysql_fetch_all($region_sql);
        foreach ($D as $region_row) {
            $lot = $region_row['id'];
            $old_regions[$lot]['coords'] = array('min_x' => $region_row['min_x'], 'min_y' => $region_row['min_y'], 'min_z' => $region_row['min_z'], 'max_x' => $region_row['max_x'], 'max_y' => $region_row['max_y'], 'max_z' => $region_row['max_z']);
            $old_regions[$lot]['users'] = array();
            $user_sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id LIKE '{$lot}';";
            $D_user = umc_mysql_fetch_all($user_sql);
            foreach ($D_user as $user_row) {
                $user_id = $user_row['user_id'];
                $old_regions[$lot]['users'][$user_id] = $user_row['owner'];
            }
            $old_regions[$lot]['flags'] = array();
            $flags_sql = "SELECT * FROM minecraft_worldguard.region_flag WHERE region_id LIKE '{$lot}';";
            $D_flags = umc_mysql_fetch_all($flags_sql);
            if (count($D_flags) > 0) {
                foreach ($D_flags as $flags_row) {
                    $flag = $flags_row['flag'];
                    $old_regions[$lot]['flags'][$flag] = $flags_row['value'];
                }
            }
        }
    }
    // start at 0 - 0 on the top left corner
    for ($z = 1; $z <= $divider; $z++) {
        // go from left to right, 30 fields
        if ($z >= 27) {
            $char = 'A' . chr($startchar + ($z - 26));
        } else {
            $char = chr($startchar + $z);
        }
        //echo "iteration z = $z<br>";
        for ($x = 0; $x < $divider; $x++) {
            // go from up to down
            $left_b = $maxval - $z * $blocksize;
            $up_b = -1 * $maxval + $x * $blocksize;
            $num = $startcol + $x;
            $up_b2 = $up_b + $blocksize - 1;
            $left_b2 = $left_b + $blocksize - 1;
            $new_lot = strtolower($lot_prefix . '_' . $char . $num);
            $flags = array();
            $users = array();
            $flags_a = array();
            $flags_b = array();
            $flags_c = array();
            $users_a = array();
            $users_b = array();
            $users_c = array();
            $reset = "'reset'";
            if ($enlarge) {
                // get old lot name
                if ($z >= 27) {
                    $old_char = 'A' . chr($startchar + ($z - 26 - $enlarge_by));
                } else {
                    $old_char = chr($startchar + $z - $enlarge_by);
                }
                $old_num = $num - $enlarge_by;
                // numbers start at 0
                $old_lot = strtolower($lot_prefix . '_' . $old_char . $old_num);
                if (isset($old_regions[$old_lot])) {
                    $flags = $old_regions[$old_lot]['flags'];
                    $users = $old_regions[$old_lot]['users'];
                    $reset = 'NULL';
                    if ($worldname == 'kingdom' || $worldname == 'draftlands') {
                        $flags_a = $old_regions[$old_lot . "_a"]['flags'];
                        $flags_b = $old_regions[$old_lot . "_b"]['flags'];
                        $flags_c = $old_regions[$old_lot . "_c"]['flags'];
                        $users_a = $old_regions[$old_lot . "_a"]['users'];
                        $users_b = $old_regions[$old_lot . "_b"]['users'];
                        $users_c = $old_regions[$old_lot . "_c"]['users'];
                    }
                }
            }
            if ($worldname !== 'kingdom' && $worldname !== 'draftlands') {
                $new_regions[$new_lot] = array('coords' => array('min_x' => $up_b, 'min_y' => 0, 'min_z' => $left_b, 'max_x' => $up_b2, 'max_y' => 256, 'max_z' => $left_b2), 'flags' => $flags, 'users' => $users, 'reset' => $reset);
            } else {
                $new_regions[$new_lot] = array('coords' => array('min_x' => $up_b, 'min_y' => 0, 'min_z' => $left_b, 'max_x' => $up_b2 - 16, 'max_y' => 256, 'max_z' => $left_b2 - 16), 'flags' => $flags, 'users' => $users, 'reset' => $reset);
                $new_regions[$new_lot . "_a"] = array('coords' => array('min_x' => $up_b2 - 15, 'min_y' => 0, 'min_z' => $left_b, 'max_x' => $up_b2, 'max_y' => 256, 'max_z' => $left_b2 - 16), 'flags' => $flags_a, 'users' => $users_a, 'reset' => $reset);
                $new_regions[$new_lot . "_b"] = array('coords' => array('min_x' => $up_b2 - 15, 'min_y' => 0, 'min_z' => $left_b2 - 15, 'max_x' => $up_b2, 'max_y' => 256, 'max_z' => $left_b2), 'flags' => $flags_b, 'users' => $users_b, 'reset' => $reset);
                $new_regions[$new_lot . "_c"] = array('coords' => array('min_x' => $up_b, 'min_y' => 0, 'min_z' => $left_b2 - 15, 'max_x' => $up_b2 - 16, 'max_y' => 256, 'max_z' => $left_b2), 'flags' => $flags_c, 'users' => $users_c, 'reset' => $reset);
            }
        }
    }
    $region_sql = 'INSERT INTO minecraft_worldguard.`region` (`id`, `world_id`, `type`, `priority`, `parent`) VALUES ';
    $cuboid_sql = 'INSERT INTO minecraft_worldguard.`region_cuboid` (`region_id`, `world_id`, `min_x`, `min_y`, `min_z`, `max_x`, `max_y`, `max_z`) VALUES ';
    $player_sql = 'INSERT INTO minecraft_worldguard.`region_players` (`region_id`, `world_id`, `user_id`, `owner`) VALUES ';
    $flags_sql = 'INSERT INTO minecraft_worldguard.`region_flag` (`world_id`, `region_id`, `flag`, `value`) VALUES ';
    $version_sql = 'INSERT INTO minecraft_srvr.`lot_version`(`lot`, `version`, `choice`, `timestamp`, `mint_version`) VALUES ';
    foreach ($new_regions as $lot => $data) {
        $region_sql .= "\n('{$lot}',{$world_id},'cuboid',0,NULL), ";
        $coords = $data['coords'];
        $cuboid_sql .= "\n('{$lot}',{$world_id},{$coords['min_x']},{$coords['min_y']},{$coords['min_z']},{$coords['max_x']},{$coords['max_y']},{$coords['max_z']}), ";
        $version_sql .= "\n('{$lot}','{$version}',{$data['reset']},NOW(),'{$version}'), ";
        foreach ($data['users'] as $user_id => $owner) {
            $player_sql .= "\n('{$lot}',{$world_id},{$user_id},{$owner}), ";
        }
        foreach ($data['flags'] as $flag => $value) {
            $flags_sql .= "\n({$world_id},'{$lot}','{$flag}','{$value}'), ";
        }
    }
    echo "DELETE FROM  minecraft_worldguard.region WHERE id LIKE '{$lot_prefix}_%';\n";
    echo "DELETE FROM  minecraft_srvr.lot_version WHERE lot LIKE '{$lot_prefix}_%';\n";
    echo rtrim($region_sql, ", ") . ";\n";
    echo rtrim($cuboid_sql, ", ") . ";\n";
    echo rtrim($player_sql, ", ") . ";\n";
    echo rtrim($flags_sql, ", ") . ";\n";
    echo rtrim($version_sql, ", ") . ";\n";
}
示例#28
0
function umc_get_userinfo($user_raw)
{
    $username = strtolower($user_raw);
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    // get registration date from Wordpress
    $uuid = umc_user2uuid($username);
    $user['uuid'] = $uuid;
    // get userlevel, balance, onlinetime
    $sql = "SELECT userlevel, onlinetime, lastlogin, lastlogout, username, UUID.UUID, balance, lot_count, firstlogin\r\n        FROM minecraft_srvr.UUID\r\n        LEFT JOIN minecraft_iconomy.mineconomy_accounts ON UUID.`UUID` = mineconomy_accounts.uuid\r\n        WHERE UUID.`UUID` = '{$uuid}'";
    $D = umc_mysql_fetch_all($sql);
    $d = $D[0];
    if ($d['userlevel'] == null) {
        $level = 'Guest';
    } else {
        $level = $d['userlevel'];
    }
    $username_history = umc_uuid_username_history($uuid);
    if ($username_history) {
        $user['Username History'] = $username_history;
    }
    $user['Level'] = $level;
    $user['Last Seen'] = $d['lastlogin'];
    if ($d['onlinetime'] == NULL) {
        $online_time = "n/a";
    } else {
        $online_time = umc_seconds_to_time($d['onlinetime']);
    }
    $firstdate = substr($d['firstlogin'], 0, 10);
    $today_ts = strtotime("now");
    $firsttime_ts = strtotime($firstdate);
    $days = round(abs($today_ts - $firsttime_ts) / 60 / 60 / 24);
    $user['User since'] = "{$firstdate} ({$days} days)";
    if ($firstdate > '2013-11-20') {
        // not all play time recorded
        $user['Online time since 2013-11-20'] = $online_time;
    } else {
        $user['Online time'] = $online_time;
    }
    if ($d['balance'] == NULL) {
        $user['Uncs'] = '0.00';
    } else {
        $user['Uncs'] = number_format($d['balance'], 2, ".", "'");
    }
    $user['First login'] = $d['firstlogin'];
    $homes_count = umc_home_count(false, $uuid);
    $user['Homes count'] = $homes_count;
    $karma = umc_getkarma($user['uuid'], true);
    $user['Karma'] = $karma;
    $lots = umc_user_getlots($uuid);
    $display_lots = array();
    foreach ($lots as $lot => $data) {
        $display_lots[$data['world']][] = $lot;
    }
    foreach ($display_lots as $world => $lots) {
        $World = ucfirst($world);
        if (count($lots) < 5) {
            $user["{$World} lots"] = implode(", ", $lots);
        } else {
            $user["{$World} lots"] = count($lots) . " lots";
        }
    }
    return $user;
}
function umc_check_lot_exists($world_id, $lot)
{
    XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    if (!is_numeric($world_id)) {
        $world_id = umc_get_worldguard_id('world', $world_id);
    }
    //  Make sure the region exists
    $sql = "SELECT id FROM minecraft_worldguard.region WHERE world_id = {$world_id} AND id = '{$lot}'";
    //echo $sql;
    $C = umc_mysql_fetch_all($sql);
    if (count($C) < 1) {
        // echo("No such region '$lot' found in world '$world_id'");
        return false;
    }
    return true;
}
<?php

require_once 'includes/mysql.inc.php';
$sql = "SELECT id FROM minecraft_srvr.`contest_contests` WHERE `status` = 'active';";
$D = umc_mysql_fetch_all($sql);
$contest_id = $D[0]['id'];
echo "Making inventory of Contest {$contest_id}:\n";
$lot_name = "con_" . $contest_id . "_%";
$sql2 = "SELECT * FROM minecraft_worldguard.region_cuboid LEFT JOIN world ON region_cuboid.world_id=world.id WHERE region_id LIKE '{$lot_name}';";
$D = $entry = umc_mysql_fetch_all($sql2);
foreach ($D as $entry) {
    $world_name = $entry['name'];
    $lot_name = $entry['region_id'];
    echo "Processing lot {$lot_name} in {$world_name}...";
    // ./minecount -wc -b "-16,0,-16 -1,256,-1" ../../world world-blocks.json^M
    $blocks = "{$entry[min_x]},{$entry[min_y]},{$entry[min_z]} {$entry[max_x]},{$entry[max_y]},{$entry[max_z]}";
    $server_path = $UMC_PATH_MC . '/server';
    $tool_path = $server_path . '/minecount/minecount -wc -b "' . $blocks . '"';
    $world_path = $server_path . '/bukkit/' . $world_name;
    $data_path = $server_path . '/minecount/output/' . $lot_name . '.json';
    $cmd = "{$tool_path} {$world_path} {$data_path}";
    exec($cmd);
    echo "Done!\n";
}