DirectAuth 是一款面向运行在离线模式下的 Minecraft 服务器的服务端登录系统。每位玩家在开始游戏前都必须使用密码执行 /register(注册)和 /login(登录),从而防止他人冒用身份加入并接管角色。拥有正版 Minecraft 账号的玩家只需通过 /online 验证一次,此后即可自动登录。
本模组支持 NeoForge 1.21.1、Forge 1.20.1 以及 Fabric 1.21.1(需 Fabric API)。客户端无需安装任何内容。
为什么使用它
离线模式的服务器不会校验连接者的身份:任何人都可以使用任意用户名加入,包括管理员的。DirectAuth 通过为每位玩家设置独立密码来填补这一安全漏洞,且无需外部数据库或复杂配置,同时不会降低服务器性能。
功能特性
- 仅服务端:只需安装在服务器上,无需其他操作。它不注册任何网络通道,因此兼容任何客户端,并可添加至任何整合包中。
- 零配置:使用内置的 SQLite 数据库。无需 MySQL 或外部服务器。
- 无延迟:数据库访问和密码哈希计算均在服务器线程之外进行。
- 安全的密码存储:采用 PBKDF2WithHmacSHA256(100,000 次迭代)并为每位玩家生成唯一盐值。
- 账号持有者自动登录:
/online 会向 Mojang 服务器验证玩家的 Minecraft 账号。验证通过后,该玩家将跳过密码输入环节,保留其物品栏、进度及所有模组数据,并使用真实皮肤。
- 与其他模组安全共存:无论客户端向其他模组发送何种数据,都会等待玩家登录后才执行,因此冒用他人名称的玩家无法释放他人的宝可梦或选择他人的起源。其他模组在首次加入时打开的界面(如起源、命运、初始套件等)将在
/login 之后显示,而不会遮挡聊天窗口。
- 会话宽限期:在可配置的时间间隔内从同一 IP 重新连接,将保持登录状态。
- 防暴力破解与机器人保护:限制登录尝试次数并实施锁定,设置注册延迟,并限制每个 IP 的最大账号数量。
- 登录前的严格限制:未认证玩家无法移动、聊天、使用除登录指令外的命令、与方块或实体交互、丢弃/移动/拾取物品、攻击、获得经验值或恢复生命值。来自其他模组的自动化行为(如部署器产生的假人)不受影响。
- 多语言支持:包含英文和西班牙文;所有消息均可编辑。
指令
玩家
| 指令 |
描述 |
/register <password> |
创建你的账号。首次加入时必需。 |
/login <password> |
登录。 |
/logout |
登出并断开连接。 |
/changepassword <old> <new> |
更改密码并登出其他会话。 |
/unregister <password> |
删除你的账号。 |
/online <password> |
验证你的 Minecraft 账号以启用自动登录。你的数据保持不变。 |
/directauth confirm |
当模组请求确认时,确认待处理的操作。 |
管理员(OP 等级 4)
| 指令 |
描述 |
/directauth online <player> <true|false> |
开启或关闭某位玩家的自动登录功能。不会踢出任何人。 |
/directauth resetpass <player> <password> |
重置密码,结束该玩家的所有会话并解除任何锁定。 |
/directauth unregister <player> |
删除玩家的账号。 |
/directauth reload |
重新加载配置文件和语言文件,无需重启服务器。 |
/directauth resetlang |
根据默认值重新生成语言文件。 |
管理员指令同样适用于服务器控制台和 RCON。
在线模式
/online 仅改变玩家的登录方式:通过 Mojang 自动登录,而非使用密码。他们的账号保留原有的 UUID,因此其物品栏、统计数据、成就以及所有模组的数据(任务、团队、初始套件等)都保持原样,磁盘上也不会移动任何文件。
在 1.3.0 及更早版本中,/online 会将玩家的数据迁移至其 Mojang UUID,许多模组会从内存中覆盖这些数据。这些账号将继续使用其 Mojang UUID 进行游戏。如果玩家因此丢失了物品或进度,这些数据可能仍然存在于磁盘上,对应于其离线 UUID(即世界的 playerdata 文件夹及各模组的数据目录)。
与其他模组的兼容性
在玩家登录之前,DirectAuth 将其与其他模组隔离:
- 其客户端发送给其他模组的数据会被挂起,并在登录后执行;如果在此期间断开连接,则永远不会执行。
- 仅限 OP 的原版数据包(命令方块、结构方块、NBT 查询等)将被忽略,即使是以 OP 的身份也不行。
- 聊天信息会在到达时被丢弃,因此没有模组能读取到它。
- 其他模组在首次加入时打开的界面将在
/register 或 /login 之后显示。内置支持的有:Origins、MCA Reborn (Destiny)、Pixelmon、Dragon Survival (NeoForge) 和 Starter Kit。服务器打开的菜单(例如 NeoForge 和 Fabric 上的 Tensura 种族选择)也会等待。
- 其他模组的首次加入传送会被保留。
如果其他模组的首次加入界面遮挡了聊天窗口,请将 logJailPayloads 设置为 true,运行 /directauth reload 并使用新账号加入:服务器日志将列出该玩家接收到的数据包。将正确的那个添加到 deferredScreenPayloads 中,并将 logJailPayloads 改回 false。
每次发布前均使用真实客户端进行测试:Origins、MCA Reborn、Pixelmon、Tensura: Reincarnated (NeoForge 和 Fabric)、Dragon Survival (NeoForge)、Cobblemon、Vampirism、Werewolves、Epic Fight、Simple Voice Chat、The Aether、Skyblock Builder、Welcome Screen、Starter Kit 和 Female Gender。
安装
- 下载适用于你加载器的版本。
- 将其放入服务器的
mods 文件夹。
- 重启服务器。
首次启动时,会在 world/serverconfig/ 目录下创建以下文件:
DirectAuth-config.json:配置文件。
DirectAuth-lang-en.json 和 DirectAuth-lang-es.json:消息文件。
directauth.db:账号数据库。
配置
DirectAuth-config.json 允许你修改:
language:"en" 或 "es"。
- 密码与尝试次数:
minPasswordLength、maxPasswordLength、maxLoginAttempts、loginCooldownMs、loginLockoutSeconds。
loginTimeout:玩家在被踢出前必须完成登录的秒数。
- 会话:
sessionGracePeriod、sessionCleanupInterval。
- 机器人防护:
registrationDelay、maxAccountsPerIP。
- 其他模组:
deferredScreenPayloads(登录后显示的界面)、heldPayloadExceptions(玩家在登录前客户端可发送的数据包)以及 logJailPayloads(参见上文)。
使用 /directauth reload 应用更改。如果文件包含无效的 JSON,模组将保留之前的设置,并且不会覆盖你的文件。
升级指南
当新版本更改数据库时,DirectAuth 会首先将其保存为 directauth-backup-<date>.db 作为备份。密码以旧版本可读取的格式存储,因此回退到 1.1 或 1.2 版本只需替换 jar 文件即可。唯一例外的是:在较旧版本中,启用了在线模式且使用 1.3.1 或更高版本的玩家加入时会显示其 Mojang UUID 且物品栏为空,直到你再次升级(他们的数据在其离线 UUID 下保持安全;不要在旧版本中更改其在线模式设置)。
兼容性
- 加载器:NeoForge 1.21.1、Forge 1.20.1、Fabric 1.21.1(需要 Fabric API)。
- 支持:专用服务器,以及 NeoForge 和 Forge 上的局域网世界(Fabric 版本仅限服务器端)。
- 不支持:跨多个服务器共享玩家数据的 BungeeCord/Velocity 网络,因为账户数据是存储在各自的世界中的。
支持本项目
DirectAuth 是免费且开源的。如果你觉得它有用,可以在 GitHub 上赞助我。
源代码与问题反馈
GitHub 仓库 · 报告问题
采用 MIT 许可证授权。
DirectAuth is a server-side login system for Minecraft servers running in offline mode. Every player has to /register and /login with a password before they can play, so nobody can join under someone else's name and take over their character. Players who own a Minecraft account can verify it once with /online and get logged in automatically from then on.
It is available for NeoForge 1.21.1, Forge 1.20.1 and Fabric 1.21.1 (with Fabric API). Clients don't need to install anything.
Why use it
A server in offline mode doesn't check who is connecting: anyone can join with any username, including an admin's. DirectAuth closes that gap with per-player passwords, without an external database or any setup, and without slowing the server down.
Features
- Server-side only: install it on the server and nothing else. It registers no network channels, so it works with any client and can be added to any modpack.
- No setup: uses an embedded SQLite database. No MySQL or external server.
- No lag: database access and password hashing run off the server thread.
- Secure passwords: PBKDF2WithHmacSHA256 (100,000 iterations) with a unique salt per player.
- Automatic login for account owners:
/online verifies the player's Minecraft account against Mojang's servers. From then on that player skips the password, keeps their inventory, progress and every mod's data, and gets their real skin.
- Safe with other mods: whatever a player's client sends to other mods waits until they log in, so someone using another player's name can't release their Pokémon or pick their origin. Screens other mods open at first join (origin, Destiny, starter...) show up after
/login instead of covering the chat.
- Session grace period: reconnecting from the same IP within a configurable time keeps you logged in.
- Brute-force and bot protection: limited login attempts with a lockout, a registration delay and a maximum number of accounts per IP.
- Strict restrictions until login: unauthenticated players cannot move, chat, use commands other than the login ones, interact with blocks or entities, drop, move or pick up items, attack, gain XP or regenerate health. Automation from other mods (fake players such as deployers) is never affected.
- Languages: English and Spanish included; every message can be edited.
Commands
Players
| Command |
Description |
/register <password> |
Creates your account. Required on your first join. |
/login <password> |
Logs you in. |
/logout |
Logs you out and disconnects you. |
/changepassword <old> <new> |
Changes your password and logs out your other sessions. |
/unregister <password> |
Deletes your account. |
/online <password> |
Verifies your Minecraft account to enable automatic login. Your data stays as it is. |
/directauth confirm |
Confirms a pending action when the mod asks for it. |
Admins (OP level 4)
| Command |
Description |
/directauth online <player> <true|false> |
Turns automatic login on or off for a player. Nobody is kicked. |
/directauth resetpass <player> <password> |
Resets a password, ends the player's sessions and lifts any lockout. |
/directauth unregister <player> |
Deletes a player's account. |
/directauth reload |
Reloads the config and language files without restarting. |
/directauth resetlang |
Regenerates the language files from the defaults. |
Admin commands also work from the server console and over RCON.
Online Mode
/online only changes how a player logs in: automatically, through Mojang, instead of with a password. Their account keeps the UUID it already had, so their inventory, statistics, advancements and every mod's data (quests, teams, starter kits...) stay exactly as they were, and nothing on disk is moved.
Up to 1.3.0, /online moved the player's data to their Mojang UUID, and many mods overwrote it from memory. Those accounts keep playing with their Mojang UUID. If a player lost items or progress that way, it may still be on disk under their offline UUID (the world's playerdata folder and each mod's data).
Compatibility with other mods
Until a player logs in, DirectAuth keeps them away from other mods:
- What their client sends to other mods waits and runs once they log in; if they disconnect first, it never runs.
- Op-only vanilla packets (command blocks, structure blocks, NBT queries...) are ignored, even for an op's name.
- Chat is dropped as it arrives, so no mod reads it either.
- Screens other mods open at first join are shown after
/register or /login. Built in: Origins, MCA Reborn (Destiny), Pixelmon, Dragon Survival (NeoForge) and Starter Kit. Menus the server opens (such as Tensura's race selection on NeoForge and Fabric) also wait.
- First-join teleports of other mods are kept.
If another mod's first-join screen hides the chat, set logJailPayloads to true, run /directauth reload and join with a new account: the server log lists the packets that player received. Add the right one to deferredScreenPayloads and set logJailPayloads back to false.
Tested with a real client before each release: Origins, MCA Reborn, Pixelmon, Tensura: Reincarnated (NeoForge and Fabric), Dragon Survival (NeoForge), Cobblemon, Vampirism, Werewolves, Epic Fight, Simple Voice Chat, The Aether, Skyblock Builder, Welcome Screen, Starter Kit and Female Gender.
Installation
- Download the version for your loader.
- Put it in the server's
mods folder.
- Restart the server.
The first start creates, in world/serverconfig/:
DirectAuth-config.json: configuration.
DirectAuth-lang-en.json and DirectAuth-lang-es.json: messages.
directauth.db: the account database.
Configuration
DirectAuth-config.json lets you change:
language: "en" or "es".
- Passwords and attempts:
minPasswordLength, maxPasswordLength, maxLoginAttempts, loginCooldownMs, loginLockoutSeconds.
loginTimeout: seconds a player has to log in before being kicked.
- Sessions:
sessionGracePeriod, sessionCleanupInterval.
- Bots:
registrationDelay, maxAccountsPerIP.
- Other mods:
deferredScreenPayloads (screens shown after login), heldPayloadExceptions (packets a player's client may send before login) and logJailPayloads (see above).
Apply changes with /directauth reload. If the file has invalid JSON, the mod keeps the previous settings and doesn't overwrite your file.
Upgrading
When a new version changes the database, DirectAuth first saves a copy as directauth-backup-<date>.db. Passwords are stored in a format older versions can read, so going back to 1.1 or 1.2 only takes swapping the jar. One exception: on older versions, players who enabled Online Mode with 1.3.1 or newer join with their Mojang UUID and an empty inventory until you upgrade again (their data stays safe under their offline UUID; don't change their Online Mode on the older version).
Compatibility
- Loaders: NeoForge 1.21.1, Forge 1.20.1, Fabric 1.21.1 (requires Fabric API).
- Supported: dedicated servers, and LAN worlds on NeoForge and Forge (the Fabric version is server-only).
- Not supported: BungeeCord/Velocity networks that share player data across several servers, because accounts are stored in each world.
Support the project
DirectAuth is free and open source. If you find it useful, you can sponsor me on GitHub.
Source code and issues
GitHub repository · Report an issue
Licensed under the MIT License.
评论 0
登录后参与评分
还没有评论,来抢沙发吧