示例#1
0
function execute_examinefleet()
{
    global $uid;
    $its_fleet = new fleet($_GET["fid"]);
    $can_see = false;
    if ($its_fleet->uid == $uid) {
        show_svg_message("There should be no button that would allow you doing this. :S");
        return false;
    }
    $allies = get_allied_ids($uid);
    if (is_array($allies)) {
        array_push($allies, $uid);
    } else {
        $allies[] = $uid;
    }
    $allied_fleet = in_array($its_fleet->uid, $allies);
    // check ob eigene oder alleierte planeten im system sind
    $sth = mysql_query("select 1 from planets where sid=" . $its_fleet->sid . " and uid in (" . implode(",", $allies) . ") LIMIT 1");
    if (!$sth) {
        show_svg_message("There was an Database error #mcontrol:exec_exam_fleet:1");
        return false;
    }
    if (mysql_num_rows($sth) > 0) {
        $can_see = true;
    }
    // check ob eigene oder alleierte flotten im system sind
    if (!$can_see) {
        $sth = mysql_query("select 1 from fleet_info where sid=" . $its_fleet->sid . " and uid in (" . implode(",", $allies) . ") LIMIT 1");
        if (!$sth) {
            show_svg_message("There was an Database error #mcontrol:exec_exam_fleet:2");
            return false;
        }
        if (mysql_num_rows($sth) > 0) {
            $can_see = true;
        }
    }
    if (can_see) {
        $doc = domxml_new_doc("1.0");
        $rootElem = $doc->create_element("SR_REQUEST");
        $rootElem->set_attribute("type", "examine_fleet");
        $rootElem->set_attribute("fid", $its_fleet->fid);
        $rootElem->set_attribute("owner", $its_fleet->uid);
        $missionElem = $doc->create_element("SR_FLEET_MISSION");
        $no_scan = false;
        // mission
        if ($allied_fleet) {
            // alleierte Flotte, wir sehen die mission
            // mission kann sich unterscheiden wenn das ziel feindlich ist.
            $no_target = false;
            $target_relation = false;
            if ($its_fleet->tsid > 0 && $its_fleet->tpid > 0) {
                $sth = mysql_query("SELECT s.name as s_name, p.name, p.uid, p.type, p.id FROM systems s LEFT JOIN planets p on s.id = p.sid WHERE s.id = " . $its_fleet->tsid . " and p.id=" . $its_fleet->tpid);
            } elseif ($its_fleet->tsid > 0) {
                $sth = mysql_query("SELECT name as s_name from systems where id = " . $its_fleet->tsid);
            } else {
                $no_target = true;
            }
            if (!$no_target) {
                if (!$sth || mysql_num_rows($sth) == 0) {
                    show_svg_message("ERR::Can not get Target");
                    return false;
                }
                $target_info = mysql_fetch_assoc($sth);
                if ($target_info["s_name"]) {
                    $missionElem->set_attribute("tsys_name", htmlspecialchars($target_info["s_name"]));
                }
                if ($target_info["name"]) {
                    if ($target_info["name"] == "Unnamed") {
                        $target_info["name"] = get_planetname($target_info["id"]);
                    }
                    $missionElem->set_attribute("tpla_name", htmlspecialchars($target_info["name"]));
                    $missionElem->set_attribute("tpla_type", $target_info["type"]);
                    if ($target_info["uid"] > 0) {
                        $target_relation = get_uids_relation($its_fleet->uid, $target_info["uid"]);
                    }
                }
                $eta = get_true_ETA_by_fid($its_fleet->fid);
                $rootElem->set_attribute("eta", $eta);
            }
            switch ($its_fleet->mission) {
                case M_MOVE:
                    if ($target_relation == "enemy") {
                        $missionElem->set_attribute("mission", "fleet_mission_attack.svgz");
                        $missionElem->set_attribute("missionText", "Attacking");
                    } elseif ($target_relation == "allie" || $target_relation == "same" || $its_fleet->tsid == 0) {
                        $missionElem->set_attribute("mission", "fleet_mission_defend.svgz");
                        $missionElem->set_attribute("missionText", "Defending");
                    } else {
                        $missionElem->set_attribute("mission", "fleet_mission_move.svgz");
                        $missionElem->set_attribute("missionText", "Moving");
                    }
                    break;
                case M_INVADE:
                    $missionElem->set_attribute("mission", "fleet_mission_invade.svgz");
                    $missionElem->set_attribute("missionText", "Invading");
                    break;
                case M_BOMB:
                    $missionElem->set_attribute("mission", "fleet_mission_bomb.svgz");
                    $missionElem->set_attribute("missionText", "Bombarding");
                    break;
                case M_COLONIZE:
                    $missionElem->set_attribute("mission", "fleet_mission_colonize.svgz");
                    $missionElem->set_attribute("missionText", "Colonizing");
                    break;
            }
            $missionElem->set_attribute("tactic", $its_fleet->tactic);
        } else {
            $missionElem->set_attribute("mission", "fleet_mission_unknown.svgz");
            $missionElem->set_attribute("missionText", "unknown mission");
            $missionElem->set_attribute("tactic", "-1");
            // gucken ob wir no-scan schiffe haben (special 'N' in shipvalues)
            $sth = mysql_query("SELECT s.prod_id FROM fleet f, shipvalues s WHERE s.special = 'N' AND s.prod_id = f.prod_id AND f.fid = " . $its_fleet->fid);
            if (!$sth) {
                show_svg_message("ERROR::Getting NOSCAN ships");
                return false;
            }
            if (mysql_num_rows($sth) > 0) {
                $no_scan = true;
            }
            // gucken ob der planet vielleicht so nen gebäude hat??
            if (!$no_scan && $its_fleet->pid > 0) {
                // alleierte der flotte
                $fleet_allies = get_allied_ids($its_fleet->uid);
                if (is_array($fleet_allies)) {
                    array_push($fleet_allies, $its_fleet->uid);
                } else {
                    $fleet_allies[] = $its_fleet->uid;
                }
                $sth = mysql_query("SELECT s.prod_id FROM planets p, constructions c join shipvalues s using(prod_id) where s.special='N' and c.pid = p.id and p.id = " . $its_fleet->pid . " and p.uid in (" . implode(",", $fleet_allies) . ")");
                if (!$sth) {
                    show_svg_message("ERROR::Getting NOSCAN buildings");
                    return false;
                }
                if (mysql_num_rows($sth) > 0) {
                    $no_scan = true;
                }
            }
        }
        $rootElem->append_child($missionElem);
        // ships
        if (!$no_scan) {
            foreach ($its_fleet->ships as $prod_id => $values) {
                $shipElem = $doc->create_element("SR_SHIP");
                $shipElem->set_attribute("prod_id", $prod_id);
                $shipElem->set_attribute("count", $values[0]);
                if ($allied_fleet) {
                    $shipElem->set_attribute("reload", $values[1]);
                } else {
                    $shipElem->set_attribute("reload", -1);
                }
                $rootElem->append_child($shipElem);
            }
        }
        // admiral
        $sth = mysql_query("SELECT a.pic, a.name, a.id, a.fid from admirals a join fleet_info f using(fid) having a.fid=" . $its_fleet->fid . "");
        if (!$sth) {
            show_svg_message("There was an Database error #mcontrol:exec_exam_fleet:3");
            return false;
        }
        if (mysql_num_rows($sth) > 0) {
            list($a_pic, $a_name, $a_id) = mysql_fetch_row($sth);
            $admiralElem = $doc->create_element("SR_ADMIRAL");
            $admiralElem->set_attribute("name", $a_name);
            $admiralElem->set_attribute("pic", $a_pic);
            $admiralElem->set_attribute("level", get_admiral_level($a_id));
            $rootElem->append_child($admiralElem);
            $rootElem->set_attribute("pic", "ADMIRAL");
        } else {
            if (!$no_scan) {
                $rootElem->set_attribute("pic", get_strongest_ship_by_fid($its_fleet->fid));
            } else {
                $rootElem->set_attribute("pic", 0);
            }
        }
        $doc->append_child($rootElem);
        echo $doc->dump_mem();
    } else {
        show_svg_message("Either this is a bug or you're a  h4xx0r. :S");
    }
}
示例#2
0
function has_noscan_ships_and_constructions($fid)
{
    // noscan schiffe?
    $sth = mysql_query("SELECT s.prod_id FROM shipvalues s JOIN fleet f USING(prod_id) WHERE s.special = 'N' and f.fid = " . $fid);
    if (!$sth) {
        show_svg_message("ERROR::GETTING NOSCAN SHIPS");
        return false;
    }
    if (mysql_num_rows($sth) > 0) {
        return true;
    }
    //noscan gebäude?
    $fleet = new fleet($fid);
    if ($fleet->pid > 0) {
        $allies = get_allied_ids($fleet->uid);
        if (is_array($allies)) {
            array_push($allies, $fleet->uid);
        } else {
            $allies[] = $fleet->uid;
        }
        $sth = mysql_query("SELECT s.prod_id FROM planets p, shipvalues s JOIN constructions c USING(prod_id) where s.special='N' and c.pid=p.id and p.id = " . $fleet->pid . " and p.uid in (" . implode(",", $allies) . ")");
        if (!$sth) {
            show_svg_message("ERROR::GETTING NOSCAN CONSTRUCTIONS");
            return false;
        }
        if (mysql_num_rows($sth) > 0) {
            return true;
        }
    }
    return false;
}
示例#3
0
function switch_mod($fid)
{
    global $uid;
    $sth = mysql_query("select milminister from fleet_info where uid=" . $uid . " and fid='" . $fid . "'");
    if (!$sth) {
        show_svg_message("ERR::SWITCH MINISTER OF DEFENSE");
        return false;
    }
    if (mysql_num_rows($sth) == 0) {
        show_svg_message("You are not allowed for such an operation.");
        return false;
    }
    list($current_mod) = mysql_fetch_row($sth);
    if ($current_mod != "0") {
        $new_mod = 0;
    } else {
        $new_mod = 1;
    }
    $sth = mysql_query("update fleet_info set milminister=" . $new_mod . " where fid='" . $fid . "'");
    if (!$sth) {
        show_svg_message("ERR:: SETTING NEW MINISTER OF DEFENCE");
    } else {
        echo "<SR_REQUEST type=\"MOD\" mod=\"" . $new_mod . "\"/>";
    }
}
function transfer()
{
    global $uid;
    global $fleet;
    global $capacity;
    $transfer = $_GET["tr"];
    $fid = $_GET["fid"];
    $pid = $_GET["pid"];
    if (!check()) {
        return false;
    }
    // check ob nicht mehr transferiert wird als vorhanden
    $inf_on_fleet = $fleet->get_infantry();
    $inf_on_planet = get_infantry_and_data_by_pid_uid($pid, $uid);
    $new_fleet_inf = array();
    $new_planet_inf = array();
    $storage_info = array();
    $needep_cap = 0;
    $i = 0;
    if (is_array($inf_on_planet)) {
        foreach ($inf_on_planet as $inf) {
            $new_planet_inf[$inf["prod_id"]] = $inf["count"];
            $storage_info[$inf["prod_id"]] = $inf["storage"];
        }
    }
    if (is_array($inf_on_fleet)) {
        foreach ($inf_on_fleet as $inf) {
            $new_fleet_inf[$inf[0]] = $inf[1];
            $storage_info[$inf[0]] = $inf[2];
        }
    }
    foreach ($transfer as $prod_id => $count) {
        if ($new_fleet_inf[$prod_id] + $count < 0 || $new_planet_inf[$prod_id] - $count < 0 || !$storage_info[$prod_id]) {
            show_svg_message("LOL >:)");
            return false;
        }
        $new_fleet_inf[$prod_id] += $count;
        $new_planet_inf[$prod_id] -= $count;
        $needed_cap += $storage_info[$prod_id] * $new_fleet_inf[$prod_id];
    }
    if ($needed_cap > $capacity) {
        show_svg_message("haxx0r? Wanna squeeze em?");
        return false;
    }
    // okay, scheint ja alles mit richtigen dingen zuzugehen
    foreach ($transfer as $prod_id => $count) {
        if ($new_fleet_inf[$prod_id] == 0) {
            $sth = mysql_query("delete from inf_transports where fid='" . $fid . "' and prod_id='" . $prod_id . "'");
        } else {
            $sth = mysql_query("replace into inf_transports values('" . $fid . "','" . $prod_id . "','" . $new_fleet_inf[$prod_id] . "')");
        }
        if (!$sth) {
            show_svg_message("Database failure! #1");
            return false;
        }
        if ($new_planet_inf[$prod_id] == 0) {
            $sth = mysql_query("delete from infantery where pid='" . $pid . "' and prod_id='" . $prod_id . "' and uid='" . $uid . "'");
        } else {
            $sth = mysql_query("replace into infantery values('" . $prod_id . "','" . $new_planet_inf[$prod_id] . "','" . $pid . "','" . $uid . "')");
        }
        if (!$sth) {
            show_svg_message("Database failure! #2");
            return false;
        }
    }
    echo "<SR_REQUEST type=\"transfer_response\" v=\"1\"/>";
}