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));
}
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));
}
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);
}
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);
}
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();
}
Aggregations