Skip to content

Commit

Permalink
Merge pull request #364 from plasmoapp/v2.0.x
Browse files Browse the repository at this point in the history
v2.0.7
  • Loading branch information
Apehum committed Sep 11, 2023
2 parents 9d77afe + 65439ee commit 57ba68a
Show file tree
Hide file tree
Showing 52 changed files with 321 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public void log(String message, Object... params) {
if (!enabled) return;
logger.info(message, params);
}

public void warn(String message, Object... params) {
if (!enabled) return;
logger.warn(message, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface ServerAudioSource<S extends SourceInfo> extends AudioSource<S>

/**
* Marks source as dirty.
* On next received packet, source will send SourceInfoPacket to all listeners
* On next UDP packet sent, source will send SourceInfoPacket to all listeners
*/
void setDirty();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ public interface TcpServerConnectionManager extends ConnectionManager<ClientPack
* @param player the player
*/
void broadcastPlayerInfoUpdate(@NotNull VoiceServerPlayer player);

/**
* Sends {@link su.plo.voice.proto.packets.tcp.clientbound.PlayerDisconnectPacket} to all connected players
*
* @param player the player
*/
void broadcastPlayerDisconnect(@NotNull VoiceServerPlayer player);
}
16 changes: 6 additions & 10 deletions client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ dependencies {
shadowCommon(prebundleNow(universalCraft))

"su.plo.ustats:${uStatsVersion()}".also {
modApi(it)
modApi(it) {
isTransitive = false
}
shadowCommon(it) {
isTransitive = false
}
Expand Down Expand Up @@ -128,15 +130,9 @@ dependencies {
isTransitive = false
}

if (platform.isForge) {
shadowCommon(rootProject.libs.guice) {
exclude("com.google.guava")
}
} else {
"include"(rootProject.libs.guice)
"include"(rootProject.libs.aopalliance)
"include"(rootProject.libs.javax.inject)
}
"include"(rootProject.libs.guice)
"include"(rootProject.libs.aopalliance)
"include"(rootProject.libs.javax.inject)
}

tasks {
Expand Down
8 changes: 6 additions & 2 deletions client/changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
- Fixed crash when entering singeplayer twice
- Fixed crash when trying to change hud icon/overlay position
- Fixed server bug when player can't hear/speak to others players after respawn
- Fixed crash on Mac OS versions lower than 11
- Fixed crash on source buffer overflow
- Fixed crash when opus was trying to decode bad frames
- guice is now bundled with JIJ in forge to fix compatibility with other mods
- Fixed crash with EssentialAddons using "reloadFakePlayers"
5 changes: 3 additions & 2 deletions client/src/main/java/su/plo/lib/mod/entity/ModEntity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package su.plo.lib.mod.entity;

import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.minecraft.world.entity.Entity;
import org.jetbrains.annotations.NotNull;
import su.plo.lib.api.entity.MinecraftEntity;
import su.plo.lib.api.entity.MinecraftPlayerEntity;
import su.plo.voice.proto.data.pos.Pos3d;

import java.util.UUID;

@RequiredArgsConstructor
public class ModEntity<E extends Entity> implements MinecraftEntity {

protected final E instance;
@Setter
protected @NotNull E instance;

private final Pos3d position = new Pos3d();
private final Pos3d lookAngle = new Pos3d();
Expand Down
43 changes: 33 additions & 10 deletions client/src/main/java/su/plo/lib/mod/server/ModServerLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
import su.plo.voice.proto.data.player.MinecraftGameProfile;
import su.plo.voice.server.player.PermissionSupplier;

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand All @@ -44,6 +45,7 @@ public final class ModServerLib implements MinecraftServerLib {
@Setter
private MinecraftServer server;
@Setter
@Getter
private PermissionSupplier permissions;

@Getter
Expand All @@ -55,6 +57,9 @@ public final class ModServerLib implements MinecraftServerLib {
@Getter
private final PermissionsManager permissionsManager = new PermissionsManager();

private ScheduledExecutorService backgroundExecutor;
private ScheduledFuture<?> worldCleanupTask;

public ModServerLib(@NotNull Supplier<ServerLanguages> languagesSupplier) {
this.textConverter = new ServerComponentTextConverter(new ComponentTextConverter(), languagesSupplier);
this.commandManager = new ModCommandManager(this, textConverter);
Expand All @@ -65,6 +70,14 @@ public ModServerLib(@NotNull Supplier<ServerLanguages> languagesSupplier) {
@Override
public void onInitialize() {
INSTANCE = this;

this.backgroundExecutor = Executors.newSingleThreadScheduledExecutor();
this.worldCleanupTask = backgroundExecutor.scheduleAtFixedRate(
this::worldsCleanupTick,
0L,
30L,
TimeUnit.SECONDS
);
}

@Override
Expand All @@ -73,6 +86,9 @@ public void onShutdown() {
this.permissions = null;
commandManager.clear();
permissionsManager.clear();

worldCleanupTask.cancel(false);
backgroundExecutor.shutdown();
}

@Override
Expand All @@ -93,10 +109,6 @@ public void executeInMainThread(@NotNull Runnable runnable) {

@Override
public Collection<MinecraftServerWorld> getWorlds() {
if (server.levelKeys().size() == worldByInstance.size()) {
return worldByInstance.values();
}

return StreamSupport.stream(server.getAllLevels().spliterator(), false)
.map(this::getWorld)
.toList();
Expand All @@ -108,15 +120,16 @@ public Collection<MinecraftServerWorld> getWorlds() {
throw new IllegalArgumentException("instance is not " + ServerPlayer.class);

MinecraftServerPlayerEntity serverPlayer = playerById.get(serverInstance.getUUID());
if (serverPlayer == null || ((ServerPlayer) serverPlayer.getInstance()).getId() != serverInstance.getId()) {
if (serverPlayer == null) {
serverPlayer = new ModServerPlayer(
this,
textConverter,
permissions,
resources,
serverInstance
);
playerById.put(serverInstance.getUUID(), serverPlayer);
} else if (serverPlayer.getInstance() != serverInstance) {
((ModServerPlayer) serverPlayer).setInstance(serverInstance);
}

return serverPlayer;
Expand Down Expand Up @@ -192,4 +205,14 @@ public int getPort() {
public @NotNull String getVersion() {
return server.getServerVersion();
}

private void worldsCleanupTick() {
Set<ServerLevel> worlds = StreamSupport.stream(server.getAllLevels().spliterator(), false)
.collect(Collectors.toSet());

worldByInstance.keySet()
.stream()
.filter(world -> !worlds.contains(world))
.forEach(worldByInstance::remove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.server.level.ServerPlayer;
import org.jetbrains.annotations.NotNull;
import su.plo.lib.api.chat.MinecraftTextComponent;
import su.plo.lib.api.server.MinecraftServerLib;
import su.plo.lib.api.server.chat.ServerTextConverter;
import su.plo.lib.api.server.entity.MinecraftServerEntity;
import su.plo.lib.api.server.entity.MinecraftServerPlayerEntity;
Expand All @@ -20,8 +19,8 @@
import su.plo.lib.api.server.world.ServerPos3d;
import su.plo.lib.mod.client.texture.ResourceCache;
import su.plo.lib.mod.entity.ModPlayer;
import su.plo.lib.mod.server.ModServerLib;
import su.plo.voice.proto.data.player.MinecraftGameProfile;
import su.plo.voice.server.player.PermissionSupplier;

import java.util.Collection;
import java.util.Optional;
Expand All @@ -33,9 +32,8 @@ public final class ModServerPlayer
extends ModPlayer<ServerPlayer>
implements MinecraftServerPlayerEntity {

private final MinecraftServerLib minecraftServer;
private final ModServerLib minecraftServer;
private final ServerTextConverter<Component> textConverter;
private final PermissionSupplier permissions;
private final ResourceCache resources;
private final Set<String> registeredChannels = Sets.newCopyOnWriteArraySet();

Expand All @@ -44,16 +42,14 @@ public final class ModServerPlayer
private String language = "en_us";
private MinecraftServerEntity spectatorTarget;

public ModServerPlayer(@NotNull MinecraftServerLib minecraftServer,
public ModServerPlayer(@NotNull ModServerLib minecraftServer,
@NotNull ServerTextConverter<Component> textConverter,
@NotNull PermissionSupplier permissions,
@NotNull ResourceCache resources,
@NotNull ServerPlayer player) {
super(player);

this.minecraftServer = minecraftServer;
this.textConverter = textConverter;
this.permissions = permissions;
this.resources = resources;
}

Expand Down Expand Up @@ -153,12 +149,16 @@ public Optional<MinecraftServerEntity> getSpectatorTarget() {

@Override
public boolean hasPermission(@NotNull String permission) {
return permissions.hasPermission(instance, permission);
if (minecraftServer.getPermissions() == null) return false;

return minecraftServer.getPermissions().hasPermission(instance, permission);
}

@Override
public @NotNull PermissionTristate getPermission(@NotNull String permission) {
return permissions.getPermission(instance, permission);
if (minecraftServer.getPermissions() == null) return PermissionTristate.UNDEFINED;

return minecraftServer.getPermissions().getPermission(instance, permission);
}

public void addChannel(@NotNull String channel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void initialize(@NotNull ServerInfo serverInfo) {
config.getVoice().getStereoCapture().value()
);

if (!getDevice().isPresent()) {
if (!getDevice().isPresent() && !config.getVoice().getDisableInputDevice().value()) {
try {
InputDevice device = voiceClient.getDeviceManager().openInputDevice(format, Params.EMPTY);
devices.replace(null, device);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private void tickJob() throws DeviceException {
}

if (inputDevices.isEmpty()) {
if (inputFactory.getDeviceNames().size() > 0) {
if (inputFactory.getDeviceNames().size() > 0 && !config.getVoice().getDisableInputDevice().value()) {
try {
replace(null, voiceClient.getDeviceManager().openInputDevice(null, Params.EMPTY));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import su.plo.voice.api.util.AudioUtil;
import su.plo.voice.rnnoise.Denoiser;

import static su.plo.voice.util.NativesKt.isNativesSupported;

public final class NoiseSuppressionFilter extends LimiterFilter {

private final ConfigEntry<Boolean> activeEntry;
Expand All @@ -16,7 +18,12 @@ public NoiseSuppressionFilter(int sampleRate, @NotNull ConfigEntry<Boolean> acti
super(sampleRate, -6.0F);

this.activeEntry = activeEntry;
if (activeEntry.value()) toggle(true);

if (!isNativesSupported()) {
activeEntry.set(false);
activeEntry.setDisabled(true);
} else if (activeEntry.value()) toggle(true);

activeEntry.clearChangeListeners();
activeEntry.addChangeListener(this::toggle);
}
Expand All @@ -25,9 +32,10 @@ private void toggle(boolean value) {
if (value) {
try {
instance = new Denoiser();
} catch (Exception e) {
} catch (Exception | LinkageError e) {
BaseVoice.LOGGER.error("RNNoise is not available on this platform");
activeEntry.set(false);
activeEntry.setDisabled(true);
}
} else if (instance != null) {
instance.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ public static class Voice implements ClientConfig.Voice {
@ConfigField
private ConfigEntry<String> outputDevice = new ConfigEntry<>("");

@ConfigField
private BooleanConfigEntry disableInputDevice = new BooleanConfigEntry(false);

@ConfigField
private BooleanConfigEntry useJavaxInput = new BooleanConfigEntry(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ private OptionEntry<DropDownWidget> createMicrophoneEntry() {

ImmutableList<String> inputDeviceNames = deviceFactory.get().getDeviceNames();
Collection<AudioDevice> inputDevices = this.devices.getDevices(DeviceType.INPUT);
Optional<AudioDevice> inputDevice = inputDevices.stream().findFirst();
Optional<AudioDevice> inputDevice = Optional.empty();
if (!config.getVoice().getDisableInputDevice().value()) {
inputDevice = inputDevices.stream().findFirst();
}

DropDownWidget dropdown = new DropDownWidget(
parent,
Expand All @@ -164,7 +167,7 @@ private OptionEntry<DropDownWidget> createMicrophoneEntry() {
}
);

dropdown.setActive(!inputDeviceNames.isEmpty());
dropdown.setActive(!inputDeviceNames.isEmpty() && !config.getVoice().getDisableInputDevice().value());

return new OptionEntry<>(
MinecraftTextComponent.translatable("gui.plasmovoice.devices.microphone"),
Expand Down Expand Up @@ -288,6 +291,8 @@ private void reloadOutputDevice() {
}

private void reloadInputDevice() {
if (config.getVoice().getDisableInputDevice().value()) return;

try {
InputDevice device = devices.openInputDevice(null, Params.EMPTY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package su.plo.voice.client.mixin;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import su.plo.lib.mod.server.ModServerLib;

@Mixin(PlayerList.class)
public abstract class MixinPlayerList {

@Inject(method = "respawn", at = @At("RETURN"))
private void onRespawn(ServerPlayer serverPlayer, boolean bl, CallbackInfoReturnable<ServerPlayer> cir) {
ServerPlayer newPlayer = cir.getReturnValue();
ModServerLib.INSTANCE.getPlayerByInstance(newPlayer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ public void handle(@NotNull SourceAudioPacket packet) {
voiceClient.getSourceManager().getSourceById(packet.getSourceId())
.ifPresent(source -> {
if (source.getSourceInfo().getState() != packet.getSourceState()) {
BaseVoice.DEBUG_LOGGER.log(
"Drop audio packet with bad source state: packet source state={}, source={}",
packet.getSourceState(), source.getSourceInfo()
);
voiceClient.getSourceManager().sendSourceInfoRequest(packet.getSourceId(), true);
return;
}

source.process(packet);
Expand Down
Loading

0 comments on commit 57ba68a

Please sign in to comment.