Example #1
0
function buildFromList($chars)
{
    //Corps
    $corps = getCorps($chars);
    $alliances = getAlliances($chars);
    //Fill in the gaps left by unknowns
    $unknowns = getUnknown($chars);
    foreach ($unknowns as $u) {
        $u = getCharFromGate($u);
        //Try to find corp
        $found = false;
        for ($i = 0; $i < count($corps); $i++) {
            if ($corps[$i]['id'] == $u['corpId']) {
                $corps[$i]['quantity']++;
                $found = true;
                $i = count($corps);
            }
        }
        //Add corp if it wasn't found
        if ($found == false) {
            $corp['id'] = $u['corpId'];
            $corp['name'] = $u['corpName'];
            $corp['ticker'] = $u['corpTicker'];
            $corp['allianceId'] = $u['allianceId'];
            $corp['quantity'] = 1;
            $corps[] = $corp;
        }
        //Try to find alliance
        if ($u['alliance'] != false) {
            $found = false;
            for ($i = 0; $i < count($alliances); $i++) {
                if ($alliances[$i]['id'] == $u['allianceId']) {
                    $alliances[$i]['quantity']++;
                    $found = true;
                    $i = count($alliances);
                }
            }
            //Add alliance if it wasn't found
            if ($found == false) {
                $alliance['id'] = $u['allianceId'];
                $alliance['name'] = $u['allianceName'];
                $alliance['ticker'] = $u['allianceTicker'];
                $alliance['quantity'] = 1;
                $alliances[] = $alliance;
            }
        }
    }
    //Re-sort corps
    for ($i = 0; $i < count($corps); $i++) {
        $sort[$i] = $corps[$i]['quantity'];
    }
    arsort($sort);
    $sort = array_keys($sort);
    for ($i = 0; $i < count($corps); $i++) {
        $sorted[] = $corps[$sort[$i]];
    }
    $corps = $sorted;
    $sorted = array();
    unset($sort);
    //Re-sort alliances
    for ($i = 0; $i < count($alliances); $i++) {
        $sort[$i] = $alliances[$i]['quantity'];
    }
    arsort($sort);
    $sort = array_keys($sort);
    for ($i = 0; $i < count($alliances); $i++) {
        $sorted[] = $alliances[$sort[$i]];
    }
    $alliances = $sorted;
    //Build associations
    //Corp -> Alliance
    $assocs = array();
    foreach ($corps as $corp) {
        if ($corp['allianceId'] != "") {
            $assocs[$corp['id']][] = $corp['allianceId'];
        }
    }
    //Alliance -> Corp
    foreach ($alliances as $alliance) {
        foreach ($corps as $corp) {
            if ($corp['allianceId'] == $alliance['id']) {
                $assocs[$alliance['id']][] = $corp['id'];
            }
        }
    }
    //Build final return object
    $ret['corps'] = $corps;
    $ret['alliances'] = $alliances;
    $ret['assocs'] = $assocs;
    return $ret;
}
Example #2
0
<?php

error_reporting(E_ERROR | E_PARSE);
include "functions.php";
if (isset($argv[1])) {
    $scan = $argv[1];
} else {
    header('Content-Type:text/plain');
    $scan = "scans/" . $_GET['key'];
}
$list = file_get_contents($scan);
$list = explode("\n", $list);
foreach ($list as $name) {
    $u = getCharFromGate($name);
    echo sprintf("%-30s%-50s%-20s", $u['name'], $u['corpName'], $u['allianceName']) . "\n";
}