Inheritance: extends CI_Model
Esempio n. 1
1
function welcome($api)
{
    $bdd = getBDD();
    $req = $bdd->prepare('UPDATE at_welcome SET jour = now(), heure = now() WHERE mac = :mac');
    $req->execute(array('mac' => $api));
    $req->closeCursor();
    $player = new Player();
    $req = $bdd->prepare('SELECT at_music.file FROM at_music JOIN at_welcome ON at_music.id = at_welcome.music WHERE at_welcome.mac = mac');
    $req->execute(array('mac' => $mac));
    $data = $req->fetch();
    $player->play($data['file']);
    $req->closeCursor();
}
 public static function handle_register()
 {
     $firstname = $_POST['firstname'];
     $username = $_POST['username'];
     $password = $_POST['password'];
     $password2 = $_POST['password2'];
     $errors = array();
     if ($firstname == null) {
         $errors[] = "Syötä nimesi.";
     }
     if ($username == null) {
         $errors[] = "Syötä uusi käyttäjätunnus.";
     }
     if (Player::username_exists($username)) {
         $errors[] = "Käyttäjätunnus on jo käytössä. Valitse toinen käyttäjätunnus.";
     }
     if ($password == null || $password2 == null) {
         $errors[] = "Syötä uusi salasana.";
     }
     if ($password != $password2) {
         $errors[] = "Annetut salasanat eivät täsmänneet.";
     }
     if ($errors != null) {
         View::make('user/register.html', array('errors' => $errors, 'username' => $username, 'firstname' => $firstname));
     } else {
         // Register user/player and login
         $player = new Player(array('firstname' => $firstname, 'username' => $username, 'password' => crypt($password)));
         $player->save();
         // POST params for signing in are the same in register.html and login.html
         self::handle_login();
     }
 }
 public function CreateControls()
 {
     $this->AddCssClass('form');
     $this->SetButtonText("Save player");
     # get player to edit
     $player = $this->GetDataObject();
     if (!$player instanceof Player) {
         $player = new Player($this->GetSettings());
     }
     require_once "xhtml/forms/radio-button.class.php";
     if ($this->GetCurrentPage() == PlayerEditor::MERGE_PLAYER) {
         $this->AddControl("<p>There's another player named '" . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . "' in this team. What would you like to do?</p>");
         $this->AddControl("<dl class=\"decision\"><dt>");
         $this->AddControl(new RadioButton($this->GetNamingPrefix() . "Merge", $this->GetNamingPrefix() . "MergeOptions", htmlentities("Merge with the other " . $player->GetName(), ENT_QUOTES, "UTF-8", false), 1, false, $this->IsValid()));
         $this->AddControl("</dt><dd>If they're the same person you can merge the records so there's only one " . htmlentities($player->GetName(), ENT_QUOTES, "UTF-8", false) . ". Don't choose this for a player who's got married and changed their name though.</dd>");
         $this->AddControl("<dt>");
         $this->AddControl(new RadioButton($this->GetNamingPrefix() . "Rename", $this->GetNamingPrefix() . "MergeOptions", "Choose a new name for this player", 2, false, $this->IsValid()));
         $this->AddControl("</dt><dd>If they're different people you need to pick a different name. For example, if you have two players called 'Jane Smith',\n\t\t\t\tchange one to 'Jane A Smith'.</dd></dl>");
     }
     # Container for form elements, useful for JavaScript to hide them
     $container = new XhtmlElement("div", null, "#playerEditorFields");
     $this->AddControl($container);
     # add name
     $name = new XhtmlElement("label", "Name");
     $name->AddAttribute("for", $this->GetNamingPrefix() . 'Name');
     $container->AddControl($name);
     $name_box = new TextBox($this->GetNamingPrefix() . 'Name', $player->GetName(), $this->IsValid());
     $name_box->AddAttribute('maxlength', 100);
     #$name = new FormPart('Name', $name_box);
     $container->AddControl($name_box);
 }
Esempio n. 4
0
function globalize_user_info($private = true, $alive = true)
{
    global $username;
    global $char_id;
    $error = null;
    $char_id = self_char_id();
    // Will default to null.
    //$username = get_username(); // Will default to null.
    if ((!is_logged_in() || !$char_id) && $private) {
        $error = 'log_in';
        // A non-null set of content being in the error triggers a die at the end of the header.
    } elseif ($char_id) {
        // **************** Player information settings. *******************
        global $player, $player_id;
        // Polluting the global namespace here.  Booo.
        $player = new Player($char_id);
        // Defaults to current session user.
        $username = $player->name();
        // Set the global username.
        $player_id = $player->player_id;
        assert('isset($player_id)');
        if ($alive) {
            // *** That page requires the player to be alive to view it.
            if (!$player->health()) {
                $error = 'dead';
            } else {
                if ($player->hasStatus(FROZEN)) {
                    $error = 'frozen';
                }
            }
        }
    }
    return $error;
}
Esempio n. 5
0
 /**
  * @covers Autumn\Janken\Domain\Player::showHand()
  */
 public function testShowHand()
 {
     $this->object = new Player("player 1");
     $expected = Player::STONE;
     $result = $this->object->showHand();
     $this->assertEquals($expected, $result);
 }
