diff --git a/README.md b/README.md index 9d38079..35af96f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # rocketleaguelivestats - -DOES NOT WORK ANYMORE!!! +Working again! This awesome sauce tool allows you to checkout the ranks of your opponents while you play! diff --git a/pom.xml b/pom.xml index 21940e1..9bf5fc9 100644 --- a/pom.xml +++ b/pom.xml @@ -28,9 +28,14 @@ 2.4 - org.apache.httpcomponents - httpclient - 4.5.1 + com.sun.jersey + jersey-client + 1.19.2 + + + com.sun.jersey + jersey-json + 1.19.2 diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/model/GamingSystem.java b/src/main/java/com/excuseme/rocketleaguelivestats/model/GamingSystem.java index cce1004..96d7831 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/model/GamingSystem.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/model/GamingSystem.java @@ -1,18 +1,17 @@ package com.excuseme.rocketleaguelivestats.model; public enum GamingSystem { - STEAM("steam","gamingsystem/steam.png"), PS4("ps4","gamingsystem/Ps4.png"), BOT("other"); + STEAM("steam","gamingsystem/steam.png", 3), PS4("ps4","gamingsystem/Ps4.png",2), XBOX("xbox","",3), BOT("other", "", null); private String qualifier; private String iconPath; + private Integer apiId; - private GamingSystem(String qualifier) { - this.qualifier = qualifier; - this.iconPath = null; - } - private GamingSystem(String qualifier, String iconPath) { + private GamingSystem(String qualifier, String iconPath, Integer apiId) { this.qualifier = qualifier; this.iconPath = iconPath; + this.apiId = apiId; + } public String getQualifier() { @@ -22,4 +21,6 @@ public String getQualifier() { public String getIconPath() { return iconPath; } + + public Integer getApiId() { return apiId; } } diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/model/Rank.java b/src/main/java/com/excuseme/rocketleaguelivestats/model/Rank.java index 62b6532..7b7f32c 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/model/Rank.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/model/Rank.java @@ -1,15 +1,14 @@ package com.excuseme.rocketleaguelivestats.model; -import java.math.BigDecimal; - public class Rank implements Comparable{ private Tier tier; private Integer division; - private Skill skill; + private Integer rating; - public Rank(Tier tier, Integer division) { + public Rank(Tier tier, Integer division, Integer rating) { this.tier = tier; this.division = division; + this.rating = rating; } public Tier getTier() { @@ -20,27 +19,14 @@ public Integer getDivision() { return division; } - public Skill getSkill() { - return skill; - } - - public void setSkill(Skill skill) { - this.skill = skill; - } - - @Override - public String toString() { - return "Rank{" + - "tier=" + tier + - ", division=" + division + - ", skill=" + skill + - '}'; + public Integer getRating() { + return rating; } @Override public int compareTo(Rank o) { - final BigDecimal mmr1 = getSkill() != null ? getSkill().getMmr() : new BigDecimal("0"); - final BigDecimal mmr2 = o.getSkill() != null ? o.getSkill().getMmr() : new BigDecimal("0"); - return mmr1.compareTo(mmr2); + final Integer rating1 = getRating() != null ? getRating() : 0; + final Integer rating2 = o.getRating() != null ? getRating() :0; + return rating1.compareTo(rating2); } } diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/model/Skill.java b/src/main/java/com/excuseme/rocketleaguelivestats/model/Skill.java deleted file mode 100644 index 0f5b598..0000000 --- a/src/main/java/com/excuseme/rocketleaguelivestats/model/Skill.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.excuseme.rocketleaguelivestats.model; - -import java.math.BigDecimal; - -public class Skill { - private BigDecimal mu; - private BigDecimal sigma; - private BigDecimal mmr; - private Integer matchesPlayed; - - public Skill(BigDecimal mu, BigDecimal sigma, BigDecimal mmr, Integer matchesPlayed) { - this.mu = mu; - this.sigma = sigma; - this.mmr = mmr; - this.matchesPlayed = matchesPlayed; - } - - public BigDecimal getMu() { - return mu; - } - - public BigDecimal getSigma() { - return sigma; - } - - public BigDecimal getMmr() { - return mmr; - } - - public Integer getMatchesPlayed() { - return matchesPlayed; - } - - @Override - public String toString() { - return "mmr=" + mmr; - } - - -} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/repository/CachedStatisticsRepository.java b/src/main/java/com/excuseme/rocketleaguelivestats/repository/CachedStatisticsRepository.java index c2cadbb..ea7ee1b 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/repository/CachedStatisticsRepository.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/repository/CachedStatisticsRepository.java @@ -2,7 +2,7 @@ import com.excuseme.rocketleaguelivestats.model.PlayerIdentifier; import com.excuseme.rocketleaguelivestats.model.Statistics; -import com.excuseme.rocketleaguelivestats.repository.rocketleague.RocketLeagueAPI; +import com.excuseme.rocketleaguelivestats.repository.rocketleague.APIStatisticsRepository; import com.excuseme.rocketleaguelivestats.scanner.model.SessionData; import java.util.HashMap; @@ -12,7 +12,7 @@ public class CachedStatisticsRepository { - private StatisticsRepository statisticsRepository; + private StatisticsRepository statisticsRepository = new APIStatisticsRepository(); private Map gamePlayerIdentifierStatisticsMap = new HashMap(); public CachedStatisticsRepository() { @@ -28,7 +28,4 @@ public Map findAll(String gameIdentifier, List playerIds = gameData.getPlayerIds(); - Set namePlates = gameData.getNamePlates(); Set playerNames = gameData.getPlayerNames(); Set playerRemoveds = gameData.getPlayerRemoveds(); final GameType gameType = gameData.getGameType(); @@ -46,11 +45,6 @@ public static Game map(GameData gameData) { boolean ownPlayer = calculateOwnPlayer(playerId, gameData.getOwnPlayer(), gamingSystem); String nickName = playerName.getName(); int row = 0; - NamePlate namePlate = findNamePlate(namePlates, nickName); - if (namePlate != null) { - row = namePlate.getRow(); - } - boolean active = isPlayerActive(playerRemoveds, playerName); final Player player = new Player(number, row, nickName, new PlayerIdentifier(id, gamingSystem), active, ownPlayer); players.add(player); @@ -108,6 +102,8 @@ private static GamingSystem mapSystem(String system) { return GamingSystem.STEAM; } else if ("PS4".equalsIgnoreCase(system)) { return GamingSystem.PS4; + } else if ("XBOX".equalsIgnoreCase(system)) { + return GamingSystem.XBOX; } else { return GamingSystem.BOT; } @@ -122,13 +118,4 @@ private static PlayerId findPlayerId(Set playerIds, int number) { } return null; } - - private static NamePlate findNamePlate(Set namePlates, String name) { - for (NamePlate namePlate : namePlates) { - if (name.equals(namePlate.getName())) { - return namePlate; - } - } - return null; - } } diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/repository/StatisticsRepository.java b/src/main/java/com/excuseme/rocketleaguelivestats/repository/StatisticsRepository.java index aef0fda..fc98dbd 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/repository/StatisticsRepository.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/repository/StatisticsRepository.java @@ -1,5 +1,6 @@ package com.excuseme.rocketleaguelivestats.repository; +import com.excuseme.rocketleaguelivestats.model.GamingSystem; import com.excuseme.rocketleaguelivestats.model.PlayerIdentifier; import com.excuseme.rocketleaguelivestats.model.Statistics; @@ -9,13 +10,13 @@ import java.util.Set; public interface StatisticsRepository { - Statistics find(String playerId, String system); + Statistics find(String playerId, GamingSystem gamingSystem); default Map find(List playerIdentifiers) throws Exception { Map map = new HashMap<>(); - playerIdentifiers.forEach(p->map.put(p, find(p.getPlayerId(), p.getGamingSystem().getQualifier()))); + playerIdentifiers.forEach(p->map.put(p, find(p.getPlayerId(), p.getGamingSystem()))); return map; } - String createUrl(String playerId, String system); + String createUrl(String playerId, GamingSystem gamingSystem); } diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/APIStatisticsRepository.java b/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/APIStatisticsRepository.java new file mode 100644 index 0000000..9f0a7a3 --- /dev/null +++ b/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/APIStatisticsRepository.java @@ -0,0 +1,226 @@ +package com.excuseme.rocketleaguelivestats.repository.rocketleague; + + +import com.excuseme.rocketleaguelivestats.model.*; +import com.excuseme.rocketleaguelivestats.repository.StatisticsRepository; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.json.JSONConfiguration; +import org.codehaus.jackson.annotate.JsonCreator; +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class APIStatisticsRepository implements StatisticsRepository { + private final static String URL = "https://20kiyaost7.execute-api.us-west-2.amazonaws.com/prod"; + private static final String API_KEY = "wn6Xw8MfNP2hYvt8VOMla9q4YH6OAIGavvKhfRYj"; + + @Override + public Statistics find(String playerId, GamingSystem gamingSystem) { + if(!GamingSystem.BOT.equals(gamingSystem)) { + ClientConfig clientConfig = new DefaultClientConfig(); + clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + Client client = Client.create(clientConfig); + WebResource webResource = client.resource(URL); + Payload payLoad = webResource.queryParam("platform",gamingSystem.getApiId().toString()) + .queryParam("name", playerId) + .header("X-API-KEY", API_KEY) + .accept("application/json") + .get(Payload.class); + if(payLoad != null) { + Statistics statistics = new Statistics(); + Stat stat = findStat(payLoad.stats, "Ranked Duel 1v1"); + statistics.setOneVsOne(createRank(stat)); + stat = findStat(payLoad.stats, "Ranked Doubles 2v2"); + statistics.setTwoVsTwo(createRank(stat)); + stat = findStat(payLoad.stats, "Ranked Solo Standard 3v3"); + statistics.setThreeVSThreeSolo(createRank(stat)); + stat = findStat(payLoad.stats, "Ranked Standard 3v3"); + statistics.setThreeVsThree(createRank(stat)); + return statistics; + } + } + return null; + } + + private Rank createRank(Stat stat) { + if(stat == null) { + return new Rank(Tier.UNRANKED, null, null); + } + Pattern pattern = Pattern.compile("^\\[([IVX]+)\\]\\s(.*)$"); + Matcher matcher = pattern.matcher(stat.subLabel); + if(matcher.matches()) { + String romanNumerals = matcher.group(1); + int division = toArabic(romanNumerals); + + Optional first = Arrays.stream(Tier.values()).filter(t -> t.getText().equalsIgnoreCase(matcher.group(2))) + .findFirst(); + if(first.isPresent()) { + + return new Rank(first.get(), division, Integer.parseInt(stat.value)); + } + } + + return null; + } + + private Stat findStat(List stats, String label) { + if(stats != null) { + Optional first = stats.stream().filter(s -> label.equalsIgnoreCase(s.label)).findFirst(); + if(first.isPresent()) { + return first.get(); + } + } + return null; + } + + static int toArabic(String number) { + if ( "".equalsIgnoreCase(number)) return 0; + if (number.startsWith("M")) return 1000 + toArabic(number.substring(1)); + if (number.startsWith("CM")) return 900 + toArabic(number.substring(2)); + if (number.startsWith("D")) return 500 + toArabic(number.substring(1)); + if (number.startsWith("CD")) return 400 + toArabic(number.substring(2)); + if (number.startsWith("C")) return 100 + toArabic(number.substring(1)); + if (number.startsWith("XC")) return 90 + toArabic(number.substring(2)); + if (number.startsWith("L")) return 50 + toArabic(number.substring(1)); + if (number.startsWith("XL")) return 40 + toArabic(number.substring(2)); + if (number.startsWith("X")) return 10 + toArabic(number.substring(1)); + if (number.startsWith("IX")) return 9 + toArabic(number.substring(2)); + if (number.startsWith("V")) return 5 + toArabic(number.substring(1)); + if (number.startsWith("IV")) return 4 + toArabic(number.substring(2)); + if (number.startsWith("I")) return 1 + toArabic(number.substring(1)); + throw new IllegalArgumentException("something bad happened"); + } + @Override + public String createUrl(String playerId, GamingSystem gamingSystem) { + return null; + } + + @JsonIgnoreProperties(ignoreUnknown = true) + private static class Payload { + Integer platformId; + String platformName; + String platformShortName; + String platformUserHandle; + List stats; + @JsonCreator + public Payload() { + } + + public Integer getPlatformId() { + return platformId; + } + + public void setPlatformId(Integer platformId) { + this.platformId = platformId; + } + + public String getPlatformName() { + return platformName; + } + + public void setPlatformName(String platformName) { + this.platformName = platformName; + } + + public String getPlatformShortName() { + return platformShortName; + } + + public void setPlatformShortName(String platformShortName) { + this.platformShortName = platformShortName; + } + + public String getPlatformUserHandle() { + return platformUserHandle; + } + + public void setPlatformUserHandle(String platformUserHandle) { + this.platformUserHandle = platformUserHandle; + } + + public List getStats() { + return stats; + } + + public void setStats(List stats) { + this.stats = stats; + } + } + @JsonIgnoreProperties(ignoreUnknown = true) + private static class Stat { + String label; + String subLabel; + String category; + String value; + String rank; + String percentile; + String displayValue; + @JsonCreator + public Stat() { + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getSubLabel() { + return subLabel; + } + + public void setSubLabel(String subLabel) { + this.subLabel = subLabel; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getRank() { + return rank; + } + + public void setRank(String rank) { + this.rank = rank; + } + + public String getPercentile() { + return percentile; + } + + public void setPercentile(String percentile) { + this.percentile = percentile; + } + + public String getDisplayValue() { + return displayValue; + } + + public void setDisplayValue(String displayValue) { + this.displayValue = displayValue; + } + } +} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/RocketLeagueAPI.java b/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/RocketLeagueAPI.java deleted file mode 100644 index cecd0be..0000000 --- a/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/RocketLeagueAPI.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.excuseme.rocketleaguelivestats.repository.rocketleague; - -import com.excuseme.rocketleaguelivestats.model.GamingSystem; -import com.excuseme.rocketleaguelivestats.model.PlayerIdentifier; -import com.excuseme.rocketleaguelivestats.model.Statistics; -import com.excuseme.rocketleaguelivestats.repository.StatisticsRepository; -import com.excuseme.rocketleaguelivestats.scanner.model.SessionData; -import org.apache.http.Header; -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.*; -import java.util.stream.Collectors; - -public class RocketLeagueAPI implements StatisticsRepository { - public static final String ISSUER_ID = "0"; - private final String APPSPOT_URL = "psyonix-rl.appspot.com"; - private final String LOGIN_PATH = "/auth/"; - private final String COMMAND_PATH = "/callproc105/"; - private final String SECRET_KEY = "dUe3SE4YsR8B0c30E6r7F2KqpZSbGiVx"; - private final String CALL_PROC_KEY = "pX9pn8F4JnBpoO8Aa219QC6N7g18FJ0F"; - private final String BUILDID = "-1543484724"; - private CloseableHttpClient httpclient = HttpClients.createDefault(); - private SessionData sessionData; - private StatisticsParser statisticsParser = new StatisticsParser(); - - public RocketLeagueAPI(SessionData sessionData) { - this.sessionData = sessionData; - } - - public String login(String playerName, String playerId, String platform, String buildId, String authCode) throws URISyntaxException, IOException { - final URI uri = new URIBuilder().setScheme("https").setHost(APPSPOT_URL).setPath(LOGIN_PATH).build(); - - HttpPost httpPost = new HttpPost(uri); - httpPost.setHeader("Cache-Control", "no-cache"); - httpPost.setHeader("LoginSecretKey", SECRET_KEY); - httpPost.setHeader("Environment", "Prod"); - httpPost.setHeader("User-Agent", "UE3-TA,UE3Ver(10897)"); - final List postParameters = new ArrayList(); - postParameters.add(new BasicNameValuePair("PlayerName", playerName)); - postParameters.add(new BasicNameValuePair("PlayerID", playerId)); - postParameters.add(new BasicNameValuePair("Platform", platform)); - postParameters.add(new BasicNameValuePair("BuildID", buildId)); - postParameters.add(new BasicNameValuePair("AuthCode", authCode)); - postParameters.add(new BasicNameValuePair("IssuerID", ISSUER_ID)); - httpPost.setEntity(new UrlEncodedFormEntity(postParameters)); - final CloseableHttpResponse response = httpclient.execute(httpPost); - final Header[] sessionIDs = response.getHeaders("SessionID"); - if (sessionIDs != null && sessionIDs.length == 1) { - return sessionIDs[0].getValue(); - } - throw new IllegalArgumentException("No session found"); - } - - private String doRequest(String sessionID, Command command) throws URISyntaxException, IOException { - final URI uri = new URIBuilder().setScheme("https").setHost(APPSPOT_URL).setPath(COMMAND_PATH) - .build(); - HttpPost httpPost = new HttpPost(uri); - setHeaders(httpPost, sessionID); - final List nameValuePairs = encodeCommand(command); - httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); - final CloseableHttpResponse response = httpclient.execute(httpPost); - final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - response.getEntity().writeTo(outputStream); - return outputStream.toString(); - } - - private void setHeaders(HttpPost httpPost, String sessionID) { - httpPost.setHeader("Cache-Control", "no-cache"); - httpPost.setHeader("Environment", "Prod"); - httpPost.setHeader("SessionID", sessionID); - httpPost.setHeader("CallProcKey", CALL_PROC_KEY); - httpPost.setHeader("User-Agent", "UE3-TA,UE3Ver(10897)"); - httpPost.setHeader("Context-Type", "application/x-www-form-urlencoded"); - httpPost.setHeader("DBVersion", "00.03.0011-00.01.0011"); - httpPost.setHeader("DB", "BattleCars_Prod"); - } - - private List encodeCommand(Command command) { - final ArrayList nameValuePairs = new ArrayList(); - nameValuePairs.add(new BasicNameValuePair("Proc[]", command.getName())); - if (command.getParameters() != null) { - for (int i = 0; i < command.getParameters().size(); i++) { - nameValuePairs.add(new BasicNameValuePair(String.format("P%sP[]", i), command.getParameters().get(i))); - } - } - return nameValuePairs; - } - - @Override - public Map find(List playerIdentifiers) throws Exception { - final String steamId = sessionData.getOwnPlayer().getSteamId(); - final String sessionId = login("", steamId, "Steam", sessionData.getBuildId(), sessionData.getAuthCode()); - final List commandList = playerIdentifiers.stream().map(p -> { - if (GamingSystem.STEAM.equals(p.getGamingSystem())) { - return new Command("GetPlayerSkillSteam", Arrays.asList(p.getPlayerId()), p); - } else if (GamingSystem.PS4.equals(p.getGamingSystem())) { - return new Command("GetPlayerSkillPS4", Arrays.asList(p.getPlayerId()), p); - } - return null; - }).filter(Objects::nonNull).collect(Collectors.toList()); - final Map playerIdentifierStatisticsHashMap = new HashMap<>(); - commandList.stream().forEach(c -> { - try { - final String result = doRequest(sessionId, c); - Statistics statistics = parseResult(result); - playerIdentifierStatisticsHashMap.put(c.getPlayerIdentifier(), statistics); - } catch (URISyntaxException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - }); - - return playerIdentifierStatisticsHashMap; - } - - private Statistics parseResult(String result) throws UnsupportedEncodingException { - return statisticsParser.parse(result); - } - - @Override - public Statistics find(String playerId, String system) { - return null; - } - - - @Override - public String createUrl(String playerId, String system) { - return null; - } - - - private class Command { - private final String name; - private final List parameters; - private PlayerIdentifier playerIdentifier; - private Command(String name, List parameters, PlayerIdentifier playerIdentifier) { - this.name = name; - this.parameters = parameters; - this.playerIdentifier = playerIdentifier; - } - - public String getName() { - return name; - } - - public List getParameters() { - return parameters; - } - - public PlayerIdentifier getPlayerIdentifier() { - return playerIdentifier; - } - - } -} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/StatisticsParser.java b/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/StatisticsParser.java deleted file mode 100644 index 9ac36a3..0000000 --- a/src/main/java/com/excuseme/rocketleaguelivestats/repository/rocketleague/StatisticsParser.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.excuseme.rocketleaguelivestats.repository.rocketleague; - -import com.excuseme.rocketleaguelivestats.model.*; - -import java.io.UnsupportedEncodingException; -import java.math.BigDecimal; -import java.net.URLDecoder; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class StatisticsParser { - private static final Pattern PLAYLIST_PATTERN = Pattern.compile("^Playlist=(\\d+)&Mu=(\\d*\\.?\\d*)&Sigma=(\\d*\\.?\\d*)&Tier=(\\d+)&Division=(\\d+)&MatchesPlayed=(\\d+)&MMR=(\\d*\\.?\\d*)$"); - - public Statistics parse(String text) throws UnsupportedEncodingException { - if(text == null || "".equals(text)) { - return null; - } - final String[] lines = text.split("\\n|\\r"); - final Statistics statistics = new Statistics(); - - statistics.setOneVsOne(new Rank(Tier.UNRANKED, null)); - statistics.setTwoVsTwo(new Rank(Tier.UNRANKED, null)); - statistics.setThreeVSThreeSolo(new Rank(Tier.UNRANKED, null)); - statistics.setThreeVsThree(new Rank(Tier.UNRANKED, null)); - - for (String line : lines) { - final Matcher matcher = PLAYLIST_PATTERN.matcher(line); - if (matcher.matches()) { - final PlaylistType playlistType = PlaylistType.findByPlaylistId(Integer.parseInt(matcher.group(1))); - if (playlistType.isRanked()) { - Rank rank = parseLine(matcher); - switch (playlistType) { - case DUEL_RANKED: - statistics.setOneVsOne(rank); - break; - case DOUBLES_RANKED: - statistics.setTwoVsTwo(rank); - break; - case SOLO_STANDARD_RANKED: - statistics.setThreeVSThreeSolo(rank); - break; - case STANDARD_RANKED: - statistics.setThreeVsThree(rank); - break; - } - } - - } - } - - return statistics; - } - - private Rank parseLine(Matcher matcher) throws UnsupportedEncodingException { - BigDecimal mu = new BigDecimal(matcher.group(2)); - BigDecimal sigma = new BigDecimal(matcher.group(3)); - BigDecimal mmr = new BigDecimal(matcher.group(7)); - Tier tier = Tier.findByTier( Integer.parseInt(matcher.group(4))); - Integer division = Integer.parseInt(matcher.group(5))+1; - Integer matchesPlayed = Integer.parseInt(matcher.group(6)); - - final Skill skill = new Skill(mu, sigma, mmr, matchesPlayed); - final Rank rank = new Rank(tier, division); - rank.setSkill(skill); - return rank; - } -} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/TailingFileScanner.java b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/TailingFileScanner.java index 07f7732..a43d9e6 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/TailingFileScanner.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/TailingFileScanner.java @@ -11,12 +11,11 @@ public class TailingFileScanner { public static final int DELAY_MILLIS = 1000; - private List> matchers = Arrays.asList(new EventLineMatcher(), new LoadoutValidationLineMatcher(), - new NamePlateDataLineMatcher(), new RegisterPlayerWithSessionLineMatcher(), new HandlePlayerRemovedLineMatcher(), new GameTypeLineMatcher()); + private List> matchers = Arrays.asList(new EventLineMatcher(), new LoadoutValidationLineMatcher() + , new RegisterPlayerWithSessionLineMatcher(), new HandlePlayerRemovedLineMatcher(), new GameTypeLineMatcher()); private OwnPlayerLineMatcher ownPlayerLineMatcher; private BuildIdLineMatcher buildIdLineMatcher; - private AuthCodeMatcher authCodeMatcher; private GameDataListener gameDataListener; public TailingFileScanner(GameDataListener gameDataListener, File file) { @@ -28,7 +27,6 @@ public TailingFileScanner(GameDataListener gameDataListener, File file) { thread.start(); ownPlayerLineMatcher = new OwnPlayerLineMatcher(); buildIdLineMatcher = new BuildIdLineMatcher(); - authCodeMatcher = new AuthCodeMatcher(); } public class MyTailerListener extends TailerListenerAdapter { @@ -47,7 +45,6 @@ public void fileRotated() { @Override public void endOfFile() { if(recentValidData != null && !recentValidData.isEmpty()) { - gameDataListener.sessionDataChanged(sessionData); gameDataListener.gameDataChanged(recentValidData); } } @@ -65,10 +62,6 @@ public void handle(String line) { sessionData.setOwnPlayer(match); } } - final String match = authCodeMatcher.match(line); - if(match != null) { - sessionData.setAuthCode(match); - } GameData newGameData = scanLine(line, gameData != null ? gameData.clone() : null); if(newGameData != null) { gameData = newGameData; @@ -95,9 +88,6 @@ private GameData scanLine(String line, GameData gameData) { return gameData; } - } else if (NamePlate.class.isInstance(match)) { - gameData.addNamePlate(NamePlate.class.cast(match)); - return gameData; } else if (PlayerName.class.isInstance(match)) { gameData.addPlayerName(PlayerName.class.cast(match)); return gameData; diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/matcher/AuthCodeMatcher.java b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/matcher/AuthCodeMatcher.java deleted file mode 100644 index 566755a..0000000 --- a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/matcher/AuthCodeMatcher.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.excuseme.rocketleaguelivestats.scanner.matcher; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class AuthCodeMatcher implements LineMatcher { - private static final Pattern SEND_LOGIN_REQUEST = Pattern.compile("^\\[.*\\] Auth: SendLoginRequest PlatformAuthorizationCode=(.*)$"); - private static final Pattern HANDLE_RECEIVED_AUTH_CODE = Pattern.compile("^\\[.*\\] Auth: HandleReceivedAuthorizationCode bSuccess=True AuthorizationCode==(.*)$"); - - @Override - public String match(String line) { - final Matcher matcher = SEND_LOGIN_REQUEST.matcher(line); - if(matcher.matches()) { - return matcher.group(1); - } - final Matcher matcher2 = HANDLE_RECEIVED_AUTH_CODE.matcher(line); - if(matcher2.matches()) { - return matcher2.group(1); - } - return null; - } -} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/matcher/NamePlateDataLineMatcher.java b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/matcher/NamePlateDataLineMatcher.java deleted file mode 100644 index a909538..0000000 --- a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/matcher/NamePlateDataLineMatcher.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.excuseme.rocketleaguelivestats.scanner.matcher; - -import com.excuseme.rocketleaguelivestats.scanner.model.NamePlate; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class NamePlateDataLineMatcher implements LineMatcher { - private static final Pattern PATTERN = Pattern.compile("^\\[\\d*\\.?\\d*\\] Nameplate: RefreshNameplates NameplateData (.*) Row=(\\d*)$"); - - public NamePlate match(String line) { - final Matcher matcher = PATTERN.matcher(line); - if(matcher.matches()) { - return new NamePlate(matcher.group(1), Integer.parseInt(matcher.group(2).replace("'",""))); - } - return null; - } - -} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/GameData.java b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/GameData.java index a08ee34..e5806b3 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/GameData.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/GameData.java @@ -5,7 +5,6 @@ public class GameData { private String identifier; - private Set namePlates; private Set playerNames; private Set playerIds; private Set playerRemoveds; @@ -15,7 +14,6 @@ public class GameData { public GameData(String identifier) { this.identifier = identifier; - namePlates = new HashSet(); playerNames = new HashSet(); playerIds = new HashSet(); playerRemoveds = new HashSet(); @@ -25,7 +23,6 @@ public GameData(String identifier) { private GameData(GameData gameData) { this.identifier = gameData.identifier; - namePlates = gameData.namePlates; playerNames = gameData.playerNames; playerIds = gameData.playerIds; playerRemoveds = gameData.playerRemoveds; @@ -34,16 +31,6 @@ private GameData(GameData gameData) { ownPlayer = gameData.ownPlayer; } - - public void addNamePlate(NamePlate namePlate) { - if(!ended) { - if (namePlates.contains(namePlate)) { - namePlates.remove(namePlate); - } - namePlates.add(namePlate); - } - } - public void addPlayerName(PlayerName playerName) { if(!ended) { if (playerNames.contains(playerName)) { @@ -74,7 +61,6 @@ public boolean equals(Object o) { if (ended != gameData.ended) return false; if (identifier != null ? !identifier.equals(gameData.identifier) : gameData.identifier != null) return false; - if (namePlates != null ? !namePlates.equals(gameData.namePlates) : gameData.namePlates != null) return false; if (playerNames != null ? !playerNames.equals(gameData.playerNames) : gameData.playerNames != null) return false; if (playerIds != null ? !playerIds.equals(gameData.playerIds) : gameData.playerIds != null) return false; @@ -87,7 +73,6 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = identifier != null ? identifier.hashCode() : 0; - result = 31 * result + (namePlates != null ? namePlates.hashCode() : 0); result = 31 * result + (playerNames != null ? playerNames.hashCode() : 0); result = 31 * result + (playerIds != null ? playerIds.hashCode() : 0); result = 31 * result + (playerRemoveds != null ? playerRemoveds.hashCode() : 0); @@ -100,7 +85,6 @@ public int hashCode() { public String toString() { return "GameData{" + "identifier='" + identifier + '\'' + - ", namePlates=" + namePlates + ", playerNames=" + playerNames + ", playerIds=" + playerIds + ", playerRemoveds=" + playerRemoveds + @@ -109,9 +93,6 @@ public String toString() { '}'; } - public Set getNamePlates() { - return namePlates; - } public Set getPlayerNames() { return playerNames; @@ -126,7 +107,7 @@ public Set getPlayerRemoveds() { } public boolean isEmpty() { - return namePlates.isEmpty() || playerNames.isEmpty() || playerIds.isEmpty(); + return playerNames.isEmpty() || playerIds.isEmpty(); } diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/NamePlate.java b/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/NamePlate.java deleted file mode 100644 index f519b9a..0000000 --- a/src/main/java/com/excuseme/rocketleaguelivestats/scanner/model/NamePlate.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.excuseme.rocketleaguelivestats.scanner.model; - -public class NamePlate { - private String name; - private int row; - - public NamePlate(String name, int row) { - this.name = name; - this.row = row; - } - - public String getName() { - return name; - } - - public int getRow() { - return row; - } - - @Override - public String toString() { - return "NamePlate{" + - "name='" + name + '\'' + - ", row=" + row + - '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - NamePlate namePlate = (NamePlate) o; - - return name != null ? name.equals(namePlate.name) : namePlate.name == null; - - } - - @Override - public int hashCode() { - return name != null ? name.hashCode() : 0; - } -} diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/view/MainTableView.java b/src/main/java/com/excuseme/rocketleaguelivestats/view/MainTableView.java index 6a36129..161ca02 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/view/MainTableView.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/view/MainTableView.java @@ -231,10 +231,6 @@ public void run() { } - @Override - public void sessionDataChanged(SessionData sessionData) { - statisticsRepository.updateSessionData(sessionData); - } @Override public void gameDataChanged(GameData gameData) { diff --git a/src/main/java/com/excuseme/rocketleaguelivestats/view/TableViewFactory.java b/src/main/java/com/excuseme/rocketleaguelivestats/view/TableViewFactory.java index d9b8a89..cd07a71 100644 --- a/src/main/java/com/excuseme/rocketleaguelivestats/view/TableViewFactory.java +++ b/src/main/java/com/excuseme/rocketleaguelivestats/view/TableViewFactory.java @@ -2,8 +2,8 @@ import com.excuseme.rocketleaguelivestats.model.GamingSystem; import com.excuseme.rocketleaguelivestats.model.Rank; -import com.excuseme.rocketleaguelivestats.model.Skill; import com.excuseme.rocketleaguelivestats.view.model.PlayerViewModel; +import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Pos; @@ -49,10 +49,12 @@ public static TableView create() { table.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { - if(oldValue != null) ((PlayerViewModel) oldValue).setExpand(false); - if(newValue != null) ((PlayerViewModel) newValue).setExpand(true); - ((TableColumn) table.getColumns().get(0)).setVisible(false); - ((TableColumn) table.getColumns().get(0)).setVisible(true); + Platform.runLater(() -> { + if(oldValue != null) ((PlayerViewModel) oldValue).setExpand(false); + if(newValue != null) ((PlayerViewModel) newValue).setExpand(true); + ((TableColumn) table.getColumns().get(0)).setVisible(false); + ((TableColumn) table.getColumns().get(0)).setVisible(true); + }); } }); final Callback, TableCell> styleNotActive = new Callback, TableCell>() { @@ -116,22 +118,8 @@ protected void updateItem(Rank rank, boolean empty) { if (rank.getDivision() != null) { stringBuilder.append("\nDivision: ").append(rank.getDivision()); } - final Skill skill = rank.getSkill(); - if(skill != null) { - if (skill.getMmr() != null) { - stringBuilder.append("\nMMR: ").append(skill.getMmr().toString()); - } - if(playerViewModel.getExpand()) { - if (skill.getMu() != null) { - stringBuilder.append("\nMu: ").append(skill.getMu().toString()); - } - if (skill.getSigma() != null) { - stringBuilder.append("\nSigma: ").append(skill.getSigma().toString()); - } - if (skill.getMatchesPlayed() != null) { - stringBuilder.append("\nMatches played: ").append(skill.getMatchesPlayed().toString()); - } - } + if(rank.getRating() != null) { + stringBuilder.append("\nRating: ").append(rank.getRating()); } } } @@ -163,21 +151,14 @@ public TableCell call(TableColumn lines = IOUtils.readLines(Thread.currentThread().getContextClassLoader().getResourceAsStream("auth_codes.txt")); - final List patterns = IOUtils.readLines(Thread.currentThread().getContextClassLoader().getResourceAsStream("auth_code_pattern.txt")); - - final int max = lines.stream().mapToInt(String::length).max().getAsInt(); - - final StringBuilder stringBuilder = new StringBuilder(); - - for(int i = 0; i set = lines.stream().map(l -> l.charAt(index)).collect(Collectors.toSet()); - if(set.size() == 1) { - stringBuilder.append(set.iterator().next()); - } else { - stringBuilder.append("x"); - } - } - assertEquals(patterns.get(0), stringBuilder.toString()); - } - - @Test - public void hex() { - System.out.println(Hex.encodeHexString("160212.65765.127596".getBytes())); - } - - @Test - public void unhex() throws DecoderException { - System.out.println(Hex.decodeHex("2858B5391813211F".toCharArray())); - } -} diff --git a/src/test/java/com/excuseme/rocketleaguelivestats/scanner/NamePlateDataLineMatcherTest.java b/src/test/java/com/excuseme/rocketleaguelivestats/scanner/NamePlateDataLineMatcherTest.java deleted file mode 100644 index 8ab552c..0000000 --- a/src/test/java/com/excuseme/rocketleaguelivestats/scanner/NamePlateDataLineMatcherTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.excuseme.rocketleaguelivestats.scanner; - -import com.excuseme.rocketleaguelivestats.scanner.matcher.NamePlateDataLineMatcher; -import com.excuseme.rocketleaguelivestats.scanner.model.NamePlate; -import org.junit.Test; - -import static org.junit.Assert.*; - -public class NamePlateDataLineMatcherTest { - - private final NamePlateDataLineMatcher namePlateDataLineMatcher = new NamePlateDataLineMatcher(); - @Test - public void testMatch() throws Exception { - NamePlate namePlate = namePlateDataLineMatcher.match("[0051.72] Nameplate: RefreshNameplates NameplateData Excuse Me Row=0"); - assertNotNull(namePlate); - assertEquals("Excuse Me", namePlate.getName()); - assertEquals(0, namePlate.getRow()); - namePlate = namePlateDataLineMatcher.match("[0092.43] Nameplate: RefreshNameplates NameplateData bo-kw-saleen Row=3"); - assertNotNull(namePlate); - assertEquals("bo-kw-saleen", namePlate.getName()); - assertEquals(3, namePlate.getRow()); - } -} \ No newline at end of file