public function __construct(HereAuth $main, Player $player, AccountInfo $info) { $this->main = $main; $this->player = $player; $this->accountInfo = $info; if ($info->passwordHash === null) { if (!$main->getConfig()->getNested("ForceRegister.Enabled", true)) { // no registration involved $this->onAuth(); $reminder = $main->getConfig()->getNested("ForceRegister.Reminder", ""); if (strlen($reminder) > 0) { $player->sendMessage($reminder); } return; } $this->startRegistration(); return; } if ($info->opts->autoSecret and $player->getClientSecret() === $info->lastSecret) { $this->onAuth(); return; } if ($info->opts->autoIp and $player->getAddress() === $info->lastIp) { $this->onAuth(); return; } if ($info->opts->autoUuid and $player->getUniqueId()->toBinary() === $info->lastUuid) { $this->onAuth(); return; } $this->state = self::STATE_PENDING_LOGIN; $this->player->sendMessage($main->getConfig()->getNested("Messages.Login.Query", "Please login")); }
public function __construct(HereAuth $main) { $this->main = $main; $this->path = $main->getConfig()->getNested("Database.JSON.DataFolder", "accounts"); if ($this->path[0] !== "/") { $this->path = $main->getDataFolder() . $this->path; } if (!is_dir($this->path)) { mkdir($this->path, 0777, true); } if (!is_dir($this->path)) { throw new \RuntimeException("Could not create data directory at {$this->path}"); } $this->path = realpath($this->path) . "/"; $this->indexEnabled = $main->getConfig()->getNested("Database.JSON.EnableLeadingIndex", false); if (is_file($hadb = $this->path . ".hadb")) { $data = json_decode(file_get_contents($hadb), true); } else { $data = ["#" => "This is a HereAuth JSON-based account database.", "created" => time(), "lastClosed" => time()]; } $data["lastOpened"] = time(); $data["version"] = $this->main->getDescription()->getVersion(); file_put_contents($hadb, json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_SLASHES)); $this->sql = new SQLite3($this->path . "reg.db"); $this->sql->exec("CREATE TABLE IF NOT EXISTS reg (ip TEXT, name TEXT PRIMARY KEY, time INTEGER)"); var_dump($this->sql->busyTimeout(1)); // outputs bool(true) }
public function __construct(HereAuth $main) { $this->main = $main; if ($this->main->getConfig()->getNested("MultiSesCtrl.Enabled", true)) { $this->registerHandler(PlayerPreLoginEvent::class, "onPreLogin", EventPriority::NORMAL, true); } $this->registerHandler(PlayerLoginEvent::class, "onLogin", EventPriority::MONITOR, true); $this->registerHandler(PlayerQuitEvent::class, "onQuit", EventPriority::MONITOR, true); $this->registerHandler(PlayerCommandPreprocessEvent::class, "onMessage", EventPriority::LOWEST, false); $this->registerHandler(PlayerRespawnEvent::class, "onRespawn", EventPriority::HIGHEST, false); $this->registerHandler(DataPacketSendEvent::class, "onSend", EventPriority::HIGH, true); $events = ["DropItem", "Touch", "Pick", "Eat"]; $class = new \ReflectionClass($this); foreach ($events as $event) { if ($main->getConfig()->getNested("Blocking.{$event}", true)) { $method = $class->getMethod("on" . $event); if ($method === null) { throw new \RuntimeException("Missing method on{$event}"); } $this->registerHandler($method->getParameters()[0]->getClass()->getName(), $method->getName(), EventPriority::LOW, true); } } if ($main->getConfig()->getNested("Blocking.Damage", true) or $main->getConfig()->getNested("Blocking.Attack", true)) { $this->registerHandler(EntityDamageEvent::class, "onDamage", EventPriority::LOW, true); } if ($main->getConfig()->getNested("Blocking.Move.Locomotion", true) or $main->getConfig()->getNested("Blocking.Move.Rotation", true)) { $this->registerHandler(PlayerMoveEvent::class, "onMove", EventPriority::LOW, true); } }
public function __construct(HereAuth $main) { parent::__construct($this->main = $main); $period = (int) ($main->getConfig()->getNested("RemindLogin.Interval", 0.5) * 20); $this->type = strtolower($main->getConfig()->getNested("RemindLogin.Type", "popup")); if ($this->type === "none") { return; } $main->getServer()->getScheduler()->scheduleDelayedRepeatingTask($this, $period, $period); }
public function __construct(HereAuth $main) { $this->main = $main; $this->crd = MySQLCredentials::fromConfig($main->getConfig()); $this->mainTable = $main->getConfig()->getNested("Database.MySQL.TablePrefix", "hereauth_") . "accs"; $main->getLogger()->info("Initializing database..."); $db = self::createMysqliInstance($this->crd); $db->query("CREATE TABLE IF NOT EXISTS `{$this->mainTable}` (\n\t\t\tname VARCHAR(63) PRIMARY KEY,\n\t\t\thash BINARY(64),\n\t\t\tregister INT UNSIGNED,\n\t\t\tlogin INT UNSIGNED,\n\t\t\tip VARCHAR(50),\n\t\t\tsecret BINARY(16),\n\t\t\tuuid BINARY(16),\n\t\t\tskin BINARY(64),\n\t\t\topts VARCHAR(1024),\n\t\t\tmultihash VARCHAR(1024)\n\t\t)"); if (isset($db->error) and $db->error) { throw new \RuntimeException($db->error); } $db->close(); }
public static function defaultInstance(HereAuth $main) { $opts = new self(); $opts->autoSecret = $main->getConfig()->getNested("DefaultSettings.AutoAuth.ClientSecretAuth", true); $opts->autoIp = $main->getConfig()->getNested("DefaultSettings.AutoAuth.IPAuth", false); $opts->autoUuid = $main->getConfig()->getNested("DefaultSettings.AutoAuth.UUIDAuth", false); $opts->maskLoc = $main->getConfig()->getNested("DefaultSettings.Masking.Location.Enabled", false); $opts->maskLocPos = $main->getConfig()->getNested("DefaultSettings.Masking.Location.Value", "?spawn?@?current?"); if (!preg_match('#^((\\?spawn\\?)|((\\-)?[0-9]+,(\\-)?[0-9]+,(\\-)?[0-9]+))@[^/\\\\]+$#', $opts->maskLocPos)) { $main->getLogger()->alert("Incorrect syntax for location-masking position (DefaultSettings.Masking.Location.Value)! Assuming as \"?spawn?@?current?\"."); $opts->maskLocPos = "?spawn?@?current?"; } return $opts; }
public function __construct(HereAuth $main, Player $player, AccountInfo $info) { $this->loadTime = microtime(true); $this->main = $main; $this->player = $player; $this->accountInfo = $info; if (!$info->passwordHash) { $main->getDataBase()->passesLimit($player->getAddress(), $main->getConfig()->getNested("Registration.RateLimit.Accounts", 3), $main->getConfig()->getNested("Registration.RateLimit.Days", 30) * 86400, $player->getId()); if (!$main->getConfig()->getNested("ForceRegister.Enabled", true)) { // no registration involved $this->onAuth(); $reminder = $main->getConfig()->getNested("ForceRegister.Reminder", ""); if (strlen($reminder) > 0) { $player->sendMessage($reminder); } return; } $this->startRegistration(); $this->initAppearance(); return; } if (!$this->checkMultiFactor()) { throw new \Exception("MFA failure"); } if ($info->passwordHash[0] !== "{") { if ($info->opts->autoSecret and $player->getClientSecret() === $info->lastSecret and $this->callLogin(HereAuthLoginEvent::METHOD_CLIENT_SECRET)) { $this->main->getAuditLogger()->logLogin(strtolower($player->getName()), $player->getAddress(), "secret"); $this->onAuth(); return; } if ($info->opts->autoIp and $player->getAddress() === $info->lastIp and $this->callLogin(HereAuthLoginEvent::METHOD_IP)) { $this->main->getAuditLogger()->logLogin(strtolower($player->getName()), $player->getAddress(), "ip"); $this->onAuth(); return; } if ($info->opts->autoUuid and $player->getUniqueId()->toBinary() === $info->lastUuid and $this->callLogin(HereAuthLoginEvent::METHOD_UUID)) { $this->main->getAuditLogger()->logLogin(strtolower($player->getName()), $player->getAddress(), "uuid"); $this->onAuth(); return; } } $this->state = self::STATE_PENDING_LOGIN; $this->player->sendMessage($main->getMessages()->getNested("Login.Query", "Please login")); $this->initAppearance(); }
public function __construct(HereAuth $main) { $dir = rtrim($main->getConfig()->getNested("AuditLogger.LogFolder", "audit"), "/") . "/"; if ($dir[0] !== "/" and strpos($dir, "://") === false) { $dir = $main->getDataFolder() . $dir; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } foreach ($entries = ["register", "login", "push", "bump", "invalid", "timeout", "factor"] as $entry) { $value = $main->getConfig()->getNested("AuditLogger.Log." . ucfirst($entry), ($isWin = Utils::getOS() === "win") ? "/NUL" : "/dev/null"); if ($value === "/NUL" and !$isWin or $value === "/dev/null" and $isWin) { $main->getLogger()->warning("Your OS is " . ($isWin ? "Windows" : "not Windows") . ", where {$value} is not a special file! HereAuth will attempt to create that file!"); } if ($value[0] !== "/") { $value = $dir . $value; } $this->{$entry} = $stream = $this->getStream($value); // fwrite($stream, date(self::DATE_FORMAT) . " Start logging $entry\n"); } }
public function __construct(HereAuth $main) { $this->main = $main; $this->registerHandler(PlayerLoginEvent::class, "onLogin", EventPriority::MONITOR, true); $this->registerHandler(PlayerQuitEvent::class, "onQuit", EventPriority::MONITOR, true); $this->registerHandler(PlayerCommandPreprocessEvent::class, "onMessage", EventPriority::LOWEST, false); $events = ["DropItem", "Touch", "Pick", "Eat"]; $class = new \ReflectionClass($this); foreach ($events as $event) { if ($main->getConfig()->getNested("Blocking.{$event}", true)) { $method = $class->getMethod("on" . $event); if ($method === null) { throw new \RuntimeException("Missing method on{$event}"); } $this->registerHandler($method->getParameters()[0]->getClass()->getName(), $method->getName(), EventPriority::LOW, true); } } }