1
0
Fork 0
mirror of https://github.com/Miasmusa/Shadow.git synced 2025-03-25 03:19:42 -04:00

irc prototype that is actually usable with the new launcher upcoming

This commit is contained in:
0x3C50 2022-04-27 22:44:20 +02:00
parent 4cf4116bb0
commit 4d10a1c9ce
4 changed files with 169 additions and 3 deletions
build.gradle
src/main/java/net/shadow/client

View file

@ -32,7 +32,8 @@ loom {
}
dependencies {
//to change the versions see the gradle.properties file
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
@ -50,12 +51,13 @@ dependencies {
// modImplementation ("net.fabricmc.fabric-api:fabric-resource-loader:0.1.0")
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
impl("meteordevelopment:discord-ipc:1.1")
impl(name: "xauthlib-1.0.0")
impl 'org.java-websocket:Java-WebSocket:1.5.3'
configurations.impl.dependencies.each {
implementation(it)

View file

@ -57,6 +57,7 @@ import net.shadow.client.feature.module.impl.misc.AntiOffhandCrash;
import net.shadow.client.feature.module.impl.misc.AntiPacketKick;
import net.shadow.client.feature.module.impl.misc.ClientSettings;
import net.shadow.client.feature.module.impl.misc.DiscordRPC;
import net.shadow.client.feature.module.impl.misc.IRC;
import net.shadow.client.feature.module.impl.misc.InfChatLength;
import net.shadow.client.feature.module.impl.misc.ItemPuke;
import net.shadow.client.feature.module.impl.misc.MoreChatHistory;
@ -345,6 +346,8 @@ public class ModuleRegistry {
registerModule(ItemPuke.class);
registerModule(EntityCrash.class);
registerModule(IRC.class);
rebuildSharedModuleList();
}

View file

@ -0,0 +1,76 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.feature.module.impl.misc;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.shadow.client.feature.module.Module;
import net.shadow.client.feature.module.ModuleType;
import net.shadow.client.helper.IRCWebSocket;
import net.shadow.client.helper.event.EventListener;
import net.shadow.client.helper.event.EventType;
import net.shadow.client.helper.event.events.PacketEvent;
import net.shadow.client.helper.util.Utils;
import java.net.URI;
public class IRC extends Module {
static final String websocketUrl = "ws://localhost:8080/irc";
static String ircPrefix = "#";
IRCWebSocket wsS;
static String authToken = System.getenv("SHADOW_API_KEY");
public IRC() {
super("IRC", "Chat with others using the client", ModuleType.MISC);
}
@EventListener(type= EventType.PACKET_SEND)
void onPackSent(PacketEvent pe) {
if (pe.getPacket() instanceof ChatMessageC2SPacket msg) {
String m = msg.getChatMessage();
if (m.startsWith(ircPrefix)) {
pe.setCancelled(true);
wsS.send(m.substring(ircPrefix.length()).trim());
}
}
}
@Override
public void tick() {
}
@Override
public void enable() {
if (authToken == null) {
Utils.Logging.error("Cannot use IRC because you didn't use the launcher to launch shadow.");
setEnabled(false);
return;
}
this.wsS = new IRCWebSocket(URI.create(websocketUrl),authToken,()-> {
this.wsS = null;
this.setEnabled(false);
});
this.wsS.connect();
}
@Override
public void disable() {
if (this.wsS != null) this.wsS.close();
}
@Override
public String getContext() {
return null;
}
@Override
public void onWorldRender(MatrixStack matrices) {
}
@Override
public void onHudRender() {
}
}

View file

@ -0,0 +1,85 @@
/*
* Copyright (c) Shadow client, 0x150, Saturn5VFive 2022. All rights reserved.
*/
package net.shadow.client.helper;
import com.google.gson.Gson;
import lombok.AllArgsConstructor;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.shadow.client.ShadowMain;
import net.shadow.client.helper.util.Utils;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;
import java.net.URI;
import java.util.Map;
public class IRCWebSocket extends WebSocketClient {
@AllArgsConstructor
public static
class Packet {
String id;
Map<String, Object> data;
public String toRawPacket() {
return new Gson().toJson(this);
}
@Override
public String toString() {
return "Packet{" +
"id='" + id + '\'' +
", data=" + data +
'}';
}
}
String authToken;
Runnable onClose;
public IRCWebSocket(URI serverUri, String authToken, Runnable onClose) {
super(serverUri, Map.of("Authorization", authToken));
this.authToken = authToken;
this.onClose = onClose;
}
@Override
public void onOpen(ServerHandshake handshakedata) {
Utils.Logging.success("Connected to IRC");
}
@Override
public void onMessage(String message) {
Packet p = new Gson().fromJson(message, Packet.class);
switch(p.id) {
case "message" -> {
String uname = p.data.get("who").toString();
String msg = p.data.get("message").toString();
ShadowMain.client.player.sendMessage(Text.of(String.format("%s[IRC] %s[%s] %s", Formatting.AQUA, Formatting.BLUE, uname, msg)), false);
}
case "userJoined" -> {
String uname = p.data.get("who").toString();
ShadowMain.client.player.sendMessage(Text.of(String.format("%s[IRC] %s%s joined the IRC", Formatting.AQUA, Formatting.GREEN, uname)), false);
}
case "userLeft" -> {
String uname = p.data.get("who").toString();
ShadowMain.client.player.sendMessage(Text.of(String.format("%s[IRC] %s%s left the IRC", Formatting.AQUA, Formatting.RED, uname)), false);
}
case "connectFailed" -> {
String reason = p.data.get("reason").toString();
Utils.Logging.error("Failed to establish connection, server said: "+reason);
}
}
}
@Override
public void onClose(int code, String reason, boolean remote) {
Utils.Logging.error("IRC Disconnected");
this.onClose.run();
}
@Override
public void onError(Exception ex) {
}
}