forked from afspiegeling/NitoriBot
Night of Nights build: 5313
This commit is contained in:
@@ -15,3 +15,6 @@ src/main/kotlin
|
||||
|
||||
# proxies
|
||||
proxies.txt
|
||||
|
||||
# fuck you make your own class
|
||||
src/main/java/land/chipmunk/parker2991/nitoribot/nightofnights/NitoriBot.java
|
||||
|
||||
+11
-3
@@ -28,19 +28,24 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation("org.geysermc.mcprotocollib:protocol:26.3-SNAPSHOT")
|
||||
implementation("ch.qos.logback:logback-classic:1.6.6")
|
||||
implementation("org.slf4j:slf4j-api:2.0.20")
|
||||
implementation("org.tinylog:slf4j-tinylog:2.8.1")
|
||||
implementation("org.tinylog:tinylog-impl:2.8.1")
|
||||
implementation("org.yaml:snakeyaml:2.7")
|
||||
implementation("net.kyori:adventure-text-serializer-ansi:5.2.0")
|
||||
implementation("net.kyori:adventure-text-serializer-plain:5.2.0")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:5.2.0")
|
||||
implementation("net.kyori:adventure-text-serializer-gson:5.2.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:5.2.0")
|
||||
implementation("net.dv8tion:JDA:6.7.0")
|
||||
implementation("org.jline:jline:4.4.7")
|
||||
implementation("com.github.oshi:oshi-core:7.7.1")
|
||||
implementation("net.kyori:adventure-nbt:5.2.0")
|
||||
implementation("org.bouncycastle:bcprov-jdk18on:1.84")
|
||||
implementation("net.jodah:expiringmap:0.5.11")
|
||||
implementation("org.apache.commons:commons-compress:1.28.0")
|
||||
implementation("io.github.wasabithumb:jtoml-configurate:1.5.1")
|
||||
implementation("com.github.luben:zstd-jni:1.5.6-9")
|
||||
implementation("land.chipmunk.code.kaboomstandardsorganization.messaginglib:mcprotocollib:3.1.2")
|
||||
implementation("com.google.guava:guava:33.6.0-jre")
|
||||
}
|
||||
|
||||
tasks.jar {
|
||||
@@ -65,6 +70,9 @@ tasks.jar {
|
||||
|
||||
from(
|
||||
{
|
||||
exclude("META-INF/*.SF")
|
||||
exclude("META-INF/*.RSA")
|
||||
exclude("META-INF/*.DSA")
|
||||
configurations.runtimeClasspath.get().filter {
|
||||
it.name.endsWith("jar")
|
||||
}.map {
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetProxiesList;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.ListenerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectingEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.PacketErrorEvent;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundPlayerLoadedPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.login.clientbound.ClientboundLoginFinishedPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class Bot extends SessionAdapter {
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
public final ConcurrentMap<String, Future<?>> services = Main.services;
|
||||
public final BotBuildInfo botBuildInfo = Main.botBuildInfo;
|
||||
public final RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
|
||||
public final @NotNull Config config;
|
||||
public final Config.Options options;
|
||||
public final List<Bot> bots;
|
||||
public final ChatModule chat;
|
||||
public final PositionModule position;
|
||||
public final CommandCoreModule core;
|
||||
public final PlayerListModule players;
|
||||
public final RegistryModule registry;
|
||||
public boolean loggedIn = false;
|
||||
public int entityId;
|
||||
public ClientNetworkSession session;
|
||||
public GameProfile profile;
|
||||
public CommandManagerModule commandManager;
|
||||
public MCServerModule mcServer;
|
||||
public WorldModule world;
|
||||
public TabCompleteModule tabComplete;
|
||||
public List<?> modules;
|
||||
|
||||
public Bot (Config.Options options, List<Bot> bots, @NotNull Config config) throws Exception {
|
||||
this.options = options;
|
||||
this.bots = bots;
|
||||
this.config = config;
|
||||
|
||||
this.modules = List.of(
|
||||
this.chat = new ChatModule(this),
|
||||
new SelfcareModule(this),
|
||||
this.position = new PositionModule(this),
|
||||
this.core = new CommandCoreModule(this),
|
||||
this.registry = new RegistryModule(this),
|
||||
this.players = new PlayerListModule(this),
|
||||
new LoggingModule(this),
|
||||
new ChatCommandHandlerModule(this),
|
||||
this.commandManager = new CommandManagerModule(this),
|
||||
new TextDisplayModule(this),
|
||||
this.mcServer = new MCServerModule(this),
|
||||
new CommandSpyModule(this),
|
||||
this.world = new WorldModule(this),
|
||||
this.tabComplete = new TabCompleteModule(this)
|
||||
);
|
||||
|
||||
try {
|
||||
connect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy) session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
).setProxy(new GetProxiesList().randomProxyIp()).setProtocol(protocol).create();
|
||||
|
||||
else session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
).setProtocol(protocol).create();
|
||||
session.addListener(this);
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnecting (DisconnectingEvent event) {
|
||||
Component component = event.getReason();
|
||||
session.disconnect(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetSent (@NonNull Session session, @NonNull Packet packet) {
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetSent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetError (PacketErrorEvent error) {
|
||||
error.setSuppress(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void packetReceived (@NonNull Session session, @NonNull Packet packet) {
|
||||
try {
|
||||
if (packet instanceof ClientboundLoginPacket) this.session.send(ServerboundPlayerLoadedPacket.INSTANCE);
|
||||
|
||||
if (packet instanceof ServerboundPlayerLoadedPacket) {
|
||||
System.out.println(packet);
|
||||
}
|
||||
|
||||
for (Listener listener : listenerManager.listeners) {
|
||||
listener.packetReceived(packet);
|
||||
}
|
||||
|
||||
if (packet instanceof ClientboundLoginFinishedPacket) getProfile((ClientboundLoginFinishedPacket) packet);
|
||||
else if (packet instanceof ClientboundLoginPacket) getEntityId((ClientboundLoginPacket) packet);
|
||||
} catch (Exception _) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void getProfile (ClientboundLoginFinishedPacket packet) {
|
||||
profile = packet.getProfile();
|
||||
|
||||
loggedIn = true;
|
||||
}
|
||||
|
||||
public void getEntityId (ClientboundLoginPacket packet) {
|
||||
entityId = packet.getEntityId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (DisconnectedEvent event) {
|
||||
loggedIn = false;
|
||||
Component component = event.getReason();
|
||||
String reason = ComponentUtil.componentToAnsi(component);
|
||||
|
||||
Logger.RECONNECT(this, reason);
|
||||
|
||||
if (services.get("reconnect") != null) services.get("reconnect").cancel(true);
|
||||
|
||||
services.put(
|
||||
"reconnect", executor.schedule(
|
||||
() -> {
|
||||
try {
|
||||
connect();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, options.reconnectDelay, TimeUnit.MILLISECONDS
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,10 @@ import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetRepoInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.LoadConfig;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.ConsoleModule;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.console.CreateConsole;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.slf4j.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -19,11 +20,12 @@ public class Main {
|
||||
|
||||
public static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
public static final ConcurrentMap<String, Future<?>> services = new ConcurrentHashMap<>();
|
||||
public static final List<Bot> Bots = new ArrayList<>();
|
||||
public static final List<NitoriBot> Bots = new ArrayList<>();
|
||||
public static RepoCommitInfo repoCommitInfo = null;
|
||||
public static BotBuildInfo botBuildInfo = null;
|
||||
public static ConsoleModule console;
|
||||
public static CreateConsole console;
|
||||
public Config config;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
void main () {
|
||||
try {
|
||||
@@ -31,11 +33,11 @@ public class Main {
|
||||
System.out.println("Starting NitoriBot " + ComponentUtil.componentToAnsi(GsonComponentSerializer.gson().deserialize(botBuildInfo.buildstring.codename.toString())));
|
||||
config = new LoadConfig().loadConfig();
|
||||
Config.Options[] bots = config.bots;
|
||||
console = new ConsoleModule();
|
||||
console = new CreateConsole();
|
||||
repoCommitInfo = new GetRepoInfo().getRepoInfo();
|
||||
|
||||
for (Config.Options options : bots) {
|
||||
final Bot bot = new Bot(
|
||||
final NitoriBot bot = new Client(
|
||||
options,
|
||||
Bots,
|
||||
config
|
||||
@@ -43,7 +45,7 @@ public class Main {
|
||||
Bots.add(bot);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
LOGGER.error("{}", Main.class, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights;
|
||||
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.Injector;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessagingEntrypoint;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.boot.GetProxiesList;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.ChatAttestation;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.console.logger.LoggerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.BotBuildInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.buildstring.RepoCommitInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.ListenerManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.modules.*;
|
||||
import org.geysermc.mcprotocollib.auth.GameProfile;
|
||||
import org.geysermc.mcprotocollib.network.event.session.SessionAdapter;
|
||||
import org.geysermc.mcprotocollib.network.factory.ClientNetworkSessionFactory;
|
||||
import org.geysermc.mcprotocollib.network.session.ClientNetworkSession;
|
||||
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public class NitoriBot extends SessionAdapter implements MCProtocolLibMessagingEntrypoint {
|
||||
public final LoggerManager logger = new LoggerManager();
|
||||
public final ListenerManager listenerManager = new ListenerManager();
|
||||
public final ScheduledExecutorService executor = Main.executor;
|
||||
public final ExecutorService executorService = Main.executorService;
|
||||
public final ConcurrentMap<String, Future<?>> services = Main.services;
|
||||
public final BotBuildInfo botBuildInfo = Main.botBuildInfo;
|
||||
public final RepoCommitInfo repoCommitInfo = Main.repoCommitInfo;
|
||||
public Config config;
|
||||
public Config.Options options;
|
||||
public List<NitoriBot> bots;
|
||||
public ChatModule chat;
|
||||
public PositionModule position;
|
||||
public CommandCoreModule core;
|
||||
public PlayerListModule players;
|
||||
public RegistryModule registry;
|
||||
public boolean loggedIn = false;
|
||||
public int entityId;
|
||||
public ClientNetworkSession session;
|
||||
public GameProfile profile;
|
||||
public CommandManagerModule commandManager;
|
||||
public MCServerModule mcServer;
|
||||
public WorldModule world;
|
||||
public TabCompleteModule tabComplete;
|
||||
public ExtrasMessagingModule extrasMessaging;
|
||||
public List<?> modules;
|
||||
public final ChatAttestation chatAttestation = new ChatAttestation();
|
||||
|
||||
private void connect () throws IOException {
|
||||
final MinecraftProtocol protocol = new MinecraftProtocol(options.username);
|
||||
|
||||
if (options.useProxy) session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
).setProxy(new GetProxiesList().randomProxyIp()).setProtocol(protocol).create();
|
||||
|
||||
else session = ClientNetworkSessionFactory.factory().setAddress(
|
||||
options.host,
|
||||
options.port
|
||||
).setProtocol(protocol).create();
|
||||
Injector.inject(
|
||||
session,
|
||||
this
|
||||
);
|
||||
chatAttestation.inject(session);
|
||||
session.addListener(this);
|
||||
session.connect(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistrationAvailable (MCProtocolLibMessenger messenger) {
|
||||
// stub
|
||||
}
|
||||
|
||||
public NitoriBot () {
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@ package land.chipmunk.parker2991.nitoribot.nightofnights.boot;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.logger.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
@@ -17,7 +18,7 @@ public class LoadConfig {
|
||||
private final Constructor yamlConfig = new Constructor(Config.class, new LoaderOptions());
|
||||
private final Yaml yaml = new Yaml(yamlConfig);
|
||||
private final String homeDirectory = System.getProperty("user.home");
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoadConfig.class);
|
||||
public Config loadConfig () throws IOException {
|
||||
Path configDirectory;
|
||||
|
||||
@@ -26,7 +27,7 @@ public class LoadConfig {
|
||||
|
||||
final Path configPath = Path.of(String.valueOf(configDirectory), "config.yml");
|
||||
if (!Files.exists(configPath)) {
|
||||
Logger.INFO(null, "config not found, creating config in " + configPath);
|
||||
LOGGER.warn("config not found! creating it now");
|
||||
|
||||
if (!Files.exists(configDirectory)) Files.createDirectory(configDirectory);
|
||||
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.Injector;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.SigningResult;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Util;
|
||||
import org.geysermc.mcprotocollib.network.ClientSession;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager.createHash;
|
||||
|
||||
public class ChatAttestation {
|
||||
private static final UUID NIL_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
|
||||
|
||||
public static SigningResult getSigningStatus (
|
||||
String message,
|
||||
UUID senderUuid,
|
||||
String senderNick
|
||||
) {
|
||||
final byte[] pyl;
|
||||
final var wrapped = new SigningManager.WrappedByteArray(createHash(message.getBytes(StandardCharsets.UTF_8)));
|
||||
final ByteBuf payload;
|
||||
payload = senderUuid == NIL_UUID
|
||||
? MessagingEntrypointImpl.RECENT_PAYLOADS.remove(wrapped)
|
||||
: MessagingEntrypointImpl.ATTRIBUTED_PAYLOADS.getOrDefault(senderUuid, Collections.emptyMap()).remove(wrapped);
|
||||
|
||||
if (payload == null) {
|
||||
pyl = null;
|
||||
} else {
|
||||
try {
|
||||
pyl = new byte[payload.readableBytes()];
|
||||
payload.readBytes(pyl);
|
||||
} finally {
|
||||
if (senderUuid != NIL_UUID) MessagingEntrypointImpl.RECENT_PAYLOADS.remove(wrapped);
|
||||
payload.release();
|
||||
}
|
||||
}
|
||||
return Signing.getSigningStatus(senderNick, message, pyl);
|
||||
|
||||
}
|
||||
|
||||
public MessagingEntrypointImpl inject (ClientSession clientNetworkSession) {
|
||||
MessagingEntrypointImpl messagingEntrypointImpl = new MessagingEntrypointImpl();
|
||||
Injector.inject(clientNetworkSession, messagingEntrypointImpl);
|
||||
return messagingEntrypointImpl;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public record KeyManifest(@SerializedName("key_to_claims") Map<String, Set<String>> keyToClaims) {
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager;
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.*;
|
||||
/*import dev.pthepro777.messaging_lib.MCProtocolLibMessagingEntrypoint;
|
||||
import dev.pthepro777.messaging_lib.MCProtocolLibMessenger;
|
||||
import dev.pthepro777.messaging_lib.MCProtocolLibPayloadReceiver;*/
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class MessagingEntrypointImpl implements MCProtocolLibMessagingEntrypoint, MCProtocolLibPayloadReceiver {
|
||||
public static final String CHANNEL_NAME = "chat-attestation/v1:stream";
|
||||
public final Map<StreamCacheKey, ByteBuf> PAYLOAD_MAP = ExpiringMap.builder()
|
||||
.maxSize(1024)
|
||||
.expiration(1, TimeUnit.MINUTES)
|
||||
.build();
|
||||
public static final Map<SigningManager.WrappedByteArray, ByteBuf> RECENT_PAYLOADS = ExpiringMap.builder()
|
||||
.maxSize(1024)
|
||||
.expiration(1, TimeUnit.MINUTES)
|
||||
.asyncExpirationListener(MessagingEntrypointImpl::onExpire)
|
||||
.build();
|
||||
public static final Map<UUID, Map<SigningManager.WrappedByteArray, ByteBuf>> ATTRIBUTED_PAYLOADS = ExpiringMap.builder()
|
||||
.maxSize(256)
|
||||
.expiration(5, TimeUnit.MINUTES)
|
||||
.expirationPolicy(ExpirationPolicy.ACCESSED)
|
||||
.build();
|
||||
public static volatile MCProtocolLibMessenger MESSENGER_INSTANCE;
|
||||
|
||||
public static void onExpire(SigningManager.WrappedByteArray byteArray, ByteBuf buf) {
|
||||
buf.release();
|
||||
}
|
||||
|
||||
|
||||
private static Map<SigningManager.WrappedByteArray, ByteBuf> getAttributionMap(UUID sender) {
|
||||
return ATTRIBUTED_PAYLOADS.computeIfAbsent(
|
||||
sender,
|
||||
_ -> ExpiringMap.builder()
|
||||
.maxSize(16)
|
||||
.expiration(1, TimeUnit.MINUTES)
|
||||
.asyncExpirationListener(MessagingEntrypointImpl::onExpire)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegistrationAvailable(@NotNull MCProtocolLibMessenger messenger) {
|
||||
MESSENGER_INSTANCE = messenger;
|
||||
|
||||
MESSENGER_INSTANCE.receivePayloads(CHANNEL_NAME, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeregister() {
|
||||
MESSENGER_INSTANCE = null;
|
||||
PAYLOAD_MAP.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivePayload(
|
||||
@NotNull String channelName,
|
||||
@NotNull UUID sender,
|
||||
@NotNull ByteBuf payload
|
||||
) {
|
||||
final byte[] contentHash = new byte[16];
|
||||
payload.readBytes(contentHash);
|
||||
|
||||
final var wrapper = new SigningManager.WrappedByteArray(contentHash);
|
||||
RECENT_PAYLOADS.put(wrapper, payload.copy());
|
||||
getAttributionMap(sender).put(wrapper, payload.copy());
|
||||
}
|
||||
|
||||
// TODO: This won't work very well with vanished players.
|
||||
public record StreamCacheKey(SigningManager.WrappedByteArray contentHash, UUID sender) {
|
||||
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.Payload.withAdditionalData;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.LOGGER;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.Payload;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums.SigningStatus;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.SigningResult;
|
||||
|
||||
|
||||
public class Signing {
|
||||
public static SigningResult getSigningStatus(String nick, String msg, byte[] pyl) {
|
||||
if (pyl == null) {
|
||||
return SigningResult.of(SigningManager.INSTANCE.doesNickRequireSignature(nick)
|
||||
? SigningStatus.NEEDS_SIGNATURE
|
||||
: SigningStatus.NO_PAYLOAD);
|
||||
}
|
||||
|
||||
final Payload decodedPayload;
|
||||
try {
|
||||
decodedPayload = Payload.read(
|
||||
msg.getBytes(StandardCharsets.UTF_8),
|
||||
new DataInputStream(new ByteArrayInputStream(pyl))
|
||||
);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("{}", Signing.class, e);
|
||||
return SigningResult.of(SigningStatus.NO_PAYLOAD);
|
||||
}
|
||||
|
||||
final var response = SigningManager.INSTANCE.verifyClaim(
|
||||
withAdditionalData(decodedPayload.msg(), decodedPayload.nonce(), decodedPayload.exp()),
|
||||
decodedPayload.signature(),
|
||||
decodedPayload.key(),
|
||||
decodedPayload.exp()
|
||||
);
|
||||
|
||||
return switch (response) {
|
||||
case SigningManager.Response.InvalidSignature __ -> SigningResult.of(SigningStatus.INVALID_SIGNATURE);
|
||||
case SigningManager.Response.NoSuchKey __ -> SigningResult.of(SigningStatus.NO_SUCH_KEY);
|
||||
case SigningManager.Response.ReusedSignature __ -> SigningResult.of(SigningStatus.REUSED_SIGNATURE);
|
||||
case SigningManager.Response.SignatureValid valid -> {
|
||||
final boolean authenticated = valid.key().manifestUrlToClaims()
|
||||
.values().stream()
|
||||
.flatMap(Collection::stream)
|
||||
.anyMatch(claim -> claim.equalsIgnoreCase(nick));
|
||||
|
||||
final String encodedKey = Base64.getEncoder()
|
||||
.encodeToString(valid.key().bc().getEncoded());
|
||||
|
||||
LOGGER.info(
|
||||
"Encoded public key: {}",
|
||||
encodedKey
|
||||
);
|
||||
yield new SigningResult(
|
||||
authenticated ? SigningStatus.VERIFIED : SigningStatus.VALID_UNVERIFIED,
|
||||
encodedKey
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config;
|
||||
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class Configuration {
|
||||
private static final String DEFAULT_MANIFEST = "https://optmstc.dev/key-manifest-v1.json";
|
||||
|
||||
public volatile List<String> keyManifestUrls = List.of(DEFAULT_MANIFEST);
|
||||
|
||||
public volatile boolean toggleForSelf = true;
|
||||
public volatile boolean forceFallback = false;
|
||||
public volatile boolean disableFallback = true;
|
||||
public volatile boolean forceCompress = false;
|
||||
public volatile boolean ignoreCspyLike = true;
|
||||
public volatile int chatMsgTrunc = 2048;
|
||||
public volatile int maxCompressedPayload = this.chatMsgTrunc * 4;
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config;
|
||||
|
||||
import io.github.wasabithumb.jtoml.configurate.TomlConfigurationLoader;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.loader.HeaderMode;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.storageDir;
|
||||
|
||||
|
||||
public final class ConfigurationManager {
|
||||
public static final ConfigurationManager INSTANCE = new ConfigurationManager();
|
||||
public final Configuration config;
|
||||
private final CommentedConfigurationNode node;
|
||||
private final TomlConfigurationLoader loader;
|
||||
|
||||
private ConfigurationManager () {
|
||||
try {
|
||||
this.loader = TomlConfigurationLoader.builder()
|
||||
.defaultOptions(opts -> opts.shouldCopyDefaults(true))
|
||||
.headerMode(HeaderMode.PRESERVE)
|
||||
.path(storageDir.resolve("chatattestation" + ".toml"))
|
||||
.build();
|
||||
|
||||
this.node = this.loader.load();
|
||||
this.config = Objects.requireNonNull(this.node.get(Configuration.class));
|
||||
save();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Configuration error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void save () {
|
||||
try {
|
||||
this.node.set(Configuration.class, this.config);
|
||||
this.loader.save(this.node);
|
||||
} catch (ConfigurateException e) {
|
||||
throw new IllegalStateException("Failed to save config", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto;
|
||||
|
||||
import com.google.common.primitives.Longs;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config.ConfigurationManager;
|
||||
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
|
||||
import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto.SigningManager.PERIOD;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.LOGGER;
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.MESSAGE_LIMIT;
|
||||
|
||||
public record Payload(byte[] msg, byte[] signature, byte[] key, byte[] nonce, long exp, boolean compressedMsg) {
|
||||
private static final int ORIGINAL_MSG_BUDGET = (MESSAGE_LIMIT - 4) - 64 - 16 - 8 - 2 - 1; // 64 for signature size, 16 for key hash, 8 for exp, 2 for nonce, 1 for payload header
|
||||
|
||||
public static Payload read(byte[] msg, DataInputStream input) throws IOException {
|
||||
final int replacementMsgBytes = input.readUnsignedByte();
|
||||
final boolean isCompressed = replacementMsgBytes != 0;
|
||||
if (isCompressed) {
|
||||
msg = new byte[replacementMsgBytes];
|
||||
input.readFully(msg);
|
||||
}
|
||||
final byte[] signature = new byte[64];
|
||||
input.readFully(signature);
|
||||
final byte[] keyHash = new byte[16];
|
||||
input.readFully(keyHash);
|
||||
final byte[] nonce = new byte[2];
|
||||
input.readFully(nonce);
|
||||
return new Payload(msg, signature, keyHash, nonce, input.readLong(), isCompressed);
|
||||
}
|
||||
|
||||
public static byte[] withAdditionalData(byte[] msg, byte[] nonce, long exp) {
|
||||
final byte[] msgWithNonceAndExp = new byte[msg.length + 2 + 8];
|
||||
System.arraycopy(nonce, 0, msgWithNonceAndExp, 0, 2);
|
||||
System.arraycopy(Longs.toByteArray(exp), 0, msgWithNonceAndExp, 2, 8);
|
||||
System.arraycopy(msg, 0, msgWithNonceAndExp, 2 + 8, msg.length);
|
||||
return msgWithNonceAndExp;
|
||||
}
|
||||
|
||||
public static boolean write(byte[] msg, DataOutput output) throws IOException {
|
||||
final boolean compressed = msg.length > ORIGINAL_MSG_BUDGET || ConfigurationManager.INSTANCE.config.forceCompress;
|
||||
|
||||
if (compressed) {
|
||||
final var out = new ByteArrayOutputStream();
|
||||
final var cmp = new ZstdCompressorOutputStream(out);
|
||||
cmp.write(msg);
|
||||
cmp.flush();
|
||||
cmp.close();
|
||||
msg = out.toByteArray();
|
||||
}
|
||||
|
||||
output.writeByte(compressed ? msg.length : 0);
|
||||
if (compressed) output.write(msg);
|
||||
final byte[] nonce = new byte[2];
|
||||
ThreadLocalRandom.current().nextBytes(nonce);
|
||||
final long exp = System.currentTimeMillis() + PERIOD;
|
||||
msg = withAdditionalData(msg, nonce, exp);
|
||||
final var signature = SigningManager.INSTANCE.createSignature(msg);
|
||||
output.write(signature);
|
||||
output.write(SigningManager.INSTANCE.selfHash);
|
||||
output.write(nonce);
|
||||
output.writeLong(exp);
|
||||
return compressed;
|
||||
}
|
||||
|
||||
public String getReplacementMsg() throws IOException {
|
||||
if (!this.compressedMsg) return new String(this.msg, StandardCharsets.UTF_8);
|
||||
@SuppressWarnings("resource") final var in = new ZstdCompressorInputStream(new ByteArrayInputStream(this.msg));
|
||||
final var out = new ByteArrayOutputStream();
|
||||
|
||||
final byte[] buf = new byte[8192];
|
||||
int read;
|
||||
while ((read = in.read(buf)) != -1) {
|
||||
if (out.size() >= ConfigurationManager.INSTANCE.config.maxCompressedPayload)
|
||||
return new String(this.msg, StandardCharsets.UTF_8);
|
||||
|
||||
out.write(buf, 0, read);
|
||||
}
|
||||
return out.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
+337
@@ -0,0 +1,337 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.crypto;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.KeyManifest;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config.ConfigurationManager;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
|
||||
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
||||
import org.bouncycastle.crypto.util.PrivateKeyInfoFactory;
|
||||
import org.bouncycastle.math.ec.rfc8032.Ed25519;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.StampedLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.Constants.*;
|
||||
|
||||
public final class SigningManager {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(SigningManager.class);
|
||||
public static final SigningManager INSTANCE = new SigningManager();
|
||||
public static final long PERIOD = 10_000L;
|
||||
public final byte[] selfHash;
|
||||
private final ExecutorService requestExecutor = Executors.newCachedThreadPool();
|
||||
private final StampedLock lock = new StampedLock();
|
||||
private final Map<String, KeyManifest> manifests;
|
||||
private final Set<String> nicks = new HashSet<>();
|
||||
private final Map<WrappedByteArray, LoadedKey> hashToKey = new HashMap<>();
|
||||
private final Map<Long, Set<WrappedByteArray>> usedSignatureMap = ExpiringMap.builder()
|
||||
.expiration(PERIOD, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
private final Ed25519PrivateKeyParameters selfKey;
|
||||
private final Path cachePath;
|
||||
|
||||
public SigningManager() {
|
||||
this.cachePath = storageDir.resolve("data").resolve("chatattestation-cache.json");
|
||||
|
||||
final var cacheParent = this.cachePath.getParent();
|
||||
final boolean orphan = Files.notExists(cacheParent);
|
||||
|
||||
try {
|
||||
if (orphan) {
|
||||
LOGGER.info("Creating Chat Attestation folder");
|
||||
Files.createDirectories(cacheParent);
|
||||
}
|
||||
|
||||
if (orphan || Files.notExists(this.cachePath)) {
|
||||
this.manifests = new HashMap<>();
|
||||
} else {
|
||||
this.manifests = GSON.fromJson(
|
||||
Files.newBufferedReader(this.cachePath),
|
||||
new TypeToken<>() {
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to initialize cache", e);
|
||||
}
|
||||
|
||||
final var legacyKeyPath = storageDir.resolve("chatattestation.key");
|
||||
final var keyPath = storageDir.resolve("chatattestation.priv.key");
|
||||
|
||||
if (Files.exists(legacyKeyPath)) {
|
||||
try {
|
||||
Files.move(legacyKeyPath, keyPath);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to rename legacy key path");
|
||||
}
|
||||
}
|
||||
|
||||
if (Files.notExists(keyPath)) {
|
||||
try {
|
||||
this.selfKey = new Ed25519PrivateKeyParameters(SecureRandom.getInstanceStrong());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalArgumentException("JVM does not provide strong secure random impl", e);
|
||||
}
|
||||
|
||||
this.savePrivateKey(keyPath);
|
||||
} else {
|
||||
final byte[] keyData;
|
||||
|
||||
try {
|
||||
keyData = Files.readAllBytes(keyPath);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException("Failed to load stored private key", e);
|
||||
}
|
||||
if (keyData.length == 32) {
|
||||
this.selfKey = new Ed25519PrivateKeyParameters(keyData);
|
||||
this.savePrivateKey(keyPath);
|
||||
} else {
|
||||
final var extractedData = Base64.getDecoder().decode(
|
||||
new String(keyData, StandardCharsets.UTF_8)
|
||||
.lines()
|
||||
.filter(l -> !l.startsWith("-"))
|
||||
.map(String::trim)
|
||||
.collect(Collectors.joining())
|
||||
);
|
||||
|
||||
try {
|
||||
this.selfKey = (Ed25519PrivateKeyParameters) PrivateKeyFactory.createKey(extractedData);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Invalid private key", e);
|
||||
}
|
||||
}
|
||||
/* LOGGER.info(
|
||||
"Encoded public key: {}",
|
||||
Base64.getEncoder().encodeToString(this.selfKey.generatePublicKey().getEncoded())
|
||||
);*/
|
||||
}
|
||||
|
||||
final var encodedPublicKey = this.selfKey.generatePublicKey().getEncoded();
|
||||
this.selfHash = createHash(encodedPublicKey);
|
||||
|
||||
@SuppressWarnings("resource") final var scheduler = Executors.newSingleThreadScheduledExecutor(DAEMON_THREAD_FACTORY);
|
||||
scheduler.scheduleAtFixedRate(this::refetchKeys, 0, 1, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
|
||||
}
|
||||
|
||||
public static byte[] createHash(byte[] input) {
|
||||
final MessageDigest messageDigest;
|
||||
try {
|
||||
messageDigest = MessageDigest.getInstance("SHA3-224");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("JVM does not have SHA3-224 support", e);
|
||||
}
|
||||
|
||||
return Arrays.copyOfRange(messageDigest.digest(input), 0, 16);
|
||||
}
|
||||
|
||||
private static long getCurrentPeriod() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void savePrivateKey(Path keyPath) {
|
||||
try (final var out = Files.newBufferedWriter(keyPath)) {
|
||||
out.write("-----BEGIN PRIVATE KEY-----\n");
|
||||
|
||||
final var encoded = Base64.getEncoder().encodeToString(
|
||||
PrivateKeyInfoFactory.createPrivateKeyInfo(
|
||||
this.selfKey
|
||||
).getEncoded()
|
||||
);
|
||||
out.write(encoded);
|
||||
out.write("\n-----END PRIVATE KEY-----");
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to save private key", e);
|
||||
}
|
||||
}
|
||||
|
||||
private CompletableFuture<KeyManifest> refetchManifest(String url) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (final var client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(30)).build()) {
|
||||
final var request = client.send(
|
||||
HttpRequest.newBuilder(URI.create(url)).GET().build(),
|
||||
HttpResponse.BodyHandlers.ofString()
|
||||
);
|
||||
|
||||
return GSON.fromJson(request.body(), KeyManifest.class);
|
||||
} catch (Exception e) {
|
||||
throw new CompletionException("Failed to fetch manifest", e);
|
||||
}
|
||||
}, this.requestExecutor);
|
||||
}
|
||||
|
||||
public void refetchKeys() {
|
||||
final var futures = ConfigurationManager.INSTANCE.config.keyManifestUrls.stream()
|
||||
.collect(Collectors.toMap(url -> url, this::refetchManifest));
|
||||
|
||||
for (final var futureEntry : futures.entrySet()) {
|
||||
final String manifest = futureEntry.getKey();
|
||||
|
||||
try {
|
||||
this.manifests.put(manifest, futureEntry.getValue().join());
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Fetching {} failed, cache will be used if present", manifest, e);
|
||||
}
|
||||
}
|
||||
|
||||
try (final var writer = Files.newBufferedWriter(this.cachePath)) {
|
||||
GSON.toJson(this.manifests, writer);
|
||||
writer.flush();
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Failed to save manifest cache", e);
|
||||
}
|
||||
|
||||
this.reloadKeys();
|
||||
}
|
||||
|
||||
private void reloadKeys() {
|
||||
final long writeLock = this.lock.writeLock();
|
||||
|
||||
try {
|
||||
this.hashToKey.clear();
|
||||
this.nicks.clear();
|
||||
|
||||
for (final var entry : this.manifests.entrySet()) {
|
||||
final var manifestUrl = entry.getKey();
|
||||
|
||||
for (final var keyToClaim : entry.getValue().keyToClaims().entrySet()) {
|
||||
final var rawKey = Base64.getDecoder()
|
||||
.decode(keyToClaim.getKey());
|
||||
final var loadedKey = this.hashToKey.computeIfAbsent(
|
||||
new WrappedByteArray(
|
||||
createHash(rawKey)
|
||||
),
|
||||
k -> new LoadedKey(
|
||||
new Ed25519PublicKeyParameters(rawKey),
|
||||
new HashMap<>()
|
||||
)
|
||||
);
|
||||
|
||||
final var keyClaims = keyToClaim.getValue();
|
||||
final var claims = loadedKey.manifestUrlToClaims.computeIfAbsent(manifestUrl, k -> new HashSet<>());
|
||||
claims.addAll(keyClaims);
|
||||
|
||||
for (final var claim : keyClaims)
|
||||
this.nicks.add(claim.toLowerCase());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.lock.unlockWrite(writeLock);
|
||||
}
|
||||
}
|
||||
|
||||
public Response verifyClaim(byte[] msg, byte[] sig, byte[] key, long exp) {
|
||||
if (System.currentTimeMillis() > exp) return Response.ReusedSignature.INSTANCE;
|
||||
|
||||
final long readLock = this.lock.readLock();
|
||||
|
||||
try {
|
||||
final var usedSignatures = this.usedSignatureMap.computeIfAbsent(getCurrentPeriod(), k -> new HashSet<>());
|
||||
final var wrappedSig = new WrappedByteArray(sig);
|
||||
if (usedSignatures.contains(wrappedSig)) return Response.ReusedSignature.INSTANCE;
|
||||
final var wrappedKey = new WrappedByteArray(key);
|
||||
final var loadedKey = this.hashToKey.get(wrappedKey);
|
||||
if (loadedKey == null) return Response.NoSuchKey.INSTANCE;
|
||||
|
||||
if (!loadedKey.bc.verify(Ed25519.Algorithm.Ed25519, null, msg, 0, msg.length, sig, 0))
|
||||
return Response.InvalidSignature.INSTANCE;
|
||||
|
||||
usedSignatures.add(wrappedSig);
|
||||
return new Response.SignatureValid(loadedKey);
|
||||
} finally {
|
||||
this.lock.unlockRead(readLock);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean doesNickRequireSignature(String nick) {
|
||||
return this.nicks.contains(nick.toLowerCase());
|
||||
}
|
||||
|
||||
public byte[] createSignature(byte[] msg) {
|
||||
final byte[] signature = new byte[64];
|
||||
this.selfKey.sign(Ed25519.Algorithm.Ed25519, null, msg, 0, msg.length, signature, 0);
|
||||
return signature;
|
||||
}
|
||||
|
||||
public sealed interface Response {
|
||||
final class NoSuchKey implements Response {
|
||||
public static final NoSuchKey INSTANCE = new NoSuchKey();
|
||||
|
||||
private NoSuchKey() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final class InvalidSignature implements Response {
|
||||
public static final InvalidSignature INSTANCE = new InvalidSignature();
|
||||
|
||||
private InvalidSignature() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
final class ReusedSignature implements Response {
|
||||
public static final ReusedSignature INSTANCE = new ReusedSignature();
|
||||
|
||||
private ReusedSignature() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
record SignatureValid(LoadedKey key) implements Response {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static final class WrappedByteArray {
|
||||
private final byte[] arr;
|
||||
|
||||
public WrappedByteArray(byte @Unmodifiable [] arr) {
|
||||
this.arr = arr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return HexFormat.of().formatHex(this.arr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(this.arr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof final WrappedByteArray wrappedByteArray && Arrays.equals(wrappedByteArray.arr, this.arr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public record LoadedKey(Ed25519PublicKeyParameters bc, Map<String, Set<String>> manifestUrlToClaims) {
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums;
|
||||
|
||||
public enum SigningStatus {
|
||||
NO_PAYLOAD,
|
||||
NEEDS_SIGNATURE,
|
||||
INVALID_SIGNATURE,
|
||||
NO_SUCH_KEY,
|
||||
REUSED_SIGNATURE,
|
||||
VERIFIED, // authenticated via manifest
|
||||
VALID_UNVERIFIED // valid sig, but key not authorized for nick
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public final class ChatEncoding {
|
||||
public static final int[] ENCODING;
|
||||
public static final int[] DECODING;
|
||||
|
||||
static {
|
||||
ENCODING = IntStream.concat(
|
||||
IntStream.range(0x21, 0x7E),
|
||||
IntStream.range(0xA1, 0x010000)
|
||||
)
|
||||
.filter(c -> c != '&' && c != '§')
|
||||
.limit(256)
|
||||
.toArray();
|
||||
|
||||
final int max = Arrays.stream(ENCODING).max().orElseThrow();
|
||||
DECODING = new int[max + 1];
|
||||
Arrays.fill(DECODING, -1);
|
||||
|
||||
for (int i = 0; i < ENCODING.length; i++) {
|
||||
DECODING[ENCODING[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
public static String encode(byte[] input) {
|
||||
final var builder = new StringBuilder(input.length);
|
||||
|
||||
for (final byte b : input) {
|
||||
builder.appendCodePoint(ENCODING[(int) b & 0xFF]);
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static byte @Nullable [] decode(String input) {
|
||||
final var out = new ByteArrayOutputStream();
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
final var ch = input.codePointAt(i);
|
||||
if (ch < 0 || ch >= DECODING.length) return null;
|
||||
final int b = DECODING[ch];
|
||||
if (b == -1) return null;
|
||||
out.write(b);
|
||||
}
|
||||
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Constants {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("chatattestation");
|
||||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final Pattern SIGNED_MESSAGE_PATTERN = Pattern.compile("\\$\\$(.*)\\$\\$(.*)$");
|
||||
public static final ThreadFactory DAEMON_THREAD_FACTORY = r -> {
|
||||
final var t = new Thread(r);
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
};
|
||||
public static final int MESSAGE_LIMIT = 256;
|
||||
public static final ExecutorService SIGN_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||
public static final Path storageDir = Path.of("chatattestation");
|
||||
|
||||
private Constants() {
|
||||
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import org.jspecify.annotations.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ListeningList<T> implements List<T> {
|
||||
private final Consumer<T> listener;
|
||||
private final List<T> handle;
|
||||
|
||||
public ListeningList(Consumer<T> listener, List<T> handle) {
|
||||
this.listener = listener;
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.handle.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.handle.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return this.handle.contains(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterator<T> iterator() {
|
||||
return this.handle.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Object @NonNull [] toArray() {
|
||||
return this.handle.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull <T1> T1 @NonNull [] toArray(@NonNull T1 @NonNull [] a) {
|
||||
return this.handle.toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(T t) {
|
||||
this.listener.accept(t);
|
||||
return this.handle.add(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return this.handle.remove(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(@NonNull Collection<?> c) {
|
||||
//noinspection SlowListContainsAll
|
||||
return this.handle.containsAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(@NonNull Collection<? extends T> c) {
|
||||
c.forEach(this.listener);
|
||||
return this.handle.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, @NonNull Collection<? extends T> c) {
|
||||
c.forEach(this.listener);
|
||||
return this.handle.addAll(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(@NonNull Collection<?> c) {
|
||||
return this.handle.removeAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(@NonNull Collection<?> c) {
|
||||
return this.handle.retainAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.handle.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
return this.handle.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T set(int index, T element) {
|
||||
this.listener.accept(element);
|
||||
return this.handle.set(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, T element) {
|
||||
this.listener.accept(element);
|
||||
this.handle.add(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove(int index) {
|
||||
return this.handle.remove(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(Object o) {
|
||||
return this.handle.indexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
return this.handle.lastIndexOf(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ListIterator<T> listIterator() {
|
||||
return this.handle.listIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ListIterator<T> listIterator(int index) {
|
||||
return this.handle.listIterator(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<T> subList(int fromIndex, int toIndex) {
|
||||
return this.handle.subList(fromIndex, toIndex);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.Normalizer;
|
||||
import java.util.Arrays;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class NormalizationUtil {
|
||||
private static final int[] CONFUSABLES;
|
||||
|
||||
static {
|
||||
int[] confusables = new int[0];
|
||||
final String read;
|
||||
final var resourceStream = Objects.requireNonNull(NormalizationUtil.class.getClassLoader().getResourceAsStream("confusables.txt"));
|
||||
|
||||
try {
|
||||
read = new String(resourceStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
resourceStream.close();
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Failed to read confusables list", e);
|
||||
}
|
||||
|
||||
final var hexFormat = HexFormat.of();
|
||||
final var lines = read.lines().iterator();
|
||||
while (lines.hasNext()) {
|
||||
var line = lines.next();
|
||||
if (line.startsWith("#")) continue;
|
||||
final var split = line.split(";");
|
||||
if (split.length < 2) continue;
|
||||
final int confusable = intFromByteArrayWithPadding(hexFormat.parseHex(padHex(split[0].trim())));
|
||||
if (confusable <= 127) continue;
|
||||
final var replacement = split[1].trim();
|
||||
if (replacement.split(" ").length != 1) continue;
|
||||
final int replacementCodepoint = intFromByteArrayWithPadding(hexFormat.parseHex(padHex(replacement)));
|
||||
if (replacementCodepoint > 127) continue;
|
||||
if (confusables.length <= confusable) {
|
||||
int[] newConfusables = new int[confusable + 1];
|
||||
Arrays.fill(newConfusables, Integer.MIN_VALUE);
|
||||
System.arraycopy(confusables, 0, newConfusables, 0, confusables.length);
|
||||
confusables = newConfusables;
|
||||
}
|
||||
|
||||
confusables[confusable] = replacementCodepoint;
|
||||
}
|
||||
|
||||
CONFUSABLES = confusables;
|
||||
}
|
||||
|
||||
private static String padHex(String input) {
|
||||
if (input.length() % 2 != 0) return "0" + input;
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
private static int intFromByteArrayWithPadding(byte[] buf) {
|
||||
if (buf.length != 4) {
|
||||
final byte[] intermediate = new byte[4];
|
||||
System.arraycopy(buf, 0, intermediate, 4 - buf.length, buf.length);
|
||||
buf = intermediate;
|
||||
}
|
||||
|
||||
return Ints.fromByteArray(buf);
|
||||
}
|
||||
|
||||
public static String normalizeString(String input) {
|
||||
input = Normalizer.normalize(input, Normalizer.Form.NFKC);
|
||||
final var output = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
final int codepoint = input.codePointAt(i);
|
||||
final int replacement;
|
||||
if (CONFUSABLES.length <= codepoint
|
||||
|| (replacement = CONFUSABLES[codepoint]) == Integer.MIN_VALUE)
|
||||
output.appendCodePoint(codepoint);
|
||||
else {
|
||||
output.appendCodePoint(replacement);
|
||||
}
|
||||
}
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums.SigningStatus;
|
||||
|
||||
public record SigningResult(SigningStatus status, String encodedKey) {
|
||||
public static SigningResult of(SigningStatus status) {
|
||||
return new SigningResult(status, null);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.config.ConfigurationManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Util {
|
||||
private static final Pattern EXTRACTOR = Pattern.compile("^<?([^:<>]*)[>:] (.*)$");
|
||||
private static final Pattern CHIPMUNK_EXTRACTOR = Pattern.compile("^\\[.*] ([^›]*) › (.*)$");
|
||||
|
||||
private Util() {
|
||||
|
||||
}
|
||||
|
||||
public static @Nullable String extractDisguisedContent(String fullMsg) {
|
||||
final var matcher = EXTRACTOR.matcher(fullMsg);
|
||||
return matcher.matches() ? matcher.group(2) : null;
|
||||
}
|
||||
|
||||
public static @Nullable SystemExtraction extractSystemContent(String msg) {
|
||||
final var chipmunkMatcher = CHIPMUNK_EXTRACTOR.matcher(msg);
|
||||
if (chipmunkMatcher.matches()) {
|
||||
return new SystemExtraction(chipmunkMatcher.group(1), chipmunkMatcher.group(2));
|
||||
} else {
|
||||
final var regularExtractor = EXTRACTOR.matcher(msg);
|
||||
if (!regularExtractor.matches()) return null;
|
||||
// TODO: Handle spaces in names.
|
||||
final var sender = regularExtractor.group(1).split(" ");
|
||||
if (sender.length == 1 && ConfigurationManager.INSTANCE.config.ignoreCspyLike) return null;
|
||||
return new SystemExtraction(sender[sender.length - 1], regularExtractor.group(2));
|
||||
}
|
||||
}
|
||||
|
||||
public record SystemExtraction(String sender, String content) {
|
||||
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.chatparsers;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.ParseChatData;
|
||||
@@ -14,9 +14,9 @@ public class KaboomChatParser implements ParseChatData {
|
||||
private static final Component SEPERATOR_COLON = Component.text(":");
|
||||
private static final Component SEPERATOR_COLON_RACCOON = Component.text("§f:"); // https://github.com/raccoonserver/extras/commit/315f704075db2f00e3e1bfbf55f858469c22880f
|
||||
private static final Component SEPERATOR_SPACE = Component.space();
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
|
||||
public KaboomChatParser (Bot bot) {
|
||||
public KaboomChatParser (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
|
||||
public record CommandContext(Bot bot, String[] args, CommandSource source) {
|
||||
public record CommandContext(NitoriBot bot, String[] args, CommandSource source) {
|
||||
}
|
||||
+2
-2
@@ -1,13 +1,13 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.command;
|
||||
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ParsedChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public record CommandSource(PlayerProfileData sender, boolean inGame, ParsedChatType chatType) {
|
||||
public void sendFeedback (Bot bot, Component message) {
|
||||
public void sendFeedback (NitoriBot bot, Component message) {
|
||||
final String selector = String.format("@p[nbt={UUID:uuid(\"%s\")}]", sender.uuid);
|
||||
|
||||
if (chatType() == ParsedChatType.NORMAL) bot.chat.tellraw("@a", message);
|
||||
|
||||
+43
-7
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
@@ -17,7 +17,11 @@ public class CoreCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public List<String> getAliases () {
|
||||
return List.of("core", "cb", "corerun");
|
||||
return List.of(
|
||||
"core",
|
||||
"cb",
|
||||
"corerun"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,16 +36,48 @@ public class CoreCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
String message = String.join(" ", context.args());
|
||||
String message = String.join(
|
||||
" ",
|
||||
context.args()
|
||||
);
|
||||
|
||||
Component output = bot.core.runTrackedWithTellraw("nitoribot.command_block.output", "@a", message);
|
||||
Component output = bot.core.runTrackedWithPacket(message);
|
||||
|
||||
source.sendFeedback(bot, output);
|
||||
try {
|
||||
System.out.println(output);
|
||||
source.sendFeedback(
|
||||
bot,
|
||||
output
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
||||
/*if (message.contains("@username") || message.contains("@uuid")) {
|
||||
for (PlayerProfileData player : bot.players.list) {
|
||||
Component output = bot.core.runTrackedWithTellraw(
|
||||
"nitoribot.command_block.output",
|
||||
"@a",
|
||||
message.replaceAll(
|
||||
"\\s+@username",
|
||||
" " + player.profile.getName()
|
||||
).replaceAll(
|
||||
"\\s+@uuid",
|
||||
" " + player.profile.getIdAsString()
|
||||
)
|
||||
);
|
||||
source.sendFeedback(bot, output);
|
||||
}
|
||||
} else {
|
||||
|
||||
//bot.core.runTrackedWithTellraw("nitoribot.command_block.output", "@a", message);
|
||||
//source.sendFeedback(bot, output);
|
||||
}*/
|
||||
/*CompletableFuture.runAsync(() -> {
|
||||
source.sendFeedback(bot, bot.core.output);
|
||||
bot.core.output = null;
|
||||
}, CompletableFuture.delayedExecutor(100, TimeUnit.MILLISECONDS));*/
|
||||
}
|
||||
}//if (args.includes("$username") || args.includes("$uuid")) {
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
@@ -34,7 +34,7 @@ public class EchoCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
String args = String.join(" ", context.args());
|
||||
if (args.startsWith("/")) {
|
||||
bot.chat.command(args.substring("/".length()));
|
||||
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
@@ -38,7 +38,7 @@ public class HelpCommand implements CommandInfo {
|
||||
return List.of("<command>");
|
||||
}
|
||||
|
||||
public Component getCommands (Bot bot) {
|
||||
public Component getCommands (NitoriBot bot) {
|
||||
List<Component> Public = new ArrayList<>();
|
||||
List<Component> Trusted = new ArrayList<>();
|
||||
|
||||
@@ -54,7 +54,7 @@ public class HelpCommand implements CommandInfo {
|
||||
return Component.empty().append(Public).append(Component.text("\n")).append(Trusted);
|
||||
}
|
||||
|
||||
private Component getUsages (Bot bot, List<String> usages) {
|
||||
private Component getUsages (NitoriBot bot, List<String> usages) {
|
||||
Component component = null;
|
||||
if (usages == null) component = Component.empty().append(
|
||||
Component.text("N/A").color(
|
||||
@@ -71,7 +71,7 @@ public class HelpCommand implements CommandInfo {
|
||||
return component;
|
||||
}
|
||||
|
||||
private Component getCommand (Bot bot, String[] command) {
|
||||
private Component getCommand (NitoriBot bot, String[] command) {
|
||||
Component component = null;
|
||||
|
||||
for (CommandInfo commands : bot.commandManager.commands) {
|
||||
@@ -96,7 +96,7 @@ public class HelpCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
String[] args = context.args();
|
||||
CommandSource source = context.source();
|
||||
|
||||
|
||||
+3
-2
@@ -131,7 +131,8 @@ public class InfoCommand implements CommandInfo {
|
||||
component = Component.translatable(
|
||||
"%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s",
|
||||
Component.text("Hostname").color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component.text(InetAddress.getLocalHost().getHostName()).color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component.text("N/A").color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
// Component.text(InetAddress.getLocalHost().getHostName()).color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component.text("Username").color(convertColorString(bot.config.colors.commands.primary)),
|
||||
Component.text(System.getProperty("user.name")).color(convertColorString(bot.config.colors.commands.secondary)),
|
||||
Component.text("Directory").color(convertColorString(bot.config.colors.commands.primary)),
|
||||
@@ -165,4 +166,4 @@ public class InfoCommand implements CommandInfo {
|
||||
component
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
@@ -39,7 +39,7 @@ public class ListCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
Component component = null;
|
||||
Component playerComponent = null;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
@@ -35,7 +35,7 @@ public class PlayerInfoCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
String[] args = context.args();
|
||||
CommandSource source = context.source();
|
||||
Component component = null;
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
@@ -37,7 +37,7 @@ public class RCCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
CommandSource source = context.source();
|
||||
|
||||
bot.core.move();
|
||||
|
||||
+1
-1
@@ -50,6 +50,6 @@ public class TestCommand implements CommandInfo {
|
||||
|
||||
var source = context.source();
|
||||
|
||||
bot.world.getBlock(Vector3i.from(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])));
|
||||
// bot.world.getBlock(Vector3i.from(Integer.parseInt(args[0]), Integer.parseInt(args[1]), Integer.parseInt(args[2])));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandTrustLevels;
|
||||
@@ -34,7 +34,7 @@ public class ReconnectCommand implements CommandInfo {
|
||||
|
||||
@Override
|
||||
public void execute (CommandContext context) {
|
||||
Bot bot = context.bot();
|
||||
NitoriBot bot = context.bot();
|
||||
|
||||
bot.session.disconnect("Reconnect Command");
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.console;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import org.jline.reader.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CreateConsole implements Completer {
|
||||
private static final List<NitoriBot> servers = Main.Bots;
|
||||
public LineReader reader;
|
||||
public final String server = "all";
|
||||
|
||||
|
||||
@Override
|
||||
public void complete (
|
||||
LineReader reader, ParsedLine line, List<Candidate> candidates
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
private void handleLine (String line) {
|
||||
for (NitoriBot bot : servers) {
|
||||
if (line.equals(bot.config.console.prefix + "kill")) System.exit(0);
|
||||
bot.chat.send(line);
|
||||
}
|
||||
}
|
||||
|
||||
public CreateConsole () {
|
||||
this.reader = LineReaderBuilder.builder().completer(this).build();
|
||||
//this.terminal = TerminalBuilder.builder().build();
|
||||
|
||||
//this.jLineAppender = new JlineAppender();
|
||||
|
||||
JlineAppender.setLineReader(reader);
|
||||
|
||||
Main.executorService.submit(
|
||||
() -> {
|
||||
while (true) {
|
||||
try {
|
||||
String line;
|
||||
|
||||
line = reader.readLine(String.format(
|
||||
"[%s] > ",
|
||||
this.server
|
||||
));
|
||||
|
||||
handleLine(line);
|
||||
} catch (Exception _) {
|
||||
}
|
||||
}
|
||||
},
|
||||
"Console Thread"
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.console;
|
||||
|
||||
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import org.jline.reader.LineReader;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class JlineAppender extends AppenderBase<ILoggingEvent> {
|
||||
private static LineReader reader;
|
||||
private PatternLayoutEncoder encoder;
|
||||
//private PatternLayoutEncoder encoder = new PatternLayoutEncoder();
|
||||
|
||||
public static void setLineReader (@Nullable LineReader lineReader) {
|
||||
reader = lineReader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start () {
|
||||
super.start();
|
||||
encoder.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop () {
|
||||
encoder.stop();
|
||||
super.stop();
|
||||
}
|
||||
|
||||
|
||||
public void setEncoder (PatternLayoutEncoder encoder) {
|
||||
this.encoder = encoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void append (ILoggingEvent event) {
|
||||
PatternLayoutEncoder enc = encoder;
|
||||
String message = new String(enc.encode(event), StandardCharsets.UTF_8).stripTrailing();
|
||||
|
||||
if (reader != null) {
|
||||
reader.printAbove(message);
|
||||
} else {
|
||||
System.out.println(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.console.logger;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.slf4j.*;
|
||||
|
||||
public class LoggerManager {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggerManager.class);
|
||||
|
||||
public String convertComponentToAnsi (Component component) {
|
||||
return ComponentUtil.componentToAnsi(component);
|
||||
}
|
||||
private String getLoggerType (LoggerType logType) {
|
||||
return switch (logType) {
|
||||
case LoggerType.COMMAND -> convertComponentToAnsi(Component.text("COMMAND").color(NamedTextColor.YELLOW));
|
||||
case LoggerType.LOG -> convertComponentToAnsi(Component.text("LOG").color(NamedTextColor.GOLD));
|
||||
case LoggerType.RECONNECT -> convertComponentToAnsi(Component.text("RECONNECT").color(NamedTextColor.AQUA));
|
||||
};
|
||||
}
|
||||
|
||||
public void log (String message) {
|
||||
MDC.putCloseable("customLevel", getLoggerType(LoggerType.LOG));
|
||||
LOGGER.info(message);
|
||||
}
|
||||
|
||||
public void command (String message) {
|
||||
MDC.putCloseable("customLevel", getLoggerType(LoggerType.COMMAND));
|
||||
LOGGER.info(message);
|
||||
}
|
||||
|
||||
public void reconnect (String message) {
|
||||
MDC.putCloseable("customLevel", getLoggerType(LoggerType.RECONNECT));
|
||||
LOGGER.info(message);
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.console.logger;
|
||||
|
||||
public enum LoggerType {
|
||||
LOG,
|
||||
COMMAND,
|
||||
RECONNECT,
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.data.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockRegistries {
|
||||
public String block;
|
||||
public final STATES[] states = new STATES[]{};
|
||||
public int blockId;
|
||||
public int itemId;
|
||||
|
||||
public static final class STATES {
|
||||
public int id;
|
||||
}
|
||||
}
|
||||
+20
-2
@@ -1,15 +1,29 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.listeners;
|
||||
|
||||
import land.chipmunk.code.kaboomstandardsorganization.messaginglib.mcprotocollib.MCProtocolLibMessenger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.enums.SigningStatus;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatType;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.chat.PlayerMessageData;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundTagQueryPacket;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Listener {
|
||||
default void packetSent () {
|
||||
}
|
||||
|
||||
default void extrasMessagingReceived (
|
||||
String channel,
|
||||
UUID uuid,
|
||||
String message
|
||||
) {
|
||||
}
|
||||
|
||||
default void chatReceived (ChatType chatType, SigningStatus signingStatus, Component message) {}
|
||||
|
||||
default void packetReceived (Packet packet) {
|
||||
}
|
||||
|
||||
@@ -28,8 +42,12 @@ public interface Listener {
|
||||
default void botMoved () {
|
||||
}
|
||||
|
||||
default void commandSpyReceived (PlayerProfileData player, String command) {
|
||||
default void commandSpyReceived (
|
||||
PlayerProfileData player,
|
||||
String command
|
||||
) {
|
||||
}
|
||||
|
||||
default void tabCompleteReceived (ClientboundTagQueryPacket packet) {}
|
||||
default void tabCompleteReceived (ClientboundTagQueryPacket packet) {
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.logger;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Logger {
|
||||
private final DateTimeFormatter formatTime = DateTimeFormatter.ofPattern("hh:mm:ss");
|
||||
|
||||
private final DateTimeFormatter formatDate = DateTimeFormatter.ofPattern("MM/dd/yyyy");
|
||||
|
||||
public Logger () {
|
||||
|
||||
}
|
||||
|
||||
public static void LOG (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.LOG, bot, message);
|
||||
}
|
||||
|
||||
public static void DEBUG (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.DEBUG, bot, message);
|
||||
}
|
||||
|
||||
public static void ERROR (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.ERROR, bot, message);
|
||||
}
|
||||
|
||||
public static void WARN (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.WARN, bot, message);
|
||||
}
|
||||
|
||||
public static void COMMAND (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.COMMAND, bot, message);
|
||||
}
|
||||
|
||||
public static void RECONNECT (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.RECONNECT, bot, message);
|
||||
}
|
||||
|
||||
public static void INFO (Bot bot, String message) {
|
||||
new Logger().prefix(LoggerType.INFO, bot, message);
|
||||
}
|
||||
|
||||
public Component getLoggerType (LoggerType type) {
|
||||
Component logType = null;
|
||||
switch (type) {
|
||||
case LoggerType.LOG -> logType = Component.text("LOG").color(NamedTextColor.GOLD);
|
||||
case LoggerType.COMMAND -> logType = Component.text("COMMAND").color(NamedTextColor.GREEN);
|
||||
case LoggerType.ERROR -> logType = Component.text("ERROR").color(NamedTextColor.DARK_RED);
|
||||
case LoggerType.WARN -> logType = Component.text("WARN").color(NamedTextColor.YELLOW);
|
||||
case LoggerType.INFO -> logType = Component.text("INFO").color(NamedTextColor.DARK_GREEN);
|
||||
case LoggerType.RECONNECT -> logType = Component.text("RECONNECT").color(NamedTextColor.AQUA);
|
||||
case LoggerType.DEBUG -> logType = Component.text("DEBUG").color(NamedTextColor.GOLD);
|
||||
}
|
||||
return logType;
|
||||
}
|
||||
|
||||
private void prefix (LoggerType loggerType, @Nullable Bot bot, String message) {
|
||||
Component component;
|
||||
Component host;
|
||||
|
||||
ZoneId timezone = ZoneId.of("America/Chicago");
|
||||
ZonedDateTime zoneDate = ZonedDateTime.now(timezone);
|
||||
LocalDate date = zoneDate.toLocalDate();
|
||||
LocalTime time = zoneDate.toLocalTime();
|
||||
|
||||
Component type = getLoggerType(loggerType);
|
||||
|
||||
if (bot == null) host = Component.text("NitoriBot Jar").color(NamedTextColor.BLUE);
|
||||
else host = Component.text(bot.options.host + ":" + bot.options.port).color(NamedTextColor.BLUE);
|
||||
|
||||
component = Component.translatable(
|
||||
"[%s %s %s] [%s] [%s] %s",
|
||||
Component.translatable(formatTime.format(time)).color(NamedTextColor.BLUE),
|
||||
Component.translatable(formatDate.format(date)).color(NamedTextColor.BLUE),
|
||||
type,
|
||||
Component.translatable(Thread.currentThread().getName()).color(NamedTextColor.BLUE),
|
||||
host,
|
||||
Component.translatable(message).color(NamedTextColor.WHITE)
|
||||
).color(NamedTextColor.DARK_BLUE);
|
||||
|
||||
String log = ComponentUtil.componentToAnsi(component);
|
||||
|
||||
if (bot == null) System.out.println(log);
|
||||
else Main.console.reader.printAbove(log);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.logger;
|
||||
|
||||
public enum LoggerType {
|
||||
LOG, DEBUG, INFO, COMMAND, WARN, ERROR, RECONNECT,
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Config;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ParsedChatType;
|
||||
@@ -13,10 +13,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatCommandHandlerModule implements Listener {
|
||||
private @NotNull final Bot bot;
|
||||
private @NotNull final NitoriBot bot;
|
||||
private @NotNull final Config config;
|
||||
|
||||
public ChatCommandHandlerModule (Bot bot) {
|
||||
public ChatCommandHandlerModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
this.config = bot.config;
|
||||
|
||||
|
||||
+29
-10
@@ -1,6 +1,9 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.ChatAttestation;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.MessagingEntrypointImpl;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatattestation.util.SigningResult;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.chatparsers.KaboomChatParser;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatTranslationsData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatType;
|
||||
@@ -17,17 +20,15 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.Clientbound
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.ServerboundChatPacket;
|
||||
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public class ChatModule implements Listener {
|
||||
public final List<ParseChatData> chatParsers;
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
|
||||
public ChatModule (Bot bot) {
|
||||
public ChatModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
this.chatParsers = List.of(new KaboomChatParser(bot));
|
||||
@@ -37,9 +38,10 @@ public class ChatModule implements Listener {
|
||||
|
||||
@Override
|
||||
public void packetReceived (Packet packet) {
|
||||
MessagingEntrypointImpl messagingEntrypoint = new MessagingEntrypointImpl();
|
||||
switch (packet) {
|
||||
case ClientboundSystemChatPacket p -> systemChat(p);
|
||||
case ClientboundPlayerChatPacket p -> playerChat(p);
|
||||
case ClientboundPlayerChatPacket p -> playerChat(messagingEntrypoint, p);
|
||||
case ClientboundDisguisedChatPacket p -> disguisedChat(p);
|
||||
default -> {
|
||||
}
|
||||
@@ -78,11 +80,19 @@ public class ChatModule implements Listener {
|
||||
message = Component.translatable(parseChatTypes, targetUsername, getMessage);
|
||||
}
|
||||
|
||||
UUID uuid = bot.players.getDisplayName(targetUsername).profile.getId();
|
||||
String username = bot.players.getDisplayName(targetUsername).profile.getName();
|
||||
|
||||
/*SigningStatus result = ChatAttestation.getSigningStatus(
|
||||
ComponentUtil.componentToString(message),
|
||||
bot.players.getDisplayName(targetUsername).profile.getId(),
|
||||
|
||||
);*/
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.disguisedChatReceived(message);
|
||||
}
|
||||
|
||||
|
||||
parseMessage(
|
||||
ChatType.DISGUISED,
|
||||
message,
|
||||
@@ -96,12 +106,21 @@ public class ChatModule implements Listener {
|
||||
|
||||
}
|
||||
|
||||
public void playerChat (ClientboundPlayerChatPacket packet) {
|
||||
public void playerChat (MessagingEntrypointImpl messagingEntrypoint, ClientboundPlayerChatPacket packet) {
|
||||
final Component unsignedContent = packet.getUnsignedContent();
|
||||
final Component content = Component.text(packet.getContent());
|
||||
|
||||
SigningResult result = ChatAttestation.getSigningStatus(
|
||||
packet.getContent(),
|
||||
packet.getSender(),
|
||||
ComponentUtil.componentToString(packet.getName())
|
||||
);
|
||||
|
||||
//bot.chat.tellraw("@a", Component.text(result.toString()));
|
||||
|
||||
for (Listener listener : bot.listenerManager.listeners) {
|
||||
listener.playerChatReceived(unsignedContent);
|
||||
listener.chatReceived(ChatType.PLAYER, result.status(), unsignedContent);
|
||||
}
|
||||
|
||||
parseMessage(
|
||||
|
||||
+62
-33
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.CommandCoreAreaData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
@@ -23,22 +23,27 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.inventory.S
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CommandCoreModule implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
public Vector3i position;
|
||||
public Vector3i itemPosition;
|
||||
public final CommandCoreAreaData area;
|
||||
public Vector3i lastBlockPosition;
|
||||
public List<Component> cmdBlockOutputs = new ArrayList<>();
|
||||
public Vector3i currentBlockRelative = Vector3i.from(
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
|
||||
public CommandCoreModule (Bot bot) {
|
||||
public CommandCoreModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
this.area = new CommandCoreAreaData(
|
||||
Vector3i.from(
|
||||
@@ -127,7 +132,7 @@ public class CommandCoreModule implements Listener {
|
||||
bot.session.send(new ServerboundSetCreativeModeSlotPacket(
|
||||
(short) 36,
|
||||
new ItemStack(
|
||||
482,
|
||||
bot.registry.getBlockRegistry("minecraft:command_block").itemId,
|
||||
64,
|
||||
dataComponents
|
||||
)
|
||||
@@ -147,7 +152,7 @@ public class CommandCoreModule implements Listener {
|
||||
0.5f,
|
||||
0.5f,
|
||||
0.5f,
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
420
|
||||
));
|
||||
@@ -160,11 +165,11 @@ public class CommandCoreModule implements Listener {
|
||||
true
|
||||
);
|
||||
|
||||
Vector3i pos = Vector3i.from(
|
||||
/*Vector3i pos = Vector3i.from(
|
||||
itemPosition.getX(),
|
||||
itemPosition.getY(),
|
||||
itemPosition.getZ()
|
||||
);
|
||||
);*/
|
||||
/*bot.world.getBlock(pos).thenApply((packet) -> {
|
||||
try {
|
||||
@Nullable NbtMap nbt = packet.getNbt();
|
||||
@@ -274,7 +279,11 @@ public class CommandCoreModule implements Listener {
|
||||
incrementCurrentBlock();
|
||||
}
|
||||
|
||||
public Component runTrackedWithTellraw (String tag, String selector, String command) {
|
||||
public Component runTrackedWithTellraw (
|
||||
String tag,
|
||||
String selector,
|
||||
String command
|
||||
) {
|
||||
commandBlock(
|
||||
currentBlock(),
|
||||
command,
|
||||
@@ -305,8 +314,9 @@ public class CommandCoreModule implements Listener {
|
||||
|
||||
return component;
|
||||
}
|
||||
/*public void runTrackedWithPacket (String command) {
|
||||
List<NbtMap> output = new ArrayList<>();
|
||||
|
||||
public Component runTrackedWithPacket (String command) {
|
||||
// List<NbtMap> output = new ArrayList<>();
|
||||
commandBlock(
|
||||
currentBlock(),
|
||||
command,
|
||||
@@ -315,34 +325,53 @@ public class CommandCoreModule implements Listener {
|
||||
true
|
||||
);
|
||||
|
||||
CompletableFuture.runAsync(
|
||||
lastBlockPosition = currentBlock();
|
||||
|
||||
incrementCurrentBlock();
|
||||
//AtomicReference<Component> output = new AtomicReference<>();
|
||||
|
||||
var runPacketAtDelay = CompletableFuture.supplyAsync(
|
||||
() -> {
|
||||
bot.world.getBlock(currentBlock()).thenApplyAsync((packet) -> {
|
||||
try {
|
||||
|
||||
if (packet.getTransactionId() == bot.world.transactionId) {
|
||||
NbtMap nbt = packet.getNbt();
|
||||
|
||||
Object json = packet.getNbt().get("LastOutput");
|
||||
if (json != null) {
|
||||
JsonObject nbtParsed = NbtMapToJson.INSTANCE.convert((NbtMap) json);
|
||||
System.out.println(nbtParsed.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return packet;
|
||||
});
|
||||
|
||||
// System.out.println(cmdBlockOutput.join());
|
||||
// incrementCurrentBlock();
|
||||
//return null;
|
||||
CompletableFuture<Component> output = null;
|
||||
try {
|
||||
output = bot.world.getBlock(lastBlockPosition);
|
||||
} catch (Exception ignore) {}
|
||||
return output;
|
||||
},
|
||||
CompletableFuture.delayedExecutor(
|
||||
50,
|
||||
TimeUnit.MILLISECONDS
|
||||
)
|
||||
);
|
||||
}*/
|
||||
|
||||
//AtomicReference<Component> output = new AtomicReference<>();
|
||||
var executor = bot.executor.submit(() -> {
|
||||
Component output = null;
|
||||
try {
|
||||
cmdBlockOutputs.add(runPacketAtDelay.join().get());
|
||||
System.out.println(cmdBlockOutputs.toString());
|
||||
|
||||
//System.out.println(runPacketAtDelay.join().get());
|
||||
//output = runPacketAtDelay.join().get();
|
||||
} catch (Exception e) {}
|
||||
//System.out.println(output);
|
||||
return output;
|
||||
});
|
||||
|
||||
return null;
|
||||
|
||||
// System.out.println(output.toString());
|
||||
// System.out.println(output);
|
||||
//runPacketAtDelay.join().join();
|
||||
//return output.get();
|
||||
|
||||
/*return CompletableFuture.supplyAsync(
|
||||
() -> (Component) bot.executor.submit(() -> bot.world.getBlock(currentBlock())),
|
||||
CompletableFuture.delayedExecutor(
|
||||
50,
|
||||
TimeUnit.MILLISECONDS
|
||||
)
|
||||
);*/
|
||||
// System.out.println(output.toString());
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,25 +1,26 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandContext;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandError;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandInfo;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.command.CommandSource;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.Public.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.commands.trusted.ReconnectCommand;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ErrorToString;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class CommandManagerModule {
|
||||
public final List<CommandInfo> commands = new ArrayList<>();
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CommandManagerModule.class);
|
||||
|
||||
public CommandManagerModule (Bot bot) throws IOException {
|
||||
public CommandManagerModule (NitoriBot bot) throws IOException {
|
||||
this.bot = bot;
|
||||
registerCommand(new EchoCommand());
|
||||
registerCommand(new HelpCommand());
|
||||
@@ -66,8 +67,7 @@ public class CommandManagerModule {
|
||||
source.sendFeedback(bot, error.message());
|
||||
} catch (Exception error) {
|
||||
source.sendFeedback(bot, Component.translatable("command.failed").color(NamedTextColor.DARK_RED));
|
||||
String Error = ErrorToString.errorToString(error);
|
||||
Logger.ERROR(bot, Error);
|
||||
LOGGER.error("{}", CommandManagerModule.class, error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -11,9 +11,9 @@ import java.util.List;
|
||||
|
||||
public class CommandSpyModule implements Listener {
|
||||
private static final String SLASH = "/";
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
|
||||
public CommandSpyModule (Bot bot) {
|
||||
public CommandSpyModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Main;
|
||||
import org.jline.reader.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ConsoleModule implements Completer {
|
||||
private static final List<Bot> servers = Main.Bots;
|
||||
|
||||
public final LineReader reader;
|
||||
|
||||
public final String server = "all";
|
||||
|
||||
public ConsoleModule () {
|
||||
this.reader = LineReaderBuilder.builder().completer(this).build();
|
||||
|
||||
Main.executorService.submit(
|
||||
() -> {
|
||||
while (true) {
|
||||
try {
|
||||
String line;
|
||||
|
||||
line = reader.readLine(String.format("[%s] > ", this.server));
|
||||
|
||||
handleLine(line);
|
||||
} catch (Exception _) {
|
||||
}
|
||||
}
|
||||
}, "Console Thread"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete (LineReader reader, ParsedLine line, List<Candidate> candidates) {
|
||||
|
||||
}
|
||||
|
||||
private void handleLine (String line) {
|
||||
for (Bot bot : servers) {
|
||||
if (line.equals(bot.config.console.prefix + "kill")) System.exit(0);
|
||||
bot.chat.send(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ExtrasMessagingModule {
|
||||
private NitoriBot bot;
|
||||
public final List<String> channels = new ArrayList<>();
|
||||
|
||||
public ExtrasMessagingModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
}
|
||||
}
|
||||
+18
-7
@@ -1,15 +1,18 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.logger.Logger;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoggingModule implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingModule.class);
|
||||
|
||||
public LoggingModule (Bot bot) {
|
||||
public LoggingModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
@@ -31,9 +34,17 @@ public class LoggingModule implements Listener {
|
||||
}
|
||||
|
||||
public void handleMessages (Component _message) {
|
||||
Component host = Component.text(
|
||||
String.format(
|
||||
"[%s:%s] ",
|
||||
bot.options.host,
|
||||
bot.options.port
|
||||
)
|
||||
).color(NamedTextColor.BLUE);
|
||||
Component component = Component.empty().append(host).append(_message);
|
||||
String message = ComponentUtil.componentToAnsi(component);
|
||||
|
||||
String message = ComponentUtil.componentToAnsi(_message);
|
||||
//if (host.equals("kaboom.pw")) return;
|
||||
Logger.LOG(bot, message);
|
||||
bot.logger.log(message);
|
||||
//LOGGER.info(message);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PingServerData;
|
||||
import org.geysermc.mcprotocollib.auth.SessionService;
|
||||
import org.geysermc.mcprotocollib.network.ClientSession;
|
||||
@@ -22,11 +22,11 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
public class MCServerModule {
|
||||
public final SessionService sessionService = new SessionService();
|
||||
public final MinecraftProtocol protocol = new MinecraftProtocol();
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
private final List<SkinPart> skinParts = new ArrayList<>();
|
||||
public ClientSession client;
|
||||
|
||||
public MCServerModule (Bot bot) {
|
||||
public MCServerModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.PlayerProfileData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -22,11 +22,11 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerListModule implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
public final List<PlayerProfileData> list = new ArrayList<>();
|
||||
|
||||
|
||||
public PlayerListModule (Bot bot) {
|
||||
public PlayerListModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import org.cloudburstmc.math.vector.Vector3d;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
@@ -13,7 +13,7 @@ import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PositionModule implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
|
||||
public ScheduledFuture<?> timer;
|
||||
public Vector3d positionData;
|
||||
@@ -21,7 +21,7 @@ public class PositionModule implements Listener {
|
||||
private int x;
|
||||
private int z;
|
||||
|
||||
public PositionModule (Bot bot) {
|
||||
public PositionModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
|
||||
+87
-6
@@ -1,24 +1,35 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import com.google.gson.*;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.ChatTranslationsData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.blocks.BlockRegistries;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.world.DimensionData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundRegistryDataPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class RegistryModule implements Listener {
|
||||
public final List<ChatTranslationsData> chatTypes = new ArrayList<>();
|
||||
public final List<DimensionData> dimensions = new ArrayList<>();
|
||||
private final Gson gson = new Gson();
|
||||
private static final Gson GSON = new Gson();
|
||||
public final List<BlockRegistries> blocks = new ArrayList<>();
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryModule.class);
|
||||
|
||||
public RegistryModule (Bot bot) {
|
||||
public RegistryModule (NitoriBot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
parseBlockRegistries();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,12 +37,81 @@ public class RegistryModule implements Listener {
|
||||
if (packet instanceof ClientboundRegistryDataPacket) packetReceived((ClientboundRegistryDataPacket) packet);
|
||||
}
|
||||
|
||||
public BlockRegistries getBlockRegistry (String block) {
|
||||
for (BlockRegistries registry : blocks) {
|
||||
if (registry.block.equals(block)) return registry;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void parseBlockRegistries () {
|
||||
final List<BlockRegistries> registries = new ArrayList<>();
|
||||
final List<BlockRegistries> blockRegistries = new ArrayList<>();
|
||||
final Reader blockRegistryReader = new InputStreamReader(RegistryModule.class.getResourceAsStream("/blocks.json"));
|
||||
final Reader registriesReader = new InputStreamReader(RegistryModule.class.getResourceAsStream("/registries.json"));
|
||||
final Map<?, ?> map = GSON.fromJson(
|
||||
blockRegistryReader,
|
||||
Map.class
|
||||
);
|
||||
for (Map.Entry<?, ?> entry : map.entrySet()) {
|
||||
String json = GSON.toJson(entry.getValue());
|
||||
final BlockRegistries parsed = GSON.fromJson(
|
||||
json,
|
||||
BlockRegistries.class
|
||||
);
|
||||
parsed.block = entry.getKey().toString();
|
||||
registries.add(parsed);
|
||||
}
|
||||
final JsonElement parseRegistries = JsonParser.parseReader(registriesReader);
|
||||
final JsonElement itemArray = parseRegistries.getAsJsonObject().get("minecraft:item").getAsJsonObject().get("entries");
|
||||
final JsonElement blockArray = parseRegistries.getAsJsonObject().get("minecraft:block").getAsJsonObject().get("entries");
|
||||
final Map<?, ?> blockEntrySet = GSON.fromJson(
|
||||
blockArray,
|
||||
Map.class
|
||||
);
|
||||
final Map<?, ?> itemEntrySet = GSON.fromJson(
|
||||
itemArray,
|
||||
Map.class
|
||||
);
|
||||
|
||||
|
||||
for (Map.Entry<?, ?> entry : blockEntrySet.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
for (BlockRegistries block : registries) {
|
||||
final Pattern pattern = Pattern.compile("\\{protocol_id=(\\d+(?:\\.\\d+)?)\\}");
|
||||
final Matcher matcher = pattern.matcher(entry.getValue().toString());
|
||||
if (matcher.find()) {
|
||||
if (block.block.equals(key)) {
|
||||
block.blockId = (int) Float.parseFloat(matcher.group(1));
|
||||
blockRegistries.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<?, ?> entry : itemEntrySet.entrySet()) {
|
||||
final String key = entry.getKey().toString();
|
||||
for (BlockRegistries block : blockRegistries) {
|
||||
final Pattern pattern = Pattern.compile("\\{protocol_id=(\\d+(?:\\.\\d+)?)\\}");
|
||||
final Matcher matcher = pattern.matcher(entry.getValue().toString());
|
||||
|
||||
if (matcher.find()) {
|
||||
if (block.block.equals(key)) {
|
||||
block.itemId = (int) Float.parseFloat(matcher.group(1));
|
||||
blocks.add(block);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void packetReceived (ClientboundRegistryDataPacket packet) {
|
||||
String getRegistry = packet.getRegistry().asString();
|
||||
for (RegistryEntry entry : packet.getEntries()) {
|
||||
switch (getRegistry) {
|
||||
case "minecraft:chat_type" -> {
|
||||
ChatTranslationsData parsed = gson.fromJson(
|
||||
ChatTranslationsData parsed = GSON.fromJson(
|
||||
entry.getData().toString(),
|
||||
ChatTranslationsData.class
|
||||
);
|
||||
@@ -41,7 +121,8 @@ public class RegistryModule implements Listener {
|
||||
case "minecraft:dimension_type" -> {
|
||||
|
||||
}
|
||||
default -> {}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,9 +1,9 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.entity.GamemodeSelfcare;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.entity.PermissionSelfcare;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.selfcare.entity.GamemodeSelfcare;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.selfcare.entity.PermissionSelfcare;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
|
||||
@@ -14,7 +14,7 @@ import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfcareModule implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
public ScheduledFuture<?> timer;
|
||||
public PermissionSelfcare permission;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SelfcareModule implements Listener {
|
||||
|
||||
public int entityId;
|
||||
|
||||
public SelfcareModule (Bot bot) {
|
||||
public SelfcareModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
loadSelfcare();
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundCommandSuggestionsPacket;
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TabCompleteModule implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
|
||||
private final Map<Integer, CompletableFuture<ClientboundCommandSuggestionsPacket>> transactions = new HashMap<>();
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TabCompleteModule implements Listener {
|
||||
transactions.get(packet.getTransactionId()).complete(packet);
|
||||
}
|
||||
|
||||
public TabCompleteModule (Bot bot) {
|
||||
public TabCompleteModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.ComponentUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -11,7 +11,7 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.Clie
|
||||
public class TextDisplayModule implements Listener {
|
||||
private static final int TEXT_DISPLAY_ENTITY_ID = 32;
|
||||
|
||||
public TextDisplayModule (Bot bot) {
|
||||
public TextDisplayModule (NitoriBot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
|
||||
+63
-14
@@ -1,10 +1,14 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.modules;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.world.ChunkPosData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.data.world.DimensionData;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.util.NbtMapToJson;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.cloudburstmc.math.vector.Vector3i;
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
|
||||
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.ClientboundLevelChunkWithLightPacket;
|
||||
@@ -15,13 +19,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class WorldModule implements Listener {
|
||||
private final @NotNull Bot bot;
|
||||
private final @NotNull NitoriBot bot;
|
||||
private final Map<Integer, CompletableFuture<ClientboundTagQueryPacket>> transactions = new HashMap<>();
|
||||
public int transactionId = (int) Math.floor(Math.random() * 69);
|
||||
|
||||
public WorldModule (Bot bot) {
|
||||
public WorldModule (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
bot.listenerManager.addListener(this);
|
||||
@@ -43,27 +48,71 @@ public class WorldModule implements Listener {
|
||||
}
|
||||
|
||||
private void respawn (ClientboundRespawnPacket packet) {
|
||||
// currentDimension = String.valueOf(packet.getCommonPlayerSpawnInfo().getWorldName());
|
||||
// currentDimension = String.valueOf(packet.getCommonPlayerSpawnInfo().getWorldName());
|
||||
}
|
||||
|
||||
private void addChunks (ClientboundLevelChunkWithLightPacket packet) {
|
||||
ChunkPosData pos = new ChunkPosData(packet.getX(), packet.getX());
|
||||
ChunkPosData pos = new ChunkPosData(
|
||||
packet.getX(),
|
||||
packet.getX()
|
||||
);
|
||||
|
||||
for (DimensionData dimension : bot.registry.dimensions) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<ClientboundTagQueryPacket> getBlock (Vector3i pos) {
|
||||
bot.session.send(
|
||||
new ServerboundBlockEntityTagQueryPacket(
|
||||
transactionId,
|
||||
pos
|
||||
)
|
||||
);
|
||||
public CompletableFuture<Component> getBlock (Vector3i pos) throws ExecutionException, InterruptedException {
|
||||
bot.session.send(new ServerboundBlockEntityTagQueryPacket(
|
||||
transactionId,
|
||||
pos
|
||||
));
|
||||
final CompletableFuture<ClientboundTagQueryPacket> future = new CompletableFuture<>();
|
||||
transactions.put(transactionId, future);
|
||||
transactions.put(
|
||||
transactionId,
|
||||
future
|
||||
);
|
||||
|
||||
|
||||
return transactions.get(transactionId).thenApplyAsync((packet) -> {
|
||||
Component nbtOutput = null;
|
||||
try {
|
||||
if (packet.getTransactionId() == bot.world.transactionId) {
|
||||
NbtMap nbt = packet.getNbt();
|
||||
|
||||
Object json = packet.getNbt().get("LastOutput");
|
||||
if (json != null) {
|
||||
nbtOutput = GsonComponentSerializer.gson().deserialize(
|
||||
NbtMapToJson.INSTANCE.convert(
|
||||
(NbtMap) packet.getNbt().get("LastOutput")
|
||||
).get("extra").toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return nbtOutput;
|
||||
});
|
||||
|
||||
return future;
|
||||
}
|
||||
}
|
||||
/*
|
||||
JsonObject nbtParsed = null;
|
||||
try {
|
||||
|
||||
if (packet.getTransactionId() == bot.world.transactionId) {
|
||||
NbtMap nbt = packet.getNbt();
|
||||
|
||||
Object json = packet.getNbt().get("LastOutput");
|
||||
if (json != null) {
|
||||
nbtParsed = NbtMapToJson.INSTANCE.convert((NbtMap) packet.getNbt().get("LastOutput.extra"));
|
||||
System.out.println(nbtParsed.toString());
|
||||
// System.out.println(nbtParsed.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
return nbtParsed;
|
||||
*/
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.entity;
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.selfcare.entity;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.GameMode;
|
||||
@@ -11,7 +11,7 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.level.Clien
|
||||
public class GamemodeSelfcare implements Listener {
|
||||
public int gamemode = 1;
|
||||
|
||||
public GamemodeSelfcare (Bot bot) {
|
||||
public GamemodeSelfcare (NitoriBot bot) {
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.entity;
|
||||
package land.chipmunk.parker2991.nitoribot.nightofnights.selfcare.entity;
|
||||
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.Bot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.NitoriBot;
|
||||
import land.chipmunk.parker2991.nitoribot.nightofnights.listeners.Listener;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.EntityEvent;
|
||||
@@ -8,10 +8,10 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.Clie
|
||||
|
||||
|
||||
public class PermissionSelfcare implements Listener {
|
||||
private final Bot bot;
|
||||
private final NitoriBot bot;
|
||||
public int level;
|
||||
|
||||
public PermissionSelfcare (Bot bot) {
|
||||
public PermissionSelfcare (NitoriBot bot) {
|
||||
this.bot = bot;
|
||||
bot.listenerManager.addListener(this);
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
"color": "blue"
|
||||
}
|
||||
],
|
||||
"build": "5312",
|
||||
"build": "5313",
|
||||
"versionReleaseDate": "N\\A",
|
||||
"initialBotRelease": "11/22/22"
|
||||
},
|
||||
@@ -71,6 +71,10 @@
|
||||
{
|
||||
"name": "Werkku",
|
||||
"reason": "v9.0.0 ComponentUtil functions / v9.0.0 command sending"
|
||||
},
|
||||
{
|
||||
"name": "hcesaropz",
|
||||
"reason": "v9.0.0 logger"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="land.chipmunk.parker2991.nitoribot.nightofnights.console.JlineAppender">
|
||||
<encoder>
|
||||
<pattern>
|
||||
%blue([%d{yyyy-MM-dd HH:mm:ss a}]) %blue([%-5thread]) %blue([%highlight(%-5X{customLevel:-INFO}) %blue(])) %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user