Skip to content

Commit

Permalink
irc
Browse files Browse the repository at this point in the history
  • Loading branch information
soshimee committed Oct 11, 2024
1 parent 180b998 commit 4acac2f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class Settings {
})
enabled = true;

@SwitchProperty({
name: "IRC",
description: "IRC for meowing",
category: "General"
})
ircEnabled = true;

@SwitchProperty({
name: "Hide lobby join messages",
description: "Hide join messages that spam your chat in lobby",
Expand Down
3 changes: 2 additions & 1 deletion features/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Settings from "../config";
import irc from "./irc";
import bloodHelper from "./bloodHelper";
import hideLobbyJoinMessages from "./hideLobbyJoinMessages";
import partyInviteNotification from "./partyInviteNotification";
Expand Down Expand Up @@ -27,7 +28,7 @@ import itemHighlight from "./itemHighlight";
import padTickTimer from "./padTickTimer";
import showTerminalClicks from "./showTerminalClicks";

export const features = { bloodHelper, hideLobbyJoinMessages, partyInviteNotification, catSounds, mute, betterPartyFinder, melodyAlert, deathAlert, mimicRelay, sbeBloodFix, p3StartTimer, i4Helper, shadowAssassinAlert, partyFinderNote, partyFinderAutoKick, invincibilityTimer, goldorTickTimer, deathTickTimer, leapHelper, positionalMessages, rightClickAnimation, partyCommands, terminals, wardrobeHelper, itemHighlight, padTickTimer, showTerminalClicks };
export const features = { irc, bloodHelper, hideLobbyJoinMessages, partyInviteNotification, catSounds, mute, betterPartyFinder, melodyAlert, deathAlert, mimicRelay, sbeBloodFix, p3StartTimer, i4Helper, shadowAssassinAlert, partyFinderNote, partyFinderAutoKick, invincibilityTimer, goldorTickTimer, deathTickTimer, leapHelper, positionalMessages, rightClickAnimation, partyCommands, terminals, wardrobeHelper, itemHighlight, padTickTimer, showTerminalClicks };

const featureState = {};
Object.keys(features).forEach(featureName => featureState[featureName] = false);
Expand Down
95 changes: 95 additions & 0 deletions features/irc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import WebSocket from "../../../WebSocket";
import request from "../../../requestV2";
import Async from "../../../Async";

const UUID = Java.type("java.util.UUID");
const C01PacketChatMessage = Java.type("net.minecraft.network.play.client.C01PacketChatMessage");
const ChatComponentText = Java.type("net.minecraft.util.ChatComponentText");

let enabled = false;
let reconnecting = false;
let ws;

const trigger = register("packetSent", (packet, event) => {
const message = packet.func_149439_c();
if (!message.startsWith("#")) return;
try {
ws.send(message.substring(1).replaceAll(/&([0-9a-fk-o])/g, "§$1"));
} catch (error) {
ChatLib.chat("§8[§bIRC§8] §7Failed to send message.");
}
cancel(event);
}).setFilteredClass(C01PacketChatMessage).unregister();

const unloadTrigger = register("gameUnload", () => {
enabled = false;
ws?.close();
}).unregister();

function reset() {
ws = new WebSocket("wss://sa-irc.p-e.kr/ws");

ws.onOpen = () => {
reconnecting = false;
ChatLib.chat("§8[§bIRC§8] §7Connected.");
auth();
};

ws.onClose = () => {
if (!reconnecting) ChatLib.chat("§8[§bIRC§8] §7Disconnected.");
if (enabled) {
if (reconnecting) Async.schedule(reset, 10000);
else reset();
reconnecting = true;
}
};

ws.onError = () => {
if (enabled) Async.schedule(reset, 10000);
}

ws.onMessage = message => {
Client.getMinecraft().field_71439_g.func_145747_a(new ChatComponentText("§8[§bIRC§8] §f" + message));
};

ws.connect();
}

function auth() {
ChatLib.chat("§8[§bIRC§8] §7Authenticating...");
const token = Client.getMinecraft().func_110432_I().func_148254_d();
const uuid = Player.getUUID().replaceAll("-", "");
const svid = UUID.randomUUID().toString().replaceAll("-", "");
request({
url: "https://sessionserver.mojang.com/session/minecraft/join",
method: "POST",
body: {
accessToken: token,
selectedProfile: uuid,
serverId: svid
},
resolveWithFullResponse: true
}).then(response => {
if (response.statusCode === 204) ws.send("/auth " + Player.getName() + " " + svid);
else ChatLib.chat("§8[§bIRC§8] §7Failed to authenticate.");
}).catch(() => {
ChatLib.chat("§8[§bIRC§8] §7Failed to authenticate.");
});
}

export function enable() {
enabled = true;
trigger.register();
unloadTrigger.register();
reset();
ChatLib.chat("§8[§bIRC§8] §7Connecting...");
}

export function disable() {
enabled = false;
trigger.unregister();
unloadTrigger.unregister();
ws.close();
}

export default { enable, disable };
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "soshimeeaddons",
"description": "F7 on top",
"creator": "soshimee",
"version": "2.7.0",
"version": "2.8.0",
"entry": "index.js",
"requires": ["PromiseV2", "BloomCore", "fparser", "requestV2", "Vigilance", "PogData", "RenderLib"]
"requires": ["PromiseV2", "BloomCore", "fparser", "requestV2", "Vigilance", "PogData", "RenderLib", "WebSocket", "Async"]
}

0 comments on commit 4acac2f

Please sign in to comment.