Exemple #1
0
 public static function login()
 {
     $connection = Flight::dbMain();
     try {
         $session = json_decode(file_get_contents("php://input"));
         if ($session == null) {
             throw new Exception(json_get_error());
         }
         $sql = "SELECT * FROM user WHERE user.user_name = :name and user.user_password = :password;";
         $query = $connection->prepare($sql);
         $password = hash('sha256', $session->Password);
         $query->bindParam(':name', $session->Name, PDO::PARAM_STR);
         $query->bindParam(':password', $password, PDO::PARAM_STR);
         $query->execute();
         $row = $query->fetch(PDO::FETCH_ASSOC);
         if ($query->rowCount() < 1) {
             throw new Exception("Username or Password is not exist");
         }
         $user = new User();
         $user->Id = (int) $row['id'];
         $user->Name = $row['user_name'];
         $user->DtCreated = $row['user_dt_created'];
         $user->DtExpired = $row['user_dt_expired'];
         // $user->Privilege = (int) $row['e_privilege_id'];
         // $user->Status = (int) $row['e_status_id'];
         // $user->Company = (int) $row['company_id'];
         // $user->Sim = $row['sim_id'] == null ? null : (int) $row['sim_id'];
         $user->Privilege = Privilege::select($row['e_privilege_id']);
         $user->Status = Status::select($row['e_status_id']);
         $user->Company = Company::select($row['company_id']);
         $user->Sim = Sim::select($row['sim_id']);
         Flight::ok($user);
     } catch (PDOException $pdoException) {
         Flight::error($pdoException);
     } catch (Exception $exception) {
         Flight::error($exception);
     } finally {
         $connection = null;
     }
 }
Exemple #2
0
 public static function delete($id)
 {
     $connection = Flight::dbMain();
     try {
         /* Begin Transaction */
         $connection->beginTransaction();
         /*Query 1 Select unit*/
         $sql = "SELECT * FROM unit WHERE id = :id;";
         $query = $connection->prepare($sql);
         $query->bindParam(':id', $id, PDO::PARAM_INT);
         $query->execute();
         $rows = $query->fetchAll(PDO::FETCH_ASSOC);
         $row = $rows[0];
         $unit = new Unit();
         $unit->Id = (int) $row['id'];
         $unit->Imei = $row['unit_imei'];
         $unit->DtCreated = $row['unit_dt_created'];
         $unit->SerialNumber = $row['unit_serial_number'];
         $unit->Sim = Sim::select($row['sim_id']);
         $unit->UnitStatus = UnitStatus::select($row['e_status_unit_id']);
         $unit->UnitType = UnitType::select($row['unit_type_id']);
         $unit->Company = Company::select($row['company_id']);
         /*Query 2 Delete unit*/
         $sql = "\n\t\t\tDELETE FROM unit \n\t\t\tWHERE\n\t\t\tid = :id";
         $query = $connection->prepare($sql);
         $query->bindParam(':id', $id, PDO::PARAM_INT);
         $query->execute();
         /*Query 3 Drop data_unit.imei table*/
         $year = date('Y');
         $schema = "app_data_{$year}";
         $imei = $unit->Imei;
         $tableName = "data_{$imei}";
         $sql = "\n\t\t\t\n\t\t\tDROP TABLE IF EXISTS {$schema}.{$tableName};\n\n\t\t\t";
         $query = $connection->prepare($sql);
         $query->execute();
         $connection->commit();
         $result = new Result();
         $result->Status = Result::DELETED;
         $result->Message = 'Done';
         $result->Id = $id;
         return $result;
     } catch (PDOException $pdoException) {
         $connection->rollBack();
         throw $pdoException;
     } catch (Exception $exception) {
         $connection->rollBack();
         throw $exception;
     } finally {
         $connection = null;
     }
 }
