Search in sources :

Example 1 with SessionKey

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

the class SessionManager method tipWave.

private void tipWave() {
    if (!onHypixel || !loggedIn) {
        taskManager.cancelTask(TaskType.TIP_WAVE);
        return;
    }
    lastTipWave = System.currentTimeMillis();
    nextTipWave = System.currentTimeMillis() + reply.getTipWaveRate() * 1000;
    TipReply r = TipRequest.of(sessionKey).execute();
    if (r.isSuccess()) {
        tipQueue.addAll(r.getTips());
        Autotip.LOGGER.info("Current tip queue: {}", StringUtils.join(tipQueue.iterator(), ", "));
    } else {
        tipQueue.addAll(TipReply.getDefault().getTips());
        Autotip.LOGGER.info("Failed to fetch tip queue, tipping 'all' instead.");
    }
    long tipCycle = reply.getTipCycleRate();
    taskManager.addRepeatingTask(TaskType.TIP_CYCLE, this::tipCycle, 0, tipCycle);
}
Also used : TipReply(me.semx11.autotip.api.reply.impl.TipReply)

Example 2 with SessionKey

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

the class KeepAliveRequest method execute.

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

Example 3 with SessionKey

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

the class ErrorReport method reportException.

public static void reportException(Throwable t) {
    Autotip.LOGGER.error(t.getMessage(), t);
    HttpURLConnection conn = null;
    try {
        URL url = new URL("https://api.autotip.pro/error_report.php");
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        JsonObjectBuilder builder = JsonObjectBuilder.newBuilder().addString("username", autotip.getGameProfile().getName()).addString("uuid", autotip.getGameProfile().getId()).addString("v", autotip.getVersion()).addString("mc", autotip.getMcVersion()).addString("os", System.getProperty("os.name")).addString("forge", "hyperium").addString("stackTrace", ExceptionUtils.getStackTrace(t)).addNumber("time", System.currentTimeMillis());
        if (autotip.isInitialized()) {
            EventClientConnection event = autotip.getEvent(EventClientConnection.class);
            builder.addString("sessionKey", autotip.getSessionManager().getKey()).addString("serverIp", event.getServerIp());
        }
        byte[] jsonBytes = builder.build().toString().getBytes(StandardCharsets.UTF_8);
        conn.setFixedLengthStreamingMode(jsonBytes.length);
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        conn.setRequestProperty("User-Agent", "Autotip v" + autotip.getVersion());
        conn.connect();
        try (OutputStream out = conn.getOutputStream()) {
            out.write(jsonBytes);
        }
        InputStream input = conn.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST ? conn.getInputStream() : conn.getErrorStream();
        String json = IOUtils.toString(input, StandardCharsets.UTF_8);
        Autotip.LOGGER.info("Error JSON: " + json);
        input.close();
        conn.disconnect();
    } catch (IOException e) {
        // Hmm... what would happen if I were to report this one?
        e.printStackTrace();
    } finally {
        if (conn != null)
            conn.disconnect();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) EventClientConnection(me.semx11.autotip.event.impl.EventClientConnection) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with SessionKey

use of me.semx11.autotip.api.SessionKey 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 5 with SessionKey

use of me.semx11.autotip.api.SessionKey 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)

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