Search in sources :

Example 6 with SessionKey

use of me.semx11.autotip.api.SessionKey in project Hyperium by HyperiumClient.

the class SessionManager method login.

public void login() {
    Session session = autotip.getMinecraft().getSession();
    GameProfile profile = session.getProfile();
    String uuid = profile.getId().toString().replace("-", "");
    String serverHash = HashUtil.hash(uuid + HashUtil.getNextSalt());
    int statusCode = authenticate(session.getToken(), uuid, serverHash);
    if (statusCode / 100 != 2) {
        messageUtil.send("&cError {} during authentication: Session servers down?", statusCode);
        return;
    }
    StatsRange all = autotip.getStatsManager().getAll();
    LoginRequest request = LoginRequest.of(autotip, profile, serverHash, all.getTipsTotalInt());
    long lastLogin = autotip.getEvent(EventClientConnection.class).getLastLogin();
    long delay = lastLogin + 5000 - System.currentTimeMillis();
    delay /= 1000;
    reply = taskManager.scheduleAndAwait(request::execute, (delay < 1) ? 1 : delay);
    if (reply == null || !reply.isSuccess()) {
        messageUtil.send("&cError during login: {}", reply == null ? "null" : reply.getCause());
        return;
    }
    sessionKey = reply.getSessionKey();
    loggedIn = true;
    long keepAlive = reply.getKeepAliveRate();
    long tipWave = reply.getTipWaveRate();
    taskManager.addRepeatingTask(TaskType.KEEP_ALIVE, this::keepAlive, keepAlive, keepAlive);
    taskManager.addRepeatingTask(TaskType.TIP_WAVE, this::tipWave, 0, tipWave);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) EventClientConnection(me.semx11.autotip.event.impl.EventClientConnection) StatsRange(me.semx11.autotip.stats.StatsRange) LoginRequest(me.semx11.autotip.api.request.impl.LoginRequest) Session(net.minecraft.util.Session)

Example 7 with SessionKey

use of me.semx11.autotip.api.SessionKey in project Hyperium by HyperiumClient.

the class SessionManager method logout.

public void logout() {
    if (!loggedIn)
        return;
    LogoutReply reply = LogoutRequest.of(sessionKey).execute();
    if (!reply.isSuccess()) {
        Autotip.LOGGER.warn("Error during logout: {}", reply.getCause());
    }
    loggedIn = false;
    sessionKey = null;
    taskManager.cancelTask(TaskType.KEEP_ALIVE);
    tipQueue.clear();
}
Also used : LogoutReply(me.semx11.autotip.api.reply.impl.LogoutReply)

Aggregations

Optional (java.util.Optional)3 GetBuilder (me.semx11.autotip.api.GetBuilder)3 RequestHandler (me.semx11.autotip.api.RequestHandler)3 RequestType (me.semx11.autotip.api.RequestType)3 SessionKey (me.semx11.autotip.api.SessionKey)3 Reply (me.semx11.autotip.api.reply.Reply)3 Request (me.semx11.autotip.api.request.Request)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 LogoutReply (me.semx11.autotip.api.reply.impl.LogoutReply)2 TipReply (me.semx11.autotip.api.reply.impl.TipReply)2 EventClientConnection (me.semx11.autotip.event.impl.EventClientConnection)2 GameProfile (com.mojang.authlib.GameProfile)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 KeepAliveReply (me.semx11.autotip.api.reply.impl.KeepAliveReply)1 LoginRequest (me.semx11.autotip.api.request.impl.LoginRequest)1 StatsRange (me.semx11.autotip.stats.StatsRange)1