Exemple #3
0
 public static function selectByCompany($id)
 {
     $connection = Flight::dbMain();
     try {
         $sql = "SELECT * FROM user WHERE company_id = :company;";
         $query = $connection->prepare($sql);
         $query->bindParam(':company', $id, PDO::PARAM_INT);
         $query->execute();
         $rows = $query->fetchAll(PDO::FETCH_ASSOC);
         $result = array();
         foreach ($rows as $row) {
             $user = new User();
             $user->Id = (int) $row['id'];
             $user->Name = $row['user_name'];
             $user->DtCreated = $row['user_dt_created'];
             $user->DtExpired = $row['user_dt_expired'];
             // $user->Privilege = (int) $row['e_privilege_id'];
             // $user->Status = (int) $row['e_status_id'];
             // $user->Company = (int) $row['company_id'];
             // $user->Sim = $row['sim_id'] == null ? null : (int) $row['sim_id'];
             $user->Privilege = Privilege::select($row['e_privilege_id']);
             $user->Status = Status::select($row['e_status_id']);
             $user->Company = Company::select($row['company_id']);
             $user->Sim = Sim::select($row['sim_id']);
             array_push($result, $user);
         }
         return $result;
     } catch (PDOException $pdoException) {
         throw $pdoException;
     } catch (Exception $exception) {
         throw $exception;
     } finally {
         $connection = null;
     }
 }
Exemple #4
0
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('PUT /v1/main/sim/@id', function ($id) {
    try {
        $object = Sim::update($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
Flight::route('DELETE /v1/main/sim/@id', function ($id) {
    try {
        $object = Sim::delete($id);
        Flight::ok($object);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
});
//=============================================================================
//SimVendor
//=============================================================================
Flight::route('GET /v1/main/simvendor', function () {
    try {
        $array = SimVendor::selectAll();
        Flight::ok($array);
    } catch (Exception $exception) {
        Flight::error($exception);
    }
Exemple #5
0
    function damageRoll(Model $defender, $pow=0, $dice=2, AttackResult $result) {
        $rollTxt = "{$dice}D6";
        $roll    = Sim::rollDice($dice);

        $roll = $roll['roll'];

        $dmg = $this->getStr() + $pow + $roll;
        $arm = $defender->getArm();

        if ($this->hasBuff('incite')) {
            $dmg += 2;
        }

        if ($defender->hasBuff('warp-arm')) {
            $arm += 2;
        }

        if ($defender->hasBuff('spiny-growth')) {
            $arm += 2;
        }

        $res = $dmg - $arm;

        $this->getSim()->debug("[{$defender->getName()}] (P {$pow} + S {$this->getStr()} + roll {$roll} ({$rollTxt}) = {$dmg} - {$arm})");

        $result->setDamage($res > 0 ? $res : 0);

        return $result;
    }
Exemple #6
0
    public function run() {
        $success = 0;
        $dmg     = array();

        for ($i = 0; $i < $this->laps; $i++) {
            $sim = new Sim();
            $sim->setAttacker(clone $this->attacker);
            $sim->setDefender(clone $this->defender);

            $sim->setBoostAttack($this->isBoostAttack());
            $sim->setBoostDamage($this->isBoostDamage());
            $sim->setChargeAttack($this->isChargeAttack());
            $sim->setStopOnDeath($this->isStopOnDeath());
            $sim->setDebug($this->debug);

            $sim->run();

            $dmg[] = $sim->getDamageDone();

            if ($sim->isKilled()) {
                $success++;
            }

            if ($this->debug) {
                echo "-------\n";
            }
        }

        sort($dmg);

        $chance = round(($success / $this->laps) * 100, 2);
        $avgdmg = round(array_sum($dmg) / $this->laps, 2);
        $avgofhp= round(($avgdmg / $sim->getDefender()->getDmg()) * 100, 2);
        $median = round(self::median($dmg), 2);
        $medofhp= round(($median / $sim->getDefender()->getDmg()) * 100, 2);

        echo "{$this->laps} laps, {$success} kills = {$chance}% chance, {$avgdmg} avg damage ({$avgofhp}%), {$median} median damage ({$medofhp}%)\n";
    }