Remove old session service and replace usages with new one
The new service was split off into a separate repository
This commit is contained in:
@@ -42,7 +42,7 @@ public class RuneLiteAPI
|
|||||||
public static final OkHttpClient CLIENT = new OkHttpClient();
|
public static final OkHttpClient CLIENT = new OkHttpClient();
|
||||||
public static final Gson GSON = new Gson();
|
public static final Gson GSON = new Gson();
|
||||||
|
|
||||||
private static final String BASE = "https://api.runelite.net/runelite-";
|
private static final String BASE = "https://api.runelite.net";
|
||||||
private static final String WSBASE = "wss://api.runelite.net/runelite-";
|
private static final String WSBASE = "wss://api.runelite.net/runelite-";
|
||||||
private static final String STATICBASE = "https://static.runelite.net";
|
private static final String STATICBASE = "https://static.runelite.net";
|
||||||
private static final Properties properties = new Properties();
|
private static final Properties properties = new Properties();
|
||||||
@@ -69,9 +69,14 @@ public class RuneLiteAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HttpUrl getApiRoot()
|
||||||
|
{
|
||||||
|
return HttpUrl.parse(BASE);
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpUrl getApiBase()
|
public static HttpUrl getApiBase()
|
||||||
{
|
{
|
||||||
return HttpUrl.parse(BASE + getVersion());
|
return HttpUrl.parse(BASE + "/runelite-" + getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpUrl getStaticBase()
|
public static HttpUrl getStaticBase()
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package net.runelite.http.service.session;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.UUID;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import net.runelite.http.service.ws.SessionManager;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/session")
|
|
||||||
public class SessionController
|
|
||||||
{
|
|
||||||
private final SessionService sessionService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SessionController(SessionService sessionService)
|
|
||||||
{
|
|
||||||
this.sessionService = sessionService;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSession(HttpServletRequest request, UUID uuid)
|
|
||||||
{
|
|
||||||
String addr = request.getRemoteAddr();
|
|
||||||
Instant now = Instant.now();
|
|
||||||
SessionEntry sessionEntry = new SessionEntry();
|
|
||||||
sessionEntry.setUuid(uuid);
|
|
||||||
sessionEntry.setIp(addr);
|
|
||||||
sessionEntry.setStart(now);
|
|
||||||
sessionEntry.setLast(now);
|
|
||||||
sessionService.createSession(sessionEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping
|
|
||||||
public UUID get(HttpServletRequest request)
|
|
||||||
{
|
|
||||||
UUID uuid = UUID.randomUUID();
|
|
||||||
createSession(request, uuid);
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/ping")
|
|
||||||
public ResponseEntity ping(HttpServletRequest request, @RequestParam("session") UUID uuid)
|
|
||||||
{
|
|
||||||
int updated = sessionService.updateLast(uuid);
|
|
||||||
if (updated == 0)
|
|
||||||
{
|
|
||||||
// create the session anyway
|
|
||||||
createSession(request, uuid);
|
|
||||||
return ResponseEntity.ok().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.ok().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping
|
|
||||||
public ResponseEntity delete(@RequestParam("session") UUID uuid)
|
|
||||||
{
|
|
||||||
int deleted = sessionService.deleteSession(uuid);
|
|
||||||
if (deleted == 0)
|
|
||||||
{
|
|
||||||
return ResponseEntity.notFound().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.ok().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/count")
|
|
||||||
public int count()
|
|
||||||
{
|
|
||||||
return sessionService.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/wscount")
|
|
||||||
public int wscount()
|
|
||||||
{
|
|
||||||
return SessionManager.getCount();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package net.runelite.http.service.session;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.UUID;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class SessionEntry
|
|
||||||
{
|
|
||||||
private int id;
|
|
||||||
private UUID uuid;
|
|
||||||
private String ip;
|
|
||||||
private Instant start;
|
|
||||||
private Instant last;
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
package net.runelite.http.service.session;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.UUID;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.sql2o.Connection;
|
|
||||||
import org.sql2o.Sql2o;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SessionService
|
|
||||||
{
|
|
||||||
private final Sql2o sql2o;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public SessionService(
|
|
||||||
@Qualifier("Runelite SQL2O") Sql2o sql2o
|
|
||||||
)
|
|
||||||
{
|
|
||||||
this.sql2o = sql2o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createSession(SessionEntry session)
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
con.createQuery("insert into session (uuid, ip, start, last) "
|
|
||||||
+ "values (:uuid, :ip, :start, :last)")
|
|
||||||
.addParameter("uuid", session.getUuid().toString())
|
|
||||||
.addParameter("ip", session.getIp())
|
|
||||||
.addParameter("start", session.getStart())
|
|
||||||
.addParameter("last", session.getLast())
|
|
||||||
.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public SessionEntry findSessionByUUID(UUID id)
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
return con.createQuery("select uuid, ip, start, last from session where uuid = :uuid")
|
|
||||||
.addParameter("uuid", id.toString())
|
|
||||||
.executeAndFetchFirst(SessionEntry.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int deleteSession(UUID id)
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
return con.createQuery("delete from session where uuid = :uuid")
|
|
||||||
.addParameter("uuid", id.toString())
|
|
||||||
.executeUpdate()
|
|
||||||
.getResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int updateLast(UUID session)
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
Instant last = Instant.now();
|
|
||||||
return con.createQuery("update session set last = :last where uuid = :uuid")
|
|
||||||
.addParameter("last", last)
|
|
||||||
.addParameter("uuid", session.toString())
|
|
||||||
.executeUpdate()
|
|
||||||
.getResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deleteExpired()
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
con.createQuery("delete from session where last + interval 11 minute < current_timestamp()")
|
|
||||||
.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCount()
|
|
||||||
{
|
|
||||||
try (Connection con = sql2o.open())
|
|
||||||
{
|
|
||||||
return con.createQuery("select count(*) from session")
|
|
||||||
.executeScalar(Integer.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 60000)
|
|
||||||
public void expire()
|
|
||||||
{
|
|
||||||
deleteExpired();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
-- MySQL dump 10.16 Distrib 10.2.9-MariaDB, for Linux (x86_64)
|
|
||||||
--
|
|
||||||
-- Host: localhost Database: runelite
|
|
||||||
-- ------------------------------------------------------
|
|
||||||
-- Server version 10.2.9-MariaDB
|
|
||||||
|
|
||||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
|
||||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
|
||||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
|
||||||
/*!40101 SET NAMES utf8 */;
|
|
||||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
|
||||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
|
||||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
|
||||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
|
||||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
|
||||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Table structure for table `session`
|
|
||||||
--
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `session`;
|
|
||||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
|
||||||
/*!40101 SET character_set_client = utf8 */;
|
|
||||||
CREATE TABLE `session` (
|
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`uuid` varchar(36) NOT NULL,
|
|
||||||
`ip` varchar(39) NOT NULL,
|
|
||||||
`start` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
|
||||||
`last` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
|
|
||||||
PRIMARY KEY (`id`),
|
|
||||||
UNIQUE KEY `uuid` (`uuid`),
|
|
||||||
KEY `last` (`last`)
|
|
||||||
) ENGINE=MEMORY DEFAULT CHARSET=latin1;
|
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
|
||||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
|
||||||
|
|
||||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
|
||||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
|
||||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
|
||||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
|
||||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
|
||||||
|
|
||||||
-- Dump completed on 2018-03-02 13:23:39
|
|
||||||
@@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.http.api.session.SessionClient;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package net.runelite.http.api.session;
|
package net.runelite.client;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -35,11 +35,11 @@ import okhttp3.Request;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
public class SessionClient
|
class SessionClient
|
||||||
{
|
{
|
||||||
public UUID open() throws IOException
|
UUID open() throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder()
|
||||||
.addPathSegment("session")
|
.addPathSegment("session")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ public class SessionClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ping(UUID uuid) throws IOException
|
void ping(UUID uuid) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder()
|
||||||
.addPathSegment("session")
|
.addPathSegment("session")
|
||||||
.addPathSegment("ping")
|
.addPathSegment("ping")
|
||||||
.addQueryParameter("session", uuid.toString())
|
.addQueryParameter("session", uuid.toString())
|
||||||
@@ -81,9 +81,9 @@ public class SessionClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(UUID uuid) throws IOException
|
void delete(UUID uuid) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getApiRoot().newBuilder()
|
||||||
.addPathSegment("session")
|
.addPathSegment("session")
|
||||||
.addQueryParameter("session", uuid.toString())
|
.addQueryParameter("session", uuid.toString())
|
||||||
.build();
|
.build();
|
||||||
Reference in New Issue
Block a user