tarihci2

Geliştirilecek bir Minecraft eklentisi ile oyuncuların hesaplarını Google Authenticator destekli 2FA (iki faktörlü kimlik doğrulama) ile koruma altına alın. Eklenti, minimum 1.21.4 sürümüne uyumlu olacak şekilde tasarlanmalı ve oyuncuların güvenlik ayarlarını yapılandırmalarını sağlamak için basit bir komut sistemi ve INVENTORY GUI arayüzü içermelidir. Ayrıca, kullanıcıların doğrulama kodlarını girmeleri için Discord entegrasyonu ile bildirim sistemini de eklemeyi unutmayın.

Kodari AI
KodariJul 11 at 8:59 pm 56

I’ll build a Fabric 2FA security mod with TOTP (Google Authenticator compatible) verification, commands, an inventory GUI, and Discord webhook notifications.

TwoFactorAuthMod
A Fabric 1.21.4 server-side mod adding Google Authenticator-compatible TOTP two-factor authentication for players. Includes a command system (/2fa setup, enable, disable, verify, discord, status, gui), an inventory GUI for managing security settings, login freeze/lockout for unverified players, and Discord webhook notifications alerting players of new login attempts requiring verification.
TwoFactorGuard
Fabric 1.21.4 sunucu eklentisi: oyuncu hesaplarını Google Authenticator uyumlu TOTP tabanlı iki faktörlü kimlik doğrulama (2FA) ile korur. /2fa setup, enable, disable, verify, discord ve gui komutlarıyla yönetilir; giriş sonrası doğrulanmamış oyuncular hareket/etkileşimden kısıtlanır (freeze). Envanter tabanlı GUI üzerinden durum görüntüleme, gizli anahtar yenileme ve Discord webhook testi yapılabilir. Yeni girişlerde Discord webhook üzerinden güvenlik bildirimi gönderilir. Veriler JSON olarak sunucu config klasöründe saklanır.

Proje kuruldu — TwoFactorGuard modu:

  • TOTP/Google Authenticator: Base32 + TotpUtil sınıfları secret üretimi, kod doğrulama (zaman toleransı ile) ve otpauth:// kurulum linki üretimi yapıyor.

  • Komutlar: /2fa setup, enable <kod>, disable <kod>, verify <kod>, discord <webhook>, status, gui.

  • Giriş koruması: PendingVerificationManager girişte 2FA aktif oyuncuları dondurur (pozisyona geri teleport), blok kırma/yerleştirme/etkileşim event’lerini iptal eder, zaman aşımında atar.

  • Inventory GUI: TwoFactorScreenHandler (GenericContainerScreenHandler tabanlı) + TwoFactorGuiBuilder — durum göstergesi, secret yenileme ve Discord test butonu.

  • Discord entegrasyonu: DiscordWebhook yeni giriş güvenlik uyarılarını ve test mesajlarını webhook’a POST eder.

  • Veriler config/twofactorguard/playerdata.json, ayarlar config/twofactorguard.json içinde saklanıyor.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
19 819
src/main/java/com/example/twofactorauth/TwoFactorAuthMod.java
package com.example.twofactorauth;

import com.example.twofactorauth.command.TwoFactorCommands;
import com.example.twofactorauth.config.ConfigManager;
import com.example.twofactorauth.data.AuthDataManager;
import com.example.twofactorauth.data.PlayerAuthData;
import com.example.twofactorauth.discord.DiscordWebhook;
import com.example.twofactorauth.gui.ModScreenHandlers;
import com.example.twofactorauth.verification.PendingVerificationManager;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TwoFactorAuthMod implements ModInitializer {
    public static final String MOD_ID = "twofactorguard";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    @Override
    public void onInitialize() {
        ModScreenHandlers.register();

        ServerLifecycleEvents.SERVER_STARTED.register(server -> {
            ConfigManager.load();
            AuthDataManager.load();
        });
        ServerLifecycleEvents.SERVER_STOPPING.register(server -> AuthDataManager.save());

        ServerTickEvents.END_SERVER_TICK.register(PendingVerificationManager::tick);

        ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
            ServerPlayerEntity player = handler.getPlayer();
            PlayerAuthData data = AuthDataManager.get(player.getUuid());
            if (data != null && data.enabled && data.secret != null) {
                PendingVerificationManager.markPending(player);
                player.sendMessage(Text.literal("§c§lGiris icin 2FA dogrulamasi gerekli!"), false);
                player.sendMessage(Text.literal("§7Google Authenticator uygulamanizdaki kodu §f/2fa verify <kod>§7 ile girin."), false);
                String webhook = data.discordWebhookUrl != null && !data.discordWebhookUrl.isBlank()
                        ? data.discordWebhookUrl
                        : ConfigManager.getConfig().globalDiscordWebhookUrl;
                DiscordWebhook.send(webhook, "Guvenlik uyarisi: " + player.getGameProfile().getName()
                        + " sunucuya giris yapti ve 2FA dogrulamasi bekliyor.");
            }
        });

        PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) ->
                !PendingVerificationManager.isPending(player.getUuid()));

        AttackBlockCallback.EVENT.register((player, world, hand, pos, direction) ->
                PendingVerificationManager.isPending(player.getUuid()) ? ActionResult.FAIL : ActionResult.PASS);

        UseBlockCallback.EVENT.register((player, world, hand, hitResult) ->
                PendingVerificationManager.isPending(player.getUuid()) ? ActionResult.FAIL : ActionResult.PASS);

        UseItemCallback.EVENT.register((player, world, hand) ->
                PendingVerificationManager.isPending(player.getUuid()) ? ActionResult.FAIL : ActionResult.PASS);

        UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) ->
                PendingVerificationManager.isPending(player.getUuid()) ? ActionResult.FAIL : ActionResult.PASS);

        AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) ->
                PendingVerificationManager.isPending(player.getUuid()) ? ActionResult.FAIL : ActionResult.PASS);

        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
                TwoFactorCommands.register(dispatcher));
    }
}