/** * Loads the player relations (from buddylist). * * @return Bengine_Game_User_Relation */ protected function loadPlayerRelations() { if ($this->playersLoaded) { return $this; } $where = Core::getDB()->quoteInto("accepted = ? AND ", 1); $where .= Core::getDB()->quoteInto("(friend1 = ? OR friend2 = ?)", $this->userid); $result = Core::getQuery()->select("buddylist", array("friend1", "friend2"), "", $where); foreach ($result->fetchAll() as $row) { $rel = $row["friend1"] == $this->userid ? $row["friend2"] : $row["friend1"]; $this->players->push($rel); } $result->closeCursor(); $this->playersLoaded = true; Hook::event("PlayerRelationsLoaded", array(&$this->players)); return $this; }
/** * Count login attempt up and redirect to login site. * * @param string $errorid Error message id * * @return Login */ protected function loginFailed($errorid) { $this->errors->push($errorid); if ($this->countLoginAttempts) { $spec = array("time" => TIME, "ip" => IPADDRESS, "username" => $this->usr); Core::getQuery()->insert("loginattempts", $spec); } if ($this->redirectOnFailure) { forwardToLogin($errorid); } return $this; }
/** * Generates picture. * * @return Bengine_Game_Planet_Creator */ protected function setPicture() { $planetTypes = new Map(); $meta = Application::getMeta(); foreach ($meta["config"]["planet"]["type"] as $name => $planetType) { if ($this->position >= $planetType["from"] && $this->position <= $planetType["to"]) { $planetTypes->push(array("name" => $name, "number" => $planetType["number"])); } } $randomPlanet = $planetTypes->getRandomElement(); $this->picture = sprintf("%s%02d", $randomPlanet["name"], mt_rand(1, $randomPlanet["number"])); return $this; }
public function test_push_pop() { $num1 = rand(); $num2 = rand(); $nums = new Map(); $nums->push($num1); $this->assertCount(1, $nums); $nums->push($num2); $this->assertCount(2, $nums); $popped = $nums->pop(); $this->assertCount(1, $nums); $this->assertSame($num2, $popped); $popped = $nums->pop(); $this->assertCount(0, $nums); $this->assertSame($num1, $popped); }