|
49 | 49 | import org.geysermc.geyser.util.JsonUtils; |
50 | 50 | import org.geysermc.geyser.util.PluginMessageUtils; |
51 | 51 | import org.java_websocket.client.WebSocketClient; |
| 52 | +import org.java_websocket.framing.CloseFrame; |
52 | 53 | import org.java_websocket.handshake.ServerHandshake; |
53 | 54 |
|
54 | 55 | public final class FloodgateSkinUploader { |
@@ -79,6 +80,8 @@ public final class FloodgateSkinUploader { |
79 | 80 | @Getter private boolean allowSubscribers = false; |
80 | 81 | private int subscribersCount; |
81 | 82 |
|
| 83 | + private int protocolErrorCount = 0; |
| 84 | + |
82 | 85 | public FloodgateSkinUploader(GeyserImpl geyser) { |
83 | 86 | this.logger = geyser.getLogger(); |
84 | 87 | this.client = new WebSocketClient(Constants.GLOBAL_API_WS_URI) { |
@@ -180,6 +183,22 @@ public void onMessage(String message) { |
180 | 183 | public void onClose(int code, String reason, boolean remote) { |
181 | 184 | allowSubscribers = false; |
182 | 185 |
|
| 186 | + // If we seem to get protocol errors quite a bit, try our alternative url. |
| 187 | + // But if that one fails too for a few times, just revert back to our main url. |
| 188 | + if (code == CloseFrame.PROTOCOL_ERROR) { |
| 189 | + boolean shouldSwitch = false; |
| 190 | + if (protocolErrorCount < 5) { |
| 191 | + shouldSwitch = ++protocolErrorCount == 5; |
| 192 | + } |
| 193 | + if (protocolErrorCount >= 5 && Constants.GLOBAL_API_WS_URI_ALT != null) { |
| 194 | + if (shouldSwitch) { |
| 195 | + uri = Constants.GLOBAL_API_WS_URI_ALT; |
| 196 | + } else if (++protocolErrorCount == 10) { |
| 197 | + uri = Constants.GLOBAL_API_WS_URI; |
| 198 | + } |
| 199 | + } |
| 200 | + } |
| 201 | + |
183 | 202 | if (reason != null && !reason.isEmpty()) { |
184 | 203 | try { |
185 | 204 | JsonObject node = JsonUtils.parseJson(reason); |
|
0 commit comments