use of me.semx11.autotip.Autotip 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.Autotip in project Hyperium by HyperiumClient.
the class StatsDaily method migrate.
public void migrate() {
// Check if legacy stats file exists
FileUtil fileUtil = autotip.getFileUtil();
File file = fileUtil.getLegacyStatsFile(date);
if (!file.exists())
return;
LegacyState state = autotip.getMigrationManager().getLegacyState(date);
try {
// Reads the contents of the file. If the file has less than 2 lines, ignore file.
List<String> lines = Files.readAllLines(file.toPath());
if (lines.size() < 2) {
fileUtil.delete(file);
return;
}
// Parses the first line of the file to tips sent and received (e.g. "124:119").
Matcher tipMatcher = TIPS_PATTERN.matcher(lines.get(0));
if (tipMatcher.matches()) {
tipsSent = Integer.parseInt(tipMatcher.group("sent"));
if (tipMatcher.group("received") != null)
tipsReceived = Integer.parseInt(tipMatcher.group("received"));
}
// This is to fix the wrong tips count in the period between the XP change, and the Autotip fix.
if (state == LegacyState.BACKTRACK)
tipsReceived /= 2;
// Every tip you send is worth 50 XP.
xpSent = tipsSent * 50;
// This is to account for tips received before the XP change, as they gave you 30 XP, not 60 XP.
xpReceived = (state == LegacyState.BEFORE ? 30 : 60) * tipsReceived;
// Parses each line with game-data (e.g. "Arcade:2900:2400") to a Map.
gameStatistics = lines.stream().skip(2).filter(s -> GAME_PATTERN.matcher(s).matches()).collect(Collectors.toMap(s -> s.split(":")[0], s -> {
String[] split = s.split(":");
int sent = Integer.parseInt(split[1]);
int received = split.length > 2 ? Integer.parseInt(split[2]) : 0;
return new Coins(sent, received);
}));
// Remove grouped stats
settings.getGameGroups().stream().filter(group -> gameStatistics.containsKey(group.getName())).forEach(group -> {
Coins coins = gameStatistics.get(group.getName());
group.getGames().forEach(game -> addCoins(game, coins));
});
// Convert aliases
settings.getGameAliases().forEach(alias -> alias.getAliases().stream().filter(aliasAlias -> gameStatistics.containsKey(aliasAlias)).map(aliasAlias -> gameStatistics.get(aliasAlias)).forEach(coins -> alias.getGames().forEach(aliasGame -> addCoins(aliasGame, coins))));
// Deletes old file to complete migration.
fileUtil.delete(file);
Autotip.LOGGER.info("Migrated legacy stats file " + file.getName());
save();
} catch (IOException e) {
Autotip.LOGGER.error("Could not read file " + file.getName(), e);
save();
}
}
Aggregations