mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-02 00:52:46 +00:00
Fixed reconnecting to the api
This commit is contained in:
parent
0832e7d65c
commit
e7eca7f7b9
1 changed files with 12 additions and 14 deletions
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package org.geysermc.connector.skin;
|
package org.geysermc.connector.skin;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
@ -38,6 +39,7 @@ import org.geysermc.floodgate.util.WebsocketEventType;
|
||||||
import org.java_websocket.client.WebSocketClient;
|
import org.java_websocket.client.WebSocketClient;
|
||||||
import org.java_websocket.handshake.ServerHandshake;
|
import org.java_websocket.handshake.ServerHandshake;
|
||||||
|
|
||||||
|
import java.net.ConnectException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -138,18 +140,21 @@ public final class FloodgateSkinUploader {
|
||||||
String error = node.get("error").asText();
|
String error = node.get("error").asText();
|
||||||
logger.info("Got disconnected from the skin uploader: " + error);
|
logger.info("Got disconnected from the skin uploader: " + error);
|
||||||
}
|
}
|
||||||
// it can't be something else then info or error, so we won't handle anything other than that.
|
} catch (JsonProcessingException ignored) {
|
||||||
// try to reconnect (which will make a new id and verify token) after a few seconds
|
// ignore invalid json
|
||||||
reconnectLater(connector);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error while handling onClose", e);
|
logger.error("Error while handling onClose", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// try to reconnect (which will make a new id and verify token) after a few seconds
|
||||||
|
reconnectLater(connector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception ex) {
|
public void onError(Exception ex) {
|
||||||
logger.error("Got an error", ex);
|
if (!(ex instanceof ConnectException)) {
|
||||||
|
logger.error("Got an error", ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -180,17 +185,10 @@ public final class FloodgateSkinUploader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reconnectLater(GeyserConnector connector) {
|
private void reconnectLater(GeyserConnector connector) {
|
||||||
//todo doesn't work
|
|
||||||
long additionalTime = ThreadLocalRandom.current().nextInt(7);
|
long additionalTime = ThreadLocalRandom.current().nextInt(7);
|
||||||
connector.getGeneralThreadPool().schedule(() -> {
|
// we don't have to check the result. onClose will handle that for us
|
||||||
try {
|
connector.getGeneralThreadPool()
|
||||||
if (!client.connectBlocking()) {
|
.schedule(client::reconnect, 8 + additionalTime, TimeUnit.SECONDS);
|
||||||
reconnectLater(connector);
|
|
||||||
}
|
|
||||||
} catch (InterruptedException ignored) {
|
|
||||||
reconnectLater(connector);
|
|
||||||
}
|
|
||||||
}, 8 + additionalTime, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FloodgateSkinUploader start() {
|
public FloodgateSkinUploader start() {
|
||||||
|
|
Loading…
Reference in a new issue