AuthFlow class

Пакет: com.hypixel.hytale.server.core.command.commands.server.auth

Файл: com/hypixel/hytale/server/core/command/commands/server/auth/AuthLoginBrowserCommand.java

extends: OAuthBrowserFlow

Методы (1)

МодификаторыВозвратСигнатура
public void onFlowInfopublic void onFlowInfo(String var1, String var2)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.command.commands.server.auth;

class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.auth.AuthCredentialStoreProvider;
class="kw">import com.hypixel.hytale.server.core.auth.MemoryAuthCredentialStoreProvider;
class="kw">import com.hypixel.hytale.server.core.auth.ServerAuthManager;
class="kw">import com.hypixel.hytale.server.core.auth.SessionServiceClient;
class="kw">import com.hypixel.hytale.server.core.auth.oauth.OAuthBrowserFlow;
class="kw">import com.hypixel.hytale.server.core.command.system.AbstractCommand;
class="kw">import com.hypixel.hytale.server.core.command.system.CommandContext;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
class="kw">import java.awt.Color;
class="kw">import java.awt.Desktop;
class="kw">import java.awt.Desktop.Action;
class="kw">import java.net.URI;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;

class="kw">public class AuthLoginBrowserCommand class="kw">extends CommandBase {
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_SINGLEPLAYER = Message.translation("server.commands.auth.login.singleplayer").color(Color.RED);
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_ALREADY_AUTHENTICATED = Message.translation("server.commands.auth.login.alreadyAuthenticated").color(Color.YELLOW);
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_STARTING = Message.translation("server.commands.auth.login.browser.starting").color(Color.YELLOW);
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_SUCCESS = Message.translation("server.commands.auth.login.browser.success").color(Color.GREEN);
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_FAILED = Message.translation("server.commands.auth.login.browser.failed").color(Color.RED);
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_PENDING = Message.translation("server.commands.auth.login.pending").color(Color.YELLOW);

   class="kw">public AuthLoginBrowserCommand() {
      super("browser", "server.commands.auth.login.browser.desc");
   }

   @Override
   class="kw">protected void executeSync(@Nonnull CommandContext var1) {
      ServerAuthManager var2 = ServerAuthManager.getInstance();
      if (var2.isSingleplayer()) {
         var1.sendMessage(MESSAGE_SINGLEPLAYER);
      } else if (var2.hasSessionToken() && var2.hasIdentityToken()) {
         var1.sendMessage(MESSAGE_ALREADY_AUTHENTICATED);
      } else {
         var1.sendMessage(MESSAGE_STARTING);
         var2.startFlowAsync(new AuthLoginBrowserCommand.AuthFlow()).thenAccept(var2x -> {
            class="kw">switch (var2x) {
               case SUCCESS:
                  var1.sendMessage(MESSAGE_SUCCESS);
                  sendPersistenceFeedback(var1);
                  break;
               case PENDING_PROFILE_SELECTION:
                  var1.sendMessage(MESSAGE_PENDING);
                  SessionServiceClient.GameProfile[] var3 = var2.getPendingProfiles();
                  if (var3 != null) {
                     AuthSelectCommand.sendProfileList(var1, var3);
                  }
                  break;
               case FAILED:
                  var1.sendMessage(MESSAGE_FAILED);
            }
         });
      }
   }

   class="kw">static void sendPersistenceFeedback(@Nonnull CommandContext var0) {
      AuthCredentialStoreProvider var1 = HytaleServer.get().getConfig().getAuthCredentialStoreProvider();
      if (var1 class="kw">instanceof MemoryAuthCredentialStoreProvider) {
         String var2 = String.join(", ", AuthCredentialStoreProvider.CODEC.getRegisteredIds());
         var0.sendMessage(Message.translation("server.commands.auth.login.persistence.memory").color(Color.ORANGE).param("types", var2));
      } else {
         String var3 = AuthCredentialStoreProvider.CODEC.getIdFor((Class<? class="kw">extends AuthCredentialStoreProvider>)var1.getClass());
         var0.sendMessage(Message.translation("server.commands.auth.login.persistence.saved").color(Color.GREEN).param("type", var3));
      }
   }

   class="kw">private class="kw">static class AuthFlow class="kw">extends OAuthBrowserFlow {
      class="kw">private AuthFlow() {
      }

      @Override
      class="kw">public void onFlowInfo(String var1, String var2) {
         AbstractCommand.LOGGER.at(Level.INFO).log("Starting OAuth browser flow...");
         AbstractCommand.LOGGER.at(Level.INFO).log("===================================================================");
         AbstractCommand.LOGGER.at(Level.INFO).log("Please open this URL in your browser to authenticate:");
         AbstractCommand.LOGGER.at(Level.INFO).log("%s", var1);
         AbstractCommand.LOGGER.at(Level.INFO).log("");
         AbstractCommand.LOGGER.at(Level.INFO).log("Verification code (must match the code shown on the consent page):");
         AbstractCommand.LOGGER.at(Level.INFO).log("    %s", var2);
         AbstractCommand.LOGGER.at(Level.INFO).log("===================================================================");
         if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
            try {
               Desktop.getDesktop().browse(new URI(var1));
               AbstractCommand.LOGGER.at(Level.INFO).log("Browser opened automatically.");
            } catch (Exception var4) {
               AbstractCommand.LOGGER.at(Level.INFO).log("Could not open browser automatically. Please open the URL manually.");
            }
         }
      }
   }
}