Esempio n. 6
0
 public static function instance(Player $player, Game $game)
 {
     $strategyRepository = new AiStrategyRepository();
     $strategy = $strategyRepository->getOneById($player['ai_strategy']);
     $strategyClassName = $strategy['title'];
     $role = $player->getRoleObject();
     if ($strategyClassName == 'Passive') {
         if ($role->getIsSheriff()) {
             // 2 players alive in game
             // or only bandits against me
             // or $me->getActualLives() <= $me->getMaxLives() / 2
             $strategyClassName = 'Normal';
         } elseif ($role->getIsRenegard()) {
             // 2 players alive in game
             // $game->getSheriff()->getActualLives() <= $game->getSheriff()->getMaxLives() / 2
             // or $me->getActualLives() <= $me->getMaxLives() / 2
             $strategyClassName = 'Normal';
         } elseif ($role->getIsBandit()) {
             // $game->getSheriff()->getActualLives() <= $game->getSheriff()->getMaxLives() / 2
             // or $me->getActualLives() <= $me->getMaxLives() / 2
             $strategyClassName = 'Normal';
         } elseif ($role->getIsVice()) {
             // $game->getSheriff()->getActualLives() <= $game->getSheriff()->getMaxLives() / 2
             // or $me->getActualLives() <= $me->getMaxLives() / 2
             $strategyClassName = 'Normal';
         }
     }
     $className = $strategyClassName . $role['title'] . 'Strategy';
     return new $className($player, $game);
 }
 public function testPlayer()
 {
     $player = new Player();
     $result = $player->betRequest(json_decode($this->gameState, true));
     $this->assertTrue(is_int($result));
     $this->assertGreaterThanOrEqual(0, $result);
 }
Esempio n. 8
0
 function post_register()
 {
     // set validation rules for new user content.
     $rules = array('name' => 'required|min:3|max:75', 'email' => 'required|unique:users|email', 'password' => 'required|min:5|max:64');
     $v = Validator::make(Input::all(), $rules);
     if ($v->fails()) {
         return Redirect::to('user/new')->with_input('except', array('password'))->with_errors($v);
     }
     $nameArr = explode(' ', Input::get('name'), 2);
     $player = new Player();
     $player->first_name = $nameArr[0];
     $player->last_name = isset($nameArr[1]) ? $nameArr[1] : '';
     $player->save();
     if ($player->save()) {
         $user = new User();
         $user->password = Hash::make(Input::get('password'));
         $user->email = Input::get('email');
         $user->player_id = $player->id;
         if ($user->save()) {
             // log the user in the session
             Auth::login($user->id);
             return Redirect::to('user')->with('welcomeMsg', true);
         } else {
             // oh shit. roll back the player and return an error
             $player->delete();
             return Redirect::to('user/new')->with_input('except', array('password'))->with('error', 'Nah fool... something went real wrong.');
         }
     } else {
         return Redirect::to('user/new')->with_input('except', array('password'))->with('error', 'This user could not be created.');
     }
 }
Esempio n. 9
0
 public function testStack()
 {
     $player = new Player('white');
     $stack = $player->getStack();
     $this->assertEquals(0, $player->getStack()->getVersion());
     $stack->addEvent(array('type' => 'test'));
     $this->assertEquals(1, $player->getStack()->getVersion());
 }
Esempio n. 10
0
 public function attack(Player $player)
 {
     $damage = $this->getDamage() - $player->getArmor();
     if ($damage < 1) {
         $damage = 1;
     }
     $player->decreaseHitpoints($damage);
 }
Esempio n. 11
0
 public function testRoleModification()
 {
     $role = new Role(Role::ADMINISTRATOR);
     $this->assertTrue($role->hasPerm(Permission::PUBLISH_NEWS));
     $this->assertFalse($this->player->hasPermission(Permission::PUBLISH_NEWS));
     $this->player->addRole($role);
     $this->assertTrue($this->player->hasPermission(Permission::PUBLISH_NEWS));
 }
