public function removePenguin($penguin) { $this->removeClient($penguin->socket); $this->databaseManager->remove($penguin); unset($this->penguins[$penguin->socket]); Logger::Notice("Player disconnected"); }
protected function loginAttempt($penguin) { $username = Packet::$Data['body']['login']['nick']; if (strstr($username, '|') !== false) { list(, , $username) = explode('|', $username); } Logger::Notice("{$username} is attempting to login"); }
private function createDatabase() { $newDatabase = new Database(); $this->databaseConnections[] = $newDatabase; $databaseIndex = array_search($newDatabase, $this->databaseConnections); Logger::Debug("New database created"); return $databaseIndex; }
public function handleWorldPacket($penguin, $beforeCall = true) { if (isset($this->worldHandlers[Packet::$Extension]) && isset($this->worldHandlers[Packet::$Extension][Packet::$Handler])) { list($methodName) = $this->worldHandlers[Packet::$Extension][Packet::$Handler]; if (method_exists($this, $methodName)) { call_user_func(array($this, $methodName), $penguin); } else { Logger::Warn("Method '{$methodName}' doesn't exist in plugin '{$this->pluginName}'"); } } }
protected function handleReceive($socket, $data) { $chunkedArray = explode("", $data); array_pop($chunkedArray); foreach ($chunkedArray as $rawData) { Logger::Debug("Received {$data}"); $packet = Packet::Parse($rawData); if (Packet::$IsXML) { $this->handleXmlPacket($socket); } else { $this->handleWorldPacket($socket); } } }
protected function handleSaveMyMusicTrack($socket) { $penguin = $this->penguins[$socket]; list($trackName, $trackPattern, $trackHash) = array_slice(Packet::$Data, 2); $encodedPattern = $this->encodeMusicTrack($trackPattern); if ($encodedPattern == $trackHash) { $trackId = $penguin->database->savePlayerTrack($penguin->id, $trackName, $trackPattern, $trackHash); $penguin->send("%xt%savemymusictrack%-1%{$trackId}%"); } else { Logger::Warn("Track hashes don't match! {$trackHash} and {$encodedPattern}"); $this->removePenguin($penguin); } }
protected function handleDisconnect($socket) { $penguin = $this->penguins[$socket]; $this->removePenguin($penguin); Logger::Info("Player disconnected"); }
protected function handleWorldPacket($socket) { // p#getdigcooldown is received before xml sometimes.. dunno why if ($this->penguins[$socket]->identified == true || Packet::$Handler == "p#getdigcooldown") { // Bot detection - there's probably a better way of doing this if (Packet::$Handler !== "p#getdigcooldown") { if (Packet::$Handler !== "j#js" && $this->penguins[$socket]->room === null) { return $this->removePenguin($this->penguins[$socket]); } } $worldPacket = Packet::GetInstance(); $penguin = $this->penguins[$socket]; foreach ($this->loadedPlugins as $loadedPlugin) { if ($loadedPlugin->worldStalker) { $loadedPlugin->handleWorldPacket($penguin); } elseif (isset($loadedPlugin->worldHandlers[$worldPacket::$Extension][$worldPacket::$Handler])) { list($handlerCallback, $callInformation) = $loadedPlugin->worldHandlers[$worldPacket::$Extension][$worldPacket::$Handler]; if ($callInformation == Plugin::Before || $callInformation == Plugin::Both) { $loadedPlugin->handleWorldPacket($penguin); } } } if (isset($this->worldHandlers[$worldPacket::$Extension])) { if (!empty($this->worldHandlers[$worldPacket::$Extension])) { if (isset($this->worldHandlers[$worldPacket::$Extension][$worldPacket::$Handler])) { $handlerCallback = $this->worldHandlers[$worldPacket::$Extension][$worldPacket::$Handler]; if (is_array($handlerCallback)) { call_user_func($handlerCallback, $penguin); } elseif (method_exists($this, $handlerCallback)) { call_user_func(array($this, $handlerCallback), $socket); } else { Logger::Warn("Method for {$worldPacket::$Extension}%{$worldPacket::$Handler} is un-callable!"); } } else { Logger::Warn("Method for {$worldPacket::$Extension}%{$worldPacket::$Handler} doesn't exist/has not been set"); } } else { Logger::Warn("There are no handlers for {$worldPacket::$Extension}"); } } else { Logger::Warn("The packet extension '{$worldPacket::$Extension}' is not handled"); } foreach ($this->loadedPlugins as $loadedPlugin) { if ($loadedPlugin->worldStalker) { $loadedPlugin->handleWorldPacket($penguin, false); } elseif (isset($loadedPlugin->worldHandlers[$worldPacket::$Extension][$worldPacket::$Handler])) { list($handlerCallback, $callInformation) = $loadedPlugin->worldHandlers[$worldPacket::$Extension][$worldPacket::$Handler]; if ($callInformation == Plugin::After || $callInformation == Plugin::Both) { $loadedPlugin->handleWorldPacket($penguin, false); } } } } else { $this->removePenguin($this->penguins[$socket]); } }
protected function handleModeratorBan($socket) { $penguin = $this->penguins[$socket]; $player = Packet::$Data[2]; $banType = Packet::$Data[3]; $banReason = Packet::$Data[4]; $banDuration = Packet::$Data[5]; $penguinName = Packet::$Data[6]; $banNotes = Packet::$Data[7]; if ($penguin->moderator) { if (is_numeric($player)) { $targetPlayer = $this->getPlayerById($player); if ($targetPlayer !== null) { if ($banDuration !== 0) { $targetPlayer->database->updateColumnById($targetPlayer->id, "Banned", strtotime("+" . $banDuration . " hours")); } else { $targetPlayer->database->updateColumnById($targetPlayer->id, "Banned", "perm"); } $penguin->database->addBan($player, $penguin->username, $banNotes, $banDuration, $banType); $targetPlayer->send("%xt%ban%-1%{$banType}%{$banReason}%{$banDuration}%{$banNotes}%"); $this->removePenguin($targetPlayer); Logger::Info("{$penguin->username} has banned {$targetPlayer->username} for {$banDuration} hours"); } } } }
public function onReady() { parent::__construct(__CLASS__); Logger::Notice("The following items are unavailable: " . implode(", ", $this->patchedItems) . " (PatchedItems)"); }
protected function handleSendMove($socket) { $penguin = $this->penguins[$socket]; if ($penguin->waddleRoom !== null) { array_shift(Packet::$Data); $penguin->room->send("%xt%zm%" . implode('%', Packet::$Data) . '%'); } elseif ($penguin->tableId !== null) { $tableId = $penguin->tableId; $isPlayer = array_search($penguin, $this->playersByTableId[$tableId]) < 2; $gameReady = count($this->playersByTableId[$tableId]) >= 2; if ($isPlayer && $gameReady) { $chipColumn = Packet::$Data[2]; $chipRow = Packet::$Data[3]; $seatId = array_search($penguin, $this->playersByTableId[$tableId]); $libraryId = $seatId + 1; if ($this->gamesByTableId[$tableId]->currentPlayer === $libraryId) { // Prevents player from placing multiple chips on a single turn $gameStatus = $this->gamesByTableId[$tableId]->placeChip($chipColumn, $chipRow); foreach ($this->playersByTableId[$tableId] as $recipient) { $recipient->send("%xt%zm%{$recipient->room->internalId}%{$seatId}%{$chipColumn}%{$chipRow}%"); } $opponentSeatId = $seatId == 0 ? 1 : 0; if ($gameStatus === FindFour::FoundFour) { $penguin->addCoins(10); $this->playersByTableId[$tableId][$opponentSeatId]->addCoins(5); } elseif ($gameStatus === FindFour::Tie) { $penguin->addCoins(10); $this->playersByTableId[$tableId][$opponentSeatId]->addCoins(10); } } else { Logger::Warn("Attempted to drop multiple chips"); } } else { Logger::Warn("Player {$penguin->id} is a spectator or is trying to drop a chip before connecting to a player!"); } } }
protected function handleSendPufflePlay($socket) { Logger::Warn("Need to log packets"); }
public function send($data) { Logger::Debug("Outgoing: {$data}"); $data .= ""; $bytesWritten = socket_send($this->socket, $data, strlen($data), 0); return $bytesWritten; }
public function getColumnById($id, $column) { try { $getStatement = $this->prepare("SELECT {$column} FROM `penguins` WHERE ID = :ID"); $getStatement->bindValue(":ID", $id); $getStatement->execute(); $getStatement->bindColumn($column, $value); $getStatement->fetch(\PDO::FETCH_BOUND); $getStatement->closeCursor(); return $value; } catch (\PDOException $pdoException) { Logger::Warn($pdoException->getMessage()); } }