Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure chat state error #876

Open
Gight16 opened this issue Jan 13, 2025 · 0 comments
Open

Secure chat state error #876

Gight16 opened this issue Jan 13, 2025 · 0 comments

Comments

@Gight16
Copy link

Gight16 commented Jan 13, 2025

Hello i created a bot and tried to send message in an premium server and it didnt send. When i tried on localhost i get this error:

[21:41:46 WARN]: Failed to update secure chat state for fentmaxxer1221: 'Chat disabled due to missing profile public key. Please try reconnecting.'

I thought the error was because of something I did wrong and when I tried the example codes I encountered the same thing. My code:

package me.deaglewolf.tools;

import net.kyori.adventure.text.Component;
import net.lenni0451.commons.httpclient.HttpClient;
import net.raphimc.minecraftauth.MinecraftAuth;
import net.raphimc.minecraftauth.step.java.StepMCProfile;
import net.raphimc.minecraftauth.step.java.StepMCToken;
import net.raphimc.minecraftauth.step.java.session.StepFullJavaSession;
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
import org.geysermc.mcprotocollib.auth.GameProfile;
import org.geysermc.mcprotocollib.auth.SessionService;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.network.tcp.TcpClientSession;
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;

import java.time.Instant;
import java.util.BitSet;

public class PlayGround {
    private static int i = 0;
    public static Thread thread = new Thread(() -> {
        while (true) {
            try {
                i++;
                System.out.println("adasda" + i);
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    public static void main(String[] args) throws Exception {
        MinecraftProtocol protocol;

        HttpClient httpClient = MinecraftAuth.createHttpClient();

        StepFullJavaSession.FullJavaSession javaSession = MinecraftAuth.JAVA_DEVICE_CODE_LOGIN.getFromInput(httpClient, new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
            // Method to generate a verification URL and a code for the user to enter on that page
            System.out.println("Go to " + msaDeviceCode.getVerificationUri());
            System.out.println("Enter code " + msaDeviceCode.getUserCode());

            // There is also a method to generate a direct URL without needing the user to enter a code
            System.out.println("Go to " + msaDeviceCode.getDirectVerificationUri());
        }));

        System.out.println("Username: " + javaSession.getMcProfile().getName());
        System.out.println("Access token: " + javaSession.getMcProfile().getMcToken().getAccessToken());
        System.out.println("Player certificates: " + javaSession.getPlayerCertificates());


        StepMCProfile.MCProfile mcProfile = javaSession.getMcProfile();
        StepMCToken.MCToken mcToken = mcProfile.getMcToken();

        GameProfile gameProfile = new GameProfile(mcProfile.getId(), mcProfile.getName());
        protocol = new MinecraftProtocol(
                gameProfile,
                mcToken.getAccessToken());

        SessionService sessionService = new SessionService();

        Session client = new TcpClientSession("127.0.0.1", 25565, protocol);
        client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
        client.setFlag(MinecraftConstants.ENCRYPT_CONNECTION, false);

        client.addListener(new SessionAdapter() {
            @Override
            public void packetReceived(Session session, Packet packet) {
                if (packet instanceof ClientboundLoginPacket) {
                    session.send(new ServerboundChatPacket("Hello, this is a test of MCProtocolLib.", Instant.now().toEpochMilli(), 0L, null, 0, new BitSet()));
                } else if (packet instanceof ClientboundSystemChatPacket systemChatPacket) {

                    session.disconnect(Component.text("Finished"));
                }
            }
        });

        thread.start();

        client.connect();

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant