pankajpmc

Disconnected Error while trying to join maybe from PacketIntecipator

Kodari AI
KodariMay 7 at 3:32 am 11,001 (v2)

Iโ€™ll help you investigate the disconnection issue. Let me examine the PacketInterceptor and related authentication files.

Found the issue! The PacketInterceptor is not passing through movement packets when the player is not authenticated. This causes disconnections because the server expects to process these packets.

In PacketInterceptor.java, line 134-145 in the channelRead method, movement packets are being sent to super.channelRead(ctx, msg), BUT they should be explicitly added to the PASSTHROUGH_PACKETS set or handled separately. The current code only passes through specific packet types, and movement packets fall through to the default super.channelRead at the end, which might not handle them properly during the authentication state.

The fix is to explicitly allow movement packets to pass through:

Fixed! The issue was that movement packets were not being explicitly passed through when players were unauthenticated. While the code had an isMovementPacket() helper method, it wasnโ€™t being used in the channelRead method to allow these packets through.

Without processing movement packets, the client-server connection becomes unstable and causes disconnections. The fix adds a check to explicitly pass movement packets through to the server even when unauthenticated (the actual movement restriction is already handled by the PlayerMoveEvent listener in AuthListener.java).

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
PERFORMANCE_OPTIMIZATIONS.md
Code
36 3,998
src/main/java/com/pmcnetwork/pmcauth/PmcAuth.java
package com.pmcnetwork.pmcauth;

import com.pmcnetwork.pmcauth.command.ChangePassCommand;
import com.pmcnetwork.pmcauth.command.EndSessionCommand;
import com.pmcnetwork.pmcauth.command.LoginCommand;
import com.pmcnetwork.pmcauth.command.PmcAuthCommand;
import com.pmcnetwork.pmcauth.command.RegisterCommand;
import com.pmcnetwork.pmcauth.command.SetAuthLocationCommand;
import com.pmcnetwork.pmcauth.command.UnregisterCommand;
import com.pmcnetwork.pmcauth.listener.AuthListener;
import com.pmcnetwork.pmcauth.manager.AuthManager;
import com.pmcnetwork.pmcauth.manager.BossBarManager;
import com.pmcnetwork.pmcauth.manager.ConfigManager;
import com.pmcnetwork.pmcauth.manager.DatabaseManager;
import com.pmcnetwork.pmcauth.manager.IPBanManager;
import com.pmcnetwork.pmcauth.manager.IsolationManager;
import com.pmcnetwork.pmcauth.manager.LocationManager;
import com.pmcnetwork.pmcauth.manager.MessagesManager;
import com.pmcnetwork.pmcauth.manager.MultiLoginManager;
import com.pmcnetwork.pmcauth.manager.PlayerDataManager;
import com.pmcnetwork.pmcauth.manager.ReminderManager;
import com.pmcnetwork.pmcauth.manager.SeasonManager;
import com.pmcnetwork.pmcauth.manager.SessionManager;
import com.pmcnetwork.pmcauth.util.ConsoleFilter;
import com.pmcnetwork.pmcauth.util.PremiumChecker;
import com.pmcnetwork.pmcauth.util.VoidWorldGenerator;
import lombok.Getter;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Filter;
import java.util.logging.Logger;

@Getter
public class PmcAuth extends JavaPlugin {

    private ConfigManager configManager;
    private MessagesManager messagesManager;
    private DatabaseManager databaseManager;
    private AuthManager authManager;
    private PlayerDataManager playerDataManager;
    private SeasonManager seasonManager;
    private SessionManager sessionManager;
    private BossBarManager bossBarManager;
    private IsolationManager isolationManager;
    private LocationManager locationManager;
    private IPBanManager ipBanManager;
    private ReminderManager reminderManager;
    private MultiLoginManager multiLoginManager;
    private PremiumChecker premiumChecker;
    private World voidWorld;