Esempio n. 12
0
 public function distributeCards(Player $player)
 {
     $cards = $player->getCards();
     if ($player->isHuman()) {
         $this->playerCards = $cards;
     } else {
         $this->bankCards = $cards;
     }
 }
 public function testLifeCannotExceedMaxValue()
 {
     $player = new Player('John Doe');
     $player->gainLife(51);
     $this->assertEquals(Player::MAX_LIFE, $player->getLife());
     $player = new Player('John Doe');
     $player->setLife(151);
     $this->assertEquals(Player::MAX_LIFE, $player->getLife());
 }
Esempio n. 14
0
 public function testDeletingCustomNewsCategoryWithPosts()
 {
     $news = News::addNews(StringMocks::SampleTitleOne, StringMocks::LargeContent, $this->player_with_create_perms->getId(), $this->newsCategory->getId());
     $this->assertArrayLengthEquals($this->newsCategory->getNews(), 1);
     $this->newsCategory->delete();
     $this->assertEquals('enabled', $this->newsCategory->getStatus());
     $this->assertArrayContainsModel($this->newsCategory, NewsCategory::getCategories());
     $this->wipe($news);
 }
Esempio n. 15
0
 public function play()
 {
     $player = new Player();
     $result = array();
     foreach (range(1, 20) as $number) {
         $result[] = $player->fizzBuzz($number);
     }
     return $result;
 }
Esempio n. 16
0
File: Queue.php Progetto: nbar1/gs
 /**
  * Purge Old Queue Data
  *
  * Removes an item marked as playing if it's been
  * more than 15 minutes since it was played.
  *
  * @param array $queue
  * @return array Modified queue
  */
 public function purgeOldQueueData($queue)
 {
     if ($queue[0]['status'] == 'playing' && date('YmdHi', strtotime($queue[0]['ts_played'])) < date('YmdHi') - 15) {
         $player = new Player();
         $player->markSongPlayed($queue[0]['id']);
         array_shift($queue);
     }
     return $queue;
 }
Esempio n. 17
0
 public function showAction(Server $server, Player $me, Request $request)
 {
     if ($server->staleInfo()) {
         $server->forceUpdate();
     }
     if ($request->get('forced') && $me->canEdit($server)) {
         $server->forceUpdate();
     }
     return array("server" => $server);
 }
Esempio n. 18
0
 /**
  * Test getters
  */
 public function testGetters()
 {
     $connection = $this->getMock('Ratchet\\ConnectionInterface');
     $type = Player::TYPE_WEREWOLF;
     $nickname = "Villager 1";
     $player = new Player($connection, $type, $nickname);
     $this->assertEquals($connection, $player->getConnection());
     $this->assertEquals($type, $player->getType());
     $this->assertEquals($nickname, $player->getNickname());
 }
Esempio n. 19
0
 /**
  * @test
  */
 public function shouldNotGrantAccessWhenAccessIsAlreadyGiven()
 {
     // given
     $pl = new Player();
     // when
     $pl->grantAccessTo(ChessRoles::LOGIN);
     $pl->grantAccessTo(ChessRoles::LOGIN);
     // then
     $this->assertEquals(ChessRoles::LOGIN, $pl->getUserAccess());
 }
Esempio n. 20
0
 public function testMessageHasARobustSender()
 {
     $rec = new Player($this->char_id);
     Message::create(['send_from' => $rec->id(), 'send_to' => $this->char_id_2, 'message' => 'Random phpunit test message of some content', 'type' => 0]);
     $messages = Message::findByReceiver(new Player($this->char_id_2), $type = 0, $limit = 1000, $offset = 0);
     $this->assertGreaterThan(0, count($messages), 'Collection has no results found');
     $first_message = $messages->first();
     $this->assertTrue($first_message instanceof Message, 'First message not a valid message model');
     $this->assertNotEmpty($first_message->sender);
     $this->assertGreaterThan(0, strlen($first_message->sender));
 }
Esempio n. 21
0
 public function testAttackLegalCantAttackSelfEvenIfUsingSelfIdVsSelfUsername()
 {
     $this->setExpectedException('InvalidArgumentException');
     $char_id = TestAccountCreateAndDestroy::create_testing_account();
     $this->oldify_character_last_attack($char_id);
     $player = new Player($char_id);
     $info = $player->dataWithClan();
     $this->assertTrue((bool) $info['uname'], 'Character uname not found to check attacklegal with');
     $legal = new AttackLegal($player, $info['uname'], ['required_turns' => 1, 'ignores_stealth' => true]);
     $this->assertFalse($legal->check(false));
 }
