From bdf9013864cca4d9e25a1f78efc9e5a3a158ead5 Mon Sep 17 00:00:00 2001 From: TheRealNull Date: Wed, 15 Jan 2020 03:52:51 -0500 Subject: [PATCH] project: remove modules to be externalized --- cache-client/cache-client.gradle.kts | 49 -- .../cache/client/ArchiveResponseHandler.java | 48 -- .../runelite/cache/client/CacheClient.java | 486 ----------------- .../cache/client/CacheClientHandler.java | 49 -- .../runelite/cache/client/ClientState.java | 31 -- .../cache/client/DownloadWatcher.java | 33 -- .../net/runelite/cache/client/FileResult.java | 92 ---- .../client/HandshakeResponseHandler.java | 81 --- .../net/runelite/cache/client/IndexInfo.java | 101 ---- .../cache/client/PendingFileRequest.java | 56 -- .../cache/client/CacheClientTest.java | 74 --- cache-updater/cache-updater.gradle.kts | 40 -- cache-updater/schema.sql | 118 ---- .../cache/updater/CacheConfiguration.java | 77 --- .../net/runelite/cache/updater/CacheDAO.java | 177 ------ .../runelite/cache/updater/CacheStorage.java | 144 ----- .../runelite/cache/updater/CacheUpdater.java | 173 ------ .../runelite/cache/updater/CacheUploader.java | 97 ---- .../cache/updater/InstantConverter.java | 48 -- .../cache/updater/beans/ArchiveEntry.java | 38 -- .../cache/updater/beans/CacheEntry.java | 36 -- .../cache/updater/beans/FileEntry.java | 36 -- .../cache/updater/beans/IndexEntry.java | 36 -- .../src/main/resources/application.yaml | 16 - .../http-service-openosrs.gradle.kts | 53 -- .../service/SpringBootWebApplication.java | 203 ------- .../http/service/SpringWebMvcConfigurer.java | 65 --- .../service/animation/AnimationCache.java | 45 -- .../animation/AnimationController.java | 92 ---- .../service/animation/AnimationEndpoint.java | 206 ------- .../service/animation/AnimationEntry.java | 75 --- .../http/service/chat/ChatController.java | 103 ---- .../http/service/chat/ChatService.java | 120 ----- .../runelite/http/service/xtea/XteaCache.java | 39 -- .../http/service/xtea/XteaController.java | 86 --- .../http/service/xtea/XteaEndpoint.java | 183 ------- .../runelite/http/service/xtea/XteaEntry.java | 109 ---- .../src/main/resources/application-dev.yaml | 31 -- .../src/main/resources/application.yaml | 39 -- .../net/runelite/http/service/xp/schema.sql | 135 ----- .../src/main/templates/markdown.hbs | 110 ---- .../src/main/templates/operation.hbs | 71 --- .../src/main/templates/security.hbs | 88 --- .../src/main/templates/template.html.hbs | 49 -- .../src/main/webapp/WEB-INF/web.xml | 32 -- .../src/test/resources/application-test.yaml | 17 - .../runelite/http/service/worlds/worldlist | Bin 5000 -> 0 bytes http-service/http-service.gradle.kts | 64 --- .../service/SpringBootWebApplication.java | 226 -------- .../http/service/SpringWebMvcConfigurer.java | 65 --- .../http/service/account/AccountService.java | 280 ---------- .../http/service/account/AuthFilter.java | 116 ---- .../runelite/http/service/account/State.java | 53 -- .../http/service/account/UserInfo.java | 46 -- .../service/account/beans/SessionEntry.java | 76 --- .../http/service/account/beans/UserEntry.java | 57 -- .../http/service/cache/CacheController.java | 362 ------------- .../runelite/http/service/cache/CacheDAO.java | 123 ----- .../http/service/cache/CacheService.java | 253 --------- .../service/cache/beans/ArchiveEntry.java | 38 -- .../http/service/cache/beans/CacheEntry.java | 36 -- .../http/service/cache/beans/FileEntry.java | 36 -- .../http/service/cache/beans/IndexEntry.java | 36 -- .../http/service/chat/ChatController.java | 238 --------- .../http/service/chat/ChatService.java | 232 -------- .../http/service/chat/KillCountKey.java | 34 -- .../http/service/config/ConfigController.java | 109 ---- .../http/service/config/ConfigService.java | 289 ---------- .../service/examine/ExamineController.java | 96 ---- .../http/service/examine/ExamineEntry.java | 86 --- .../http/service/examine/ExamineService.java | 94 ---- .../http/service/examine/ExamineType.java | 32 -- .../http/service/feed/FeedController.java | 134 ----- .../http/service/feed/blog/BlogService.java | 129 ----- .../feed/osrsnews/OSRSNewsService.java | 129 ----- .../twitter/TwitterOAuth2TokenResponse.java | 38 -- .../service/feed/twitter/TwitterService.java | 176 ------ .../twitter/TwitterStatusesResponseItem.java | 35 -- .../TwitterStatusesResponseItemUser.java | 38 -- .../service/ge/GrandExchangeController.java | 111 ---- .../http/service/ge/GrandExchangeService.java | 113 ---- .../runelite/http/service/ge/TradeAction.java | 31 -- .../runelite/http/service/ge/TradeEntry.java | 40 -- .../service/hiscore/HiscoreController.java | 96 ---- .../http/service/hiscore/HiscoreKey.java | 36 -- .../http/service/hiscore/HiscoreService.java | 67 --- .../http/service/item/ItemController.java | 251 --------- .../runelite/http/service/item/ItemEntry.java | 52 -- .../http/service/item/ItemService.java | 505 ------------------ .../http/service/item/PendingLookup.java | 55 -- .../http/service/item/PriceEntry.java | 38 -- .../runelite/http/service/item/RSItem.java | 50 -- .../http/service/item/RSItemResponse.java | 33 -- .../runelite/http/service/item/RSPrices.java | 37 -- .../runelite/http/service/item/RSSearch.java | 34 -- .../http/service/loottracker/LootResult.java | 40 -- .../loottracker/LootTrackerController.java | 95 ---- .../loottracker/LootTrackerService.java | 216 -------- .../service/osbuddy/GrandExchangeEntry.java | 38 -- .../osbuddy/OSBGrandExchangeController.java | 58 -- .../osbuddy/OSBGrandExchangeService.java | 124 ----- .../http/service/osbuddy/OsbuddyClient.java | 70 --- .../osbuddy/beans/OsbuddySummaryItem.java | 39 -- .../http/service/sprite/SpriteController.java | 73 --- .../http/service/sprite/SpriteService.java | 117 ---- .../service/util/HiscoreEndpointEditor.java | 39 -- .../http/service/util/InstantConverter.java | 48 -- .../InternalServerErrorException.java | 38 -- .../util/exception/NotFoundException.java | 32 -- .../http/service/util/redis/RedisPool.java | 80 --- .../http/service/worlds/ServiceWorldType.java | 59 -- .../http/service/worlds/WorldController.java | 60 --- .../http/service/worlds/WorldsService.java | 131 ----- .../runelite/http/service/xp/XpMapper.java | 92 ---- .../http/service/xp/XpTrackerController.java | 59 -- .../http/service/xp/XpTrackerService.java | 307 ----------- .../http/service/xp/beans/PlayerEntity.java | 38 -- .../http/service/xp/beans/XpEntity.java | 85 --- .../runelite/http/service/xtea/XteaCache.java | 39 -- .../http/service/xtea/XteaController.java | 86 --- .../runelite/http/service/xtea/XteaEntry.java | 109 ---- .../http/service/xtea/XteaService.java | 240 --------- .../src/main/resources/application-dev.yaml | 36 -- .../src/main/resources/application.yaml | 42 -- .../net/runelite/http/service/xp/schema.sql | 135 ----- http-service/src/main/templates/markdown.hbs | 110 ---- http-service/src/main/templates/operation.hbs | 71 --- http-service/src/main/templates/security.hbs | 88 --- .../src/main/templates/template.html.hbs | 49 -- http-service/src/main/webapp/WEB-INF/web.xml | 32 -- .../service/config/ConfigControllerTest.java | 85 --- .../service/config/ConfigServiceTest.java | 55 -- .../service/hiscore/HiscoreServiceTest.java | 157 ------ .../service/hiscore/HiscoreTestService.java | 46 -- .../LootTrackerControllerTest.java | 92 ---- .../service/worlds/WorldsServiceTest.java | 82 --- .../http/service/xp/XpMapperTest.java | 59 -- .../src/test/resources/application-test.yaml | 21 - .../runelite/http/service/worlds/worldlist | Bin 5000 -> 0 bytes protocol-api/protocol-api.gradle.kts | 38 -- .../api/handshake/HandshakePacket.java | 27 - .../handshake/HandshakeResponsePacket.java | 34 -- .../protocol/api/handshake/HandshakeType.java | 55 -- .../api/handshake/LoginHandshakePacket.java | 32 -- .../api/handshake/UpdateHandshakePacket.java | 39 -- .../api/login/HandshakeResponseType.java | 86 --- .../api/update/ArchiveRequestPacket.java | 68 --- .../api/update/ArchiveResponsePacket.java | 68 --- .../protocol/api/update/EncryptionPacket.java | 33 -- protocol/protocol.gradle.kts | 41 -- .../protocol/handshake/HandshakeDecoder.java | 78 --- .../handshake/HandshakeResponseEncoder.java | 43 -- .../handshake/LoginHandshakeEncoder.java | 41 -- .../handshake/UpdateHandshakeEncoder.java | 42 -- .../decoders/ArchiveRequestDecoder.java | 58 -- .../decoders/ArchiveResponseDecoder.java | 161 ------ .../update/decoders/EncryptionDecoder.java | 53 -- .../decoders/HandshakeResponseDecoder.java | 47 -- .../update/decoders/LoggedInDecoder.java | 46 -- .../update/decoders/LoggedOutDecoder.java | 46 -- .../update/decoders/UpdateOpcodes.java | 34 -- .../encoders/ArchiveRequestEncoder.java | 42 -- .../encoders/ArchiveResponseEncoder.java | 86 --- .../update/encoders/EncryptionEncoder.java | 44 -- .../protocol/update/encoders/XorEncoder.java | 60 --- .../encoders/ArchiveResponseEncoderTest.java | 76 --- .../update/encoders/XorEncoderTest.java | 51 -- settings.gradle.kts | 6 - 168 files changed, 14499 deletions(-) delete mode 100644 cache-client/cache-client.gradle.kts delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/ArchiveResponseHandler.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/CacheClient.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/CacheClientHandler.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/ClientState.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/DownloadWatcher.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/FileResult.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/HandshakeResponseHandler.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/IndexInfo.java delete mode 100644 cache-client/src/main/java/net/runelite/cache/client/PendingFileRequest.java delete mode 100644 cache-client/src/test/java/net/runelite/cache/client/CacheClientTest.java delete mode 100644 cache-updater/cache-updater.gradle.kts delete mode 100644 cache-updater/schema.sql delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java delete mode 100644 cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java delete mode 100644 cache-updater/src/main/resources/application.yaml delete mode 100644 http-service-openosrs/http-service-openosrs.gradle.kts delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/SpringBootWebApplication.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationCache.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationController.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEndpoint.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEntry.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatController.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatService.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaCache.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaController.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEndpoint.java delete mode 100644 http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEntry.java delete mode 100644 http-service-openosrs/src/main/resources/application-dev.yaml delete mode 100644 http-service-openosrs/src/main/resources/application.yaml delete mode 100644 http-service-openosrs/src/main/resources/net/runelite/http/service/xp/schema.sql delete mode 100644 http-service-openosrs/src/main/templates/markdown.hbs delete mode 100644 http-service-openosrs/src/main/templates/operation.hbs delete mode 100644 http-service-openosrs/src/main/templates/security.hbs delete mode 100644 http-service-openosrs/src/main/templates/template.html.hbs delete mode 100644 http-service-openosrs/src/main/webapp/WEB-INF/web.xml delete mode 100644 http-service-openosrs/src/test/resources/application-test.yaml delete mode 100644 http-service-openosrs/src/test/resources/net/runelite/http/service/worlds/worldlist delete mode 100644 http-service/http-service.gradle.kts delete mode 100644 http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/account/AccountService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/account/AuthFilter.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/account/State.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/account/UserInfo.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/account/beans/SessionEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/account/beans/UserEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/CacheController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/CacheService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/chat/ChatController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/chat/ChatService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/config/ConfigController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/config/ConfigService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/examine/ExamineController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/examine/ExamineEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/examine/ExamineService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/examine/ExamineType.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/FeedController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/blog/BlogService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/osrsnews/OSRSNewsService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterOAuth2TokenResponse.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItem.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItemUser.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/ge/TradeAction.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/ge/TradeEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreKey.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/ItemController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/ItemEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/ItemService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/PendingLookup.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/PriceEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/RSItem.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/RSItemResponse.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/RSPrices.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/item/RSSearch.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/loottracker/LootResult.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/sprite/SpriteController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/sprite/SpriteService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/util/HiscoreEndpointEditor.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/util/InstantConverter.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/util/exception/InternalServerErrorException.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/util/exception/NotFoundException.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/util/redis/RedisPool.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/worlds/ServiceWorldType.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xp/XpMapper.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xp/beans/PlayerEntity.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xp/beans/XpEntity.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xtea/XteaCache.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xtea/XteaController.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xtea/XteaEntry.java delete mode 100644 http-service/src/main/java/net/runelite/http/service/xtea/XteaService.java delete mode 100644 http-service/src/main/resources/application-dev.yaml delete mode 100644 http-service/src/main/resources/application.yaml delete mode 100644 http-service/src/main/resources/net/runelite/http/service/xp/schema.sql delete mode 100644 http-service/src/main/templates/markdown.hbs delete mode 100644 http-service/src/main/templates/operation.hbs delete mode 100644 http-service/src/main/templates/security.hbs delete mode 100644 http-service/src/main/templates/template.html.hbs delete mode 100644 http-service/src/main/webapp/WEB-INF/web.xml delete mode 100644 http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java delete mode 100644 http-service/src/test/java/net/runelite/http/service/config/ConfigServiceTest.java delete mode 100644 http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreServiceTest.java delete mode 100644 http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreTestService.java delete mode 100644 http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java delete mode 100644 http-service/src/test/java/net/runelite/http/service/worlds/WorldsServiceTest.java delete mode 100644 http-service/src/test/java/net/runelite/http/service/xp/XpMapperTest.java delete mode 100644 http-service/src/test/resources/application-test.yaml delete mode 100644 http-service/src/test/resources/net/runelite/http/service/worlds/worldlist delete mode 100644 protocol-api/protocol-api.gradle.kts delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakePacket.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeResponsePacket.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeType.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/handshake/LoginHandshakePacket.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/handshake/UpdateHandshakePacket.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/login/HandshakeResponseType.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveRequestPacket.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveResponsePacket.java delete mode 100644 protocol-api/src/main/java/net/runelite/protocol/api/update/EncryptionPacket.java delete mode 100644 protocol/protocol.gradle.kts delete mode 100644 protocol/src/main/java/net/runelite/protocol/handshake/HandshakeDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/handshake/HandshakeResponseEncoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/handshake/LoginHandshakeEncoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/handshake/UpdateHandshakeEncoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveRequestDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveResponseDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/EncryptionDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/HandshakeResponseDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedInDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedOutDecoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/decoders/UpdateOpcodes.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveRequestEncoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/encoders/EncryptionEncoder.java delete mode 100644 protocol/src/main/java/net/runelite/protocol/update/encoders/XorEncoder.java delete mode 100644 protocol/src/test/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoderTest.java delete mode 100644 protocol/src/test/java/net/runelite/protocol/update/encoders/XorEncoderTest.java diff --git a/cache-client/cache-client.gradle.kts b/cache-client/cache-client.gradle.kts deleted file mode 100644 index 794a19ab8e..0000000000 --- a/cache-client/cache-client.gradle.kts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2019 Owain van Brakel - * 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. - */ - -description = "Cache Client" - -dependencies { - api(project(":cache")) - api(project(":protocol")) - - implementation(Libraries.guava) - implementation(Libraries.nettyAll) - implementation(Libraries.slf4jApi) - - testImplementation(Libraries.junit) - testImplementation(Libraries.slf4jSimple) - testImplementation(project(path = ":cache", configuration = "testArchives")) -} - -tasks { - register("download") { - dependsOn(":cache-client:build") - - classpath = project.sourceSets.main.get().runtimeClasspath - main = "net.runelite.cache.client.CacheClient" - args(listOf(ProjectVersions.rsversion)) - } -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/ArchiveResponseHandler.java b/cache-client/src/main/java/net/runelite/cache/client/ArchiveResponseHandler.java deleted file mode 100644 index f6bffbeba1..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/ArchiveResponseHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import net.runelite.protocol.api.update.ArchiveResponsePacket; - -public class ArchiveResponseHandler extends SimpleChannelInboundHandler -{ - private final CacheClient client; - - public ArchiveResponseHandler(CacheClient client) - { - this.client = client; - } - - @Override - protected void channelRead0(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse) throws Exception - { - client.onFileFinish(archiveResponse.getIndex(), - archiveResponse.getArchive(), - archiveResponse.getData()); - } - -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/CacheClient.java b/cache-client/src/main/java/net/runelite/cache/client/CacheClient.java deleted file mode 100644 index 956905f539..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/CacheClient.java +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import com.google.common.base.Stopwatch; -import io.netty.bootstrap.Bootstrap; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.List; -import java.util.Queue; -import java.util.concurrent.CompletableFuture; -import net.runelite.cache.fs.Archive; -import net.runelite.cache.fs.Index; -import net.runelite.cache.fs.Storage; -import net.runelite.cache.fs.Store; -import net.runelite.cache.index.ArchiveData; -import net.runelite.cache.index.IndexData; -import net.runelite.protocol.update.decoders.HandshakeResponseDecoder; -import net.runelite.protocol.update.encoders.ArchiveRequestEncoder; -import net.runelite.protocol.update.encoders.EncryptionEncoder; -import net.runelite.protocol.api.update.ArchiveRequestPacket; -import net.runelite.protocol.api.login.HandshakeResponseType; -import net.runelite.cache.util.Crc32; -import net.runelite.protocol.api.handshake.UpdateHandshakePacket; -import net.runelite.protocol.handshake.UpdateHandshakeEncoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CacheClient implements AutoCloseable -{ - private static final Logger logger = LoggerFactory.getLogger(CacheClient.class); - - private static final String HOST = "oldschool1.runescape.com"; - private static final int PORT = 43594; - - private static final int MAX_REQUESTS = 19; // too many and the server closes the conncetion - - private final Store store; // store cache will be written to - private final String host; - private final int clientRevision; - private DownloadWatcher watcher; - - private ClientState state; - - private final EventLoopGroup group = new NioEventLoopGroup(1); - private Channel channel; - - private CompletableFuture handshakeFuture; - private final Queue requests = new ArrayDeque<>(); - - public static void main(String[] args) - { - Path path = Paths.get(System.getProperty("user.home"), "jagexcache" + File.separator + "oldschool" + File.separator + "LIVE"); - final File jagexcache = new File(String.valueOf(path)); - - jagexcache.mkdirs(); - - try (Store store = new Store(jagexcache)) - { - store.load(); - CacheClient c = new CacheClient(store, Integer.parseInt(args[0])); - c.connect(); - CompletableFuture handshake = c.handshake(); - handshake.get(); - c.download(); - c.close(); - store.save(); - } - catch (Exception ex) - { - logger.error(ex.getMessage()); - } - } - - public CacheClient(Store store, int clientRevision) - { - this(store, HOST, clientRevision); - } - - public CacheClient(Store store, String host, int clientRevision) - { - this.store = store; - this.host = host; - this.clientRevision = clientRevision; - } - - public CacheClient(Store store, int clientRevision, DownloadWatcher watcher) - { - this(store, clientRevision); - this.watcher = watcher; - } - - public void connect() - { - Bootstrap b = new Bootstrap(); - b.group(group) - .channel(NioSocketChannel.class) - .option(ChannelOption.TCP_NODELAY, true) - .handler(new ChannelInitializer() - { - @Override - public void initChannel(SocketChannel ch) throws Exception - { - ChannelPipeline p = ch.pipeline(); - - //p.addFirst(new HttpProxyHandler(new InetSocketAddress("runelite.net", 3128))); - p.addLast("decoder", new HandshakeResponseDecoder()); - - p.addLast( - new CacheClientHandler(), - new HandshakeResponseHandler(CacheClient.this), - new ArchiveResponseHandler(CacheClient.this) - ); - - p.addLast( - new UpdateHandshakeEncoder(), - new EncryptionEncoder(), - new ArchiveRequestEncoder() - ); - } - }); - - // Start the client. - ChannelFuture f = b.connect(host, PORT).syncUninterruptibly(); - channel = f.channel(); - } - - public CompletableFuture handshake() - { - UpdateHandshakePacket handshakePacket = new UpdateHandshakePacket(); - handshakePacket.setRevision(getClientRevision()); - - state = ClientState.HANDSHAKING; - - assert handshakeFuture == null; - handshakeFuture = new CompletableFuture<>(); - - channel.writeAndFlush(handshakePacket); - - logger.info("Sent handshake with revision {}", handshakePacket.getRevision()); - - return handshakeFuture; - } - - @Override - public void close() - { - channel.close().syncUninterruptibly(); - group.shutdownGracefully(); - } - - public int getClientRevision() - { - return clientRevision; - } - - public ClientState getState() - { - return state; - } - - void setState(ClientState state) - { - this.state = state; - } - - CompletableFuture getHandshakeFuture() - { - return handshakeFuture; - } - - public List requestIndexes() throws IOException - { - logger.info("Requesting indexes"); - - FileResult result = requestFile(255, 255, true).join(); - result.decompress(null); - - ByteBuf buffer = Unpooled.wrappedBuffer(result.getContents()); - int indexCount = result.getContents().length / 8; - List indexInfo = new ArrayList<>(); - - for (int i = 0; i < indexCount; ++i) - { - int crc = buffer.readInt(); - int revision = buffer.readInt(); - indexInfo.add(new IndexInfo(i, crc, revision)); - } - - return indexInfo; - } - - public void download() throws IOException - { - Stopwatch stopwatch = Stopwatch.createStarted(); - - List indexes = requestIndexes(); - for (IndexInfo indexInfo : indexes) - { - int i = indexInfo.getId(); - int crc = indexInfo.getCrc(); - int revision = indexInfo.getRevision(); - - Index index = store.findIndex(i); - - if (index == null) - { - logger.info("Index {} does not exist, creating", i); - } - else if (index.getRevision() != revision) - { - if (revision < index.getRevision()) - { - logger.warn("Index {} revision is going BACKWARDS! (our revision {}, their revision {})", index.getId(), index.getRevision(), revision); - } - else - { - logger.info("Index {} has the wrong revision (our revision {}, their revision {})", index.getId(), index.getRevision(), revision); - } - } - else if (index.getCrc() != crc) - { - logger.warn("Index {} CRC has changed! (our crc {}, their crc {})", - index.getCrc(), index.getCrc(), crc); - } - else - { - // despite the index being up to date, not everything - // can be downloaded, eg. for tracks. - logger.info("Index {} is up to date", index.getId()); - } - - logger.info("Downloading index {}", i); - - FileResult indexFileResult = requestFile(255, i, true).join(); - indexFileResult.decompress(null); - - logger.info("Downloaded index {}", i); - - if (indexFileResult.getCrc() != crc) - { - logger.warn("Corrupted download for index {}", i); - continue; - } - - IndexData indexData = new IndexData(); - indexData.load(indexFileResult.getContents()); - - if (index == null) - { - index = store.addIndex(i); - } - - // update index settings - index.setProtocol(indexData.getProtocol()); - index.setNamed(indexData.isNamed()); - index.setCrc(crc); - index.setRevision(revision); - - logger.info("Index {} has {} archives", i, indexData.getArchives().length); - - for (ArchiveData ad : indexData.getArchives()) - { - Archive existing = index.getArchive(ad.getId()); - - if (existing != null && existing.getRevision() == ad.getRevision() - && existing.getCrc() == ad.getCrc() - && existing.getNameHash() == ad.getNameHash()) - { - logger.debug("Archive {}/{} in index {} is up to date", - ad.getId(), indexData.getArchives().length, index.getId()); - continue; - } - - if (existing == null) - { - logger.info("Archive {}/{} in index {} is out of date, downloading", - ad.getId(), indexData.getArchives().length, index.getId()); - } - else if (ad.getRevision() < existing.getRevision()) - { - logger.warn("Archive {}/{} in index {} revision is going BACKWARDS! (our revision {}, their revision {})", - ad.getId(), indexData.getArchives().length, index.getId(), - existing.getRevision(), ad.getRevision()); - } - else - { - logger.info("Archive {}/{} in index {} is out of date, downloading. " + - "revision: ours: {} theirs: {}, crc: ours: {} theirs {}, name: ours {} theirs {}", - ad.getId(), indexData.getArchives().length, index.getId(), - existing.getRevision(), ad.getRevision(), - existing.getCrc(), ad.getCrc(), - existing.getNameHash(), ad.getNameHash()); - } - - final Archive archive = existing == null - ? index.addArchive(ad.getId()) - : existing; - - archive.setRevision(ad.getRevision()); - archive.setCrc(ad.getCrc()); - archive.setNameHash(ad.getNameHash()); - - // Add files - archive.setFileData(ad.getFiles()); - - CompletableFuture future = requestFile(index.getId(), ad.getId(), false); - future.handle((fr, ex) -> - { - byte[] data = fr.getCompressedData(); - - Crc32 crc32 = new Crc32(); - crc32.update(data, 0, data.length); - int hash = crc32.getHash(); - - if (hash != archive.getCrc()) - { - logger.warn("crc mismatch on downloaded archive {}/{}: {} != {}", - archive.getIndex().getId(), archive.getArchiveId(), - hash, archive.getCrc()); - throw new RuntimeException("crc mismatch"); - } - - if (watcher != null) - { - watcher.downloadComplete(archive, data); - } - else - { - try - { - Storage storage = store.getStorage(); - storage.saveArchive(archive, data); - } - catch (IOException ex1) - { - logger.warn("unable to save archive data", ex1); - } - } - return null; - }); - } - } - - // flush any pending requests - channel.flush(); - - while (!requests.isEmpty()) - { - // wait for pending requests - synchronized (this) - { - try - { - wait(); - } - catch (InterruptedException ex) - { - logger.warn(null, ex); - } - } - } - - stopwatch.stop(); - logger.info("Download completed in {}", stopwatch); - } - - private synchronized CompletableFuture requestFile(int index, int fileId, boolean flush) - { - if (state != ClientState.CONNECTED) - { - throw new IllegalStateException("Can't request files until connected!"); - } - - if (!flush) - { - while (requests.size() >= MAX_REQUESTS) - { - channel.flush(); - - try - { - wait(); - } - catch (InterruptedException ex) - { - logger.warn("interrupted while waiting for requests", ex); - } - } - } - - ArchiveRequestPacket archiveRequest = new ArchiveRequestPacket(); - archiveRequest.setPriority(false); - archiveRequest.setIndex(index); - archiveRequest.setArchive(fileId); - - CompletableFuture future = new CompletableFuture<>(); - PendingFileRequest pf = new PendingFileRequest(index, - fileId, future); - - logger.trace("Sending request for {}/{}", index, fileId); - - requests.add(pf); - - if (!flush) - { - channel.write(archiveRequest); - } - else - { - channel.writeAndFlush(archiveRequest); - } - - return future; - } - - private PendingFileRequest findRequest(int index, int file) - { - for (PendingFileRequest pr : requests) - { - if (pr.getIndex() == index && pr.getArchive() == file) - { - return pr; - } - } - return null; - } - - protected synchronized void onFileFinish(int index, int file, byte[] compressedData) - { - PendingFileRequest pr = findRequest(index, file); - - if (pr == null) - { - logger.warn("File download {}/{} with no pending request", index, file); - return; - } - - requests.remove(pr); - - notify(); - - FileResult result = new FileResult(index, file, compressedData); - - logger.debug("File download finished for index {} file {}, length {}", index, file, compressedData.length); - - pr.getFuture().complete(result); - } -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/CacheClientHandler.java b/cache-client/src/main/java/net/runelite/cache/client/CacheClientHandler.java deleted file mode 100644 index 9afe8f976b..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/CacheClientHandler.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CacheClientHandler extends ChannelInboundHandlerAdapter -{ - private static final Logger logger = LoggerFactory.getLogger(CacheClientHandler.class); - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception - { - logger.warn("Channel has gone inactive"); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) - { - // Close the connection when an exception is raised. - logger.warn(null, cause); - ctx.close(); - } -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/ClientState.java b/cache-client/src/main/java/net/runelite/cache/client/ClientState.java deleted file mode 100644 index 5c859aa61c..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/ClientState.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -public enum ClientState -{ - HANDSHAKING, - CONNECTED -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/DownloadWatcher.java b/cache-client/src/main/java/net/runelite/cache/client/DownloadWatcher.java deleted file mode 100644 index 3924c74541..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/DownloadWatcher.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import net.runelite.cache.fs.Archive; - -@FunctionalInterface -public interface DownloadWatcher -{ - void downloadComplete(Archive archive, byte[] data); -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/FileResult.java b/cache-client/src/main/java/net/runelite/cache/client/FileResult.java deleted file mode 100644 index 2c5046af62..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/FileResult.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import java.io.IOException; -import net.runelite.cache.fs.Container; - -public class FileResult -{ - private final int index; - private final int fileId; - private final byte[] compressedData; - - private byte[] contents; - private int revision; - private int crc; - private int compression; // compression method used by archive data - - public FileResult(int index, int fileId, byte[] compressedData) - { - this.index = index; - this.fileId = fileId; - this.compressedData = compressedData; - } - - public int getIndex() - { - return index; - } - - public int getFileId() - { - return fileId; - } - - public byte[] getCompressedData() - { - return compressedData; - } - - public void decompress(int[] keys) throws IOException - { - Container res = Container.decompress(compressedData, keys); - - contents = res.data; - revision = res.revision; - crc = res.crc; - compression = res.compression; - } - - public byte[] getContents() - { - return contents; - } - - public int getRevision() - { - return revision; - } - - public int getCrc() - { - return crc; - } - - public int getCompression() - { - return compression; - } -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/HandshakeResponseHandler.java b/cache-client/src/main/java/net/runelite/cache/client/HandshakeResponseHandler.java deleted file mode 100644 index bcbb01bafb..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/HandshakeResponseHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.SimpleChannelInboundHandler; -import java.util.concurrent.CompletableFuture; -import net.runelite.protocol.update.decoders.ArchiveResponseDecoder; -import net.runelite.protocol.api.update.EncryptionPacket; -import net.runelite.protocol.api.handshake.HandshakeResponsePacket; -import net.runelite.protocol.api.login.HandshakeResponseType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HandshakeResponseHandler extends SimpleChannelInboundHandler -{ - private static final Logger logger = LoggerFactory.getLogger(HandshakeResponseHandler.class); - - private final CacheClient client; - - public HandshakeResponseHandler(CacheClient client) - { - this.client = client; - } - - @Override - protected void channelRead0(ChannelHandlerContext ctx, HandshakeResponsePacket handshakeResponse) throws Exception - { - Channel channel = ctx.channel(); - ChannelPipeline p = ctx.pipeline(); - CompletableFuture handshakeFuture = client.getHandshakeFuture(); - - assert handshakeFuture != null; - - if (handshakeResponse.getResponse() != HandshakeResponseType.RESPONSE_OK) - { - logger.warn("Non-ok response from server {}", handshakeResponse.getResponse()); - handshakeFuture.complete(handshakeResponse.getResponse()); - ctx.close(); - return; - } - - // Send encryption packet - EncryptionPacket encryptionPacket = new EncryptionPacket(); - encryptionPacket.setKey((byte) 0); - channel.writeAndFlush(encryptionPacket); - - client.setState(ClientState.CONNECTED); - - logger.info("Client is now connected!"); - - p.replace("decoder", "decoder", new ArchiveResponseDecoder()); - - handshakeFuture.complete(handshakeResponse.getResponse()); - } - -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/IndexInfo.java b/cache-client/src/main/java/net/runelite/cache/client/IndexInfo.java deleted file mode 100644 index b6f088e84b..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/IndexInfo.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -public class IndexInfo -{ - private final int id; - private final int crc; - private final int revision; - - public IndexInfo(int id, int crc, int revision) - { - this.id = id; - this.crc = crc; - this.revision = revision; - } - - @Override - public String toString() - { - return "IndexInfo{" + "id=" + id + ", crc=" + crc + ", revision=" + revision + '}'; - } - - @Override - public int hashCode() - { - int hash = 5; - hash = 71 * hash + this.id; - hash = 71 * hash + this.crc; - hash = 71 * hash + this.revision; - return hash; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - { - return true; - } - if (obj == null) - { - return false; - } - if (getClass() != obj.getClass()) - { - return false; - } - final IndexInfo other = (IndexInfo) obj; - if (this.id != other.id) - { - return false; - } - if (this.crc != other.crc) - { - return false; - } - if (this.revision != other.revision) - { - return false; - } - return true; - } - - public int getId() - { - return id; - } - - public int getCrc() - { - return crc; - } - - public int getRevision() - { - return revision; - } -} diff --git a/cache-client/src/main/java/net/runelite/cache/client/PendingFileRequest.java b/cache-client/src/main/java/net/runelite/cache/client/PendingFileRequest.java deleted file mode 100644 index d07dc4f606..0000000000 --- a/cache-client/src/main/java/net/runelite/cache/client/PendingFileRequest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import java.util.concurrent.CompletableFuture; - -public class PendingFileRequest -{ - private final int index; - private final int archive; - private final CompletableFuture future; - - public PendingFileRequest(int index, int archive, CompletableFuture future) - { - this.index = index; - this.archive = archive; - this.future = future; - } - - public int getIndex() - { - return index; - } - - public int getArchive() - { - return archive; - } - - public CompletableFuture getFuture() - { - return future; - } -} diff --git a/cache-client/src/test/java/net/runelite/cache/client/CacheClientTest.java b/cache-client/src/test/java/net/runelite/cache/client/CacheClientTest.java deleted file mode 100644 index f5ba5d6824..0000000000 --- a/cache-client/src/test/java/net/runelite/cache/client/CacheClientTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.cache.client; - -import java.io.File; -import java.util.concurrent.CompletableFuture; -import net.runelite.cache.CacheProperties; -import net.runelite.cache.fs.Store; -import net.runelite.protocol.api.login.HandshakeResponseType; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.impl.SimpleLogger; - -public class CacheClientTest -{ - private static final Logger logger = LoggerFactory.getLogger(CacheClientTest.class); - - @Before - public void before() - { - System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE"); - } - - @Test - @Ignore - public void test() throws Exception - { - try (Store store = new Store(new File("D:\\rs\\07\\temp\\cache"))) - { - store.load(); - - CacheClient c = new CacheClient(store, CacheProperties.getRsVersion()); - c.connect(); - CompletableFuture handshake = c.handshake(); - - HandshakeResponseType result = handshake.get(); - logger.info("Handshake result: {}", result); - - Assert.assertEquals(HandshakeResponseType.RESPONSE_OK, result); - - c.download(); - - c.close(); - - store.save(); - } - } -} diff --git a/cache-updater/cache-updater.gradle.kts b/cache-updater/cache-updater.gradle.kts deleted file mode 100644 index 2007258401..0000000000 --- a/cache-updater/cache-updater.gradle.kts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 Owain van Brakel - * 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. - */ - -description = "Cache Updater" - -dependencies { - annotationProcessor(Libraries.lombok) - - compileOnly(Libraries.lombok) - - implementation(Libraries.minio) - implementation(Libraries.mysqlConnectorJava) - implementation(Libraries.springbootDevtools) - implementation(Libraries.springbootStarter) - implementation(Libraries.springbootStarterJdbc) - implementation(Libraries.sql2o) - implementation(project(":cache-client")) -} diff --git a/cache-updater/schema.sql b/cache-updater/schema.sql deleted file mode 100644 index a4e063e1a6..0000000000 --- a/cache-updater/schema.sql +++ /dev/null @@ -1,118 +0,0 @@ --- MySQL dump 10.16 Distrib 10.2.9-MariaDB, for Linux (x86_64) --- --- Host: localhost Database: cache --- ------------------------------------------------------ --- 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 `archive` --- - -DROP TABLE IF EXISTS `archive`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `archive` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `archiveId` int(11) NOT NULL, - `nameHash` int(11) NOT NULL, - `crc` int(11) NOT NULL, - `revision` int(11) NOT NULL, - `hash` binary(32) NOT NULL, - PRIMARY KEY (`id`), - KEY `archive_revision` (`archiveId`,`revision`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `cache` --- - -DROP TABLE IF EXISTS `cache`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `cache` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `revision` int(11) NOT NULL, - `date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - PRIMARY KEY (`id`), - UNIQUE KEY `revision_date` (`revision`,`date`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `file` --- - -DROP TABLE IF EXISTS `file`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `file` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `archive` int(11) NOT NULL, - `fileId` int(11) NOT NULL, - `nameHash` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `archive_file` (`archive`,`fileId`), - CONSTRAINT `file_ibfk_1` FOREIGN KEY (`archive`) REFERENCES `archive` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `index` --- - -DROP TABLE IF EXISTS `index`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `index` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `cache` int(11) NOT NULL, - `indexId` int(11) NOT NULL, - `crc` int(11) NOT NULL, - `revision` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `indexId` (`cache`,`indexId`,`revision`,`crc`) USING BTREE, - CONSTRAINT `index_ibfk_1` FOREIGN KEY (`cache`) REFERENCES `cache` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `index_archive` --- - -DROP TABLE IF EXISTS `index_archive`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `index_archive` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `index` int(11) NOT NULL, - `archive` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `idx_index_archive` (`index`,`archive`) USING BTREE, - KEY `archive` (`archive`) USING BTREE, - CONSTRAINT `index_archive_ibfk_1` FOREIGN KEY (`index`) REFERENCES `index` (`id`), - CONSTRAINT `index_archive_ibfk_2` FOREIGN KEY (`archive`) REFERENCES `archive` (`id`) -) ENGINE=InnoDB 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-02-02 21:55:48 diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java deleted file mode 100644 index 69c405aeb4..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/CacheConfiguration.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.cache.updater; - -import io.minio.MinioClient; -import io.minio.errors.InvalidEndpointException; -import io.minio.errors.InvalidPortException; -import java.time.Instant; -import java.util.HashMap; -import java.util.Map; -import javax.sql.DataSource; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.jdbc.DataSourceBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.sql2o.Sql2o; -import org.sql2o.converters.Converter; -import org.sql2o.quirks.NoQuirks; - -@Configuration -public class CacheConfiguration -{ - @Value("${minio.endpoint}") - private String minioUrl; - - @Value("${minio.accesskey}") - private String minioAccessKey; - - @Value("${minio.secretkey}") - private String minioSecretKey; - - @Bean - @ConfigurationProperties(prefix = "datasource.runelite-cache") - public DataSource dataSource() - { - return DataSourceBuilder.create().build(); - } - - @Bean - @Qualifier("Runelite Cache SQL2O") - public Sql2o sql2o(DataSource dataSource) - { - Map converters = new HashMap<>(); - converters.put(Instant.class, new InstantConverter()); - return new Sql2o(dataSource, new NoQuirks(converters)); - } - - @Bean - public MinioClient minioClient() throws InvalidEndpointException, InvalidPortException - { - return new MinioClient(minioUrl, minioAccessKey, minioSecretKey); - } -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java deleted file mode 100644 index 2834e5bb1e..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/CacheDAO.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater; - -import java.time.Instant; -import java.util.List; -import net.runelite.cache.updater.beans.ArchiveEntry; -import net.runelite.cache.updater.beans.CacheEntry; -import net.runelite.cache.updater.beans.IndexEntry; -import org.sql2o.Connection; -import org.sql2o.Query; -import org.sql2o.ResultSetIterable; - -class CacheDAO -{ - // cache prepared statements for high volume queries - private Query associateArchive; - private Query findArchive, insertArchive; - private Query associateFile; - - public CacheEntry findMostRecent(Connection con) - { - return con.createQuery("select id, revision, date from cache order by revision desc, date desc limit 1") - .executeAndFetchFirst(CacheEntry.class); - } - - public List findIndexesForCache(Connection con, CacheEntry cache) - { - return con.createQuery("select id, indexId, crc, revision from `index` where cache = :cache") - .addParameter("cache", cache.getId()) - .executeAndFetch(IndexEntry.class); - } - - public ResultSetIterable findArchivesForIndex(Connection con, IndexEntry indexEntry) - { - return con.createQuery("select archive.id, archive.archiveId, archive.nameHash," - + " archive.crc, archive.revision, archive.hash from index_archive " - + "join archive on index_archive.archive = archive.id " - + "where index_archive.index = :id") - .addParameter("id", indexEntry.getId()) - .executeAndFetchLazy(ArchiveEntry.class); - } - - public CacheEntry createCache(Connection con, int revision, Instant date) - { - int cacheId = con.createQuery("insert into cache (revision, date) values (:revision, :date)") - .addParameter("revision", revision) - .addParameter("date", date) - .executeUpdate() - .getKey(int.class); - - CacheEntry entry = new CacheEntry(); - entry.setId(cacheId); - entry.setRevision(revision); - entry.setDate(date); - return entry; - } - - public IndexEntry createIndex(Connection con, CacheEntry cache, int indexId, int crc, int revision) - { - int id = con.createQuery("insert into `index` (cache, indexId, crc, revision) values (:cache, :indexId, :crc, :revision)") - .addParameter("cache", cache.getId()) - .addParameter("indexId", indexId) - .addParameter("crc", crc) - .addParameter("revision", revision) - .executeUpdate() - .getKey(int.class); - - IndexEntry entry = new IndexEntry(); - entry.setId(id); - entry.setIndexId(indexId); - entry.setCrc(crc); - entry.setRevision(revision); - return entry; - } - - public void associateArchiveToIndex(Connection con, ArchiveEntry archive, IndexEntry index) - { - if (associateArchive == null) - { - associateArchive = con.createQuery("insert into index_archive (`index`, archive) values (:index, :archive)"); - } - associateArchive - .addParameter("index", index.getId()) - .addParameter("archive", archive.getId()) - .executeUpdate(); - } - - public ArchiveEntry findArchive(Connection con, IndexEntry index, - int archiveId, int nameHash, int crc, int revision) - { - if (findArchive == null) - { - findArchive = con.createQuery("select distinct archive.id, archive.archiveId, archive.nameHash," - + " archive.crc, archive.revision, archive.hash from archive " - + " join index_archive on index_archive.archive = archive.id" - + " join `index` on index.id = index_archive.index" - + " where archive.archiveId = :archiveId" - + " and archive.nameHash = :nameHash" - + " and archive.crc = :crc" - + " and archive.revision = :revision" - + " and index.indexId = :indexId"); - } - - ArchiveEntry entry = findArchive - .addParameter("archiveId", archiveId) - .addParameter("nameHash", nameHash) - .addParameter("crc", crc) - .addParameter("revision", revision) - .addParameter("indexId", index.getIndexId()) - .executeAndFetchFirst(ArchiveEntry.class); - return entry; - } - - public ArchiveEntry createArchive(Connection con, IndexEntry index, - int archiveId, int nameHash, int crc, int revision, byte[] hash) - { - if (insertArchive == null) - { - insertArchive = con.createQuery("insert into archive (archiveId, nameHash, crc, revision, hash) values " - + "(:archiveId, :nameHash, :crc, :revision, :hash)"); - } - - int id = insertArchive - .addParameter("archiveId", archiveId) - .addParameter("nameHash", nameHash) - .addParameter("crc", crc) - .addParameter("revision", revision) - .addParameter("hash", hash) - .executeUpdate() - .getKey(int.class); - - ArchiveEntry entry = new ArchiveEntry(); - entry.setId(id); - entry.setArchiveId(archiveId); - entry.setNameHash(nameHash); - entry.setCrc(crc); - entry.setRevision(revision); - entry.setHash(hash); - return entry; - } - - public void associateFileToArchive(Connection con, ArchiveEntry archive, int fileId, int nameHash) - { - if (associateFile == null) - { - associateFile = con.createQuery("insert into file (archive, fileId, nameHash) values (:archive, :fileId, :nameHash)"); - } - associateFile - .addParameter("archive", archive.getId()) - .addParameter("fileId", fileId) - .addParameter("nameHash", nameHash) - .executeUpdate(); - } -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java deleted file mode 100644 index cac605da09..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/CacheStorage.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater; - -import java.io.IOException; -import java.util.List; -import net.runelite.cache.fs.Archive; -import net.runelite.cache.fs.Index; -import net.runelite.cache.fs.Storage; -import net.runelite.cache.fs.Store; -import net.runelite.cache.index.FileData; -import net.runelite.cache.updater.beans.ArchiveEntry; -import net.runelite.cache.updater.beans.CacheEntry; -import net.runelite.cache.updater.beans.IndexEntry; -import org.sql2o.Connection; -import org.sql2o.ResultSetIterable; - -public class CacheStorage implements Storage -{ - private CacheEntry cacheEntry; - private final CacheDAO cacheDao; - private final Connection con; - - public CacheStorage(CacheEntry cacheEntry, CacheDAO cacheDao, Connection con) - { - this.cacheEntry = cacheEntry; - this.cacheDao = cacheDao; - this.con = con; - } - - public CacheEntry getCacheEntry() - { - return cacheEntry; - } - - public void setCacheEntry(CacheEntry cacheEntry) - { - this.cacheEntry = cacheEntry; - } - - @Override - public void init(Store store) throws IOException - { - } - - @Override - public void close() throws IOException - { - } - - @Override - public void load(Store store) throws IOException - { - List indexes = cacheDao.findIndexesForCache(con, cacheEntry); - for (IndexEntry indexEntry : indexes) - { - Index index = store.addIndex(indexEntry.getIndexId()); - index.setCrc(indexEntry.getCrc()); - index.setRevision(indexEntry.getRevision()); - - try (ResultSetIterable archives = cacheDao.findArchivesForIndex(con, indexEntry)) - { - for (ArchiveEntry archiveEntry : archives) - { - if (index.getArchive(archiveEntry.getArchiveId()) != null) - { - throw new IOException("Duplicate archive " + archiveEntry + " on " + indexEntry); - } - - Archive archive = index.addArchive(archiveEntry.getArchiveId()); - archive.setNameHash(archiveEntry.getNameHash()); - archive.setCrc(archiveEntry.getCrc()); - archive.setRevision(archiveEntry.getRevision()); - archive.setHash(archiveEntry.getHash()); - - // File data is not necessary for cache updating - } - } - } - } - - @Override - public void save(Store store) throws IOException - { - for (Index index : store.getIndexes()) - { - IndexEntry entry = cacheDao.createIndex(con, cacheEntry, index.getId(), index.getCrc(), index.getRevision()); - - for (Archive archive : index.getArchives()) - { - ArchiveEntry archiveEntry = cacheDao.findArchive(con, entry, archive.getArchiveId(), - archive.getNameHash(), archive.getCrc(), archive.getRevision()); - if (archiveEntry == null) - { - byte[] hash = archive.getHash(); - archiveEntry = cacheDao.createArchive(con, entry, archive.getArchiveId(), - archive.getNameHash(), archive.getCrc(), archive.getRevision(), hash); - - for (FileData file : archive.getFileData()) - { - cacheDao.associateFileToArchive(con, archiveEntry, file.getId(), file.getNameHash()); - } - } - - cacheDao.associateArchiveToIndex(con, archiveEntry, entry); - } - } - } - - @Override - public byte[] loadArchive(Archive archive) throws IOException - { - throw new UnsupportedOperationException(); - } - - @Override - public void saveArchive(Archive archive, byte[] data) throws IOException - { - throw new UnsupportedOperationException(); - } - -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java deleted file mode 100644 index 1a8f81c5ec..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/CacheUpdater.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater; - -import io.minio.MinioClient; -import io.minio.errors.InvalidEndpointException; -import io.minio.errors.InvalidPortException; -import java.io.IOException; -import java.time.Instant; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import net.runelite.cache.client.CacheClient; -import net.runelite.cache.client.IndexInfo; -import net.runelite.cache.fs.Archive; -import net.runelite.cache.fs.Store; -import net.runelite.cache.updater.beans.CacheEntry; -import net.runelite.cache.updater.beans.IndexEntry; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.protocol.api.login.HandshakeResponseType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.sql2o.Connection; -import org.sql2o.Sql2o; - -@SpringBootApplication -public class CacheUpdater implements CommandLineRunner -{ - private static final Logger logger = LoggerFactory.getLogger(CacheUpdater.class); - - private final Sql2o sql2o; - private final MinioClient minioClient; - - @Value("${minio.bucket}") - private String minioBucket; - - @Autowired - public CacheUpdater( - @Qualifier("Runelite Cache SQL2O") Sql2o sql2o, - MinioClient minioClient - ) - { - this.sql2o = sql2o; - this.minioClient = minioClient; - } - - public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException - { - int rsVersion = RuneLiteAPI.getRsVersion(); - - try (Connection con = sql2o.beginTransaction()) - { - CacheDAO cacheDao = new CacheDAO(); - CacheEntry cache = cacheDao.findMostRecent(con); - boolean created = false; - if (cache == null) - { - created = true; - cache = cacheDao.createCache(con, rsVersion, Instant.now()); - } - - CacheStorage storage = new CacheStorage(cache, cacheDao, con); - Store store = new Store(storage); - store.load(); - - ExecutorService executor = Executors.newSingleThreadExecutor(); - - CacheClient client = new CacheClient(store, rsVersion, - (Archive archive, byte[] data) -> executor.submit(new CacheUploader(minioClient, minioBucket, archive, data))); - - client.connect(); - HandshakeResponseType result = client.handshake().join(); - - if (result != HandshakeResponseType.RESPONSE_OK) - { - logger.warn("Out of date!"); - return; - } - - List indexes = client.requestIndexes(); - List entries = cacheDao.findIndexesForCache(con, cache); - - if (!checkOutOfDate(indexes, entries)) - { - logger.info("All up to date."); - return; - } - - client.download(); - - CacheEntry newCache = created ? cache : cacheDao.createCache(con, rsVersion, Instant.now()); - - storage.setCacheEntry(newCache); - store.save(); - - // ensure objects are added to the store before they become - // visible in the database - executor.shutdown(); - while (!executor.awaitTermination(1, TimeUnit.SECONDS)) - { - logger.debug("Waiting for termination of executor..."); - } - - // commit database - con.commit(); - } - } - - private boolean checkOutOfDate(List indexes, List dbIndexes) - { - if (indexes.size() != dbIndexes.size()) - { - return true; - } - - for (int i = 0; i < indexes.size(); ++i) - { - IndexInfo ii = indexes.get(i); - IndexEntry ie = dbIndexes.get(i); - - if (ii.getId() != ie.getIndexId() - || ii.getRevision() != ie.getRevision() - || ii.getCrc() != ie.getCrc()) - { - return true; - } - } - - return false; - } - - @Override - public void run(String... args) throws Exception - { - update(); - } - - public static void main(String[] args) - { - SpringApplication.run(CacheUpdater.class, args).close(); - System.exit(0); - } - -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java b/cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java deleted file mode 100644 index 5712d82645..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/CacheUploader.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater; - -import com.google.common.hash.Hashing; -import com.google.common.io.BaseEncoding; -import io.minio.MinioClient; -import io.minio.errors.ErrorResponseException; -import io.minio.errors.InsufficientDataException; -import io.minio.errors.InternalException; -import io.minio.errors.InvalidArgumentException; -import io.minio.errors.InvalidBucketNameException; -import io.minio.errors.InvalidResponseException; -import io.minio.errors.NoResponseException; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import net.runelite.cache.fs.Archive; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xmlpull.v1.XmlPullParserException; - -public class CacheUploader implements Runnable -{ - private static final Logger logger = LoggerFactory.getLogger(CacheUploader.class); - - private final MinioClient minioClient; - private final String minioBucket; - private final Archive archive; - private final byte[] data; - - public CacheUploader(MinioClient minioClient, String minioBucket, Archive archive, byte[] data) - { - this.minioClient = minioClient; - this.minioBucket = minioBucket; - this.archive = archive; - this.data = data; - } - - @Override - public void run() - { - byte[] hash = Hashing.sha256().hashBytes(data).asBytes(); - String hashStr = BaseEncoding.base16().encode(hash); - - archive.setHash(hash); - - String path = new StringBuilder() - .append(hashStr, 0, 2) - .append('/') - .append(hashStr.substring(2)) - .toString(); - - try - { - try (InputStream in = minioClient.getObject(minioBucket, path)) - { - return; // already exists - } - catch (ErrorResponseException ex) - { - // doesn't exist - } - - minioClient.putObject(minioBucket, path, new ByteArrayInputStream(data), data.length, "binary/octet-stream"); - } - catch (ErrorResponseException | InsufficientDataException | InternalException | InvalidArgumentException | InvalidBucketNameException | NoResponseException | IOException | InvalidKeyException | NoSuchAlgorithmException | XmlPullParserException | InvalidResponseException ex) - { - logger.warn("unable to upload data to store", ex); - } - } - -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java b/cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java deleted file mode 100644 index 953fe9bd3a..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/InstantConverter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.cache.updater; - -import java.sql.Timestamp; -import java.time.Instant; -import org.sql2o.converters.Converter; -import org.sql2o.converters.ConverterException; - -public class InstantConverter implements Converter -{ - @Override - public Instant convert(Object val) throws ConverterException - { - Timestamp ts = (Timestamp) val; - return ts.toInstant(); - } - - @Override - public Object toDatabaseParam(Instant val) - { - return Timestamp.from(val); - } - -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java deleted file mode 100644 index 9bacab75b8..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/beans/ArchiveEntry.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater.beans; - -import lombok.Data; - -@Data -public class ArchiveEntry -{ - private int id; - private int archiveId; - private int nameHash; - private int crc; - private int revision; - private byte[] hash; -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java deleted file mode 100644 index c9081cd883..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/beans/CacheEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater.beans; - -import java.time.Instant; -import lombok.Data; - -@Data -public class CacheEntry -{ - private int id; - private int revision; - private Instant date; -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java deleted file mode 100644 index bb43c2a189..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/beans/FileEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater.beans; - -import lombok.Data; - -@Data -public class FileEntry -{ - private int id; - private int archiveId; - private int fileId; - private int nameHash; -} diff --git a/cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java b/cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java deleted file mode 100644 index a5a0748f18..0000000000 --- a/cache-updater/src/main/java/net/runelite/cache/updater/beans/IndexEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.updater.beans; - -import lombok.Data; - -@Data -public class IndexEntry -{ - private int id; - private int indexId; - private int crc; - private int revision; -} diff --git a/cache-updater/src/main/resources/application.yaml b/cache-updater/src/main/resources/application.yaml deleted file mode 100644 index df290d680f..0000000000 --- a/cache-updater/src/main/resources/application.yaml +++ /dev/null @@ -1,16 +0,0 @@ ---- -# Database -datasource: - runelite-cache: - driverClassName: com.mysql.jdbc.Driver - type: com.mysql.jdbc.jdbc2.optional.MysqlDataSource - url: jdbc:mysql://localhost/runelite-cache - username: runelite - password: runelite - -# Minio client storage for cache -minio: - endpoint: http://localhost:9000 - accesskey: AM54M27O4WZK65N6F8IP - secretkey: /PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP - bucket: runelite diff --git a/http-service-openosrs/http-service-openosrs.gradle.kts b/http-service-openosrs/http-service-openosrs.gradle.kts deleted file mode 100644 index 6bf4f040ac..0000000000 --- a/http-service-openosrs/http-service-openosrs.gradle.kts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2019 Owain van Brakel - * 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. - */ - -plugins { - war -} - -description = "Web Service OpenOSRS" - -dependencies { - annotationProcessor(Libraries.lombok) - - api(project(":cache")) - api(project(":http-api")) - api(project(":http-service")) - - implementation(Libraries.gson) - implementation(Libraries.guava) - implementation(Libraries.okhttp3) - implementation(Libraries.springbootJdbc) - implementation(Libraries.springbootDevtools) - implementation(Libraries.springbootStarterWeb) - implementation(Libraries.sql2o) - implementation(Libraries.jedis) { - exclude(module = "commons-pool2") - } - - providedCompile(Libraries.mariadbJdbc) - providedCompile(Libraries.lombok) - providedCompile(Libraries.springbootStarterTomcat) -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/SpringBootWebApplication.java b/http-service-openosrs/src/main/java/net/runelite/http/service/SpringBootWebApplication.java deleted file mode 100644 index cb935d1270..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/SpringBootWebApplication.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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; - -import ch.qos.logback.classic.LoggerContext; -import com.google.common.base.Strings; -import java.io.IOException; -import java.time.Instant; -import java.util.HashMap; -import java.util.Map; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.sql.DataSource; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.service.util.InstantConverter; -import okhttp3.Cache; -import okhttp3.OkHttpClient; -import org.slf4j.ILoggerFactory; -import org.slf4j.impl.StaticLoggerBinder; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.sql2o.Sql2o; -import org.sql2o.converters.Converter; -import org.sql2o.quirks.NoQuirks; - -@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) -@EnableScheduling -@Slf4j -public class SpringBootWebApplication extends SpringBootServletInitializer -{ - @Bean - protected ServletContextListener listener() - { - return new ServletContextListener() - { - @Override - public void contextInitialized(ServletContextEvent sce) - { - log.info("OpenOSRS API started"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) - { - // Destroy okhttp client - OkHttpClient client = RuneLiteAPI.CLIENT; - client.dispatcher().executorService().shutdown(); - client.connectionPool().evictAll(); - try - { - Cache cache = client.cache(); - if (cache != null) - { - cache.close(); - } - } - catch (IOException ex) - { - log.warn(null, ex); - } - - log.info("OpenOSRS API stopped"); - } - - }; - } - - @ConfigurationProperties(prefix = "datasource.openosrs") - @Bean("dataSourceRuneLite") - public DataSourceProperties dataSourceProperties() - { - return new DataSourceProperties(); - } - - @ConfigurationProperties(prefix = "datasource.openosrs-cache") - @Bean("dataSourceRuneLiteCache") - public DataSourceProperties dataSourcePropertiesCache() - { - return new DataSourceProperties(); - } - - @ConfigurationProperties(prefix = "datasource.openosrs-tracker") - @Bean("dataSourceRuneLiteTracker") - public DataSourceProperties dataSourcePropertiesTracker() - { - return new DataSourceProperties(); - } - - @Bean(value = "runelite", destroyMethod = "") - public DataSource runeliteDataSource(@Qualifier("dataSourceRuneLite") DataSourceProperties dataSourceProperties) - { - return getDataSource(dataSourceProperties); - } - - @Bean(value = "runelite-cache2", destroyMethod = "") - public DataSource runeliteCache2DataSource(@Qualifier("dataSourceRuneLiteCache") DataSourceProperties dataSourceProperties) - { - return getDataSource(dataSourceProperties); - } - - @Bean(value = "runelite-tracker", destroyMethod = "") - public DataSource runeliteTrackerDataSource(@Qualifier("dataSourceRuneLiteTracker") DataSourceProperties dataSourceProperties) - { - return getDataSource(dataSourceProperties); - } - - @Bean("Runelite SQL2O") - public Sql2o sql2o(@Qualifier("runelite") DataSource dataSource) - { - return createSql2oFromDataSource(dataSource); - } - - @Bean("Runelite Cache SQL2O") - public Sql2o cacheSql2o(@Qualifier("runelite-cache2") DataSource dataSource) - { - return createSql2oFromDataSource(dataSource); - } - - @Bean("Runelite XP Tracker SQL2O") - public Sql2o trackerSql2o(@Qualifier("runelite-tracker") DataSource dataSource) - { - return createSql2oFromDataSource(dataSource); - } - - private static DataSource getDataSource(DataSourceProperties dataSourceProperties) - { - if (!Strings.isNullOrEmpty(dataSourceProperties.getJndiName())) - { - // Use JNDI provided datasource, which is already configured with pooling - JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); - return dataSourceLookup.getDataSource(dataSourceProperties.getJndiName()); - } - else - { - return dataSourceProperties.initializeDataSourceBuilder().build(); - } - } - - private static Sql2o createSql2oFromDataSource(final DataSource dataSource) - { - final Map converters = new HashMap<>(); - converters.put(Instant.class, new InstantConverter()); - return new Sql2o(dataSource, new NoQuirks(converters)); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) - { - return application.sources(SpringBootWebApplication.class); - } - - @Override - public void onStartup(ServletContext servletContext) throws ServletException - { - super.onStartup(servletContext); - ILoggerFactory loggerFactory = StaticLoggerBinder.getSingleton().getLoggerFactory(); - if (loggerFactory instanceof LoggerContext) - { - LoggerContext loggerContext = (LoggerContext) loggerFactory; - loggerContext.setPackagingDataEnabled(false); - log.debug("Disabling logback packaging data"); - } - } - - public static void main(String[] args) - { - SpringApplication.run(SpringBootWebApplication.class, args); - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java b/http-service-openosrs/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java deleted file mode 100644 index 841eb28eeb..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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; - -import java.util.List; -import net.runelite.http.api.RuneLiteAPI; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.MediaType; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -@EnableWebMvc -public class SpringWebMvcConfigurer implements WebMvcConfigurer -{ - /** - * Configure .js as application/json to trick Cloudflare into caching json responses - */ - @Override - public void configureContentNegotiation(ContentNegotiationConfigurer configurer) - { - configurer.mediaType("js", MediaType.APPLICATION_JSON); - } - - /** - * Use GSON instead of Jackson for JSON serialization - * @param converters - */ - @Override - public void extendMessageConverters(List> converters) - { - // Could not figure out a better way to force GSON - converters.removeIf(MappingJackson2HttpMessageConverter.class::isInstance); - - GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter(); - gsonHttpMessageConverter.setGson(RuneLiteAPI.GSON); - converters.add(gsonHttpMessageConverter); - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationCache.java b/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationCache.java deleted file mode 100644 index 05f8e5ae11..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationCache.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.animation; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -class AnimationCache -{ - private int npcid; - private int anim1; - private int anim2; - private int anim3; - private int anim4; - private int anim5; - private int anim6; - private int anim7; - private int anim8; - private int anim9; - private int anim10; -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationController.java b/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationController.java deleted file mode 100644 index c588b8193d..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationController.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.animation; - -import java.util.List; -import java.util.stream.Collectors; -import net.runelite.http.api.animation.AnimationKey; -import net.runelite.http.api.animation.AnimationRequest; -import net.runelite.http.service.util.exception.NotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import static org.springframework.web.bind.annotation.RequestMethod.POST; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/animation") -public class AnimationController -{ - @Autowired - private AnimationEndpoint animationService; - - @RequestMapping(method = POST) - public void submit(@RequestBody AnimationRequest animationRequest) - { - animationService.submit(animationRequest); - } - - @GetMapping - public List get() - { - return animationService.get().stream() - .map(AnimationController::entryToKey) - .collect(Collectors.toList()); - } - - @GetMapping("/{npcid}") - public AnimationKey getRegion(@PathVariable int npcid) - { - AnimationEntry animationEntry = animationService.getNPC(npcid); - if (animationEntry == null) - { - throw new NotFoundException(); - } - - return entryToKey(animationEntry); - } - - private static AnimationKey entryToKey(AnimationEntry xe) - { - AnimationKey animationKey = new AnimationKey(); - animationKey.setNPCId(xe.getNPCId()); - animationKey.setAnimations(new int[] - { - xe.getAnimations()[0], - xe.getAnimations()[1], - xe.getAnimations()[2], - xe.getAnimations()[3], - xe.getAnimations()[4], - xe.getAnimations()[5], - xe.getAnimations()[6], - xe.getAnimations()[7], - xe.getAnimations()[8], - xe.getAnimations()[9], - }); - return animationKey; - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEndpoint.java b/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEndpoint.java deleted file mode 100644 index d33ca43051..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEndpoint.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.animation; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import java.util.List; -import net.runelite.http.api.animation.AnimationKey; -import net.runelite.http.api.animation.AnimationRequest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.Query; -import org.sql2o.Sql2o; - -@Service -public class AnimationEndpoint -{ - private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS `animation` (\n" - + " `id` int(11) NOT NULL AUTO_INCREMENT,\n" - + " `npcid` int(11) NOT NULL,\n" - + " `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" - + " `rev` int(11) NOT NULL,\n" - + " `anim1` int(11) NOT NULL,\n" - + " `anim2` int(11),\n" - + " `anim3` int(11),\n" - + " `anim4` int(11),\n" - + " `anim5` int(11),\n" - + " `anim6` int(11),\n" - + " `anim7` int(11),\n" - + " `anim8` int(11),\n" - + " `anim9` int(11),\n" - + " `anim10` int(11),\n" - + " PRIMARY KEY (`id`),\n" - + " KEY `npcid` (`npcid`,`time`)\n" - + ") ENGINE=InnoDB"; - - private final Sql2o sql2o; - - private final Cache keyCache = CacheBuilder.newBuilder() - .maximumSize(1024) - .build(); - - @Autowired - public AnimationEndpoint( - @Qualifier("Runelite SQL2O") Sql2o sql2o - ) - { - this.sql2o = sql2o; - - try (Connection con = sql2o.beginTransaction()) - { - con.createQuery(CREATE_SQL) - .executeUpdate(); - } - } - - private AnimationEntry findLatestAnimations(Connection con, int npcid) - { - return con.createQuery("select npcid, time, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10 from animation " - + "where npcid = :npcid " - + "order by time desc " - + "limit 1") - .addParameter("npcid", npcid) - .executeAndFetchFirst(AnimationEntry.class); - } - - public void submit(AnimationRequest animationRequest) - { - boolean cached = true; - for (AnimationKey key : animationRequest.getKeys()) - { - int npcid = key.getNPCId(); - int[] animations = key.getAnimations(); - - AnimationCache animationCache = keyCache.getIfPresent(npcid); - if (animationCache == null - || animationCache.getAnim1() != animations[0] - || animationCache.getAnim2() != animations[1] - || animationCache.getAnim3() != animations[2] - || animationCache.getAnim4() != animations[3] - || animationCache.getAnim5() != animations[4] - || animationCache.getAnim6() != animations[5] - || animationCache.getAnim7() != animations[6] - || animationCache.getAnim8() != animations[7] - || animationCache.getAnim9() != animations[8] - || animationCache.getAnim10() != animations[9]) - { - cached = false; - keyCache.put(npcid, new AnimationCache(npcid, animations[0], animations[1], animations[2], animations[3], animations[4], animations[5], animations[6], animations[7], animations[8], animations[9])); - } - } - - if (cached) - { - return; - } - - try (Connection con = sql2o.beginTransaction()) - { - Query query = null; - - for (AnimationKey key : animationRequest.getKeys()) - { - int npcid = key.getNPCId(); - int[] animations = key.getAnimations(); - - AnimationEntry animationEntry = findLatestAnimations(con, npcid); - - if (animations.length != 10) - { - throw new IllegalArgumentException("Key length must be 10"); - } - - // already have these? - if (animationEntry != null - && animationEntry.getAnimations()[0] == animations[0] - && animationEntry.getAnimations()[1] == animations[1] - && animationEntry.getAnimations()[2] == animations[2] - && animationEntry.getAnimations()[3] == animations[3] - && animationEntry.getAnimations()[4] == animations[4] - && animationEntry.getAnimations()[5] == animations[5] - && animationEntry.getAnimations()[6] == animations[6] - && animationEntry.getAnimations()[7] == animations[7] - && animationEntry.getAnimations()[8] == animations[8] - && animationEntry.getAnimations()[9] == animations[9]) - { - continue; - } - - - if (query == null) - { - query = con.createQuery("insert into animation (npcid, rev, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10) " - + "values (:npcid, :rev, :anim1, :anim2, :anim3, :anim4, anim5, anim6, anim7, anim8, anim9, anim10)"); - } - - query.addParameter("npcid", npcid) - .addParameter("rev", animationRequest.getRevision()) - .addParameter("anim1", animations[0]) - .addParameter("anim2", animations[1]) - .addParameter("anim3", animations[2]) - .addParameter("anim4", animations[3]) - .addParameter("anim5", animations[4]) - .addParameter("anim6", animations[5]) - .addParameter("anim7", animations[6]) - .addParameter("anim8", animations[7]) - .addParameter("anim9", animations[8]) - .addParameter("anim10", animations[9]) - .addToBatch(); - } - - if (query != null) - { - query.executeBatch(); - con.commit(false); - } - } - } - - public List get() - { - try (Connection con = sql2o.open()) - { - return con.createQuery( - "select t1.npcid, t2.time, t2.rev, t2.anim1, t2.anim2, t2.anim3, t2.anim4, t2.anim5, t2.anim6, t2.anim7, t2.anim8, t2.anim9, t2.anim10 from " + - "(select npcid,max(id) as id from animation group by npcid) t1 " + - "join animation t2 on t1.id = t2.id") - .executeAndFetch(AnimationEntry.class); - } - } - - public AnimationEntry getNPC(int npcid) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("select npcid, time, rev, anim1, anim2, anim3, anim4, anim5, anim6, anim7, anim8, anim9, anim10 from animation " - + "where npcid = :npcid order by time desc limit 1") - .addParameter("npcid", npcid) - .executeAndFetchFirst(AnimationEntry.class); - } - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEntry.java b/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEntry.java deleted file mode 100644 index af8ed67257..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/animation/AnimationEntry.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.animation; - -import java.time.Instant; - -public class AnimationEntry -{ - private int npcid; - private Instant time; - private int rev; - private int[] animations; - - public int getNPCId() - { - return npcid; - } - - public void setNPCId(int npcid) - { - this.npcid = npcid; - } - - public Instant getTime() - { - return time; - } - - public void setTime(Instant time) - { - this.time = time; - } - - public int getRev() - { - return rev; - } - - public void setRev(int rev) - { - this.rev = rev; - } - - public int[] getAnimations() - { - return animations; - } - - public void setAnimations(int[] animations) - { - this.animations = animations; - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatController.java b/http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatController.java deleted file mode 100644 index df287e6512..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatController.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.chat; - -import java.util.regex.Pattern; -import com.google.common.base.Strings; -import net.runelite.http.api.chat.House; -import net.runelite.http.service.util.exception.NotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/chat") -public class ChatController -{ - private static final Pattern STRING_VALIDATION = Pattern.compile("[^a-zA-Z0-9' -]"); - private static final int STRING_MAX_LENGTH = 50; - - @Autowired - private ChatService chatService; - - @PostMapping("/layout") - public void submitLayout(@RequestParam String name, @RequestParam String layout) - { - if (Strings.isNullOrEmpty(layout)) - { - return; - } - - chatService.setLayout(name, layout); - } - - @GetMapping("/layout") - public String getLayout(@RequestParam String name) - { - String layout = chatService.getLayout(name); - if (layout == null) - { - throw new NotFoundException(); - } - return layout; - } - - @PostMapping("/hosts") - public void submitHost(@RequestParam int world, @RequestParam String location, @RequestParam String owner, @RequestParam boolean guildedAltar, @RequestParam boolean occultAltar, @RequestParam boolean spiritTree, @RequestParam boolean fairyRing, @RequestParam boolean wildernessObelisk, @RequestParam boolean repairStand, @RequestParam boolean combatDummy, @RequestParam(required = false, defaultValue = "false") boolean remove) - { - if (!location.equals("Rimmington") && !location.equals("Yanille")) - { - return; - } - - House house = new House(); - house.setOwner(owner); - house.setGuildedAltarPresent(guildedAltar); - house.setOccultAltarPresent(occultAltar); - house.setSpiritTreePresent(spiritTree); - house.setFairyRingPresent(fairyRing); - house.setWildernessObeliskPresent(wildernessObelisk); - house.setRepairStandPresent(repairStand); - house.setCombatDummyPresent(combatDummy); - - if (remove) - { - chatService.removeHost(world, location, house); - } - else - { - chatService.addHost(world, location, house); - } - } - - @GetMapping("/hosts") - public House[] getHosts(@RequestParam int world, @RequestParam String location) - { - return chatService.getHosts(world, location); - } -} \ No newline at end of file diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatService.java b/http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatService.java deleted file mode 100644 index aa23d3f18d..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/chat/ChatService.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.chat; - -import java.time.Duration; -import java.util.List; -import net.runelite.http.api.chat.ChatClient; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.chat.House; -import net.runelite.http.service.util.redis.RedisPool; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import redis.clients.jedis.Jedis; - -@Service -public class ChatService -{ - private static final Duration EXPIRE = Duration.ofMinutes(2); - - private final RedisPool jedisPool; - private final ChatClient chatClient = new ChatClient(); - - - @Autowired - public ChatService(RedisPool jedisPool) - { - this.jedisPool = jedisPool; - } - - public String getLayout(String name) - { - String value; - try (Jedis jedis = jedisPool.getResource()) - { - value = jedis.get("layout." + name); - } - return value; - } - - public void setLayout(String name, String layout) - { - if (!chatClient.testLayout(layout)) - { - throw new IllegalArgumentException(layout); - } - - try (Jedis jedis = jedisPool.getResource()) - { - jedis.setex("layout." + name, (int) EXPIRE.getSeconds(), layout); - } - } - - public void addHost(int world, String location, House house) - { - String houseJSON = house.toString(); - - String key = "hosts.w" + Integer.toString(world) + "." + location; - - try (Jedis jedis = jedisPool.getResource()) - { - jedis.rpush(key, houseJSON); - } - } - - public House[] getHosts(int world, String location) - { - List json; - String key = "hosts.w" + Integer.toString(world) + "." + location; - - try (Jedis jedis = jedisPool.getResource()) - { - json = jedis.lrange(key, 0, 25); - } - - if (json.isEmpty()) - { - return null; - } - - House[] hosts = new House[json.size()]; - for (int i = 0; i < json.size(); i++) - { - hosts[i] = RuneLiteAPI.GSON.fromJson(json.get(i), House.class); - } - return hosts; - } - - public void removeHost(int world, String location, House house) - { - String json = house.toString(); - String key = "hosts.w" + Integer.toString(world) + "." + location; - - try (Jedis jedis = jedisPool.getResource()) - { - jedis.lrem(key, 0, json); - } - } -} \ No newline at end of file diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaCache.java b/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaCache.java deleted file mode 100644 index 7c5f2bb5b0..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaCache.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xtea; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -class XteaCache -{ - private int region; - private int key1; - private int key2; - private int key3; - private int key4; -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaController.java b/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaController.java deleted file mode 100644 index b0c592fc70..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaController.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xtea; - -import java.util.List; -import java.util.stream.Collectors; -import net.runelite.http.api.xtea.XteaKey; -import net.runelite.http.api.xtea.XteaRequest; -import net.runelite.http.service.util.exception.NotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import static org.springframework.web.bind.annotation.RequestMethod.POST; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/xtea") -public class XteaController -{ - @Autowired - private XteaEndpoint xteaService; - - @RequestMapping(method = POST) - public void submit(@RequestBody XteaRequest xteaRequest) - { - xteaService.submit(xteaRequest); - } - - @GetMapping - public List get() - { - return xteaService.get().stream() - .map(XteaController::entryToKey) - .collect(Collectors.toList()); - } - - @GetMapping("/{region}") - public XteaKey getRegion(@PathVariable int region) - { - XteaEntry xteaRegion = xteaService.getRegion(region); - if (xteaRegion == null) - { - throw new NotFoundException(); - } - - return entryToKey(xteaRegion); - } - - private static XteaKey entryToKey(XteaEntry xe) - { - XteaKey xteaKey = new XteaKey(); - xteaKey.setRegion(xe.getRegion()); - xteaKey.setKeys(new int[] - { - xe.getKey1(), - xe.getKey2(), - xe.getKey3(), - xe.getKey4() - }); - return xteaKey; - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEndpoint.java b/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEndpoint.java deleted file mode 100644 index e6c82d74ac..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEndpoint.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.xtea; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import java.util.List; -import net.runelite.http.api.xtea.XteaKey; -import net.runelite.http.api.xtea.XteaRequest; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.Query; -import org.sql2o.Sql2o; - -@Service -public class XteaEndpoint -{ - private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS `xtea` (\n" - + " `id` int(11) NOT NULL AUTO_INCREMENT,\n" - + " `region` int(11) NOT NULL,\n" - + " `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" - + " `rev` int(11) NOT NULL,\n" - + " `key1` int(11) NOT NULL,\n" - + " `key2` int(11) NOT NULL,\n" - + " `key3` int(11) NOT NULL,\n" - + " `key4` int(11) NOT NULL,\n" - + " PRIMARY KEY (`id`),\n" - + " KEY `region` (`region`,`time`)\n" - + ") ENGINE=InnoDB"; - - private final Sql2o sql2o; - - private final Cache keyCache = CacheBuilder.newBuilder() - .maximumSize(1024) - .build(); - - @Autowired - public XteaEndpoint( - @Qualifier("Runelite SQL2O") Sql2o sql2o - ) - { - this.sql2o = sql2o; - - try (Connection con = sql2o.beginTransaction()) - { - con.createQuery(CREATE_SQL) - .executeUpdate(); - } - } - - private XteaEntry findLatestXtea(Connection con, int region) - { - return con.createQuery("select region, time, key1, key2, key3, key4 from xtea " - + "where region = :region " - + "order by time desc " - + "limit 1") - .addParameter("region", region) - .executeAndFetchFirst(XteaEntry.class); - } - - public void submit(XteaRequest xteaRequest) - { - boolean cached = true; - for (XteaKey key : xteaRequest.getKeys()) - { - int region = key.getRegion(); - int[] keys = key.getKeys(); - - XteaCache xteaCache = keyCache.getIfPresent(region); - if (xteaCache == null - || xteaCache.getKey1() != keys[0] - || xteaCache.getKey2() != keys[1] - || xteaCache.getKey3() != keys[2] - || xteaCache.getKey4() != keys[3]) - { - cached = false; - keyCache.put(region, new XteaCache(region, keys[0], keys[1], keys[2], keys[3])); - } - } - - if (cached) - { - return; - } - - try (Connection con = sql2o.beginTransaction()) - { - Query query = null; - - for (XteaKey key : xteaRequest.getKeys()) - { - int region = key.getRegion(); - int[] keys = key.getKeys(); - - XteaEntry xteaEntry = findLatestXtea(con, region); - - if (keys.length != 4) - { - throw new IllegalArgumentException("Key length must be 4"); - } - - // already have these? - // TODO : check if useful / works should check with findLatestXtea - if (xteaEntry != null - && xteaEntry.getKey1() == keys[0] - && xteaEntry.getKey2() == keys[1] - && xteaEntry.getKey3() == keys[2] - && xteaEntry.getKey4() == keys[3]) - { - continue; - } - - - if (query == null) - { - query = con.createQuery("insert into xtea (region, rev, key1, key2, key3, key4) " - + "values (:region, :rev, :key1, :key2, :key3, :key4)"); - } - - query.addParameter("region", region) - .addParameter("rev", xteaRequest.getRevision()) - .addParameter("key1", keys[0]) - .addParameter("key2", keys[1]) - .addParameter("key3", keys[2]) - .addParameter("key4", keys[3]) - .addToBatch(); - } - - if (query != null) - { - query.executeBatch(); - con.commit(false); - } - } - } - - public List get() - { - try (Connection con = sql2o.open()) - { - return con.createQuery( - "select t1.region, t2.time, t2.rev, t2.key1, t2.key2, t2.key3, t2.key4 from " + - "(select region,max(id) as id from xtea group by region) t1 " + - "join xtea t2 on t1.id = t2.id") - .executeAndFetch(XteaEntry.class); - } - } - - public XteaEntry getRegion(int region) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("select region, time, rev, key1, key2, key3, key4 from xtea " - + "where region = :region order by time desc limit 1") - .addParameter("region", region) - .executeAndFetchFirst(XteaEntry.class); - } - } -} diff --git a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEntry.java b/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEntry.java deleted file mode 100644 index e1e86d0bf7..0000000000 --- a/http-service-openosrs/src/main/java/net/runelite/http/service/xtea/XteaEntry.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.xtea; - -import java.time.Instant; - -public class XteaEntry -{ - private int region; - private Instant time; - private int rev; - private int key1; - private int key2; - private int key3; - private int key4; - - public int getRegion() - { - return region; - } - - public void setRegion(int region) - { - this.region = region; - } - - public Instant getTime() - { - return time; - } - - public void setTime(Instant time) - { - this.time = time; - } - - public int getRev() - { - return rev; - } - - public void setRev(int rev) - { - this.rev = rev; - } - - public int getKey1() - { - return key1; - } - - public void setKey1(int key1) - { - this.key1 = key1; - } - - public int getKey2() - { - return key2; - } - - public void setKey2(int key2) - { - this.key2 = key2; - } - - public int getKey3() - { - return key3; - } - - public void setKey3(int key3) - { - this.key3 = key3; - } - - public int getKey4() - { - return key4; - } - - public void setKey4(int key4) - { - this.key4 = key4; - } - -} diff --git a/http-service-openosrs/src/main/resources/application-dev.yaml b/http-service-openosrs/src/main/resources/application-dev.yaml deleted file mode 100644 index cc2286e9b3..0000000000 --- a/http-service-openosrs/src/main/resources/application-dev.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# Enable debug logging -debug: true -logging.level.net.runelite: DEBUG - -# Development data sources -datasource: - runelite: - jndiName: - driverClassName: org.mariadb.jdbc.Driver - type: org.mariadb.jdbc.MariaDbDataSource - url: jdbc:mariadb://localhost:3306/runelite - username: runelite - password: runelite - runelite-cache: - jndiName: - driverClassName: org.mariadb.jdbc.Driver - type: org.mariadb.jdbc.MariaDbDataSource - url: jdbc:mariadb://localhost:3306/cache - username: runelite - password: runelite - runelite-tracker: - jndiName: - driverClassName: org.mariadb.jdbc.Driver - type: org.mariadb.jdbc.MariaDbDataSource - url: jdbc:mariadb://localhost:3306/xptracker - username: runelite - password: runelite - -# Development oauth callback (without proxy) -oauth: - callback: http://localhost:8080/account/callback diff --git a/http-service-openosrs/src/main/resources/application.yaml b/http-service-openosrs/src/main/resources/application.yaml deleted file mode 100644 index 8f21c31693..0000000000 --- a/http-service-openosrs/src/main/resources/application.yaml +++ /dev/null @@ -1,39 +0,0 @@ -datasource: - openosrs: - jndiName: java:comp/env/jdbc/runelite - openosrs-cache: - jndiName: java:comp/env/jdbc/runelite-cache2 - openosrs-tracker: - jndiName: java:comp/env/jdbc/runelite-tracker - -# By default Spring tries to register the datasource as an MXBean, -# so if multiple apis are deployed on one web container with -# shared datasource it tries to register it multiples times and -# fails when starting the 2nd api -spring.jmx.enabled: false - -# Google OAuth client -oauth: - client-id: - client-secret: - callback: https://api.runelite.net/oauth/ - -# Minio client storage for cache -minio: - endpoint: http://localhost:9000 - accesskey: AM54M27O4WZK65N6F8IP - secretkey: /PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP - bucket: runelite - -# Redis client for temporary data storage -redis: - pool.size: 10 - host: http://localhost:6379 - - -# Twitter client for feed -runelite: - twitter: - consumerkey: - secretkey: - listid: 968949795153948673 \ No newline at end of file diff --git a/http-service-openosrs/src/main/resources/net/runelite/http/service/xp/schema.sql b/http-service-openosrs/src/main/resources/net/runelite/http/service/xp/schema.sql deleted file mode 100644 index 70f83a30fd..0000000000 --- a/http-service-openosrs/src/main/resources/net/runelite/http/service/xp/schema.sql +++ /dev/null @@ -1,135 +0,0 @@ --- MySQL dump 10.16 Distrib 10.2.18-MariaDB, for Linux (x86_64) --- --- Host: localhost Database: xptracker --- ------------------------------------------------------ --- Server version 10.2.18-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 `player` --- - -DROP TABLE IF EXISTS `player`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `player` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(32) NOT NULL, - `tracked_since` timestamp NOT NULL DEFAULT current_timestamp(), - `last_updated` timestamp NOT NULL DEFAULT current_timestamp(), - `rank` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `xp` --- - -DROP TABLE IF EXISTS `xp`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `xp` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `time` timestamp NOT NULL DEFAULT current_timestamp(), - `player` int(11) NOT NULL, - `attack_xp` int(11) NOT NULL, - `defence_xp` int(11) NOT NULL, - `strength_xp` int(11) NOT NULL, - `hitpoints_xp` int(11) NOT NULL, - `ranged_xp` int(11) NOT NULL, - `prayer_xp` int(11) NOT NULL, - `magic_xp` int(11) NOT NULL, - `cooking_xp` int(11) NOT NULL, - `woodcutting_xp` int(11) NOT NULL, - `fletching_xp` int(11) NOT NULL, - `fishing_xp` int(11) NOT NULL, - `firemaking_xp` int(11) NOT NULL, - `crafting_xp` int(11) NOT NULL, - `smithing_xp` int(11) NOT NULL, - `mining_xp` int(11) NOT NULL, - `herblore_xp` int(11) NOT NULL, - `agility_xp` int(11) NOT NULL, - `thieving_xp` int(11) NOT NULL, - `slayer_xp` int(11) NOT NULL, - `farming_xp` int(11) NOT NULL, - `runecraft_xp` int(11) NOT NULL, - `hunter_xp` int(11) NOT NULL, - `construction_xp` int(11) NOT NULL, - `overall_xp` int(11) GENERATED ALWAYS AS (`attack_xp` + `defence_xp` + `strength_xp` + `hitpoints_xp` + `ranged_xp` + `prayer_xp` + `magic_xp` + `cooking_xp` + `woodcutting_xp` + `fletching_xp` + `fishing_xp` + `firemaking_xp` + `crafting_xp` + `smithing_xp` + `mining_xp` + `herblore_xp` + `agility_xp` + `thieving_xp` + `slayer_xp` + `farming_xp` + `runecraft_xp` + `hunter_xp` + `construction_xp`) VIRTUAL, - `attack_level` int(11) GENERATED ALWAYS AS (level_for_xp(`attack_xp` AS `attack_xp`)) VIRTUAL, - `defence_level` int(11) GENERATED ALWAYS AS (level_for_xp(`defence_xp` AS `defence_xp`)) VIRTUAL, - `strength_level` int(11) GENERATED ALWAYS AS (level_for_xp(`strength_xp` AS `strength_xp`)) VIRTUAL, - `hitpoints_level` int(11) GENERATED ALWAYS AS (level_for_xp(`hitpoints_xp` AS `hitpoints_xp`)) VIRTUAL, - `ranged_level` int(11) GENERATED ALWAYS AS (level_for_xp(`ranged_xp` AS `ranged_xp`)) VIRTUAL, - `prayer_level` int(11) GENERATED ALWAYS AS (level_for_xp(`prayer_xp` AS `prayer_xp`)) VIRTUAL, - `magic_level` int(11) GENERATED ALWAYS AS (level_for_xp(`magic_xp` AS `magic_xp`)) VIRTUAL, - `cooking_level` int(11) GENERATED ALWAYS AS (level_for_xp(`cooking_xp` AS `cooking_xp`)) VIRTUAL, - `woodcutting_level` int(11) GENERATED ALWAYS AS (level_for_xp(`woodcutting_xp` AS `woodcutting_xp`)) VIRTUAL, - `fletching_level` int(11) GENERATED ALWAYS AS (level_for_xp(`fletching_xp` AS `fletching_xp`)) VIRTUAL, - `fishing_level` int(11) GENERATED ALWAYS AS (level_for_xp(`fishing_xp` AS `fishing_xp`)) VIRTUAL, - `firemaking_level` int(11) GENERATED ALWAYS AS (level_for_xp(`firemaking_xp` AS `firemaking_xp`)) VIRTUAL, - `crafting_level` int(11) GENERATED ALWAYS AS (level_for_xp(`crafting_xp` AS `crafting_xp`)) VIRTUAL, - `smithing_level` int(11) GENERATED ALWAYS AS (level_for_xp(`smithing_xp` AS `smithing_xp`)) VIRTUAL, - `mining_level` int(11) GENERATED ALWAYS AS (level_for_xp(`mining_xp` AS `mining_xp`)) VIRTUAL, - `herblore_level` int(11) GENERATED ALWAYS AS (level_for_xp(`herblore_xp` AS `herblore_xp`)) VIRTUAL, - `agility_level` int(11) GENERATED ALWAYS AS (level_for_xp(`agility_xp` AS `agility_xp`)) VIRTUAL, - `thieving_level` int(11) GENERATED ALWAYS AS (level_for_xp(`thieving_xp` AS `thieving_xp`)) VIRTUAL, - `slayer_level` int(11) GENERATED ALWAYS AS (level_for_xp(`slayer_xp` AS `slayer_xp`)) VIRTUAL, - `farming_level` int(11) GENERATED ALWAYS AS (level_for_xp(`farming_xp` AS `farming_xp`)) VIRTUAL, - `runecraft_level` int(11) GENERATED ALWAYS AS (level_for_xp(`runecraft_xp` AS `runecraft_xp`)) VIRTUAL, - `hunter_level` int(11) GENERATED ALWAYS AS (level_for_xp(`hunter_xp` AS `hunter_xp`)) VIRTUAL, - `construction_level` int(11) GENERATED ALWAYS AS (level_for_xp(`construction_xp` AS `construction_xp`)) VIRTUAL, - `overall_level` int(11) GENERATED ALWAYS AS (`attack_level` + `defence_level` + `strength_level` + `hitpoints_level` + `ranged_level` + `prayer_level` + `magic_level` + `cooking_level` + `woodcutting_level` + `fletching_level` + `fishing_level` + `firemaking_level` + `crafting_level` + `smithing_level` + `mining_level` + `herblore_level` + `agility_level` + `thieving_level` + `slayer_level` + `farming_level` + `runecraft_level` + `hunter_level` + `construction_level`) VIRTUAL, - `attack_rank` int(11) NOT NULL, - `defence_rank` int(11) NOT NULL, - `strength_rank` int(11) NOT NULL, - `hitpoints_rank` int(11) NOT NULL, - `ranged_rank` int(11) NOT NULL, - `prayer_rank` int(11) NOT NULL, - `magic_rank` int(11) NOT NULL, - `cooking_rank` int(11) NOT NULL, - `woodcutting_rank` int(11) NOT NULL, - `fletching_rank` int(11) NOT NULL, - `fishing_rank` int(11) NOT NULL, - `firemaking_rank` int(11) NOT NULL, - `crafting_rank` int(11) NOT NULL, - `smithing_rank` int(11) NOT NULL, - `mining_rank` int(11) NOT NULL, - `herblore_rank` int(11) NOT NULL, - `agility_rank` int(11) NOT NULL, - `thieving_rank` int(11) NOT NULL, - `slayer_rank` int(11) NOT NULL, - `farming_rank` int(11) NOT NULL, - `runecraft_rank` int(11) NOT NULL, - `hunter_rank` int(11) NOT NULL, - `construction_rank` int(11) NOT NULL, - `overall_rank` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `player_time` (`player`,`time`), - KEY `idx_time` (`time`), - CONSTRAINT `fk_player` FOREIGN KEY (`player`) REFERENCES `player` (`id`) -) ENGINE=InnoDB 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 2019-02-15 21:01:17 \ No newline at end of file diff --git a/http-service-openosrs/src/main/templates/markdown.hbs b/http-service-openosrs/src/main/templates/markdown.hbs deleted file mode 100644 index 1beacd052a..0000000000 --- a/http-service-openosrs/src/main/templates/markdown.hbs +++ /dev/null @@ -1,110 +0,0 @@ -{{#info}} -# {{title}} -{{join schemes " | "}}://{{host}}{{basePath}} - -{{description}} - -{{#contact}} -[**Contact the developer**](mailto:{{email}}) -{{/contact}} - -**Version** {{version}} - -{{#if termsOfService}} -[**Terms of Service**]({{termsOfService}}) -{{/if}} - -{{/info}} - -{{#if consumes}}__Consumes:__ {{join consumes ", "}}{{/if}} - -{{#if produces}}__Produces:__ {{join produces ", "}}{{/if}} - -{{#if securityDefinitions}} -# Security Definitions -{{> security}} -{{/if}} - -
-Table Of Contents -[toc] -
- -# APIs - -{{#each paths}} -## {{@key}} -{{#this}} -{{#get}} -### GET -{{> operation}} -{{/get}} - -{{#put}} -### PUT -{{> operation}} -{{/put}} - -{{#post}} -### POST - -{{> operation}} - -{{/post}} - -{{#delete}} -### DELETE -{{> operation}} -{{/delete}} - -{{#option}} -### OPTION -{{> operation}} -{{/option}} - -{{#patch}} -### PATCH -{{> operation}} -{{/patch}} - -{{#head}} -### HEAD -{{> operation}} -{{/head}} - -{{/this}} -{{/each}} - -# Definitions -{{#each definitions}} -## {{@key}} - - - - - - - - - - {{#each this.properties}} - - - - - - - - {{/each}} -
nametyperequireddescriptionexample
{{@key}} - {{#ifeq type "array"}} - {{#items.$ref}} - {{type}}[{{basename items.$ref}}] - {{/items.$ref}} - {{^items.$ref}}{{type}}[{{items.type}}]{{/items.$ref}} - {{else}} - {{#$ref}}{{basename $ref}}{{/$ref}} - {{^$ref}}{{type}}{{#format}} ({{format}}){{/format}}{{/$ref}} - {{/ifeq}} - {{#required}}required{{/required}}{{^required}}optional{{/required}}{{#description}}{{{description}}}{{/description}}{{^description}}-{{/description}}{{example}}
-{{/each}} diff --git a/http-service-openosrs/src/main/templates/operation.hbs b/http-service-openosrs/src/main/templates/operation.hbs deleted file mode 100644 index f7015850b8..0000000000 --- a/http-service-openosrs/src/main/templates/operation.hbs +++ /dev/null @@ -1,71 +0,0 @@ -{{#deprecated}}-deprecated-{{/deprecated}} -{{summary}} - -{{description}} - -{{#if externalDocs.url}}{{externalDocs.description}}. [See external documents for more details]({{externalDocs.url}}) -{{/if}} - -{{#if security}} -#### Security -{{/if}} - -{{#security}} -{{#each this}} -* {{@key}} -{{#this}} * {{this}} -{{/this}} -{{/each}} -{{/security}} - -#### Request - -{{#if consumes}}__Content-Type:__ {{join consumes ", "}}{{/if}} - -##### Parameters -{{#if parameters}} - - - - - - - - - -{{/if}} - -{{#parameters}} - - - - - - -{{#ifeq in "body"}} - -{{else}} - {{#ifeq type "array"}} - - {{else}} - - {{/ifeq}} -{{/ifeq}} - -{{/parameters}} -{{#if parameters}} -
NameLocated inRequiredDescriptionDefaultSchema
{{name}}{{in}}{{#if required}}yes{{else}}no{{/if}}{{description}}{{#if pattern}} (**Pattern**: `{{pattern}}`){{/if}} - - {{#ifeq schema.type "array"}}Array[{{basename schema.items.$ref}}]{{/ifeq}} - {{#schema.$ref}}{{basename schema.$ref}} {{/schema.$ref}} - Array[{{items.type}}] ({{collectionFormat}}){{type}} {{#format}}({{format}}){{/format}}
-{{/if}} - - -#### Response - -{{#if produces}}__Content-Type:__ {{join produces ", "}}{{/if}} - -| Status Code | Reason | Response Model | -|-------------|-------------|----------------| -{{#each responses}}| {{@key}} | {{description}} | {{#schema.$ref}}{{basename schema.$ref}}{{/schema.$ref}}{{#ifeq schema.type "array"}}Array[{{basename schema.items.$ref}}]{{/ifeq}}{{^schema}} - {{/schema}}| -{{/each}} diff --git a/http-service-openosrs/src/main/templates/security.hbs b/http-service-openosrs/src/main/templates/security.hbs deleted file mode 100644 index 04f86e8380..0000000000 --- a/http-service-openosrs/src/main/templates/security.hbs +++ /dev/null @@ -1,88 +0,0 @@ -{{#each securityDefinitions}} -### {{@key}} -{{#this}} -{{#ifeq type "oauth2"}} - - - - - -{{#if description}} - - - - -{{/if}} -{{#if authorizationUrl}} - - - - -{{/if}} -{{#if flow}} - - - - -{{/if}} -{{#if tokenUrl}} - - - - -{{/if}} -{{#if scopes}} - - -{{#each scopes}} - - - - -{{/each}} - -{{/if}} -
type{{type}}
description{{description}}
authorizationUrl{{authorizationUrl}}
flow{{flow}}
tokenUrl{{tokenUrl}}
scopes{{@key}}{{this}}
-{{/ifeq}} -{{#ifeq type "apiKey"}} - - - - - -{{#if description}} - - - - -{{/if}} -{{#if name}} - - - - -{{/if}} -{{#if in}} - - - - -{{/if}} -
type{{type}}
description{{description}}
name{{name}}
in{{in}}
-{{/ifeq}} -{{#ifeq type "basic"}} - - - - - -{{#if description}} - - - - -{{/if}} -
type{{type}}
description{{description}}
-{{/ifeq}} -{{/this}} -{{/each}} \ No newline at end of file diff --git a/http-service-openosrs/src/main/templates/template.html.hbs b/http-service-openosrs/src/main/templates/template.html.hbs deleted file mode 100644 index da587c2cc4..0000000000 --- a/http-service-openosrs/src/main/templates/template.html.hbs +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - {{info.title}} {{info.version}} - - - - - \ No newline at end of file diff --git a/http-service-openosrs/src/main/webapp/WEB-INF/web.xml b/http-service-openosrs/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 0b07dbb973..0000000000 --- a/http-service-openosrs/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - RuneLite API - \ No newline at end of file diff --git a/http-service-openosrs/src/test/resources/application-test.yaml b/http-service-openosrs/src/test/resources/application-test.yaml deleted file mode 100644 index 0532963ade..0000000000 --- a/http-service-openosrs/src/test/resources/application-test.yaml +++ /dev/null @@ -1,17 +0,0 @@ -# Use in-memory database for tests -datasource: - runelite: - jndiName: - driverClassName: org.h2.Driver - type: org.h2.jdbcx.JdbcDataSource - url: jdbc:h2:mem:runelite - runelite-cache: - jndiName: - driverClassName: org.h2.Driver - type: org.h2.jdbcx.JdbcDataSource - url: jdbc:h2:mem:cache - runelite-tracker: - jndiName: - driverClassName: org.h2.Driver - type: org.h2.jdbcx.JdbcDataSource - url: jdbc:h2:mem:xptracker diff --git a/http-service-openosrs/src/test/resources/net/runelite/http/service/worlds/worldlist b/http-service-openosrs/src/test/resources/net/runelite/http/service/worlds/worldlist deleted file mode 100644 index 1d1360e5795d066b068e095cf2a033a504405ad6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5000 zcmeHKOK%%h6uu{Nt&HNnr;&XfUL@?A&0Xv2`>KbrNjykW>2xs2%({goUE2ojRl+UsP2YF3kRF>f)3pl!mq&wAvxSj*vi<` zL+jfJeGeWY1bdoC8M!GddJqr^AHcJOR^c?>rfy383=~o`EgbG-%g){BFW?y(jytE( z4^`J~%Z8WuXg~ztgnJ0Z;z}$8;g*g%lgkR9g4r$CbK^cTzJkXHugooe2$gZDT;KJ# z5d9785>A!3$~+oBz{>`Iajg@H&p1F21Jocycp5{fJHd`3fGmV+CeBADvbNG8Q=gAg+81nq!QO^DM%tc zH84YRq~rOT1m2nR1XRk~LWtMl z2?8qTYY^fMxR-z|?j4iUn{bAJO8M>y@ir_|5ZBq9v=3&$j#M`;+($4^Kz81CLVOIX z1XRx3&dih&0dYfNN^lGwCz$dW(8M2bzu9)u-NWLb!G;%fdpdSwciSv#@4%DfT!$yP zy1S%QDC@Z54Bq;|-nLCR)x1LhZ{@=TRN|n~^~Azc4`7oJ9Bu?UG(mg|W^`uNI=ou5 zV}1u~1XSjxXa=61?0Kqh-a8QA!y^>W{gDj_Pwfn+1K_|vg{*8_w7Fr@Z4pEK3@ao= zi5q7TSJ7xN?r_2eTlg3smkZiQ>aTDSse5UI%lt;=mP-)7LxqI1c!!s9`_+D14&VOS z7COW1M - * 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. - */ - -plugins { - war -} - -description = "Web Service" - -dependencies { - annotationProcessor(Libraries.mapstructProcessor) - annotationProcessor(Libraries.lombok) - - api(project(":cache")) - api(project(":http-api")) - api(project(":runelite-api")) - - implementation(Libraries.scribejava) - implementation(Libraries.gson) - implementation(Libraries.guava) - implementation(Libraries.minio) - implementation(Libraries.mapstruct) - implementation(Libraries.mongodbDriverSync) - implementation(Libraries.slf4jApi) - implementation(Libraries.springbootJdbc) - implementation(Libraries.springbootDevtools) - implementation(Libraries.springbootStarterWeb) - implementation(Libraries.sql2o) - implementation(Libraries.jedis) { - exclude(module = "commons-pool2") - } - - providedCompile(Libraries.mariadbJdbc) - providedCompile(Libraries.lombok) - providedCompile(Libraries.springbootStarterTomcat) - - testImplementation(Libraries.h2) - testImplementation(Libraries.okhttp3Webserver) - testImplementation(Libraries.springbootStarterTest) { - exclude(module = "commons-logging") - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java b/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java deleted file mode 100644 index 3c4042e981..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/SpringBootWebApplication.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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; - -import ch.qos.logback.classic.LoggerContext; -import com.google.common.base.Strings; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoClients; -import java.io.IOException; -import java.time.Instant; -import java.util.HashMap; -import java.util.Map; -import javax.naming.NamingException; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.sql.DataSource; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.service.util.InstantConverter; -import okhttp3.Cache; -import okhttp3.OkHttpClient; -import org.slf4j.ILoggerFactory; -import org.slf4j.impl.StaticLoggerBinder; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; -import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup; -import org.springframework.jndi.JndiTemplate; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.sql2o.Sql2o; -import org.sql2o.converters.Converter; -import org.sql2o.quirks.NoQuirks; - -@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) -@EnableScheduling -@Slf4j -public class SpringBootWebApplication extends SpringBootServletInitializer -{ - @Bean - protected ServletContextListener listener() - { - return new ServletContextListener() - { - @Override - public void contextInitialized(ServletContextEvent sce) - { - log.info("RuneLite API started"); - } - - @Override - public void contextDestroyed(ServletContextEvent sce) - { - // Destroy okhttp client - OkHttpClient client = RuneLiteAPI.CLIENT; - client.dispatcher().executorService().shutdown(); - client.connectionPool().evictAll(); - try - { - Cache cache = client.cache(); - if (cache != null) - { - cache.close(); - } - } - catch (IOException ex) - { - log.warn(null, ex); - } - - log.info("RuneLite API stopped"); - } - - }; - } - - @ConfigurationProperties(prefix = "datasource.runelite") - @Bean("dataSourceRuneLite") - public DataSourceProperties dataSourceProperties() - { - return new DataSourceProperties(); - } - - @ConfigurationProperties(prefix = "datasource.runelite-cache") - @Bean("dataSourceRuneLiteCache") - public DataSourceProperties dataSourcePropertiesCache() - { - return new DataSourceProperties(); - } - - @ConfigurationProperties(prefix = "datasource.runelite-tracker") - @Bean("dataSourceRuneLiteTracker") - public DataSourceProperties dataSourcePropertiesTracker() - { - return new DataSourceProperties(); - } - - @Bean(value = "runelite", destroyMethod = "") - public DataSource runeliteDataSource(@Qualifier("dataSourceRuneLite") DataSourceProperties dataSourceProperties) - { - return getDataSource(dataSourceProperties); - } - - @Bean(value = "runelite-cache", destroyMethod = "") - public DataSource runeliteCache2DataSource(@Qualifier("dataSourceRuneLiteCache") DataSourceProperties dataSourceProperties) - { - return getDataSource(dataSourceProperties); - } - - @Bean(value = "runelite-tracker", destroyMethod = "") - public DataSource runeliteTrackerDataSource(@Qualifier("dataSourceRuneLiteTracker") DataSourceProperties dataSourceProperties) - { - return getDataSource(dataSourceProperties); - } - - @Bean("Runelite SQL2O") - public Sql2o sql2o(@Qualifier("runelite") DataSource dataSource) - { - return createSql2oFromDataSource(dataSource); - } - - @Bean("Runelite Cache SQL2O") - public Sql2o cacheSql2o(@Qualifier("runelite-cache") DataSource dataSource) - { - return createSql2oFromDataSource(dataSource); - } - - @Bean("Runelite XP Tracker SQL2O") - public Sql2o trackerSql2o(@Qualifier("runelite-tracker") DataSource dataSource) - { - return createSql2oFromDataSource(dataSource); - } - - @Bean(destroyMethod = "") - public MongoClient mongoClient(@Value("${mongo.host:}") String host, @Value("${mongo.jndiName:}") String jndiName) throws NamingException - { - if (!Strings.isNullOrEmpty(jndiName)) - { - JndiTemplate jndiTemplate = new JndiTemplate(); - return jndiTemplate.lookup(jndiName, MongoClient.class); - } - else if (!Strings.isNullOrEmpty(host)) - { - return MongoClients.create(host); - } - else - { - throw new RuntimeException("Either mongo.host or mongo.jndiName must be set"); - } - } - - private static DataSource getDataSource(DataSourceProperties dataSourceProperties) - { - if (!Strings.isNullOrEmpty(dataSourceProperties.getJndiName())) - { - // Use JNDI provided datasource, which is already configured with pooling - JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); - return dataSourceLookup.getDataSource(dataSourceProperties.getJndiName()); - } - else - { - return dataSourceProperties.initializeDataSourceBuilder().build(); - } - } - - private static Sql2o createSql2oFromDataSource(final DataSource dataSource) - { - final Map converters = new HashMap<>(); - converters.put(Instant.class, new InstantConverter()); - return new Sql2o(dataSource, new NoQuirks(converters)); - } - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) - { - return application.sources(SpringBootWebApplication.class); - } - - @Override - public void onStartup(ServletContext servletContext) throws ServletException - { - super.onStartup(servletContext); - ILoggerFactory loggerFactory = StaticLoggerBinder.getSingleton().getLoggerFactory(); - if (loggerFactory instanceof LoggerContext) - { - LoggerContext loggerContext = (LoggerContext) loggerFactory; - loggerContext.setPackagingDataEnabled(false); - log.debug("Disabling logback packaging data"); - } - } - - public static void main(String[] args) - { - SpringApplication.run(SpringBootWebApplication.class, args); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java b/http-service/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java deleted file mode 100644 index 704e4f9cb2..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/SpringWebMvcConfigurer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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; - -import java.util.List; -import net.runelite.http.api.RuneLiteAPI; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.MediaType; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -@Configuration -@EnableWebMvc -public class SpringWebMvcConfigurer extends WebMvcConfigurerAdapter -{ - /** - * Configure .js as application/json to trick Cloudflare into caching json responses - */ - @Override - public void configureContentNegotiation(ContentNegotiationConfigurer configurer) - { - configurer.mediaType("js", MediaType.APPLICATION_JSON); - } - - /** - * Use GSON instead of Jackson for JSON serialization - * @param converters - */ - @Override - public void extendMessageConverters(List> converters) - { - // Could not figure out a better way to force GSON - converters.removeIf(MappingJackson2HttpMessageConverter.class::isInstance); - - GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter(); - gsonHttpMessageConverter.setGson(RuneLiteAPI.GSON); - converters.add(gsonHttpMessageConverter); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/account/AccountService.java b/http-service/src/main/java/net/runelite/http/service/account/AccountService.java deleted file mode 100644 index 19add15121..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/account/AccountService.java +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.account; - -import com.github.scribejava.apis.GoogleApi20; -import com.github.scribejava.core.builder.ServiceBuilder; -import com.github.scribejava.core.model.OAuth2AccessToken; -import com.github.scribejava.core.model.OAuthRequest; -import com.github.scribejava.core.model.Response; -import com.github.scribejava.core.model.Verb; -import com.github.scribejava.core.oauth.OAuth20Service; -import com.google.gson.Gson; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.account.OAuthResponse; -import net.runelite.http.api.ws.WebsocketGsonFactory; -import net.runelite.http.api.ws.WebsocketMessage; -import net.runelite.http.api.ws.messages.LoginResponse; -import net.runelite.http.service.account.beans.SessionEntry; -import net.runelite.http.service.account.beans.UserEntry; -import net.runelite.http.service.util.redis.RedisPool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.sql2o.Connection; -import org.sql2o.Sql2o; -import org.sql2o.Sql2oException; -import redis.clients.jedis.Jedis; - -@RestController -@RequestMapping("/account") -public class AccountService -{ - private static final Logger logger = LoggerFactory.getLogger(AccountService.class); - - private static final String CREATE_SESSIONS = "CREATE TABLE IF NOT EXISTS `sessions` (\n" - + " `user` int(11) NOT NULL PRIMARY KEY,\n" - + " `uuid` varchar(36) NOT NULL,\n" - + " `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" - + " `last_used` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" - + " UNIQUE KEY `uuid` (`uuid`),\n" - + " KEY `user` (`user`)\n" - + ") ENGINE=InnoDB"; - - private static final String CREATE_USERS = "CREATE TABLE IF NOT EXISTS `users` (\n" - + " `id` int(11) NOT NULL AUTO_INCREMENT,\n" - + " `username` tinytext NOT NULL,\n" - + " `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" - + " PRIMARY KEY (`id`),\n" - + " UNIQUE KEY `username` (`username`(64))\n" - + ") ENGINE=InnoDB"; - - private static final String SESSIONS_FK = "ALTER TABLE `sessions`\n" - + " ADD CONSTRAINT `id` FOREIGN KEY (`user`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;"; - - private static final String SCOPE = "https://www.googleapis.com/auth/userinfo.email"; - private static final String USERINFO = "https://www.googleapis.com/oauth2/v2/userinfo"; - private static final String RL_REDIR = "https://runelite.net/logged-in"; - - private final Gson gson = RuneLiteAPI.GSON; - private final Gson websocketGson = WebsocketGsonFactory.build(); - - private final Sql2o sql2o; - private final String oauthClientId; - private final String oauthClientSecret; - private final String oauthCallback; - private final AuthFilter auth; - private final RedisPool jedisPool; - - @Autowired - public AccountService( - @Qualifier("Runelite SQL2O") Sql2o sql2o, - @Value("${oauth.client-id}") String oauthClientId, - @Value("${oauth.client-secret}") String oauthClientSecret, - @Value("${oauth.callback}") String oauthCallback, - AuthFilter auth, - RedisPool jedisPool - ) - { - this.sql2o = sql2o; - this.oauthClientId = oauthClientId; - this.oauthClientSecret = oauthClientSecret; - this.oauthCallback = oauthCallback; - this.auth = auth; - this.jedisPool = jedisPool; - - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_SESSIONS) - .executeUpdate(); - - con.createQuery(CREATE_USERS) - .executeUpdate(); - - try - { - con.createQuery(SESSIONS_FK) - .executeUpdate(); - } - catch (Sql2oException ex) - { - // Ignore, happens when index already exists - } - } - } - - @GetMapping("/login") - public OAuthResponse login(@RequestParam UUID uuid) - { - State state = new State(); - state.setUuid(uuid); - state.setApiVersion(RuneLiteAPI.getVersion()); - - OAuth20Service service = new ServiceBuilder(oauthClientId) - .apiSecret(oauthClientSecret) - .defaultScope(SCOPE) - .callback(oauthCallback) - .build(GoogleApi20.instance()); - - final Map additionalParams = new HashMap<>(); - additionalParams.put("prompt", "select_account"); - - final String authorizationUrl = service.createAuthorizationUrlBuilder() - .state(gson.toJson(state)) - .additionalParams(additionalParams) - .build(); - - OAuthResponse lr = new OAuthResponse(); - lr.setOauthUrl(authorizationUrl); - lr.setUid(uuid); - - return lr; - } - - @GetMapping("/callback") - public Object callback( - HttpServletRequest request, - HttpServletResponse response, - @RequestParam(required = false) String error, - @RequestParam String code, - @RequestParam("state") String stateStr - ) throws InterruptedException, ExecutionException, IOException - { - if (error != null) - { - logger.info("Error in oauth callback: {}", error); - return null; - } - - State state = gson.fromJson(stateStr, State.class); - - logger.info("Got authorization code {} for uuid {}", code, state.getUuid()); - - OAuth20Service service = new ServiceBuilder(oauthClientId) - .apiSecret(oauthClientSecret) - .defaultScope(SCOPE) - .callback(oauthCallback) - .build(GoogleApi20.instance()); - - OAuth2AccessToken accessToken = service.getAccessToken(code); - - // Access user info - OAuthRequest orequest = new OAuthRequest(Verb.GET, USERINFO); - service.signRequest(accessToken, orequest); - - Response oresponse = service.execute(orequest); - - if (oresponse.getCode() / 100 != 2) - { - // Could be a forged result - return null; - } - - UserInfo userInfo = gson.fromJson(oresponse.getBody(), UserInfo.class); - - logger.info("Got user info: {}", userInfo); - - try (Connection con = sql2o.open()) - { - con.createQuery("insert ignore into users (username) values (:username)") - .addParameter("username", userInfo.getEmail()) - .executeUpdate(); - - UserEntry user = con.createQuery("select id from users where username = :username") - .addParameter("username", userInfo.getEmail()) - .executeAndFetchFirst(UserEntry.class); - - if (user == null) - { - logger.warn("Unable to find newly created user session"); - return null; // that's weird - } - - // insert session - con.createQuery("insert ignore into sessions (user, uuid) values (:user, :uuid)") - .addParameter("user", user.getId()) - .addParameter("uuid", state.getUuid().toString()) - .executeUpdate(); - - logger.info("Created session for user {}", userInfo.getEmail()); - } - - response.sendRedirect(RL_REDIR); - - notifySession(state.getUuid(), userInfo.getEmail()); - - return ""; - } - - private void notifySession(UUID uuid, String username) - { - LoginResponse response = new LoginResponse(); - response.setUsername(username); - - try (Jedis jedis = jedisPool.getResource()) - { - jedis.publish("session." + uuid, websocketGson.toJson(response, WebsocketMessage.class)); - } - } - - @GetMapping("/logout") - public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException - { - SessionEntry session = auth.handle(request, response); - - if (session == null) - { - return; - } - - auth.invalidate(session.getUuid()); - - try (Connection con = sql2o.open()) - { - con.createQuery("delete from sessions where uuid = :uuid") - .addParameter("uuid", session.getUuid().toString()) - .executeUpdate(); - } - } - - @GetMapping("/session-check") - public void sessionCheck(HttpServletRequest request, HttpServletResponse response) throws IOException - { - auth.handle(request, response); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/account/AuthFilter.java b/http-service/src/main/java/net/runelite/http/service/account/AuthFilter.java deleted file mode 100644 index d283e71c5c..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/account/AuthFilter.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.account; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalNotification; -import java.io.IOException; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.service.account.beans.SessionEntry; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.Sql2o; - -@Service -public class AuthFilter -{ - private final Sql2o sql2o; - - private final Cache sessionCache = CacheBuilder.newBuilder() - .maximumSize(10000L) - .expireAfterAccess(30, TimeUnit.MINUTES) - .removalListener(this::removalListener) - .build(); - - @Autowired - public AuthFilter(@Qualifier("Runelite SQL2O") Sql2o sql2o) - { - this.sql2o = sql2o; - } - - public SessionEntry handle(HttpServletRequest request, HttpServletResponse response) throws IOException - { - String runeliteAuth = request.getHeader(RuneLiteAPI.RUNELITE_AUTH); - if (runeliteAuth == null) - { - response.sendError(401, "Access denied"); - return null; - } - - UUID uuid = UUID.fromString(runeliteAuth); - SessionEntry sessionEntry = sessionCache.getIfPresent(uuid); - if (sessionEntry != null) - { - return sessionEntry; - } - - try (Connection con = sql2o.open()) - { - sessionEntry = con.createQuery("select user, uuid, created, last_used as lastUsed from sessions where uuid = :uuid") - .addParameter("uuid", uuid.toString()) - .executeAndFetchFirst(SessionEntry.class); - } - - if (sessionEntry == null) - { - response.sendError(401, "Access denied"); - return null; - } - - sessionCache.put(uuid, sessionEntry); - - return sessionEntry; - } - - private void removalListener(RemovalNotification notification) - { - UUID uuid = notification.getKey(); - Instant now = Instant.now(); - - try (Connection con = sql2o.open()) - { - con.createQuery("update sessions set last_used = :last_used where uuid = :uuid") - .addParameter("last_used", Timestamp.from(now)) - .addParameter("uuid", uuid.toString()) - .executeUpdate(); - } - } - - public void invalidate(UUID uuid) - { - // If we ever run multiple services, may need to publish something here to invalidate... - sessionCache.invalidate(uuid); - } - -} diff --git a/http-service/src/main/java/net/runelite/http/service/account/State.java b/http-service/src/main/java/net/runelite/http/service/account/State.java deleted file mode 100644 index 50b47b2c19..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/account/State.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.account; - -import java.util.UUID; - -public class State -{ - private UUID uuid; - private String apiVersion; - - public UUID getUuid() - { - return uuid; - } - - public void setUuid(UUID uuid) - { - this.uuid = uuid; - } - - public String getApiVersion() - { - return apiVersion; - } - - public void setApiVersion(String apiVersion) - { - this.apiVersion = apiVersion; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/account/UserInfo.java b/http-service/src/main/java/net/runelite/http/service/account/UserInfo.java deleted file mode 100644 index a1cde03f79..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/account/UserInfo.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.account; - -public class UserInfo -{ - private String email; - - @Override - public String toString() - { - return "UserInfo{" + "email=" + email + '}'; - } - - public String getEmail() - { - return email; - } - - public void setEmail(String email) - { - this.email = email; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/account/beans/SessionEntry.java b/http-service/src/main/java/net/runelite/http/service/account/beans/SessionEntry.java deleted file mode 100644 index ded67c7a45..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/account/beans/SessionEntry.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.account.beans; - -import java.time.Instant; -import java.util.UUID; - -public class SessionEntry -{ - private int user; - private UUID uuid; - private Instant created; - private Instant lastUsed; - - public int getUser() - { - return user; - } - - public void setUser(int user) - { - this.user = user; - } - - public UUID getUuid() - { - return uuid; - } - - public void setUuid(UUID uuid) - { - this.uuid = uuid; - } - - public Instant getCreated() - { - return created; - } - - public void setCreated(Instant created) - { - this.created = created; - } - - public Instant getLastUsed() - { - return lastUsed; - } - - public void setLastUsed(Instant lastUsed) - { - this.lastUsed = lastUsed; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/account/beans/UserEntry.java b/http-service/src/main/java/net/runelite/http/service/account/beans/UserEntry.java deleted file mode 100644 index 83dd4152ac..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/account/beans/UserEntry.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.account.beans; - -public class UserEntry -{ - private int id; - private String username; - - @Override - public String toString() - { - return "UserEntry{" + "id=" + id + ", username=" + username + '}'; - } - - public int getId() - { - return id; - } - - public void setId(int id) - { - this.id = id; - } - - public String getUsername() - { - return username; - } - - public void setUsername(String username) - { - this.username = username; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheController.java b/http-service/src/main/java/net/runelite/http/service/cache/CacheController.java deleted file mode 100644 index f86f453412..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/CacheController.java +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; -import javax.imageio.ImageIO; -import lombok.extern.slf4j.Slf4j; -import net.runelite.cache.ConfigType; -import net.runelite.cache.IndexType; -import net.runelite.cache.definitions.ItemDefinition; -import net.runelite.cache.definitions.ModelDefinition; -import net.runelite.cache.definitions.NpcDefinition; -import net.runelite.cache.definitions.ObjectDefinition; -import net.runelite.cache.definitions.SpriteDefinition; -import net.runelite.cache.definitions.TextureDefinition; -import net.runelite.cache.definitions.loaders.ItemLoader; -import net.runelite.cache.definitions.loaders.ModelLoader; -import net.runelite.cache.definitions.loaders.NpcLoader; -import net.runelite.cache.definitions.loaders.ObjectLoader; -import net.runelite.cache.definitions.loaders.SpriteLoader; -import net.runelite.cache.definitions.loaders.TextureLoader; -import net.runelite.cache.definitions.providers.ItemProvider; -import net.runelite.cache.definitions.providers.ModelProvider; -import net.runelite.cache.definitions.providers.SpriteProvider; -import net.runelite.cache.definitions.providers.TextureProvider; -import net.runelite.cache.fs.ArchiveFiles; -import net.runelite.cache.fs.Container; -import net.runelite.cache.fs.FSFile; -import net.runelite.cache.item.ItemSpriteFactory; -import net.runelite.http.api.cache.Cache; -import net.runelite.http.api.cache.CacheArchive; -import net.runelite.http.api.cache.CacheIndex; -import net.runelite.http.service.cache.beans.ArchiveEntry; -import net.runelite.http.service.cache.beans.CacheEntry; -import net.runelite.http.service.cache.beans.IndexEntry; -import net.runelite.http.service.util.exception.NotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/cache") -@Slf4j -public class CacheController -{ - @Autowired - private CacheService cacheService; - - @GetMapping("/") - public List listCaches() - { - return cacheService.listCaches().stream() - .map(entry -> new Cache(entry.getId(), entry.getRevision(), entry.getDate())) - .collect(Collectors.toList()); - } - - @GetMapping("{cacheId}") - public List listIndexes(@PathVariable int cacheId) - { - CacheEntry cache = cacheService.findCache(cacheId); - if (cache == null) - { - throw new NotFoundException(); - } - - List indexes = cacheService.findIndexesForCache(cache); - - return indexes.stream() - .map(entry -> new CacheIndex(entry.getIndexId(), entry.getRevision())) - .collect(Collectors.toList()); - } - - @GetMapping("{cacheId}/{indexId}") - public List listArchives(@PathVariable int cacheId, - @PathVariable int indexId) - { - CacheEntry cache = cacheService.findCache(cacheId); - if (cache == null) - { - throw new NotFoundException(); - } - - IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId); - if (indexEntry == null) - { - throw new NotFoundException(); - } - - List archives = cacheService.findArchivesForIndex(indexEntry); - - return archives.stream() - .map(archive -> new CacheArchive(archive.getArchiveId(), archive.getNameHash(), archive.getRevision())) - .collect(Collectors.toList()); - } - - @GetMapping("{cacheId}/{indexId}/{archiveId}") - public CacheArchive getCacheArchive(@PathVariable int cacheId, - @PathVariable int indexId, - @PathVariable int archiveId) - { - CacheEntry cache = cacheService.findCache(cacheId); - if (cache == null) - { - throw new NotFoundException(); - } - - IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId); - if (indexEntry == null) - { - throw new NotFoundException(); - } - - ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, archiveId); - if (archiveEntry == null) - { - throw new NotFoundException(); - } - - return new CacheArchive(archiveEntry.getArchiveId(), - archiveEntry.getNameHash(), archiveEntry.getRevision()); - } - - @GetMapping("{cacheId}/{indexId}/{archiveId}/data") - public byte[] getArchiveData( - @PathVariable int cacheId, - @PathVariable int indexId, - @PathVariable int archiveId - ) - { - CacheEntry cache = cacheService.findCache(cacheId); - if (cache == null) - { - throw new NotFoundException(); - } - - IndexEntry indexEntry = cacheService.findIndexForCache(cache, indexId); - if (indexEntry == null) - { - throw new NotFoundException(); - } - - ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, archiveId); - if (archiveEntry == null) - { - throw new NotFoundException(); - } - - return cacheService.getArchive(archiveEntry); - } - - private ArchiveEntry findConfig(ConfigType config) - { - CacheEntry cache = cacheService.findMostRecent(); - if (cache == null) - { - throw new NotFoundException(); - } - - IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.CONFIGS.getNumber()); - if (indexEntry == null) - { - throw new NotFoundException(); - } - - ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, config.getId()); - if (archiveEntry == null) - { - throw new NotFoundException(); - } - - return archiveEntry; - } - - @GetMapping("item/{itemId}") - public ItemDefinition getItem(@PathVariable int itemId) throws IOException - { - ArchiveEntry archiveEntry = findConfig(ConfigType.ITEM); - - ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry); - if (archiveFiles == null) - { - throw new NotFoundException(); - } - - FSFile file = archiveFiles.findFile(itemId); - if (file == null) - { - throw new NotFoundException(); - } - - ItemDefinition itemdef = new ItemLoader().load(itemId, file.getContents()); - return itemdef; - } - - @GetMapping(path = "item/{itemId}/image", produces = "image/png") - public ResponseEntity getItemImage( - @PathVariable int itemId, - @RequestParam(defaultValue = "1") int quantity, - @RequestParam(defaultValue = "1") int border, - @RequestParam(defaultValue = "3153952") int shadowColor - ) throws IOException - { - final CacheEntry cache = cacheService.findMostRecent(); - ItemProvider itemProvider = new ItemProvider() - { - @Override - public ItemDefinition provide(int itemId) - { - try - { - return getItem(itemId); - } - catch (IOException ex) - { - log.warn(null, ex); - return null; - } - } - }; - ModelProvider modelProvider = new ModelProvider() - { - @Override - public ModelDefinition provide(int modelId) throws IOException - { - IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.MODELS.getNumber()); - ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, modelId); - byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data; - return new ModelLoader().load(modelId, archiveData); - } - }; - SpriteProvider spriteProvider = new SpriteProvider() - { - @Override - public SpriteDefinition provide(int spriteId, int frameId) - { - try - { - IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.SPRITES.getNumber()); - ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, spriteId); - byte[] archiveData = Container.decompress(cacheService.getArchive(archiveEntry), null).data; - SpriteDefinition[] defs = new SpriteLoader().load(spriteId, archiveData); - return defs[frameId]; - } - catch (Exception ex) - { - log.warn(null, ex); - return null; - } - } - }; - - TextureProvider textureProvider2 = new TextureProvider() - { - @Override - public TextureDefinition[] provide() - { - try - { - IndexEntry indexEntry = cacheService.findIndexForCache(cache, IndexType.TEXTURES.getNumber()); - ArchiveEntry archiveEntry = cacheService.findArchiveForIndex(indexEntry, 0); - ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry); - TextureLoader loader = new TextureLoader(); - TextureDefinition[] defs = new TextureDefinition[archiveFiles.getFiles().size()]; - int i = 0; - for (FSFile file : archiveFiles.getFiles()) - { - TextureDefinition def = loader.load(file.getFileId(), file.getContents()); - defs[i++] = def; - } - return defs; - } - catch (Exception ex) - { - log.warn(null, ex); - return null; - } - } - }; - - BufferedImage itemImage = ItemSpriteFactory.createSprite(itemProvider, modelProvider, spriteProvider, textureProvider2, - itemId, quantity, border, shadowColor, false); - ByteArrayOutputStream bao = new ByteArrayOutputStream(); - ImageIO.write(itemImage, "png", bao); - return ResponseEntity.ok(bao.toByteArray()); - } - - @GetMapping("object/{objectId}") - public ObjectDefinition getObject( - @PathVariable int objectId - ) throws IOException - { - ArchiveEntry archiveEntry = findConfig(ConfigType.OBJECT); - - ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry); - if (archiveFiles == null) - { - throw new NotFoundException(); - } - - FSFile file = archiveFiles.findFile(objectId); - if (file == null) - { - throw new NotFoundException(); - } - - ObjectDefinition objectdef = new ObjectLoader().load(objectId, file.getContents()); - return objectdef; - } - - @GetMapping("npc/{npcId}") - public NpcDefinition getNpc( - @PathVariable int npcId - ) throws IOException - { - ArchiveEntry archiveEntry = findConfig(ConfigType.NPC); - - ArchiveFiles archiveFiles = cacheService.getArchiveFiles(archiveEntry); - if (archiveFiles == null) - { - throw new NotFoundException(); - } - - FSFile file = archiveFiles.findFile(npcId); - if (file == null) - { - throw new NotFoundException(); - } - - NpcDefinition npcdef = new NpcLoader().load(npcId, file.getContents()); - return npcdef; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java b/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java deleted file mode 100644 index 08282ca38e..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/CacheDAO.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache; - -import java.util.List; -import net.runelite.cache.IndexType; -import net.runelite.http.service.cache.beans.ArchiveEntry; -import net.runelite.http.service.cache.beans.CacheEntry; -import net.runelite.http.service.cache.beans.FileEntry; -import net.runelite.http.service.cache.beans.IndexEntry; -import org.sql2o.Connection; -import org.sql2o.Query; -import org.sql2o.ResultSetIterable; - -class CacheDAO -{ - public List listCaches(Connection con) - { - return con.createQuery("select id, revision, date from cache") - .executeAndFetch(CacheEntry.class); - } - - public CacheEntry findMostRecent(Connection con) - { - return con.createQuery("select id, revision, date from cache order by revision desc, date desc limit 1") - .executeAndFetchFirst(CacheEntry.class); - } - - public List findIndexesForCache(Connection con, CacheEntry cache) - { - return con.createQuery("select id, indexId, crc, revision from `index` where cache = :cache") - .addParameter("cache", cache.getId()) - .executeAndFetch(IndexEntry.class); - } - - public IndexEntry findIndexForCache(Connection con, CacheEntry cache, int indexId) - { - return con.createQuery("select id, indexId, crc, revision from `index` " - + "where cache = :id " - + "and indexId = :indexId") - .addParameter("id", cache.getId()) - .addParameter("indexId", indexId) - .executeAndFetchFirst(IndexEntry.class); - } - - public ResultSetIterable findArchivesForIndex(Connection con, IndexEntry indexEntry) - { - return con.createQuery("select archive.id, archive.archiveId, archive.nameHash," - + " archive.crc, archive.revision, archive.hash from index_archive " - + "join archive on index_archive.archive = archive.id " - + "where index_archive.index = :id") - .addParameter("id", indexEntry.getId()) - .executeAndFetchLazy(ArchiveEntry.class); - } - - public ArchiveEntry findArchiveForIndex(Connection con, IndexEntry indexEntry, int archiveId) - { - return con.createQuery("select archive.id, archive.archiveId, archive.nameHash," - + " archive.crc, archive.revision, archive.hash from index_archive " - + "join archive on index_archive.archive = archive.id " - + "where index_archive.index = :id " - + "and archive.archiveId = :archiveId") - .addParameter("id", indexEntry.getId()) - .addParameter("archiveId", archiveId) - .executeAndFetchFirst(ArchiveEntry.class); - } - - public ArchiveEntry findArchiveByName(Connection con, CacheEntry cache, IndexType index, int nameHash) - { - return con.createQuery("select archive.id, archive.archiveId, archive.nameHash," - + " archive.crc, archive.revision, archive.hash from archive " - + "join index_archive on index_archive.archive = archive.id " - + "join `index` on index.id = index_archive.index " - + "where index.cache = :cacheId " - + "and index.indexId = :indexId " - + "and archive.nameHash = :nameHash " - + "limit 1") - .addParameter("cacheId", cache.getId()) - .addParameter("indexId", index.getNumber()) - .addParameter("nameHash", nameHash) - .executeAndFetchFirst(ArchiveEntry.class); - } - - public ResultSetIterable findFilesForArchive(Connection con, ArchiveEntry archiveEntry) - { - Query findFilesForArchive = con.createQuery("select id, fileId, nameHash from file " - + "where archive = :archive"); - - return findFilesForArchive - .addParameter("archive", archiveEntry.getId()) - .executeAndFetchLazy(FileEntry.class); - } - - public CacheEntry findCache(Connection con, int cacheId) - { - return con.createQuery("select id, revision, date from cache " - + "where id = :cacheId") - .addParameter("cacheId", cacheId) - .executeAndFetchFirst(CacheEntry.class); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/CacheService.java b/http-service/src/main/java/net/runelite/http/service/cache/CacheService.java deleted file mode 100644 index f058510765..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/CacheService.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2017-2018, Adam - * 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.cache; - -import com.google.common.collect.Iterables; -import com.google.common.io.BaseEncoding; -import com.google.common.io.ByteStreams; -import io.minio.MinioClient; -import io.minio.errors.ErrorResponseException; -import io.minio.errors.InsufficientDataException; -import io.minio.errors.InternalException; -import io.minio.errors.InvalidArgumentException; -import io.minio.errors.InvalidBucketNameException; -import io.minio.errors.InvalidEndpointException; -import io.minio.errors.InvalidPortException; -import io.minio.errors.InvalidResponseException; -import io.minio.errors.NoResponseException; -import java.io.IOException; -import java.io.InputStream; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import lombok.extern.slf4j.Slf4j; -import net.runelite.cache.ConfigType; -import net.runelite.cache.IndexType; -import net.runelite.cache.definitions.ItemDefinition; -import net.runelite.cache.definitions.loaders.ItemLoader; -import net.runelite.cache.fs.ArchiveFiles; -import net.runelite.cache.fs.Container; -import net.runelite.cache.fs.FSFile; -import net.runelite.http.service.cache.beans.ArchiveEntry; -import net.runelite.http.service.cache.beans.CacheEntry; -import net.runelite.http.service.cache.beans.FileEntry; -import net.runelite.http.service.cache.beans.IndexEntry; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.ResultSetIterable; -import org.sql2o.Sql2o; -import org.xmlpull.v1.XmlPullParserException; - -@Service -@Slf4j -public class CacheService -{ - @Autowired - @Qualifier("Runelite Cache SQL2O") - private Sql2o sql2o; - - @Value("${minio.bucket}") - private String minioBucket; - - private final MinioClient minioClient; - - @Autowired - public CacheService( - @Value("${minio.endpoint}") String minioEndpoint, - @Value("${minio.accesskey}") String accessKey, - @Value("${minio.secretkey}") String secretKey - ) throws InvalidEndpointException, InvalidPortException - { - this.minioClient = new MinioClient(minioEndpoint, accessKey, secretKey); - } - - @Bean - public MinioClient minioClient() - { - return minioClient; - } - - /** - * retrieve archive from storage - * - * @param archiveEntry - * @return - */ - public byte[] getArchive(ArchiveEntry archiveEntry) - { - String hashStr = BaseEncoding.base16().encode(archiveEntry.getHash()); - String path = new StringBuilder() - .append(hashStr, 0, 2) - .append('/') - .append(hashStr.substring(2)) - .toString(); - - try (InputStream in = minioClient.getObject(minioBucket, path)) - { - return ByteStreams.toByteArray(in); - } - catch (InvalidBucketNameException | NoSuchAlgorithmException | InsufficientDataException | IOException | InvalidKeyException | NoResponseException | XmlPullParserException | ErrorResponseException | InternalException | InvalidArgumentException | InvalidResponseException ex) - { - log.warn(null, ex); - return null; - } - } - - public ArchiveFiles getArchiveFiles(ArchiveEntry archiveEntry) throws IOException - { - CacheDAO cacheDao = new CacheDAO(); - - try (Connection con = sql2o.open(); - ResultSetIterable files = cacheDao.findFilesForArchive(con, archiveEntry)) - { - byte[] archiveData = getArchive(archiveEntry); - - if (archiveData == null) - { - return null; - } - - Container result = Container.decompress(archiveData, null); - if (result == null) - { - return null; - } - - byte[] decompressedData = result.data; - - ArchiveFiles archiveFiles = new ArchiveFiles(); - for (FileEntry fileEntry : files) - { - FSFile file = new FSFile(fileEntry.getFileId()); - archiveFiles.addFile(file); - file.setNameHash(fileEntry.getNameHash()); - } - archiveFiles.loadContents(decompressedData); - return archiveFiles; - } - } - - public List listCaches() - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.listCaches(con); - } - } - - public CacheEntry findCache(int cacheId) - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.findCache(con, cacheId); - } - } - - public CacheEntry findMostRecent() - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.findMostRecent(con); - } - } - - public List findIndexesForCache(CacheEntry cacheEntry) - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.findIndexesForCache(con, cacheEntry); - } - } - - public IndexEntry findIndexForCache(CacheEntry cahceEntry, int indexId) - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.findIndexForCache(con, cahceEntry, indexId); - } - } - - public List findArchivesForIndex(IndexEntry indexEntry) - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - ResultSetIterable archiveEntries = cacheDao.findArchivesForIndex(con, indexEntry); - List archives = new ArrayList<>(); - Iterables.addAll(archives, archiveEntries); - return archives; - } - } - - public ArchiveEntry findArchiveForIndex(IndexEntry indexEntry, int archiveId) - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.findArchiveForIndex(con, indexEntry, archiveId); - } - } - - public ArchiveEntry findArchiveForTypeAndName(CacheEntry cache, IndexType index, int nameHash) - { - try (Connection con = sql2o.open()) - { - CacheDAO cacheDao = new CacheDAO(); - return cacheDao.findArchiveByName(con, cache, index, nameHash); - } - } - - public List getItems() throws IOException - { - CacheEntry cache = findMostRecent(); - if (cache == null) - { - return Collections.emptyList(); - } - - IndexEntry indexEntry = findIndexForCache(cache, IndexType.CONFIGS.getNumber()); - ArchiveEntry archiveEntry = findArchiveForIndex(indexEntry, ConfigType.ITEM.getId()); - ArchiveFiles archiveFiles = getArchiveFiles(archiveEntry); - final ItemLoader itemLoader = new ItemLoader(); - final List result = new ArrayList<>(archiveFiles.getFiles().size()); - for (FSFile file : archiveFiles.getFiles()) - { - ItemDefinition itemDef = itemLoader.load(file.getFileId(), file.getContents()); - result.add(itemDef); - } - return result; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java deleted file mode 100644 index acda96e77f..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/beans/ArchiveEntry.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.beans; - -import lombok.Data; - -@Data -public class ArchiveEntry -{ - private int id; - private int archiveId; - private int nameHash; - private int crc; - private int revision; - private byte[] hash; -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java deleted file mode 100644 index 231ad7c655..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/beans/CacheEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.beans; - -import java.time.Instant; -import lombok.Data; - -@Data -public class CacheEntry -{ - private int id; - private int revision; - private Instant date; -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java deleted file mode 100644 index c5f35a4cc3..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/beans/FileEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.beans; - -import lombok.Data; - -@Data -public class FileEntry -{ - private int id; - private int archiveId; - private int fileId; - private int nameHash; -} diff --git a/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java b/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java deleted file mode 100644 index 8d60927c71..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/cache/beans/IndexEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.cache.beans; - -import lombok.Data; - -@Data -public class IndexEntry -{ - private int id; - private int indexId; - private int crc; - private int revision; -} diff --git a/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java deleted file mode 100644 index ccba9db430..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.chat; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import net.runelite.http.api.chat.Duels; -import net.runelite.http.api.chat.LayoutRoom; -import net.runelite.http.api.chat.Task; -import net.runelite.http.service.util.exception.NotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/chat") -public class ChatController -{ - private static final Pattern STRING_VALIDATION = Pattern.compile("[^a-zA-Z0-9' -]"); - private static final int STRING_MAX_LENGTH = 50; - private static final int MAX_LAYOUT_ROOMS = 16; - - private final Cache killCountCache = CacheBuilder.newBuilder() - .expireAfterWrite(2, TimeUnit.MINUTES) - .maximumSize(128L) - .build(); - - @Autowired - private ChatService chatService; - - @PostMapping("/kc") - public void submitKc(@RequestParam String name, @RequestParam String boss, @RequestParam int kc) - { - if (kc <= 0) - { - return; - } - - chatService.setKc(name, boss, kc); - killCountCache.put(new KillCountKey(name, boss), kc); - } - - @GetMapping("/kc") - public int getKc(@RequestParam String name, @RequestParam String boss) - { - Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss)); - if (kc == null) - { - kc = chatService.getKc(name, boss); - if (kc != null) - { - killCountCache.put(new KillCountKey(name, boss), kc); - } - } - - if (kc == null) - { - throw new NotFoundException(); - } - return kc; - } - - @PostMapping("/qp") - public void submitQp(@RequestParam String name, @RequestParam int qp) - { - if (qp < 0) - { - return; - } - - chatService.setQp(name, qp); - } - - @GetMapping("/qp") - public int getQp(@RequestParam String name) - { - Integer kc = chatService.getQp(name); - if (kc == null) - { - throw new NotFoundException(); - } - return kc; - } - - @PostMapping("/gc") - public void submitGc(@RequestParam String name, @RequestParam int gc) - { - if (gc < 0) - { - return; - } - - chatService.setGc(name, gc); - } - - @GetMapping("/gc") - public int getKc(@RequestParam String name) - { - Integer gc = chatService.getGc(name); - if (gc == null) - { - throw new NotFoundException(); - } - return gc; - } - - @PostMapping("/task") - public void submitTask(@RequestParam String name, @RequestParam("task") String taskName, @RequestParam int amount, - @RequestParam int initialAmount, @RequestParam String location) - { - Matcher mTask = STRING_VALIDATION.matcher(taskName); - Matcher mLocation = STRING_VALIDATION.matcher(location); - if (mTask.find() || taskName.length() > STRING_MAX_LENGTH || - mLocation.find() || location.length() > STRING_MAX_LENGTH) - { - return; - } - - Task task = new Task(); - task.setTask(taskName); - task.setAmount(amount); - task.setInitialAmount(initialAmount); - task.setLocation(location); - - chatService.setTask(name, task); - } - - @GetMapping("/task") - public Task getTask(@RequestParam String name) - { - return chatService.getTask(name); - } - - @PostMapping("/pb") - public void submitPb(@RequestParam String name, @RequestParam String boss, @RequestParam int pb) - { - if (pb < 0) - { - return; - } - - chatService.setPb(name, boss, pb); - } - - @GetMapping("/pb") - public int getPb(@RequestParam String name, @RequestParam String boss) - { - Integer pb = chatService.getPb(name, boss); - if (pb == null) - { - throw new NotFoundException(); - } - return pb; - } - - @PostMapping("/duels") - public void submitDuels(@RequestParam String name, @RequestParam int wins, - @RequestParam int losses, - @RequestParam int winningStreak, @RequestParam int losingStreak) - { - if (wins < 0 || losses < 0 || winningStreak < 0 || losingStreak < 0) - { - return; - } - - Duels duels = new Duels(); - duels.setWins(wins); - duels.setLosses(losses); - duels.setWinningStreak(winningStreak); - duels.setLosingStreak(losingStreak); - - chatService.setDuels(name, duels); - } - - @GetMapping("/duels") - public Duels getDuels(@RequestParam String name) - { - Duels duels = chatService.getDuels(name); - if (duels == null) - { - throw new NotFoundException(); - } - return duels; - } - - @PostMapping("/layout") - public void submitLayout(@RequestParam String name, @RequestBody LayoutRoom[] rooms) - { - if (rooms.length > MAX_LAYOUT_ROOMS) - { - return; - } - - chatService.setLayout(name, rooms); - } - - @GetMapping("/layout") - public LayoutRoom[] getLayout(@RequestParam String name) - { - LayoutRoom[] layout = chatService.getLayout(name); - - if (layout == null) - { - throw new NotFoundException(); - } - - return layout; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java deleted file mode 100644 index be497b40bd..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.chat; - -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableMap; -import java.time.Duration; -import java.util.List; -import java.util.Map; -import net.runelite.http.api.chat.LayoutRoom; -import net.runelite.http.api.chat.Task; -import net.runelite.http.api.chat.Duels; -import net.runelite.http.service.util.redis.RedisPool; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import redis.clients.jedis.Jedis; - -@Service -public class ChatService -{ - private static final Duration EXPIRE = Duration.ofMinutes(2); - - private final RedisPool jedisPool; - - @Autowired - public ChatService(RedisPool jedisPool) - { - this.jedisPool = jedisPool; - } - - public Integer getKc(String name, String boss) - { - String value; - try (Jedis jedis = jedisPool.getResource()) - { - value = jedis.get("kc." + name + "." + boss); - } - return value == null ? null : Integer.parseInt(value); - } - - public void setKc(String name, String boss, int kc) - { - try (Jedis jedis = jedisPool.getResource()) - { - jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc)); - } - } - - public Integer getQp(String name) - { - String value; - try (Jedis jedis = jedisPool.getResource()) - { - value = jedis.get("qp." + name); - } - return value == null ? null : Integer.parseInt(value); - } - - public void setQp(String name, int qp) - { - try (Jedis jedis = jedisPool.getResource()) - { - jedis.setex("qp." + name, (int) EXPIRE.getSeconds(), Integer.toString(qp)); - } - } - - public Task getTask(String name) - { - Map map; - - try (Jedis jedis = jedisPool.getResource()) - { - map = jedis.hgetAll("task." + name); - } - - if (map.isEmpty()) - { - return null; - } - - Task task = new Task(); - task.setTask(map.get("task")); - task.setAmount(Integer.parseInt(map.get("amount"))); - task.setInitialAmount(Integer.parseInt(map.get("initialAmount"))); - task.setLocation(map.get("location")); - return task; - } - - public void setTask(String name, Task task) - { - Map taskMap = ImmutableMap.builderWithExpectedSize(4) - .put("task", task.getTask()) - .put("amount", Integer.toString(task.getAmount())) - .put("initialAmount", Integer.toString(task.getInitialAmount())) - .put("location", task.getLocation()) - .build(); - - String key = "task." + name; - - try (Jedis jedis = jedisPool.getResource()) - { - jedis.hmset(key, taskMap); - jedis.expire(key, (int) EXPIRE.getSeconds()); - } - } - - public Integer getPb(String name, String boss) - { - String value; - try (Jedis jedis = jedisPool.getResource()) - { - value = jedis.get("pb." + boss + "." + name); - } - return value == null ? null : Integer.parseInt(value); - } - - public void setPb(String name, String boss, int pb) - { - try (Jedis jedis = jedisPool.getResource()) - { - jedis.setex("pb." + boss + "." + name, (int) EXPIRE.getSeconds(), Integer.toString(pb)); - } - } - - public Integer getGc(String name) - { - String value; - try (Jedis jedis = jedisPool.getResource()) - { - value = jedis.get("gc." + name); - } - return value == null ? null : Integer.parseInt(value); - } - - public void setGc(String name, int gc) - { - try (Jedis jedis = jedisPool.getResource()) - { - jedis.setex("gc." + name, (int) EXPIRE.getSeconds(), Integer.toString(gc)); - } - } - - public Duels getDuels(String name) - { - Map map; - - try (Jedis jedis = jedisPool.getResource()) - { - map = jedis.hgetAll("duels." + name); - } - - if (map.isEmpty()) - { - return null; - } - - Duels duels = new Duels(); - duels.setWins(Integer.parseInt(map.get("wins"))); - duels.setLosses(Integer.parseInt(map.get("losses"))); - duels.setWinningStreak(Integer.parseInt(map.get("winningStreak"))); - duels.setLosingStreak(Integer.parseInt(map.get("losingStreak"))); - return duels; - } - - public void setDuels(String name, Duels duels) - { - Map duelsMap = ImmutableMap.builderWithExpectedSize(4) - .put("wins", Integer.toString(duels.getWins())) - .put("losses", Integer.toString(duels.getLosses())) - .put("winningStreak", Integer.toString(duels.getWinningStreak())) - .put("losingStreak", Integer.toString(duels.getLosingStreak())) - .build(); - - String key = "duels." + name; - - try (Jedis jedis = jedisPool.getResource()) - { - jedis.hmset(key, duelsMap); - jedis.expire(key, (int) EXPIRE.getSeconds()); - } - } - - public LayoutRoom[] getLayout(String name) - { - String layout; - try (Jedis jedis = jedisPool.getResource()) - { - layout = jedis.get("layout." + name); - } - - if (layout == null) - { - return null; - } - - List roomList = Splitter.on(' ').splitToList(layout); - return roomList.stream() - .map(LayoutRoom::valueOf) - .toArray(LayoutRoom[]::new); - } - - public void setLayout(String name, LayoutRoom[] rooms) - { - try (Jedis jedis = jedisPool.getResource()) - { - jedis.setex("layout." + name, (int) EXPIRE.getSeconds(), Joiner.on(' ').join(rooms)); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java b/http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java deleted file mode 100644 index 07ca775dad..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.chat; - -import lombok.Value; - -@Value -class KillCountKey -{ - private String username; - private String boss; -} diff --git a/http-service/src/main/java/net/runelite/http/service/config/ConfigController.java b/http-service/src/main/java/net/runelite/http/service/config/ConfigController.java deleted file mode 100644 index 51d3f485f0..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/config/ConfigController.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.config; - -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.config.Configuration; -import net.runelite.http.service.account.AuthFilter; -import net.runelite.http.service.account.beans.SessionEntry; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import static org.springframework.web.bind.annotation.RequestMethod.DELETE; -import static org.springframework.web.bind.annotation.RequestMethod.PUT; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/config") -public class ConfigController -{ - private final ConfigService configService; - private final AuthFilter authFilter; - - @Autowired - public ConfigController(ConfigService configService, AuthFilter authFilter) - { - this.configService = configService; - this.authFilter = authFilter; - } - - @GetMapping - public Configuration get(HttpServletRequest request, HttpServletResponse response) throws IOException - { - SessionEntry session = authFilter.handle(request, response); - - if (session == null) - { - return null; - } - - return configService.get(session.getUser()); - } - - @RequestMapping(path = "/{key:.+}", method = PUT) - public void setKey( - HttpServletRequest request, - HttpServletResponse response, - @PathVariable String key, - @RequestBody(required = false) String value - ) throws IOException - { - SessionEntry session = authFilter.handle(request, response); - - if (session == null) - { - return; - } - - if (!configService.setKey(session.getUser(), key, value)) - { - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } - } - - @RequestMapping(path = "/{key:.+}", method = DELETE) - public void unsetKey( - HttpServletRequest request, - HttpServletResponse response, - @PathVariable String key - ) throws IOException - { - SessionEntry session = authFilter.handle(request, response); - - if (session == null) - { - return; - } - - if (!configService.unsetKey(session.getUser(), key)) - { - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/config/ConfigService.java b/http-service/src/main/java/net/runelite/http/service/config/ConfigService.java deleted file mode 100644 index 727620570f..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/config/ConfigService.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (c) 2017-2019, Adam - * 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.config; - -import com.google.common.annotations.VisibleForTesting; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSyntaxException; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoDatabase; -import static com.mongodb.client.model.Filters.eq; -import com.mongodb.client.model.IndexOptions; -import com.mongodb.client.model.Indexes; -import com.mongodb.client.model.UpdateOptions; -import static com.mongodb.client.model.Updates.set; -import static com.mongodb.client.model.Updates.unset; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import javax.annotation.Nullable; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.config.ConfigEntry; -import net.runelite.http.api.config.Configuration; -import org.bson.Document; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -@Service -public class ConfigService -{ - private static final int MAX_DEPTH = 8; - private static final int MAX_VALUE_LENGTH = 262144; - - private final Gson GSON = RuneLiteAPI.GSON; - private final UpdateOptions upsertUpdateOptions = new UpdateOptions().upsert(true); - - private final MongoCollection mongoCollection; - - @Autowired - public ConfigService( - MongoClient mongoClient, - @Value("${mongo.database}") String databaseName - ) - { - - MongoDatabase database = mongoClient.getDatabase(databaseName); - MongoCollection collection = database.getCollection("config"); - this.mongoCollection = collection; - - // Create unique index on _userId - IndexOptions indexOptions = new IndexOptions().unique(true); - collection.createIndex(Indexes.ascending("_userId"), indexOptions); - } - - private Document getConfig(int userId) - { - return mongoCollection.find(eq("_userId", userId)).first(); - } - - public Configuration get(int userId) - { - Map configMap = getConfig(userId); - - if (configMap == null || configMap.isEmpty()) - { - return new Configuration(Collections.emptyList()); - } - - List config = new ArrayList<>(); - - for (String group : configMap.keySet()) - { - // Reserved keys - if (group.startsWith("_") || group.startsWith("$")) - { - continue; - } - - Map groupMap = (Map) configMap.get(group); - - for (Map.Entry entry : groupMap.entrySet()) - { - String key = entry.getKey(); - Object value = entry.getValue(); - - if (value instanceof Map || value instanceof Collection) - { - value = GSON.toJson(entry.getValue()); - } - else if (value == null) - { - continue; - } - - ConfigEntry configEntry = new ConfigEntry(); - configEntry.setKey(group + "." + key.replace(':', '.')); - configEntry.setValue(value.toString()); - config.add(configEntry); - } - } - - return new Configuration(config); - } - - public boolean setKey( - int userId, - String key, - @Nullable String value - ) - { - if (key.startsWith("$") || key.startsWith("_")) - { - return false; - } - - String[] split = key.split("\\.", 2); - if (split.length != 2) - { - return false; - } - - if (!validateJson(value)) - { - return false; - } - - Object jsonValue = parseJsonString(value); - mongoCollection.updateOne(eq("_userId", userId), - set(split[0] + "." + split[1].replace('.', ':'), jsonValue), - upsertUpdateOptions); - return true; - } - - public boolean unsetKey( - int userId, - String key - ) - { - if (key.startsWith("$") || key.startsWith("_")) - { - return false; - } - - String[] split = key.split("\\.", 2); - if (split.length != 2) - { - return false; - } - - mongoCollection.updateOne(eq("_userId", userId), - unset(split[0] + "." + split[1].replace('.', ':'))); - return true; - } - - @VisibleForTesting - static Object parseJsonString(String value) - { - Object jsonValue; - try - { - jsonValue = RuneLiteAPI.GSON.fromJson(value, Object.class); - - if (jsonValue instanceof Double || jsonValue instanceof Float) - { - Number number = (Number) jsonValue; - if (Math.floor(number.doubleValue()) == number.doubleValue() && !Double.isInfinite(number.doubleValue())) - { - // value is an int or long. 'number' might be truncated so parse it from 'value' - try - { - jsonValue = Integer.parseInt(value); - } - catch (NumberFormatException ex) - { - try - { - jsonValue = Long.parseLong(value); - } - catch (NumberFormatException ex2) - { - - } - } - } - } - } - catch (JsonSyntaxException ex) - { - jsonValue = value; - } - return jsonValue; - } - - @VisibleForTesting - static boolean validateJson(String value) - { - try - { - // I couldn't figure out a better way to do this than a second json parse - JsonElement jsonElement = RuneLiteAPI.GSON.fromJson(value, JsonElement.class); - return validateObject(jsonElement, 1); - } - catch (JsonSyntaxException ex) - { - // the client submits the string representation of objects which is not always valid json, - // eg. a value with a ':' in it. We just ignore it now. We can't json encode the values client - // side due to them already being strings, which prevents gson from being able to convert them - // to ints/floats/maps etc. - return value.length() < MAX_VALUE_LENGTH; - } - } - - private static boolean validateObject(JsonElement jsonElement, int depth) - { - if (depth >= MAX_DEPTH) - { - return false; - } - - if (jsonElement.isJsonObject()) - { - JsonObject jsonObject = jsonElement.getAsJsonObject(); - - for (Map.Entry entry : jsonObject.entrySet()) - { - JsonElement element = entry.getValue(); - - if (!validateObject(element, depth + 1)) - { - return false; - } - } - } - else if (jsonElement.isJsonArray()) - { - JsonArray jsonArray = jsonElement.getAsJsonArray(); - - for (int i = 0; i < jsonArray.size(); ++i) - { - JsonElement element = jsonArray.get(i); - - if (!validateObject(element, depth + 1)) - { - return false; - } - } - } - else if (jsonElement.isJsonPrimitive()) - { - JsonPrimitive jsonPrimitive = jsonElement.getAsJsonPrimitive(); - String value = jsonPrimitive.getAsString(); - if (value.length() >= MAX_VALUE_LENGTH) - { - return false; - } - } - - return true; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/examine/ExamineController.java b/http-service/src/main/java/net/runelite/http/service/examine/ExamineController.java deleted file mode 100644 index b7e079497f..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/examine/ExamineController.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.examine; - -import static net.runelite.http.service.examine.ExamineType.ITEM; -import static net.runelite.http.service.examine.ExamineType.NPC; -import static net.runelite.http.service.examine.ExamineType.OBJECT; -import net.runelite.http.service.item.ItemEntry; -import net.runelite.http.service.item.ItemService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import static org.springframework.web.bind.annotation.RequestMethod.POST; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/examine") -public class ExamineController -{ - private final ExamineService examineService; - private final ItemService itemService; - - @Autowired - public ExamineController(ExamineService examineService, ItemService itemService) - { - this.examineService = examineService; - this.itemService = itemService; - } - - @GetMapping("/npc/{id}") - public String getNpc(@PathVariable int id) - { - return examineService.get(NPC, id); - } - - @GetMapping("/object/{id}") - public String getObject(@PathVariable int id) - { - return examineService.get(OBJECT, id); - } - - @GetMapping("/item/{id}") - public String getItem(@PathVariable int id) - { - // Tradeable item examine info is available from the Jagex item API - ItemEntry item = itemService.getItem(id); - if (item != null) - { - return item.getDescription(); - } - - return examineService.get(ITEM, id); - } - - @RequestMapping(path = "/npc/{id}", method = POST) - public void submitNpc(@PathVariable int id, @RequestBody String examine) - { - examineService.insert(NPC, id, examine); - } - - @RequestMapping(path = "/object/{id}", method = POST) - public void submitObject(@PathVariable int id, @RequestBody String examine) - { - examineService.insert(OBJECT, id, examine); - } - - @RequestMapping(path = "/item/{id}", method = POST) - public void submitItem(@PathVariable int id, @RequestBody String examine) - { - examineService.insert(ITEM, id, examine); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/examine/ExamineEntry.java b/http-service/src/main/java/net/runelite/http/service/examine/ExamineEntry.java deleted file mode 100644 index 5222ef3059..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/examine/ExamineEntry.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.examine; - -import java.time.Instant; - -public class ExamineEntry -{ - private ExamineType type; - private int id; - private Instant time; - private int count; - private String text; - - public ExamineType getType() - { - return type; - } - - public void setType(ExamineType type) - { - this.type = type; - } - - public int getId() - { - return id; - } - - public void setId(int id) - { - this.id = id; - } - - public Instant getTime() - { - return time; - } - - public void setTime(Instant time) - { - this.time = time; - } - - public int getCount() - { - return count; - } - - public void setCount(int count) - { - this.count = count; - } - - public String getText() - { - return text; - } - - public void setText(String text) - { - this.text = text; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/examine/ExamineService.java b/http-service/src/main/java/net/runelite/http/service/examine/ExamineService.java deleted file mode 100644 index c7fa265eea..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/examine/ExamineService.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.examine; - -import java.sql.Timestamp; -import java.time.Instant; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.Sql2o; - -@Service -public class ExamineService -{ - private static final String CREATE_EXAMINE = "CREATE TABLE IF NOT EXISTS `examine` (\n" - + " `type` enum('OBJECT','NPC','ITEM') NOT NULL,\n" - + " `id` int(11) NOT NULL,\n" - + " `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" - + " `count` int(11) NOT NULL,\n" - + " `text` tinytext NOT NULL,\n" - + " UNIQUE KEY `type` (`type`,`id`,`text`(64))\n" - + ") ENGINE=InnoDB"; - - private final Sql2o sql2o; - - @Autowired - public ExamineService(@Qualifier("Runelite SQL2O") Sql2o sql2o) - { - this.sql2o = sql2o; - - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_EXAMINE) - .executeUpdate(); - } - } - - public String get(ExamineType type, int id) - { - try (Connection con = sql2o.open()) - { - ExamineEntry entry = con.createQuery("select text from examine where type = :type and id = :id " - + "order by count desc limit 1") - .addParameter("type", type.toString()) - .addParameter("id", id) - .executeAndFetchFirst(ExamineEntry.class); - - if (entry != null) - { - return entry.getText(); - } - } - - return null; - } - - public void insert(ExamineType type, int id, String examine) - { - try (Connection con = sql2o.open()) - { - con.createQuery("insert into examine (type, id, time, count, text) values " - + "(:type, :id, :time, :count, :text) on duplicate key update count = count + 1") - .addParameter("type", type.toString()) - .addParameter("id", id) - .addParameter("time", Timestamp.from(Instant.now())) - .addParameter("count", 1) - .addParameter("text", examine) - .executeUpdate(); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/examine/ExamineType.java b/http-service/src/main/java/net/runelite/http/service/examine/ExamineType.java deleted file mode 100644 index 86826c0325..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/examine/ExamineType.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.examine; - -public enum ExamineType -{ - OBJECT, - NPC, - ITEM; -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/FeedController.java b/http-service/src/main/java/net/runelite/http/service/feed/FeedController.java deleted file mode 100644 index 66bd8582ce..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/FeedController.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed; - -import com.google.common.hash.HashCode; -import com.google.common.hash.Hasher; -import com.google.common.hash.Hashing; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.api.feed.FeedItem; -import net.runelite.http.api.feed.FeedResult; -import net.runelite.http.service.feed.blog.BlogService; -import net.runelite.http.service.feed.osrsnews.OSRSNewsService; -import net.runelite.http.service.feed.twitter.TwitterService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.CacheControl; -import org.springframework.http.ResponseEntity; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/feed") -@Slf4j -public class FeedController -{ - private final BlogService blogService; - private final TwitterService twitterService; - private final OSRSNewsService osrsNewsService; - - private static class MemoizedFeed - { - final FeedResult feedResult; - final String hash; - - MemoizedFeed(FeedResult feedResult) - { - this.feedResult = feedResult; - - Hasher hasher = Hashing.sha256().newHasher(); - for (FeedItem itemPrice : feedResult.getItems()) - { - hasher.putBytes(itemPrice.getTitle().getBytes()).putBytes(itemPrice.getContent().getBytes()); - } - HashCode code = hasher.hash(); - hash = code.toString(); - } - } - - private MemoizedFeed memoizedFeed; - - @Autowired - public FeedController(BlogService blogService, TwitterService twitterService, OSRSNewsService osrsNewsService) - { - this.blogService = blogService; - this.twitterService = twitterService; - this.osrsNewsService = osrsNewsService; - } - - @Scheduled(fixedDelay = 10 * 60 * 1000) - public void updateFeed() - { - List items = new ArrayList<>(); - - try - { - items.addAll(blogService.getBlogPosts()); - } - catch (Exception e) - { - log.warn("unable to fetch blogs", e); - } - - try - { - items.addAll(twitterService.getTweets()); - } - catch (Exception e) - { - log.warn("unable to fetch tweets", e); - } - - try - { - items.addAll(osrsNewsService.getNews()); - } - catch (Exception e) - { - log.warn("unable to fetch news", e); - } - - memoizedFeed = new MemoizedFeed(new FeedResult(items)); - } - - @GetMapping - public ResponseEntity getFeed() - { - if (memoizedFeed == null) - { - return ResponseEntity.notFound() - .build(); - } - - return ResponseEntity.ok() - .eTag(memoizedFeed.hash) - .cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePublic()) - .body(memoizedFeed.feedResult); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/blog/BlogService.java b/http-service/src/main/java/net/runelite/http/service/feed/blog/BlogService.java deleted file mode 100644 index 9da6cc171b..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/blog/BlogService.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed.blog; - -import java.io.IOException; -import java.io.InputStream; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.feed.FeedItem; -import net.runelite.http.api.feed.FeedItemType; -import net.runelite.http.service.util.exception.InternalServerErrorException; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -import org.springframework.stereotype.Service; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -@Service -public class BlogService -{ - private static final HttpUrl RSS_URL = HttpUrl.parse("https://runelite.net/atom.xml"); - private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); - - public List getBlogPosts() throws IOException - { - Request request = new Request.Builder() - .url(RSS_URL) - .build(); - - try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!response.isSuccessful()) - { - throw new IOException("Error getting blog posts: " + response); - } - - try - { - InputStream in = response.body().byteStream(); - Document document = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(in); - - Element documentElement = document.getDocumentElement(); - NodeList documentItems = documentElement.getElementsByTagName("entry"); - - List items = new ArrayList<>(); - - for (int i = 0; i < Math.min(documentItems.getLength(), 3); i++) - { - Node item = documentItems.item(i); - NodeList children = item.getChildNodes(); - - String title = null; - String summary = null; - String link = null; - long timestamp = -1; - - for (int j = 0; j < children.getLength(); j++) - { - Node childItem = children.item(j); - String nodeName = childItem.getNodeName(); - - switch (nodeName) - { - case "title": - title = childItem.getTextContent(); - break; - case "summary": - summary = childItem.getTextContent().replace("\n", "").trim(); - break; - case "link": - link = childItem.getAttributes().getNamedItem("href").getTextContent(); - break; - case "updated": - timestamp = DATE_FORMAT.parse(childItem.getTextContent()).getTime(); - break; - } - } - - if (title == null || summary == null || link == null || timestamp == -1) - { - throw new InternalServerErrorException("Failed to find title, summary, link and/or timestamp in the blog post feed"); - } - - items.add(new FeedItem(FeedItemType.BLOG_POST, title, summary, link, timestamp)); - } - - return items; - } - catch (ParserConfigurationException | SAXException | ParseException e) - { - throw new InternalServerErrorException("Failed to parse blog posts: " + e.getMessage()); - } - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/osrsnews/OSRSNewsService.java b/http-service/src/main/java/net/runelite/http/service/feed/osrsnews/OSRSNewsService.java deleted file mode 100644 index 0ae08bc85c..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/osrsnews/OSRSNewsService.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed.osrsnews; - -import java.io.IOException; -import java.io.InputStream; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.feed.FeedItem; -import net.runelite.http.api.feed.FeedItemType; -import net.runelite.http.service.util.exception.InternalServerErrorException; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -import org.springframework.stereotype.Service; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -@Service -public class OSRSNewsService -{ - private static final HttpUrl RSS_URL = HttpUrl.parse("https://services.runescape.com/m=news/latest_news.rss?oldschool=true"); - private static final SimpleDateFormat PUB_DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy '00:00:00 GMT'", Locale.US); - - public List getNews() throws IOException - { - Request request = new Request.Builder() - .url(RSS_URL) - .build(); - - try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!response.isSuccessful()) - { - throw new IOException("Error getting OSRS news: " + response); - } - - try - { - InputStream in = response.body().byteStream(); - Document document = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(in); - - Element documentElement = document.getDocumentElement(); - NodeList documentItems = documentElement.getElementsByTagName("item"); - - List items = new ArrayList<>(); - - for (int i = 0; i < documentItems.getLength(); i++) - { - Node item = documentItems.item(i); - NodeList children = item.getChildNodes(); - - String title = null; - String description = null; - String link = null; - long timestamp = -1; - - for (int j = 0; j < children.getLength(); j++) - { - Node childItem = children.item(j); - String nodeName = childItem.getNodeName(); - - switch (nodeName) - { - case "title": - title = childItem.getTextContent(); - break; - case "description": - description = childItem.getTextContent().replace("\n", "").trim(); - break; - case "link": - link = childItem.getTextContent(); - break; - case "pubDate": - timestamp = PUB_DATE_FORMAT.parse(childItem.getTextContent()).getTime(); - break; - } - } - - if (title == null || description == null || link == null || timestamp == -1) - { - throw new InternalServerErrorException("Failed to find title, description, link and/or timestamp in the OSRS RSS feed"); - } - - items.add(new FeedItem(FeedItemType.OSRS_NEWS, title, description, link, timestamp)); - } - - return items; - } - catch (ParserConfigurationException | SAXException | ParseException e) - { - throw new InternalServerErrorException("Failed to parse OSRS news: " + e.getMessage()); - } - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterOAuth2TokenResponse.java b/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterOAuth2TokenResponse.java deleted file mode 100644 index 24df0b6cf6..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterOAuth2TokenResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed.twitter; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -@Data -class TwitterOAuth2TokenResponse -{ - @SerializedName("token_type") - private String tokenType; - - @SerializedName("access_token") - private String token; -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterService.java b/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterService.java deleted file mode 100644 index 12b01c127c..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterService.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed.twitter; - -import com.google.gson.reflect.TypeToken; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.Base64; -import java.util.List; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.feed.FeedItem; -import net.runelite.http.api.feed.FeedItemType; -import net.runelite.http.service.util.exception.InternalServerErrorException; -import okhttp3.FormBody; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; - -@Service -public class TwitterService -{ - private static final HttpUrl AUTH_URL = HttpUrl.parse("https://api.twitter.com/oauth2/token"); - private static final HttpUrl LIST_STATUSES_URL = HttpUrl.parse("https://api.twitter.com/1.1/lists/statuses.json"); - - private final String credentials; - private final String listId; - - private String token; - - @Autowired - public TwitterService( - @Value("${runelite.twitter.consumerkey}") String consumerKey, - @Value("${runelite.twitter.secretkey}") String consumerSecret, - @Value("${runelite.twitter.listid}") String listId - ) - { - this.credentials = consumerKey + ":" + consumerSecret; - this.listId = listId; - } - - public List getTweets() throws IOException - { - return getTweets(false); - } - - private List getTweets(boolean hasRetried) throws IOException - { - if (token == null) - { - updateToken(); - } - - HttpUrl url = LIST_STATUSES_URL.newBuilder() - .addQueryParameter("list_id", listId) - .addQueryParameter("count", "15") - .addQueryParameter("include_entities", "false") - .build(); - - Request request = new Request.Builder() - .url(url) - .header("Authorization", "Bearer " + token) - .build(); - - try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!response.isSuccessful()) - { - switch (HttpStatus.valueOf(response.code())) - { - case BAD_REQUEST: - case UNAUTHORIZED: - updateToken(); - if (!hasRetried) - { - return getTweets(true); - } - throw new InternalServerErrorException("Could not auth to Twitter after trying once: " + response); - default: - throw new IOException("Error getting Twitter list: " + response); - } - } - - InputStream in = response.body().byteStream(); - Type listType = new TypeToken>() {}.getType(); - List statusesResponse = RuneLiteAPI.GSON - .fromJson(new InputStreamReader(in), listType); - - List items = new ArrayList<>(); - - for (TwitterStatusesResponseItem i : statusesResponse) - { - items.add(new FeedItem(FeedItemType.TWEET, - i.getUser().getProfileImageUrl(), - i.getUser().getScreenName(), - i.getText().replace("\n\n", " ").replaceAll("\n", " "), - "https://twitter.com/" + i.getUser().getScreenName() + "/status/" + i.getId(), - getTimestampFromSnowflake(i.getId()))); - } - - return items; - } - } - - private void updateToken() throws IOException - { - String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); - - Request request = new Request.Builder() - .url(AUTH_URL) - .header("Authorization", "Basic " + encodedCredentials) - .post(new FormBody.Builder().add("grant_type", "client_credentials").build()) - .build(); - - try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!response.isSuccessful()) - { - throw new IOException("Error authing to Twitter: " + response); - } - - InputStream in = response.body().byteStream(); - TwitterOAuth2TokenResponse tokenResponse = RuneLiteAPI.GSON - .fromJson(new InputStreamReader(in), TwitterOAuth2TokenResponse.class); - - if (!tokenResponse.getTokenType().equals("bearer")) - { - throw new InternalServerErrorException("Returned token was not a bearer token"); - } - - if (tokenResponse.getToken() == null) - { - throw new InternalServerErrorException("Returned token was null"); - } - - token = tokenResponse.getToken(); - } - } - - /** - * Extracts the UTC timestamp from a Twitter snowflake as per - * https://github.com/client9/snowflake2time/blob/master/python/snowflake.py#L24 - */ - private long getTimestampFromSnowflake(long snowflake) - { - return (snowflake >> 22) + 1288834974657L; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItem.java b/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItem.java deleted file mode 100644 index 90b37c5021..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItem.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed.twitter; - -import lombok.Data; - -@Data -class TwitterStatusesResponseItem -{ - private long id; - private String text; - private TwitterStatusesResponseItemUser user; -} diff --git a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItemUser.java b/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItemUser.java deleted file mode 100644 index 94fe9360f9..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/feed/twitter/TwitterStatusesResponseItemUser.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.feed.twitter; - -import com.google.gson.annotations.SerializedName; -import lombok.Data; - -@Data -class TwitterStatusesResponseItemUser -{ - @SerializedName("screen_name") - private String screenName; - - @SerializedName("profile_image_url_https") - private String profileImageUrl; -} diff --git a/http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeController.java b/http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeController.java deleted file mode 100644 index 94c759b130..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeController.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.ge; - -import java.io.IOException; -import java.util.Collection; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.ge.GrandExchangeTrade; -import net.runelite.http.service.account.AuthFilter; -import net.runelite.http.service.account.beans.SessionEntry; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/ge") -public class GrandExchangeController -{ - private final GrandExchangeService grandExchangeService; - private final AuthFilter authFilter; - - @Autowired - public GrandExchangeController(GrandExchangeService grandExchangeService, AuthFilter authFilter) - { - this.grandExchangeService = grandExchangeService; - this.authFilter = authFilter; - } - - @PostMapping - public void submit(HttpServletRequest request, HttpServletResponse response, @RequestBody GrandExchangeTrade grandExchangeTrade) throws IOException - { - SessionEntry session = authFilter.handle(request, response); - - if (session == null) - { - return; - } - - grandExchangeService.add(session.getUser(), grandExchangeTrade); - } - - @GetMapping - public Collection get(HttpServletRequest request, HttpServletResponse response, - @RequestParam(required = false, defaultValue = "1024") int limit, - @RequestParam(required = false, defaultValue = "0") int offset) throws IOException - { - SessionEntry session = authFilter.handle(request, response); - - if (session == null) - { - return null; - } - - return grandExchangeService.get(session.getUser(), limit, offset).stream() - .map(GrandExchangeController::convert) - .collect(Collectors.toList()); - } - - private static GrandExchangeTrade convert(TradeEntry tradeEntry) - { - GrandExchangeTrade grandExchangeTrade = new GrandExchangeTrade(); - grandExchangeTrade.setBuy(tradeEntry.getAction() == TradeAction.BUY); - grandExchangeTrade.setItemId(tradeEntry.getItem()); - grandExchangeTrade.setQuantity(tradeEntry.getQuantity()); - grandExchangeTrade.setPrice(tradeEntry.getPrice()); - grandExchangeTrade.setTime(tradeEntry.getTime()); - return grandExchangeTrade; - } - - @DeleteMapping - public void delete(HttpServletRequest request, HttpServletResponse response) throws IOException - { - SessionEntry session = authFilter.handle(request, response); - - if (session == null) - { - return; - } - - grandExchangeService.delete(session.getUser()); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeService.java b/http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeService.java deleted file mode 100644 index 6456beb85f..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/ge/GrandExchangeService.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.ge; - -import java.util.Collection; -import net.runelite.http.api.ge.GrandExchangeTrade; -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 GrandExchangeService -{ - private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS `ge_trades` (\n" + - " `id` int(11) NOT NULL AUTO_INCREMENT,\n" + - " `user` int(11) NOT NULL,\n" + - " `action` enum('BUY','SELL') NOT NULL,\n" + - " `item` int(11) NOT NULL,\n" + - " `quantity` int(11) NOT NULL,\n" + - " `price` int(11) NOT NULL,\n" + - " `time` timestamp NOT NULL DEFAULT current_timestamp(),\n" + - " PRIMARY KEY (`id`),\n" + - " KEY `user_time` (`user`, `time`),\n" + - " KEY `time` (`time`),\n" + - " CONSTRAINT `ge_trades_ibfk_1` FOREIGN KEY (`user`) REFERENCES `users` (`id`)\n" + - ") ENGINE=InnoDB;"; - - private final Sql2o sql2o; - - @Autowired - public GrandExchangeService(@Qualifier("Runelite SQL2O") Sql2o sql2o) - { - this.sql2o = sql2o; - - // Ensure necessary tables exist - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_TABLE).executeUpdate(); - } - } - - public void add(int userId, GrandExchangeTrade grandExchangeTrade) - { - try (Connection con = sql2o.open()) - { - con.createQuery("insert into ge_trades (user, action, item, quantity, price) values (:user," + - " :action, :item, :quantity, :price)") - .addParameter("user", userId) - .addParameter("action", grandExchangeTrade.isBuy() ? "BUY" : "SELL") - .addParameter("item", grandExchangeTrade.getItemId()) - .addParameter("quantity", grandExchangeTrade.getQuantity()) - .addParameter("price", grandExchangeTrade.getPrice()) - .executeUpdate(); - } - } - - public Collection get(int userId, int limit, int offset) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("select id, user, action, item, quantity, price, time from ge_trades where user = :user limit :limit offset :offset") - .addParameter("user", userId) - .addParameter("limit", limit) - .addParameter("offset", offset) - .executeAndFetch(TradeEntry.class); - } - } - - public void delete(int userId) - { - try (Connection con = sql2o.open()) - { - con.createQuery("delete from ge_trades where user = :user") - .addParameter("user", userId) - .executeUpdate(); - } - } - - @Scheduled(fixedDelay = 60 * 60 * 1000) - public void expire() - { - try (Connection con = sql2o.open()) - { - con.createQuery("delete from ge_trades where time < current_timestamp - interval 1 month") - .executeUpdate(); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/ge/TradeAction.java b/http-service/src/main/java/net/runelite/http/service/ge/TradeAction.java deleted file mode 100644 index fcc96d615f..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/ge/TradeAction.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.ge; - -enum TradeAction -{ - BUY, - SELL; -} diff --git a/http-service/src/main/java/net/runelite/http/service/ge/TradeEntry.java b/http-service/src/main/java/net/runelite/http/service/ge/TradeEntry.java deleted file mode 100644 index bca3869811..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/ge/TradeEntry.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.ge; - -import java.time.Instant; -import lombok.Data; - -@Data -class TradeEntry -{ - private int id; - private int user; - private TradeAction action; - private int item; - private int quantity; - private int price; - private Instant time; -} diff --git a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreController.java b/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreController.java deleted file mode 100644 index 25a89e6a8d..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreController.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.hiscore; - -import java.util.concurrent.ExecutionException; -import net.runelite.http.api.hiscore.HiscoreEndpoint; -import net.runelite.http.api.hiscore.HiscoreResult; -import net.runelite.http.api.hiscore.HiscoreSkill; -import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; -import net.runelite.http.api.hiscore.Skill; -import net.runelite.http.service.util.HiscoreEndpointEditor; -import net.runelite.http.service.xp.XpTrackerService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.InitBinder; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/hiscore") -public class HiscoreController -{ - @Autowired - private HiscoreService hiscoreService; - - @Autowired - private XpTrackerService xpTrackerService; - - @GetMapping("/{endpoint}") - public HiscoreResult lookup(@PathVariable HiscoreEndpoint endpoint, @RequestParam String username) throws ExecutionException - { - HiscoreResult result = hiscoreService.lookupUsername(username, endpoint); - - // Submit to xp tracker? - switch (endpoint) - { - case NORMAL: - case IRONMAN: - case ULTIMATE_IRONMAN: - case HARDCORE_IRONMAN: - xpTrackerService.update(username, result); - } - - return result; - } - - @GetMapping("/{endpoint}/{skillName}") - public SingleHiscoreSkillResult singleSkillLookup(@PathVariable HiscoreEndpoint endpoint, @PathVariable String skillName, @RequestParam String username) throws ExecutionException - { - HiscoreSkill skill = HiscoreSkill.valueOf(skillName.toUpperCase()); - - // RS api only supports looking up all stats - HiscoreResult result = hiscoreService.lookupUsername(username, endpoint); - - // Find the skill to return - Skill requested = result.getSkill(skill); - - SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); - skillResult.setPlayer(username); - skillResult.setSkillName(skillName); - skillResult.setSkill(requested); - - return skillResult; - } - - @InitBinder - public void initBinder(WebDataBinder binder) - { - binder.registerCustomEditor(HiscoreEndpoint.class, new HiscoreEndpointEditor()); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreKey.java b/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreKey.java deleted file mode 100644 index b15603a224..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreKey.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.hiscore; - -import lombok.Value; -import net.runelite.http.api.hiscore.HiscoreEndpoint; - -@Value -class HiscoreKey -{ - String username; - HiscoreEndpoint endpoint; -} diff --git a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java b/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java deleted file mode 100644 index cc565b4444..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/hiscore/HiscoreService.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.hiscore; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import net.runelite.http.api.hiscore.HiscoreClient; -import net.runelite.http.api.hiscore.HiscoreEndpoint; -import net.runelite.http.api.hiscore.HiscoreResult; -import okhttp3.HttpUrl; -import org.springframework.stereotype.Service; - -@Service -public class HiscoreService -{ - private final HiscoreClient hiscoreClient = new HiscoreClient(); - private final LoadingCache hiscoreCache = CacheBuilder.newBuilder() - .maximumSize(128) - .expireAfterWrite(1, TimeUnit.MINUTES) - .build( - new CacheLoader() - { - @Override - public HiscoreResult load(HiscoreKey key) throws IOException - { - return hiscoreClient.lookup(key.getUsername(), key.getEndpoint()); - } - }); - - @VisibleForTesting - HiscoreResult lookupUsername(String username, HttpUrl httpUrl) throws IOException - { - return hiscoreClient.lookup(username, httpUrl); - } - - public HiscoreResult lookupUsername(String username, HiscoreEndpoint endpoint) throws ExecutionException - { - return hiscoreCache.get(new HiscoreKey(username, endpoint)); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/ItemController.java b/http-service/src/main/java/net/runelite/http/service/item/ItemController.java deleted file mode 100644 index 8db56ef2ff..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/ItemController.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2017-2018, Adam - * 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.item; - -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.hash.HashCode; -import com.google.common.hash.Hasher; -import com.google.common.hash.Hashing; -import java.time.Instant; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.item.Item; -import net.runelite.http.api.item.ItemPrice; -import net.runelite.http.api.item.SearchResult; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.CacheControl; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/item") -public class ItemController -{ - private static final String RUNELITE_CACHE = "RuneLite-Cache"; - private static final int MAX_BATCH_LOOKUP = 1024; - - private static class MemoizedPrices - { - final ItemPrice[] prices; - final String hash; - - MemoizedPrices(ItemPrice[] prices) - { - this.prices = prices; - - Hasher hasher = Hashing.sha256().newHasher(); - for (ItemPrice itemPrice : prices) - { - hasher.putInt(itemPrice.getId()).putInt(itemPrice.getPrice()); - } - HashCode code = hasher.hash(); - hash = code.toString(); - } - } - - private final Cache cachedEmpty = CacheBuilder.newBuilder() - .maximumSize(1024L) - .build(); - - private final ItemService itemService; - - private final Supplier memoizedPrices; - - @Autowired - public ItemController(ItemService itemService) - { - this.itemService = itemService; - - memoizedPrices = Suppliers.memoizeWithExpiration(() -> new MemoizedPrices(itemService.fetchPrices().stream() - .map(priceEntry -> - { - ItemPrice itemPrice = new ItemPrice(); - itemPrice.setId(priceEntry.getItem()); - itemPrice.setName(priceEntry.getName()); - itemPrice.setPrice(priceEntry.getPrice()); - itemPrice.setTime(priceEntry.getTime()); - return itemPrice; - }) - .toArray(ItemPrice[]::new)), 30, TimeUnit.MINUTES); - } - - @GetMapping("/{itemId}") - public Item getItem(HttpServletResponse response, @PathVariable int itemId) - { - ItemEntry item = itemService.getItem(itemId); - if (item != null) - { - return item.toItem(); - } - - itemService.queueItem(itemId); - return null; - } - - @GetMapping(path = "/{itemId}/icon", produces = "image/gif") - public ResponseEntity getIcon(@PathVariable int itemId) - { - ItemEntry item = itemService.getItem(itemId); - if (item != null && item.getIcon() != null) - { - return ResponseEntity.ok(item.getIcon()); - } - - itemService.queueItem(itemId); - return ResponseEntity.notFound().build(); - } - - @GetMapping(path = "/{itemId}/icon/large", produces = "image/gif") - public ResponseEntity getIconLarge(HttpServletResponse response, @PathVariable int itemId) - { - ItemEntry item = itemService.getItem(itemId); - if (item != null && item.getIcon_large() != null) - { - return ResponseEntity.ok(item.getIcon_large()); - } - - itemService.queueItem(itemId); - return ResponseEntity.notFound().build(); - } - - @GetMapping("/{itemId}/price") - public ResponseEntity itemPrice( - @PathVariable int itemId, - @RequestParam(required = false) Instant time - ) - { - if (cachedEmpty.getIfPresent(itemId) != null) - { - return ResponseEntity.notFound() - .header(RUNELITE_CACHE, "HIT") - .build(); - } - - Instant now = Instant.now(); - - if (time != null && time.isAfter(now)) - { - time = now; - } - - ItemEntry item = itemService.getItem(itemId); - if (item == null) - { - itemService.queueItem(itemId); // queue lookup - cachedEmpty.put(itemId, itemId); // cache empty - return ResponseEntity.notFound() - .header(RUNELITE_CACHE, "MISS") - .build(); - } - - PriceEntry priceEntry = itemService.getPrice(itemId, time); - - if (time != null) - { - if (priceEntry == null) - { - // we maybe can't backfill this - return ResponseEntity.notFound() - .header(RUNELITE_CACHE, "MISS") - .build(); - } - } - else if (priceEntry == null) - { - // Price is unknown - cachedEmpty.put(itemId, itemId); - return ResponseEntity.notFound() - .header(RUNELITE_CACHE, "MISS") - .build(); - } - - ItemPrice itemPrice = new ItemPrice(); - itemPrice.setId(item.getId()); - itemPrice.setName(item.getName()); - itemPrice.setPrice(priceEntry.getPrice()); - itemPrice.setTime(priceEntry.getTime()); - - return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic()) - .body(itemPrice); - } - - @GetMapping("/search") - public SearchResult search(@RequestParam String query) - { - List result = itemService.search(query); - - itemService.queueSearch(query); - - SearchResult searchResult = new SearchResult(); - searchResult.setItems(result.stream() - .map(ItemEntry::toItem) - .collect(Collectors.toList())); - return searchResult; - } - - @GetMapping("/price") - public ItemPrice[] prices(@RequestParam("id") int[] itemIds) - { - if (itemIds.length > MAX_BATCH_LOOKUP) - { - itemIds = Arrays.copyOf(itemIds, MAX_BATCH_LOOKUP); - } - - List prices = itemService.getPrices(itemIds); - - return prices.stream() - .map(priceEntry -> - { - ItemPrice itemPrice = new ItemPrice(); - itemPrice.setId(priceEntry.getItem()); - itemPrice.setName(priceEntry.getName()); - itemPrice.setPrice(priceEntry.getPrice()); - itemPrice.setTime(priceEntry.getTime()); - return itemPrice; - }) - .toArray(ItemPrice[]::new); - } - - @GetMapping("/prices") - public ResponseEntity prices() - { - MemoizedPrices memorizedPrices = this.memoizedPrices.get(); - return ResponseEntity.ok() - .eTag(memorizedPrices.hash) - .cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic()) - .body(memorizedPrices.prices); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/ItemEntry.java b/http-service/src/main/java/net/runelite/http/service/item/ItemEntry.java deleted file mode 100644 index b92f171cc7..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/ItemEntry.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.item; - -import java.time.Instant; -import lombok.Data; -import net.runelite.http.api.item.Item; -import net.runelite.http.api.item.ItemType; - -@Data -public class ItemEntry -{ - private int id; - private String name; - private String description; - private ItemType type; - private byte[] icon; - private byte[] icon_large; - private Instant timestamp; - - public Item toItem() - { - Item item = new Item(); - item.setId(id); - item.setName(name); - item.setDescription(description); - item.setType(type); - return item; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/ItemService.java b/http-service/src/main/java/net/runelite/http/service/item/ItemService.java deleted file mode 100644 index 72a0fe85aa..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/ItemService.java +++ /dev/null @@ -1,505 +0,0 @@ -/* - * Copyright (c) 2017-2018, Adam - * 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.item; - -import com.google.gson.JsonParseException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.time.Instant; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.ConcurrentLinkedQueue; -import lombok.extern.slf4j.Slf4j; -import net.runelite.cache.definitions.ItemDefinition; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.item.ItemType; -import net.runelite.http.service.cache.CacheService; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -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.Query; -import org.sql2o.Sql2o; - -@Service -@Slf4j -public class ItemService -{ - private static final String BASE = "https://services.runescape.com/m=itemdb_oldschool"; - private static final HttpUrl RS_ITEM_URL = HttpUrl.parse(BASE + "/api/catalogue/detail.json"); - private static final HttpUrl RS_PRICE_URL = HttpUrl.parse(BASE + "/api/graph"); - private static final HttpUrl RS_SEARCH_URL = HttpUrl.parse(BASE + "/api/catalogue/items.json?category=1"); - - private static final String CREATE_ITEMS = "CREATE TABLE IF NOT EXISTS `items` (\n" - + " `id` int(11) NOT NULL,\n" - + " `name` tinytext NOT NULL,\n" - + " `description` tinytext NOT NULL,\n" - + " `type` enum('DEFAULT') NOT NULL,\n" - + " `icon` blob,\n" - + " `icon_large` blob,\n" - + " `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n" - + " PRIMARY KEY (`id`),\n" - + " FULLTEXT idx_name (name)\n" - + ") ENGINE=InnoDB"; - - private static final String CREATE_PRICES = "CREATE TABLE IF NOT EXISTS `prices` (\n" - + " `item` int(11) NOT NULL,\n" - + " `price` int(11) NOT NULL,\n" - + " `time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n" - + " `fetched_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',\n" - + " UNIQUE KEY `item_time` (`item`,`time`),\n" - + " KEY `item_fetched_time` (`item`,`fetched_time`)\n" - + ") ENGINE=InnoDB"; - - private static final int MAX_PENDING = 512; - - private final Sql2o sql2o; - private final CacheService cacheService; - - private final ConcurrentLinkedQueue pendingLookups = new ConcurrentLinkedQueue(); - private int[] tradeableItems; - private final Random random = new Random(); - - @Autowired - public ItemService(@Qualifier("Runelite SQL2O") Sql2o sql2o, - CacheService cacheService) - { - this.sql2o = sql2o; - this.cacheService = cacheService; - - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_ITEMS) - .executeUpdate(); - - con.createQuery(CREATE_PRICES) - .executeUpdate(); - } - } - - public ItemEntry getItem(int itemId) - { - try (Connection con = sql2o.open()) - { - ItemEntry item = con.createQuery("select id, name, description, type, icon, icon_large from items where id = :id") - .addParameter("id", itemId) - .executeAndFetchFirst(ItemEntry.class); - - return item; - } - } - - private PriceEntry getPrice(Connection con, int itemId, Instant time) - { - if (time != null) - { - return con.createQuery("select item, name, price, time, fetched_time from prices t1 join items t2 on t1.item=t2.id where item = :item and time <= :time order by time desc limit 1") - .addParameter("item", itemId) - .addParameter("time", time.toString()) - .executeAndFetchFirst(PriceEntry.class); - } - else - { - return con.createQuery("select item, name, price, time, fetched_time from prices t1 join items t2 on t1.item=t2.id where item = :item order by time desc limit 1") - .addParameter("item", itemId) - .executeAndFetchFirst(PriceEntry.class); - } - } - - public PriceEntry getPrice(int itemId, Instant time) - { - try (Connection con = sql2o.open()) - { - return getPrice(con, itemId, time); - } - } - - public List getPrices(int... itemIds) - { - try (Connection con = sql2o.open()) - { - Set seen = new HashSet<>(); - List priceEntries = new ArrayList<>(itemIds.length); - - for (int itemId : itemIds) - { - if (seen.contains(itemId)) - { - continue; - } - seen.add(itemId); - - PriceEntry priceEntry = getPrice(con, itemId, null); - - if (priceEntry == null) - { - continue; - } - - priceEntries.add(priceEntry); - } - - return priceEntries; - } - } - - public List search(String search) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("select id, name, description, type, match (name) against (:search) as score from items " - + "where match (name) against (:search) order by score desc limit 10") - .throwOnMappingFailure(false) // otherwise it tries to map 'score' - .addParameter("search", search) - .executeAndFetch(ItemEntry.class); - } - } - - public ItemEntry fetchItem(int itemId) - { - try - { - RSItem rsItem = fetchRSItem(itemId); - byte[] icon = null, iconLarge = null; - - try - { - icon = fetchImage(rsItem.getIcon()); - } - catch (IOException ex) - { - log.warn("error fetching image", ex); - } - - try - { - iconLarge = fetchImage(rsItem.getIcon_large()); - } - catch (IOException ex) - { - log.warn("error fetching image", ex); - } - - try (Connection con = sql2o.open()) - { - con.createQuery("insert into items (id, name, description, type, icon, icon_large) values (:id," - + " :name, :description, :type, :icon, :icon_large) ON DUPLICATE KEY UPDATE name = :name," - + " description = :description, type = :type, icon = :icon, icon_large = :icon_large") - .addParameter("id", rsItem.getId()) - .addParameter("name", rsItem.getName()) - .addParameter("description", rsItem.getDescription()) - .addParameter("type", rsItem.getType()) - .addParameter("icon", icon) - .addParameter("icon_large", iconLarge) - .executeUpdate(); - } - - ItemEntry item = new ItemEntry(); - item.setId(itemId); - item.setName(rsItem.getName()); - item.setDescription(rsItem.getDescription()); - item.setType(ItemType.of(rsItem.getType())); - item.setIcon(icon); - item.setIcon_large(iconLarge); - return item; - } - catch (IOException ex) - { - log.warn("unable to fetch item {}", itemId, ex); - return null; - } - } - - public List fetchPrice(int itemId) - { - RSPrices rsprice; - try - { - rsprice = fetchRSPrices(itemId); - } - catch (IOException ex) - { - log.warn("unable to fetch price for item {}", itemId, ex); - return null; - } - - try (Connection con = sql2o.beginTransaction()) - { - List entries = new ArrayList<>(); - Instant now = Instant.now(); - - Query query = con.createQuery("insert into prices (item, price, time, fetched_time) values (:item, :price, :time, :fetched_time) " - + "ON DUPLICATE KEY UPDATE price = VALUES(price), fetched_time = VALUES(fetched_time)"); - - for (Map.Entry entry : rsprice.getDaily().entrySet()) - { - long ts = entry.getKey(); // ms since epoch - int price = entry.getValue(); // gp - - Instant time = Instant.ofEpochMilli(ts); - - PriceEntry priceEntry = new PriceEntry(); - priceEntry.setItem(itemId); - priceEntry.setPrice(price); - priceEntry.setTime(time); - priceEntry.setFetched_time(now); - entries.add(priceEntry); - - query - .addParameter("item", itemId) - .addParameter("price", price) - .addParameter("time", time) - .addParameter("fetched_time", now) - .addToBatch(); - } - - query.executeBatch(); - con.commit(false); - - return entries; - } - } - - public List fetchPrices() - { - try (Connection con = sql2o.beginTransaction()) - { - Query query = con.createQuery("select t2.item, t3.name, t2.time, prices.price, prices.fetched_time from (select t1.item as item, max(t1.time) as time from prices t1 group by item) t2 " + - " join prices on t2.item=prices.item and t2.time=prices.time" + - " join items t3 on t2.item=t3.id"); - return query.executeAndFetch(PriceEntry.class); - } - } - - private RSItem fetchRSItem(int itemId) throws IOException - { - HttpUrl itemUrl = RS_ITEM_URL - .newBuilder() - .addQueryParameter("item", "" + itemId) - .build(); - - Request request = new Request.Builder() - .url(itemUrl) - .build(); - - RSItemResponse itemResponse = fetchJson(request, RSItemResponse.class); - return itemResponse.getItem(); - - } - - private RSPrices fetchRSPrices(int itemId) throws IOException - { - HttpUrl priceUrl = RS_PRICE_URL - .newBuilder() - .addPathSegment(itemId + ".json") - .build(); - - Request request = new Request.Builder() - .url(priceUrl) - .build(); - - return fetchJson(request, RSPrices.class); - } - - public RSSearch fetchRSSearch(String query) throws IOException - { - // rs api seems to require lowercase - query = query.toLowerCase(); - - HttpUrl searchUrl = RS_SEARCH_URL - .newBuilder() - .addQueryParameter("alpha", query) - .build(); - - Request request = new Request.Builder() - .url(searchUrl) - .build(); - - return fetchJson(request, RSSearch.class); - } - - private void batchInsertItems(RSSearch search) - { - try (Connection con = sql2o.beginTransaction()) - { - Query q = con.createQuery("insert into items (id, name, description, type) values (:id," - + " :name, :description, :type) ON DUPLICATE KEY UPDATE name = :name," - + " description = :description, type = :type"); - - for (RSItem rsItem : search.getItems()) - { - q.addParameter("id", rsItem.getId()) - .addParameter("name", rsItem.getName()) - .addParameter("description", rsItem.getDescription()) - .addParameter("type", rsItem.getType()) - .addToBatch(); - } - - q.executeBatch(); - con.commit(false); - } - } - - private T fetchJson(Request request, Class clazz) throws IOException - { - try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!response.isSuccessful()) - { - throw new IOException("Unsuccessful http response: " + response); - } - - InputStream in = response.body().byteStream(); - return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), clazz); - } - catch (JsonParseException ex) - { - throw new IOException(ex); - } - } - - private byte[] fetchImage(String url) throws IOException - { - HttpUrl httpUrl = HttpUrl.parse(url); - - Request request = new Request.Builder() - .url(httpUrl) - .build(); - - try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!response.isSuccessful()) - { - throw new IOException("Unsuccessful http response: " + response); - } - - return response.body().bytes(); - } - } - - public void queueSearch(String search) - { - if (pendingLookups.size() < MAX_PENDING) - { - pendingLookups.add(new PendingLookup(search, PendingLookup.Type.SEARCH)); - } - else - { - log.debug("Dropping pending search for {}", search); - } - } - - public void queueItem(int itemId) - { - if (pendingLookups.size() < MAX_PENDING) - { - pendingLookups.add(new PendingLookup(itemId, PendingLookup.Type.ITEM)); - } - else - { - log.debug("Dropping pending item lookup for {}", itemId); - } - } - - @Scheduled(fixedDelay = 5000) - public void check() - { - PendingLookup pendingLookup = pendingLookups.poll(); - if (pendingLookup == null) - { - return; - } - - switch (pendingLookup.getType()) - { - case SEARCH: - try - { - RSSearch reSearch = fetchRSSearch(pendingLookup.getSearch()); - - batchInsertItems(reSearch); - } - catch (IOException ex) - { - log.warn("error while searching items", ex); - } - break; - case ITEM: - fetchItem(pendingLookup.getItemId()); - break; - } - } - - @Scheduled(fixedDelay = 20_000) - public void crawlPrices() - { - if (tradeableItems == null || tradeableItems.length == 0) - { - return; - } - - int idx = random.nextInt(tradeableItems.length); - int id = tradeableItems[idx]; - - if (getItem(id) == null) - { - // This is a new item.. - log.debug("Fetching new item {}", id); - queueItem(id); - return; - } - - log.debug("Fetching price for {}", id); - - fetchPrice(id); - } - - @Scheduled(fixedDelay = 1_8000_000) // 30 minutes - public void reloadItems() throws IOException - { - List items = cacheService.getItems(); - if (items.isEmpty()) - { - log.warn("Failed to load any items from cache, item price updating will be disabled"); - } - - tradeableItems = items.stream() - .filter(item -> item.isTradeable) - .mapToInt(item -> item.id) - .toArray(); - - log.debug("Loaded {} tradeable items", tradeableItems.length); - } - -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/PendingLookup.java b/http-service/src/main/java/net/runelite/http/service/item/PendingLookup.java deleted file mode 100644 index d23ff5c1d9..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/PendingLookup.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.item; - -import lombok.Value; - -@Value -class PendingLookup -{ - enum Type - { - SEARCH, - ITEM; - } - - private final int itemId; - private final String search; - private final Type type; - - public PendingLookup(int itemId, Type type) - { - this.itemId = itemId; - this.search = null; - this.type = type; - } - - public PendingLookup(String search, Type type) - { - this.itemId = -1; - this.search = search; - this.type = type; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/PriceEntry.java b/http-service/src/main/java/net/runelite/http/service/item/PriceEntry.java deleted file mode 100644 index 00f0e6815c..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/PriceEntry.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.item; - -import java.time.Instant; -import lombok.Data; - -@Data -class PriceEntry -{ - private int item; - private String name; - private int price; - private Instant time; - private Instant fetched_time; -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/RSItem.java b/http-service/src/main/java/net/runelite/http/service/item/RSItem.java deleted file mode 100644 index b7c09260c6..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/RSItem.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.item; - -import lombok.Data; -import net.runelite.http.api.item.Item; -import net.runelite.http.api.item.ItemType; - -@Data -public class RSItem -{ - private int id; - private String name; - private String description; - private String type; - private String icon; - private String icon_large; - - public Item toItem() - { - Item item = new Item(); - item.setId(id); - item.setName(name); - item.setType(ItemType.of(type)); - item.setDescription(description); - return item; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/RSItemResponse.java b/http-service/src/main/java/net/runelite/http/service/item/RSItemResponse.java deleted file mode 100644 index 3fd7b3cef3..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/RSItemResponse.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.item; - -import lombok.Data; - -@Data -public class RSItemResponse -{ - private RSItem item; -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/RSPrices.java b/http-service/src/main/java/net/runelite/http/service/item/RSPrices.java deleted file mode 100644 index 04331d753e..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/RSPrices.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.item; - -import java.util.Map; -import lombok.Data; - -@Data -public class RSPrices -{ - /** - * unix time in ms to price in gp - */ - private Map daily; -} diff --git a/http-service/src/main/java/net/runelite/http/service/item/RSSearch.java b/http-service/src/main/java/net/runelite/http/service/item/RSSearch.java deleted file mode 100644 index b0edfdf798..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/item/RSSearch.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.item; - -import java.util.List; -import lombok.Data; - -@Data -public class RSSearch -{ - private List items; -} diff --git a/http-service/src/main/java/net/runelite/http/service/loottracker/LootResult.java b/http-service/src/main/java/net/runelite/http/service/loottracker/LootResult.java deleted file mode 100644 index 5bfd7afee0..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/loottracker/LootResult.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.loottracker; - -import java.time.Instant; -import lombok.Data; -import net.runelite.http.api.loottracker.LootRecordType; - -@Data -class LootResult -{ - private int killId; - private Instant time; - private LootRecordType type; - private String eventId; - private int itemId; - private int itemQuantity; -} diff --git a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java b/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java deleted file mode 100644 index 1033d62187..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerController.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2018, TheStonedTurtle - * Copyright (c) 2018, Adam - * 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.loottracker; - -import com.google.api.client.http.HttpStatusCodes; -import java.io.IOException; -import java.util.Collection; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.loottracker.LootRecord; -import net.runelite.http.service.account.AuthFilter; -import net.runelite.http.service.account.beans.SessionEntry; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/loottracker") -public class LootTrackerController -{ - @Autowired - private LootTrackerService service; - - @Autowired - private AuthFilter auth; - - @RequestMapping(method = RequestMethod.POST) - public void storeLootRecord(HttpServletRequest request, HttpServletResponse response, @RequestBody Collection records) throws IOException - { - SessionEntry e = auth.handle(request, response); - if (e == null) - { - response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED); - return; - } - - service.store(records, e.getUser()); - response.setStatus(HttpStatusCodes.STATUS_CODE_OK); - } - - @GetMapping - public Collection getLootRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "count", defaultValue = "1024") int count, @RequestParam(value = "start", defaultValue = "0") int start) throws IOException - { - SessionEntry e = auth.handle(request, response); - if (e == null) - { - response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED); - return null; - } - - return service.get(e.getUser(), count, start); - } - - @DeleteMapping - public void deleteLoot(HttpServletRequest request, HttpServletResponse response, - @RequestParam(required = false) String eventId) throws IOException - { - SessionEntry e = auth.handle(request, response); - if (e == null) - { - response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED); - return; - } - - service.delete(e.getUser(), eventId); - } -} \ No newline at end of file diff --git a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java b/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java deleted file mode 100644 index 8f97ce144d..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/loottracker/LootTrackerService.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2018, TheStonedTurtle - * Copyright (c) 2018, Adam - * 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.loottracker; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import net.runelite.http.api.loottracker.GameItem; -import net.runelite.http.api.loottracker.LootRecord; -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.Query; -import org.sql2o.Sql2o; - -@Service -public class LootTrackerService -{ - // Table for storing individual LootRecords - private static final String CREATE_KILLS = "CREATE TABLE IF NOT EXISTS `kills` (\n" - + " `id` INT AUTO_INCREMENT UNIQUE,\n" - + " `time` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),\n" - + " `accountId` INT NOT NULL,\n" - + " `type` enum('NPC', 'PLAYER', 'EVENT', 'UNKNOWN') NOT NULL,\n" - + " `eventId` VARCHAR(255) NOT NULL,\n" - + " PRIMARY KEY (id),\n" - + " FOREIGN KEY (accountId) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE,\n" - + " INDEX idx_acc (accountId, time)," - + " INDEX idx_time (time)" - + ") ENGINE=InnoDB"; - - // Table for storing Items received as loot for individual LootRecords - private static final String CREATE_DROPS = "CREATE TABLE IF NOT EXISTS `drops` (\n" - + " `killId` INT NOT NULL,\n" - + " `itemId` INT NOT NULL,\n" - + " `itemQuantity` INT NOT NULL,\n" - + " FOREIGN KEY (killId) REFERENCES kills(id) ON DELETE CASCADE\n" - + ") ENGINE=InnoDB"; - - // Queries for inserting kills - private static final String INSERT_KILL_QUERY = "INSERT INTO kills (accountId, type, eventId) VALUES (:accountId, :type, :eventId)"; - private static final String INSERT_DROP_QUERY = "INSERT INTO drops (killId, itemId, itemQuantity) VALUES (:killId, :itemId, :itemQuantity)"; - - private static final String SELECT_LOOT_QUERY = "SELECT killId,time,type,eventId,itemId,itemQuantity FROM kills JOIN drops ON drops.killId = kills.id WHERE accountId = :accountId ORDER BY TIME DESC LIMIT :limit OFFSET :offset"; - - private static final String DELETE_LOOT_ACCOUNT = "DELETE FROM kills WHERE accountId = :accountId"; - private static final String DELETE_LOOT_ACCOUNT_EVENTID = "DELETE FROM kills WHERE accountId = :accountId AND eventId = :eventId"; - - private final Sql2o sql2o; - - @Autowired - public LootTrackerService(@Qualifier("Runelite SQL2O") Sql2o sql2o) - { - this.sql2o = sql2o; - - // Ensure necessary tables exist - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_KILLS).executeUpdate(); - con.createQuery(CREATE_DROPS).executeUpdate(); - } - } - - /** - * Store LootRecord - * - * @param records LootRecords to store - * @param accountId runelite account id to tie data too - */ - public void store(Collection records, int accountId) - { - try (Connection con = sql2o.beginTransaction()) - { - // Kill Entry Query - Query killQuery = con.createQuery(INSERT_KILL_QUERY, true); - - for (LootRecord record : records) - { - killQuery - .addParameter("accountId", accountId) - .addParameter("type", record.getType()) - .addParameter("eventId", record.getEventId()) - .addToBatch(); - } - - killQuery.executeBatch(); - Object[] keys = con.getKeys(); - - if (keys.length != records.size()) - { - throw new RuntimeException("Mismatch in keys vs records size"); - } - - Query insertDrop = con.createQuery(INSERT_DROP_QUERY); - - // Append all queries for inserting drops - int idx = 0; - for (LootRecord record : records) - { - for (GameItem drop : record.getDrops()) - { - insertDrop - .addParameter("killId", keys[idx]) - .addParameter("itemId", drop.getId()) - .addParameter("itemQuantity", drop.getQty()) - .addToBatch(); - } - - ++idx; - } - - insertDrop.executeBatch(); - con.commit(false); - } - } - - public Collection get(int accountId, int limit, int offset) - { - List lootResults; - - try (Connection con = sql2o.open()) - { - lootResults = con.createQuery(SELECT_LOOT_QUERY) - .addParameter("accountId", accountId) - .addParameter("limit", limit) - .addParameter("offset", offset) - .executeAndFetch(LootResult.class); - } - - LootResult current = null; - List lootRecords = new ArrayList<>(); - List gameItems = new ArrayList<>(); - - for (LootResult lootResult : lootResults) - { - if (current == null || current.getKillId() != lootResult.getKillId()) - { - if (!gameItems.isEmpty()) - { - LootRecord lootRecord = new LootRecord(current.getEventId(), current.getType(), gameItems, current.getTime()); - lootRecords.add(lootRecord); - - gameItems = new ArrayList<>(); - } - - current = lootResult; - } - - GameItem gameItem = new GameItem(lootResult.getItemId(), lootResult.getItemQuantity()); - gameItems.add(gameItem); - } - - if (!gameItems.isEmpty()) - { - LootRecord lootRecord = new LootRecord(current.getEventId(), current.getType(), gameItems, current.getTime()); - lootRecords.add(lootRecord); - } - - return lootRecords; - } - - public void delete(int accountId, String eventId) - { - try (Connection con = sql2o.open()) - { - if (eventId == null) - { - con.createQuery(DELETE_LOOT_ACCOUNT) - .addParameter("accountId", accountId) - .executeUpdate(); - } - else - { - con.createQuery(DELETE_LOOT_ACCOUNT_EVENTID) - .addParameter("accountId", accountId) - .addParameter("eventId", eventId) - .executeUpdate(); - } - } - } - - @Scheduled(fixedDelay = 15 * 60 * 1000) - public void expire() - { - try (Connection con = sql2o.open()) - { - con.createQuery("delete from kills where time < current_timestamp() - interval 30 day") - .executeUpdate(); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java deleted file mode 100644 index 8ea34c10c9..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/GrandExchangeEntry.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, AeonLucid - * 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.osbuddy; - -import java.time.Instant; -import lombok.Data; - -@Data -class GrandExchangeEntry -{ - private int item_id; - private int buy_average; - private int sell_average; - private int overall_average; - private Instant last_update; -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java deleted file mode 100644 index eaade27c12..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeController.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2018, AeonLucid - * 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.osbuddy; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.CacheControl; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/osb/ge") -public class OSBGrandExchangeController -{ - private final OSBGrandExchangeService grandExchangeService; - - @Autowired - public OSBGrandExchangeController(OSBGrandExchangeService grandExchangeService) - { - this.grandExchangeService = grandExchangeService; - } - - @GetMapping - public ResponseEntity get(@RequestParam("itemId") int itemId) throws ExecutionException - { - GrandExchangeEntry grandExchangeEntry = grandExchangeService.get(itemId); - - return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(30, TimeUnit.MINUTES).cachePublic()) - .body(grandExchangeEntry); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java deleted file mode 100644 index 49e9e4a636..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/OSBGrandExchangeService.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2018, AeonLucid - * 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.osbuddy; - -import java.io.IOException; -import java.sql.Timestamp; -import java.time.Instant; -import java.util.Map; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.service.osbuddy.beans.OsbuddySummaryItem; -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.Query; -import org.sql2o.Sql2o; - -@Service -@Slf4j -public class OSBGrandExchangeService -{ - private static final String CREATE_GRAND_EXCHANGE_PRICES = "CREATE TABLE IF NOT EXISTS `osb_ge` (\n" - + " `item_id` int(11) NOT NULL,\n" - + " `buy_average` int(11) NOT NULL,\n" - + " `sell_average` int(11) NOT NULL,\n" - + " `overall_average` int(11) NOT NULL,\n" - + " `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" - + " PRIMARY KEY (`item_id`)\n" - + ") ENGINE=InnoDB"; - - private static final OsbuddyClient CLIENT = new OsbuddyClient(); - - private final Sql2o sql2o; - - @Autowired - public OSBGrandExchangeService(@Qualifier("Runelite SQL2O") Sql2o sql2o) - { - this.sql2o = sql2o; - - try (Connection con = sql2o.open()) - { - con.createQuery(CREATE_GRAND_EXCHANGE_PRICES).executeUpdate(); - } - } - - public GrandExchangeEntry get(int itemId) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("SELECT item_id, buy_average, sell_average, overall_average, last_update" - + " FROM osb_ge WHERE item_id = :itemId") - .addParameter("itemId", itemId) - .executeAndFetchFirst(GrandExchangeEntry.class); - } - } - - @Scheduled(initialDelay = 1000 * 5, fixedDelay = 1000 * 60 * 30) - private void updateDatabase() - { - try - { - Map summary = CLIENT.getSummary(); - - try (Connection con = sql2o.beginTransaction()) - { - Instant updateTime = Instant.now(); - - Query query = con.createQuery("INSERT INTO osb_ge (item_id, buy_average, sell_average, overall_average," - + " last_update) VALUES (:itemId, :buyAverage, :sellAverage, :overallAverage, :lastUpdate)" - + " ON DUPLICATE KEY UPDATE buy_average = VALUES(buy_average), sell_average = VALUES(sell_average)," - + " overall_average = VALUES(overall_average), last_update = VALUES(last_update)"); - - for (Map.Entry entry : summary.entrySet()) - { - Integer itemId = entry.getKey(); - OsbuddySummaryItem item = entry.getValue(); - - if (item.getBuy_average() <= 0 || item.getSell_average() <= 0 || item.getOverall_average() <= 0) - { - continue; - } - - query - .addParameter("itemId", itemId) - .addParameter("buyAverage", item.getBuy_average()) - .addParameter("sellAverage", item.getSell_average()) - .addParameter("overallAverage", item.getOverall_average()) - .addParameter("lastUpdate", Timestamp.from(updateTime)) - .addToBatch(); - } - - query.executeBatch(); - con.commit(false); - } - } - catch (IOException e) - { - log.warn("Error while updating the osb grand exchange table", e); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java deleted file mode 100644 index e522301948..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/OsbuddyClient.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018, AeonLucid - * 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.osbuddy; - -import com.google.gson.JsonSyntaxException; -import com.google.gson.reflect.TypeToken; -import java.io.IOException; -import java.lang.reflect.Type; -import java.util.Map; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.service.osbuddy.beans.OsbuddySummaryItem; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; - -public class OsbuddyClient -{ - public Map getSummary() throws IOException - { - HttpUrl httpUrl = new HttpUrl.Builder() - .scheme("https") - .host("storage.googleapis.com") - .addPathSegment("osb-exchange") - .addPathSegment("summary.json") - .build(); - - Request request = new Request.Builder() - .url(httpUrl) - .header("User-Agent", "RuneLite") - .build(); - - try (Response responseOk = RuneLiteAPI.CLIENT.newCall(request).execute()) - { - if (!responseOk.isSuccessful()) - { - throw new IOException("Error retrieving summary from OSBuddy: " + responseOk.message()); - } - - Type type = new TypeToken>() {}.getType(); - - return RuneLiteAPI.GSON.fromJson(responseOk.body().string(), type); - } - catch (JsonSyntaxException ex) - { - throw new IOException(ex); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java b/http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java deleted file mode 100644 index 2f969d9636..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/osbuddy/beans/OsbuddySummaryItem.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, AeonLucid - * 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.osbuddy.beans; - -import lombok.Data; - -@Data -public class OsbuddySummaryItem -{ - private int id; - private String name; - private boolean members; - private int sp; - private int buy_average; - private int sell_average; - private int overall_average; -} diff --git a/http-service/src/main/java/net/runelite/http/service/sprite/SpriteController.java b/http-service/src/main/java/net/runelite/http/service/sprite/SpriteController.java deleted file mode 100644 index 5afc6299bc..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/sprite/SpriteController.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.sprite; - -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.cache.LoadingCache; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/sprite") -public class SpriteController -{ - @Autowired - private SpriteService spriteService; - - private final LoadingCache spriteCache = CacheBuilder.newBuilder() - .maximumSize(1024L) - .expireAfterWrite(10, TimeUnit.MINUTES) - .build(new CacheLoader() - { - @Override - public byte[] load(Integer key) throws Exception - { - byte[] data = spriteService.getImagePng(key >>> 16, key & 0xffff); - return data != null ? data : new byte[0]; - } - }); - - @GetMapping(produces = "image/png") - public ResponseEntity getSprite( - @RequestParam int spriteId, - @RequestParam(defaultValue = "0") int frameId - ) throws IOException - { - byte[] data = spriteCache.getUnchecked(spriteId << 16 | frameId); - if (data == null || data.length == 0) - { - return ResponseEntity.notFound().build(); - } - - return ResponseEntity.ok(data); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/sprite/SpriteService.java b/http-service/src/main/java/net/runelite/http/service/sprite/SpriteService.java deleted file mode 100644 index 659f1e03e2..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/sprite/SpriteService.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.sprite; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import javax.imageio.ImageIO; -import net.runelite.cache.IndexType; -import net.runelite.cache.definitions.SpriteDefinition; -import net.runelite.cache.definitions.loaders.SpriteLoader; -import net.runelite.cache.fs.ArchiveFiles; -import net.runelite.cache.fs.FSFile; -import net.runelite.http.service.cache.CacheService; -import net.runelite.http.service.cache.beans.ArchiveEntry; -import net.runelite.http.service.cache.beans.CacheEntry; -import net.runelite.http.service.cache.beans.IndexEntry; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class SpriteService -{ - @Autowired - private CacheService cacheService; - - public SpriteDefinition getSprite(int spriteId, int frameId) throws IOException - { - CacheEntry cache = cacheService.findMostRecent(); - if (cache == null) - { - return null; - } - - IndexEntry index = cacheService.findIndexForCache(cache, IndexType.SPRITES.getNumber()); - if (index == null) - { - return null; - } - - ArchiveEntry archive = cacheService.findArchiveForIndex(index, spriteId); - if (archive == null) - { - return null; - } - - ArchiveFiles files = cacheService.getArchiveFiles(archive); - if (files == null) - { - return null; - } - - FSFile file = files.getFiles().get(0); - byte[] contents = file.getContents(); - SpriteDefinition[] sprite = new SpriteLoader().load(archive.getArchiveId(), contents); - if (frameId < 0 || frameId >= sprite.length) - { - return null; - } - - return sprite[frameId]; - } - - public BufferedImage getImage(int spriteId, int frameId) throws IOException - { - SpriteDefinition sprite = getSprite(spriteId, frameId); - if (sprite == null) - { - return null; - } - - BufferedImage bufferedImage = getSpriteImage(sprite); - return bufferedImage; - } - - public byte[] getImagePng(int spriteId, int frameId) throws IOException - { - BufferedImage image = getImage(spriteId, frameId); - if (image == null) - { - return null; - } - - ByteArrayOutputStream bao = new ByteArrayOutputStream(); - ImageIO.write(image, "png", bao); - return bao.toByteArray(); - } - - private BufferedImage getSpriteImage(SpriteDefinition sprite) - { - BufferedImage image = new BufferedImage(sprite.getWidth(), sprite.getHeight(), BufferedImage.TYPE_INT_ARGB); - image.setRGB(0, 0, sprite.getWidth(), sprite.getHeight(), sprite.getPixels(), 0, sprite.getWidth()); - return image; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/util/HiscoreEndpointEditor.java b/http-service/src/main/java/net/runelite/http/service/util/HiscoreEndpointEditor.java deleted file mode 100644 index bbc84f573a..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/util/HiscoreEndpointEditor.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.util; - -import java.beans.PropertyEditorSupport; -import net.runelite.http.api.hiscore.HiscoreEndpoint; - -public class HiscoreEndpointEditor extends PropertyEditorSupport -{ - @Override - public void setAsText(String text) throws IllegalArgumentException - { - setValue(HiscoreEndpoint.valueOf(text.toUpperCase())); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/util/InstantConverter.java b/http-service/src/main/java/net/runelite/http/service/util/InstantConverter.java deleted file mode 100644 index 785ad00266..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/util/InstantConverter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.util; - -import java.sql.Timestamp; -import java.time.Instant; -import org.sql2o.converters.Converter; -import org.sql2o.converters.ConverterException; - -public class InstantConverter implements Converter -{ - @Override - public Instant convert(Object val) throws ConverterException - { - Timestamp ts = (Timestamp) val; - return ts.toInstant(); - } - - @Override - public Object toDatabaseParam(Instant val) - { - return Timestamp.from(val); - } - -} diff --git a/http-service/src/main/java/net/runelite/http/service/util/exception/InternalServerErrorException.java b/http-service/src/main/java/net/runelite/http/service/util/exception/InternalServerErrorException.java deleted file mode 100644 index 62adc5b6fc..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/util/exception/InternalServerErrorException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.util.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) -public class InternalServerErrorException extends RuntimeException -{ - public InternalServerErrorException(String message) - { - super(message); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/util/exception/NotFoundException.java b/http-service/src/main/java/net/runelite/http/service/util/exception/NotFoundException.java deleted file mode 100644 index c7d01175ef..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/util/exception/NotFoundException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.util.exception; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Not found") -public class NotFoundException extends RuntimeException {} diff --git a/http-service/src/main/java/net/runelite/http/service/util/redis/RedisPool.java b/http-service/src/main/java/net/runelite/http/service/util/redis/RedisPool.java deleted file mode 100644 index a69232ed55..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/util/redis/RedisPool.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.util.redis; - -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import redis.clients.jedis.Jedis; - -@Component -public class RedisPool -{ - private final BlockingQueue queue; - - RedisPool(@Value("${redis.pool.size:10}") int queueSize, @Value("${redis.host:localhost}") String redisHost) - { - queue = new ArrayBlockingQueue<>(queueSize); - for (int i = 0; i < queueSize; ++i) - { - Jedis jedis = new PooledJedis(redisHost); - queue.offer(jedis); - } - } - - public Jedis getResource() - { - Jedis jedis; - try - { - jedis = queue.poll(1, TimeUnit.SECONDS); - } - catch (InterruptedException e) - { - throw new RuntimeException(e); - } - if (jedis == null) - { - throw new RuntimeException("Unable to acquire connection from pool, timeout"); - } - return jedis; - } - - class PooledJedis extends Jedis - { - PooledJedis(String host) - { - super(host); - } - - @Override - public void close() - { - queue.offer(this); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/worlds/ServiceWorldType.java b/http-service/src/main/java/net/runelite/http/service/worlds/ServiceWorldType.java deleted file mode 100644 index 896f152752..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/worlds/ServiceWorldType.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Lotto - * 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.worlds; - -import net.runelite.http.api.worlds.WorldType; - -enum ServiceWorldType -{ - MEMBERS(WorldType.MEMBERS, 1), - PVP(WorldType.PVP, 1 << 2), - BOUNTY(WorldType.BOUNTY, 1 << 5), - SKILL_TOTAL(WorldType.SKILL_TOTAL, 1 << 7), - HIGH_RISK(WorldType.HIGH_RISK, 1 << 10), - LAST_MAN_STANDING(WorldType.LAST_MAN_STANDING, 1 << 14), - TOURNAMENT(WorldType.TOURNAMENT, 1 << 25), - DEADMAN(WorldType.DEADMAN, 1 << 29), - LEAGUE(WorldType.LEAGUE, 1 << 30); - - private final WorldType apiType; - private final int mask; - - ServiceWorldType(WorldType apiType, int mask) - { - this.apiType = apiType; - this.mask = mask; - } - - public WorldType getApiType() - { - return apiType; - } - - public int getMask() - { - return mask; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java b/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java deleted file mode 100644 index 537e252b96..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/worlds/WorldController.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.worlds; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import net.runelite.http.api.worlds.WorldResult; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.CacheControl; -import org.springframework.http.ResponseEntity; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/worlds") -public class WorldController -{ - @Autowired - private WorldsService worldsService; - - private WorldResult worldResult; - - @GetMapping - public ResponseEntity listWorlds() throws IOException - { - return ResponseEntity.ok() - .cacheControl(CacheControl.maxAge(10, TimeUnit.MINUTES).cachePublic()) - .body(worldResult); - } - - @Scheduled(fixedDelay = 60_000L) - public void refreshWorlds() throws IOException - { - worldResult = worldsService.getWorlds(); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java b/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java deleted file mode 100644 index a3bd010430..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/worlds/WorldsService.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.worlds; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.worlds.World; -import net.runelite.http.api.worlds.WorldResult; -import net.runelite.http.api.worlds.WorldType; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -import org.springframework.stereotype.Service; - -@Service -public class WorldsService -{ - private static final HttpUrl WORLD_URL = HttpUrl.parse("http://www.runescape.com/g=oldscape/slr.ws?order=LPWM"); - - private HttpUrl url = WORLD_URL; - - public WorldResult getWorlds() throws IOException - { - Request okrequest = new Request.Builder() - .url(url) - .build(); - - byte[] b; - - try (Response okresponse = RuneLiteAPI.CLIENT.newCall(okrequest).execute()) - { - b = okresponse.body().bytes(); - } - - List worlds = new ArrayList<>(); - ByteBuffer buf = ByteBuffer.wrap(b); - - int length = buf.getInt(); - buf.limit(length + 4); - - int num = buf.getShort() & 0xFFFF; - - for (int i = 0; i < num; ++i) - { - final World.WorldBuilder worldBuilder = World.builder() - .id(buf.getShort() & 0xFFFF) - .types(getTypes(buf.getInt())) - .address(readString(buf)) - .activity(readString(buf)) - .location(buf.get() & 0xFF) - .players(buf.getShort() & 0xFFFF); - - worlds.add(worldBuilder.build()); - } - - WorldResult result = new WorldResult(); - result.setWorlds(worlds); - return result; - } - - private static EnumSet getTypes(int mask) - { - EnumSet types = EnumSet.noneOf(WorldType.class); - - for (ServiceWorldType type : ServiceWorldType.values()) - { - if ((mask & type.getMask()) != 0) - { - types.add(type.getApiType()); - } - } - - return types; - } - - private static String readString(ByteBuffer buf) - { - byte b; - StringBuilder sb = new StringBuilder(); - - for (;;) - { - b = buf.get(); - - if (b == 0) - { - break; - } - - sb.append((char) b); - } - - return sb.toString(); - } - - public HttpUrl getUrl() - { - return url; - } - - public void setUrl(HttpUrl url) - { - this.url = url; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/xp/XpMapper.java b/http-service/src/main/java/net/runelite/http/service/xp/XpMapper.java deleted file mode 100644 index 068c6e5438..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xp/XpMapper.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xp; - -import net.runelite.http.api.hiscore.HiscoreResult; -import net.runelite.http.api.xp.XpData; -import net.runelite.http.service.xp.beans.XpEntity; -import org.mapstruct.Mapper; -import org.mapstruct.Mapping; -import org.mapstruct.factory.Mappers; - -@Mapper -public interface XpMapper -{ - XpMapper INSTANCE = Mappers.getMapper(XpMapper.class); - - XpData xpEntityToXpData(XpEntity xpEntity); - - @Mapping(target = "time", ignore = true) - - @Mapping(source = "attack.experience", target = "attack_xp") - @Mapping(source = "defence.experience", target = "defence_xp") - @Mapping(source = "strength.experience", target = "strength_xp") - @Mapping(source = "hitpoints.experience", target = "hitpoints_xp") - @Mapping(source = "ranged.experience", target = "ranged_xp") - @Mapping(source = "prayer.experience", target = "prayer_xp") - @Mapping(source = "magic.experience", target = "magic_xp") - @Mapping(source = "cooking.experience", target = "cooking_xp") - @Mapping(source = "woodcutting.experience", target = "woodcutting_xp") - @Mapping(source = "fletching.experience", target = "fletching_xp") - @Mapping(source = "fishing.experience", target = "fishing_xp") - @Mapping(source = "firemaking.experience", target = "firemaking_xp") - @Mapping(source = "crafting.experience", target = "crafting_xp") - @Mapping(source = "smithing.experience", target = "smithing_xp") - @Mapping(source = "mining.experience", target = "mining_xp") - @Mapping(source = "herblore.experience", target = "herblore_xp") - @Mapping(source = "agility.experience", target = "agility_xp") - @Mapping(source = "thieving.experience", target = "thieving_xp") - @Mapping(source = "slayer.experience", target = "slayer_xp") - @Mapping(source = "farming.experience", target = "farming_xp") - @Mapping(source = "runecraft.experience", target = "runecraft_xp") - @Mapping(source = "hunter.experience", target = "hunter_xp") - @Mapping(source = "construction.experience", target = "construction_xp") - - @Mapping(source = "overall.rank", target = "overall_rank") - @Mapping(source = "attack.rank", target = "attack_rank") - @Mapping(source = "defence.rank", target = "defence_rank") - @Mapping(source = "strength.rank", target = "strength_rank") - @Mapping(source = "hitpoints.rank", target = "hitpoints_rank") - @Mapping(source = "ranged.rank", target = "ranged_rank") - @Mapping(source = "prayer.rank", target = "prayer_rank") - @Mapping(source = "magic.rank", target = "magic_rank") - @Mapping(source = "cooking.rank", target = "cooking_rank") - @Mapping(source = "woodcutting.rank", target = "woodcutting_rank") - @Mapping(source = "fletching.rank", target = "fletching_rank") - @Mapping(source = "fishing.rank", target = "fishing_rank") - @Mapping(source = "firemaking.rank", target = "firemaking_rank") - @Mapping(source = "crafting.rank", target = "crafting_rank") - @Mapping(source = "smithing.rank", target = "smithing_rank") - @Mapping(source = "mining.rank", target = "mining_rank") - @Mapping(source = "herblore.rank", target = "herblore_rank") - @Mapping(source = "agility.rank", target = "agility_rank") - @Mapping(source = "thieving.rank", target = "thieving_rank") - @Mapping(source = "slayer.rank", target = "slayer_rank") - @Mapping(source = "farming.rank", target = "farming_rank") - @Mapping(source = "runecraft.rank", target = "runecraft_rank") - @Mapping(source = "hunter.rank", target = "hunter_rank") - @Mapping(source = "construction.rank", target = "construction_rank") - XpData hiscoreResultToXpData(HiscoreResult hiscoreResult); -} diff --git a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java b/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java deleted file mode 100644 index d247d735a4..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xp; - -import java.time.Instant; -import net.runelite.http.api.xp.XpData; -import net.runelite.http.service.xp.beans.XpEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/xp") -public class XpTrackerController -{ - @Autowired - private XpTrackerService xpTrackerService; - - @GetMapping("/update") - public void update(@RequestParam String username) - { - xpTrackerService.tryUpdate(username); - } - - @GetMapping("/get") - public XpData get(@RequestParam String username, @RequestParam(required = false) Instant time) - { - if (time == null) - { - time = Instant.now(); - } - XpEntity xpEntity = xpTrackerService.findXpAtTime(username, time); - return XpMapper.INSTANCE.xpEntityToXpData(xpEntity); - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java b/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java deleted file mode 100644 index 9e8e0a5e06..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xp; - -import com.google.common.hash.BloomFilter; -import com.google.common.hash.Funnels; -import java.nio.charset.Charset; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayDeque; -import java.util.Queue; -import java.util.concurrent.ExecutionException; -import lombok.extern.slf4j.Slf4j; -import net.runelite.http.api.hiscore.HiscoreEndpoint; -import net.runelite.http.api.hiscore.HiscoreResult; -import net.runelite.http.api.xp.XpData; -import net.runelite.http.service.hiscore.HiscoreService; -import net.runelite.http.service.xp.beans.PlayerEntity; -import net.runelite.http.service.xp.beans.XpEntity; -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 -@Slf4j -public class XpTrackerService -{ - private static final int QUEUE_LIMIT = 32768; - private static final int BLOOMFILTER_EXPECTED_INSERTIONS = 100_000; - - @Autowired - @Qualifier("Runelite XP Tracker SQL2O") - private Sql2o sql2o; - - @Autowired - private HiscoreService hiscoreService; - - private final Queue usernameUpdateQueue = new ArrayDeque<>(); - private BloomFilter usernameFilter = createFilter(); - - public void update(String username) throws ExecutionException - { - HiscoreResult hiscoreResult = hiscoreService.lookupUsername(username, HiscoreEndpoint.NORMAL); - update(username, hiscoreResult); - } - - public void tryUpdate(String username) - { - if (usernameFilter.mightContain(username)) - { - return; - } - - try (Connection con = sql2o.open()) - { - PlayerEntity playerEntity = findOrCreatePlayer(con, username); - Duration frequency = updateFrequency(playerEntity); - Instant now = Instant.now(); - Duration timeSinceLastUpdate = Duration.between(playerEntity.getLast_updated(), now); - if (timeSinceLastUpdate.toMillis() < frequency.toMillis()) - { - log.debug("User {} updated too recently", username); - usernameFilter.put(username); - return; - } - - synchronized (usernameUpdateQueue) - { - if (usernameUpdateQueue.size() >= QUEUE_LIMIT) - { - log.warn("Username update queue is full ({})", QUEUE_LIMIT); - return; - } - - usernameUpdateQueue.add(username); - } - } - - usernameFilter.put(username); - } - - public void update(String username, HiscoreResult hiscoreResult) - { - try (Connection con = sql2o.open()) - { - PlayerEntity playerEntity = findOrCreatePlayer(con, username); - - Instant now = Instant.now(); - XpEntity currentXp = findXpAtTime(con, username, now); - if (currentXp != null) - { - XpData hiscoreData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult); - XpData existingData = XpMapper.INSTANCE.xpEntityToXpData(currentXp); - - if (hiscoreData.equals(existingData)) - { - log.debug("Hiscore for {} already up to date", username); - return; - } - } - - con.createQuery("insert into xp (player,attack_xp,defence_xp,strength_xp,hitpoints_xp,ranged_xp,prayer_xp,magic_xp,cooking_xp,woodcutting_xp," - + "fletching_xp,fishing_xp,firemaking_xp,crafting_xp,smithing_xp,mining_xp,herblore_xp,agility_xp,thieving_xp,slayer_xp,farming_xp," - + "runecraft_xp,hunter_xp,construction_xp,attack_rank,defence_rank,strength_rank,hitpoints_rank,ranged_rank,prayer_rank,magic_rank," - + "cooking_rank,woodcutting_rank,fletching_rank,fishing_rank,firemaking_rank,crafting_rank,smithing_rank,mining_rank,herblore_rank," - + "agility_rank,thieving_rank,slayer_rank,farming_rank,runecraft_rank,hunter_rank,construction_rank,overall_rank) values (:player,:attack_xp,:defence_xp," - + ":strength_xp,:hitpoints_xp,:ranged_xp,:prayer_xp,:magic_xp,:cooking_xp,:woodcutting_xp,:fletching_xp,:fishing_xp,:firemaking_xp," - + ":crafting_xp,:smithing_xp,:mining_xp,:herblore_xp,:agility_xp,:thieving_xp,:slayer_xp,:farming_xp,:runecraft_xp,:hunter_xp," - + ":construction_xp,:attack_rank,:defence_rank,:strength_rank,:hitpoints_rank,:ranged_rank,:prayer_rank,:magic_rank,:cooking_rank," - + ":woodcutting_rank,:fletching_rank,:fishing_rank,:firemaking_rank,:crafting_rank,:smithing_rank,:mining_rank,:herblore_rank," - + ":agility_rank,:thieving_rank,:slayer_rank,:farming_rank,:runecraft_rank,:hunter_rank,:construction_rank,:overall_rank)") - .addParameter("player", playerEntity.getId()) - .addParameter("attack_xp", hiscoreResult.getAttack().getExperience()) - .addParameter("defence_xp", hiscoreResult.getDefence().getExperience()) - .addParameter("strength_xp", hiscoreResult.getStrength().getExperience()) - .addParameter("hitpoints_xp", hiscoreResult.getHitpoints().getExperience()) - .addParameter("ranged_xp", hiscoreResult.getRanged().getExperience()) - .addParameter("prayer_xp", hiscoreResult.getPrayer().getExperience()) - .addParameter("magic_xp", hiscoreResult.getMagic().getExperience()) - .addParameter("cooking_xp", hiscoreResult.getCooking().getExperience()) - .addParameter("woodcutting_xp", hiscoreResult.getWoodcutting().getExperience()) - .addParameter("fletching_xp", hiscoreResult.getFletching().getExperience()) - .addParameter("fishing_xp", hiscoreResult.getFishing().getExperience()) - .addParameter("firemaking_xp", hiscoreResult.getFiremaking().getExperience()) - .addParameter("crafting_xp", hiscoreResult.getCrafting().getExperience()) - .addParameter("smithing_xp", hiscoreResult.getSmithing().getExperience()) - .addParameter("mining_xp", hiscoreResult.getMining().getExperience()) - .addParameter("herblore_xp", hiscoreResult.getHerblore().getExperience()) - .addParameter("agility_xp", hiscoreResult.getAgility().getExperience()) - .addParameter("thieving_xp", hiscoreResult.getThieving().getExperience()) - .addParameter("slayer_xp", hiscoreResult.getSlayer().getExperience()) - .addParameter("farming_xp", hiscoreResult.getFarming().getExperience()) - .addParameter("runecraft_xp", hiscoreResult.getRunecraft().getExperience()) - .addParameter("hunter_xp", hiscoreResult.getHunter().getExperience()) - .addParameter("construction_xp", hiscoreResult.getConstruction().getExperience()) - .addParameter("attack_rank", hiscoreResult.getAttack().getRank()) - .addParameter("defence_rank", hiscoreResult.getDefence().getRank()) - .addParameter("strength_rank", hiscoreResult.getStrength().getRank()) - .addParameter("hitpoints_rank", hiscoreResult.getHitpoints().getRank()) - .addParameter("ranged_rank", hiscoreResult.getRanged().getRank()) - .addParameter("prayer_rank", hiscoreResult.getPrayer().getRank()) - .addParameter("magic_rank", hiscoreResult.getMagic().getRank()) - .addParameter("cooking_rank", hiscoreResult.getCooking().getRank()) - .addParameter("woodcutting_rank", hiscoreResult.getWoodcutting().getRank()) - .addParameter("fletching_rank", hiscoreResult.getFletching().getRank()) - .addParameter("fishing_rank", hiscoreResult.getFishing().getRank()) - .addParameter("firemaking_rank", hiscoreResult.getFiremaking().getRank()) - .addParameter("crafting_rank", hiscoreResult.getCrafting().getRank()) - .addParameter("smithing_rank", hiscoreResult.getSmithing().getRank()) - .addParameter("mining_rank", hiscoreResult.getMining().getRank()) - .addParameter("herblore_rank", hiscoreResult.getHerblore().getRank()) - .addParameter("agility_rank", hiscoreResult.getAgility().getRank()) - .addParameter("thieving_rank", hiscoreResult.getThieving().getRank()) - .addParameter("slayer_rank", hiscoreResult.getSlayer().getRank()) - .addParameter("farming_rank", hiscoreResult.getFarming().getRank()) - .addParameter("runecraft_rank", hiscoreResult.getRunecraft().getRank()) - .addParameter("hunter_rank", hiscoreResult.getHunter().getRank()) - .addParameter("construction_rank", hiscoreResult.getConstruction().getRank()) - .addParameter("overall_rank", hiscoreResult.getOverall().getRank()) - .executeUpdate(); - - con.createQuery("update player set rank = :rank, last_updated = CURRENT_TIMESTAMP where id = :id") - .addParameter("id", playerEntity.getId()) - .addParameter("rank", hiscoreResult.getOverall().getRank()) - .executeUpdate(); - } - } - - private synchronized PlayerEntity findOrCreatePlayer(Connection con, String username) - { - PlayerEntity playerEntity = con.createQuery("select * from player where name = :name") - .addParameter("name", username) - .executeAndFetchFirst(PlayerEntity.class); - if (playerEntity != null) - { - return playerEntity; - } - - Instant now = Instant.now(); - - int id = con.createQuery("insert into player (name, tracked_since) values (:name, :tracked_since)") - .addParameter("name", username) - .addParameter("tracked_since", now) - .executeUpdate() - .getKey(int.class); - - playerEntity = new PlayerEntity(); - playerEntity.setId(id); - playerEntity.setName(username); - playerEntity.setTracked_since(now); - playerEntity.setLast_updated(now); - return playerEntity; - } - - private XpEntity findXpAtTime(Connection con, String username, Instant time) - { - return con.createQuery("select * from xp join player on player.id=xp.player where player.name = :username and time <= :time order by time desc limit 1") - .throwOnMappingFailure(false) - .addParameter("username", username) - .addParameter("time", time) - .executeAndFetchFirst(XpEntity.class); - } - - public XpEntity findXpAtTime(String username, Instant time) - { - try (Connection con = sql2o.open()) - { - return findXpAtTime(con, username, time); - } - } - - @Scheduled(fixedDelay = 1000) - public void update() throws ExecutionException - { - String next; - synchronized (usernameUpdateQueue) - { - next = usernameUpdateQueue.poll(); - } - - if (next == null) - { - return; - } - - update(next); - } - - @Scheduled(fixedDelay = 6 * 60 * 60 * 1000) // 6 hours - public void clearFilter() - { - usernameFilter = createFilter(); - } - - private BloomFilter createFilter() - { - final BloomFilter filter = BloomFilter.create( - Funnels.stringFunnel(Charset.defaultCharset()), - BLOOMFILTER_EXPECTED_INSERTIONS - ); - - synchronized (usernameUpdateQueue) - { - for (String toUpdate : usernameUpdateQueue) - { - filter.put(toUpdate); - } - } - - return filter; - } - - /** - * scale how often to check hiscore updates for players based on their rank - * @param playerEntity - * @return - */ - private static Duration updateFrequency(PlayerEntity playerEntity) - { - Integer rank = playerEntity.getRank(); - if (rank == null || rank == -1) - { - return Duration.ofDays(7); - } - else if (rank < 10_000) - { - return Duration.ofHours(6); - } - else if (rank < 50_000) - { - return Duration.ofDays(2); - } - else if (rank < 100_000) - { - return Duration.ofDays(5); - } - else - { - return Duration.ofDays(7); - } - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/xp/beans/PlayerEntity.java b/http-service/src/main/java/net/runelite/http/service/xp/beans/PlayerEntity.java deleted file mode 100644 index 11bec532d7..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xp/beans/PlayerEntity.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xp.beans; - -import java.time.Instant; -import lombok.Data; - -@Data -public class PlayerEntity -{ - private Integer id; - private String name; - private Instant tracked_since; - private Instant last_updated; - private Integer rank; -} diff --git a/http-service/src/main/java/net/runelite/http/service/xp/beans/XpEntity.java b/http-service/src/main/java/net/runelite/http/service/xp/beans/XpEntity.java deleted file mode 100644 index acab775873..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xp/beans/XpEntity.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xp.beans; - -import java.time.Instant; -import lombok.Data; - -@Data -public class XpEntity -{ - private Integer id; - private Instant time; - private Integer player; - private int overall_xp; - private int attack_xp; - private int defence_xp; - private int strength_xp; - private int hitpoints_xp; - private int ranged_xp; - private int prayer_xp; - private int magic_xp; - private int cooking_xp; - private int woodcutting_xp; - private int fletching_xp; - private int fishing_xp; - private int firemaking_xp; - private int crafting_xp; - private int smithing_xp; - private int mining_xp; - private int herblore_xp; - private int agility_xp; - private int thieving_xp; - private int slayer_xp; - private int farming_xp; - private int runecraft_xp; - private int hunter_xp; - private int construction_xp; - - private int overall_rank; - private int attack_rank; - private int defence_rank; - private int strength_rank; - private int hitpoints_rank; - private int ranged_rank; - private int prayer_rank; - private int magic_rank; - private int cooking_rank; - private int woodcutting_rank; - private int fletching_rank; - private int fishing_rank; - private int firemaking_rank; - private int crafting_rank; - private int smithing_rank; - private int mining_rank; - private int herblore_rank; - private int agility_rank; - private int thieving_rank; - private int slayer_rank; - private int farming_rank; - private int runecraft_rank; - private int hunter_rank; - private int construction_rank; -} diff --git a/http-service/src/main/java/net/runelite/http/service/xtea/XteaCache.java b/http-service/src/main/java/net/runelite/http/service/xtea/XteaCache.java deleted file mode 100644 index 7c5f2bb5b0..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xtea/XteaCache.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xtea; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -class XteaCache -{ - private int region; - private int key1; - private int key2; - private int key3; - private int key4; -} diff --git a/http-service/src/main/java/net/runelite/http/service/xtea/XteaController.java b/http-service/src/main/java/net/runelite/http/service/xtea/XteaController.java deleted file mode 100644 index 3868acb8c6..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xtea/XteaController.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xtea; - -import java.util.List; -import java.util.stream.Collectors; -import net.runelite.http.api.xtea.XteaKey; -import net.runelite.http.api.xtea.XteaRequest; -import net.runelite.http.service.util.exception.NotFoundException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import static org.springframework.web.bind.annotation.RequestMethod.POST; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/xtea") -public class XteaController -{ - @Autowired - private XteaService xteaService; - - @RequestMapping(method = POST) - public void submit(@RequestBody XteaRequest xteaRequest) - { - xteaService.submit(xteaRequest); - } - - @GetMapping - public List get() - { - return xteaService.get().stream() - .map(XteaController::entryToKey) - .collect(Collectors.toList()); - } - - @GetMapping("/{region}") - public XteaKey getRegion(@PathVariable int region) - { - XteaEntry xteaRegion = xteaService.getRegion(region); - if (xteaRegion == null) - { - throw new NotFoundException(); - } - - return entryToKey(xteaRegion); - } - - private static XteaKey entryToKey(XteaEntry xe) - { - XteaKey xteaKey = new XteaKey(); - xteaKey.setRegion(xe.getRegion()); - xteaKey.setKeys(new int[] - { - xe.getKey1(), - xe.getKey2(), - xe.getKey3(), - xe.getKey4() - }); - return xteaKey; - } -} diff --git a/http-service/src/main/java/net/runelite/http/service/xtea/XteaEntry.java b/http-service/src/main/java/net/runelite/http/service/xtea/XteaEntry.java deleted file mode 100644 index e1e86d0bf7..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xtea/XteaEntry.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.xtea; - -import java.time.Instant; - -public class XteaEntry -{ - private int region; - private Instant time; - private int rev; - private int key1; - private int key2; - private int key3; - private int key4; - - public int getRegion() - { - return region; - } - - public void setRegion(int region) - { - this.region = region; - } - - public Instant getTime() - { - return time; - } - - public void setTime(Instant time) - { - this.time = time; - } - - public int getRev() - { - return rev; - } - - public void setRev(int rev) - { - this.rev = rev; - } - - public int getKey1() - { - return key1; - } - - public void setKey1(int key1) - { - this.key1 = key1; - } - - public int getKey2() - { - return key2; - } - - public void setKey2(int key2) - { - this.key2 = key2; - } - - public int getKey3() - { - return key3; - } - - public void setKey3(int key3) - { - this.key3 = key3; - } - - public int getKey4() - { - return key4; - } - - public void setKey4(int key4) - { - this.key4 = key4; - } - -} diff --git a/http-service/src/main/java/net/runelite/http/service/xtea/XteaService.java b/http-service/src/main/java/net/runelite/http/service/xtea/XteaService.java deleted file mode 100644 index 61650b4e51..0000000000 --- a/http-service/src/main/java/net/runelite/http/service/xtea/XteaService.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.xtea; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import java.io.IOException; -import java.util.List; -import net.runelite.cache.IndexType; -import net.runelite.cache.fs.Container; -import net.runelite.cache.util.Djb2; -import net.runelite.http.api.xtea.XteaKey; -import net.runelite.http.api.xtea.XteaRequest; -import net.runelite.http.service.cache.CacheService; -import net.runelite.http.service.cache.beans.ArchiveEntry; -import net.runelite.http.service.cache.beans.CacheEntry; -import net.runelite.http.service.util.exception.InternalServerErrorException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.sql2o.Connection; -import org.sql2o.Query; -import org.sql2o.Sql2o; - -@Service -public class XteaService -{ - private static final String CREATE_SQL = "CREATE TABLE IF NOT EXISTS `xtea` (\n" - + " `id` int(11) NOT NULL AUTO_INCREMENT,\n" - + " `region` int(11) NOT NULL,\n" - + " `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" - + " `rev` int(11) NOT NULL,\n" - + " `key1` int(11) NOT NULL,\n" - + " `key2` int(11) NOT NULL,\n" - + " `key3` int(11) NOT NULL,\n" - + " `key4` int(11) NOT NULL,\n" - + " PRIMARY KEY (`id`),\n" - + " KEY `region` (`region`,`time`)\n" - + ") ENGINE=InnoDB"; - - private final Sql2o sql2o; - private final CacheService cacheService; - - private final Cache keyCache = CacheBuilder.newBuilder() - .maximumSize(1024) - .build(); - - @Autowired - public XteaService( - @Qualifier("Runelite SQL2O") Sql2o sql2o, - CacheService cacheService - ) - { - this.sql2o = sql2o; - this.cacheService = cacheService; - - try (Connection con = sql2o.beginTransaction()) - { - con.createQuery(CREATE_SQL) - .executeUpdate(); - } - } - - private XteaEntry findLatestXtea(Connection con, int region) - { - return con.createQuery("select region, time, key1, key2, key3, key4 from xtea " - + "where region = :region " - + "order by time desc " - + "limit 1") - .addParameter("region", region) - .executeAndFetchFirst(XteaEntry.class); - } - - public void submit(XteaRequest xteaRequest) - { - boolean cached = true; - for (XteaKey key : xteaRequest.getKeys()) - { - int region = key.getRegion(); - int[] keys = key.getKeys(); - - XteaCache xteaCache = keyCache.getIfPresent(region); - if (xteaCache == null - || xteaCache.getKey1() != keys[0] - || xteaCache.getKey2() != keys[1] - || xteaCache.getKey3() != keys[2] - || xteaCache.getKey4() != keys[3]) - { - cached = false; - keyCache.put(region, new XteaCache(region, keys[0], keys[1], keys[2], keys[3])); - } - } - - if (cached) - { - return; - } - - try (Connection con = sql2o.beginTransaction()) - { - CacheEntry cache = cacheService.findMostRecent(); - - if (cache == null) - { - throw new InternalServerErrorException("No most recent cache"); - } - - Query query = null; - - for (XteaKey key : xteaRequest.getKeys()) - { - int region = key.getRegion(); - int[] keys = key.getKeys(); - - XteaEntry xteaEntry = findLatestXtea(con, region); - - if (keys.length != 4) - { - throw new IllegalArgumentException("Key length must be 4"); - } - - // already have these? - if (xteaEntry != null - && xteaEntry.getKey1() == keys[0] - && xteaEntry.getKey2() == keys[1] - && xteaEntry.getKey3() == keys[2] - && xteaEntry.getKey4() == keys[3]) - { - continue; - } - - if (!checkKeys(cache, region, keys)) - { - continue; - } - - if (query == null) - { - query = con.createQuery("insert into xtea (region, rev, key1, key2, key3, key4) " - + "values (:region, :rev, :key1, :key2, :key3, :key4)"); - } - - query.addParameter("region", region) - .addParameter("rev", xteaRequest.getRevision()) - .addParameter("key1", keys[0]) - .addParameter("key2", keys[1]) - .addParameter("key3", keys[2]) - .addParameter("key4", keys[3]) - .addToBatch(); - } - - if (query != null) - { - query.executeBatch(); - con.commit(false); - } - } - } - - public List get() - { - try (Connection con = sql2o.open()) - { - return con.createQuery( - "select t1.region, t2.time, t2.rev, t2.key1, t2.key2, t2.key3, t2.key4 from " + - "(select region,max(id) as id from xtea group by region) t1 " + - "join xtea t2 on t1.id = t2.id") - .executeAndFetch(XteaEntry.class); - } - } - - public XteaEntry getRegion(int region) - { - try (Connection con = sql2o.open()) - { - return con.createQuery("select region, time, rev, key1, key2, key3, key4 from xtea " - + "where region = :region order by time desc limit 1") - .addParameter("region", region) - .executeAndFetchFirst(XteaEntry.class); - } - } - - private boolean checkKeys(CacheEntry cache, int regionId, int[] keys) - { - int x = regionId >>> 8; - int y = regionId & 0xFF; - - String archiveName = new StringBuilder() - .append('l') - .append(x) - .append('_') - .append(y) - .toString(); - int archiveNameHash = Djb2.hash(archiveName); - - ArchiveEntry archiveEntry = cacheService.findArchiveForTypeAndName(cache, IndexType.MAPS, archiveNameHash); - if (archiveEntry == null) - { - throw new InternalServerErrorException("Unable to find archive for region"); - } - - byte[] data = cacheService.getArchive(archiveEntry); - if (data == null) - { - throw new InternalServerErrorException("Unable to get archive data"); - } - - try - { - Container.decompress(data, keys); - return true; - } - catch (IOException ex) - { - return false; - } - } -} diff --git a/http-service/src/main/resources/application-dev.yaml b/http-service/src/main/resources/application-dev.yaml deleted file mode 100644 index 9397951858..0000000000 --- a/http-service/src/main/resources/application-dev.yaml +++ /dev/null @@ -1,36 +0,0 @@ -# Enable debug logging -debug: true -logging.level.net.runelite: DEBUG - -# Development data sources -datasource: - runelite: - jndiName: - driverClassName: org.mariadb.jdbc.Driver - type: org.mariadb.jdbc.MariaDbDataSource - url: jdbc:mariadb://localhost:3306/runelite - username: runelite - password: runelite - runelite-cache: - jndiName: - driverClassName: org.mariadb.jdbc.Driver - type: org.mariadb.jdbc.MariaDbDataSource - url: jdbc:mariadb://localhost:3306/cache - username: runelite - password: runelite - runelite-tracker: - jndiName: - driverClassName: org.mariadb.jdbc.Driver - type: org.mariadb.jdbc.MariaDbDataSource - url: jdbc:mariadb://localhost:3306/xptracker - username: runelite - password: runelite - -# Development mongo -mongo: - jndiName: - host: mongodb://localhost:27017 - -# Development oauth callback (without proxy) -oauth: - callback: http://localhost:8080/account/callback diff --git a/http-service/src/main/resources/application.yaml b/http-service/src/main/resources/application.yaml deleted file mode 100644 index f5e1a799d9..0000000000 --- a/http-service/src/main/resources/application.yaml +++ /dev/null @@ -1,42 +0,0 @@ -datasource: - runelite: - jndiName: java:comp/env/jdbc/runelite - runelite-cache: - jndiName: java:comp/env/jdbc/runelite-cache2 - runelite-tracker: - jndiName: java:comp/env/jdbc/runelite-tracker - -# By default Spring tries to register the datasource as an MXBean, -# so if multiple apis are deployed on one web container with -# shared datasource it tries to register it multiples times and -# fails when starting the 2nd api -spring.jmx.enabled: false - -# Google OAuth client -oauth: - client-id: - client-secret: - callback: https://api.runelite.net/oauth/ - -# Minio client storage for cache -minio: - endpoint: http://localhost:9000 - accesskey: AM54M27O4WZK65N6F8IP - secretkey: /PZCxzmsJzwCHYlogcymuprniGCaaLUOET2n6yMP - bucket: runelite - -# Redis client for temporary data storage -redis: - pool.size: 10 - host: http://localhost:6379 - -mongo: - jndiName: java:comp/env/mongodb/runelite - database: runelite - -# Twitter client for feed -runelite: - twitter: - consumerkey: - secretkey: - listid: 1185897074786742273 \ No newline at end of file diff --git a/http-service/src/main/resources/net/runelite/http/service/xp/schema.sql b/http-service/src/main/resources/net/runelite/http/service/xp/schema.sql deleted file mode 100644 index 70f83a30fd..0000000000 --- a/http-service/src/main/resources/net/runelite/http/service/xp/schema.sql +++ /dev/null @@ -1,135 +0,0 @@ --- MySQL dump 10.16 Distrib 10.2.18-MariaDB, for Linux (x86_64) --- --- Host: localhost Database: xptracker --- ------------------------------------------------------ --- Server version 10.2.18-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 `player` --- - -DROP TABLE IF EXISTS `player`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `player` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(32) NOT NULL, - `tracked_since` timestamp NOT NULL DEFAULT current_timestamp(), - `last_updated` timestamp NOT NULL DEFAULT current_timestamp(), - `rank` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `xp` --- - -DROP TABLE IF EXISTS `xp`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `xp` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `time` timestamp NOT NULL DEFAULT current_timestamp(), - `player` int(11) NOT NULL, - `attack_xp` int(11) NOT NULL, - `defence_xp` int(11) NOT NULL, - `strength_xp` int(11) NOT NULL, - `hitpoints_xp` int(11) NOT NULL, - `ranged_xp` int(11) NOT NULL, - `prayer_xp` int(11) NOT NULL, - `magic_xp` int(11) NOT NULL, - `cooking_xp` int(11) NOT NULL, - `woodcutting_xp` int(11) NOT NULL, - `fletching_xp` int(11) NOT NULL, - `fishing_xp` int(11) NOT NULL, - `firemaking_xp` int(11) NOT NULL, - `crafting_xp` int(11) NOT NULL, - `smithing_xp` int(11) NOT NULL, - `mining_xp` int(11) NOT NULL, - `herblore_xp` int(11) NOT NULL, - `agility_xp` int(11) NOT NULL, - `thieving_xp` int(11) NOT NULL, - `slayer_xp` int(11) NOT NULL, - `farming_xp` int(11) NOT NULL, - `runecraft_xp` int(11) NOT NULL, - `hunter_xp` int(11) NOT NULL, - `construction_xp` int(11) NOT NULL, - `overall_xp` int(11) GENERATED ALWAYS AS (`attack_xp` + `defence_xp` + `strength_xp` + `hitpoints_xp` + `ranged_xp` + `prayer_xp` + `magic_xp` + `cooking_xp` + `woodcutting_xp` + `fletching_xp` + `fishing_xp` + `firemaking_xp` + `crafting_xp` + `smithing_xp` + `mining_xp` + `herblore_xp` + `agility_xp` + `thieving_xp` + `slayer_xp` + `farming_xp` + `runecraft_xp` + `hunter_xp` + `construction_xp`) VIRTUAL, - `attack_level` int(11) GENERATED ALWAYS AS (level_for_xp(`attack_xp` AS `attack_xp`)) VIRTUAL, - `defence_level` int(11) GENERATED ALWAYS AS (level_for_xp(`defence_xp` AS `defence_xp`)) VIRTUAL, - `strength_level` int(11) GENERATED ALWAYS AS (level_for_xp(`strength_xp` AS `strength_xp`)) VIRTUAL, - `hitpoints_level` int(11) GENERATED ALWAYS AS (level_for_xp(`hitpoints_xp` AS `hitpoints_xp`)) VIRTUAL, - `ranged_level` int(11) GENERATED ALWAYS AS (level_for_xp(`ranged_xp` AS `ranged_xp`)) VIRTUAL, - `prayer_level` int(11) GENERATED ALWAYS AS (level_for_xp(`prayer_xp` AS `prayer_xp`)) VIRTUAL, - `magic_level` int(11) GENERATED ALWAYS AS (level_for_xp(`magic_xp` AS `magic_xp`)) VIRTUAL, - `cooking_level` int(11) GENERATED ALWAYS AS (level_for_xp(`cooking_xp` AS `cooking_xp`)) VIRTUAL, - `woodcutting_level` int(11) GENERATED ALWAYS AS (level_for_xp(`woodcutting_xp` AS `woodcutting_xp`)) VIRTUAL, - `fletching_level` int(11) GENERATED ALWAYS AS (level_for_xp(`fletching_xp` AS `fletching_xp`)) VIRTUAL, - `fishing_level` int(11) GENERATED ALWAYS AS (level_for_xp(`fishing_xp` AS `fishing_xp`)) VIRTUAL, - `firemaking_level` int(11) GENERATED ALWAYS AS (level_for_xp(`firemaking_xp` AS `firemaking_xp`)) VIRTUAL, - `crafting_level` int(11) GENERATED ALWAYS AS (level_for_xp(`crafting_xp` AS `crafting_xp`)) VIRTUAL, - `smithing_level` int(11) GENERATED ALWAYS AS (level_for_xp(`smithing_xp` AS `smithing_xp`)) VIRTUAL, - `mining_level` int(11) GENERATED ALWAYS AS (level_for_xp(`mining_xp` AS `mining_xp`)) VIRTUAL, - `herblore_level` int(11) GENERATED ALWAYS AS (level_for_xp(`herblore_xp` AS `herblore_xp`)) VIRTUAL, - `agility_level` int(11) GENERATED ALWAYS AS (level_for_xp(`agility_xp` AS `agility_xp`)) VIRTUAL, - `thieving_level` int(11) GENERATED ALWAYS AS (level_for_xp(`thieving_xp` AS `thieving_xp`)) VIRTUAL, - `slayer_level` int(11) GENERATED ALWAYS AS (level_for_xp(`slayer_xp` AS `slayer_xp`)) VIRTUAL, - `farming_level` int(11) GENERATED ALWAYS AS (level_for_xp(`farming_xp` AS `farming_xp`)) VIRTUAL, - `runecraft_level` int(11) GENERATED ALWAYS AS (level_for_xp(`runecraft_xp` AS `runecraft_xp`)) VIRTUAL, - `hunter_level` int(11) GENERATED ALWAYS AS (level_for_xp(`hunter_xp` AS `hunter_xp`)) VIRTUAL, - `construction_level` int(11) GENERATED ALWAYS AS (level_for_xp(`construction_xp` AS `construction_xp`)) VIRTUAL, - `overall_level` int(11) GENERATED ALWAYS AS (`attack_level` + `defence_level` + `strength_level` + `hitpoints_level` + `ranged_level` + `prayer_level` + `magic_level` + `cooking_level` + `woodcutting_level` + `fletching_level` + `fishing_level` + `firemaking_level` + `crafting_level` + `smithing_level` + `mining_level` + `herblore_level` + `agility_level` + `thieving_level` + `slayer_level` + `farming_level` + `runecraft_level` + `hunter_level` + `construction_level`) VIRTUAL, - `attack_rank` int(11) NOT NULL, - `defence_rank` int(11) NOT NULL, - `strength_rank` int(11) NOT NULL, - `hitpoints_rank` int(11) NOT NULL, - `ranged_rank` int(11) NOT NULL, - `prayer_rank` int(11) NOT NULL, - `magic_rank` int(11) NOT NULL, - `cooking_rank` int(11) NOT NULL, - `woodcutting_rank` int(11) NOT NULL, - `fletching_rank` int(11) NOT NULL, - `fishing_rank` int(11) NOT NULL, - `firemaking_rank` int(11) NOT NULL, - `crafting_rank` int(11) NOT NULL, - `smithing_rank` int(11) NOT NULL, - `mining_rank` int(11) NOT NULL, - `herblore_rank` int(11) NOT NULL, - `agility_rank` int(11) NOT NULL, - `thieving_rank` int(11) NOT NULL, - `slayer_rank` int(11) NOT NULL, - `farming_rank` int(11) NOT NULL, - `runecraft_rank` int(11) NOT NULL, - `hunter_rank` int(11) NOT NULL, - `construction_rank` int(11) NOT NULL, - `overall_rank` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `player_time` (`player`,`time`), - KEY `idx_time` (`time`), - CONSTRAINT `fk_player` FOREIGN KEY (`player`) REFERENCES `player` (`id`) -) ENGINE=InnoDB 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 2019-02-15 21:01:17 \ No newline at end of file diff --git a/http-service/src/main/templates/markdown.hbs b/http-service/src/main/templates/markdown.hbs deleted file mode 100644 index 1beacd052a..0000000000 --- a/http-service/src/main/templates/markdown.hbs +++ /dev/null @@ -1,110 +0,0 @@ -{{#info}} -# {{title}} -{{join schemes " | "}}://{{host}}{{basePath}} - -{{description}} - -{{#contact}} -[**Contact the developer**](mailto:{{email}}) -{{/contact}} - -**Version** {{version}} - -{{#if termsOfService}} -[**Terms of Service**]({{termsOfService}}) -{{/if}} - -{{/info}} - -{{#if consumes}}__Consumes:__ {{join consumes ", "}}{{/if}} - -{{#if produces}}__Produces:__ {{join produces ", "}}{{/if}} - -{{#if securityDefinitions}} -# Security Definitions -{{> security}} -{{/if}} - -
-Table Of Contents -[toc] -
- -# APIs - -{{#each paths}} -## {{@key}} -{{#this}} -{{#get}} -### GET -{{> operation}} -{{/get}} - -{{#put}} -### PUT -{{> operation}} -{{/put}} - -{{#post}} -### POST - -{{> operation}} - -{{/post}} - -{{#delete}} -### DELETE -{{> operation}} -{{/delete}} - -{{#option}} -### OPTION -{{> operation}} -{{/option}} - -{{#patch}} -### PATCH -{{> operation}} -{{/patch}} - -{{#head}} -### HEAD -{{> operation}} -{{/head}} - -{{/this}} -{{/each}} - -# Definitions -{{#each definitions}} -## {{@key}} - - - - - - - - - - {{#each this.properties}} - - - - - - - - {{/each}} -
nametyperequireddescriptionexample
{{@key}} - {{#ifeq type "array"}} - {{#items.$ref}} - {{type}}[{{basename items.$ref}}] - {{/items.$ref}} - {{^items.$ref}}{{type}}[{{items.type}}]{{/items.$ref}} - {{else}} - {{#$ref}}{{basename $ref}}{{/$ref}} - {{^$ref}}{{type}}{{#format}} ({{format}}){{/format}}{{/$ref}} - {{/ifeq}} - {{#required}}required{{/required}}{{^required}}optional{{/required}}{{#description}}{{{description}}}{{/description}}{{^description}}-{{/description}}{{example}}
-{{/each}} diff --git a/http-service/src/main/templates/operation.hbs b/http-service/src/main/templates/operation.hbs deleted file mode 100644 index f7015850b8..0000000000 --- a/http-service/src/main/templates/operation.hbs +++ /dev/null @@ -1,71 +0,0 @@ -{{#deprecated}}-deprecated-{{/deprecated}} -{{summary}} - -{{description}} - -{{#if externalDocs.url}}{{externalDocs.description}}. [See external documents for more details]({{externalDocs.url}}) -{{/if}} - -{{#if security}} -#### Security -{{/if}} - -{{#security}} -{{#each this}} -* {{@key}} -{{#this}} * {{this}} -{{/this}} -{{/each}} -{{/security}} - -#### Request - -{{#if consumes}}__Content-Type:__ {{join consumes ", "}}{{/if}} - -##### Parameters -{{#if parameters}} - - - - - - - - - -{{/if}} - -{{#parameters}} - - - - - - -{{#ifeq in "body"}} - -{{else}} - {{#ifeq type "array"}} - - {{else}} - - {{/ifeq}} -{{/ifeq}} - -{{/parameters}} -{{#if parameters}} -
NameLocated inRequiredDescriptionDefaultSchema
{{name}}{{in}}{{#if required}}yes{{else}}no{{/if}}{{description}}{{#if pattern}} (**Pattern**: `{{pattern}}`){{/if}} - - {{#ifeq schema.type "array"}}Array[{{basename schema.items.$ref}}]{{/ifeq}} - {{#schema.$ref}}{{basename schema.$ref}} {{/schema.$ref}} - Array[{{items.type}}] ({{collectionFormat}}){{type}} {{#format}}({{format}}){{/format}}
-{{/if}} - - -#### Response - -{{#if produces}}__Content-Type:__ {{join produces ", "}}{{/if}} - -| Status Code | Reason | Response Model | -|-------------|-------------|----------------| -{{#each responses}}| {{@key}} | {{description}} | {{#schema.$ref}}{{basename schema.$ref}}{{/schema.$ref}}{{#ifeq schema.type "array"}}Array[{{basename schema.items.$ref}}]{{/ifeq}}{{^schema}} - {{/schema}}| -{{/each}} diff --git a/http-service/src/main/templates/security.hbs b/http-service/src/main/templates/security.hbs deleted file mode 100644 index 04f86e8380..0000000000 --- a/http-service/src/main/templates/security.hbs +++ /dev/null @@ -1,88 +0,0 @@ -{{#each securityDefinitions}} -### {{@key}} -{{#this}} -{{#ifeq type "oauth2"}} - - - - - -{{#if description}} - - - - -{{/if}} -{{#if authorizationUrl}} - - - - -{{/if}} -{{#if flow}} - - - - -{{/if}} -{{#if tokenUrl}} - - - - -{{/if}} -{{#if scopes}} - - -{{#each scopes}} - - - - -{{/each}} - -{{/if}} -
type{{type}}
description{{description}}
authorizationUrl{{authorizationUrl}}
flow{{flow}}
tokenUrl{{tokenUrl}}
scopes{{@key}}{{this}}
-{{/ifeq}} -{{#ifeq type "apiKey"}} - - - - - -{{#if description}} - - - - -{{/if}} -{{#if name}} - - - - -{{/if}} -{{#if in}} - - - - -{{/if}} -
type{{type}}
description{{description}}
name{{name}}
in{{in}}
-{{/ifeq}} -{{#ifeq type "basic"}} - - - - - -{{#if description}} - - - - -{{/if}} -
type{{type}}
description{{description}}
-{{/ifeq}} -{{/this}} -{{/each}} \ No newline at end of file diff --git a/http-service/src/main/templates/template.html.hbs b/http-service/src/main/templates/template.html.hbs deleted file mode 100644 index da587c2cc4..0000000000 --- a/http-service/src/main/templates/template.html.hbs +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - {{info.title}} {{info.version}} - - - - - \ No newline at end of file diff --git a/http-service/src/main/webapp/WEB-INF/web.xml b/http-service/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 0b07dbb973..0000000000 --- a/http-service/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - RuneLite API - \ No newline at end of file diff --git a/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java b/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java deleted file mode 100644 index 646b19611e..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/config/ConfigControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.config; - -import java.io.IOException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.service.account.AuthFilter; -import net.runelite.http.service.account.beans.SessionEntry; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@WebMvcTest(ConfigController.class) -@ActiveProfiles("test") -public class ConfigControllerTest -{ - @Autowired - private MockMvc mockMvc; - - @MockBean - private ConfigService configService; - - @MockBean - private AuthFilter authFilter; - - @Before - public void before() throws IOException - { - when(authFilter.handle(any(HttpServletRequest.class), any(HttpServletResponse.class))) - .thenReturn(mock(SessionEntry.class)); - - when(configService.setKey(anyInt(), anyString(), anyString())).thenReturn(true); - } - - @Test - public void testSetKey() throws Exception - { - mockMvc.perform(put("/config/key") - .content("value") - .contentType(MediaType.TEXT_PLAIN)) - .andExpect(status().isOk()); - - verify(configService).setKey(anyInt(), eq("key"), eq("value")); - } -} \ No newline at end of file diff --git a/http-service/src/test/java/net/runelite/http/service/config/ConfigServiceTest.java b/http-service/src/test/java/net/runelite/http/service/config/ConfigServiceTest.java deleted file mode 100644 index 64c4ef574c..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/config/ConfigServiceTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.config; - -import com.google.common.collect.ImmutableMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -public class ConfigServiceTest -{ - @Test - public void testParseJsonString() - { - assertEquals(1, ConfigService.parseJsonString("1")); - assertEquals(3.14, ConfigService.parseJsonString("3.14")); - assertEquals(1L << 32, ConfigService.parseJsonString("4294967296")); - assertEquals("test", ConfigService.parseJsonString("test")); - assertEquals("test", ConfigService.parseJsonString("\"test\"")); - assertEquals(ImmutableMap.of("key", "value"), ConfigService.parseJsonString("{\"key\": \"value\"}")); - } - - @Test - public void testValidateJson() - { - assertTrue(ConfigService.validateJson("1")); - assertTrue(ConfigService.validateJson("3.14")); - assertTrue(ConfigService.validateJson("test")); - assertTrue(ConfigService.validateJson("\"test\"")); - assertTrue(ConfigService.validateJson("key:value")); - assertTrue(ConfigService.validateJson("{\"key\": \"value\"}")); - } -} \ No newline at end of file diff --git a/http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreServiceTest.java b/http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreServiceTest.java deleted file mode 100644 index b019bdd990..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreServiceTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.hiscore; - -import java.io.IOException; -import net.runelite.http.api.hiscore.HiscoreEndpoint; -import net.runelite.http.api.hiscore.HiscoreResult; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class HiscoreServiceTest -{ - private static final String RESPONSE = "654683,705,1304518\n" - + "679419,50,107181\n" - + "550667,48,85764\n" - + "861497,50,101366\n" - + "891591,48,87843\n" - + "-1,1,4\n" - + "840255,27,10073\n" - + "1371912,10,1310\n" - + "432193,56,199795\n" - + "495638,56,198304\n" - + "514466,37,27502\n" - + "456981,54,159727\n" - + "459159,49,93010\n" - + "1028855,8,823\n" - + "862906,29,12749\n" - + "795020,31,16097\n" - + "673591,5,495\n" - + "352676,51,112259\n" - + "428419,40,37235\n" - + "461887,43,51971\n" - + "598582,1,10\n" - + "638177,1,0\n" - + "516239,9,1000\n" - + "492790,1,0\n" - + "2,2460\n" // leagues - + "-1,-1\n" - + "73,1738\n" - + "531,1432\n" - + "324,212\n" - + "8008,131\n" - + "1337,911\n" - + "42,14113\n" - + "1,777\n" - + "254,92\n" - + "-1,-1\n" // lms - + "24870,37\n" - + "15020,388\n" - + "50463,147\n" - + "-1,-1\n" - + "92357,1\n" - + "22758,637\n" - + "22744,107\n" - + "-1,-1\n" - + "20150,17\n" - + "29400,18\n" - + "13465,172\n" - + "1889,581\n" - + "42891,11\n" - + "1624,1957\n" - + "1243,2465\n" - + "1548,2020\n" - + "-1,-1\n" - + "16781,327\n" - + "19004,149\n" - + "-1,-1\n" - + "72046,5\n" - + "5158,374\n" - + "20902,279\n" - + "702,6495\n" - + "10170,184\n" - + "8064,202\n" - + "6936,2\n" - + "-1,-1\n" - + "-1,-1\n" - + "19779,22\n" - + "58283,10\n" - + "-1,-1\n" - + "-1,-1\n" - + "-1,-1\n" - + "29347,130\n" - + "723,4\n" - + "1264,38\n" - + "44595,4\n" - + "24820,4\n" - + "12116,782\n" - + "2299,724\n" - + "19301,62\n" - + "1498,5847\n"; - - private final MockWebServer server = new MockWebServer(); - - @Before - public void before() throws IOException - { - server.enqueue(new MockResponse().setBody(RESPONSE)); - - server.start(); - } - - @After - public void after() throws IOException - { - server.shutdown(); - } - - @Test - public void testNormalLookup() throws Exception - { - HiscoreTestService hiscores = new HiscoreTestService(server.url("/")); - - HiscoreResult result = hiscores.lookupUsername("zezima", HiscoreEndpoint.NORMAL.getHiscoreURL()); - - Assert.assertEquals(50, result.getAttack().getLevel()); - Assert.assertEquals(159727L, result.getFishing().getExperience()); - Assert.assertEquals(492790, result.getConstruction().getRank()); - Assert.assertEquals(1432, result.getClueScrollAll().getLevel()); - Assert.assertEquals(324, result.getClueScrollBeginner().getRank()); - Assert.assertEquals(8008, result.getClueScrollEasy().getRank()); - Assert.assertEquals(911, result.getClueScrollMedium().getLevel()); - Assert.assertEquals(42, result.getClueScrollHard().getRank()); - Assert.assertEquals(777, result.getClueScrollElite().getLevel()); - Assert.assertEquals(254, result.getClueScrollMaster().getRank()); - Assert.assertEquals(-1, result.getLastManStanding().getLevel()); - Assert.assertEquals(2460, result.getLeaguePoints().getLevel()); - Assert.assertEquals(37, result.getAbyssalSire().getLevel()); - Assert.assertEquals(92357, result.getCallisto().getRank()); - Assert.assertEquals(5847, result.getZulrah().getLevel()); - } -} diff --git a/http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreTestService.java b/http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreTestService.java deleted file mode 100644 index bdd59b077a..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/hiscore/HiscoreTestService.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 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 HOLDER 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.hiscore; - -import java.io.IOException; -import net.runelite.http.api.hiscore.HiscoreResult; -import okhttp3.HttpUrl; - -class HiscoreTestService extends HiscoreService -{ - private final HttpUrl testUrl; - - HiscoreTestService(HttpUrl testUrl) - { - this.testUrl = testUrl; - } - - @Override - public HiscoreResult lookupUsername(String username, HttpUrl endpoint) throws IOException - { - return super.lookupUsername(username, testUrl); - } -} diff --git a/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java b/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java deleted file mode 100644 index ccf7ab7603..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/loottracker/LootTrackerControllerTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2019, Adam - * 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.loottracker; - -import java.io.IOException; -import java.time.Instant; -import java.util.Collections; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import net.runelite.http.api.RuneLiteAPI; -import net.runelite.http.api.loottracker.GameItem; -import net.runelite.http.api.loottracker.LootRecord; -import net.runelite.http.api.loottracker.LootRecordType; -import net.runelite.http.service.account.AuthFilter; -import net.runelite.http.service.account.beans.SessionEntry; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@WebMvcTest(LootTrackerController.class) -@ActiveProfiles("test") -public class LootTrackerControllerTest -{ - @Autowired - private MockMvc mockMvc; - - @MockBean - private LootTrackerService lootTrackerService; - - @MockBean - private AuthFilter authFilter; - - @Before - public void before() throws IOException - { - when(authFilter.handle(any(HttpServletRequest.class), any(HttpServletResponse.class))) - .thenReturn(mock(SessionEntry.class)); - } - - @Test - public void storeLootRecord() throws Exception - { - LootRecord lootRecord = new LootRecord(); - lootRecord.setType(LootRecordType.NPC); - lootRecord.setTime(Instant.now()); - lootRecord.setDrops(Collections.singletonList(new GameItem(4151, 1))); - - String data = RuneLiteAPI.GSON.toJson(Collections.singletonList(lootRecord)); - mockMvc.perform(post("/loottracker").content(data).contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()); - - verify(lootTrackerService).store(eq(Collections.singletonList(lootRecord)), anyInt()); - } -} \ No newline at end of file diff --git a/http-service/src/test/java/net/runelite/http/service/worlds/WorldsServiceTest.java b/http-service/src/test/java/net/runelite/http/service/worlds/WorldsServiceTest.java deleted file mode 100644 index 152a6e4e5a..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/worlds/WorldsServiceTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.worlds; - -import java.io.IOException; -import java.io.InputStream; -import net.runelite.http.api.worlds.World; -import net.runelite.http.api.worlds.WorldResult; -import net.runelite.http.api.worlds.WorldType; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okio.Buffer; -import org.junit.After; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import org.sql2o.tools.IOUtils; - -public class WorldsServiceTest -{ - - private final MockWebServer server = new MockWebServer(); - - @Before - public void before() throws IOException - { - InputStream in = WorldsServiceTest.class.getResourceAsStream("worldlist"); - byte[] worldData = IOUtils.toByteArray(in); - - Buffer buffer = new Buffer(); - buffer.write(worldData); - - server.enqueue(new MockResponse().setBody(buffer)); - - server.start(); - } - - @After - public void after() throws IOException - { - server.shutdown(); - } - - @Test - public void testListWorlds() throws Exception - { - WorldsService worlds = new WorldsService(); - worlds.setUrl(server.url("/")); - - WorldResult worldResult = worlds.getWorlds(); - assertEquals(82, worldResult.getWorlds().size()); - - World world = worldResult.findWorld(385); - assertNotNull(world); - assertTrue(world.getTypes().contains(WorldType.SKILL_TOTAL)); - } - -} diff --git a/http-service/src/test/java/net/runelite/http/service/xp/XpMapperTest.java b/http-service/src/test/java/net/runelite/http/service/xp/XpMapperTest.java deleted file mode 100644 index 2c24f9cc81..0000000000 --- a/http-service/src/test/java/net/runelite/http/service/xp/XpMapperTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2018, Adam - * 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.xp; - -import net.runelite.http.api.hiscore.HiscoreResult; -import net.runelite.http.api.hiscore.Skill; -import net.runelite.http.api.xp.XpData; -import net.runelite.http.service.xp.beans.XpEntity; -import static org.junit.Assert.assertEquals; -import org.junit.Test; - -public class XpMapperTest -{ - @Test - public void testXpEntityToXpData() - { - XpEntity xpEntity = new XpEntity(); - xpEntity.setAgility_rank(42); - xpEntity.setAgility_xp(9001); - - XpData xpData = XpMapper.INSTANCE.xpEntityToXpData(xpEntity); - assertEquals(42, xpData.getAgility_rank()); - assertEquals(9001, xpData.getAgility_xp()); - } - - @Test - public void testHiscoreResultToXpData() - { - HiscoreResult hiscoreResult = new HiscoreResult(); - hiscoreResult.setAgility(new Skill(42, 9, 9001)); - - XpData xpData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult); - assertEquals(42, xpData.getAgility_rank()); - assertEquals(9001, xpData.getAgility_xp()); - } - -} diff --git a/http-service/src/test/resources/application-test.yaml b/http-service/src/test/resources/application-test.yaml deleted file mode 100644 index 3a8e416a54..0000000000 --- a/http-service/src/test/resources/application-test.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Use in-memory database for tests -datasource: - runelite: - jndiName: - driverClassName: org.h2.Driver - type: org.h2.jdbcx.JdbcDataSource - url: jdbc:h2:mem:runelite - runelite-cache: - jndiName: - driverClassName: org.h2.Driver - type: org.h2.jdbcx.JdbcDataSource - url: jdbc:h2:mem:cache - runelite-tracker: - jndiName: - driverClassName: org.h2.Driver - type: org.h2.jdbcx.JdbcDataSource - url: jdbc:h2:mem:xptracker - -mongo: - jndiName: - host: mongodb://localhost:27017 \ No newline at end of file diff --git a/http-service/src/test/resources/net/runelite/http/service/worlds/worldlist b/http-service/src/test/resources/net/runelite/http/service/worlds/worldlist deleted file mode 100644 index 1d1360e5795d066b068e095cf2a033a504405ad6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5000 zcmeHKOK%%h6uu{Nt&HNnr;&XfUL@?A&0Xv2`>KbrNjykW>2xs2%({goUE2ojRl+UsP2YF3kRF>f)3pl!mq&wAvxSj*vi<` zL+jfJeGeWY1bdoC8M!GddJqr^AHcJOR^c?>rfy383=~o`EgbG-%g){BFW?y(jytE( z4^`J~%Z8WuXg~ztgnJ0Z;z}$8;g*g%lgkR9g4r$CbK^cTzJkXHugooe2$gZDT;KJ# z5d9785>A!3$~+oBz{>`Iajg@H&p1F21Jocycp5{fJHd`3fGmV+CeBADvbNG8Q=gAg+81nq!QO^DM%tc zH84YRq~rOT1m2nR1XRk~LWtMl z2?8qTYY^fMxR-z|?j4iUn{bAJO8M>y@ir_|5ZBq9v=3&$j#M`;+($4^Kz81CLVOIX z1XRx3&dih&0dYfNN^lGwCz$dW(8M2bzu9)u-NWLb!G;%fdpdSwciSv#@4%DfT!$yP zy1S%QDC@Z54Bq;|-nLCR)x1LhZ{@=TRN|n~^~Azc4`7oJ9Bu?UG(mg|W^`uNI=ou5 zV}1u~1XSjxXa=61?0Kqh-a8QA!y^>W{gDj_Pwfn+1K_|vg{*8_w7Fr@Z4pEK3@ao= zi5q7TSJ7xN?r_2eTlg3smkZiQ>aTDSse5UI%lt;=mP-)7LxqI1c!!s9`_+D14&VOS z7COW1M - * 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. - */ - -description = "Protocol API" - -dependencies { - annotationProcessor(Libraries.lombok) - - compileOnly(Libraries.lombok) - - implementation(Libraries.guava) - implementation(Libraries.slf4jApi) - implementation(project(":runelite-api")) - - testImplementation(Libraries.junit) -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakePacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakePacket.java deleted file mode 100644 index 16794ac5e9..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakePacket.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.handshake; - -public abstract class HandshakePacket {} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeResponsePacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeResponsePacket.java deleted file mode 100644 index 5164e042d3..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeResponsePacket.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.handshake; - -import lombok.Data; -import net.runelite.protocol.api.login.HandshakeResponseType; - -@Data -public class HandshakeResponsePacket -{ - private HandshakeResponseType response; -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeType.java b/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeType.java deleted file mode 100644 index 6da6ac01f9..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/HandshakeType.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.handshake; - -public enum HandshakeType -{ - LOGIN(14), - UPDATE(15); - - private final byte value; - - HandshakeType(int value) - { - this.value = (byte) value; - } - - public byte getValue() - { - return value; - } - - public static HandshakeType of(byte value) - { - for (HandshakeType type : values()) - { - if (type.value == value) - { - return type; - } - } - return null; - } -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/LoginHandshakePacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/handshake/LoginHandshakePacket.java deleted file mode 100644 index e19f72d725..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/LoginHandshakePacket.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.handshake; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -public class LoginHandshakePacket extends HandshakePacket {} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/UpdateHandshakePacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/handshake/UpdateHandshakePacket.java deleted file mode 100644 index 86b39d41e8..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/handshake/UpdateHandshakePacket.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.handshake; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -@Data -@EqualsAndHashCode(callSuper = true) -@NoArgsConstructor -@AllArgsConstructor -public class UpdateHandshakePacket extends HandshakePacket -{ - private int revision; -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/login/HandshakeResponseType.java b/protocol-api/src/main/java/net/runelite/protocol/api/login/HandshakeResponseType.java deleted file mode 100644 index 8ba9816c96..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/login/HandshakeResponseType.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.login; - -public enum HandshakeResponseType -{ - RESPONSE_OK(0), - LOGGED_IN(2), - INVALID_USERNAME_OR_PASSWORD(3), - ACCOUNT_DISABLED(4), - ACCOUNT_ONLINE(5), - RESPONSE_OUTDATED(6), - WORLD_FULL(7), - SERVER_OFFLINE(8), - LIMITED_EXCEEDED(9), - BAD_SESSION_ID(10), - ACCOUNT_HIJACK(11), - MEMBERS_WORLD(12), - COULD_NOT_COMPLETE_LOGIN(13), - SERVER_BEING_UPDATED(14), - TOO_MANY_ATTEMPTS(16), - MEMBERS_ONLY_AREA(17), - ACCOUNT_LOCKED(18), - CLOSED_BETA(19), - INVALID_LOGINSERVER(20), - PROFILE_TRANSFER(21), - MALFORMED_PACKET(22), - NO_REPLY_FROM_LOGINSERVER(23), - ERR_LOADING_PROFILE(24), - UNEXPECTED_LOGINSERVER_RESPONSE(25), - IP_BANNED(26), - SERVICE_UNAVAILABLE(27), - NO_DISPLAY_NAME(31), - BILLING_ERROR(32), - ACCOUNT_INACCESSABLE(37), - VOTE_TO_PLAY(38), - NOT_ELIGIBLE(55), - NEED_AUTHENTICATOR(56), - AUTHENTICATOR_CODE_WRONG(57); - - private final byte value; - - HandshakeResponseType(int value) - { - this.value = (byte) value; - } - - public byte getValue() - { - return value; - } - - public static HandshakeResponseType of(byte value) - { - for (HandshakeResponseType type : values()) - { - if (type.value == value) - { - return type; - } - } - return null; - } -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveRequestPacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveRequestPacket.java deleted file mode 100644 index fd545b8745..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveRequestPacket.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.update; - -public class ArchiveRequestPacket -{ - private boolean priority; - private int index; - private int archive; - - @Override - public String toString() - { - return "ArchiveRequestPacket{" + "priority=" + priority + ", index=" + index + ", archive=" + archive + '}'; - } - - public boolean isPriority() - { - return priority; - } - - public void setPriority(boolean priority) - { - this.priority = priority; - } - - public int getIndex() - { - return index; - } - - public void setIndex(int index) - { - this.index = index; - } - - public int getArchive() - { - return archive; - } - - public void setArchive(int archive) - { - this.archive = archive; - } -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveResponsePacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveResponsePacket.java deleted file mode 100644 index 1a9a0b6178..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/update/ArchiveResponsePacket.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.update; - -public class ArchiveResponsePacket -{ - private int index; - private int archive; - private byte[] data; - - @Override - public String toString() - { - return "ArchiveResponsePacket{" + "index=" + index + ", archive=" + archive + ", data=" + data + '}'; - } - - public int getIndex() - { - return index; - } - - public void setIndex(int index) - { - this.index = index; - } - - public int getArchive() - { - return archive; - } - - public void setArchive(int archive) - { - this.archive = archive; - } - - public byte[] getData() - { - return data; - } - - public void setData(byte[] data) - { - this.data = data; - } -} diff --git a/protocol-api/src/main/java/net/runelite/protocol/api/update/EncryptionPacket.java b/protocol-api/src/main/java/net/runelite/protocol/api/update/EncryptionPacket.java deleted file mode 100644 index dbd8ab6eb9..0000000000 --- a/protocol-api/src/main/java/net/runelite/protocol/api/update/EncryptionPacket.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.api.update; - -import lombok.Data; - -@Data -public class EncryptionPacket -{ - private byte key; -} diff --git a/protocol/protocol.gradle.kts b/protocol/protocol.gradle.kts deleted file mode 100644 index f8f830a7c3..0000000000 --- a/protocol/protocol.gradle.kts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2019 Owain van Brakel - * 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. - */ - -description = "Protocol" - -dependencies { - annotationProcessor(Libraries.lombok) - - api(project(":protocol-api")) - - compileOnly(Libraries.lombok) - - implementation(Libraries.guava) - implementation(Libraries.nettyAll) - implementation(Libraries.slf4jApi) - implementation(project(":cache")) - - testImplementation(Libraries.junit) -} diff --git a/protocol/src/main/java/net/runelite/protocol/handshake/HandshakeDecoder.java b/protocol/src/main/java/net/runelite/protocol/handshake/HandshakeDecoder.java deleted file mode 100644 index b733d77041..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/handshake/HandshakeDecoder.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.handshake; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; -import lombok.extern.slf4j.Slf4j; -import net.runelite.protocol.api.handshake.HandshakeType; -import net.runelite.protocol.api.handshake.LoginHandshakePacket; -import net.runelite.protocol.api.handshake.UpdateHandshakePacket; - -@Slf4j -public class HandshakeDecoder extends ByteToMessageDecoder -{ - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List out) throws Exception - { - buf.markReaderIndex(); - byte handshakeOpcode = buf.readByte(); - - HandshakeType handshakeType = HandshakeType.of(handshakeOpcode); - if (handshakeType == null) - { - log.warn("Unknown handshake type {} from {}", - handshakeOpcode, ctx.channel().remoteAddress()); - ctx.close(); - return; - } - - switch (handshakeType) - { - case LOGIN: - { - LoginHandshakePacket packet = new LoginHandshakePacket(); - out.add(packet); - break; - } - case UPDATE: - { - if (buf.readableBytes() < 4) - { - buf.resetReaderIndex(); - return; - } - - int revision = buf.readInt(); - UpdateHandshakePacket packet = new UpdateHandshakePacket(revision); - out.add(packet); - break; - } - } - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/handshake/HandshakeResponseEncoder.java b/protocol/src/main/java/net/runelite/protocol/handshake/HandshakeResponseEncoder.java deleted file mode 100644 index 91f2c9f753..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/handshake/HandshakeResponseEncoder.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.handshake; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.runelite.protocol.api.handshake.HandshakeResponsePacket; -import net.runelite.protocol.api.login.HandshakeResponseType; - -public class HandshakeResponseEncoder extends MessageToByteEncoder -{ - - @Override - protected void encode(ChannelHandlerContext ctx, HandshakeResponsePacket handshakeResponse, ByteBuf out) throws Exception - { - HandshakeResponseType handshakeResponseType = handshakeResponse.getResponse(); - out.writeByte(handshakeResponseType.getValue()); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/handshake/LoginHandshakeEncoder.java b/protocol/src/main/java/net/runelite/protocol/handshake/LoginHandshakeEncoder.java deleted file mode 100644 index 54189c4ec3..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/handshake/LoginHandshakeEncoder.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.handshake; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.runelite.protocol.api.handshake.HandshakeType; -import net.runelite.protocol.api.handshake.LoginHandshakePacket; - -public class LoginHandshakeEncoder extends MessageToByteEncoder -{ - @Override - protected void encode(ChannelHandlerContext ctx, LoginHandshakePacket packet, ByteBuf buf) throws Exception - { - buf.writeByte(HandshakeType.LOGIN.getValue()); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/handshake/UpdateHandshakeEncoder.java b/protocol/src/main/java/net/runelite/protocol/handshake/UpdateHandshakeEncoder.java deleted file mode 100644 index cb3dec90ec..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/handshake/UpdateHandshakeEncoder.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.handshake; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.runelite.protocol.api.handshake.HandshakeType; -import net.runelite.protocol.api.handshake.UpdateHandshakePacket; - -public class UpdateHandshakeEncoder extends MessageToByteEncoder -{ - @Override - protected void encode(ChannelHandlerContext ctx, UpdateHandshakePacket packet, ByteBuf buf) throws Exception - { - buf.writeByte(HandshakeType.UPDATE.getValue()); - buf.writeInt(packet.getRevision()); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveRequestDecoder.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveRequestDecoder.java deleted file mode 100644 index 449f8cf3b7..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveRequestDecoder.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.decoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; -import net.runelite.protocol.api.update.ArchiveRequestPacket; - -public class ArchiveRequestDecoder extends ByteToMessageDecoder -{ - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception - { - byte opcode = in.getByte(in.readerIndex()); - if (opcode != UpdateOpcodes.ARCHIVE_REQUEST_HIGH - && opcode != UpdateOpcodes.ARCHIVE_REQUEST_LOW) - { - ctx.fireChannelRead(in.retain()); - return; - } - - byte priority = in.readByte(); - int index = in.readByte() & 0xFF; - int archiveId = in.readShort() & 0xFFFF; - - ArchiveRequestPacket archiveRequest = new ArchiveRequestPacket(); - archiveRequest.setPriority(priority == 1); - archiveRequest.setIndex(index); - archiveRequest.setArchive(archiveId); - out.add(archiveRequest); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveResponseDecoder.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveResponseDecoder.java deleted file mode 100644 index 2c12a42264..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/ArchiveResponseDecoder.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.decoders; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; -import net.runelite.cache.fs.jagex.CompressionType; -import net.runelite.protocol.api.update.ArchiveResponsePacket; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ArchiveResponseDecoder extends ByteToMessageDecoder -{ - private static final Logger logger = LoggerFactory.getLogger(ArchiveResponseDecoder.class); - - private static final int CHUNK_SIZE = 512; - - @Override - public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception - { - if (in.readableBytes() < 8) - { - return; - } - - ByteBuf copy = in.slice(); - - int index = copy.readUnsignedByte(); - int file = copy.readUnsignedShort(); - // decompress() starts reading here - int compression = copy.readUnsignedByte(); - int compressedFileSize = copy.readInt(); - - assert compression == CompressionType.NONE || - compression == CompressionType.BZ2 || - compression == CompressionType.GZ; - - int size = compressedFileSize - + 5 // 1 byte compresion type, 4 byte compressed size - + (compression != CompressionType.NONE ? 4 : 0); // compression has leading 4 byte decompressed length - - assert size > 0; - - int breaks = calculateBreaks(size); - - // 3 for index/file - if (size + 3 + breaks > in.readableBytes()) - { - logger.trace("Index {} archive {}: Not enough data yet {} > {}", index, file, size + 3 + breaks, in.readableBytes()); - return; - } - - ByteBuf compressedData = Unpooled.buffer(size); - - int totalRead = 3; - in.skipBytes(3); // skip index/file - - for (int i = 0; i < breaks + 1; ++i) - { - int bytesInBlock = CHUNK_SIZE - (totalRead % CHUNK_SIZE); - int bytesToRead = Math.min(bytesInBlock, size - compressedData.writerIndex()); - - logger.trace("{}/{}: reading block {}/{}, read so far this block: {}, file status: {}/{}", - index, file, - (totalRead % CHUNK_SIZE), CHUNK_SIZE, - bytesInBlock, - compressedData.writerIndex(), size); - - ByteBuf chunk = in.readBytes(bytesToRead); - compressedData.writeBytes(chunk); - chunk.release(); - - totalRead += bytesToRead; - - if (i < breaks) - { - assert compressedData.writerIndex() < size; - int b = in.readUnsignedByte(); - ++totalRead; - assert b == 0xff; - } - } - - assert compressedData.writerIndex() == size; - - logger.trace("{}/{}: done downloading file, remaining buffer {}", - index, file, - in.readableBytes()); - - ArchiveResponsePacket archiveResponse = new ArchiveResponsePacket(); - archiveResponse.setIndex(index); - archiveResponse.setArchive(file); - archiveResponse.setData(compressedData.array()); - out.add(archiveResponse); - - compressedData.release(); - } - - /** - * Calculate how many breaks there are in the file stream. There are - * calculateBreaks()+1 total chunks in the file stream - * - * File contents are sent in 512 byte chunks, with the first byte of - * each chunk except for the first one being 0xff. - * - * The first chunk has an 8 byte header (index, file, compression, - * compressed size). So, the first chunk can contain 512 - 8 bytes of - * the file, and each chunk after 511 bytes. - * - * The 'size' parameter has the compression type and size included in - * it, since they haven't been read yet by the buffer stream, as - * decompress() reads it, so we use 512 - 3 (because 8-5) = 3 - */ - private static int calculateBreaks(int size) - { - int initialSize = CHUNK_SIZE - 3; - if (size <= initialSize) - { - return 0; // First in the initial chunk, no breaks - } - int left = size - initialSize; - - if (left % (CHUNK_SIZE - 1) == 0) - { - return (left / (CHUNK_SIZE - 1)); - } - else - { - // / 511 because 511 bytes of the file per chunk. - // + 1 if there is some left over, it still needs its - // own chunk - return (left / (CHUNK_SIZE - 1)) + 1; - } - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/EncryptionDecoder.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/EncryptionDecoder.java deleted file mode 100644 index 2f13f5559c..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/EncryptionDecoder.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.decoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; -import net.runelite.protocol.api.update.EncryptionPacket; - -public class EncryptionDecoder extends ByteToMessageDecoder -{ - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception - { - if (in.getByte(in.readerIndex()) != UpdateOpcodes.ENCRYPTION) - { - ctx.fireChannelRead(in.retain()); - return; - } - - in.readByte(); - byte xorKey = in.readByte(); - in.readShort(); // always 0 - - EncryptionPacket encryptionPacket = new EncryptionPacket(); - encryptionPacket.setKey(xorKey); - out.add(encryptionPacket); - } -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/HandshakeResponseDecoder.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/HandshakeResponseDecoder.java deleted file mode 100644 index bcadbb6a7a..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/HandshakeResponseDecoder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.decoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; -import net.runelite.protocol.api.handshake.HandshakeResponsePacket; -import net.runelite.protocol.api.login.HandshakeResponseType; - -public class HandshakeResponseDecoder extends ByteToMessageDecoder -{ - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception - { - byte response = in.readByte(); - - HandshakeResponsePacket handshakeResponse = new HandshakeResponsePacket(); - handshakeResponse.setResponse(HandshakeResponseType.of(response)); - out.add(handshakeResponse); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedInDecoder.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedInDecoder.java deleted file mode 100644 index d21ec96978..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedInDecoder.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.update.decoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; - -public class LoggedInDecoder extends ByteToMessageDecoder -{ - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List list) throws Exception - { - if (in.getByte(in.readerIndex()) != UpdateOpcodes.CLIENT_LOGGED_IN) - { - ctx.fireChannelRead(in.retain()); - return; - } - - in.skipBytes(4); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedOutDecoder.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedOutDecoder.java deleted file mode 100644 index 4fb1ced6df..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/LoggedOutDecoder.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.update.decoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import java.util.List; - -public class LoggedOutDecoder extends ByteToMessageDecoder -{ - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List list) throws Exception - { - if (in.getByte(in.readerIndex()) != UpdateOpcodes.CLIENT_LOGGED_OUT) - { - ctx.fireChannelRead(in.retain()); - return; - } - - in.skipBytes(4); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/decoders/UpdateOpcodes.java b/protocol/src/main/java/net/runelite/protocol/update/decoders/UpdateOpcodes.java deleted file mode 100644 index 46df56aa0d..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/decoders/UpdateOpcodes.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.protocol.update.decoders; - -public class UpdateOpcodes -{ - public static final int ARCHIVE_REQUEST_LOW = 0; - public static final int ARCHIVE_REQUEST_HIGH = 1; - public static final int CLIENT_LOGGED_IN = 2; - public static final int CLIENT_LOGGED_OUT = 3; - public static final int ENCRYPTION = 4; -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveRequestEncoder.java b/protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveRequestEncoder.java deleted file mode 100644 index 13ae829ccd..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveRequestEncoder.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.encoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.runelite.protocol.api.update.ArchiveRequestPacket; - -public class ArchiveRequestEncoder extends MessageToByteEncoder -{ - @Override - protected void encode(ChannelHandlerContext ctx, ArchiveRequestPacket archiveRequest, ByteBuf out) throws Exception - { - out.writeByte(archiveRequest.isPriority() ? 1 : 0); - out.writeByte(archiveRequest.getIndex()); - out.writeShort(archiveRequest.getArchive()); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoder.java b/protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoder.java deleted file mode 100644 index 06eb258115..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoder.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.encoders; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.runelite.protocol.api.update.ArchiveResponsePacket; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ArchiveResponseEncoder extends MessageToByteEncoder -{ - private static final Logger logger = LoggerFactory.getLogger(ArchiveResponseEncoder.class); - - private static final int CHUNK_SIZE = 512; - - @Override - protected void encode(ChannelHandlerContext ctx, ArchiveResponsePacket archiveResponse, ByteBuf out) throws Exception - { - // archive file header - // 1 byte index - // 2 byte archive - out.writeByte(archiveResponse.getIndex()); - out.writeShort(archiveResponse.getArchive()); - - int pos = out.readableBytes(); - - // next is the compressed data which starts with compression - // type and length - ByteBuf file = Unpooled.wrappedBuffer(archiveResponse.getData()); - // - 3 for the header - int chunkSize = Math.min(file.readableBytes(), CHUNK_SIZE - 3); - - writeChunk(file.readBytes(chunkSize), out); - - while (file.isReadable()) - { - out.writeByte(0xff); - - chunkSize = Math.min(file.readableBytes(), CHUNK_SIZE - 1); - writeChunk(file.readBytes(chunkSize), out); - } - - int size = out.readableBytes() - pos; - logger.debug("Wrote index {} archive {} (size {}) in {} bytes", - archiveResponse.getIndex(), archiveResponse.getArchive(), - archiveResponse.getData().length, size); - } - - private void writeChunk(ByteBuf chunk, ByteBuf out) - { - try - { - out.writeBytes(chunk); - } - finally - { - chunk.release(); - } - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/encoders/EncryptionEncoder.java b/protocol/src/main/java/net/runelite/protocol/update/encoders/EncryptionEncoder.java deleted file mode 100644 index 8b686358fa..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/encoders/EncryptionEncoder.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.encoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import net.runelite.protocol.api.update.EncryptionPacket; -import net.runelite.protocol.update.decoders.UpdateOpcodes; - -public class EncryptionEncoder extends MessageToByteEncoder -{ - - @Override - protected void encode(ChannelHandlerContext ctx, EncryptionPacket encryptionPacket, ByteBuf out) throws Exception - { - out.writeByte(UpdateOpcodes.ENCRYPTION); - out.writeByte(encryptionPacket.getKey()); - out.writeShort(0); - } - -} diff --git a/protocol/src/main/java/net/runelite/protocol/update/encoders/XorEncoder.java b/protocol/src/main/java/net/runelite/protocol/update/encoders/XorEncoder.java deleted file mode 100644 index 0d86f99f47..0000000000 --- a/protocol/src/main/java/net/runelite/protocol/update/encoders/XorEncoder.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.encoders; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; - -public class XorEncoder extends MessageToByteEncoder -{ - private byte key; - - public byte getKey() - { - return key; - } - - public void setKey(byte key) - { - this.key = key; - } - - @Override - protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception - { - if (key == 0) - { - out.writeBytes(msg); - return; - } - - while (msg.isReadable()) - { - out.writeByte(msg.readByte() ^ key); - } - } - -} diff --git a/protocol/src/test/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoderTest.java b/protocol/src/test/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoderTest.java deleted file mode 100644 index 8cf508c834..0000000000 --- a/protocol/src/test/java/net/runelite/protocol/update/encoders/ArchiveResponseEncoderTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.encoders; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import net.runelite.cache.fs.Container; -import net.runelite.cache.fs.jagex.CompressionType; -import net.runelite.protocol.update.decoders.ArchiveResponseDecoder; -import net.runelite.protocol.api.update.ArchiveResponsePacket; -import org.junit.Assert; -import org.junit.Test; - -public class ArchiveResponseEncoderTest -{ - @Test - public void testEncode() throws Exception - { - byte[] data = new byte[1000]; - Random random = new Random(42L); - random.nextBytes(data); - - Container container = new Container(CompressionType.NONE, -1); - container.compress(data, null); - byte[] compressedData = container.data; - - ArchiveResponsePacket archiveResponse = new ArchiveResponsePacket(); - archiveResponse.setIndex(0); - archiveResponse.setArchive(1); - archiveResponse.setData(compressedData); - - ByteBuf buf = Unpooled.buffer(1024); - ArchiveResponseEncoder encoder = new ArchiveResponseEncoder(); - encoder.encode(null, archiveResponse, buf); - - ArchiveResponseDecoder decoder = new ArchiveResponseDecoder(); - List out = new ArrayList<>(); - decoder.decode(null, buf, out); - - Assert.assertEquals(1, out.size()); - ArchiveResponsePacket response = (ArchiveResponsePacket) out.get(0); - - Assert.assertEquals(archiveResponse.getIndex(), response.getIndex()); - Assert.assertEquals(archiveResponse.getArchive(), response.getArchive()); - Assert.assertArrayEquals(archiveResponse.getData(), response.getData()); - - byte[] decompressedData = Container.decompress(response.getData(), null).data; - Assert.assertArrayEquals(data, decompressedData); - } - -} diff --git a/protocol/src/test/java/net/runelite/protocol/update/encoders/XorEncoderTest.java b/protocol/src/test/java/net/runelite/protocol/update/encoders/XorEncoderTest.java deleted file mode 100644 index 0b22ed87d8..0000000000 --- a/protocol/src/test/java/net/runelite/protocol/update/encoders/XorEncoderTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2016-2017, Adam - * 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.protocol.update.encoders; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import org.junit.Assert; -import org.junit.Test; - -public class XorEncoderTest -{ - @Test - public void testEncode() throws Exception - { - ByteBuf buf = Unpooled.buffer(1); - buf.markWriterIndex(); - buf.writeByte(0xff); - - XorEncoder encoder = new XorEncoder(); - encoder.setKey((byte) 0x1); - - ByteBuf out = Unpooled.buffer(1); - encoder.encode(null, buf, out); - - byte encoded = out.readByte(); - Assert.assertEquals((Byte) (byte) 0xfe, (Byte) encoded); - } - -} diff --git a/settings.gradle.kts b/settings.gradle.kts index efde4679b5..518074823a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -32,10 +32,6 @@ plugins { include(":http-api") include(":cache") include(":runelite-api") -include(":protocol-api") -include(":protocol") -include(":cache-client") -include(":cache-updater") include(":runescape-api") include(":runescape-client") include(":deobfuscator") @@ -45,8 +41,6 @@ include(":runelite-mixins") include(":injected-client") include("injection-annotations") include(":runelite-plugin-archetype") -include(":http-service") -include(":http-service-openosrs") include(":wiki-scraper") for (project in rootProject.children) {