22
33import com .google .gson .Gson ;
44import com .google .gson .GsonBuilder ;
5+ import com .google .gson .JsonObject ;
56import generated .*;
67import org .apache .http .client .config .RequestConfig ;
78import org .apache .http .client .entity .EntityBuilder ;
@@ -83,11 +84,13 @@ public class ClientApi {
8384 "lol-simple-dialog-messages" ,
8485 "lol-spectator" ,
8586 "lol-suggested-players" ,
86- "lol-trophies"
87+ "lol-trophies" ,
88+ "liveclientdata"
8789 );
8890 private static final Pattern INSTALL_DIR =
8991 Pattern .compile (".+\" --install-directory=([()a-zA-Z_0-9- :.\\ \\ /]+)\" .+" );
9092 private static final Gson GSON = new GsonBuilder ().create ();
93+ private static final int LIVE_PORT = 2999 ;
9194 /**
9295 * Enabled 'legacy' mode
9396 */
@@ -227,6 +230,13 @@ public ClientApi(String clientPath, int connectTimeout, int readTimeout) {
227230 start ();
228231 }
229232
233+ /**
234+ * @return a {@code java.lang.String} that points to the League of Legends client directory
235+ */
236+ public String getClientPath () {
237+ return clientPath ;
238+ }
239+
230240 /**
231241 * Adds client connection listener
232242 */
@@ -516,20 +526,33 @@ public boolean isAuthorized() throws IOException {
516526 }
517527
518528 public String getSwaggerJson () throws IOException {
519- return dumpHttpRequest (getConnection ("/swagger/v2/swagger.json" , new HttpGet ()));
529+ return dumpHttpRequest (getConnection ("/swagger/v2/swagger.json" , port , new HttpGet ()));
520530 }
521531
522532 public String getOpenapiJson () throws IOException {
523- return dumpHttpRequest (getConnection ("/swagger/v3/openapi.json" , new HttpGet ()));
533+ return dumpHttpRequest (getConnection ("/swagger/v3/openapi.json" , port , new HttpGet ()));
534+ }
535+
536+ public String getLiveSwaggerJson () throws IOException {
537+ return dumpHttpRequest (getConnection ("/swagger/v2/swagger.json" , LIVE_PORT , new HttpGet ()));
538+ }
539+
540+ public String getLiveOpenapiJson () throws IOException {
541+ return dumpHttpRequest (getConnection ("/swagger/v3/openapi.json" , LIVE_PORT , new HttpGet ()));
524542 }
525543
526544 public <T > T executeGet (String path , Class <T > clz ) throws IOException {
527- HttpGet conn = getConnection (path , new HttpGet ());
545+ HttpGet conn = getConnection (path , port , new HttpGet ());
546+ return getResponseObject (clz , conn );
547+ }
548+
549+ public <T > T executeLiveGet (String path , Class <T > clz ) throws IOException {
550+ HttpGet conn = getConnection (path , LIVE_PORT , new HttpGet ());
528551 return getResponseObject (clz , conn );
529552 }
530553
531554 public InputStream executeBinaryGet (String path ) throws IOException {
532- HttpGet conn = getConnection (path , new HttpGet ());
555+ HttpGet conn = getConnection (path , port , new HttpGet ());
533556 CloseableHttpResponse response = client .execute (conn );
534557 boolean b = response .getStatusLine ().getStatusCode () == 200 ;
535558 if (!b ) {
@@ -540,45 +563,45 @@ public InputStream executeBinaryGet(String path) throws IOException {
540563 }
541564
542565 public <T > T executeGet (String path , Class <T > clz , String ... queryParams ) throws IOException {
543- HttpGet conn = getConnection (path , new HttpGet (), queryParams );
566+ HttpGet conn = getConnection (path , port , new HttpGet (), queryParams );
544567 return getResponseObject (clz , conn );
545568 }
546569
547570 public boolean executePut (String path , Object jsonObject ) throws IOException {
548- HttpPut conn = getConnection (path , new HttpPut ());
571+ HttpPut conn = getConnection (path , port , new HttpPut ());
549572 addJsonBody (jsonObject , conn );
550573 return isOk (conn );
551574 }
552575
553576 public <T > T executePost (String path , Object jsonObject , Class <T > clz ) throws IOException {
554- HttpPost conn = getConnection (path , new HttpPost ());
577+ HttpPost conn = getConnection (path , port , new HttpPost ());
555578 addJsonBody (jsonObject , conn );
556579 return getResponseObject (clz , conn );
557580 }
558581
559582 public <T > T executePost (String path , Class <T > clz ) throws IOException {
560- HttpPost conn = getConnection (path , new HttpPost ());
583+ HttpPost conn = getConnection (path , port , new HttpPost ());
561584 return getResponseObject (clz , conn );
562585 }
563586
564587 public boolean executePost (String path , Object jsonObject ) throws IOException {
565- HttpPost conn = getConnection (path , new HttpPost ());
588+ HttpPost conn = getConnection (path , port , new HttpPost ());
566589 addJsonBody (jsonObject , conn );
567590 return isOk (conn );
568591 }
569592
570593 public boolean executePatch (String path , Object jsonObject ) throws IOException {
571- HttpPatch conn = getConnection (path , new HttpPatch ());
594+ HttpPatch conn = getConnection (path , port , new HttpPatch ());
572595 addJsonBody (jsonObject , conn );
573596 return isOk (conn );
574597 }
575598
576599 public boolean executePost (String path ) throws IOException {
577- return isOk (getConnection (path , new HttpPost ()));
600+ return isOk (getConnection (path , port , new HttpPost ()));
578601 }
579602
580603 public boolean executeDelete (String path ) throws IOException {
581- return isOk (getConnection (path , new HttpDelete ()));
604+ return isOk (getConnection (path , port , new HttpDelete ()));
582605 }
583606
584607 private <T extends HttpEntityEnclosingRequestBase > void addJsonBody (Object jsonObject , T method ) {
@@ -619,7 +642,7 @@ private <T extends HttpRequestBase> boolean isOk(T method) throws IOException {
619642 * @param method Base request
620643 * @param queryParams Pairs of get parameters. Must be divisible by 2.
621644 */
622- private <T extends HttpRequestBase > T getConnection (String endpoint , T method , String ... queryParams ) {
645+ private <T extends HttpRequestBase > T getConnection (String endpoint , int port , T method , String ... queryParams ) {
623646 if (!connected .get ()) {
624647 throw new IllegalStateException ("API not connected!" );
625648 }
@@ -641,7 +664,7 @@ private <T extends HttpRequestBase> T getConnection(String endpoint, T method, S
641664 sb .append (queryParams [i ]).append ("=" ).append (queryParams [i + 1 ]);
642665 }
643666 URI uri = new URI (sb .toString ());
644- if (!disableEndpointWarnings .get ()) {
667+ if (!disableEndpointWarnings .get () && uri . getPath (). substring ( 1 ). indexOf ( '/' ) != - 1 ) {
645668 String path = uri .getPath ().substring (1 , uri .getPath ().substring (1 ).indexOf ('/' ) + 1 );
646669 if (!ALLOWED_ENDPOINTS .contains (path )) {
647670 System .err .println (
@@ -669,6 +692,14 @@ public LolRsoAuthAuthorization getAuth() throws IOException {
669692 return executeGet ("/rso-auth/v1/authorization" , LolRsoAuthAuthorization .class );
670693 }
671694
695+ /**
696+ * @deprecated Will be removed someday. It should be moved and organized.
697+ */
698+ @ Deprecated
699+ public JsonObject getLiveGameData () throws IOException {
700+ return executeGet ("/liveclientdata/allgamedata" , JsonObject .class );
701+ }
702+
672703 /**
673704 * @deprecated Will be removed someday. It should be moved and organized.
674705 */
0 commit comments