Example #1
0
 public function __construct($player_id_or_username = null)
 {
     if (!empty($player_id_or_username)) {
         if (!is_numeric($player_id_or_username) && is_string($player_id_or_username)) {
             $sel = "SELECT player_id FROM players WHERE lower(uname) = lower(:uname) LIMIT 1";
             $this->player_id = query_item($sel, array(':uname' => array($player_id_or_username, PDO::PARAM_INT)));
         } else {
             $this->player_id = (int) $player_id_or_username;
         }
         $dao = new PlayerDAO();
         if (!($this->vo = $dao->get($this->player_id))) {
             $this->vo = new PlayerVO();
         }
     } else {
         $this->vo = new PlayerVO();
     }
 }
Example #2
0
 /**
  * group char
  **/
 function testCreatePlayerObjectCanSaveChanges()
 {
     $char = new Player($this->char_id);
     $ki = $char->ki();
     $char->add_ki(55);
     $player_factory = new PlayerDAO();
     $this->markTestIncomplete('Player objects not yet self-saving');
     $player_factory->save($char->vo);
     $char_copy = new Player($this->char_id);
     $this->assertEquals($char_copy->ki(), $ki + 55);
 }
Example #3
0
 function getPlayer($playerId)
 {
     $playerDao = new PlayerDAO();
     $player = $playerDao->getPlayerByPlayerId($playerId);
     return $player;
 }
