Search in sources :

Example 6 with Reply

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

the class LocaleRequest method execute.

@Override
public LocaleReply execute() {
    HttpUriRequest request = GetBuilder.of(this).addParameter("lang", locale.toLanguageTag()).addParameter("v", version.get()).build();
    Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
    return optional.map(reply -> (LocaleReply) reply).orElseGet(() -> new LocaleReply(false));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Autotip(me.semx11.autotip.Autotip) RequestHandler(me.semx11.autotip.api.RequestHandler) LocaleReply(me.semx11.autotip.api.reply.impl.LocaleReply) Locale(java.util.Locale) RequestType(me.semx11.autotip.api.RequestType) GetBuilder(me.semx11.autotip.api.GetBuilder) Reply(me.semx11.autotip.api.reply.Reply) Version(me.semx11.autotip.util.Version) Optional(java.util.Optional) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Request(me.semx11.autotip.api.request.Request) LocaleReply(me.semx11.autotip.api.reply.impl.LocaleReply) LocaleReply(me.semx11.autotip.api.reply.impl.LocaleReply) Reply(me.semx11.autotip.api.reply.Reply)

Example 7 with Reply

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

the class LogoutRequest method execute.

@Override
public LogoutReply execute() {
    HttpUriRequest request = GetBuilder.of(this).addParameter("key", sessionKey).build();
    Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
    return optional.map(reply -> (LogoutReply) reply).orElseGet(() -> new LogoutReply(false));
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) LogoutReply(me.semx11.autotip.api.reply.impl.LogoutReply) RequestHandler(me.semx11.autotip.api.RequestHandler) SessionKey(me.semx11.autotip.api.SessionKey) RequestType(me.semx11.autotip.api.RequestType) GetBuilder(me.semx11.autotip.api.GetBuilder) Reply(me.semx11.autotip.api.reply.Reply) Optional(java.util.Optional) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Request(me.semx11.autotip.api.request.Request) LogoutReply(me.semx11.autotip.api.reply.impl.LogoutReply) LogoutReply(me.semx11.autotip.api.reply.impl.LogoutReply) Reply(me.semx11.autotip.api.reply.Reply)

Example 8 with Reply

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

the class TipRequest method execute.

@Override
public TipReply execute() {
    HttpUriRequest request = GetBuilder.of(this).addParameter("key", sessionKey).build();
    Optional<Reply> optional = RequestHandler.getReply(this, request.getURI());
    return optional.map(reply -> (TipReply) reply).orElseGet(TipReply::getDefault);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) RequestHandler(me.semx11.autotip.api.RequestHandler) SessionKey(me.semx11.autotip.api.SessionKey) TipReply(me.semx11.autotip.api.reply.impl.TipReply) RequestType(me.semx11.autotip.api.RequestType) GetBuilder(me.semx11.autotip.api.GetBuilder) Reply(me.semx11.autotip.api.reply.Reply) Optional(java.util.Optional) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Request(me.semx11.autotip.api.request.Request) TipReply(me.semx11.autotip.api.reply.impl.TipReply) Reply(me.semx11.autotip.api.reply.Reply) TipReply(me.semx11.autotip.api.reply.impl.TipReply)

Example 9 with Reply

use of me.semx11.autotip.api.reply.Reply 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 10 with Reply

use of me.semx11.autotip.api.reply.Reply 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

Reply (me.semx11.autotip.api.reply.Reply)7 Optional (java.util.Optional)6 GetBuilder (me.semx11.autotip.api.GetBuilder)6 RequestHandler (me.semx11.autotip.api.RequestHandler)6 RequestType (me.semx11.autotip.api.RequestType)6 Request (me.semx11.autotip.api.request.Request)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 Autotip (me.semx11.autotip.Autotip)3 SessionKey (me.semx11.autotip.api.SessionKey)3 GameProfile (com.mojang.authlib.GameProfile)2 LocaleReply (me.semx11.autotip.api.reply.impl.LocaleReply)2 LogoutReply (me.semx11.autotip.api.reply.impl.LogoutReply)2 SettingsReply (me.semx11.autotip.api.reply.impl.SettingsReply)2 Version (me.semx11.autotip.util.Version)2 JsonParseException (com.google.gson.JsonParseException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 Locale (java.util.Locale)1 KeepAliveReply (me.semx11.autotip.api.reply.impl.KeepAliveReply)1