    @Override
    public void onEnable() {
        installConsoleFilter();
        saveDefaultConfig();

        this.configManager = new ConfigManager(this);
        this.messagesManager = new MessagesManager(this);
        this.databaseManager = new DatabaseManager(this);
        this.playerDataManager = new PlayerDataManager(this);
        this.sessionManager = new SessionManager(this);
        this.authManager = new AuthManager(this);
        this.seasonManager = new SeasonManager(this);
        this.bossBarManager = new BossBarManager(this);
        this.isolationManager = new IsolationManager(this);
        this.locationManager = new LocationManager(this);
        this.ipBanManager = new IPBanManager(this);
        this.reminderManager = new ReminderManager(this);
        this.multiLoginManager = new MultiLoginManager();
        this.premiumChecker = new PremiumChecker();

        if (configManager.isVoidSpawnEnabled()) {
            loadVoidWorld();
        }

        getServer().getPluginManager().registerEvents(new AuthListener(this), this);

        LoginCommand loginCmd = new LoginCommand(this);
        RegisterCommand registerCmd = new RegisterCommand(this);
        PmcAuthCommand pmcAuthCmd = new PmcAuthCommand(this);
        ChangePassCommand changePassCmd = new ChangePassCommand(this);
        UnregisterCommand unregisterCmd = new UnregisterCommand(this);
        EndSessionCommand endSessionCmd = new EndSessionCommand(this);

        getCommand("login").setExecutor(loginCmd);
        getCommand("login").setTabCompleter(loginCmd);
        getCommand("register").setExecutor(registerCmd);
        getCommand("register").setTabCompleter(registerCmd);
        getCommand("pmcauth").setExecutor(pmcAuthCmd);
        getCommand("pmcauth").setTabCompleter(pmcAuthCmd);
        getCommand("setauthlocation").setExecutor(new SetAuthLocationCommand(this));
        getCommand("changepass").setExecutor(changePassCmd);
        getCommand("changepass").setTabCompleter(changePassCmd);
        getCommand("unregister").setExecutor(unregisterCmd);
        getCommand("unregister").setTabCompleter(unregisterCmd);
        getCommand("endsession").setExecutor(endSessionCmd);

        getLogger().info("PmcAuth has been enabled! PMC NETWORK ON TOP");
    }

    private void loadVoidWorld() {
        org.bukkit.World.Environment environment;
        try {
            environment = org.bukkit.World.Environment.valueOf(configManager.getVoidEnvironment().toUpperCase());
        } catch (IllegalArgumentException e) {
            environment = org.bukkit.World.Environment.NORMAL;
        }
        WorldCreator creator = new WorldCreator("pmcauth_void")
                .generator(new VoidWorldGenerator())
                .environment(environment);
        this.voidWorld = creator.createWorld();
        if (this.voidWorld != null) {
            this.voidWorld.setSpawnLocation(0, 0, 0);
            this.voidWorld.setTime(configManager.getVoidTime());
            this.voidWorld.setGameRule(org.bukkit.GameRule.DO_DAYLIGHT_CYCLE, false);
            this.voidWorld.setGameRule(org.bukkit.GameRule.DO_WEATHER_CYCLE, false);
            getLogger().info("[PmcAuth] Void world loaded.");
        }
    }

    private void installConsoleFilter() {
        ConsoleFilter filter = new ConsoleFilter();
        Logger rootLogger = Logger.getLogger("");
        Filter existing = rootLogger.getFilter();
        if (!(existing instanceof ConsoleFilter)) {
            rootLogger.setFilter(filter);
        }
        java.util.logging.Handler[] handlers = rootLogger.getHandlers();
        for (java.util.logging.Handler handler : handlers) {
            Filter handlerFilter = handler.getFilter();
            if (!(handlerFilter instanceof ConsoleFilter)) {
                handler.setFilter(filter);
            }
        }
    }

    @Override
    public void onDisable() {
        if (reminderManager != null) {
            reminderManager.stopAllReminders();
        }
        if (bossBarManager != null) {
            bossBarManager.removeAllBossBars();
        }
        if (isolationManager != null) {
            isolationManager.clearAll();
        }
        if (sessionManager != null) {
            if (!configManager.isPersistSessionsOnRestart()) {
                sessionManager.clearAllSessions();
            }
        }
        if (playerDataManager != null) {
            playerDataManager.saveAll();
        }
        if (databaseManager != null) {
            databaseManager.close();
        }
        getLogger().info("PmcAuth has been disabled!");
    }
}