Esempio n. 22
0
 public function testCantAttackIfExcessiveAmountOfTurnsIsRequired()
 {
     $confirm = true;
     $char_id = TestAccountCreateAndDestroy::create_testing_account($confirm);
     $this->oldify_character_last_attack($char_id);
     $char_2_id = TestAccountCreateAndDestroy::create_alternate_testing_account($confirm);
     $this->oldify_character_last_attack($char_2_id);
     $char = new Player($char_2_id);
     $legal = new AttackLegal($char_id, $char->name(), ['required_turns' => 4000000000.0, 'ignores_stealth' => true]);
     $this->assertFalse($legal->check($update_timer = false));
 }
Esempio n. 23
0
 /**
  * Handle the admin notes form
  * @param  Form   $form   The form
  * @param  Player $player The player in question
  * @param  Player $me     The currently logged in player
  * @return Form   The updated form
  */
 private function handleAdminNotesForm($form, $player, $me)
 {
     $notes = $form->get('notes')->getData();
     if ($form->get('save_and_sign')->isClicked()) {
         $notes .= ' — ' . $me->getUsername() . ' on ' . TimeDate::now()->toRFC2822String();
     }
     $player->setAdminNotes($notes);
     $this->getFlashBag()->add('success', "The admin notes for {$player->getUsername()} have been updated");
     // Reset the form so that the user sees the updated admin notes
     return $this->creator->create();
 }
Esempio n. 24
0
 function canCreateDeck($username)
 {
     if (strcasecmp($username, $this->player->name) == 0) {
         return true;
     }
     $player = new Player($username);
     if ($player->isSuper()) {
         return true;
     }
     return $this->event->isHost($username) || $this->event->isSteward($username);
 }
Esempio n. 25
0
 /**
  ** Location callbacks
  **/
 protected function OnEnter(Player $player, $numparams, $params)
 {
     if ($this->open) {
         return LOCATION_ALLOW;
     } else {
         if ($player->GetFaction() && $player->GetFaction()->ID() == $this->owner->ID()) {
             return LOCATION_ALLOW;
         }
     }
     GameTextForPlayer($player->id, '~r~Closed', 2000, 3);
     return LOCATION_DISALLOW;
 }
Esempio n. 26
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (!$ev->isCancelled()) {
         $player->getLevel()->setBlock($target, new RedstoneWire(), \true, \true);
         if ($player->isSurvival()) {
             $player->getInventory()->setItemInHand($ev->getItem(), $player);
         }
         return \true;
     } else {
         $player->getInventory()->sendContents($player);
     }
 }
 private function createAdminUser($details)
 {
     if (isset($details['adminUserName']) && isset($details['adminUserName'])) {
         $pl = new Player();
         $pl->grantAdminAccess();
         $pl->setUsername($details['adminUserName']);
         $pl->setPassword($details['adminPassword']);
         $pl->commit();
         $session = new Session();
         $session->signIn(array('username' => $details['adminUserName'], 'password' => $details['adminPassword'], 'rememberMe' => true));
     }
 }
Esempio n. 28
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (($player->gamemode & 0x1) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()) {
         $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
     }
     if ($block->getID() === AIR and $target instanceof SolidBlock) {
         $level->setBlock($block, new FireBlock(), true, false, true);
         $block->level->scheduleBlockUpdate(new Position($block, 0, 0, $block->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
         return true;
     }
     return false;
 }
Esempio n. 29
0
 public function wipeAction(Player $me)
 {
     $wipeable = array('Ban', 'Map', 'Match', 'News', 'NewsCategory', 'Page', 'Server', 'Team');
     $models = array();
     foreach ($wipeable as $type) {
         if (!$me->hasPermission($type::HARD_DELETE_PERMISSION)) {
             continue;
         }
         $models = array_merge($models, $type::getQueryBuilder()->where('status')->equals('deleted')->getModels());
     }
     return array('models' => $models);
 }
 public function __construct(Player $player)
 {
     $this->searchable = new SearchItem("player", "player" . $player->GetId(), $player->GetPlayerUrl());
     $this->searchable->Description($player->GetPlayerDescription());
     $this->searchable->WeightOfType(20);
     if ($player->GetPlayerRole() == Player::PLAYER) {
         $this->searchable->Title($player->GetName() . ", " . $player->Team()->GetName());
         $this->searchable->WeightWithinType($player->GetTotalMatches());
     } else {
         $this->searchable->Title($player->GetName() . " conceded by " . $player->Team()->GetName());
     }
     $this->searchable->Keywords($this->searchable->Title());
 }