Example #4
0
require_once '../../config/paths.php';
require '../../config/map.cfg.php';
require_once_model('StaticData');
require_once_model('Sector');
require_once_model('Building');
require_once_model('Technology');
require_once_model('Battle');
require_once_model('Player');
require_once_model('Message');
require_once_model('Resource');
session_start();
$staticData = $_SESSION['staticData'];
$allPlayers = $staticData->getPlayers();
$allBuildings = $staticData->getBuildings();
$sessionPlayer = $_SESSION['player'];
$playerConn = new PlayerDAO();
$sectorConn = new SectorDAO();
$newMessages = false;
$messagesArr = $playerConn->getMessages($sessionPlayer->getId(), true, 0);
if (count($messagesArr)) {
    $newMessages = true;
}
if ($_POST['height'] != 'undefined' && $_POST['width'] != 'undefined') {
    $height = $_POST['height'];
    $width = $_POST['width'];
} else {
    $lastMapViewArr = $playerConn->getLastMapView($sessionPlayer->getId());
    $coordinates = explode(",", $lastMapViewArr[0]);
    $originX = $coordinates[0];
    $originY = $coordinates[1];
    $height = $lastMapViewArr[1];
<?php

require_once '../../lib/inclusion.php';
require_once_model('Player');
require_once_model('Technology');
require_once_model('StaticData');
session_start();
$playerConn = new PlayerDAO();
$technologyConn = new TechnologyDAO();
$techId = $_POST['techId'];
$percentOrder = $_POST['percentOrder'];
$player = $_SESSION['player'];
$staticData = $_SESSION['staticData'];
$allTechnologies = $staticData->getTechnologies();
//SAFETY CHECK ON NON-UPGRADABLE TECHNOLOGIES
$avail = $player->getAvailableTechnologies();
$tech = $avail[$techId];
$techOver = !$tech->getUpgradable() && $tech->getLevel() > 0;
if ($techOver) {
    die("Esta tecnología no es nivelable. Recarga la pestaña de Tecnologías para ver los cambios.");
}
//COPYPASTA FROM TECHNOLOGIES_REQUEST
$availableTechsArr = $playerConn->getAvailableTechnologies($player->getId(), $player->getAge());
$technologies = array();
foreach ($availableTechsArr as $technologyArr) {
    $technology = clone $allTechnologies[$technologyArr[0]];
    /* $technology = new Technology($rs->fields[0], $name, $rs->fields[2], $rs->fields[3], $rs->fields[4],
                $costs, $increments, $rs->fields[7], $rs->fields[8], $rs->fields[9], $rs->fields[10], $rs->fields[11],
                $rs->fields[12], $rs->fields[13], $rs->fields[14], $rs->fields[15], $rs->fields[16]);
    */
    $technology->setLevel($technologyArr[13]);
Example #6
0
    // Check that the text features don't differ
    $char->set_description($description);
    $char->set_goals($goals);
    $char->set_instincts($instincts);
    $char->set_beliefs($beliefs);
    $char->set_traits($traits);
    /*
    	foreach(['description', 'goals', 'instincts', 'beliefs', 'traits'] as $type){
    		if($$type && isset($char->vo)){
    			$method = 'set_'.$type;
    			$char->$method($$type); // Set the various details in the Player obj
    			$changed = true;
    		}
    		$$type = $char->$type(); // Default to current values.
    	}*/
    $changed = PlayerDAO::saveDetails($char);
    redirect('/stats.php?changed=' . (int) $changed . ($profile_changed ? '&profile_changed=1' : ''));
}
/*
if(false && DEBUG){
	$description = 'This is a description here and all';
	$goals = 'Kill ninja of the ramen clan';
	$beliefs = 'I believe in a one true ninja god';
	$instincts = 'When I hear whistling, I duck';
	$traits = 'Hardy, nervous, meaty, silent';
}
*/
$player = self_info();
//$player['created_date']=$player['created_date']? date("c", strtotime($player['created_date'])) : null;
$class_theme = class_theme($char->class_identity());
$level_category = level_category($player['level']);
Example #7
0
<?php

require_once '../../lib/inclusion.php';
require_once '../../config/units.cfg.php';
require_once_model('Player');
require_once_model('Unit');
require_once_model('Sector');
session_start();
$sectorConn = new SectorDAO();
$playerConn = new PlayerDAO();
$player = $_SESSION['player'];
$action = $_POST['action'];
$unitId = $_POST['unitId'];
$coordinateX = $_POST['coordinateX'];
$coordinateY = $_POST['coordinateY'];
$quantity = $_POST['quantity'];
$playerSectors = array();
foreach ($player->getSectors() as $playerSector) {
    $sectorC = $playerSector->getCoordinateX() . "," . $playerSector->getCoordinateY();
    $playerSectors[] = $sectorC;
}
$sectorOK = in_array($coordinateX . "," . $coordinateY, $playerSectors);
$unitOK = array_key_exists($unitId, $player->getAvailableUnits());
$resourcesOK = true;
$available_units = $player->getAvailableUnits();
$unit_resources = $available_units[$unitId]->getProductionCost();
$player_resources = $player->getResources();
$leftResources = array();
for ($i = 0; $i < count($unit_resources); $i++) {
    $leftResources[$i] = $player_resources[$i] - $unit_resources[$i] * $quantity;
    if ($leftResources[$i] < 0 && $unit_resources[$i] > 0) {
<?php

$dir = opendir("../../img/avatars/default/");
$nick = "";
$pass1 = "";
$pass2 = "";
$errorMsg = "";
if (isset($_POST['continuar'])) {
    require_once '../../lib/inclusion.php';
    require_once '../../config/paths.php';
    require_once_model('Player');
    require_once_model('Sector');
    $playerConn = new PlayerDAO();
    $sectorConn = new SectorDAO();
    $continuar = $_POST['continuar'];
    @($nick = $_POST['nick']);
    @($pass1 = $_POST['pass1']);
    @($pass2 = $_POST['pass2']);
    @($email = $_POST['email']);
    @($civName = $_POST['civName']);
    @($avatar = $_FILES["avatar"]);
    @($flag = $_FILES["flag"]);
    $images_ok = false;
    if (isset($_FILES["avatar_file"]) && isset($_FILES["flag"])) {
        $type_ok = (strpos($_FILES["avatar_file"]["type"], "gif") || strpos($_FILES["avatar_file"]["type"], "png") || strpos($_FILES["avatar_file"]["type"], "jpeg")) && (strpos($_FILES["flag"]["type"], "gif") || strpos($_FILES["flag"]["type"], "png") || strpos($_FILES["flag"]["type"], "jpeg"));
        $size_ok = $_FILES["avatar_file"]["size"] < 100000 && $_FILES["flag"]["size"] < 100000;
        if (!($type_ok && $size_ok)) {
            $errorMsg .= "* La extensión o el tamaño de los archivos no es correcta.\r\n                    <ul>\r\n                        <li>Se permiten archivos .png, .gif o .jpg</li>\r\n                        <li>se permiten archivos de 100 Kb máximo.</li>\r\n                    </ul>";
        } else {
            move_uploaded_file($_FILES['avatar_file']['tmp_name'], $img_avatars . $nick . "_avatar.png");
            move_uploaded_file($_FILES['flag']['tmp_name'], $img_flags . $nick . "_flag.png");
<?php

require_once '../../lib/inclusion.php';
require_once '../../config/paths.php';
require_once_model('Technology');
require_once_model('Building');
require_once_model('Unit');
require_once_model('Resource');
require_once_model('Player');
require_once_model('StaticData');
session_start();
$playerConn = new PlayerDAO();
$player = $_SESSION["player"];
$staticData = $_SESSION['staticData'];
$resources = $staticData->getResources();
$allTechnologies = $staticData->getTechnologies();
$playerConn->getAgeAdvanceCosts($player->getId());
$availableTechsArr = $playerConn->getAvailableTechnologies($player->getId(), $player->getAge());
$technologies = array();
foreach ($availableTechsArr as $technologyArr) {
    $technology = clone $allTechnologies[$technologyArr[0]];
    $technology->setLevel($technologyArr[13]);
    $technology->setProgress($technologyArr[14]);
    $technology->setDateStartProgress($technologyArr[15]);
    $technology->setDateEndProgress($technologyArr[16]);
    $now = $_SERVER['REQUEST_TIME'];
    $start = $technology->getDateStartProgress();
    $end = $technology->getDateEndProgress();
    $timeLeft = $end - $now;
    if ($timeLeft < 0) {
        $timeLeft = 0;
 public function ParseAndSaveWorldMap($world_response, $descriptor)
 {
     $log_seq = 0;
     $func_args = func_get_args();
     $func_args[0] = 'Removed Hex Array. See WS Request Log.';
     $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args);
     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'INFO', $descriptor);
     // Get the Hexes section of the world response
     $success = $world_response['responses'][0]['return_value']['success'];
     if ($success != 1) {
         $reason = $world_response['responses'][0]['return_value']['reason'];
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Error Getting Map Data: {$reason}", 1);
         // Even though this is technically a failure, we return true because we don't want to retry this request
         return true;
     }
     $world = $world_response['responses'][0]['return_value']['hexes'];
     $hex_count = 0;
     // Sometimes this happens but I'm not sure why... so I created a return code to try again...
     if (empty($world)) {
         DataLoadLogDAO::completeFunction($this->db, $func_log_id, 'No Hexes Found', 1);
         echo "No hexes found.\r\n";
         return false;
     }
     // Parse and store each Hex
     foreach ($world as $key => $hex_arr) {
         $hex_count++;
         // Take the array and create the Hex object
         $hex = Hex::FromJson($hex_arr);
         $hex->data_load_id = $this->data_load_id;
         // Set the world ID
         $hex->world_id = $this->auth->world_id;
         // Recalculate the x coordinate.  Not sure why they store the data this way.
         $hex->hex_x = (int) self::convertToMapCoordinate($hex->hex_x, $hex->hex_y);
         // Check if this hex already exists so we know whether we're inserting or updating
         $hex_exists = WorldMapDAO::checkHexExists($this->db, $hex->world_id, $hex->hex_x, $hex->hex_y);
         if ($hex->building_id) {
             $hex->building_id = BuildingDAO::getLocalIdFromGameId($this->db, $hex->building_id);
         }
         // Determine whether we should use the player ID or NPC ID
         if (isset($hex->player_id)) {
             $game_player_id = $hex->player_id;
         } else {
             if (isset($hex->npc_player_id)) {
                 $game_player_id = $hex->npc_player_id;
             } else {
                 $game_player_id = null;
             }
         }
         // Get the local Player ID from our database
         $player_id = PlayerDAO::getLocalIdFromGameId($this->db, $game_player_id);
         // Start building a new player record
         $player = new Player();
         // Set the local Player ID if we found one
         if ($player_id) {
             $player->id = $player_id;
         }
         // Set the world ID and game player ID
         $player->world_id = $hex->world_id;
         $player->game_player_id = $game_player_id;
         // Initialize flags to NULL
         $hex->is_sb = null;
         $hex->is_npc = null;
         // Handle Alliance Base as a special case
         if ($hex->is_guild_town_center === 1) {
             $hex->town_name = $hex->guild_name;
             $hex->player_name = $hex->guild_name;
             $hex->player_level = $hex->guild_town_phase;
             $hex->building_id = 15;
         }
         // If this is a town tile then we have additional information, so let's process it
         if (isset($hex->town_name) || in_array($hex->building_id, array(14))) {
             $hex->command_center = true;
             // Set base properties
             $hex->is_sb = ($hex->town_radius == 2 and $hex->building_id == 1) ? 1 : 0;
             $hex->is_npc = $hex->town_name === 'Renegade Outpost' ? 1 : 0;
             // Set the player's name and level
             $player->player_name = $hex->player_name;
             $player->level = $hex->player_level;
             $player->data_load_id = $this->data_load_id;
             // Calculate the end of the player's bubble
             if ($hex->immune_until_ts > 0) {
                 $player->immune_until = date('Y-m-d H:i:s', $hex->immune_until_ts);
             } else {
                 $player->immune_until = null;
             }
             // If this player is in a guild, process that information
             if (isset($hex->guild_id)) {
                 // Get the local Guild ID from our database
                 $guild_id = GuildDAO::getLocalIdFromGameId($this->db, $hex->guild_id);
                 // If we didn't find this guild, then start building the record.
                 // Otherwise, don't bother because this information won't change frequently.
                 if (!$guild_id) {
                     $guild = new Guild();
                     $guild->world_id = $hex->world_id;
                     $guild->game_guild_id = $hex->guild_id;
                     $guild->guild_name = $hex->guild_name;
                     $guild->data_load_id = $this->data_load_id;
                     // Insert the guild record into our database and keep the new local ID for later
                     $guild_id = GuildDAO::insertGuild($this->db, $guild);
                     if ($this->db->hasError()) {
                         echo 'Error inserting Guild: ';
                         print_r($this->db->getError());
                         $log_msg = print_r($guild, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                         DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error inserting Guild [{$guild->guild_name}] into World [{$guild->world_id}]", $log_msg, 1);
                         echo "\r\n";
                     }
                 }
                 // Set the player's guild
                 $player->guild_id = $guild_id;
             }
         }
         // If this player didn't already exist in our database, create it.  Otherwise, update it.
         if (!$player_id) {
             if ($game_player_id) {
                 //DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'DEBUG', "Inserting Player [{$player->player_name}] into World [{$player->world_id}]", var_export($player, true));
                 $player_id = PlayerDAO::insertPlayer($this->db, $player);
                 if ($this->db->hasError()) {
                     echo 'Error inserting Player: ';
                     print_r($this->db->getError());
                     echo "\r\n";
                     $log_msg = print_r($player, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error inserting Player [{$player->player_name}] into World [{$player->world_id}]", $log_msg, 1);
                 }
             }
         } else {
             if ($player->player_name) {
                 //DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'DEBUG', "Updating Player [{$player->player_name}] in World [{$player->world_id}]", var_export($player, true));
                 // Update the player, but exclude battle points, power, and the number of bases because these aren't available in this case
                 $updateCount = PlayerDAO::updatePlayer($this->db, $player, array('battle_points', 'glory_points', 'bases'));
                 if ($this->db->hasError()) {
                     echo 'Error updating Player: ';
                     print_r($this->db->getError());
                     echo "\r\n";
                     $log_msg = var_export($player, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                     DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error updating Player [{$player->player_name}] in World [{$player->world_id}]", $log_msg, 1);
                 }
             }
         }
         // Set the player ID on the hex tile to the local database ID
         if (isset($hex->player_id) || isset($hex->npc_player_id)) {
             $hex->player_id = $player_id;
         }
         // Insert or update the hex record
         if ($hex_exists == false) {
             $hex_id = WorldMapDAO::insertHex($this->db, $hex);
             if ($this->db->hasError()) {
                 echo 'Error inserting Hex: ';
                 print_r($this->db->getError());
                 echo "\r\n";
                 $log_msg = var_export($hex, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error inserting hex into World {$hex->world_id}, X: {$hex->hex_x}, Y: {$hex->hex_y}", $log_msg);
             }
         } else {
             $hex_id = WorldMapDAO::updateHex($this->db, $hex);
             if ($this->db->hasError()) {
                 echo 'Error updating Hex: ';
                 print_r($this->db->getError());
                 echo "\r\n";
                 $log_msg = var_export($hex, true) . "\r\n\r\n" . print_r($this->db->getError(), true);
                 DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error updating hex in World {$hex->world_id}, X: {$hex->hex_x}, Y: {$hex->hex_y}", $log_msg, 1);
             }
         }
     }
     DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Created {$hex_count} Hexes");
     echo "Created {$hex_count} Hexes\r\n";
     return true;
 }
 function SaveGuildLeaderboard($leader_data)
 {
     $log_seq = 0;
     $func_args = func_get_args();
     $func_args[0] = 'Removed Hex Array. See WS Request Log.';
     $func_log_id = DataLoadLogDAO::startFunction($this->db, $this->data_load_id, __CLASS__, __FUNCTION__, $func_args);
     $count = 0;
     foreach ($leader_data as $key => $leader) {
         $guild = new Guild();
         $guild->world_id = $this->auth->world_id;
         $guild->data_load_id = $this->data_load_id;
         $guild->game_guild_id = $leader['guild_id'];
         if (array_key_exists('owner_id', $leader) && ($leader_id = PlayerDAO::getLocalIdFromGameId($this->db, $leader['owner_id']))) {
             $guild->leader_id = $leader_id;
         }
         $guild->guild_name = $leader['guild_name'];
         $guild->battle_points = $leader['score'];
         $guild->glory_points = $leader['glory_points'];
         $guild->members = $leader['member_count'];
         $id = GuildDAO::getLocalIdFromGameId($this->db, $guild->game_guild_id);
         if ($id) {
             $guild->id = $id;
             GuildDAO::updateGuild($this->db, $guild);
         } else {
             GuildDAO::insertGuild($this->db, $guild);
         }
         if ($this->db->hasError()) {
             echo 'Error saving guild: ';
             print_r($this->db->getError());
             echo "\r\n";
             $log_msg = var_dump($player) . "\r\n\r\n" . print_r($this->db->getError(), true);
             DataLoadLogDAO::logEvent2($this->db, $func_log_id, $log_seq++, 'ERROR', "Error Saving Guild: World [{$guild->world_id}], Guild: [{$guild->guild_name}]", $log_msg, 1);
         } else {
             $count++;
         }
     }
     DataLoadLogDAO::completeFunction($this->db, $func_log_id, "Saved {$count} Guilds");
 }
Example #12
0
require '../../../public/config/sector.cfg.php';
require_once_model('Global');
function soMuchWin($success)
{
    if ($success) {
        echo "<img src='../../../public/img/buttons/done.gif'><br/>";
    } else {
        echo "<img src='../../../public/img/buttons/delete.png' style='width:20px; height: 20px; margin-left:10px;'><br/>Abortado.";
        die;
    }
}
//error_reporting (E_STRICT);
define('MODEL_ROUTE', '../../../public/models/');
require_once_model('Player', MODEL_ROUTE);
$globalConn = new GlobalDAO();
$playerConn = new PlayerDAO();
echo "Vaciando tablas";
soMuchWin($globalConn->truncateNonStaticData());
echo "Creando mapa";
$MAP_INCREMENTX = 10;
$MAP_INCREMENTY = 5;
require '../../controllers/global/seed_map_generator.php';
echo "<img src='../../../public/img/buttons/done.gif'><br/>";
$MAP_INCREMENTX = 2;
$MAP_INCREMENTY = 1;
echo "Reiniciando datos de Jugadores";
soMuchWin($globalConn->restartPlayerData());
echo "Asignando sectores iniciales";
$playerIdsArr = $globalConn->getAllPlayerIds();
$success = true;
foreach ($playerIdsArr as $playerIdArr) {
Example #13
0
<?php

if (!isset($_SESSION['nick'])) {
    header("Location: ../index.php");
} else {
    $nick = $_SESSION['nick'];
}
$playerConn = new PlayerDAO();
$staticData = $_SESSION['staticData'];
$allPlayers = $staticData->getPlayers();
$allResources = $staticData->getResources();
$allUnits = $staticData->getUnits();
$allTechnologies = $staticData->getTechnologies();
/* Iniciamos los datos del jugador que ha iniciado sesión */
$playerArr = $playerConn->getPlayerByNick($nick);
$player = $allPlayers[$playerArr[0]];
//Set player as logged in
//$rs = $connection->setPlayerLogged($player->getId(), true);
$availableResourcesArr = $playerConn->getAvailableResources($player->getAge());
foreach ($availableResourcesArr as $availableResourceArr) {
    $availableResources[$availableResourceArr[0]] = $allResources[$availableResourceArr[0]];
}
$player->setAvailableResources($availableResources);
$availableUnitsArr = $playerConn->getAvailableUnits($player);
foreach ($availableUnitsArr as $availableUnitArr) {
    $availableUnits[$availableUnitArr[0]] = $allUnits[$availableUnitArr[0]];
}
$player->setAvailableUnits($availableUnits);
$availableTechnologiesArr = $playerConn->getAvailableTechnologies($player->getId(), $player->getAge());
foreach ($availableTechnologiesArr as $availableTechnologyArr) {
    $technology = clone $allTechnologies[$availableTechnologyArr[0]];
Example #14
0
 public function save()
 {
     $sql = new DBAccess();
     $dao = new PlayerDAO($sql);
     $dao->save($this->vo);
 }
Example #15
0
function test_PlayerDAO()
{
    // in: player_id, out: vo with uname and player_id.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo = $dao->get($player_id);
    //var_dump($player_vo);
    assert(isset($player_vo));
    assert(isset($player_vo->uname));
    assert(isset($player_vo->player_id));
    // in: player_id, out: vo with same id.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2->player_id == $player_id);
    // in: player_id, out: vo with same username.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2->uname == 'glassbox');
    // in: player_id that doesn't exist, out: null
    $player_id = 999999;
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2 === null);
    // in: non-numeric player_id, out: false
    $player_id = 'not-a-player-id';
    $dao = new PlayerDAO($db);
    $player_vo2 = $dao->get($player_id);
    assert($player_vo2 === false);
    // in: player_vo, change the energy, save it. out: get that player, compare energy
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo_original = $dao->get($player_id);
    assert($player_vo_original->player_id == $player_id);
    $orig_energy = $player_vo_original->energy;
    $player_vo_original->energy = $player_vo_original->energy + 2;
    $dao->save($player_vo_original);
    $player_vo_after = $dao->get($player_vo_original->player_id);
    assert($orig_energy == $player_vo_after->energy - 2);
    // in: player_vo, change the energy, save it. out: get that player, compare energy
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    $dao = new PlayerDAO($db);
    $player_vo_original = $dao->get($player_id);
    $starting_clan = $player_vo_original->clan_long_name;
    $player_vo_original->clan_long_name = 'TestClanChange';
    $dao->save($player_vo_original);
    $changed_vo = $dao->get($player_vo_original->player_id);
    $changed_clan = $changed_vo->clan_long_name;
    $changed_vo->clan_long_name = $starting_clan;
    $dao->save($changed_vo);
    assert('TestClanChange' == $changed_clan);
    // in: a player_vo to change and save then delete, out: successful deletion
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    assert($player_id);
    $dao = new PlayerDAO($db);
    $player_vo = $dao->get($player_id);
    assert(isset($player_vo->player_id));
    $player_vo->player_id = null;
    $player_vo->uname = "TestUserName2";
    $player_vo->pname = "dummypassword";
    $dao->save($player_vo);
    $player_id_sel = "select player_id from players where uname = 'TestUserName2'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    assert($player_id);
    $dao = new PlayerDAO($db);
    $player_vo = $dao->get($player_id);
    assert(isset($player_vo->player_id));
    $deleted = $dao->delete($player_vo);
    // Need a player_id to delete.
    assert($deleted == true);
    $player_id_sel = "select player_id from players where uname = 'TestUserName2'";
    $deleted_id = $db->QueryItem($player_id_sel);
    assert($deleted_id == null);
    // in: a new player_vo to save n delete, out: no such new vo.
    $player_id_sel = "select player_id from players where uname = 'glassbox'";
    $db = new DBAccess();
    $player_id = $db->QueryItem($player_id_sel);
    assert($player_id);
    $dao = new PlayerDAO($db);
    $player_vo1 = $dao->get($player_id);
    assert(isset($player_vo1->player_id));
    $player_vo1->player_id = null;
    $username = "******" . rand();
    $player_vo1->uname = $username;
    $player_vo1->pname = "dummypassword";
    $dao->save($player_vo1);
    assert($player_vo1->player_id != 0);
    //var_dump($player_vo1->player_id, $player_vo1->uname);
    $saved_vo1 = $dao->get($player_vo1->player_id);
    $player_from_uname_sel = "select player_id from players where uname = '" . $username . "'";
    $player_id_from_uname = $db->QueryItem($player_from_uname_sel);
    assert($player_id_from_uname != false);
    //var_dump($player_id_from_uname, $username);
    $player_uname_from_id_sel = "select uname from players where player_id = '" . $player_vo1->player_id . "'";
    $player_uname = $db->QueryItem($player_uname_from_id_sel);
    //var_dump($saved_vo1->uname); // for some reason the vo is not coming back here.
    assert(isset($saved_vo1->player_id));
    assert($saved_vo1->uname == $username);
    assert($player_id_from_uname == $saved_vo1->player_id);
    $success = $dao->delete($saved_vo1);
    assert($success == true);
}
Example #16
0
    $iterator->next();
}
echo '<br />';
echo 'Login test';
echo '<br />';
$loginResult = $coachDAO->login("*****@*****.**", "1234");
echo '$loginResult: ' . $loginResult;
echo '<br />';
echo '<br />';
echo 'Team List test';
echo '<br />';
$teamDAO = new TeamDAO();
$team = $teamDAO->getTeamByCoachId(61);
echo 'teamID: ' . $team->get_teamId() . ', Team Name: ' . $team->get_teamName();
echo '<br />';
$playerDAO = new PlayerDAO();
$playerList = $playerDAO->getPlayersByTeamId(20);
$iterator = $playerList->getIterator();
echo 'Player List test';
echo '<br />';
while ($iterator->valid()) {
    $player = $iterator->current();
    echo 'PlayerName: ' . $player->get_fname() . ' ' . $player->get_lname() . ',TeamName=' . $player->get_teamName() . ', PlayerId: ' . $player->get_playerId() . ', Email=' . $player->get_email();
    echo '<br />';
    $iterator->next();
}
$locDAO = new LocationsDAO();
$locList = $locDAO->getTournaments("baseball");
$iterator = $locList->getIterator();
echo '<br />';
echo 'Location List test';
Example #17
0
        require_once_model('Technology');
        require_once_model('Sector');
        require_once_model('Player');
        require_once_model('Resource');
        require_once_model('StaticData');
        require_once_model('ProductionMod');
        require_once_model('BattleMod');
    }
}
//session_start();
$staticData = StaticData::singleton();
$termConn = new TermDAO();
$unitConn = new UnitDAO();
$buildingConn = new BuildingDAO();
$technologyConn = new TechnologyDAO();
$playerConn = new PlayerDAO();
$resourceConn = new ResourceDAO();
$productionModConn = new ProductionModDAO();
$battleModConn = new BattleModDAO();
Term::setLang($_SESSION['language']);
$termsArr = $termConn->getAllTerms($_SESSION['language']);
foreach ($termsArr as $termArr) {
    $term = new Term($termArr[0], $termArr[1]);
    $terms[$termArr[0]] = $term;
}
$battleModsArr = $battleModConn->getAllBattleMods();
foreach ($battleModsArr as $battleModArr) {
    $battleModName = $terms[$battleModArr[1]];
    $battleMod = new BattleMod($battleModArr[0], $battleModName, $battleModArr[2], $battleModArr[3], $battleModArr[4], $battleModArr[5]);
    $battleMods[$battleMod->getId()] = $battleMod;
}