/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  jakarta.servlet.ServletException
 *  jakarta.websocket.HandshakeResponse
 *  jakarta.websocket.server.HandshakeRequest
 *  jakarta.websocket.server.ServerEndpointConfig
 *  org.apache.tomcat.websocket.server.DefaultServerEndpointConfigurator
 */
package com.l7tech.server.tomcat.websocket;

import com.l7tech.server.transport.http.websocket.SsgWebSocketEndpointHandler;
import com.l7tech.server.transport.http.websocket.SsgWebSocketManager;
import com.l7tech.server.transport.http.websocket.SsgWebSocketRuntimeException;
import jakarta.servlet.ServletException;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.server.HandshakeRequest;
import jakarta.websocket.server.ServerEndpointConfig;
import java.io.IOException;
import java.util.List;
import org.apache.tomcat.websocket.server.DefaultServerEndpointConfigurator;

public class SsgServerEndpointConfigurator
extends DefaultServerEndpointConfigurator {
    private static final String[] a;

    public void modifyHandshake(ServerEndpointConfig serverEndpointConfig, HandshakeRequest handshakeRequest, HandshakeResponse handshakeResponse) {
        SsgWebSocketManager ssgWebSocketManager = SsgWebSocketManager.getInstance();
        SsgWebSocketEndpointHandler ssgWebSocketEndpointHandler = ssgWebSocketManager.getEndpointHandler();
        String[] stringArray = a;
        String string = (String)((List)handshakeRequest.getHeaders().get(stringArray[2])).get(0);
        serverEndpointConfig.getUserProperties().put(stringArray[1], string);
        try {
            ssgWebSocketEndpointHandler.getInboundConnectionHandler().handleUpgrade(serverEndpointConfig, ssgWebSocketManager.getHandshakeSsgServerEndpointConfig(string), ssgWebSocketManager.getHandshakeRequest(string), ssgWebSocketManager.getHandshakeResponse(string));
        }
        catch (ServletException | IOException throwable) {
            throw new SsgWebSocketRuntimeException(a[0] + throwable.getMessage(), throwable);
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[3];
        int n2 = 0;
        String string = "guY\u00130\u001f\u0002B{S\u001e%\u000eCA\u007f\u001d\u001f8\u0005M_tI\u001f$\u0003F\n\u007fO\b9\u0014\u0018\n\u0010yIzW\u001e\u0007LNiU\u001b=\u0003\u000fc^\u0011y\u007f^W\u0001\u0003@yu^\u00113\u0012\u000fa\u007fD";
        int n3 = "guY\u00130\u001f\u0002B{S\u001e%\u000eCA\u007f\u001d\u001f8\u0005M_tI\u001f$\u0003F\n\u007fO\b9\u0014\u0018\n\u0010yIzW\u001e\u0007LNiU\u001b=\u0003\u000fc^\u0011y\u007f^W\u0001\u0003@yu^\u00113\u0012\u000fa\u007fD".length();
        int n4 = 36;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = SsgServerEndpointConfigurator.a(114, SsgServerEndpointConfigurator.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                a = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x50);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 88;
                    case 1 -> 104;
                    case 2 -> 79;
                    case 3 -> 8;
                    case 4 -> 36;
                    case 5 -> 20;
                    default -> 80;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

