Created
June 10, 2014 10:52
-
-
Save PEMapModder/707539b8f91efd70048a to your computer and use it in GitHub Desktop.
A snapshot of LegionPE hub's core code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HubPlugin extends PluginBase{ | |
public function onChat(PlayerChatEvent $event){ // if session is not self::HUB, monitor it. if session is self::HUB, prevent typing password here | |
$p = $event->getPlayer(); | |
if(($s = $this->sessions[$p->getID()]) < self::HUB or $s >= self::LOGIN){ // if not authed | |
$event->setCancelled(true); | |
} | |
elseif($this->getDb($p)->get("pw-hash") === $this->hash($event->getMessage())){ // if authed but is telling password | |
$event->setCancelled(true); | |
$p->sendMessage("Never talk loudly to others your password!"); | |
} | |
if($s === self::REGISTER){ // request repeat password: registry wizard step 1 | |
$this->tmpPws[$p->getID()] = $event->getMessage(); | |
$p->sendMessage("Step 2:"); | |
$p->sendMessage("Please enter your password again to confirm."); | |
$this->sessions[$p->getID()] ++; | |
} | |
elseif($s === self::REGISTER + 1){ // check repeated password: registry wizard step 2 | |
if($this->tmpPws[$p->getID()] === $event->getMessage()){ // choose team, if matches password | |
$p->sendMessage("The password matches! Type this password into your chat and send it next time you login."); | |
$p->sendMessage("LegionPE registry wizard closed!"); | |
$this->getDb($p)->set("pw-hash", $this->hash($event->getMessage())); | |
var_export($this->hash($event->getMessage())); | |
var_export($this->hash($event->getMessage())); | |
$this->getDb($p)->save(); | |
$this->sessions[$p->getID()]++; | |
unset($this->tmpPws[$p->getID()]); | |
console($p->getDisplayName()." successfully registered!"); | |
$this->onRegistered($p); | |
} | |
else{ // if password different | |
$p->sendMessage("Password doesn't match! Going back to step 1."); | |
$p->sendMessage("Please type your password in the chat."); | |
$this->sessions[$p->getID()] = self::REGISTER; | |
} | |
} | |
elseif($s >= self::LOGIN){ // check password, if session is waiting login | |
$hash = $this->getDb($p)->get("pw-hash"); | |
if($this->hash($event->getMessage()) === $hash){ // auth, if password matches | |
if($this->getDb($p)->get("ip-auth") !== false){ // update IP | |
$this->getDb($p)->set("ip-auth", $p->getAddress()); | |
$p->sendMessage("Your IP address has been updated to \"{$p->getAddress()}\"."); | |
} | |
$this->onAuthPlayer($p); | |
} | |
else{ // add session, if password doesn't match | |
$p->sendMessage("Password doesn't match! Please try again."); | |
$this->sessions[$p->getID()]++; | |
if($s >= self::LOGIN_MAX){ // if reaches maximum trials of login | |
$p->sendMessage("You exceeded the max number of trials to login! You are being kicked."); | |
$this->getServer()->getScheduler()->scheduleDelayedTask( | |
new CallbackPluginTask(array($p, "close"), $this, array("Failing to auth.", "Auth failure"), true), 80); | |
} | |
} | |
} | |
} | |
} | |
?> | |
<?php | |
class Hub{ | |
protected function joinMg(Player $p, MgMain $mg){ | |
$TID = $this->hub->getDb($p)->get("team"); | |
if(($reason = $mg->isJoinable($p, $TID)) === true){ | |
$this->server->getScheduler()->scheduleDelayedTask(new CallbackPluginTask(array($p, "teleport"), $this->hub, $mg->getSpawn($p, $TID)), 40); | |
$p->teleport($mg->getSpawn($p, $TID)); | |
$p->sendMessage("You are teleported to the"); | |
$p->sendMessage(" ".$mg->getName()." world! You might lag!"); | |
$this->teleports[$p->getID()] = time(); | |
$this->hub->sessions[$p->getID()] = $mg->getSessionId(); | |
if(!$this->hub->getDb($p)->get("mute")){ | |
$this->setChannel($p, $mg->getDefaultChatChannel($p, $TID)); | |
} | |
$mg->onJoinMg($p); | |
} | |
else{ | |
$p->sendMessage("{$mg->getName()} cannot be joined currently due to $reason!"); | |
$p->teleport(RL::spawn()); | |
} | |
} | |
public function parseChannel(Player $player, $chan){ | |
$t = $this->hub->getDb($player)->get("team"); | |
$s = $this->hub->getSession($player); | |
$spleef = ($s === HubPlugin::SPLEEF); | |
switch(strtolower($chan)){ | |
case "general": | |
case "gen": | |
case "g": | |
case "public": | |
case "pub": | |
case "p": | |
$ch = "public"; | |
break; | |
case "team": | |
case "t": | |
$ch = $t; | |
break; | |
case "arena": | |
case "a": | |
case "at": | |
case "arenateam": | |
case "teamarena": | |
case "ta": | |
if($spleef){ | |
$ch = Spleef::get()->getArena($player); | |
if($ch !== false){ | |
$ch = "s".$ch.((stripos($chan, "t") !== false) ? (".t".$t):""); | |
break; | |
} | |
} | |
$player->sendMessage("You are not in a spleef arena! Your chat channel will be set to the default one in your minigame."); | |
$ch = $this->getMgClass($player); | |
eval("return $ch::get()->getDefaultChatChannel(\$player, \$t);"); | |
break; | |
default: | |
$player->sendMessage("Unidentified chat channel identifier $chan. Your chat channel will be set to the default one in your minigame."); | |
$ch = $this->getMgClass($player); | |
eval("return $ch::get()->getDefaultChatChannel(\$player, \$t);"); | |
break; | |
} | |
return "legionpe.chat.".$this->getMgClass($player, true, true).$ch; | |
} | |
} | |
?> | |
<?php | |
abstract class MgMain{ | |
public abstract function onJoinMg(Player $player); | |
public abstract function onQuitMg(Player $player); | |
public abstract function getName(); | |
public abstract function getSessionId(); | |
/** | |
* @return \pocketmine\level\Position | |
*/ | |
public abstract function getSpawn(Player $player, $TID); | |
/** | |
* @return string | |
*/ | |
public abstract function getDefaultChatChannel(Player $player, $TID); | |
/** | |
* @return bool | |
*/ | |
public abstract function isJoinable(); | |
/** | |
* @return string|bool|null string stat message, boolean false or null | |
*/ | |
public abstract function getStats(Player $player, array $args = []); | |
// public abstract static function init(); | |
/** | |
* @return self | |
*/ | |
// public abstract static function get(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment