Skip to content

Commit

Permalink
Merge pull request #411 from Mindgamesnl/feature/auto-reconnect
Browse files Browse the repository at this point in the history
Feature/auto reconnect
  • Loading branch information
Mindgamesnl authored Feb 21, 2024
2 parents 505560c + 3599122 commit 201e423
Show file tree
Hide file tree
Showing 37 changed files with 541 additions and 114 deletions.
2 changes: 2 additions & 0 deletions client/public/en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ settings.interpolation.title=Location smoothing
settings.interpolation.body=Automatically smooth movements to minimize speaker/voicechat stuttering while walking. This adds extra movement delay, but sounds better.
settings.interpolation.button=Enable smoothing

network.serverUnhealthy={serverName}'s connection to OpenAudioMc is unhealthy, client functionality may be limited until the connection is restored.

tooltip.close=Close
2 changes: 1 addition & 1 deletion client/public/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildMajor":1,"buildMinor":125,"buildRevision":214,"buildTag":"dev","buildDate":"Mon Feb 19 2024","build":"1.125.214 dev"}
{"buildMajor":1,"buildMinor":125,"buildRevision":221,"buildTag":"dev","buildDate":"Wed Feb 21 2024","build":"1.125.221 dev"}
8 changes: 8 additions & 0 deletions client/src/client/services/socket/SocketModule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ export const SocketManager = new class ISocketManager {
TimeService.sync(timeStamp, hoursOffset);
});

this.socket.on('server-reconnecting', () => {
setGlobalState({ isServerHealthy: false });
});

this.socket.on('server-reconnected', () => {
setGlobalState({ isServerHealthy: true });
});

