コード例 #1
0
function Get_Player_Stats_ByWorld($playerid, $worldid)
{
    // Get ID of players whose names partially match the search parameter
    Use_DB("xray");
    $sql_PlayerStats = "SELECT * FROM `x-stats`";
    $sql_PlayerStats .= "    WHERE `playerid` = {$playerid} AND `worldid` = {$worldid}";
    //echo "SQL QUERY: <BR>" . $sql_PlayerIDexists . "<BR>";
    $res_PlayerStats = mysql_query($sql_PlayerStats) or die("Get_Player_Stats_ByWorld: " . mysql_error());
    while (($PlayerStatsArray[] = mysql_fetch_assoc($res_PlayerStats)) || array_pop($PlayerStatsArray)) {
    }
    if (mysql_num_rows($res_PlayerStats) > 0) {
        return $PlayerStatsArray;
    } else {
        return false;
    }
}
コード例 #2
0
function Add_NewBreaks()
{
    // Detect datetime of most recent break
    // This prevents omitting any breaks that occurr during this script
    $datetime_now = new DateTime();
    $sql_getdate = "";
    foreach ($GLOBALS['worlds'] as $world_index => $world_item) {
        if ($world_index > 0) {
            $sql_getdate .= " UNION ALL";
        }
        $sql_getdate .= " SELECT '" . $world_item["worldid"] . "' AS worldid, MAX(date) AS latest_break_date";
        $sql_getdate .= " FROM `lb-" . $world_item["worldname"] . "`";
        $sql_getdate .= " WHERE  replaced = 1";
        $sql_getdate .= "     OR replaced = 15";
        $sql_getdate .= "     OR replaced = 14";
        $sql_getdate .= "     OR replaced = 56";
        $sql_getdate .= "     OR replaced = 25";
        $sql_getdate .= "     OR replaced = 48";
        $sql_getdate .= "     AND type = 0";
    }
    //echo "SQL_QUERY: <br>". $sql_getdate . "<br>";
    $res_getdate = mysql_query($sql_getdate) or die("World-LatestBreakDate: " . mysql_error());
    while (($LatestDateArray[] = mysql_fetch_assoc($res_getdate)) || array_pop($LatestDateArray)) {
    }
    //echo "LATEST_DATE_ARRAY: <BR>"; print_r($LatestDateArray); echo "<BR>";
    foreach ($GLOBALS['worlds'] as $world_index => $world_item) {
        echo "====================================================<br>";
        echo "Processing World [" . $world_item["worldalias"] . "]<BR>";
        // Check for latest date entry in X-Stats Table
        echo "...This world was last checked on: " . $world_item["last_date_processed"] . "<BR>";
        //TODO: Change format to TIME AGO
        $found_break = false;
        foreach ($LatestDateArray as $wdate_item) {
            //echo "WORLD ID COMPARE [". $wdate_item["worldid"] . "] vs [" . $world_item["worldid"] . "]<BR>";
            if ($wdate_item["worldid"] == $world_item["worldid"]) {
                $found_break = true;
                $latest_break_date = $wdate_item["latest_break_date"];
                if ($latest_break_date == "") {
                    $wdate_item["latest_break_date"] = "NEVER (No logs)";
                    $latest_break_date = $datetime_now->format('Y-m-d H:i:s');
                }
                echo "...The last break in this world occurred on: " . $wdate_item["latest_break_date"] . "<BR>";
            }
        }
        if (!$found_break) {
            echo "...This world has no mining history. Aborting scan.<br>";
        }
        if ($latest_break_date == $world_item["last_date_processed"]) {
            echo "...There is no new information to process in this world. Skipping scan.<BR>";
        } else {
            if ($found_break) {
                // Get ALL new breaks after latest_date_processed
                echo "...Beginning User Scan, Please Be Patient...";
                Use_DB("xray");
                $sql_newbreaks = "INSERT INTO `x-stats` ";
                $sql_newbreaks .= " (`playerid`, `worldid`, `diamond_count`, `gold_count`, `lapis_count`, `mossy_count`, `iron_count`, `stone_count`) ";
                $sql_newbreaks .= " SELECT p.playerid, '" . $world_item["worldid"] . "', IFNULL(diamond_info.cnt,0) AS diamond_count, IFNULL(gold_info.cnt,0) AS gold_count, ";
                $sql_newbreaks .= " \tIFNULL(lapis_info.cnt,0) AS lapis_count, IFNULL(mossy_info.cnt,0) AS mossy_count, IFNUlL(iron_info.cnt,0) AS iron_count, IFNULL(stone_info.cnt,0) AS stone_count";
                $sql_newbreaks .= " FROM `lb-players`";
                $sql_newbreaks .= " AS p";
                $sql_newbreaks .= " INNER JOIN (SELECT playerid, count(playerid) AS cnt FROM `lb-" . $world_item["worldname"] . "` ";
                $sql_newbreaks .= " \tWHERE ((date BETWEEN '" . $world_item["last_date_processed"] . "' AND '" . $latest_break_date . "') AND replaced = 1 AND type = 0 AND y <= 50) ";
                $sql_newbreaks .= " \tGROUP BY playerid) AS stone_info ON p.playerid = stone_info.playerid";
                $sql_newbreaks .= " LEFT JOIN (SELECT playerid, count(playerid) AS cnt FROM `lb-" . $world_item["worldname"] . "` ";
                $sql_newbreaks .= " \tWHERE ((date BETWEEN '" . $world_item["last_date_processed"] . "' AND '" . $latest_break_date . "') AND replaced = 56 AND type = 0 AND y <= 50) ";
                $sql_newbreaks .= " \tGROUP BY playerid) AS diamond_info ON p.playerid = diamond_info.playerid";
                $sql_newbreaks .= " LEFT JOIN (SELECT playerid, count(playerid) AS cnt FROM `lb-" . $world_item["worldname"] . "` ";
                $sql_newbreaks .= " \tWHERE ((date BETWEEN '" . $world_item["last_date_processed"] . "' AND '" . $latest_break_date . "') AND replaced = 14 AND type = 0 AND y <= 50) ";
                $sql_newbreaks .= " \tGROUP BY playerid) AS gold_info ON p.playerid = gold_info.playerid";
                $sql_newbreaks .= " LEFT JOIN (SELECT playerid, count(playerid) AS cnt FROM `lb-" . $world_item["worldname"] . "` ";
                $sql_newbreaks .= " \tWHERE ((date BETWEEN '" . $world_item["last_date_processed"] . "' AND '" . $latest_break_date . "') AND replaced = 15 AND type = 0 AND y <= 50) ";
                $sql_newbreaks .= " \tGROUP BY playerid) AS iron_info ON p.playerid = iron_info.playerid";
                $sql_newbreaks .= " LEFT JOIN (SELECT playerid, count(playerid) AS cnt FROM `lb-" . $world_item["worldname"] . "` ";
                $sql_newbreaks .= " \tWHERE ((date BETWEEN '" . $world_item["last_date_processed"] . "' AND '" . $latest_break_date . "') AND replaced = 48 AND type = 0 AND y <= 50) ";
                $sql_newbreaks .= " \tGROUP BY playerid) AS mossy_info ON p.playerid = mossy_info.playerid";
                $sql_newbreaks .= " LEFT JOIN (SELECT playerid, count(playerid) AS cnt FROM `lb-" . $world_item["worldname"] . "` ";
                $sql_newbreaks .= " \tWHERE ((date BETWEEN '" . $world_item["last_date_processed"] . "' AND '" . $latest_break_date . "') AND replaced = 21 AND type = 0 AND y <= 50) ";
                $sql_newbreaks .= " \tGROUP BY playerid) AS lapis_info ON p.playerid = lapis_info.playerid";
                $sql_newbreaks .= " GROUP BY p.playerid";
                $sql_newbreaks .= " ON DUPLICATE KEY UPDATE `diamond_count`=`diamond_count`+VALUES(diamond_count), `gold_count`=`gold_count`+VALUES(gold_count),";
                $sql_newbreaks .= " \t `lapis_count`=`lapis_count`+VALUES(lapis_count), `iron_count`=`iron_count`+VALUES(iron_count), `stone_count`=`stone_count`+VALUES(stone_count)";
                $res_newbreaks = mysql_query($sql_newbreaks);
                if (mysql_errno()) {
                    die("SQL_QUERY[newbreaks]: " . $sql_newbreaks . "<BR> " . mysql_error() . "<BR>");
                } else {
                    echo "DONE!<BR>";
                }
                //while(($BreaksArray[] = mysql_fetch_assoc($res_newbreaks)) || array_pop($BreaksArray));
                $stats_sql = GetMySQL_ResultStats();
                //echo "STATS_SQL: <BR>"; print_r($stats_sql); echo "<BR>";
                echo "-----------------------------------------------<br>";
                echo "Summary For World [" . $world_item["worldalias"] . "]<BR>";
                echo "-----------------------------------------------<br>";
                echo "..." . $stats_sql["records"] . " Users Processed.<BR>";
                echo "..." . ($stats_sql["records"] - $stats_sql["duplicates"]) . " New Users Found.<BR>";
                echo "..." . $stats_sql["duplicates"] . " Users Updated.<BR>";
                echo "-----------------------------------------------<br>";
                if ($latest_break_date != "") {
                    // Update World's LAST_PROCESSED_DATE to curent time
                    $sql_setdate = "UPDATE `x-worlds` SET `last_date_processed`='" . $latest_break_date . "' WHERE `worldid`='" . $world_item["worldid"] . "'";
                    //echo "SQL_QUERY: <br>". $sql_setdate . "<br>";
                    $res_setdate = mysql_query($sql_setdate) or die("SetDate([" . $world_item["worldalias"] . "] => '" . $latest_break_date . "'): " . mysql_error() . " SQL: [{$sql_setdate}]");
                }
            }
        }
    }
    Update_Stats_RatioTotals();
}
コード例 #3
0
<?php

