Jump to content

Recommended Posts

Posted
1 minute ago, diesieben07 said:

Im currently using this, but nothing happens

package me.mrfunny.nextlevelauth;

import com.google.gson.Gson;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("nextlevelauth")
public class ExampleMod {
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
            new ResourceLocation("nextlevelauth", "authmain"),
            () -> PROTOCOL_VERSION,
            PROTOCOL_VERSION::equals,
            PROTOCOL_VERSION::equals
    );
    private int id = 0;
    public ExampleMod() {
        MinecraftForge.EVENT_BUS.register(ExampleMod.class);
        try{
            INSTANCE.registerMessage(id, AuthMessage.class, new BiConsumer<AuthMessage, PacketBuffer>() {
                @Override
                public void accept(AuthMessage authMessage, PacketBuffer packetBuffer) {
                    id++;
                    packetBuffer.writeString(authMessage.token);
                }
            }, new Function<PacketBuffer, AuthMessage>() {
                @Override
                public AuthMessage apply(PacketBuffer packetBuffer) {
                    LOGGER.info("logged in1");
                    return new AuthMessage(packetBuffer.readString());
                }
            }, new BiConsumer<AuthMessage, Supplier<NetworkEvent.Context>>() {
                @Override
                public void accept(AuthMessage authMessage, Supplier<NetworkEvent.Context> contextSupplier) {
                    LOGGER.info("logged in2");
                    handle(authMessage, contextSupplier);
                }
            });
        } catch (Exception exception){
            exception.printStackTrace();
        }

    }

    public static void handle(AuthMessage msg, Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {
            ServerPlayerEntity sender = ctx.get().getSender(); // the client that sent this packet
            try{
                URL url = new URL("https://nextlevel.su/api/v1/user/");
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("GET");
                connection.addRequestProperty("User-Agent", "PostmanRuntime/7.26.8");
                connection.addRequestProperty("Authorization", "Bearer " + msg.token);
                connection.addRequestProperty("Content-Type", "application/json");
                connection.addRequestProperty("Accept", "application/json");
                connection.connect();
                int responseCode = connection.getResponseCode();
                if(responseCode != 200){
                    connection.disconnect();
                    sender.disconnect();
                    return;
                }
                ctx.get().setPacketHandled(true);
                connection.disconnect();
            } catch (Exception exception){
                exception.printStackTrace();
                ctx.get().getSender().disconnect();
            }
        });
    }
    @OnlyIn(Dist.CLIENT)
    @SubscribeEvent
    public static void onJoin(PlayerEvent.PlayerLoggedInEvent event){
        try {
            LOGGER.info("connected");
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    public static String readFile(String path, Charset encoding) {
        byte[] encoded = new byte[0];
        try {
            encoded = Files.readAllBytes(Paths.get(path));
        } catch (IOException exception) {
            exception.printStackTrace();
        }
        return new String(encoded, encoding).replace("\n", "").replace("\r", "");
    }
}

My AuthMessage class
 

package me.mrfunny.nextlevelauth;

public class AuthMessage {
    public String token;
    public AuthMessage(String token){
        this.token = token;
    }
}

 

Posted

Because I have modded server and with custom launcher. I have JWT token and on login I need send to server this token and on server i need to validate this token.

Posted
Just now, diesieben07 said:

No, you don't.

Make a whitelist. Tada, problem solved.

I need to install mods and other things in 1 click with site and others features for server. Can you just leave example for send and handle or not?

Posted
Just now, diesieben07 said:

No.

Custom launchers are not supported. Use an installer approach to create a profile in the vanilla launcher.

How about forge hacks and another. For example launcher checks hash, automatical update from server and another things.

Posted
1 minute ago, diesieben07 said:

So you think having a custom launcher will prevent people from installing cheats.

You are naive, my friend.

Not only for that. can you not ask unnecessary questions?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.