this.socket.on('disconnect', () => {
MediaManager.destroySounds(null, true);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { connect } from 'react-redux';
import React from 'react';
import { msg } from '../../client/OpenAudioAppContainer';

function ServerConnectionWarning(props) {
if (props.isServerHealthy) {
return null;
}

const message = msg('network.serverUnhealthy').replace('{serverName}', props.settings.serverDisplayName || 'the server');

return (
<div className="pb-4">
<div className="bg-red-500 border border-red-400 text-white font-extrabold px-4 py-3 rounded relative flex justify-center" role="alert">
<span className="block">{message}</span>
</div>
</div>
);
}

export default connect(mapStateToProps)(ServerConnectionWarning);

function mapStateToProps(state) {
return {
isServerHealthy: state.isServerHealthy,
settings: state.settings,
};
}
2 changes: 2 additions & 0 deletions client/src/components/tabwindow/TabWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { connect } from 'react-redux';
import { showTextModal } from '../modal/InputModal';
import { setGlobalState } from '../../state/store';
import { msg } from '../../client/OpenAudioAppContainer';
import ServerConnectionWarning from '../connectionwarning/ServerConnectionWarning';

export const setTab = (tab) => {
setGlobalState({
Expand Down Expand Up @@ -57,6 +58,7 @@ class TabWindow extends Component {
<div className="flex flex-col-reverse bg-gray-800 bg-opacity-25 text-white h-screen w-screen">
<main className="flex justify-center overflow-x-hidden overflow-y-auto w-full h-full backdrop-blur">
<div className="content-wrapper">
<ServerConnectionWarning />
{pages[this.props.currentTab].content}
</div>
</main>
Expand Down
2 changes: 1 addition & 1 deletion client/src/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"buildMajor":1,"buildMinor":125,"buildRevision":214,"buildTag":"dev","buildDate":"Mon Feb 19 2024","build":"1.125.214 dev"}
{"buildMajor":1,"buildMinor":125,"buildRevision":221,"buildTag":"dev","buildDate":"Wed Feb 21 2024","build":"1.125.221 dev"}
1 change: 1 addition & 0 deletions client/src/state/store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const initialState = {

isPremium: false,
isClaimed: false,
isServerHealthy: true,
clientSupportsVoiceChat: false, // not valid https
browserSupportsVoiceChat: false, // no webrtc at all
browserSupportIsLimited: false, // operagx, broken settings?
Expand Down
6 changes: 0 additions & 6 deletions modules/vistas-server/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,6 @@
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/bash/data.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BUILD_NUM="1309"
BUILD_NUM="1386"
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ public void disable() {
serviceManager.getService(ModuleLoaderService.class).fire(ModuleEvent.SHUTDOWN);

try {
serviceManager.getService(OpenaudioAccountService.class).shutdown();
serviceManager.getService(RedisService.class).shutdown();
if (serviceManager.getService(StateService.class).getCurrentState().isConnected()) {
serviceManager.getService(NetworkingService.class).stop();
}
serviceManager.getService(OpenaudioAccountService.class).shutdown();
serviceManager.getService(RedisService.class).shutdown();
} catch (NoClassDefFoundError exception) {
OpenAudioLogger.warn("Core dependencies were already unloaded by the classloader, skipping shutdown");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<String> getTabCompletions(CommandContext context, String[] args, Use
try {
Set<String> completions = new HashSet<>();
for (String subCommand : getSubCommands(context)) {
if (args.length <= 1 && subCommand.startsWith(args[0])) {
if (args.length <= 1 && subCommand.toLowerCase(Locale.ROOT).startsWith(args[0].toLowerCase(Locale.ROOT))) {
// Not typing yet, add the entire damn thing
completions.add(subCommand);
}
Expand All @@ -180,6 +180,7 @@ public List<String> getTabCompletions(CommandContext context, String[] args, Use
int localArgIndex = args.length - 2;

boolean isMatch = true;

for (int i = 0; i < localArgIndex; i++) {
if (args.length - 1 < i + 1 || argumentSyntaxParts.length < i + 1) {
isMatch = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.craftmend.openaudiomc.generic.authentication.AuthenticationService;
import com.craftmend.openaudiomc.generic.client.helpers.SerializableClient;
import com.craftmend.openaudiomc.generic.client.objects.ClientConnection;
import com.craftmend.openaudiomc.generic.networking.queue.PacketQueue;
import com.craftmend.openaudiomc.generic.oac.OpenaudioAccountService;
import com.craftmend.openaudiomc.generic.environment.MagicValue;
import com.craftmend.openaudiomc.generic.logging.OpenAudioLogger;
Expand All @@ -22,6 +23,7 @@
import com.craftmend.openaudiomc.generic.platform.interfaces.TaskService;
import com.craftmend.openaudiomc.generic.proxy.interfaces.UserHooks;
import com.craftmend.openaudiomc.generic.state.StateService;
import com.craftmend.openaudiomc.generic.state.states.ReconnectingState;
import com.craftmend.openaudiomc.generic.user.User;
import com.craftmend.openaudiomc.spigot.OpenAudioMcSpigot;
import com.craftmend.openaudiomc.spigot.modules.proxy.enums.OAClientMode;
Expand All @@ -37,6 +39,7 @@ public class DefaultNetworkingService extends NetworkingService {
private final Set<INetworkingEvents> eventHandlers = new HashSet<>();
private final Map<UUID, ClientConnection> clientMap = new ConcurrentHashMap<>();
private final Map<PacketChannel, PayloadHandler<?>> packetHandlerMap = new HashMap<>();
private final PacketQueue packetQueue = new PacketQueue();
private SocketConnection socketConnection;
private int packetThroughput = 0;

Expand Down Expand Up @@ -99,7 +102,7 @@ private void init() {
20, 20);

try {
socketConnection = new SocketConnection(OpenAudioMc.getService(AuthenticationService.class).getServerKeySet());
socketConnection = new SocketConnection(getService(AuthenticationService.class).getServerKeySet(), this);
} catch (Exception e) {
OpenAudioLogger.error(e, "The plugin was unable to start because of a connection problem when requesting the initial private key. Please contact support in https://discord.openaudiomc.net/");
}
Expand Down Expand Up @@ -129,6 +132,20 @@ public void connectIfDown() {
@Override
public void send(Authenticatable client, AbstractPacket packet) {
for (INetworkingEvents event : getEvents()) event.onPacketSend(client, packet);

// are we in a compromised state?
if (getService(StateService.class).getCurrentState() instanceof ReconnectingState) {
// is this packet important?
if (packet.isQueueableIfReconnecting()) {
// we need to queue it
packetQueue.addPacket(client.getOwner().getUniqueId(), packet);
return;
} else {
// drop this packet
return;
}
}

socketConnection.send(client, packet);
}

Expand Down Expand Up @@ -259,4 +276,11 @@ public void addEventHandler(INetworkingEvents events) {
eventHandlers.add(events);
}

public void discardQueue() {
this.packetQueue.clearAll();
}

public void flushQueue() {
this.packetQueue.flush(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.craftmend.openaudiomc.generic.networking.abstracts;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -9,7 +8,6 @@

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class AbstractPacket {

/**
Expand All @@ -21,4 +19,12 @@ public class AbstractPacket {
private PacketChannel packetChannel;
@Setter private UUID client;

public AbstractPacket(AbstractPacketPayload data, PacketChannel packetChannel, UUID client) {
this.data = data;
this.packetChannel = packetChannel;
this.client = client;
}

protected transient boolean queueableIfReconnecting = false;

}
Loading

0 comments on commit 201e423

Please sign in to comment.