作者:vibroci
项目:BigBrothe
public function spawnTo(Player $player)
{
if ($player instanceof DesktopPlayer) {
if ($this !== $player and $this->spawned === true and $player->getLevel() === $this->getLevel() and $player->canSee($this)) {
$this->hasSpawned[$player->getID()] = $player;
$pk = new SpawnPlayerPacket();
if ($player->getRemoveFormat()) {
$pk->name = TextFormat::clean($this->nameTag);
} else {
$pk->name = $this->nameTag;
}
$pk->eid = $this->getID();
$pk->uuid = $this->bigBrother_formatedUUID;
$pk->x = $this->x;
$pk->z = $this->y;
$pk->y = $this->z;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$pk->item = $this->inventory->getItemInHand()->getID();
$pk->metadata = $this->getData();
$pk->data = $this->bigBrother_properties;
$player->putRawPacket($pk);
$pk = new EntityTeleportPacket();
$pk->eid = $this->getID();
$pk->x = $this->x;
$pk->z = $this->y;
$pk->y = $this->z;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$player->putRawPacket($pk);
$pk = new SetEntityMotionPacket();
$pk->eid = $this->getID();
$pk->speedX = $this->motionX;
$pk->speedY = $this->motionY;
$pk->speedZ = $this->motionZ;
$player->dataPacket($pk);
$this->inventory->sendHeldItem($player);
$this->inventory->sendArmorContents($player);
}
} else {
parent::spawnTo($player);
}
}
作者:ChalkP
项目:PocketTelegra
public function onTelegramMessage(TelegramMessageEvent $event)
{
if (!PocketTelegram::$broadcastTelegramMessages) {
return;
}
$message = $event->getMessage();
switch (true) {
case $message instanceof TextMessage:
if (PocketTelegram::$enableTelegramCommands and $message->isCommand()) {
$this->handleTelegramCommands($message);
return;
}
$text = $message->getText();
break;
case $message instanceof PhotoMessage:
$text = "(Photo)";
break;
default:
return;
}
if ($message->getChat()->getId() !== PocketTelegram::getDefaultChannel()) {
return;
}
if (is_null($from = $message->getFrom()) or is_null($username = $from->getUsername())) {
return;
}
$this->broadcastMessage(PocketTelegram::getInstance()->getConfig()->get("telegramUserPrefix", "@") . $username, TextFormat::clean($text));
}
作者:Nader
项目:AdvancedKit
public function onSignChange(SignChangeEvent $event)
{
if (strtolower(TextFormat::clean($event->getLine(0))) === "[advancedkits]" and !$event->getPlayer()->hasPermission("advancedkits.admin")) {
$event->getPlayer()->sendMessage($this->ak->langManager->getTranslation("no-perm-sign"));
$event->setCancelled();
}
}
作者:NL-4-DEV
项目:Parkou
public function onPlayerTouch(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$b = $event->getBlock();
$name = $event->getPlayer()->getName();
$name = strtolower($name);
if ($b->getID() === 63 || $b->getID() === 68) {
$sign = $player->getLevel()->getTile($b);
if (!$sign instanceof Sign) {
return;
}
$sign = $sign->getText();
if (TextFormat::clean($sign[0]) === '[Checkpoint]') {
$this->data->set($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->data->save();
$player->sendMessage($this->getConfig()->get("CheckpointSaved"));
}
if (TextFormat::clean($sign[0]) === '[Earn Reward]') {
$this->data->remove($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->data->save();
$player->sendMessage($this->getConfig()->get("EarnReward"));
if ($this->getConfig()->get("reward-command")) {
$player->getServer()->dispatchCommand(new ConsoleCommandSender(), str_ireplace("{PLAYER}", $player->getName(), $this->getConfig()->get("reward-command")));
$player->teleport($player->getLevel()->getSafeSpawn());
}
}
}
if ($b->getID() === $this->getConfig()->get("CheckPointBlock")) {
$this->data->set($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->data->save();
$player->sendMessage($this->getConfig()->get("CheckpointSaved"));
}
}
作者:ClearSkyTea
项目:ClearSk
public function check()
{
for ($n = 0; $n < $this->threads; ++$n) {
if ($this->workers[$n]->isTerminated() === true) {
$this->workers[$n] = new RCONInstance($this->socket, $this->password, $this->clientsPerThread);
} elseif ($this->workers[$n]->isWaiting()) {
if ($this->workers[$n]->response !== "") {
$this->server->getLogger()->info($this->workers[$n]->response);
$this->workers[$n]->synchronized(function (RCONInstance $thread) {
$thread->notify();
}, $this->workers[$n]);
} else {
$response = new RemoteConsoleCommandSender();
$command = $this->workers[$n]->cmd;
$this->server->getPluginManager()->callEvent($ev = new RemoteServerCommandEvent($response, $command));
if (!$ev->isCancelled()) {
$this->server->dispatchCommand($ev->getSender(), $ev->getCommand());
}
$this->workers[$n]->response = TextFormat::clean($response->getMessage());
$this->workers[$n]->synchronized(function (RCONInstance $thread) {
$thread->notify();
}, $this->workers[$n]);
}
}
}
}
作者:legoboy021
项目:LegionPE-Theta-Bas
public function onPostRelease($rowId)
{
if ($this->src === "{BOT}CapsDetector" or $this->src === "{BOT}SwearDetector") {
return;
}
$message = implode("\n", ["{$this->src} @ `{$this->ip}:{$this->port}` executed /console. Message `#{$rowId}``:", MUtils::toMd($this->msg)]);
$isBot = substr($this->src, 0, 5) === "{BOT}";
$this->main->getServer()->getScheduler()->scheduleAsyncTask(new PostUrlTask(Credentials::SLACK_WEBHOOK, json_encode(["text" => TextFormat::clean($message), "icon_url" => Credentials::LEGIONPE_ICON_URL, "username" => $isBot ? substr($this->src, 5) : $this->src, "channel" => $isBot ? "#spam" : "#support"])));
}
作者:happyexcee
项目:PocketMine-Plugins-
/**
* Replaces all formatted color codes in the specified message, if revert is true, it will remove all text effects
* @param string $message
* @param bool $revert
* @return string
*/
public static function replaceSymbols($message, $revert = false)
{
$defaultFormat = [TextFormat::BLACK, TextFormat::DARK_BLUE, TextFormat::DARK_GREEN, TextFormat::DARK_AQUA, TextFormat::DARK_RED, TextFormat::DARK_PURPLE, TextFormat::GOLD, TextFormat::GRAY, TextFormat::DARK_GRAY, TextFormat::BLUE, TextFormat::GREEN, TextFormat::AQUA, TextFormat::RED, TextFormat::LIGHT_PURPLE, TextFormat::YELLOW, TextFormat::WHITE, TextFormat::OBFUSCATED, TextFormat::BOLD, TextFormat::STRIKETHROUGH, TextFormat::UNDERLINE, TextFormat::ITALIC, TextFormat::RESET];
$newFormat = ["&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&k", "&l", "&m", "&n", "&o", "&r"];
if ($revert) {
return TextFormat::clean($message);
} else {
return str_replace($newFormat, $defaultFormat, $message);
}
}
作者:legoboy021
项目:LegionPE-Theta-Bas
public function onQueryRegen(QueryRegenerateEvent $event)
{
$event->setWorld($this->main->query_world());
$this->main->getPlayersCount($total, $max, $classTotal, $classMax);
$event->setPlayerCount($classTotal);
$event->setMaxPlayerCount($classMax);
$event->setPlayerList([]);
$event->setServerName(TextFormat::clean($this->main->getServer()->getNetwork()->getName()));
$extra = $event->getExtraData();
$extra["class_numplayers"] = $classMax;
$extra["class_maxplayers"] = $classMax;
$this->addExtras($extra);
$event->setExtraData($extra);
}
作者:Addison11
项目:LegionPE-Theta-Bas
public function onQueryRegen(QueryRegenerateEvent $event)
{
$event->setWorld($this->main->query_world());
$this->main->getPlayersCount($total, $max, $classTotal, $classMax);
$event->setPlayerCount($classTotal);
$event->setMaxPlayerCount($classMax);
$event->setPlayerList([]);
$event->setServerName(TextFormat::clean($this->main->getServer()->getNetwork()->getName()));
$extra = $event->getExtraData();
$name = strtolower(Settings::$CLASSES_NAMES[Settings::$LOCALIZE_CLASS]);
$extra[$name . "_numplayers"] = $classTotal;
$extra[$name . "_maxplayers"] = $classMax;
$this->addExtras($extra);
$event->setExtraData($extra);
}
作者:EpicArtz0899
项目:Developmen
public function onRun($currentTick)
{
foreach ($this->plugin->getServer()->getLevels() as $levels) {
foreach ($levels->getTiles() as $tiles) {
if ($tiles instanceof Sign) {
$text = $tiles->getText();
if (TextFormat::clean(strtolower(trim($text[0]))) === strtolower(trim($this->plugin->sign->get("sign_final_change")))) {
$world = $text[1];
$level = $this->plugin->getServer()->getLevelByName($world);
$players = count($level->getPlayers());
$tiles->setText($text[0] = TextFormat::GREEN . $this->plugin->sign->get("sign_final_change"), $text[2] = TextFormat::YELLOW . $players . " players");
}
}
}
}
}
作者:gitter-badge
项目:Parkou
public function onPlayerTouch(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$b = $event->getBlock();
$name = $event->getPlayer()->getName();
$name = strtolower($name);
if ($b->getID() == 63 || $b->getID() == 68) {
$sign = $player->getLevel()->getTile($b);
if (!$sign instanceof Sign) {
return;
}
$sign = $sign->getText();
if (TextFormat::clean($sign[0]) === '[Checkpoint]') {
$this->config->set($name, array($player->x, $player->y, $player->z, $player->getLevel()->getName()));
$this->config->save();
$player->sendMessage("Saved");
} elseif (TextFormat::clean($sign[0]) === '[To Checkpoint]') {
$pos = $this->config->get($name);
if (is_array($pos)) {
if (count($pos) === 4) {
$player->sendMessage("Teleporting to Checkpoint...");
$level = $this->getServer()->getLevelByName($pos[3]);
if ($level) {
$player->teleport(new Position($pos[0], $pos[1], $pos[2], $level));
} else {
$player->sendMessage("Level is not loaded");
}
} else {
$player->sendMessage("Save Corrupted");
}
} else {
$player->sendMessage("No Save Found");
}
}
}
}
作者:brandon1581
项目:PocketDockConsol
/**
* Handle data received from a client
*
* @param Payload $payload A payload object, that supports __toString()
* @param Connection $connection
*/
public function onData($payload, $connection)
{
$payloado = $payload;
$payload = trim($payload);
if (in_array($connection, $this->autharray)) {
$this->thread->buffer .= $payloado;
if (stripos($payloado, "json") != -1) {
} else {
$connection->send($payload . "\r\n");
}
} elseif ($this->tryAuth($payload)) {
$this->autharray[] = $connection;
$connection->send(TextFormat::toANSI(TextFormat::DARK_GREEN . "[PocketDockConsole] Authenticated! Now accepting commands\r\n"));
$this->thread->log(TextFormat::DARK_GREEN . "Successful login from: " . $connection->getIp() . "!");
$stuffArray = explode("\n", $this->thread->stuffToSend);
$stuffArray = array_reverse($stuffArray);
for ($i = $this->thread->backlog; $i >= 0; $i--) {
if (isset($stuffArray[$i])) {
$line = trim($stuffArray[$i]) . "\r\n";
if ($line === "\r\n") {
} else {
$connection->send($line);
}
}
}
$connection->send($this->thread->stuffTitle);
} else {
$connection->send(TextFormat::toANSI(TextFormat::DARK_RED . "[PocketDockConsole] Failed login attempt, this event will be recorded!\r\n"));
$this->thread->log(TextFormat::DARK_RED . "Failed login attempt from: " . $connection->getIp() . "!");
}
}
作者:iPocketTea
项目:BigBrothe
public function serverToInterface(DesktopPlayer $player, DataPacket $packet)
{
switch ($packet->pid()) {
case Info::DISCONNECT_PACKET:
if ($player->bigBrother_getStatus() === 0) {
$pk = new LoginDisconnectPacket();
$pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message);
} else {
$pk = new PlayDisconnectPacket();
$pk->reason = TextFormat::toJSON($packet->message === "" ? "You have been disconnected." : $packet->message);
}
return $pk;
case Info::TEXT_PACKET:
echo $player->getSetting("Lang") . "\n";
/*if($packet->message === "chat.type.achievement"){
/*$pk = new ScoreboardObjectivePacket();
$pk->ObjectiveName = $packet->parameters[0];
$pk->Mode = 0;
$pk->ObjectiveValue = 3;
return $pk;*/
/*echo "TextPacket: achievement\n";
return null;
}else{
$pk = new STCChatPacket();
$pk->message = TextFormat::toJSON($packet->message, $packet->type, $packet->parameters);
}*/
//return $pk;
return null;
case Info::SET_TIME_PACKET:
$pk = new TimeUpdatePacket();
$pk->age = $packet->time;
$pk->time = $packet->time;
//TODO: calculate offset from MCPE
return $pk;
case Info::START_GAME_PACKET:
$packets = [];
$pk = new JoinGamePacket();
$pk->eid = $packet->eid;
$pk->gamemode = $packet->gamemode;
$pk->dimension = 0;
$pk->difficulty = $player->getServer()->getDifficulty();
$pk->maxPlayers = $player->getServer()->getMaxPlayers();
$pk->levelType = "default";
$packets[] = $pk;
$pk = new SpawnPositionPacket();
$pk->spawnX = $packet->spawnX;
$pk->spawnY = $packet->spawnY;
$pk->spawnZ = $packet->spawnZ;
$packets[] = $pk;
$pk = new PlayerAbilitiesPacket();
$pk->flyingSpeed = 0.05;
$pk->walkingSpeed = 0.1;
$pk->canFly = ($player->getGamemode() & 0x1) > 0;
$pk->damageDisabled = ($player->getGamemode() & 0x1) > 0;
$pk->isFlying = false;
$pk->isCreative = ($player->getGamemode() & 0x1) > 0;
$packets[] = $pk;
$pk = new PositionAndLookPacket();
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $player->yaw;
$pk->pitch = $player->pitch;
$packets[] = $pk;
return $packets;
case Info::ADD_PLAYER_PACKET:
$packets = [];
$packetplayer = $player->getServer()->getPlayerExact($packet->username);
$pk = new PlayerListPacket();
$pk->actionID = PlayerListPacket::TYPE_ADD;
$pk->players[] = [$packetplayer->getUniqueId()->toBinary(), $packetplayer->getName(), [], $packetplayer->getGamemode(), 0, false];
if ($packetplayer instanceof DesktopPlayer) {
$pk->players[0][2] = $packetplayer->bigBrother_getPeroperties();
}
$packets[] = $pk;
$pk = new SpawnPlayerPacket();
$pk->eid = $packet->eid;
$pk->uuid = $packetplayer->getUniqueId()->toBinary();
$pk->x = $packet->x;
$pk->z = $packet->z;
$pk->y = $packet->y;
$pk->yaw = $packet->yaw;
$pk->pitch = $packet->pitch;
$pk->item = $packetplayer->getInventory()->getItemInHand()->getId();
$pk->metadata = $packet->metadata;
$packets[] = $pk;
$pk = new EntityTeleportPacket();
$pk->eid = $packet->eid;
$pk->x = $packet->x;
$pk->y = $packet->y;
$pk->z = $packet->z;
$pk->yaw = $packet->yaw;
$pk->pitch = $packet->pitch;
$packets[] = $pk;
return $packets;
/*case Info::ADD_ENTITY_PACKET:
return null;*/
/*case Info::REMOVE_PLAYER_PACKET:
$pk = new PlayerListPacket();
$pk->actionID = PlayerListPacket::TYPE_REMOVE;
//.........这里部分代码省略.........
作者:flaxue
项目:BuddyPet
public function getPlayer($player)
{
if (!$this->validateName($player, false)) {
return false;
}
$player = strtolower($player);
$found = false;
foreach ($this->getServer()->getOnlinePlayers() as $p) {
if (strtolower(TextFormat::clean($p->getDisplayName(), true)) === $player || strtolower($p->getName()) === $player) {
$found = $p;
break;
}
}
// If cannot get the exact player name/nick, try with portions of it
if (!$found) {
$found = ($f = $this->getServer()->getPlayer($player)) === null ? false : $f;
// PocketMine function to get from portions of name
}
/*
* Copy from PocketMine's function (use above xD) but modified to work with Nicknames :P
*
* ALL THE RIGHTS FROM THE FOLLOWING CODE BELONGS TO POCKETMINE-MP
*/
if (!$found) {
$delta = \PHP_INT_MAX;
foreach ($this->getServer()->getOnlinePlayers() as $p) {
// Clean the Display Name due to colored nicks :S
if (\stripos($n = TextFormat::clean($p->getDisplayName(), true), $player) === 0) {
$curDelta = \strlen($n) - \strlen($player);
if ($curDelta < $delta) {
$found = $p;
$delta = $curDelta;
}
if ($curDelta === 0) {
break;
}
}
}
}
return $found;
}
作者:Skull3
项目:DontStopRunnin
public function onInteract(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$sign = $event->getPlayer()->getLevel()->getTile($event->getBlock());
if ($event->getBlock()->getId() == 63 or $event->getBlock()->getId() == 68) {
if ($sign instanceof Sign) {
$signtext = $sign->getText();
if (TextFormat::clean($signtext[0]) === "[DeadEnd]") {
$player->teleport(126.3, 5, 128.3, DeadEnd - lobby);
$player->sendMessage(TextFormat::GOLD . "You entered DeadEnd!");
}
}
}
}
作者:WonderlandP
项目:Steadfast
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
if ($packet->pid() === ProtocolInfo::BATCH_PACKET) {
/** @var BatchPacket $packet */
$this->server->getNetwork()->processBatch($packet, $this);
return;
}
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
return;
}
switch ($packet->pid()) {
case ProtocolInfo::LOGIN_PACKET:
/*
* A/N: Not going to implement any session code until it actually does stuff.
* Single line functions are obnoxious to follow.
*/
if ($this->loggedIn === true) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->setNameTag($this->username);
$this->iusername = strtolower($this->username);
$this->randomClientId = $packet->clientId;
$this->loginData = ["clientId" => $packet->clientId, "loginData" => null];
$this->uuid = $packet->clientUUID;
$this->rawUUID = $this->uuid->toBinary();
$this->clientSecret = $packet->clientSecret;
$this->protocol = $packet->protocol1;
if (count($this->server->getOnlinePlayers()) > $this->server->getMaxPlayers() and $this->kick("Server is full")) {
break;
}
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "";
if ($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "Please update Minecraft PE to join.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
$this->dataPacket($pk);
} else {
$message = "Please use an older version of Minecraft PE.";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
$this->dataPacket($pk);
}
$this->close("", $message, false);
return;
}
if (strpos($packet->username, "") !== false or preg_match('#^[a-zA-Z0-9_]{3,16}$#', $packet->username) == 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or strlen($packet->username) > 16 or strlen($packet->username) < 3) {
$this->close("", "Please choose a valid username.");
return;
}
if (strlen($packet->skin) < 64 * 32 * 4) {
$this->close("", "Invalid skin.", false);
return;
}
$this->setSkin($packet->skin, $packet->slim);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
if ($ev->isCancelled()) {
$this->close("", $ev->getKickMessage());
return;
}
if (!$this->server->isWhitelisted(strtolower($this->getName()))) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "Server is private.");
return;
} elseif ($this->server->getNameBans()->isBanned(strtolower($this->getName())) or $this->server->getIPBans()->isBanned($this->getAddress())) {
$this->close(TextFormat::YELLOW . $this->username . " has left the game", "You have been banned.");
return;
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_USERS)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_USERS, $this);
}
if ($this->hasPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE)) {
$this->server->getPluginManager()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
}
foreach ($this->server->getOnlinePlayers() as $p) {
if ($p !== $this and strtolower($p->getName()) === strtolower($this->getName())) {
if ($p->kick("You connected from somewhere else.") === false) {
$this->close(TextFormat::YELLOW . $this->getName() . " has left the game", "You connected from somewhere else.");
return;
} else {
return;
}
}
}
$nbt = $this->server->getOfflinePlayerData($this->username);
if (!isset($nbt->NameTag)) {
//.........这里部分代码省略.........
作者:robske11
项目:ClearSk
/**
* Handles a Minecraft packet
* TODO: Separate all of this in handlers
*
* WARNING: Do not use this, it's only for internal use.
* Changes to this function won't be recorded on the version.
*
* @param DataPacket $packet
*/
public function handleDataPacket(DataPacket $packet)
{
if ($this->connected === false) {
return;
}
if ($packet::NETWORK_ID === ProtocolInfo::BATCH_PACKET) {
/** @var BatchPacket $packet */
$this->server->getNetwork()->processBatch($packet, $this);
return;
}
$timings = Timings::getReceiveDataPacketTimings($packet);
$timings->startTiming();
$this->server->getPluginManager()->callEvent($ev = new DataPacketReceiveEvent($this, $packet));
if ($ev->isCancelled()) {
$timings->stopTiming();
return;
}
switch ($packet::NETWORK_ID) {
case ProtocolInfo::ITEM_FRAME_DROP_ITEM_PACKET:
$tile = $this->level->getTile($this->temporalVector->setComponents($packet->x, $packet->y, $packet->z));
if ($tile instanceof ItemFrame) {
if ($tile->getItem()->getId() !== Item::AIR) {
$this->getServer()->getPluginManager()->callEvent($ev = new ItemFrameDropItemEvent($this->getLevel()->getBlock($tile), $this, $tile->getItem(), $tile->getItemDropChance()));
if (!$ev->isCancelled()) {
if (mt_rand(0, 10) / 10 <= $tile->getItemDropChance()) {
$this->level->dropItem($tile, $tile->getItem());
}
$tile->setItem(Item::get(Item::AIR));
$tile->setItemRotation(0);
}
}
}
break;
case ProtocolInfo::PLAYER_INPUT_PACKET:
break;
case ProtocolInfo::LOGIN_PACKET:
if ($this->loggedIn) {
break;
}
$this->username = TextFormat::clean($packet->username);
$this->displayName = $this->username;
$this->iusername = strtolower($this->username);
#$this->setDataProperty(self::DATA_NAMETAG, self::DATA_TYPE_STRING, $this->username, false);
if ($this->server->getMaxPlayers() !== -1) {
if (count($this->server->getOnlinePlayers()) >= $this->server->getMaxPlayers() and $this->kick("disconnectionScreen.serverFull", false)) {
break;
}
}
if (!in_array($packet->protocol, ProtocolInfo::ACCEPT_PROTOCOL)) {
if ($packet->protocol < ProtocolInfo::CURRENT_PROTOCOL) {
$message = "disconnectionScreen.outdatedClient";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT;
$this->directDataPacket($pk);
} else {
$message = "disconnectionScreen.outdatedServer";
$pk = new PlayStatusPacket();
$pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER;
$this->directDataPacket($pk);
}
$this->close("", $message, false);
break;
}
$this->randomClientId = $packet->clientId;
$this->uuid = UUID::fromString($packet->clientUUID);
$this->rawUUID = $this->uuid->toBinary();
$this->identityPublicKey = $packet->identityPublicKey;
$this->chainData = $packet->chainData;
$valid = true;
$len = strlen($packet->username);
if ($len > 16 or $len < 3) {
$valid = false;
}
for ($i = 0; $i < $len and $valid; ++$i) {
$c = ord($packet->username[$i]);
if ($c >= ord("a") and $c <= ord("z") or $c >= ord("A") and $c <= ord("Z") or $c >= ord("0") and $c <= ord("9") or $c === ord("_")) {
continue;
}
$valid = false;
break;
}
if (!$valid or $this->iusername === "rcon" or $this->iusername === "console") {
$this->close("", "disconnectionScreen.invalidName");
break;
}
if (strlen($packet->skin) !== 64 * 32 * 4 and strlen($packet->skin) !== 64 * 64 * 4) {
$this->close("", "disconnectionScreen.invalidSkin");
break;
}
$this->setSkin($packet->skin, $packet->skinId);
$this->server->getPluginManager()->callEvent($ev = new PlayerPreLoginEvent($this, "Plugin reason"));
//.........这里部分代码省略.........
作者:iTXTec
项目:Genisy
protected function send($message, $level, $prefix, $color)
{
$now = time();
$thread = \Thread::getCurrentThread();
if ($thread === null) {
$threadName = "Server thread";
} elseif ($thread instanceof Thread or $thread instanceof Worker) {
$threadName = $thread->getThreadName() . " thread";
} else {
$threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
}
if ($this->shouldRecordMsg) {
if (time() - $this->lastGet >= 10) {
$this->shouldRecordMsg = false;
} else {
if (strlen($this->shouldSendMsg) >= 10000) {
$this->shouldSendMsg = "";
}
$this->shouldSendMsg .= $color . "|" . $prefix . "|" . trim($message, "\r\n") . "\n";
}
}
$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s", $now) . "] " . TextFormat::RESET . $color . "[" . $threadName . "/" . $prefix . "]:" . " " . $message . TextFormat::RESET);
//$message = TextFormat::toANSI(TextFormat::AQUA . "[" . date("H:i:s") . "] ". TextFormat::RESET . $color ."<".$prefix . ">" . " " . $message . TextFormat::RESET);
$cleanMessage = TextFormat::clean($message);
if (!Terminal::hasFormattingCodes()) {
echo $cleanMessage . PHP_EOL;
} else {
echo $message . PHP_EOL;
}
if (isset($this->consoleCallback)) {
call_user_func($this->consoleCallback);
}
if ($this->attachment instanceof \ThreadedLoggerAttachment) {
$this->attachment->call($level, $message);
}
$this->logStream[] = date("Y-m-d", $now) . " " . $cleanMessage . "\n";
if ($this->logStream->count() === 1) {
$this->synchronized(function () {
$this->notify();
});
}
}
作者:legoboy021
项目:LegionPE-Theta-Bas
public static function toMd($string)
{
if (!\is_array($string)) {
$string = TextFormat::tokenize($string);
}
$newString = "";
$tokens = 0;
$close = "";
foreach ($string as $token) {
switch ($token) {
case TextFormat::BOLD:
$newString .= $close . "**";
$close = "**";
++$tokens;
break;
case TextFormat::OBFUSCATED:
$newString .= $close . "~~";
$close = "~~";
++$tokens;
break;
case TextFormat::ITALIC:
$newString .= $close . "_";
$close = "_";
++$tokens;
break;
case TextFormat::UNDERLINE:
$newString .= $close;
$close = "";
++$tokens;
break;
case TextFormat::STRIKETHROUGH:
$newString .= $close . "~~";
$close = "~~";
++$tokens;
break;
case TextFormat::RESET:
$newString .= $close;
$close = "";
$tokens = 0;
break;
//Colors
//Colors
case TextFormat::BLACK:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::DARK_BLUE:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::DARK_GREEN:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::DARK_AQUA:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::DARK_RED:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::DARK_PURPLE:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::GOLD:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::GRAY:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::DARK_GRAY:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::BLUE:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::GREEN:
$newString .= $close . "`";
$close = "`";
++$tokens;
break;
case TextFormat::AQUA:
$newString .= $close . "`";
$close = "`";
//.........这里部分代码省略.........
作者:LegionP
项目:LegionPE-Et
public function log($level, $message)
{
$this->sender->push(TextFormat::clean("[{$level}] {$message}"));
}