Example #1
0
<?php

require_once '../_includes/connection.php';
require_once '_includes/header_footer_blog.php';
require_once '../_includes/functions.php';
require_once '_includes/blog_functions.php';
require_once '_includes/session.php';
logged_in();
$url = 'login.php';
//decided if someone is friendly
is_friendly($_GET['friendly'], $_SESSION['user_name'], $_COOKIE['friendly'], $url);
if (isset($_POST['submit'])) {
    global $connection;
    //form was submitted
    $errors = array();
    //form validation
    $required_fields = array('user_name', 'password');
    //validation ends here
    $user_name = trim(mysql_prep($_POST['user_name']));
    $password = trim(mysql_prep($_POST['password']));
    $hashed_password = sha1($password);
    $query = "SELECT user_name, ";
    $query .= " update_authority ";
    $query .= "FROM users ";
    $query .= "WHERE user_name = '{$user_name}' ";
    $query .= "AND hashed_password ='******'";
    $result_set = mysql_query($query, $connection);
    confirm_query($result_set);
    if (mysql_num_rows($result_set) == 1) {
        //user name and password authenticated
        $found_user = mysql_fetch_array($result_set);
 function get_minimap_values($colors = true, $scanrange = true, $fleets = true)
 {
     global $uid;
     $user_alliance = get_alliance($uid);
     if (!$colors) {
         $scanrange = false;
     }
     $sth = mysql_query("select id, uid from planets where sid=" . $this->id . " and uid != 0");
     if (!$sth) {
         return 0;
     }
     while ($its_planets = mysql_fetch_array($sth)) {
         $its_uid = $its_planets["uid"];
         $its_id = $its_planets["id"];
         // minimap_colors
         if ($colors) {
             if ($its_uid == $uid) {
                 $this->minimap_colors[] = "lime";
                 $this->scan = true;
                 // scanrange
                 if ($scanrange) {
                     $its_scanradius = get_max_scan_range_by_pid($its_id);
                 }
             } elseif (is_allied($its_uid, $uid)) {
                 $this->minimap_colors[] = "yellow";
                 $this->scan = true;
                 // scanrange
                 if ($scanrange) {
                     $its_scanradius = get_max_scan_range_by_pid($its_id);
                 }
             } else {
                 $planet_alliance = get_alliance($its_uid);
                 if ($user_alliance && $planet_alliance && is_friendly($user_alliance, $planet_alliance)) {
                     $this->minimap_colors[] = "orange";
                 } elseif ($user_alliance && $planet_alliance && is_enemy($user_alliance, $planet_alliance)) {
                     $this->minimap_colors[] = "red";
                 } else {
                     $this->minimap_colors[] = "blue";
                 }
             }
         }
         // max scanrange ermitteln
         if ($its_scanradius && $this->scanradius < $its_scanradius) {
             $this->scanradius = $its_scanradius;
         }
     }
     // minimap_fleets
     if ($fleets) {
         $sth = mysql_query("select distinct(uid) as unique_uid from fleet_info where sid=" . $this->id);
         if (!$sth || !mysql_num_rows($sth)) {
             return 0;
         }
         while ($its_fleets = mysql_fetch_array($sth)) {
             $its_uid = $its_fleets["unique_uid"];
             if ($its_uid == $uid) {
                 $this->minimap_fleets[] = "lime";
                 $this->scan = true;
                 // scanrange der Flotten
                 if ($scanrange) {
                     $fleet_scanradius = get_max_fleet_scanrange_by_sid($this->id);
                 }
             } elseif (is_allied($its_uid, $uid)) {
                 $this->minimap_fleets[] = "yellow";
                 $this->scan = true;
                 // scanrange der Flotten
                 if ($scanrange) {
                     $fleet_scanradius = get_max_fleet_scanrange_by_sid($this->id);
                 }
             } else {
                 $fleet_alliance = get_alliance($its_uid);
                 if ($user_alliance && $fleet_alliance && is_friendly($user_alliance, $fleet_alliance)) {
                     $this->minimap_fleets[] = "orange";
                 } elseif ($user_alliance && $fleet_alliance && is_enemy($user_alliance, $fleet_alliance)) {
                     $this->minimap_fleets[] = "red";
                 } else {
                     $this->minimap_fleets[] = "blue";
                 }
             }
             if ($fleet_scanradius && $this->scanradius < $fleet_scanradius) {
                 $this->scanradius = $fleet_scanradius;
             }
         }
         // Scanrange
         if ($scanrange) {
             // Systeme in Scanrange
             $visible_systems = get_systems_in_scanrange($this->id, $this->scanradius);
             if (is_array($visible_systems)) {
                 for ($j = 0; $j < sizeof($visible_systems); $j++) {
                     $this->systems_in_scanrange[] = new MINIMAP_SYSTEM($visible_systems[$j]);
                 }
             }
             for ($j = 0; $j < sizeof($this->systems_in_scanrange); $j++) {
                 $this->systems_in_scanrange[$j]->get_minimap_values(true, false, true);
                 $this->systems_in_scanrange[$j]->make_visible();
             }
         }
     }
     // ende WHILE
     if (isset($this->minimap_colors[0])) {
         $this->minimap_colors = array_unique($this->minimap_colors);
     }
     if (isset($this->minimap_fleets[0])) {
         $this->minimap_fleets = array_unique($this->minimap_fleets);
     }
 }
 function shipbattle($simulation = false, $aarray = null, $darray = null)
 {
     // einfach nur ne simulation?
     if ($simulation) {
         $this->prepare_simulation($aarray, $darray);
     } else {
         // Ersma alle flotten raussuchen, die mit anderen flotten, die einem nich gehören auf einem fleck hocken
         $sth = mysql_query("select f1.fid,f1.pid,f1.sid,f1.uid,f1.mission from fleet_info f1,fleet_info f2 where f1.uid!=f2.uid and f1.pid=f2.pid and f1.sid=f2.sid group by f1.fid order by f1.pid,f1.sid");
         if (!$sth) {
             echo "Database failure!";
         }
         while ($poss_battle = mysql_fetch_array($sth)) {
             // neue pid und sid?
             if ($poss_battle["pid"] != $last_pid && $poss_battle["sid"] != $last_sid) {
                 if (!isset($i)) {
                     $i = 0;
                 } else {
                     $i++;
                 }
                 // neuen container erzeugen
                 $poss_battle_locations[$i] = new possible_battle_container();
                 $poss_battle_locations[$i]->sid = $poss_battle["sid"];
                 $poss_battle_locations[$i]->pid = $poss_battle["pid"];
                 $last_pid = $poss_battle["pid"];
                 $last_sid = $poss_battle["sid"];
             }
             $poss_battle_locations[$i]->fleets[$poss_battle["uid"]][] = array("fid" => $poss_battle["fid"], "mission" => $poss_battle["mission"]);
         }
         // so jetzt die uids pro location vergleichen und schauen ob nen kampf zustande kommt und die battlelocations indizes sichern
         for ($i = 0; $i < sizeof($poss_battle_locations); $i++) {
             $battle_location[$i] = new possible_battle_container();
             $battle_location[$i]->pid = $poss_battle_locations[$i]->pid;
             $battle_location[$i]->sid = $poss_battle_locations[$i]->sid;
             $nachzuegler = array();
             $uids = array_keys($poss_battle_locations[$i]->fleets);
             $uids = array_flip($uids);
             $owner = get_uid_by_pid($poss_battle_locations[$i]->pid);
             $owner_alliance = get_alliance($owner);
             while (list($uid, $dummy) = each($poss_battle_locations[$i]->fleets)) {
                 $uids_temp = $uids;
                 unset($uids_temp[$uid]);
                 reset($uids_temp);
                 while (list($second_uid, $dummy) = each($uids_temp)) {
                     $alliance = get_alliance($uid);
                     $sec_alliance = get_alliance($second_uid);
                     if (is_enemy($alliance, $sec_alliance)) {
                         $battle_location[$i]->fleets[$uid] = $poss_battle_locations[$i]->fleets[$uid];
                         $battle_location[$i]->fleets[$second_uid] = $poss_battle_locations[$i]->fleets[$second_uid];
                         unset($poss_battle_locations[$i]->fleets[$second_uid]);
                         echo "BLA\n";
                     } elseif (is_allied($alliance, $sec_alliance) || is_friendly($alliance, $sec_alliance)) {
                         $nachzuegler[] = $poss_battle_locations[$i]->fleet[$second_uid];
                         unset($poss_battle_locations[$i]->fleets[$second_uid]);
                     } elseif (is_enemy($alliance, $owner_alliance)) {
                         for ($j = 0; $j < sizeof($poss_battle_locations[$i]->fleets[$uid]); $j++) {
                             if ($poss_battle_locations[$i]->fleets[$uid][$j]["mission"] == 3 || $poss_battle_locations[$i]->fleets[$uid][$j]["mission"] == 5) {
                                 // invading oder bombarding? ziemlicher gayer hack :S
                                 $battle_location[$i]->fleets[$uid] = $poss_battle_locations[$i]->fleets[$uid];
                             }
                         }
                     } else {
                         // neutrale müssen nochmal gesondert betrachtet werden deswegen kein unset
                     }
                 }
             }
             // mop: wenn es ne freund/feind situation irgendwie gibt, dann müssen die nachzuegler mit rein
             if (is_array($battle_location[$i]->fleets)) {
                 for ($j = 0; $j < sizeof($nachzuegler); $j++) {
                     $battle_location[$i]->fleets = array_merge($battle_location[$i]->fleets, $nachzuegler[$j]);
                 }
                 echo "BLA2\n";
             }
         }
         echo "BLA3\n";
         var_dump($battle_location);
         // jetzt haben wir die battlelocations...nun wirds interessant...wir müssen die ganze hundescheisse jetzt nach defenders und
         // attackers umdröseln
         for ($i = 0; $i < sizeof($battle_location); $i++) {
             echo "=> {$i}\n";
             $this->a_uids = array();
             $this->d_uids = array();
             $this->attackers = array();
             $this->defenders = array();
             $this->report = new battlereport();
             $this->report->pid = $battle_location[$i]->pid;
             $this->report->sid = $battle_location[$i]->sid;
             if (is_array($battle_location[$i]->fleets)) {
                 echo "JO\n";
                 // dann muss es da auch irgendwas zum kampftrollen geben
                 if ($battle_location[$i]->pid == 0) {
                     echo "JO=>2\n";
                     if ($intercepting = $battle_location[$i]->find_intercepting_uid()) {
                         $this->d_uids[] = $intercepting;
                         for ($j = 0; $j < sizeof($battle_location[$i]->fleets[$intercepting]); $j++) {
                             $battlefleet = new battlefleet($battle_location[$i]->fleets[$intercepting][$j]["fid"], 0);
                             $this->report->add_fleet($battlefleet);
                             $this->defenders[] = $battlefleet;
                         }
                         $d_alliance = get_alliance($intercepting);
                         // verteidigende allianz sichern
                         reset($battle_location[$i]->fleets);
                         while (list($uid, $fleet) = each($battle_location[$i]->fleets)) {
                             if ($uid != $this->d_uids[0]) {
                                 if (is_enemy($d_alliance, get_alliance($uid))) {
                                     if (!in_array($uid, $this->a_uids)) {
                                         $this->a_uids[] = $uid;
                                         for ($j = 0; $j < sizeof($fleet); $j++) {
                                             $battlefleet = new battlefleet($fleet[$j]["fid"], 1);
                                             $this->report->add_fleet($battlefleet);
                                             $this->attackers[] = $battlefleet;
                                         }
                                     }
                                 } elseif (is_friendly($d_alliance, get_alliance($uid)) || is_allied($d_alliance, get_alliance($uid))) {
                                     if (!in_array($uid, $this->d_uids)) {
                                         $this->d_uids[] = $uid;
                                         for ($j = 0; $j < sizeof($fleet); $j++) {
                                             $battlefleet = new battlefleet($fleet[$j]["fid"], 0);
                                             $this->report->add_fleet($battlefleet);
                                             $this->defenders[] = $battlefleet;
                                         }
                                     }
                                 } else {
                                     echo "Neutral Player detected :S\n";
                                 }
                             }
                         }
                     } else {
                         // :S
                     }
                 } else {
                     echo "JO2\n";
                     $owner = get_uid_by_pid($battle_location[$i]->pid);
                     $planet_active = false;
                     if (in_array($owner, array_keys($battle_location[$i]->fleets))) {
                         $this->d_uids[] = $owner;
                     } else {
                         $owner = array_rand($battle_location[$i]->fleets);
                         $this->d_uids[] = $owner;
                         echo "Owner ist => " . $owner . "\n";
                     }
                     for ($j = 0; $j < sizeof($battle_location[$i]->fleets[$owner]); $j++) {
                         $battlefleet = new battlefleet($battle_location[$i]->fleets[$owner][$j]["fid"], 0);
                         $this->report->add_fleet($battlefleet);
                         $this->defenders[] = $battlefleet;
                     }
                     $d_alliance = get_alliance($owner);
                     // verteidigende allianz sichern
                     reset($battle_location[$i]->fleets);
                     while (list($uid, $fleet) = each($battle_location[$i]->fleets)) {
                         if ($uid != $this->d_uids[0]) {
                             if (is_enemy($d_alliance, get_alliance($uid))) {
                                 if (!in_array($uid, $this->a_uids)) {
                                     $this->a_uids[] = $uid;
                                     for ($j = 0; $j < sizeof($fleet); $j++) {
                                         $battlefleet = new battlefleet($fleet[$j]["fid"], 1);
                                         if ($battlefleet->mission == 3) {
                                             $planet_active = true;
                                             $planet_attack_type = 0;
                                         } elseif ($battlefleet->mission == 5) {
                                             $planet_active = true;
                                             $planet_attack_type = 1;
                                         }
                                         $this->report->add_fleet($battlefleet);
                                         $this->attackers[] = $battlefleet;
                                     }
                                 }
                             } elseif (is_friendly($d_alliance, get_alliance($uid)) || is_allied($d_alliance, get_alliance($uid))) {
                                 if (!in_array($uid, $this->d_uids)) {
                                     $this->d_uids[] = $uid;
                                     for ($j = 0; $j < sizeof($fleet); $j++) {
                                         $battlefleet = new battlefleet($fleet[$j]["fid"], 0);
                                         $this->report->add_fleet($battlefleet);
                                         $this->defenders[] = $battlefleet;
                                     }
                                 }
                             } else {
                                 echo "Neutral Player detected :S\n";
                             }
                         }
                     }
                 }
                 if ($planet_active) {
                     // d_uids wurde schon vorher hinzugfügt
                     $battleplanet = new battleplanet($battle_location[0]->pid, $planet_attack_type);
                     $this->report->add_planet($battleplanet);
                     $this->defenders[] = $battleplanet;
                 }
             }
             if (sizeof($this->a_uids) > 0 && sizeof($this->d_uids) > 0) {
                 $this->attackers_count = sizeof($this->attackers);
                 $this->defenders_count = sizeof($this->defenders);
                 $this->prepare_battle();
                 $this->do_battle();
                 $this->destroy_ships();
                 $this->report->do_report();
             }
         }
     }
 }
function get_color_by_alliancestatus($aid1, $aid2)
{
    $color = "black";
    if ($aid1 == $aid2) {
        $color = "yellow";
    } elseif (is_enemy($aid1, $aid2)) {
        $color = "red";
    } elseif (is_friendly($aid1, $aid2)) {
        $color = "orange";
    } else {
        $color = "blue";
    }
    return $color;
}
Example #5
0
function get_uids_relation($uid1, $uid2, $type = 0)
{
    if ($uid1 == $uid2) {
        $type == 0 ? $relation = "same" : ($relation = "colorOwn");
    } elseif (is_allied($uid1, $uid2)) {
        $type == 0 ? $relation = "allie" : ($relation = "colorAllied");
    } else {
        $alliance1 = get_alliance($uid1);
        $alliance2 = get_alliance($uid2);
        if ($alliance1 && $alliance2) {
            if (is_friendly($alliance1, $alliance2)) {
                $type == 0 ? $relation = "friend" : ($relation = "colorFriend");
            } elseif (is_enemy($alliance1, $alliance2)) {
                $type == 0 ? $relation = "enemy" : ($relation = "colorEnemy");
            } else {
                $type == 0 ? $relation = "neutral" : ($relation = "colorNeutral");
            }
        } else {
            $type == 0 ? $relation = "neutral" : ($relation = "colorNeutral");
        }
    }
    return $relation;
}