Search in sources :

Example 26 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class ProxyServerInfo method registerServer.

private Server registerServer() {
    Server proxy = createServerObject();
    fromDatabase.save(proxy);
    Server stored = fromDatabase.load(null).orElseThrow(() -> new EnableException("BungeeCord registration failed (DB)"));
    fromFile.save(stored);
    return stored;
}
Also used : EnableException(com.djrapitops.plan.exceptions.EnableException) Server(com.djrapitops.plan.identification.Server)

Example 27 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class RootPageResolver method getResponse.

private Response getResponse(Request request) {
    Server server = serverInfo.getServer();
    if (!webServer.get().isAuthRequired()) {
        String redirectTo = server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName());
        return responseFactory.redirectResponse(redirectTo);
    }
    WebUser user = request.getUser().orElseThrow(() -> new WebUserAuthException(FailReason.EXPIRED_COOKIE));
    if (user.hasPermission("page.server")) {
        return responseFactory.redirectResponse(server.isProxy() ? "network" : "server/" + Html.encodeToURL(server.getIdentifiableName()));
    } else if (user.hasPermission("page.players")) {
        return responseFactory.redirectResponse("players");
    } else if (user.hasPermission("page.player.self")) {
        return responseFactory.redirectResponse("player/" + Html.encodeToURL(user.getName()));
    } else {
        return responseFactory.forbidden403(user.getName() + " has insufficient permissions to be redirected to any page. Needs one of: 'page.server', 'page.players' or 'page.player.self'");
    }
}
Also used : Server(com.djrapitops.plan.identification.Server) WebServer(com.djrapitops.plan.delivery.webserver.WebServer) WebUserAuthException(com.djrapitops.plan.exceptions.WebUserAuthException) WebUser(com.djrapitops.plan.delivery.web.resolver.request.WebUser)

Example 28 with Server

use of com.djrapitops.plan.identification.Server in project Plan by plan-player-analytics.

the class UserInfoQueriesTest method joinAddressUpdateIsUniquePerServer.

@Test
default void joinAddressUpdateIsUniquePerServer() {
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "")));
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, () -> "example.join.address"));
    Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
    Set<UserInfo> expected = new HashSet<>(Arrays.asList(new UserInfo(playerUUID, serverUUID(), TestConstants.REGISTER_TIME, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false), new UserInfo(playerUUID, TestConstants.SERVER_TWO_UUID, TestConstants.REGISTER_TIME, false, "example.join.address", false)));
    assertEquals(expected, userInfo);
}
Also used : Server(com.djrapitops.plan.identification.Server) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) Test(org.junit.jupiter.api.Test)

Aggregations

Server (com.djrapitops.plan.identification.Server)28 ServerUUID (com.djrapitops.plan.identification.ServerUUID)11 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)9 Test (org.junit.jupiter.api.Test)7 PreparedStatement (java.sql.PreparedStatement)6 Database (com.djrapitops.plan.storage.database.Database)5 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)5 ResultSet (java.sql.ResultSet)5 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)3 EnableException (com.djrapitops.plan.exceptions.EnableException)3 ServerInfo (com.djrapitops.plan.identification.ServerInfo)3 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 DBSystem (com.djrapitops.plan.storage.database.DBSystem)3 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)3 SetServerAsUninstalledTransaction (com.djrapitops.plan.storage.database.transactions.commands.SetServerAsUninstalledTransaction)3 User (com.djrapitops.plan.delivery.domain.auth.User)2 ExtensionPlayerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery)2 Locale (com.djrapitops.plan.settings.locale.Locale)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2