コード例 #1
0
ファイル: EventListener.php プロジェクト: ecoron/SimpleAuth
 /**
  * @param PlayerPreLoginEvent $event
  *
  * @priority HIGHEST
  */
 public function onPlayerPreLogin(PlayerPreLoginEvent $event)
 {
     if ($this->plugin->getConfig()->get("forceSingleSession") !== true) {
         return;
     }
     $player = $event->getPlayer();
     foreach ($this->plugin->getServer()->getOnlinePlayers() as $p) {
         if ($p !== $player and strtolower($player->getName()) === strtolower($p->getName())) {
             if ($this->plugin->isPlayerAuthenticated($p)) {
                 $event->setCancelled(true);
                 $player->kick("already logged in");
                 return;
             }
             //if other non logged in players are there leave it to the default behaviour
         }
     }
 }
コード例 #2
0
 public function __construct(SimpleAuth $plugin)
 {
     $this->plugin = $plugin;
     $config = $this->plugin->getConfig()->get("dataProviderSettings");
     if (!isset($config["host"]) or !isset($config["user"]) or !isset($config["password"]) or !isset($config["database"])) {
         $this->plugin->getLogger()->critical("Invalid MySQL settings");
         $this->plugin->setDataProvider(new DummyDataProvider($this->plugin));
         return;
     }
     $this->database = new \mysqli($config["host"], $config["user"], $config["password"], $config["database"], isset($config["port"]) ? $config["port"] : 3306);
     if ($this->database->connect_error) {
         $this->plugin->getLogger()->critical("Couldn't connect to MySQL: " . $this->database->connect_error);
         $this->plugin->setDataProvider(new DummyDataProvider($this->plugin));
         return;
     }
     $resource = $this->plugin->getResource("mysql.sql");
     $this->database->query(stream_get_contents($resource));
     fclose($resource);
     $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask(new MySQLPingTask($this->plugin, $this->database), 600);
     //Each 30 seconds
     $this->plugin->getLogger()->info("Connected to MySQL server");
 }