require_once '../core_xdetector.php';
Global_Init();
Use_DB("source");
$sql_Get_All_Players = "SELECT `playername` FROM " . $GLOBALS['db']['table_players'] . " WHERE `playername` LIKE '%" . $_GET['term'] . "%' LIMIT 10";
//echo "SQL QUERY: <BR>" . $sql_Get_All_Players . "<BR>";
$res_Get_All_Players = @mysql_query($sql_Get_All_Players) or die(json_encode(array()));
$playername_array = array();
if (mysql_num_rows($res_Get_All_Players) > 0) {
    while (($Player_result[] = mysql_fetch_assoc($res_Get_All_Players)) || array_pop($Player_result)) {
    }
    foreach ($Player_result as $playername_item) {
        array_push($playername_array, $playername_item["playername"]);
    }
    //echo "Playernames: "; print_r($playername_array); echo "<BR>";
} else {
    echo json_encode(array());
}
echo json_encode($playername_array);
コード例 #4
0
function Do_Auth($ip_only = false)
{
    //echo "FIRST SETUP (Config): " . FixOutput_Bool($GLOBALS['config_settings']['settings']['first_setup'], "YES", "NO", "UNDEFINED") . "<BR>";
    // Force IP to match Failsafe IPs list if running setup for first time
    if (FixOutput_Bool($GLOBALS['config_settings']['settings']['first_setup'], true, false, true)) {
        session_unset();
        session_start();
        $_SESSION['first_setup'] = true;
        $ip_only = true;
    } else {
        if (!isset($_SESSION)) {
            session_start();
        }
        $_SESSION['first_setup'] = false;
    }
    // Initialize variables
    if (count($_GET) > 0) {
        $_POST = $_GET;
    }
    if (!isset($_POST['form'])) {
        $_POST['form'] = "";
    }
    if (!isset($_POST['submit'])) {
        $_POST['submit'] = "";
    }
    $IP_Users_list = array();
    $login_error = "";
    $logout_success = "";
    $_SESSION['auth_is_valid'] = false;
    $_SESSION['first_setup'] = FixOutput_Bool($GLOBALS['config_settings']['settings']['first_setup'], true, false, true);
    if (!$ip_only) {
        //echo "IP-Only Authentication is OFF.<BR>";
        if ($_SESSION['auth_is_valid'] == true) {
            /*
            echo "You are logged in!<br>";
            echo "User ID: " . $_SESSION['viewer_id'] . "<br>";
            echo "User Name: " . $_SESSION['viewer_name'] . "<br>";
            echo "Password: "******"<br>";
            */
        } else {
            Use_DB("source");
            //mysql_select_db($GLOBALS['db']['db_source']['base'], $GLOBALS['db']['s_resource']);
            $query_IP_Users = sprintf("SELECT * FROM `" . DB_Type_PlayersTable($GLOBALS['db']['type']) . "` WHERE ip LIKE %s ORDER BY playername ASC", GetSQLValueString("%" . $_SERVER['REMOTE_ADDR'] . "%", "text"));
            //echo "SQL[query_IP_Users]: <BR>". $query_IP_Users. "<BR>";
            $res_IP_Users = mysql_query($query_IP_Users, $GLOBALS['db']['s_resource']) or die(mysql_error());
            $totalRows_IP_Users = mysql_num_rows($res_IP_Users);
            // VALIDATE IP
            $ip_valid = false;
            if ($totalRows_IP_Users > 0) {
                while (($IP_Users_list[] = mysql_fetch_assoc($res_IP_Users)) || array_pop($IP_Users_list)) {
                }
            } else {
                //echo "WARNING: There are no known users with your IP.<BR>";
            }
            if ($_POST['form'] == "loginform") {
                //echo "Login form detected...<BR>";
                if ($GLOBALS['config_settings']['auth']['mode'] == "username") {
                    // VALIDATE IP
                    $ip_valid = false;
                    if ($totalRows_IP_Users > 0) {
                        //$playerid = $IP_Users_list[0]["playerid"];
                        $auth_allow_guest_users = FixInput_Bool($auth_allow_guest_users);
                        $auth_admin_usernames_exploded = explode(",", $GLOBALS['config']['auth']['admin_usernames']);
                        foreach ($auth_admin_usernames_exploded as &$input_fix_item) {
                            $input_fix_item = trim($input_fix_item);
                        }
                        $auth_mod_usernames_exploded = explode(",", $GLOBALS['config']['auth']['mod_usernames']);
                        foreach ($auth_mod_usernames_exploded as &$input_fix_item) {
                            $input_fix_item = trim($input_fix_item);
                        }
                        $auth_user_usernames_exploded = explode(",", $GLOBALS['config']['auth']['user_usernames']);
                        foreach ($auth_user_usernames_exploded as &$input_fix_item) {
                            $input_fix_item = trim($input_fix_item);
                        }
                        //echo "AUTH_ADMIN_USERNAMES: "; print_r($auth_admin_usernames_exploded); echo "<BR>";
                        //echo "AUTH_MOD_USERNAMES: "; print_r($auth_mod_usernames_exploded); echo "<BR>";
                        //echo "AUTH_USER_USERNAMES: "; print_r($auth_user_usernames_exploded); echo "<BR>";
                        foreach ($IP_Users_list as $auth_test_item) {
                            $ip_valid = true;
                            if ($auth_test_item["playername"] == $_GET['my_username']) {
                                foreach ($auth_admin_usernames_exploded as $admin_name_item) {
                                    if (!strnatcasecmp($admin_name_item, $auth_test_item["playername"])) {
                                        //echo "AUTH: VALID ADMINISTRATOR!<BR>";
                                        $_SESSION["auth_admin"] = true;
                                        $_SESSION["auth_level"] = "Administrator";
                                        break;
                                        $_SESSION["auth_username"] = $auth_test_item["playername"];
                                    }
                                }
                                foreach ($auth_mod_usernames_exploded as $mod_name_item) {
                                    if (!strnatcasecmp($mod_name_item, $auth_test_item["playername"])) {
                                        //echo "AUTH: VALID MODERATOR!<BR>";
                                        $_SESSION["auth_mod"] = true;
                                        $_SESSION["auth_level"] = "Moderator";
                                        break;
                                    }
                                }
                                foreach ($auth_user_usernames_exploded as $user_name_item) {
                                    if (!strnatcasecmp($user_name_item, $auth_test_item["playername"])) {
                                        //echo "AUTH: VALID USER!<BR>";
                                        $_SESSION["auth_user"] = true;
                                        $_SESSION["auth_level"] = "User";
                                        break;
                                    }
                                }
                                if ($_SESSION["auth_admin"] || $_SESSION["auth_mod"] || $_SESSION["auth_user"]) {
                                    $_SESSION["auth_type"] = $GLOBALS['config_settings']['auth']['mode'];
                                    $_SESSION["account"] = $auth_test_item;
                                    $_SESSION['auth_is_valid'] = true;
                                }
                            }
                        }
                    } else {
                        $login_error .= "ERROR: You do not have access to this page!<br>";
                        $_SESSION['auth_is_valid'] = false;
                    }
                } elseif ($GLOBALS['config_settings']['auth']['mode'] == "password") {
                    if ($_POST['login_password'] == "") {
                        $login_error .= "ERROR: Password cannot be blank!<br>";
                    }
                    if (!strnatcasecmp($GLOBALS['config']['auth']['admin_password'], $_POST['login_password'])) {
                        //echo "AUTH: VALID ADMINISTRATOR!<BR>";
                        $_SESSION["auth_admin"] = true;
                        $_SESSION["auth_level"] = "Administrator";
                    } elseif (!strnatcasecmp($GLOBALS['config']['auth']['mod_password'], $_POST['login_password'])) {
                        //echo "AUTH: VALID MODERATOR!<BR>";
                        $_SESSION["auth_mod"] = true;
                        $_SESSION["auth_level"] = "Moderator";
                    } elseif (!strnatcasecmp($GLOBALS['config']['auth']['user_password'], $_POST['login_password'])) {
                        //echo "AUTH: VALID USER!<BR>";
                        $_SESSION["auth_user"] = true;
                        $_SESSION["auth_level"] = "User";
                    }
                    if ($_SESSION["auth_admin"] || $_SESSION["auth_mod"] || $_SESSION["auth_user"]) {
                        $_SESSION["auth_type"] = $GLOBALS['config_settings']['auth']['mode'];
                        $_SESSION["account"] = false;
                        $_SESSION['auth_is_valid'] = true;
                    } else {
                        $login_error .= "ERROR: Incorrect password!<br>";
                        $_SESSION['auth_is_valid'] = false;
                    }
                }
            }
            if ($GLOBALS['config_settings']['auth']['mode'] == "none") {
                $_SESSION["auth_user"] = true;
                $_SESSION["auth_level"] = "Administrator";
                $_SESSION["auth_username"] = NULL;
            }
        }
    }
    if (!isset($_SESSION['auth_is_valid']) || !$_SESSION['auth_is_valid'] || $ip_only) {
        $auth_failsafe_ips_exploded = explode(",", $GLOBALS['config']['auth']['failsafe_ips']);
        foreach ($auth_failsafe_ips_exploded as &$input_fix_item) {
            $input_fix_item = trim($input_fix_item);
        }
        array_push($auth_failsafe_ips_exploded, "127.0.0.1", "::1");
        //echo "FAILSAFE_IPS: "; print_r($auth_failsafe_ips_exploded); echo "<BR>";
        foreach ($auth_failsafe_ips_exploded as $auth_test_item) {
            if ($_SERVER['REMOTE_ADDR'] == $auth_test_item) {
                $_SESSION["auth_admin"] = true;
                $_SESSION["auth_level"] = "Administrator";
                $_SESSION["auth_type"] = "ip";
                $_SESSION["account"] = false;
                $_SESSION['auth_is_valid'] = true;
                break;
            }
        }
    }
    if ($_POST['form'] == "logoutform" && $_POST['Submit'] == "Logout") {
        session_unset();
        $logout_success .= "You have been logged off successfully.<br>";
        $_SESSION['auth_is_valid'] = false;
        $_SESSION['first_setup'] = FixOutput_Bool($GLOBALS['config_settings']['settings']['first_setup'], true, false, true);
        $_SESSION['IP_Users_List'] = $IP_Users_list;
    }
    $GLOBALS['auth']['IP_Users_list'] = $IP_Users_list;
    //echo "FIRST SETUP (Session - Final): " . FixOutput_Bool($_SESSION['first_setup'], "YES", "NO", "UNDEFINED") . "<BR>";
    //echo "AUTH VALID (Session - Final): " . FixOutput_Bool($_SESSION['auth_is_valid'], "YES", "NO", "UNDEFINED") . "<BR>";
    return array("valid_ips" => $IP_Users_list, "login_error" => $login_error, "logout_success" => $logout_success);
}