forked from ChomeNS/chomens-bot-java
some more packets in voicechat IDK
This commit is contained in:
parent
89e3a62407
commit
bd4f565ae2
8 changed files with 140 additions and 5 deletions
|
@ -0,0 +1,26 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.data.voiceChat;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.util.FriendlyByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ClientGroup {
|
||||
@Getter private final UUID id;
|
||||
@Getter private final String name;
|
||||
@Getter private final boolean hasPassword;
|
||||
@Getter private final boolean persistent;
|
||||
@Getter private final GroupType type;
|
||||
|
||||
public static ClientGroup fromBytes(FriendlyByteBuf buf) {
|
||||
return new ClientGroup(
|
||||
buf.readUUID(),
|
||||
buf.readUtf(512),
|
||||
buf.readBoolean(),
|
||||
buf.readBoolean(),
|
||||
GroupType.values()[buf.readShort()]
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.data.voiceChat;
|
||||
|
||||
public enum GroupType {
|
||||
NORMAL,
|
||||
OPEN,
|
||||
ISOLATED
|
||||
}
|
|
@ -8,16 +8,22 @@ import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
|||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.voiceChat.ClientGroup;
|
||||
import land.chipmunk.chayapak.chomens_bot.data.voiceChat.RawUdpPacket;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.FriendlyByteBuf;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.InitializationData;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.NetworkMessage;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.customPayload.JoinGroupPacket;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.customPayload.SecretPacket;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.packets.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// most of these codes are from the simple voice chat mod itself including the other voicechat classes
|
||||
// i didn't implement mic yet because my goal is to make `/voicechat test` work with the bot
|
||||
// ALMOST ALL of these codes are from the simple voice chat mod itself including the other voicechat classes
|
||||
// mic packet exists but is never sent because i am too lazy to implement the player + evilbot already has a voicechat music player
|
||||
public class VoiceChatPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
|
@ -27,6 +33,8 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
|
||||
private boolean running = false;
|
||||
|
||||
@Getter private List<ClientGroup> groups = new ArrayList<>();
|
||||
|
||||
public VoiceChatPlugin(Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
|
@ -100,9 +108,36 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
}
|
||||
}
|
||||
}).start();
|
||||
} else if (_packet.getChannel().equals("voicechat:add_group")) {
|
||||
final byte[] bytes = _packet.getData();
|
||||
final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
|
||||
|
||||
final ClientGroup group = ClientGroup.fromBytes(buf);
|
||||
|
||||
groups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
public void joinGroup (String group, String password) {
|
||||
final ClientGroup[] clientGroups = groups
|
||||
.stream()
|
||||
.filter(eachGroup -> eachGroup.name().equals(group))
|
||||
.toArray(ClientGroup[]::new);
|
||||
|
||||
if (clientGroups.length == 0) throw new RuntimeException("Group " + group + " doesn't exist");
|
||||
|
||||
final ClientGroup clientGroup = clientGroups[0];
|
||||
|
||||
final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
|
||||
new JoinGroupPacket(clientGroup.id(), password).toBytes(buf);
|
||||
|
||||
bot.session().send(new ServerboundCustomPayloadPacket(
|
||||
"voicechat:set_group",
|
||||
buf.array()
|
||||
));
|
||||
}
|
||||
|
||||
public void sendToServer (NetworkMessage message) {
|
||||
try {
|
||||
socket.send(
|
||||
|
@ -144,6 +179,8 @@ public class VoiceChatPlugin extends Bot.Listener {
|
|||
public void disconnected(DisconnectedEvent event) {
|
||||
socket.close();
|
||||
|
||||
groups.clear();
|
||||
|
||||
running = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.voiceChat;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.data.voiceChat.Codec;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.packets.SecretPacket;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.customPayload.SecretPacket;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
|
@ -39,7 +39,7 @@ public class NetworkMessage {
|
|||
|
||||
static {
|
||||
packetRegistry = new HashMap<>();
|
||||
// packetRegistry.put((byte) 0x1, MicPacket.class);
|
||||
packetRegistry.put((byte) 0x1, MicPacket.class);
|
||||
// packetRegistry.put((byte) 0x2, PlayerSoundPacket.class);
|
||||
// packetRegistry.put((byte) 0x3, GroupSoundPacket.class);
|
||||
// packetRegistry.put((byte) 0x4, LocationSoundPacket.class);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.voiceChat.customPayload;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.util.FriendlyByteBuf;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.Packet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class JoinGroupPacket implements Packet<JoinGroupPacket> {
|
||||
@Getter private UUID group;
|
||||
@Getter private String password;
|
||||
|
||||
public JoinGroupPacket () {}
|
||||
|
||||
@Override
|
||||
public JoinGroupPacket fromBytes(FriendlyByteBuf buf) {
|
||||
group = buf.readUUID();
|
||||
if (buf.readBoolean()) {
|
||||
password = buf.readUtf(512);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(FriendlyByteBuf buf) {
|
||||
buf.writeUUID(group);
|
||||
buf.writeBoolean(password != null);
|
||||
if (password != null) {
|
||||
buf.writeUtf(password, 512);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.voiceChat.packets;
|
||||
package land.chipmunk.chayapak.chomens_bot.voiceChat.customPayload;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.data.voiceChat.Codec;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.FriendlyByteBuf;
|
|
@ -0,0 +1,31 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.voiceChat.packets;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.util.FriendlyByteBuf;
|
||||
import land.chipmunk.chayapak.chomens_bot.voiceChat.Packet;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class MicPacket implements Packet<MicPacket> {
|
||||
@Getter private byte[] data;
|
||||
@Getter private boolean whispering;
|
||||
@Getter private long sequenceNumber;
|
||||
|
||||
public MicPacket() {}
|
||||
|
||||
@Override
|
||||
public MicPacket fromBytes(FriendlyByteBuf buf) {
|
||||
MicPacket soundPacket = new MicPacket();
|
||||
soundPacket.data = buf.readByteArray();
|
||||
soundPacket.sequenceNumber = buf.readLong();
|
||||
soundPacket.whispering = buf.readBoolean();
|
||||
return soundPacket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(FriendlyByteBuf buf) {
|
||||
buf.writeByteArray(data);
|
||||
buf.writeLong(sequenceNumber);
|
||||
buf.writeBoolean(whispering);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue